[gtk-list] Re: how to change the color of a GdkGC




Subject: [gtk-list] Re: how to change the color of a GdkGC

> gdk_gc_set_foreground(gc,color1);
> gdk_draw_rectangle(drawable,gc,.....);


  Here's how I do it.  Not necessarily the optimum way, but it works for
me.  
  
  I've removed most of my program for simplicity, so the Demo() part
might 
act funky; not refresh right, etc.  But everything else is tested. 
  
  John
  
#include <gtk/gtk.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <malloc.h> 
  
   /* global variables - color palatte */ 
   GdkGC *red, *green, *blue, *purple; 

   void DefColor(GtkWidget *widget,
      GdkGC **gc,char redbyte,char greenbyte,char bluebyte)  
   /* **********************************************************  
   *   Define a single new color for *gc. 
   ********************************************************** */ 
   {        
      GdkColor color; 
   
     /* first, create a GC to draw on */ 
      *gc = gdk_gc_new(widget->window); 
   
      color.red = redbyte * (65535/255);  
      color.green = greenbyte * (65535/255);  
      color.blue = bluebyte * (65535/255); 
      color.pixel = (gulong)(redbyte*65536 + greenbyte*256 + bluebyte); 
      gdk_color_alloc(gtk_widget_get_colormap(widget), &color); 
      gdk_gc_set_foreground(*gc, &color); 
   }/* DefColor */ 

   void DefColors(GtkWidget *widget) 
   /* ********************************************************** 
   *  Define a set of five colors, call only once at the 
   * start of the program. 
   ********************************************************** */ 
   { 
      DefColor(widget,&red,250, 0, 0); 
      DefColor(widget,&green,0,250,0); 
      DefColor(widget,&blue,0,0,255); 
      DefColor(widget,&purple,125,0,125); 
      DefColor(widget,&orange,125, 50, 0);
   }/* DefColors */

   void FreeColors() 
   /* **********************************************************  
   * dispose of all colors at end of program.
   ********************************************************** */ 
   { 
      free(red); free(green); free(blue); free(orange);
   }/* FreeColors */ 

   
   void Demo(GtkWidget *widget)
   /* **********************************************************  
   * Call this to demo the above functions; draw on a widget.
   ********************************************************** */ 
   {
     DefColors(widget); 

     /* fill the widget with a big red rectangle */
     gdk_draw_rectangle (widget->window, red, TRUE, 
            0, 0, widget->allocation.width, widget->allocation.height); 

     /* and a blue line too, for fun. */
     gdk_draw_line(widget->window, blue,1,1,10,21); 
     FreeColors();
   }/* Demo */



___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: http://dl.www.juno.com/dynoget/tagj.



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