Mercurial > projects > dynamin
comparison dynamin/gui/control.d @ 5:4029d5af7542
Add blank lines and rewrap some comments.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 20 Jun 2009 12:26:40 -0500 |
parents | aa4efef0f0b1 |
children | b621b528823d |
comparison
equal
deleted
inserted
replaced
4:fc2420d39e3c | 5:4029d5af7542 |
---|---|
179 e.graphics.save(); | 179 e.graphics.save(); |
180 // TODO: every call to a handler should be wrapped in a save/restore | 180 // TODO: every call to a handler should be wrapped in a save/restore |
181 painting.callHandlers(e); | 181 painting.callHandlers(e); |
182 e.graphics.restore(); | 182 e.graphics.restore(); |
183 } | 183 } |
184 | |
184 this() { | 185 this() { |
185 moved = new Event!()(&whenMoved); | 186 moved = new Event!()(&whenMoved); |
186 resized = new Event!()(&whenResized); | 187 resized = new Event!()(&whenResized); |
187 mouseEntered = new Event!()(&whenMouseEntered, &dispatchMouseEntered); | 188 mouseEntered = new Event!()(&whenMouseEntered, &dispatchMouseEntered); |
188 mouseLeft = new Event!()(&whenMouseLeft); | 189 mouseLeft = new Event!()(&whenMouseLeft); |
208 | 209 |
209 // TODO: remove these when themes mature | 210 // TODO: remove these when themes mature |
210 _foreColor = Color.Black; | 211 _foreColor = Color.Black; |
211 _font = new Font("Tahoma", 11); | 212 _font = new Font("Tahoma", 11); |
212 } | 213 } |
214 | |
213 protected Graphics quickCreateGraphics() { | 215 protected Graphics quickCreateGraphics() { |
214 if(_parent is null) | 216 if(_parent is null) |
215 return null; | 217 return null; |
216 auto g = _parent.quickCreateGraphics(); | 218 auto g = _parent.quickCreateGraphics(); |
217 g.translate(location); | 219 g.translate(location); |
218 return g; | 220 return g; |
219 } | 221 } |
222 | |
220 /** | 223 /** |
221 * Sets the specified Graphics' font and source to this control's font | 224 * Sets the specified Graphics' font and source to this control's font |
222 * and foreground color. Also, clips to this control's rectangle. | 225 * and foreground color. Also, clips to this control's rectangle. |
223 */ | 226 */ |
224 void setupGraphics(Graphics g) { | 227 void setupGraphics(Graphics g) { |
225 g.rectangle(0, 0, width, height); | 228 g.rectangle(0, 0, width, height); |
226 g.clip(); | 229 g.clip(); |
227 g.font = font; | 230 g.font = font; |
228 g.source = foreColor; | 231 g.source = foreColor; |
229 } | 232 } |
233 | |
230 /** | 234 /** |
231 * Creates a Graphics, calls the specified delegate with it, and deletes | 235 * Creates a Graphics, calls the specified delegate with it, and deletes |
232 * it to release resources. | 236 * it to release resources. |
233 */ | 237 */ |
234 void withGraphics(void delegate(Graphics g) dg) { | 238 void withGraphics(void delegate(Graphics g) dg) { |
235 auto g = quickCreateGraphics(); | 239 auto g = quickCreateGraphics(); |
236 setupGraphics(g); | 240 setupGraphics(g); |
237 dg(g); | 241 dg(g); |
238 delete g; | 242 delete g; |
239 } | 243 } |
244 | |
240 /** | 245 /** |
241 * | 246 * |
242 */ | 247 */ |
243 bool focused() { | 248 bool focused() { |
244 return _focused; | 249 return _focused; |
245 } | 250 } |
251 | |
246 /** | 252 /** |
247 * | 253 * |
248 */ | 254 */ |
249 void focus() { | 255 void focus() { |
250 if(!_focusable) | 256 if(!_focusable) |
260 win.focusedControl = this; | 266 win.focusedControl = this; |
261 _focused = true; | 267 _focused = true; |
262 repaint(); | 268 repaint(); |
263 } | 269 } |
264 } | 270 } |
271 | |
265 /** | 272 /** |
266 * Returns whether this control is on the screen. A control is | 273 * Returns whether this control is on the screen. A control is |
267 * on screen if one of its ancestors is a top level window. Whether or | 274 * on screen if one of its ancestors is a top level window. Whether or |
268 * not the control is visible has no bearing on this value. If a control | 275 * not the control is visible has no bearing on this value. If a control |
269 * has no parent, then it is clearly not on the screen. | 276 * has no parent, then it is clearly not on the screen. |
270 */ | 277 */ |
271 bool onScreen() { | 278 bool onScreen() { |
272 return _parent && _parent.onScreen; | 279 return _parent && _parent.onScreen; |
273 } | 280 } |
281 | |
274 /** | 282 /** |
275 * Gets the location of this control in screen coordinates. An exception is | 283 * Gets the location of this control in screen coordinates. An exception is |
276 * thrown if this control is not on the screen. | 284 * thrown if this control is not on the screen. |
277 */ | 285 */ |
278 Point screenLocation() { | 286 Point screenLocation() { |
279 if(!_parent) | 287 if(!_parent) |
280 throw new Exception("control is not on screen"); | 288 throw new Exception("control is not on screen"); |
281 return _parent.screenLocation + location; | 289 return _parent.screenLocation + location; |
282 } | 290 } |
291 | |
283 /** | 292 /** |
284 * Converts the specified point in content coordinates into screen | 293 * Converts the specified point in content coordinates into screen |
285 * coordinates. An exception is thrown if this control is not on the screen. | 294 * coordinates. An exception is thrown if this control is not on the screen. |
286 */ | 295 */ |
287 Point contentToScreen(Point pt) { // TODO: content?? even on Window?? | 296 Point contentToScreen(Point pt) { // TODO: content?? even on Window?? |
288 if(!_parent) | 297 if(!_parent) |
289 throw new Exception("control is not on screen"); | 298 throw new Exception("control is not on screen"); |
290 return _parent.contentToScreen(pt + location); | 299 return _parent.contentToScreen(pt + location); |
291 } | 300 } |
301 | |
292 /** | 302 /** |
293 * Converts the specified point in screen coordinates into content | 303 * Converts the specified point in screen coordinates into content |
294 * coordinates. An exception is thrown if this control is not on the screen. | 304 * coordinates. An exception is thrown if this control is not on the screen. |
295 */ | 305 */ |
296 Point screenToContent(Point pt) { | 306 Point screenToContent(Point pt) { |
297 if(!_parent) | 307 if(!_parent) |
298 throw new Exception("control is not on screen"); | 308 throw new Exception("control is not on screen"); |
299 return _parent.screenToContent(pt) - location; // TODO: borders | 309 return _parent.screenToContent(pt) - location; // TODO: borders |
300 } | 310 } |
311 | |
301 /** | 312 /** |
302 * Converts the specified point in this control's content coordinates | 313 * Converts the specified point in this control's content coordinates |
303 * into the specified control's content coordinates. An exception is | 314 * into the specified control's content coordinates. An exception is |
304 * thrown if this control is not on the screen. | 315 * thrown if this control is not on the screen. |
305 */ | 316 */ |
306 Point contentToContent(Point pt, Control c) { | 317 Point contentToContent(Point pt, Control c) { |
307 return c.screenToContent(contentToScreen(pt)); | 318 return c.screenToContent(contentToScreen(pt)); |
308 } | 319 } |
320 | |
309 /** | 321 /** |
310 * Returns whether the specified point is inside this control. | 322 * Returns whether the specified point is inside this control. |
311 */ | 323 */ |
312 bool contains(Point pt) { | 324 bool contains(Point pt) { |
313 return pt.x >= 0 && pt.y >= 0 && pt.x < width && pt.y < height; | 325 return pt.x >= 0 && pt.y >= 0 && pt.x < width && pt.y < height; |
314 } | 326 } |
315 /// ditto | 327 /// ditto |
316 bool contains(real x, real y) { | 328 bool contains(real x, real y) { |
317 return contains(Point(x, y)); | 329 return contains(Point(x, y)); |
318 } | 330 } |
331 | |
319 bool topLevel() { return false; } | 332 bool topLevel() { return false; } |
320 // TODO: return NativeControl/Window? | 333 // TODO: return NativeControl/Window? |
321 Control getTopLevel() { | 334 Control getTopLevel() { |
322 Control c = this; | 335 Control c = this; |
323 while(c.parent) | 336 while(c.parent) |
324 c = c.parent; | 337 c = c.parent; |
325 return c.topLevel ? c : null; | 338 return c.topLevel ? c : null; |
326 } | 339 } |
340 | |
327 /** | 341 /** |
328 * Gets this control's parent. | 342 * Gets this control's parent. |
329 */ | 343 */ |
330 Container parent() { return _parent; } | 344 Container parent() { return _parent; } |
331 package void parent(Container c) { | 345 package void parent(Container c) { |
332 _parent = c; | 346 _parent = c; |
333 //ParentChanged(new EventArgs); // TODO: add event | 347 //ParentChanged(new EventArgs); // TODO: add event |
334 } | 348 } |
335 /** | 349 |
336 * Gets or sets whether is control is visible. The default is true, except on top-level windows. | 350 /** |
351 * Gets or sets whether is control is visible. The default is true, except | |
352 * on top-level windows. | |
337 */ | 353 */ |
338 //void visible(bool b) { visible = b; } | 354 //void visible(bool b) { visible = b; } |
339 bool visible() { return _visible; } | 355 bool visible() { return _visible; } |
340 | 356 |
341 /** | 357 /** |
399 * if it is elastic, or if it needs to be aligned with other controls. | 415 * if it is elastic, or if it needs to be aligned with other controls. |
400 * | 416 * |
401 * This property should be overridden in subclasses to return a best size. | 417 * This property should be overridden in subclasses to return a best size. |
402 */ | 418 */ |
403 Size bestSize() { return Size(100, 100); } | 419 Size bestSize() { return Size(100, 100); } |
420 | |
404 /** | 421 /** |
405 * Gets the distance from the top of this control to the baseline of | 422 * Gets the distance from the top of this control to the baseline of |
406 * the first line of this control's text. If this control does not have | 423 * the first line of this control's text. If this control does not have |
407 * text, 0 may be returned. | 424 * text, 0 may be returned. |
408 */ | 425 */ |
427 void elasticX(bool b) { _elasticX = b; } | 444 void elasticX(bool b) { _elasticX = b; } |
428 /// ditto | 445 /// ditto |
429 bool elasticY() { return _elasticY; } | 446 bool elasticY() { return _elasticY; } |
430 /// ditto | 447 /// ditto |
431 void elasticY(bool b) { _elasticY = b; } | 448 void elasticY(bool b) { _elasticY = b; } |
449 | |
432 /** | 450 /** |
433 * Gets or sets the text that this control shows. | 451 * Gets or sets the text that this control shows. |
434 */ | 452 */ |
435 string text() { return _text.dup; } | 453 string text() { return _text.dup; } |
436 /// ditto | 454 /// ditto |
475 /// ditto | 493 /// ditto |
476 void font(Font f) { | 494 void font(Font f) { |
477 _font = f; | 495 _font = f; |
478 repaint(); | 496 repaint(); |
479 } | 497 } |
498 | |
480 Cursor cursor() { | 499 Cursor cursor() { |
481 return _cursor; | 500 return _cursor; |
482 } | 501 } |
483 void cursor(Cursor cur) { | 502 void cursor(Cursor cur) { |
484 if(_cursor is cur) | 503 if(_cursor is cur) |
495 * The control will not be repainted before this method returns; rather, | 514 * The control will not be repainted before this method returns; rather, |
496 * the area is just marked as needing to be repainted. The next time there | 515 * the area is just marked as needing to be repainted. The next time there |
497 * are no other system events to be processed, a painting event will called. | 516 * are no other system events to be processed, a painting event will called. |
498 */ | 517 */ |
499 void repaint(Rect rect) { | 518 void repaint(Rect rect) { |
500 // TODO: make sure that parts clipped off by the parent are not invalidated | 519 // TODO: make sure that parts clipped off by the parent are |
520 // not invalidated | |
501 if(_parent) | 521 if(_parent) |
502 _parent.repaint(rect + location); | 522 _parent.repaint(rect + location); |
503 } | 523 } |
504 /// ditto | 524 /// ditto |
505 void repaint(real x, real y, real width, real height) { | 525 void repaint(real x, real y, real width, real height) { |