Mercurial > projects > dynamin
comparison dynamin/gui/control.d @ 60:cf7c5f968306
Fix crash in withGraphics() if there wasn't a Window ancestor with a handle.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 20:00:33 -0500 |
parents | d3ba5d4a3a27 |
children | aa7eafe2865d |
comparison
equal
deleted
inserted
replaced
59:d3ba5d4a3a27 | 60:cf7c5f968306 |
---|---|
284 | 284 |
285 protected Graphics quickCreateGraphics() { | 285 protected Graphics quickCreateGraphics() { |
286 if(_parent is null) | 286 if(_parent is null) |
287 return null; | 287 return null; |
288 auto g = _parent.quickCreateGraphics(); | 288 auto g = _parent.quickCreateGraphics(); |
289 g.translate(location); | 289 if(g) |
290 g.translate(location); | |
290 return g; | 291 return g; |
291 } | 292 } |
292 | 293 |
293 /** | 294 /** |
294 * Sets the specified Graphics' font and source to this control's font | 295 * Sets the specified Graphics' font and source to this control's font |
305 * Creates a Graphics, calls the specified delegate with it, and deletes | 306 * Creates a Graphics, calls the specified delegate with it, and deletes |
306 * it to release resources. | 307 * it to release resources. |
307 */ | 308 */ |
308 void withGraphics(void delegate(Graphics g) dg) { | 309 void withGraphics(void delegate(Graphics g) dg) { |
309 auto g = quickCreateGraphics(); | 310 auto g = quickCreateGraphics(); |
311 if(!g) | |
312 return; | |
310 setupGraphics(g); | 313 setupGraphics(g); |
311 dg(g); | 314 dg(g); |
312 delete g; | 315 delete g; |
313 } | 316 } |
314 | 317 |
672 void repaint() { | 675 void repaint() { |
673 repaint(Rect(0, 0, width, height)); | 676 repaint(Rect(0, 0, width, height)); |
674 } | 677 } |
675 } | 678 } |
676 | 679 |
677 | 680 unittest { |
681 Control c = new Control; | |
682 c.withGraphics((Graphics g) { g.source = Color.Blue; }); | |
683 } | |
684 |