Mercurial > projects > doodle
annotate doodle/tk/events.d @ 33:157b4ad5615d
Added intersection code for lines and segments.
Wrote my first unit test to for geometry stuff.
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 01:34:14 +0930 |
parents | 1754cb773d41 |
children | 1b4c9ba58673 |
rev | line source |
---|---|
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
17
diff
changeset
|
1 module doodle.tk.events; |
0 | 2 |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
3 public { |
28
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
17
diff
changeset
|
4 import doodle.tk.types; |
1754cb773d41
Part-way through getting to compile with configure/builder.
Graham St Jack <graham.stjack@internode.on.net>
parents:
17
diff
changeset
|
5 import doodle.tk.geometry; |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
6 } |
0 | 7 |
8 abstract class Event { | |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
9 this(in Mask mask) { |
6 | 10 mMask = mask; |
0 | 11 } |
12 | |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
13 Mask mask() const { return mMask; } |
0 | 14 |
15 private { | |
16 Mask mMask; | |
17 } | |
18 } | |
19 | |
33
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
20 /+ |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
21 final class FocusEvent : Event { |
0 | 22 } |
33
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
23 +/ |
0 | 24 |
13 | 25 final class KeyEvent : Event { |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
26 this(in string str, in uint value, in Mask mask) { |
0 | 27 super(mask); |
28 mStr = str; | |
29 mValue = value; | |
30 } | |
31 | |
5 | 32 string str() const { return mStr; } |
0 | 33 |
5 | 34 override string toString() const { |
8 | 35 return std.string.format("Key event: %s, %d, %s", mStr, mValue, mMask); |
0 | 36 } |
37 | |
38 private { | |
39 string mStr; | |
40 uint mValue; | |
41 } | |
42 } | |
43 | |
13 | 44 abstract class PointerEvent : Event { |
17 | 45 this(in Point pixel_point, in Point model_point, in Mask mask) { |
0 | 46 super(mask); |
17 | 47 mPixelPoint = pixel_point; |
3
7d57cae10805
Renamed geometry2 to geometry
David Bryant <daveb@acres.com.au>
parents:
2
diff
changeset
|
48 mModelPoint = model_point; |
0 | 49 } |
50 | |
17 | 51 Point pixel_point() const { return mPixelPoint; } |
5 | 52 Point model_point() const { return mModelPoint; } |
0 | 53 |
54 private { | |
17 | 55 Point mPixelPoint; |
3
7d57cae10805
Renamed geometry2 to geometry
David Bryant <daveb@acres.com.au>
parents:
2
diff
changeset
|
56 Point mModelPoint; |
0 | 57 } |
58 } | |
59 | |
33
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
60 /* |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
61 final class CrossingEvent : PointerEvent { |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
62 this(in Mask mask) { |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
63 super(mask); |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
64 } |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
65 |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
66 private { |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
67 } |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
68 } |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
69 */ |
157b4ad5615d
Added intersection code for lines and segments.
David Bryant <bagnose@gmail.com>
parents:
28
diff
changeset
|
70 |
0 | 71 final class ButtonEvent : PointerEvent { |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
72 this(in ButtonAction button_action, |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
73 in ButtonName button_name, |
17 | 74 in Point pixel_point, |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
75 in Point model_point, |
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
76 in Mask mask) { |
17 | 77 super(pixel_point, model_point, mask); |
7 | 78 mButtonAction = button_action; |
79 mButtonName = button_name; | |
0 | 80 } |
81 | |
5 | 82 override string toString() const { |
8 | 83 return std.string.format("Button event: %s, %s, %s, %s, %s", |
84 enumToString(mButtonAction), enumToString(mButtonName), | |
17 | 85 mPixelPoint, mModelPoint, mMask); |
0 | 86 } |
87 | |
7 | 88 ButtonAction button_action() const { return mButtonAction; } |
89 ButtonName button_name() const { return mButtonName; } | |
0 | 90 |
91 private { | |
7 | 92 ButtonAction mButtonAction; |
93 ButtonName mButtonName; | |
0 | 94 } |
95 } | |
96 | |
97 final class MotionEvent : PointerEvent { | |
17 | 98 this(in Point pixel_point, |
5 | 99 in Point model_point, |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
100 in Mask mask) { |
17 | 101 super(pixel_point, model_point, mask); |
0 | 102 } |
103 | |
5 | 104 override string toString() const { |
8 | 105 return std.string.format("Motion event: %s, %s, %s", |
17 | 106 mPixelPoint, mModelPoint, mMask); |
0 | 107 } |
108 } | |
109 | |
110 final class ScrollEvent : PointerEvent { | |
5 | 111 this(in ScrollDirection scroll_direction, |
17 | 112 in Point pixel_point, |
5 | 113 in Point model_point, |
16
9e63308b749c
* Fix up public/private includes
David Bryant <daveb@acres.com.au>
parents:
13
diff
changeset
|
114 in Mask mask) { |
17 | 115 super(pixel_point, model_point, mask); |
0 | 116 mScrollDirection = scroll_direction; |
117 } | |
118 | |
5 | 119 override string toString() const { |
8 | 120 return std.string.format("Scroll event: %s, %s, %s, %s", |
17 | 121 enumToString(mScrollDirection), mPixelPoint, mModelPoint, mMask); |
0 | 122 } |
123 | |
5 | 124 ScrollDirection scroll_direction() const { return mScrollDirection; } |
0 | 125 |
126 private { | |
127 ScrollDirection mScrollDirection; | |
128 } | |
129 } |