static gboolean on_draw(GtkWidget *widget, gpointer data) { cairo_t *cr; GtkAllocation alloc; gtk_widget_get_allocation(widget, &alloc); gint width = alloc.width; gint height = alloc.height; gint r = 5; cr = gdk_cairo_create(gtk_widget_get_window(widget)); cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr2 = cairo_create(surface); draw_round_rectangle(cr2, 0, 0, width, height, r); cairo_stroke_preserve(cr2); cairo_fill(cr2) ; cairo_destroy(cr2); cairo_region_t *region = gdk_cairo_region_create_from_surface(surface); gtk_widget_shape_combine_region(widget, region); cairo_set_line_width(cr, 0.3); cairo_set_source_rgb(cr, 0.78, 0.78, 0.78); draw_round_rectangle(cr, 0, 0, width, height, r); cairo_stroke(cr); cairo_region_destroy(region); cairo_surface_destroy(surface); cairo_destroy(cr); }
static void decode_and_draw(rectangle_t* obj, const area_t * limiting_canvas_area) { area_t canvas_area = widget_compute_canvas_area(obj->glyph, limiting_canvas_area); canvas_t *canv = canvas_new(&canvas_area); if (obj->corner_radius) { if (obj->is_filled) { draw_solid_round_rectangle(canv, color_to_pixel(obj->fill_color), obj->corner_radius); } if (obj->has_border) { draw_round_rectangle(canv, color_to_pixel(obj->border_color), obj->border_tickness, obj->corner_radius); } } else { if (obj->is_filled) { draw_solid_rectangle(canv, color_to_pixel(obj->fill_color)); } if (obj->has_border) { draw_rectangle(canv, color_to_pixel(obj->border_color), obj->border_tickness); } } canvas_delete(canv); }
void draw_vlinear(cairo_t *cr, gint x, gint y, gint w, gint h, gboolean top_to_buttom) { gint r = 0; cairo_save(cr); // Translate y coordinate, otherwise y is too big for LinearGradient cause render bug. cairo_translate(cr, 0, y); cairo_pattern_t *linear = NULL; if(top_to_buttom) linear = cairo_pattern_create_linear(0, 0, 0, h); else linear = cairo_pattern_create_linear(0, h, 0, 0); cairo_pattern_add_color_stop_rgba(linear, 0, 0, 0, 0, 0); cairo_pattern_add_color_stop_rgba(linear, 0.66, 0, 0, 0, 0.2); cairo_pattern_add_color_stop_rgba(linear, 1, 0, 0, 0, 0.33); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source(cr, linear); draw_round_rectangle(cr, x, 0, w, h, r); cairo_fill(cr); cairo_restore(cr); cairo_pattern_destroy(linear); }