X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=demo-item.c;h=b38e4210dc3258b5f43875aff4fc71cd548f265d;hb=1478e50ab9b22ef50fb0a1be0d77a5f532eb7bd8;hp=2eaf830c2235faee43ec53633f3c7d2262e90ec7;hpb=5e131ba1815778bc6ea172cc4ca4f0c478edd316;p=wordgame diff --git a/demo-item.c b/demo-item.c index 2eaf830..b38e421 100644 --- a/demo-item.c +++ b/demo-item.c @@ -4,6 +4,8 @@ * * demo-item.c - a simple demo item. */ +#include + #include "goocanvas.h" #include "demo-item.h" @@ -31,6 +33,7 @@ goo_demo_item_new (GooCanvasItem *parent, gdouble y, gdouble width, gdouble height, + char letter, ...) { GooCanvasItem *item; @@ -45,8 +48,9 @@ goo_demo_item_new (GooCanvasItem *parent, demo_item->y = y; demo_item->width = width; demo_item->height = height; + demo_item->letter = letter; - va_start (var_args, height); + va_start (var_args, letter); first_property = va_arg (var_args, char*); if (first_property) g_object_set_valist ((GObject*) item, first_property, var_args); @@ -88,16 +92,52 @@ goo_demo_item_paint (GooCanvasItemSimple *simple, cairo_t *cr, GooCanvasBounds *bounds) { - GooDemoItem *demo_item = (GooDemoItem*) simple; + GooDemoItem *item = (GooDemoItem*) simple; + cairo_pattern_t *gradient; + cairo_text_extents_t extents; + int rad = (int) MIN (item->width / 2, item->height / 2); + int cx = item->x + item->width / 2; + int cy = item->y + item->height / 2; + 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_move_to (cr, demo_item->x, demo_item->y); - cairo_line_to (cr, demo_item->x, demo_item->y + demo_item->height); - cairo_line_to (cr, demo_item->x + demo_item->width, - demo_item->y + demo_item->height); - cairo_line_to (cr, demo_item->x + demo_item->width, demo_item->y); - cairo_close_path (cr); - goo_canvas_style_set_fill_options (simple->simple_data->style, cr); 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); } /* Hit detection. This should check if the given coordinate (in the item's