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