Mercurial > projects > doodle
annotate tk/types.d @ 26:06c30d250c0a
Cleanup
author | "David Bryant <bagnose@gmail.com>" |
---|---|
date | Thu, 16 Jul 2009 00:12:02 +0930 |
parents | 9e63308b749c |
children |
rev | line source |
---|---|
0 | 1 module tk.types; |
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 | |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
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 | |
26 | 47 bool is_set(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 | |
26 | 51 bool is_unset(in Modifier m) const { |
5 | 52 return !is_set(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 } |