--- libxfcegui4-4.3.90.2.orig/libxfcegui4/xfce_clock.c +++ libxfcegui4-4.3.90.2/libxfcegui4/xfce_clock.c @@ -44,6 +44,7 @@ #include #include +#include #include "xfce_clock.h" @@ -845,22 +846,37 @@ } static void -draw_ticks (GtkWidget * widget, GdkGC * gc, gint xc, gint yc) +set_cairo_colour (cairo_t *cgc, GdkGC *gc) +{ + GdkGCValues gcv; + GdkColor colour; + gdk_gc_get_values (gc, &gcv); + gdk_colormap_query_color (gdk_gc_get_colormap (gc), gcv.foreground.pixel, + &colour); + gdk_cairo_set_source_color (cgc, &colour); +} + +static void +draw_ticks (GtkWidget * widget, cairo_t *cgc, GdkGC * gc, gdouble xc, gdouble yc) { XfceClock *clock; gint i; gdouble theta; gdouble s, c; gdouble demi, quarter; - GdkPoint points[5]; g_return_if_fail (widget != NULL); g_return_if_fail (XFCE_IS_CLOCK (widget)); + g_return_if_fail (cgc != NULL); + g_return_if_fail (gc != NULL); + + set_cairo_colour (cgc, gc); + cairo_new_path (cgc); clock = XFCE_CLOCK (widget); - demi = clock->pointer_width / 2; - quarter = clock->pointer_width / 4; + demi = clock->pointer_width / 2.0; + quarter = clock->pointer_width / 4.0; if (clock->pointer_width / 4 > 0) { @@ -870,19 +886,13 @@ s = sin (theta); c = cos (theta); - points[0].x = xc + s * (clock->radius - demi) - quarter; - points[0].y = yc + c * (clock->radius - demi) - quarter; - points[1].x = xc + s * (clock->radius - demi) - quarter; - points[1].y = yc + c * (clock->radius - demi) + quarter; - points[2].x = xc + s * (clock->radius - demi) + quarter; - points[2].y = yc + c * (clock->radius - demi) + quarter; - points[3].x = xc + s * (clock->radius - demi) + quarter; - points[3].y = yc + c * (clock->radius - demi) - quarter; - points[4].x = xc + s * (clock->radius - demi) - quarter; - points[4].y = yc + c * (clock->radius - demi) - quarter; - - gdk_draw_polygon (widget->window, gc, TRUE, points, 5); + cairo_rectangle (cgc, + xc + s * (clock->radius - demi) - quarter, + yc + c * (clock->radius - demi) - quarter, + demi, demi); } + + cairo_fill (cgc); } else { @@ -892,114 +902,103 @@ s = sin (theta); c = cos (theta); - gdk_draw_line (widget->window, gc, xc + s * (clock->radius - 1), - yc + c * (clock->radius - 1), - xc + s * (clock->radius + 1), - yc + c * (clock->radius + 1)); + cairo_move_to (cgc, xc + s * (clock->radius - 1.5), yc + c * (clock->radius - 1.5)); + cairo_line_to (cgc, xc + s * (clock->radius + 1), yc + c * (clock->radius + 1)); + cairo_close_path (cgc); } + + cairo_stroke (cgc); } } static void -draw_sec_pointer (GtkWidget * widget, GdkGC * gc, gint xc, gint yc) +draw_sec_pointer (GtkWidget * widget, cairo_t *cgc, GdkGC * gc, gdouble xc, gdouble yc) { XfceClock *clock; - GdkPoint points[6]; gdouble s, c; gdouble width; g_return_if_fail (widget != NULL); g_return_if_fail (XFCE_IS_CLOCK (widget)); + g_return_if_fail (cgc != NULL); g_return_if_fail (gc != NULL); + set_cairo_colour (cgc, gc); + clock = XFCE_CLOCK (widget); s = sin (clock->sec_angle); c = cos (clock->sec_angle); width = (gdouble) MAX (clock->pointer_width / 3, 1); - points[0].x = xc + s * width; - points[0].y = yc + c * width; - points[1].x = xc + c * clock->radius + s * 0.5; - points[1].y = yc - s * clock->radius + c * 0.5; - points[2].x = xc + c * clock->radius - s * 0.5; - points[2].y = yc - s * clock->radius - c * 0.5; - points[3].x = xc - s * width; - points[3].y = yc - c * width; - points[4].x = xc - c * width; - points[4].y = yc + s * width; - points[5].x = xc + s * width; - points[5].y = yc + c * width; - - gdk_draw_polygon (widget->window, gc, TRUE, points, 6); + cairo_new_path (cgc); + cairo_move_to (cgc, xc + s * width, yc + c * width); + cairo_line_to (cgc, xc + c * clock->radius + s * 0.5, yc - s * clock->radius + c * 0.5); + cairo_line_to (cgc, xc + c * clock->radius - s * 0.5, yc - s * clock->radius - c * 0.5); + cairo_line_to (cgc, xc - s * width, yc - c * width); + cairo_line_to (cgc, xc - c * width, yc + s * width); + cairo_close_path (cgc); + cairo_fill (cgc); } static void -draw_min_pointer (GtkWidget * widget, GdkGC * gc, gint xc, gint yc) +draw_min_pointer (GtkWidget * widget, cairo_t *cgc, GdkGC * gc, gdouble xc, gdouble yc) { XfceClock *clock; - GdkPoint points[6]; gdouble s, c; gdouble width; g_return_if_fail (widget != NULL); g_return_if_fail (XFCE_IS_CLOCK (widget)); + g_return_if_fail (cgc != NULL); g_return_if_fail (gc != NULL); + set_cairo_colour (cgc, gc); + clock = XFCE_CLOCK (widget); s = sin (clock->min_angle); c = cos (clock->min_angle); width = (gdouble) MAX (clock->pointer_width / 2, 1); - points[0].x = xc + s * width; - points[0].y = yc + c * width; - points[1].x = xc + 3.0 * c * clock->radius / 4.0 + s * 0.5; - points[1].y = yc - 3.0 * s * clock->radius / 4.0 + c * 0.5; - points[2].x = xc + 3.0 * c * clock->radius / 4.0 - s * 0.5; - points[2].y = yc - 3.0 * s * clock->radius / 4.0 - c * 0.5; - points[3].x = xc - s * width; - points[3].y = yc - c * width; - points[4].x = xc - c * width; - points[4].y = yc + s * width; - points[5].x = xc + s * width; - points[5].y = yc + c * width; - - gdk_draw_polygon (widget->window, gc, TRUE, points, 6); + cairo_new_path (cgc); + cairo_move_to (cgc, xc + s * width, yc + c * width); + cairo_line_to (cgc, xc + 3.0 * c * clock->radius / 4.0 + s * 0.5, yc - 3.0 * s * clock->radius / 4.0 + c * 0.5); + cairo_line_to (cgc, xc + 3.0 * c * clock->radius / 4.0 - s * 0.5, yc - 3.0 * s * clock->radius / 4.0 - c * 0.5); + cairo_line_to (cgc, xc - s * width, yc - c * width); + cairo_line_to (cgc, xc - c * width, yc + s * width); + cairo_close_path (cgc); + cairo_fill (cgc); } static void -draw_hrs_pointer (GtkWidget * widget, GdkGC * gc, gint xc, gint yc) +draw_hrs_pointer (GtkWidget * widget, cairo_t *cgc, GdkGC * gc, gdouble xc, gdouble yc) { XfceClock *clock; - GdkPoint points[6]; gdouble s, c; gdouble width; g_return_if_fail (widget != NULL); g_return_if_fail (XFCE_IS_CLOCK (widget)); + g_return_if_fail (cgc != NULL); g_return_if_fail (gc != NULL); + set_cairo_colour (cgc, gc); + clock = XFCE_CLOCK (widget); s = sin (clock->hrs_angle); c = cos (clock->hrs_angle); width = (gdouble) MAX (clock->pointer_width / 2, 1); - points[0].x = xc + s * width; - points[0].y = yc + c * width; - points[1].x = xc + 2.0 * c * clock->radius / 5.0 + s * 0.5; - points[1].y = yc - 2.0 * s * clock->radius / 5.0 + c * 0.5; - points[2].x = xc + 2.0 * c * clock->radius / 5.0 - s * 0.5; - points[2].y = yc - 2.0 * s * clock->radius / 5.0 - c * 0.5; - points[3].x = xc - s * width; - points[3].y = yc - c * width; - points[4].x = xc - c * width; - points[4].y = yc + s * width; - points[5].x = xc + s * width; - points[5].y = yc + c * width; - - gdk_draw_polygon (widget->window, gc, TRUE, points, 6); + cairo_new_path (cgc); + cairo_move_to (cgc, xc + s * width, yc + c * width); + cairo_line_to (cgc, xc + 2.0 * c * clock->radius / 5.0 + s * 0.5, yc - 2.0 * s * clock->radius / 5.0 + c * 0.5); + cairo_line_to (cgc, xc + 2.0 * c * clock->radius / 5.0 - s * 0.5, yc - 2.0 * s * clock->radius / 5.0 - c * 0.5); + cairo_line_to (cgc, xc - s * width, yc - c * width); + cairo_line_to (cgc, xc - c * width, yc + s * width); + cairo_close_path (cgc); + cairo_fill (cgc); } @@ -1107,35 +1106,35 @@ xfce_clock_draw_analog (GtkWidget * widget, GdkRectangle * area) { XfceClock *clock; + cairo_t *cgc; gint xc, yc; g_return_if_fail (widget != NULL); g_return_if_fail (XFCE_IS_CLOCK (widget)); + cgc = gdk_cairo_create (widget->window); + g_return_if_fail (cgc != NULL); + cairo_set_line_width (cgc, 1); + clock = XFCE_CLOCK (widget); xc = widget->allocation.width / 2 + 1; yc = widget->allocation.height / 2 + 1; + set_cairo_colour (cgc, widget->style->bg_gc[widget->state]); + cairo_new_path (cgc); if (area) { - gdk_gc_set_clip_rectangle (widget->style->light_gc[widget->state], - area); - gdk_gc_set_clip_rectangle (widget->style->dark_gc[widget->state], - area); - gdk_gc_set_clip_rectangle (widget->style->mid_gc[widget->state], - area); - gdk_gc_set_clip_rectangle (widget->style->black_gc, area); - gdk_gc_set_clip_rectangle (widget->style->bg_gc[widget->state], area); - gdk_window_clear_area (widget->window, area->x, area->y, area->width, - area->height); + cairo_rectangle (cgc, area->x, area->y, area->width, area->height); } else { - gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width, - widget->allocation.height); + cairo_rectangle (cgc, 0, 0, widget->allocation.width, + widget->allocation.height); + cairo_clip (cgc); } + cairo_fill (cgc); /* * Here we decide arbitrary that if the clock widget is smaller than @@ -1143,40 +1142,35 @@ */ if (MIN (xc, yc) >= 20) { - draw_ticks (widget, widget->style->dark_gc[widget->state], xc, yc); - draw_hrs_pointer (widget, widget->style->dark_gc[widget->state], xc, + draw_ticks (widget, cgc, widget->style->dark_gc[widget->state], xc, yc); + draw_hrs_pointer (widget, cgc, widget->style->dark_gc[widget->state], xc, yc); - draw_min_pointer (widget, widget->style->dark_gc[widget->state], xc, + draw_min_pointer (widget, cgc, widget->style->dark_gc[widget->state], xc, yc); if (clock->display_secs) { - draw_sec_pointer (widget, widget->style->dark_gc[widget->state], + draw_sec_pointer (widget, cgc, widget->style->dark_gc[widget->state], xc, yc); } } - draw_ticks (widget, widget->style->text_gc[widget->state], xc - 1, + draw_ticks (widget, cgc, widget->style->text_gc[widget->state], xc - 1, yc - 1); - draw_hrs_pointer (widget, widget->style->text_gc[widget->state], xc - 1, + draw_hrs_pointer (widget, cgc, widget->style->text_gc[widget->state], xc - 1, yc - 1); - draw_min_pointer (widget, widget->style->text_gc[widget->state], xc - 1, + draw_min_pointer (widget, cgc, widget->style->text_gc[widget->state], xc - 1, yc - 1); if (clock->display_secs) { - draw_sec_pointer (widget, widget->style->text_gc[widget->state], + draw_sec_pointer (widget, cgc, widget->style->text_gc[widget->state], xc - 1, yc - 1); } if (area) { - gdk_gc_set_clip_rectangle (widget->style->light_gc[widget->state], - NULL); - gdk_gc_set_clip_rectangle (widget->style->dark_gc[widget->state], - NULL); - gdk_gc_set_clip_rectangle (widget->style->mid_gc[widget->state], - NULL); - gdk_gc_set_clip_rectangle (widget->style->black_gc, NULL); gdk_gc_set_clip_rectangle (widget->style->bg_gc[widget->state], NULL); } + + cairo_destroy (cgc); } static void