refactor cairo-demo a bit

db4
Doug Coleman 2009-02-23 16:47:07 -06:00
parent c3ef25f81c
commit ea851e3a32
1 changed files with 38 additions and 28 deletions

View File

@ -7,11 +7,10 @@
USING: cairo.ffi math math.constants byte-arrays kernel ui ui.render
ui.gadgets opengl.gl accessors ;
combinators ui.gadgets opengl.gl accessors ;
IN: cairo-demo
: make-image-array ( -- array )
384 256 4 * * <byte-array> ;
@ -37,24 +36,35 @@ M: cairo-demo-gadget draw-gadget* ( gadget -- )
M: cairo-demo-gadget pref-dim* drop { 384 256 0 } ;
ERROR: no-cairo-t ;
<PRIVATE
: draw-hello-world ( gadget -- )
cairo-t>>
dup "Sans" CAIRO_FONT_SLANT_NORMAL CAIRO_FONT_WEIGHT_BOLD cairo_select_font_face
dup 90.0 cairo_set_font_size
dup 10.0 135.0 cairo_move_to
dup "Hello" cairo_show_text
dup 70.0 165.0 cairo_move_to
dup "World" cairo_text_path
dup 0.5 0.5 1 cairo_set_source_rgb
dup cairo_fill_preserve
dup 0 0 0 cairo_set_source_rgb
dup 2.56 cairo_set_line_width
dup cairo_stroke
dup 1 0.2 0.2 0.6 cairo_set_source_rgba
dup 10.0 135.0 5.12 0 pi 2 * cairo_arc
dup cairo_close_path
dup 70.0 165.0 5.12 0 pi 2 * cairo_arc
cairo_fill ;
cairo-t>> [ no-cairo-t ] unless*
{
[
"Sans" CAIRO_FONT_SLANT_NORMAL CAIRO_FONT_WEIGHT_BOLD
cairo_select_font_face
]
[ 90.0 cairo_set_font_size ]
[ 10.0 135.0 cairo_move_to ]
[ "Hello" cairo_show_text ]
[ 70.0 165.0 cairo_move_to ]
[ "World" cairo_text_path ]
[ 0.5 0.5 1 cairo_set_source_rgb ]
[ cairo_fill_preserve ]
[ 0 0 0 cairo_set_source_rgb ]
[ 2.56 cairo_set_line_width ]
[ cairo_stroke ]
[ 1 0.2 0.2 0.6 cairo_set_source_rgba ]
[ 10.0 135.0 5.12 0 pi 2 * cairo_arc ]
[ cairo_close_path ]
[ 70.0 165.0 5.12 0 pi 2 * cairo_arc ]
[ cairo_fill ]
} cleave ;
PRIVATE>
M: cairo-demo-gadget graft* ( gadget -- )
dup dup init-cairo swap (>>cairo-t) draw-hello-world ;