Mercurial > projects > dynamin
annotate dynamin/gui/events.d @ 26:87265a206638
Add toString() on some events.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 25 Jul 2009 15:10:32 -0500 |
parents | aa4efef0f0b1 |
children | dfaa3da21b27 |
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; | |
31 | |
32 /// | |
33 enum MouseButton { | |
34 None, /// | |
35 Left, /// | |
36 Right, /// | |
37 Middle, /// | |
38 XButton1, /// | |
39 XButton2 /// | |
40 } | |
41 | |
42 /// | |
43 class PaintingEventArgs : EventArgs { | |
44 Graphics g; | |
45 //NativeGraphics ng; | |
46 public: | |
47 /// | |
48 this(Graphics g) { | |
49 this.g = g; | |
50 } | |
51 /// | |
52 Graphics graphics() { return g; } | |
53 } | |
54 | |
55 /// | |
56 class MouseEventArgs : StopEventArgs { | |
57 Point _location; | |
58 MouseButton _button; | |
59 public: | |
60 /// | |
61 this(real x, real y, MouseButton b) { | |
62 _location = Point(x, y); | |
63 _button = b; | |
64 } | |
65 /// | |
66 Point location() { return _location; } | |
67 /// | |
68 void location(Point pt) { _location = pt; } | |
69 /// | |
70 real x() { return _location.x; } | |
71 /// | |
72 real y() { return _location.y; } | |
73 /// | |
74 MouseButton button() { return _button; } | |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
75 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
76 return format("MouseEventArgs [x={}, y={}, button={}]", |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
77 _x, _y, _button); |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
78 } |
0 | 79 } |
80 /// | |
81 class MouseTurnedEventArgs : StopEventArgs { | |
82 int _delta; | |
83 double _scrollAmount; | |
84 public: | |
85 this(int delta, double scrollAmount) { | |
86 _delta = delta; | |
87 _scrollAmount = scrollAmount; | |
88 } | |
89 /* | |
90 * This is the amount the mouse wheel was turned. | |
91 */ | |
92 //int delta() { return _delta; } | |
93 /** | |
94 * The amount that a control should scroll in response to this event. | |
95 * In a text control, this is the number of lines to scroll. | |
96 * This will be negative if the control should scroll upward and positive | |
97 * if the control should scroll downward. If the amount to be scrolled | |
98 * is more than what is visible on screen, only what is on screen | |
99 * should be scrolled. | |
100 * | |
101 * All users of this class should check scrollScreen to see whether to | |
102 * scroll one screen or to scroll the amount by this. | |
103 */ | |
104 double scrollAmount() { return _scrollAmount; } | |
105 /** | |
106 * On some systems, such as Windows, there is the option of setting | |
107 * the mouse wheel to scroll a screen at a time, the same as the page up | |
108 * and page down keys do. If this option is turned on, scrollScreen will | |
109 * return true and scrollAmount will return ±3. If the option is turned off, | |
110 * scrollScreen will return false. | |
111 */ | |
112 bool scrollScreen() { | |
113 return false; | |
114 } | |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
115 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
116 return format("MouseTurnedEventArgs [scrollAmount={}, scrollScreen={}]", |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
117 _scrollAmount, scrollScreen); |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
118 } |
0 | 119 } |
120 /// | |
121 class KeyEventArgs : StopEventArgs { | |
122 Key _key; | |
123 bool _repeat; | |
124 public: | |
125 this(Key key, bool repeat) { | |
126 _key = key; | |
127 _repeat = repeat; | |
128 } | |
129 /** | |
130 * Returns: the key that was typed. | |
131 */ | |
132 Key key() { return _key; } | |
133 /** | |
134 * Gets whether this key event was generated by the user holding | |
135 * down the key. | |
136 * Returns: true if the key was already down before this event, false | |
137 * if the key was just pressed | |
138 */ | |
139 bool repeat() { return _repeat; } | |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
140 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
141 return format("KeyEventArgs [key={}, repeat={}]", _key, _repeat); |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
142 } |
0 | 143 } |
144 /// | |
145 class KeyTypedEventArgs : StopEventArgs { | |
146 dchar _ch; | |
147 bool _repeat; | |
148 public: | |
149 this(dchar c, bool repeat) { | |
150 _ch = c; | |
151 _repeat = repeat; | |
152 } | |
153 /** | |
154 * Gets whether this key event was generated from the user holding | |
155 * down the key. | |
156 * Returns: true if the key was already down before this event, false | |
157 * if the key was just pressed | |
158 */ | |
159 bool repeat() { return _repeat; } | |
160 /** | |
161 * Gets the character that was typed by the user. Many keys on the | |
162 * keyboard will not generate a KeyTyped event, as they do not represent | |
163 * characters. Shift, Insert, Home, F7, and Caps Lock are just some of | |
164 * the keys that do not represent characters. | |
165 */ | |
166 dchar character() { return _ch; } | |
167 } | |
168 |