Re: [gtk-list] Drawing area color weirdness help?



On Sun, 10 Jan 1999, Andrew P. Lentvorski wrote:

> Blue ... you name it.  No particular rhyme or reason.
> 
> Why?
> 

I don't know, but I attached a source of test prograb I've written in the
begining of my Gtk programming, it's a red GtkDrawingArea, and it goes
properly.

Good Luck
_____
Alexander Kotelnikov
Saint-Petersburg, Russia
mailto:sacha@ak2614.spb.edu
#include <gtk/gtk.h>

static GdkGC *gc = NULL;
static GdkColor *color ;
void quit()
{
gtk_main_quit();
//gtk_exit(0);
}

/*********
gint draw_black(GtkWidget* drawing_area)
{
       gdk_draw_rectangle (drawing_area->window,
                           drawing_area->style->white_gc,
			   TRUE,
			   0,0,
			   drawing_area->allocation.width,
			   drawing_area->allocation.height);
return 0;
}
********/
gint draw_exp (GtkWidget *widget) 
{
  color = (GdkColor*) g_malloc (sizeof(GdkColor));
  color->red   =  0xffff;
  color->green =  0x0000;  
  color->blue  =  0x0000;
  gdk_color_alloc (gdk_colormap_get_system () , color);
   gc = gdk_gc_new(widget->window);
   gdk_gc_copy(gc,widget->style->white_gc);
   gdk_gc_set_foreground(gc,color);
   gdk_gc_set_background(gc,color);


  gdk_draw_rectangle(widget->window,
                     gc,//widget->style->white_gc,
                     TRUE,
                     0,0,
                     widget->allocation.width,
                     widget->allocation.height);

  return TRUE;
}


static gint expose_event(GtkWidget *widget, GdkEventExpose *event)
{
//draw_black(widget);
draw_exp(widget);
return TRUE;
}
int main (int argc, char *argv[])
     {
       GtkWidget *window;
       GtkWidget *drawing_area;

       gtk_init (&argc, &argv);

       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_signal_connect (GTK_OBJECT(window),"destroy",
                           GTK_SIGNAL_FUNC(quit),NULL);
       drawing_area = gtk_drawing_area_new ();
       gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
       gtk_container_add (GTK_CONTAINER (window), drawing_area);

       gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
                           (GtkSignalFunc) expose_event, NULL);

       gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK);

       gtk_widget_show (drawing_area);
       gtk_widget_show (window);

       gtk_main ();
       return 0;
     }
#include <gtk/gtk.h>

static GdkGC *gc = NULL;
static GdkColor *RED, *GREEN, *BLUE, *BLACK;
void quit()
{
gtk_main_quit();
//gtk_exit(0);
}

gint draw_exp (GtkWidget *widget) 
{
  gdk_gc_set_foreground(gc,RED);
  gdk_draw_rectangle(widget->window,
                     gc,
                     TRUE,
                     0,0,
                     widget->allocation.width,
                     widget->allocation.height/3);

  gdk_gc_set_foreground(gc,GREEN);
  gdk_draw_rectangle(widget->window,
                     gc,
                     TRUE,
                     0,
                     widget->allocation.height/3,
                     2*widget->allocation.width,
                     2*widget->allocation.height/3);

  gdk_gc_set_foreground(gc,BLUE);
  gdk_draw_rectangle(widget->window,
                     gc,
                     TRUE,
                     0,
                     2*widget->allocation.height/3,
                     widget->allocation.width,
                     widget->allocation.height);

  gdk_gc_set_foreground(gc,BLACK);
  gdk_draw_line      (widget->window,
                     gc,
                     0,
                     0,
                     widget->allocation.width,
                     widget->allocation.height);

  return TRUE;
}


static gint expose_event(GtkWidget *widget, GdkEventExpose *event)
{
//draw_black(widget);
draw_exp(widget);
return TRUE;
}
int main (int argc, char *argv[])
     {
       GtkWidget *window;
       GtkWidget *drawing_area;
       

       gtk_init (&argc, &argv);

       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_signal_connect (GTK_OBJECT(window),"destroy",
                           GTK_SIGNAL_FUNC(quit),NULL);
       drawing_area = gtk_drawing_area_new ();
       gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
       gtk_container_add (GTK_CONTAINER (window), drawing_area);

       gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
                           (GtkSignalFunc) expose_event, NULL);

       gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK);

       gtk_widget_show (drawing_area);
       gtk_widget_show (window);

  RED = (GdkColor*) g_malloc (sizeof(GdkColor));
  RED->red   =  0xffff;
  RED->green =  0x0000;  
  RED->blue  =  0x0000;
  gdk_color_alloc (gdk_colormap_get_system () , RED);

  GREEN = (GdkColor*) g_malloc (sizeof(GdkColor));
  GREEN->red   =  0x0000;
  GREEN->green =  0xffff;  
  GREEN->blue  =  0x0000;
  gdk_color_alloc (gdk_colormap_get_system () , GREEN);

  BLUE = (GdkColor*) g_malloc (sizeof(GdkColor));
  BLUE->red   =  0x0000;
  BLUE->green =  0x0000;  
  BLUE->blue  =  0xffff;
  gdk_color_alloc (gdk_colormap_get_system () , BLUE);

  BLACK = (GdkColor*) g_malloc (sizeof(GdkColor));
  BLACK->red   =  0x0000;
  BLACK->green =  0x0000;  
  BLACK->blue  =  0x0000;
  gdk_color_alloc (gdk_colormap_get_system () , BLACK);

   gc = gdk_gc_new(drawing_area->window);
   gdk_gc_copy(gc,drawing_area->style->white_gc);


       gtk_main ();
       return 0;
     }


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