1 /* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License ONLY.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import arsd
.simpledisplay
;
21 import iv
.cmdcon
.keybinds
;
24 // ////////////////////////////////////////////////////////////////////////// //
36 __gshared
ubyte[ActionKey
.max
+1] keystate
= 0;
37 __gshared ActionKey
[Key
] keybinds
;
40 void setupDefaultKeyBindings () {
41 keybinds
[findKeyByName("up")] = ActionKey
.Up
;
42 keybinds
[findKeyByName("down")] = ActionKey
.Down
;
43 keybinds
[findKeyByName("left")] = ActionKey
.Left
;
44 keybinds
[findKeyByName("right")] = ActionKey
.Right
;
45 keybinds
[findKeyByName("ctrl")] = ActionKey
.Fire
;
46 keybinds
[findKeyByName("z")] = ActionKey
.Fire
;
47 keybinds
[findKeyByName("x")] = ActionKey
.Fire
;
48 keybinds
[findKeyByName("alt")] = ActionKey
.Fire
;
49 keybinds
[findKeyByName("shift")] = ActionKey
.Fire
;
53 // true: press/release registered
54 bool doActionBind (KeyEvent event
, ActionKey
* kk
=null) {
55 if (!event
.key
) return false;
56 if (auto akp
= event
.key
in keybinds
) {
57 if (kk
!is null) *kk
= *akp
;
59 keystate
[*akp
] |
= 0b011;
61 keystate
[*akp
] &= 0b101;
69 void actionBindFrameEnd () {
70 foreach (ref ubyte b
; keystate
[]) {
71 if (b
&0b10) b
= 0b11; else b
= 0;
76 void actionBindClear () {
81 bool actionPressed (ActionKey key
) nothrow @nogc { pragma(inline
, true); return ((keystate
[key
]&1) != 0); }
82 bool actionWasRelease (ActionKey key
) nothrow @nogc { pragma(inline
, true); return ((keystate
[key
]&0b100) != 0); }