Mercurial > projects > dynamin
annotate dynamin/gui/events.d @ 104:5c8c1c2e12c0
Change from real to double.
double is not dependant on the platform, and it uses less space.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Fri, 06 Jul 2012 18:39:45 -0500 |
parents | 73060bc3f004 |
children | acdbb30fee7e |
rev | line source |
---|---|
0 | 1 |
2 /* | |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
72
diff
changeset
|
3 * Copyright Jordan Miner |
0 | 4 * |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
72
diff
changeset
|
5 * This Source Code Form is subject to the terms of the Mozilla Public |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
72
diff
changeset
|
6 * License, v. 2.0. If a copy of the MPL was not distributed with this |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
72
diff
changeset
|
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
0 | 8 * |
9 */ | |
10 | |
11 module dynamin.gui.events; | |
12 | |
13 import dynamin.all_core; | |
14 import dynamin.all_painting; | |
15 import dynamin.all_gui; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
16 import dynamin.gui.control; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
17 import dynamin.gui.container; |
0 | 18 |
19 /// | |
20 enum MouseButton { | |
21 None, /// | |
22 Left, /// | |
23 Right, /// | |
24 Middle, /// | |
25 XButton1, /// | |
26 XButton2 /// | |
27 } | |
28 | |
29 /// | |
30 class PaintingEventArgs : EventArgs { | |
31 Graphics g; | |
32 //NativeGraphics ng; | |
33 public: | |
34 /// | |
35 this(Graphics g) { | |
36 this.g = g; | |
37 } | |
38 /// | |
39 Graphics graphics() { return g; } | |
40 } | |
41 | |
42 /// | |
43 class MouseEventArgs : StopEventArgs { | |
44 Point _location; | |
45 MouseButton _button; | |
46 public: | |
47 /// | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
48 this(double x, double y, MouseButton b) { |
0 | 49 _location = Point(x, y); |
50 _button = b; | |
51 } | |
52 /// | |
53 Point location() { return _location; } | |
54 /// | |
55 void location(Point pt) { _location = pt; } | |
56 /// | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
57 double x() { return _location.x; } |
0 | 58 /// |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
59 double y() { return _location.y; } |
0 | 60 /// |
61 MouseButton button() { return _button; } | |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
62 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
63 return format("MouseEventArgs [x={}, y={}, button={}]", |
27
dfaa3da21b27
Fix stupid mistake with last commit.
Jordan Miner <jminer7@gmail.com>
parents:
26
diff
changeset
|
64 x, y, _button); |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
65 } |
0 | 66 } |
67 /// | |
68 class MouseTurnedEventArgs : StopEventArgs { | |
69 double _scrollAmount; | |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
70 bool _scrollScreen; |
0 | 71 public: |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
72 this(double scrollAmount, bool scrollScreen) { |
0 | 73 _scrollAmount = scrollAmount; |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
74 _scrollScreen = scrollScreen; |
0 | 75 } |
76 /** | |
77 * The amount that a control should scroll in response to this event. | |
78 * In a text control, this is the number of lines to scroll. | |
79 * This will be negative if the control should scroll upward and positive | |
80 * if the control should scroll downward. If the amount to be scrolled | |
81 * is more than what is visible on screen, only what is on screen | |
82 * should be scrolled. | |
83 * | |
84 * All users of this class should check scrollScreen to see whether to | |
85 * scroll one screen or to scroll the amount by this. | |
86 */ | |
87 double scrollAmount() { return _scrollAmount; } | |
88 /** | |
89 * On some systems, such as Windows, there is the option of setting | |
90 * the mouse wheel to scroll a screen at a time, the same as the page up | |
91 * and page down keys do. If this option is turned on, scrollScreen will | |
92 * return true and scrollAmount will return ±3. If the option is turned off, | |
93 * scrollScreen will return false. | |
94 */ | |
95 bool scrollScreen() { | |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
96 return _scrollScreen; |
0 | 97 } |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
98 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
99 return format("MouseTurnedEventArgs [scrollAmount={}, scrollScreen={}]", |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
100 _scrollAmount, _scrollScreen); |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
101 } |
0 | 102 } |
103 /// | |
104 class KeyEventArgs : StopEventArgs { | |
105 Key _key; | |
106 bool _repeat; | |
72
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
107 bool _shiftDown, _controlDown, _altDown; |
0 | 108 public: |
72
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
109 this(Key key, bool repeat, bool shift, bool ctrl, bool alt) { |
0 | 110 _key = key; |
111 _repeat = repeat; | |
72
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
112 _shiftDown = shift; |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
113 _controlDown = ctrl; |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
114 _altDown = alt; |
0 | 115 } |
116 /** | |
117 * Returns: the key that was typed. | |
118 */ | |
119 Key key() { return _key; } | |
120 /** | |
121 * Gets whether this key event was generated by the user holding | |
122 * down the key. | |
123 * Returns: true if the key was already down before this event, false | |
124 * if the key was just pressed | |
125 */ | |
126 bool repeat() { return _repeat; } | |
72
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
127 // Returns true if the shift key is currently down and false otherwise. |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
128 bool shiftDown() { return _shiftDown; } |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
129 // Returns true if the control key is currently down and false otherwise. |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
130 bool controlDown() { return _controlDown; } |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
131 // Returns true if the alt key is currently down and false otherwise. |
8dac206ea523
Add shift/control/altDown to KeyEventArgs.
Jordan Miner <jminer7@gmail.com>
parents:
55
diff
changeset
|
132 bool altDown() { return _altDown; } |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
133 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
134 return format("KeyEventArgs [key={}, repeat={}]", _key, _repeat); |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
135 } |
0 | 136 } |
137 /// | |
138 class KeyTypedEventArgs : StopEventArgs { | |
139 dchar _ch; | |
140 bool _repeat; | |
141 public: | |
142 this(dchar c, bool repeat) { | |
143 _ch = c; | |
144 _repeat = repeat; | |
145 } | |
146 /** | |
147 * Gets whether this key event was generated from the user holding | |
148 * down the key. | |
149 * Returns: true if the key was already down before this event, false | |
150 * if the key was just pressed | |
151 */ | |
152 bool repeat() { return _repeat; } | |
153 /** | |
154 * Gets the character that was typed by the user. Many keys on the | |
155 * keyboard will not generate a KeyTyped event, as they do not represent | |
156 * characters. Shift, Insert, Home, F7, and Caps Lock are just some of | |
157 * the keys that do not represent characters. | |
158 */ | |
159 dchar character() { return _ch; } | |
160 } | |
161 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
162 /// |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
163 class HierarchyEventArgs : EventArgs { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
164 int _levels = 0; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
165 Control _control; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
166 public: |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
167 this(Control c) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
168 _control = c; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
169 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
170 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
171 * An immediate child would be a level of 0. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
172 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
173 int levels() { return _levels; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
174 /// ditto |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
175 void levels(int l) { _levels = l; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
176 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
177 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
178 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
179 Control descendant() { return _control; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
180 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
181 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
182 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
183 Container ancestor() { return cast(Container)_control; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
184 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
185 |