Mercurial > projects > doodle
annotate doodle/tk/types.d @ 63:20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
author | daveb |
---|---|
date | Thu, 12 Aug 2010 16:35:24 +0930 |
parents | 1b4c9ba58673 |
children | eb5436b47d13 |
rev | line source |
---|---|
29
960b408d3ac5
Builds and runs ok with builder now.
Graham St Jack <graham.stjack@internode.on.net>
parents:
28
diff
changeset
|
1 module doodle.tk.types; |
0 | 2 |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
3 public { |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
4 import std.string; |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
5 } |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
6 |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
7 private { |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
8 import std.typecons; |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
9 import std.algorithm; |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
10 } |
0 | 11 |
7 | 12 mixin(defineEnum!("ButtonAction", |
8 | 13 "SINGLE_PRESS", "DOUBLE_PRESS", "TRIPLE_PRESS", "RELEASE")); |
26 | 14 |
7 | 15 mixin(defineEnum!("ButtonName", |
16 "LEFT", "MIDDLE", "RIGHT", "FOUR", "FIVE")); | |
26 | 17 |
5 | 18 mixin(defineEnum!("ScrollDirection", |
19 "UP", "DOWN", "LEFT", "RIGHT")); | |
26 | 20 |
5 | 21 mixin(defineEnum!("Modifier", |
22 "SHIFT", "CAPS_LOCK", "CONTROL", "ALT", "NUM_LOCK", "META", | |
26 | 23 "SCROLL_LOCK", "LEFT_BUTTON", "MIDDLE_BUTTON", "RIGHT_BUTTON", |
24 "UNUSED_BUTTON_1", "UNUSED_BUTTON_2")); | |
5 | 25 |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
26 struct Mask { |
5 | 27 this(in Modifier[] modifiers) { |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
28 foreach (ref m; modifiers) { |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
29 _bits |= 1 << m; |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
30 } |
5 | 31 } |
32 | |
63
20d6327c4a75
Event progress. Got key press/release working and panning via keyboard.
daveb
parents:
48
diff
changeset
|
33 string toString() { |
5 | 34 string s; |
35 | |
26 | 36 // FIXME this is terrible |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
37 for (int i = 0; i < uint.sizeof * 8; ++i) { |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
38 if (_bits & (1 << i)) { |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
39 if (s != "") s ~= "|"; |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
40 s ~= enumToString(cast(Modifier)i); |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
41 } |
5 | 42 } |
43 | |
44 return s; | |
45 } | |
46 | |
48 | 47 bool isSet(in Modifier m) const { |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
48 return _bits & (1 << m); |
5 | 49 } |
50 | |
48 | 51 bool isUnset(in Modifier m) const { |
52 return !isSet(m); | |
0 | 53 } |
54 | |
55 private { | |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
56 uint _bits; |
5 | 57 } |
58 } |