From d5dfd1d086a486925f49d975fccb423e2983ffb0 Mon Sep 17 00:00:00 2001
From: koniifer <koniifer@proton.me>
Date: Tue, 11 Feb 2025 20:18:38 +0000
Subject: [PATCH] colour palette buttons for render example

---
 sysdata/libraries/intouch/src/keycodes.hb     | 198 ++++++++----------
 sysdata/libraries/intouch/src/lib.hb          |  12 +-
 .../render_example/src/examples/intouch.hb    |  24 ++-
 3 files changed, 116 insertions(+), 118 deletions(-)

diff --git a/sysdata/libraries/intouch/src/keycodes.hb b/sysdata/libraries/intouch/src/keycodes.hb
index cdab92f..2c1b5c0 100644
--- a/sysdata/libraries/intouch/src/keycodes.hb
+++ b/sysdata/libraries/intouch/src/keycodes.hb
@@ -7,115 +7,89 @@ I am now modelling it as I see fit. This is likely not the final version.
 
 KeyCode := u32
 
-// Typically this is not a keycode you will ever recieve.
-None := KeyCode.(0)
-
-Escape := KeyCode.(1)
-/* Alphabet keycodes */
-
-A := KeyCode.(2)
-B := KeyCode.(3)
-C := KeyCode.(4)
-D := KeyCode.(5)
-E := KeyCode.(6)
-F := KeyCode.(7)
-G := KeyCode.(8)
-H := KeyCode.(9)
-I := KeyCode.(10)
-J := KeyCode.(11)
-K := KeyCode.(12)
-L := KeyCode.(13)
-M := KeyCode.(14)
-N := KeyCode.(15)
-O := KeyCode.(16)
-P := KeyCode.(17)
-Q := KeyCode.(18)
-R := KeyCode.(19)
-S := KeyCode.(20)
-T := KeyCode.(21)
-U := KeyCode.(22)
-V := KeyCode.(23)
-W := KeyCode.(24)
-X := KeyCode.(25)
-Y := KeyCode.(26)
-Z := KeyCode.(27)
-
-/* Numeric keycodes*/
-
-Number0 := KeyCode.(28)
-Number1 := KeyCode.(29)
-Number2 := KeyCode.(30)
-Number3 := KeyCode.(31)
-Number4 := KeyCode.(32)
-Number5 := KeyCode.(33)
-Number6 := KeyCode.(34)
-Number7 := KeyCode.(35)
-Number8 := KeyCode.(36)
-Number9 := KeyCode.(37)
-
-KeypadNumber0 := KeyCode.(38)
-KeypadNumber1 := KeyCode.(39)
-KeypadNumber2 := KeyCode.(40)
-KeypadNumber3 := KeyCode.(41)
-KeypadNumber4 := KeyCode.(42)
-KeypadNumber5 := KeyCode.(43)
-KeypadNumber6 := KeyCode.(44)
-KeypadNumber7 := KeyCode.(45)
-KeypadNumber8 := KeyCode.(46)
-KeypadNumber9 := KeyCode.(47)
-
-KeypadPeriod := KeyCode.(48)
-KeypadDivide := KeyCode.(49)
-KeypadMultiply := KeyCode.(50)
-KeypadMinus := KeyCode.(51)
-KeypadPlus := KeyCode.(52)
-KeypadEnter := KeyCode.(53)
-KeypadEquals := KeyCode.(54)
-
-Delete := KeyCode.(55)
-/* Locking Keys */
-NumLock := KeyCode.(56)
-CapsLock := KeyCode.(57)
-ScrollLock := KeyCode.(58)
-
-/* "Alt Gr" key */
-Mode := KeyCode.(59)
-
-/* Multi-key compose key */
-Compose := KeyCode.(60)
-
-LeftAlt := KeyCode.(61)
-LeftControl := KeyCode.(62)
-LeftMeta := KeyCode.(63)
-LeftShift := KeyCode.(64)
-/* Left "Windows" key */
-LeftSuper := KeyCode.(65)
-
-RightAlt := KeyCode.(66)
-RightControl := KeyCode.(67)
-RightMeta := KeyCode.(68)
-RightShift := KeyCode.(69)
-/* Right "Windows" key */
-RightSuper := KeyCode.(70)
-
-/*
-    This block of any triggers on any press of any of the keys.
-    Typically this is the event to care about.
-*/
-AnyNumber0 := KeyCode.(71)
-AnyNumber1 := KeyCode.(72)
-AnyNumber2 := KeyCode.(73)
-AnyNumber3 := KeyCode.(74)
-AnyNumber4 := KeyCode.(75)
-AnyNumber5 := KeyCode.(76)
-AnyNumber6 := KeyCode.(77)
-AnyNumber7 := KeyCode.(78)
-AnyNumber8 := KeyCode.(79)
-AnyNumber9 := KeyCode.(80)
-
-AnyAlt := KeyCode.(81)
-AnyControl := KeyCode.(82)
-AnyMeta := KeyCode.(83)
-AnyShift := KeyCode.(84)
-/* Any "Windows" key */
-AnySuper := KeyCode.(85)
\ No newline at end of file
+$NONE: KeyCode = 0
+$ESCAPE: KeyCode = 1
+$A: KeyCode = 2
+$B: KeyCode = 3
+$C: KeyCode = 4
+$D: KeyCode = 5
+$E: KeyCode = 6
+$F: KeyCode = 7
+$G: KeyCode = 8
+$H: KeyCode = 9
+$I: KeyCode = 10
+$J: KeyCode = 11
+$K: KeyCode = 12
+$L: KeyCode = 13
+$M: KeyCode = 14
+$N: KeyCode = 15
+$O: KeyCode = 16
+$P: KeyCode = 17
+$Q: KeyCode = 18
+$R: KeyCode = 19
+$S: KeyCode = 20
+$T: KeyCode = 21
+$U: KeyCode = 22
+$V: KeyCode = 23
+$W: KeyCode = 24
+$X: KeyCode = 25
+$Y: KeyCode = 26
+$Z: KeyCode = 27
+$NUMBER0: KeyCode = 28
+$NUMBER1: KeyCode = 29
+$NUMBER2: KeyCode = 30
+$NUMBER3: KeyCode = 31
+$NUMBER4: KeyCode = 32
+$NUMBER5: KeyCode = 33
+$NUMBER6: KeyCode = 34
+$NUMBER7: KeyCode = 35
+$NUMBER8: KeyCode = 36
+$NUMBER9: KeyCode = 37
+$KEYPADNUMBER0: KeyCode = 38
+$KEYPADNUMBER1: KeyCode = 39
+$KEYPADNUMBER2: KeyCode = 40
+$KEYPADNUMBER3: KeyCode = 41
+$KEYPADNUMBER4: KeyCode = 42
+$KEYPADNUMBER5: KeyCode = 43
+$KEYPADNUMBER6: KeyCode = 44
+$KEYPADNUMBER7: KeyCode = 45
+$KEYPADNUMBER8: KeyCode = 46
+$KEYPADNUMBER9: KeyCode = 47
+$KEYPADPERIOD: KeyCode = 48
+$KEYPADDIVIDE: KeyCode = 49
+$KEYPADMULTIPLY: KeyCode = 50
+$KEYPADMINUS: KeyCode = 51
+$KEYPADPLUS: KeyCode = 52
+$KEYPADENTER: KeyCode = 53
+$KEYPADEQUALS: KeyCode = 54
+$DELETE: KeyCode = 55
+$NUMLOCK: KeyCode = 56
+$CAPSLOCK: KeyCode = 57
+$SCROLLLOCK: KeyCode = 58
+$MODE: KeyCode = 59
+$COMPOSE: KeyCode = 60
+$LEFTALT: KeyCode = 61
+$LEFTCONTROL: KeyCode = 62
+$LEFTMETA: KeyCode = 63
+$LEFTSHIFT: KeyCode = 64
+$LEFTSUPER: KeyCode = 65
+$RIGHTALT: KeyCode = 66
+$RIGHTCONTROL: KeyCode = 67
+$RIGHTMETA: KeyCode = 68
+$RIGHTSHIFT: KeyCode = 69
+$RIGHTSUPER: KeyCode = 70
+$ANYNUMBER0: KeyCode = 71
+$ANYNUMBER1: KeyCode = 72
+$ANYNUMBER2: KeyCode = 73
+$ANYNUMBER3: KeyCode = 74
+$ANYNUMBER4: KeyCode = 75
+$ANYNUMBER5: KeyCode = 76
+$ANYNUMBER6: KeyCode = 77
+$ANYNUMBER7: KeyCode = 78
+$ANYNUMBER8: KeyCode = 79
+$ANYNUMBER9: KeyCode = 80
+$ANYALT: KeyCode = 81
+$ANYCONTROL: KeyCode = 82
+$ANYMETA: KeyCode = 83
+$ANYSHIFT: KeyCode = 84
+$ANYSUPER: KeyCode = 85
\ No newline at end of file
diff --git a/sysdata/libraries/intouch/src/lib.hb b/sysdata/libraries/intouch/src/lib.hb
index 090bf79..ba37612 100644
--- a/sysdata/libraries/intouch/src/lib.hb
+++ b/sysdata/libraries/intouch/src/lib.hb
@@ -11,8 +11,10 @@ mouse_buf := 0
 recieve_key_event := fn(): ?KeyEvent {
 	kevent := KeyEvent.{}
 
-	if key_buf == 0 key_buf = buffer.search("PS/2 Keyboard")
-	if key_buf == 0 return null
+	if key_buf == 0 {
+		key_buf = buffer.search("PS/2 Keyboard")
+		if key_buf == 0 return null
+	}
 
 	// Read out of the Keyboard buffer here
 	buffer.recv(KeyEvent, key_buf, &kevent)
@@ -27,8 +29,10 @@ recieve_key_event := fn(): ?KeyEvent {
 recieve_mouse_event := fn(): ?MouseEvent {
 	mevent := MouseEvent.{}
 
-	if mouse_buf == 0 mouse_buf = buffer.search("PS/2 Mouse")
-	if mouse_buf == 0 return null
+	if mouse_buf == 0 {
+		mouse_buf = buffer.search("PS/2 Mouse")
+		if mouse_buf == 0 return null
+	}
 
 	// Read out of the Mouse buffer here
 	buffer.recv(MouseEvent, mouse_buf, &mevent)
diff --git a/sysdata/programs/render_example/src/examples/intouch.hb b/sysdata/programs/render_example/src/examples/intouch.hb
index 2c0267d..7d72ed2 100644
--- a/sysdata/programs/render_example/src/examples/intouch.hb
+++ b/sysdata/programs/render_example/src/examples/intouch.hb
@@ -25,8 +25,28 @@ example := fn(): void {
 		kb := intouch.recieve_key_event()
 		if kb != null {
 			if kb.just_triggered {
-				bg_colour = stn.random.any(render.Color)
-				screen.clear(bg_colour)
+				if kb.key == intouch.keycodes.NUMBER1 {
+					pen_colour = render.WHITE
+				} else if kb.key == intouch.keycodes.NUMBER2 {
+					pen_colour = render.BLACK
+				} else if kb.key == intouch.keycodes.NUMBER3 {
+					pen_colour = render.RED
+				} else if kb.key == intouch.keycodes.NUMBER4 {
+					pen_colour = render.YELLOW
+				} else if kb.key == intouch.keycodes.NUMBER5 {
+					pen_colour = render.BLUE
+				} else if kb.key == intouch.keycodes.NUMBER6 {
+					pen_colour = render.CYAN
+				} else if kb.key == intouch.keycodes.NUMBER7 {
+					pen_colour = render.GREEN
+				} else if kb.key == intouch.keycodes.NUMBER8 {
+					pen_colour = render.MAGENTA
+				} else if kb.key == intouch.keycodes.NUMBER9 {
+					pen_colour = render.GRAY
+				} else {
+					bg_colour = stn.random.any(render.Color)
+					screen.clear(bg_colour)
+				}
 			}
 		}