GTK+2: gdk_draw_arc() -- changing arc colour
- From: Chris Martin <c martin sheffield ac uk>
- To: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: GTK+2: gdk_draw_arc() -- changing arc colour
- Date: Thu, 12 Sep 2002 16:20:00 +0100
In the example shown in GTK API/Miscellaneous/GtkDrawingArea it seems
impossible to change the colour the arc is drawn in.
Has anybody a solution to this?
Two examples of code tried -- the first is the "simple" method, the
second a more devious one: seeing that gdk_gc_new() called
gdk_gc_new_with_values() it seemed possible that supplying it with
values might work...
Example 1:
gboolean
expose_event_callback(GtkWidget * widget, GdkEventExpose * event,
gpointer data)
{
GdkGC *gc;
GdkColor colour;
memset(&colour, 0, sizeof(colour));
if (gdk_color_parse(colour_str, &colour)) {
g_print("gdk_color_parse(%s) succeeds.\n", colour_str);
g_print("colour: pixel %lu, red 0x%04x, green 0x%04x, blue 0x%04x.\n",
colour.pixel, colour.red, colour.green, colour.blue);
g_print("colour: pixel %lu, red %u, green %u, blue %u.\n",
colour.pixel, colour.red>>8, colour.green>>8, colour.blue>>8);
} else
g_print("gdk_color_parse(%s) fails.\n", colour_str);
gc = gdk_gc_new(widget->window);
gdk_gc_set_foreground(gc, &colour);
gdk_draw_arc(widget->window, gc, TRUE,
0, 0, widget->allocation.width, widget->allocation.height,
0, 64 * 360);
return TRUE;
}
Example 2:
gboolean
expose_event_callback(GtkWidget * widget, GdkEventExpose * event,
gpointer data)
{
GdkGC *gc;
GdkGCValues values;
GdkColor colour;
gdk_gc_get_values(widget->style->fg_gc[GTK_WIDGET_STATE(widget)], &values);
memset(&colour, 0, sizeof(colour));
if (gdk_color_parse(colour_str, &colour)) {
g_print("gdk_color_parse(%s) succeeds.\n", colour_str);
g_print("colour: pixel %lu, red 0x%04x, green 0x%04x, blue 0x%04x.\n",
colour.pixel, colour.red, colour.green, colour.blue);
g_print("colour: pixel %lu, red %u, green %u, blue %u.\n",
colour.pixel, colour.red>>8, colour.green>>8, colour.blue>>8);
} else
fprintf(stderr, "gdk_color_parse(%s) fails.\n", colour_str);
values.foreground = colour;
gc = gdk_gc_new_with_values(widget->window, &values, GDK_GC_FOREGROUND);
gdk_draw_arc(widget->window, gc, TRUE,
0, 0, widget->allocation.width, widget->allocation.height,
0, 64 * 360);
return TRUE;
}
In both cases the filled arc is drawn in black -- the output shows
that the colour was parsed correctly and the GdkColor was set
correctly:
Example 1:
$ ./try-colour1
gdk_color_parse(LightGrey) succeeds.
colour: pixel 0, red 0xd3d3, green 0xd3d3, blue 0xd3d3.
colour: pixel 0, red 211, green 211, blue 211.
Example 2:
$ ./try-colour2
gdk_color_parse(LightGrey) succeeds.
colour: pixel 0, red 0xd3d3, green 0xd3d3, blue 0xd3d3.
colour: pixel 0, red 211, green 211, blue 211.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]