Mercurial > projects > dynamin
comparison dynamin/painting/graphics.d @ 106:acdbb30fee7e
Port to D2.
Most of the effort was dealing with immutable and const.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 17 Dec 2012 23:41:50 -0600 |
parents | 5c8c1c2e12c0 |
children |
comparison
equal
deleted
inserted
replaced
105:97997a544ac0 | 106:acdbb30fee7e |
---|---|
23 private: | 23 private: |
24 string _family; | 24 string _family; |
25 int _style = 0; | 25 int _style = 0; |
26 int _size; | 26 int _size; |
27 public: | 27 public: |
28 this(string family_ = "", int size = 10, bool b = false, bool i = false, bool u = false) { | 28 this(string family_ = null, int size = 10, bool b = false, bool i = false, bool u = false) { |
29 this.family = family_; | 29 this.family = family_; |
30 this.size = size; | 30 this.size = size; |
31 bold = b; | 31 bold = b; |
32 italic = i; | 32 italic = i; |
33 underline = u; | 33 underline = u; |
93 protected this() { | 93 protected this() { |
94 } | 94 } |
95 Color* opIndex(int x, int y) { | 95 Color* opIndex(int x, int y) { |
96 return _data + x+y*_width; | 96 return _data + x+y*_width; |
97 } | 97 } |
98 static Image load(string file) { | 98 static Image load(cstring file) { |
99 static if(false) { | 99 static if(false) { |
100 auto img = new Image; | 100 auto img = new Image; |
101 lodepng.PngInfo info; | 101 lodepng.PngInfo info; |
102 img._data = cast(Color*)lodepng.decode32(readFileBytes(file), info); | 102 img._data = cast(Color*)lodepng.decode32(readFileBytes(file), info); |
103 img._width = info.image.width; | 103 img._width = info.image.width; |
190 * Therefore, the cap extends past the end point for half the line width. | 190 * Therefore, the cap extends past the end point for half the line width. |
191 */ | 191 */ |
192 Square | 192 Square |
193 } | 193 } |
194 | 194 |
195 // cairo_copy_clip_rectangles --> Rectangle[] ClipRectangles() | 195 // cairo_copy_clip_rectangles --> Rectangle[] clipRectangles() |
196 // cairo_get_dash --> Dashes() | 196 // cairo_get_dash --> dashes() |
197 // cairo_get_color_stop_rgba --> ColorStops() | 197 // cairo_get_color_stop_rgba --> colorStops() |
198 /** | 198 /** |
199 * A Graphics object uses its source to draw on its target. Its target is set | 199 * A Graphics object uses its source to draw on its target. Its target is set |
200 * when it is created, but its source can be changed whenever desired. For | 200 * when it is created, but its source can be changed whenever desired. For |
201 * example, for a painting event, the target of a Graphics is the control | 201 * example, for a painting event, the target of a Graphics is the control |
202 * being painted. In other cases it could be an image. Its source is usually a | 202 * being painted. In other cases it could be an image. Its source is usually a |
380 } | 380 } |
381 /** | 381 /** |
382 * Draws the inside of the current path. | 382 * Draws the inside of the current path. |
383 * Example: | 383 * Example: |
384 * ----- | 384 * ----- |
385 * graphics.MoveTo(12.5, 14.5); | 385 * graphics.moveTo(12.5, 14.5); |
386 * graphics.LineTo(123.5, 22.5); | 386 * graphics.lineTo(123.5, 22.5); |
387 * graphics.LineTo(139.5, 108.5); | 387 * graphics.lineTo(139.5, 108.5); |
388 * graphics.LineTo(49.5, 86.5); | 388 * graphics.lineTo(49.5, 86.5); |
389 * graphics.ClosePath(); | 389 * graphics.closePath(); |
390 * graphics.Fill(); | 390 * graphics.fill(); |
391 * ----- | 391 * ----- |
392 * $(IMAGE ../web/example_fill.png) | 392 * $(IMAGE ../web/example_fill.png) |
393 */ | 393 */ |
394 void fill() { | 394 void fill() { |
395 cairo_fill(cr); | 395 cairo_fill(cr); |
455 assert(f.size != 0); | 455 assert(f.size != 0); |
456 cairo_set_font_size(cr, f.size); | 456 cairo_set_font_size(cr, f.size); |
457 cairo_select_font_face(cr, toCharPtr(f.family), f.italic, f.bold); | 457 cairo_select_font_face(cr, toCharPtr(f.family), f.italic, f.bold); |
458 } | 458 } |
459 // TODO: if text is all ascii, do fast path with no uniscribe | 459 // TODO: if text is all ascii, do fast path with no uniscribe |
460 void drawText(string text, double x, double y) { | 460 void drawText(cstring text, double x, double y) { |
461 auto extents = getFontExtents; | 461 auto extents = getFontExtents; |
462 cairo_font_extents_t fextents; | 462 cairo_font_extents_t fextents; |
463 cairo_font_extents(cr, &fextents); | 463 cairo_font_extents(cr, &fextents); |
464 cairo_move_to(cr, x, y + fextents.ascent); | 464 cairo_move_to(cr, x, y + fextents.ascent); |
465 cairo_show_text(cr, toCharPtr(text)); // 99% of time spent in show_text | 465 cairo_show_text(cr, toCharPtr(text)); // 99% of time spent in show_text |
466 checkStatus(); | 466 checkStatus(); |
467 } | 467 } |
468 /// | 468 /// |
469 Size getTextExtents(string text) { | 469 Size getTextExtents(cstring text) { |
470 cairo_text_extents_t textents; | 470 cairo_text_extents_t textents; |
471 cairo_text_extents(cr, toCharPtr(text), &textents); | 471 cairo_text_extents(cr, toCharPtr(text), &textents); |
472 cairo_font_extents_t fextents; | 472 cairo_font_extents_t fextents; |
473 cairo_font_extents(cr, &fextents); | 473 cairo_font_extents(cr, &fextents); |
474 return Size(textents.x_advance, fextents.height); | 474 return Size(textents.x_advance, fextents.height); |
543 /// ditto | 543 /// ditto |
544 void fillRule(GraphicsFillRule rule) { | 544 void fillRule(GraphicsFillRule rule) { |
545 cairo_set_fill_rule(cr, cast(cairo_fill_rule_t)rule); | 545 cairo_set_fill_rule(cr, cast(cairo_fill_rule_t)rule); |
546 } | 546 } |
547 /** | 547 /** |
548 * The temporary surface created will be the same size as the current clip. To speed up using this function, call Clip() to the area you will be drawing in. | 548 * The temporary surface created will be the same size as the current clip. To speed up using this function, call clip() to the area you will be drawing in. |
549 */ | 549 */ |
550 void pushGroup() { | 550 void pushGroup() { |
551 cairo_push_group(cr); | 551 cairo_push_group(cr); |
552 } | 552 } |
553 //popGroup() { // TODO: returning a pattern | 553 //popGroup() { // TODO: returning a pattern |
554 // cairo_pop_group(cr); | 554 // cairo_pop_group(cr); |
555 //} | 555 //} |
556 /** | 556 /** |
557 * Terminates the redirection begun by a call to PushGroup() or | 557 * Terminates the redirection begun by a call to pushGroup() or |
558 * PushGroupWithContent() and installs the resulting pattern as the | 558 * pushGroupWithContent() and installs the resulting pattern as the |
559 * source pattern. | 559 * source pattern. |
560 */ | 560 */ |
561 void popGroupToSource() { | 561 void popGroupToSource() { |
562 cairo_pop_group_to_source(cr); | 562 cairo_pop_group_to_source(cr); |
563 checkStatus(); | 563 checkStatus(); |