Re: Setting Drawing Area Background Color



Fiorillo.Paul wrote:

Hello all,

How do I set the background color of a DrawingArea?

You can use gtk_widget_modify_base() function:
---
GdkColor bg;

   bg.red = 50000;
   bg.green = 40000;
   bg.blue = 30000;
   gtk_widget_modify_base(GTK_WIDGET(drawing_area), GTK_STATE_NORMAL, &bg);
---
http://developer.gnome.org/doc/API/2.0/gdk/ gdk-colormaps-and-colors.html
http://developer.gnome.org/doc/API/2.0/gtk/ gtkwidget.html

The DrawingArea is a
GtkWidget and I'm able to use the default DrawingArea->style->black_gc to
color it black when calling gdk_draw_rectangle() , but I want to change the
color to something else other than the default colors of white_gc or
black_gc.  Any hints on how to do this?

Create new gc, allocate the colour you need, set colour into gc and use this gc in
gdk_draw_rectangle call.
---
GdkGC gc;
GdkColor *color;

   gdk_colormap_alloc_color(
gtk_widget_get_colormap(GTK_WIDGET(drawing_area)),
                                                  &color,
                                                  FALSE, TRUE
   );
   gc = gdk_gc_new(GTK_WIDGET(drawing_area)->window);
   gdk_gc_set_foreground(gc, &color);
/* now you can use gc in drawing */
---
http://developer.gnome.org/doc/API/2.0/gdk/ gdk-colormaps-and-colors.html
http://developer.gnome.org/doc/API/2.0/gdk/ gdk-graphics-contexts.html
http://developer.gnome.org/doc/API/2.0/gtk/ gtkwidget.html

Olexiy




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]