X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=demo-item.c;h=99c45fb8b380de280e2a1dd215ddea8f920d6872;hb=a5187a6b925208af24014e40290f323f8ecd9be7;hp=99aaf4afa856a24213c2ea26841e323fe625d6e8;hpb=169f626b0c71bc2cc5f7929ffa4b986e0acfee2a;p=wordgame diff --git a/demo-item.c b/demo-item.c index 99aaf4a..99c45fb 100644 --- a/demo-item.c +++ b/demo-item.c @@ -21,26 +21,14 @@ goo_demo_item_init (GooDemoItem *demo_item) demo_item->size = 0.0; } -void -goo_demo_item_move_to (GooCanvasItem *item, - gdouble x, - gdouble y) -{ - cairo_matrix_t matrix; - - cairo_matrix_init_translate (&matrix, x, y); - goo_canvas_item_set_transform (item, &matrix); -} - /* The convenience function to create new items. This should start with a parent argument and end with a variable list of object properties to fit in with the standard canvas items. */ GooCanvasItem* -goo_demo_item_new (GooCanvasItem *parent, - gdouble x, - gdouble y, - gdouble size, - char letter, +goo_demo_item_new (GooCanvasItem *parent, + gdouble size, + GooDemoItemPaintFunc paint, + void *closure, ...) { GooCanvasItem *item; @@ -52,9 +40,10 @@ goo_demo_item_new (GooCanvasItem *parent, demo_item = (GooDemoItem*) item; demo_item->size = size; - demo_item->letter = letter; + demo_item->paint = paint; + demo_item->closure = closure; - va_start (var_args, letter); + va_start (var_args, closure); first_property = va_arg (var_args, char*); if (first_property) g_object_set_valist ((GObject*) item, first_property, var_args); @@ -66,8 +55,6 @@ goo_demo_item_new (GooCanvasItem *parent, g_object_unref (item); } - goo_demo_item_move_to (item, x, y); - return item; } @@ -99,50 +86,8 @@ goo_demo_item_paint (GooCanvasItemSimple *simple, GooCanvasBounds *bounds) { GooDemoItem *item = (GooDemoItem*) simple; - cairo_pattern_t *gradient; - cairo_text_extents_t extents; - int rad = (int) (item->size / 2); - int cx = item->size / 2; - int cy = cx; - double spot_angle = M_PI / 4.0; - double spot_rad = rad / 2.0; - char string[2]; - - cairo_save (cr); - - gradient = cairo_pattern_create_radial (cx - spot_rad * cos (spot_angle), - cy - spot_rad * sin (spot_angle), - 0.0, - cx - spot_rad * cos (spot_angle), - cy - spot_rad * sin (spot_angle), - rad + spot_rad); - cairo_pattern_add_color_stop_rgb (gradient, 0.0, 1.0, 1.0, 1.0); - cairo_pattern_add_color_stop_rgb (gradient, 1.0, 0.33, 0.33, 0.33); - - cairo_set_source (cr, gradient); - - cairo_arc (cr, - cx, cy, - rad, 0, 2 * M_PI); - - cairo_fill (cr); - - cairo_select_font_face (cr, "mono", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (cr, 1.8 * rad); - - string[0] = item->letter; - string[1] = '\0'; - cairo_text_extents (cr, string, &extents); - cairo_move_to (cr, - cx - extents.width / 2 - extents.x_bearing, - cy - extents.height / 2 - extents.y_bearing); - - cairo_set_source_rgb (cr, 0.2, 0.3, 0.8); - cairo_show_text (cr, string); - - cairo_restore (cr); + + item->paint (cr, item->closure); } /* Hit detection. This should check if the given coordinate (in the item's