annotate semiconginev2/input.nim @ 1256:bfb75c934f4e

add: window focus handling, improve window api a bit
author sam <sam@basx.dev>
date Sun, 28 Jul 2024 17:33:41 +0700
parents b0f4c8ccd49a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
1 type
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
2 Input = object
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
3 keyIsDown: set[Key]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
4 keyWasPressed: set[Key]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
5 keyWasReleased: set[Key]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
6 mouseIsDown: set[MouseButton]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
7 mouseWasPressed: set[MouseButton]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
8 mouseWasReleased: set[MouseButton]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
9 mousePosition: Vec2f
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
10 mouseMove: Vec2f
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
11 mouseWheel: float32
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
12 windowWasResized: bool = true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
13 windowIsMinimized: bool = false
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
14 lockMouse: bool = false
1256
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
15 hasFocus: bool = false
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
16
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
17 # warning, shit is not thread safe
1256
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
18 var input = Input()
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
19
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
20 proc UpdateInputs*(): bool =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
21 # reset input states
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
22 input.keyWasPressed = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
23 input.keyWasReleased = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
24 input.mouseWasPressed = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
25 input.mouseWasReleased = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
26 input.mouseWheel = 0
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
27 input.mouseMove = NewVec2f()
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
28 input.windowWasResized = false
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
29
1256
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
30 if input.lockMouse and input.hasFocus:
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
31 SetMousePosition(vulkan.window, x=int(vulkan.swapchain.width div 2), y=int(vulkan.swapchain.height div 2))
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
32
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
33 var killed = false
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
34 for event in vulkan.window.PendingEvents():
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
35 case event.eventType:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
36 of Quit:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
37 killed = true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
38 of ResizedWindow:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
39 input.windowWasResized = true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
40 of KeyPressed:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
41 input.keyWasPressed.incl event.key
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
42 input.keyIsDown.incl event.key
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
43 of KeyReleased:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
44 input.keyWasReleased.incl event.key
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
45 input.keyIsDown.excl event.key
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
46 of MousePressed:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
47 input.mouseWasPressed.incl event.button
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
48 input.mouseIsDown.incl event.button
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
49 of MouseReleased:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
50 input.mouseWasReleased.incl event.button
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
51 input.mouseIsDown.excl event.button
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
52 of MouseMoved:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
53 let newPos = NewVec2(float32(event.x), float32(event.y))
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
54 input.mouseMove = newPos - input.mousePosition
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
55 input.mousePosition = newPos
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
56 of MouseWheel:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
57 input.mouseWheel = event.amount
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
58 of MinimizedWindow:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
59 input.windowIsMinimized = true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
60 of RestoredWindow:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
61 input.windowIsMinimized = false
1256
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
62 of GotFocus:
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
63 input.hasFocus = true
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
64 of LostFocus:
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
65 input.hasFocus = false
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
66
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
67 return not killed
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
68
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
69 proc KeyIsDown*(key: Key): bool = key in input.keyIsDown
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
70 proc KeyWasPressed*(key: Key): bool = key in input.keyWasPressed
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
71 proc KeyWasPressed*(): bool = input.keyWasPressed.len > 0
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
72 proc KeyWasReleased*(key: Key): bool = key in input.keyWasReleased
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
73 proc MouseIsDown*(button: MouseButton): bool = button in input.mouseIsDown
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
74 proc MouseWasPressed*(): bool = input.mouseWasPressed.len > 0
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
75 proc MouseWasPressed*(button: MouseButton): bool = button in input.mouseWasPressed
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
76 proc MousePressedButtons*(): set[MouseButton] = input.mouseWasPressed
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
77 proc MouseWasReleased*(): bool = input.mouseWasReleased.len > 0
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
78 proc MouseWasReleased*(button: MouseButton): bool = button in input.mouseWasReleased
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
79 proc MouseReleasedButtons*(): set[MouseButton] = input.mouseWasReleased
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
80 proc MousePosition*(): Vec2f = input.mousePosition
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
81 proc MousePositionNormalized*(size: (int, int)): Vec2f =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
82 result.x = (input.mousePosition.x / float32(size[0])) * 2.0 - 1.0
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
83 result.y = (input.mousePosition.y / float32(size[1])) * 2.0 - 1.0
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
84 proc MouseMove*(): Vec2f = input.mouseMove
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
85 proc MouseWheel*(): float32 = input.mouseWheel
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
86 proc WindowWasResized*(): auto = input.windowWasResized
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
87 proc WindowIsMinimized*(): auto = input.windowIsMinimized
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
88 proc LockMouse*(value: bool) = input.lockMouse = value
1256
bfb75c934f4e add: window focus handling, improve window api a bit
sam <sam@basx.dev>
parents: 1254
diff changeset
89 proc HasFocus*(): bool = input.hasFocus
1254
b0f4c8ccd49a did: stuff to test gltf importer
sam <sam@basx.dev>
parents: 1218
diff changeset
90
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
91
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
92 # actions as a slight abstraction over raw input
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
93
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
94 type
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
95 ActionMap = object
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
96 keyActions: Table[string, set[Key]]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
97 mouseActions: Table[string, set[MouseButton]]
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
98
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
99 # warning, shit is not thread safe
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
100 var actionMap: ActionMap
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
101
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
102 proc MapAction*[T: enum](action: T, key: Key) =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
103 if not actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
104 actionMap.keyActions[$action] = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
105 actionMap.keyActions[$action].incl key
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
106
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
107 proc MapAction*[T: enum](action: T, button: MouseButton) =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
108 if not actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
109 actionMap.mouseActions[$action] = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
110 actionMap.mouseActions[$action].incl button
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
111
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
112 proc MapAction*[T: enum](action: T, keys: openArray[Key|MouseButton]) =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
113 for key in keys:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
114 MapAction(action, key)
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
115
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
116 proc UnmapAction*[T: enum](action: T, key: Key) =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
117 if actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
118 actionMap.keyActions[$action].excl(key)
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
119
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
120 proc UnmapAction*[T: enum](action: T, button: MouseButton) =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
121 if actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
122 actionMap.mouseActions[$action].excl(button)
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
123
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
124 proc UnmapAction*[T: enum](action: T) =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
125 if actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
126 actionMap.keyActions[$action] = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
127 if actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
128 actionMap.mouseActions[$action] = {}
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
129
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
130 proc SaveCurrentActionMapping*() =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
131 for name, keys in actionMap.keyActions.pairs:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
132 SystemStorage.Store(name, keys, table = "input_mapping_key")
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
133 for name, buttons in actionMap.mouseActions.pairs:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
134 SystemStorage.Store(name, buttons, table = "input_mapping_mouse")
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
135
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
136 proc LoadActionMapping*[T]() =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
137 reset(actionMap)
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
138 for name in SystemStorage.List(table = "input_mapping_key"):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
139 let action = parseEnum[T](name)
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
140 let keys = SystemStorage.Load(name, set[Key](), table = "input_mapping_key")
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
141 for key in keys:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
142 MapAction(action, key)
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
143
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
144 proc ActionDown*[T](action: T): bool =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
145 if actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
146 for key in actionMap.keyActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
147 if key in input.keyIsDown:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
148 return true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
149 return false
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
150 if actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
151 for button in actionMap.mouseActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
152 if button in input.mouseIsDown:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
153 return true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
154 return false
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
155
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
156 proc ActionPressed*[T](action: T): bool =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
157 if actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
158 for key in actionMap.keyActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
159 if key in input.keyWasPressed:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
160 return true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
161 elif actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
162 for button in actionMap.mouseActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
163 if button in input.mouseWasPressed:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
164 return true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
165
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
166 proc ActionReleased*[T](action: T): bool =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
167 if actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
168 for key in actionMap.keyActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
169 if key in input.keyWasReleased:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
170 return true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
171 elif actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
172 for button in actionMap.mouseActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
173 if button in input.mouseWasReleased:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
174 return true
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
175
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
176 proc ActionValue*[T](action: T): float32 =
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
177 if actionMap.keyActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
178 for key in actionMap.keyActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
179 if key in input.keyIsDown:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
180 return 1
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
181 elif actionMap.mouseActions.contains($action):
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
182 for button in actionMap.mouseActions[$action]:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
183 if button in input.mouseIsDown:
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents:
diff changeset
184 return 1