Mercurial > projects > dynamin
comparison dynamin/gui/control.d @ 10:ccc108b25a0a
Convert to using a struct for events. Fix some comments too.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Wed, 15 Jul 2009 21:22:20 -0500 |
parents | b621b528823d |
children | 96b29f2efa4d |
comparison
equal
deleted
inserted
replaced
9:682fa50ab831 | 10:ccc108b25a0a |
---|---|
112 // TODO: every call to a handler should be wrapped in a save/restore | 112 // TODO: every call to a handler should be wrapped in a save/restore |
113 painting.callHandlers(e); | 113 painting.callHandlers(e); |
114 e.graphics.restore(); | 114 e.graphics.restore(); |
115 } | 115 } |
116 | 116 |
117 /// Override this method in a subclass to handle the Moved event. | 117 /// Override this method in a subclass to handle the moved event. |
118 protected void whenMoved(EventArgs e) { } | 118 protected void whenMoved(EventArgs e) { } |
119 /// This event occurs after the control has been moved. | 119 /// This event occurs after the control has been moved. |
120 Event!() moved; | 120 Event!(whenMoved) moved; |
121 | 121 |
122 /// Override this method in a subclass to handle the Resized event. | 122 /// Override this method in a subclass to handle the resized event. |
123 protected void whenResized(EventArgs e) { } | 123 protected void whenResized(EventArgs e) { } |
124 /// This event occurs after the control has been resized. | 124 /// This event occurs after the control has been resized. |
125 Event!() resized; | 125 Event!(whenResized) resized; |
126 | 126 |
127 /// Override this method in a subclass to handle the MouseEntered event. | 127 /// Override this method in a subclass to handle the mouseEntered event. |
128 protected void whenMouseEntered(EventArgs e) { } | 128 protected void whenMouseEntered(EventArgs e) { } |
129 /// This event occurs after the mouse has entered the control. | 129 /// This event occurs after the mouse has entered the control. |
130 Event!() mouseEntered; | 130 Event!(whenMouseEntered) mouseEntered; |
131 | 131 |
132 /// Override this method in a subclass to handle the MouseLeft event. | 132 /// Override this method in a subclass to handle the mouseLeft event. |
133 protected void whenMouseLeft(EventArgs e) { } | 133 protected void whenMouseLeft(EventArgs e) { } |
134 /// This event occurs after the mouse has left the control. | 134 /// This event occurs after the mouse has left the control. |
135 Event!() mouseLeft; | 135 Event!(whenMouseLeft) mouseLeft; |
136 | 136 |
137 /// Override this method in a subclass to handle the MouseDown event. | 137 /// Override this method in a subclass to handle the mouseDown event. |
138 protected void whenMouseDown(MouseEventArgs e) { } | 138 protected void whenMouseDown(MouseEventArgs e) { } |
139 /// This event occurs after a mouse button is pressed. | 139 /// This event occurs after a mouse button is pressed. |
140 Event!(MouseEventArgs) mouseDown; | 140 Event!(whenMouseDown) mouseDown; |
141 | 141 |
142 /// Override this method in a subclass to handle the MouseUp event. | 142 /// Override this method in a subclass to handle the mouseUp event. |
143 protected void whenMouseUp(MouseEventArgs e) { } | 143 protected void whenMouseUp(MouseEventArgs e) { } |
144 /// This event occurs after a mouse button is released. | 144 /// This event occurs after a mouse button is released. |
145 Event!(MouseEventArgs) mouseUp; | 145 Event!(whenMouseUp) mouseUp; |
146 | 146 |
147 /// Override this method in a subclass to handle the MouseMoved event. | 147 /// Override this method in a subclass to handle the mouseMoved event. |
148 protected void whenMouseMoved(MouseEventArgs e) { } | 148 protected void whenMouseMoved(MouseEventArgs e) { } |
149 /// This event occurs after the mouse has been moved. | 149 /// This event occurs after the mouse has been moved. |
150 Event!(MouseEventArgs) mouseMoved; | 150 Event!(whenMouseMoved) mouseMoved; |
151 | 151 |
152 /// Override this method in a subclass to handle the MouseMoved event. | 152 /// Override this method in a subclass to handle the mouseMoved event. |
153 protected void whenMouseDragged(MouseEventArgs e) { } | 153 protected void whenMouseDragged(MouseEventArgs e) { } |
154 /// This event occurs after the mouse has been moved. | 154 /// This event occurs after the mouse has been moved. |
155 Event!(MouseEventArgs) mouseDragged; | 155 Event!(whenMouseDragged) mouseDragged; |
156 | 156 |
157 /// Override this method in a subclass to handle the MouseTurned event. | 157 /// Override this method in a subclass to handle the mouseTurned event. |
158 protected void whenMouseTurned(MouseTurnedEventArgs e) { } | 158 protected void whenMouseTurned(MouseTurnedEventArgs e) { } |
159 /// This event occurs after the mouse wheel has been turned. | 159 /// This event occurs after the mouse wheel has been turned. |
160 Event!(MouseTurnedEventArgs) mouseTurned; | 160 Event!(whenMouseTurned) mouseTurned; |
161 | 161 |
162 /// Override this method in a subclass to handle the KeyDown event. | 162 /// Override this method in a subclass to handle the keyDown event. |
163 protected void whenKeyDown(KeyEventArgs e) { } | 163 protected void whenKeyDown(KeyEventArgs e) { } |
164 /// This event occurs after a key is pressed. | 164 /// This event occurs after a key is pressed. |
165 Event!(KeyEventArgs) keyDown; | 165 Event!(whenKeyDown) keyDown; |
166 | 166 |
167 /// Override this method in a subclass to handle the KeyTyped event. | 167 /// Override this method in a subclass to handle the keyTyped event. |
168 protected void whenKeyTyped(KeyTypedEventArgs e) { } | 168 protected void whenKeyTyped(KeyTypedEventArgs e) { } |
169 /// This event occurs after a character key is pressed. | 169 /// This event occurs after a character key is pressed. |
170 Event!(KeyTypedEventArgs) keyTyped; | 170 Event!(whenKeyTyped) keyTyped; |
171 | 171 |
172 /// Override this method in a subclass to handle the KeyUp event. | 172 /// Override this method in a subclass to handle the keyUp event. |
173 protected void whenKeyUp(KeyEventArgs e) { } | 173 protected void whenKeyUp(KeyEventArgs e) { } |
174 /// This event occurs after a key is released. | 174 /// This event occurs after a key is released. |
175 Event!(KeyEventArgs) keyUp; | 175 Event!(whenKeyUp) keyUp; |
176 | 176 |
177 /// Override this method in a subclass to handle the painting event. | 177 /// Override this method in a subclass to handle the painting event. |
178 protected void whenPainting(PaintingEventArgs e) { | 178 protected void whenPainting(PaintingEventArgs e) { |
179 e.graphics.source = backColor; | 179 e.graphics.source = backColor; |
180 e.graphics.paint(); | 180 e.graphics.paint(); |
181 } | 181 } |
182 /// This event occurs when the control needs to be painted. | 182 /// This event occurs when the control needs to be painted. |
183 Event!(PaintingEventArgs) painting; | 183 Event!(whenPainting) painting; |
184 | 184 |
185 this() { | 185 this() { |
186 moved = new Event!()(&whenMoved); | 186 moved.mainHandler = &whenMoved; |
187 resized = new Event!()(&whenResized); | 187 resized.mainHandler = &whenResized; |
188 mouseEntered = new Event!()(&whenMouseEntered, &dispatchMouseEntered); | 188 mouseEntered.mainHandler = &whenMouseEntered; |
189 mouseLeft = new Event!()(&whenMouseLeft); | 189 mouseEntered.dispatcher = &dispatchMouseEntered; |
190 mouseDown = new Event!(MouseEventArgs)(&whenMouseDown, &dispatchMouseDown); | 190 mouseLeft.mainHandler = &whenMouseLeft; |
191 mouseUp = new Event!(MouseEventArgs)(&whenMouseUp, &dispatchMouseUp); | 191 mouseDown.mainHandler = &whenMouseDown; |
192 mouseMoved = new Event!(MouseEventArgs)(&whenMouseMoved, &dispatchMouseMoved); | 192 mouseDown.dispatcher = &dispatchMouseDown; |
193 mouseDragged = new Event!(MouseEventArgs)(&whenMouseDragged, &dispatchMouseDragged); | 193 mouseUp.mainHandler = &whenMouseUp; |
194 mouseTurned = new Event!(MouseTurnedEventArgs)(&whenMouseTurned, &dispatchMouseTurned); | 194 mouseUp.dispatcher = &dispatchMouseUp; |
195 keyDown = new Event!(KeyEventArgs)(&whenKeyDown); | 195 mouseMoved.mainHandler = &whenMouseMoved; |
196 keyTyped = new Event!(KeyTypedEventArgs)(&whenKeyTyped); | 196 mouseMoved.dispatcher = &dispatchMouseMoved; |
197 keyUp = new Event!(KeyEventArgs)(&whenKeyUp); | 197 mouseDragged.mainHandler = &whenMouseDragged; |
198 painting = new Event!(PaintingEventArgs)(&whenPainting, &dispatchPainting); | 198 mouseDragged.dispatcher = &dispatchMouseDragged; |
199 mouseTurned.mainHandler = &whenMouseTurned; | |
200 mouseTurned.dispatcher = &dispatchMouseTurned; | |
201 keyDown.mainHandler = &whenKeyDown; | |
202 keyTyped.mainHandler = &whenKeyTyped; | |
203 keyUp.mainHandler = &whenKeyUp; | |
204 painting.mainHandler = &whenPainting; | |
205 painting.dispatcher = &dispatchPainting; | |
199 | 206 |
200 _location = Point(0, 0); | 207 _location = Point(0, 0); |
201 _size = Size(100, 100); | 208 _size = Size(100, 100); |
202 _text = ""; | 209 _text = ""; |
203 _focusable = false; | 210 _focusable = false; |