No subject


Mon Jul 11 11:12:57 PDT 2011


when the widget is selected. Why don't you just give the right
GtkStateFlags to gtk_style_context_get_color? That would take care of
the right forground/background colors for normal/selected and gives a
result more consistent with the current theme.

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
>
> /*
> =C2=A0* The 'data' parameter is a GtkDrawingArea widget.
> =C2=A0*/
>
> static gboolean invert =3D TRUE;
> static cairo_surface_t *s;
>
> /*
> =C2=A0* Function type just to simplify the code.
> =C2=A0*/
> typedef void (*get_color_func_t)(GtkStyleContext *,GtkStateFlags,GdkRGBA =
*);
>
> static void
> invert_bitmap(GtkWidget *w, gpointer data)
> {
> =C2=A0 =C2=A0cairo_t *cr =3D gdk_cairo_create(gtk_widget_get_window(GTK_W=
IDGET(data)));
> =C2=A0 =C2=A0GtkStyleContext *ctx =3D gtk_widget_get_style_context(GTK_WI=
DGET(data));
> =C2=A0 =C2=A0GdkRGBA c;
> =C2=A0 =C2=A0get_color_func_t get_bg, get_fg;
>
> =C2=A0 =C2=A0if (invert) {
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/*
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 * Display inverted form: background of rectan=
gle in foreground color
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 * and bitmap in background color.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0get_bg =3D gtk_style_context_get_color;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0get_fg =3D gtk_style_context_get_background_co=
lor;
> =C2=A0 =C2=A0} else {
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/*
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 * Show normal bitmap while clearing the backg=
round behind it.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0get_fg =3D gtk_style_context_get_color;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0get_bg =3D gtk_style_context_get_background_co=
lor;
> =C2=A0 =C2=A0}
>
> =C2=A0 =C2=A0(*get_bg)(ctx,GTK_STATE_FLAG_NORMAL,&c);
> =C2=A0 =C2=A0cairo_set_source_rgb(cr,c.red,c.green,c.blue);

> =C2=A0 =C2=A0cairo_rectangle(cr, 1, 1, 13, 22);
> =C2=A0 =C2=A0cairo_fill(cr);

If that rectangle is supposed to fill the entire widget area, you can
replace those two lines with a call to cairo_paint().

> =C2=A0 =C2=A0(*get_fg)(ctx,GTK_STATE_FLAG_NORMAL,&c);
> =C2=A0 =C2=A0cairo_set_source_rgb(cr,c.red,c.green,c.blue);
> =C2=A0 =C2=A0cairo_mask_surface(cr,s,2.0,1.0);
>
> =C2=A0 =C2=A0cairo_destroy(cr);
> =C2=A0 =C2=A0invert =3D !invert;
> }

Maarten


More information about the cairo mailing list