drawing a bitmap in a window with gdk_draw_rgb_image



Hi,

I have used glade to build an application in which I want to use 4 color
RGB images throughout the entire application. I have taken a look at an
example on the web (see below), but I run into trouble when I want to
"share" the variables over "main.c" and "callback.c".

Where an how do I declare e.g. "rgbbuf", etc. so I can manipulate them
throughout main (initialisation) and callback ?

I have also ran into trouble when I tried to connect event handlers to
GdkImage (GTK 1.2), they don't seem to respond so I had to use an
"eventbox" ? I suppose GdkImage was the right widget to use to draw the
bitmaps in ?

Thanks in advance for your help.

Best regards,

Peter

===================================================

#include <gtk/gtk.h>

#define IMAGE_WIDTH      256
#define IMAGE_HEIGHT     256

 guchar rgbbuf[IMAGE_WIDTH * IMAGE_HEIGHT * 3];

 gboolean on_darea_expose (GtkWidget *widget,
                           GdkEventExpose *event,
                           gpointer user_data);

 int
 main (int argc, char *argv[])
 {
   GtkWidget *window, *darea;
   gint x, y;
   guchar *pos;

   gtk_init (&argc, &argv);
   gdk_rgb_init();
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   darea = gtk_drawing_area_new();
   gtk_drawing_area_size (GTK_DRAWING_AREA (darea), IMAGE_WIDTH,
IMAGE_HEIGHT);
   gtk_container_add (GTK_CONTAINER (window), darea);
   gtk_signal_connect (GTK_OBJECT (darea), "expose-event",
                       GTK_SIGNAL_FUNC (on_darea_expose), NULL);
   gtk_widget_show_all (window);

   /* Set up the RGB buffer. */
   pos = rgbbuf;
   for (y = 0; y < IMAGE_HEIGHT; y++)
     {
       for (x = 0; x < IMAGE_WIDTH; x++)
         {
           *pos++ = x - x % 32;                  /* Red. */
           *pos++ = (x / 32) * 4 + y - y % 32;   /* Green. */
           *pos++ = y - y % 32;                  /* Blue. */
         }
     }

   gtk_main();
   return 0;
 }


 gboolean
 on_darea_expose (GtkWidget *widget,
                  GdkEventExpose *event,
                  gpointer user_data)
 {
   gdk_draw_rgb_image (widget->window,
widget->style->fg_gc[GTK_STATE_NORMAL],
                       0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
                       GDK_RGB_DITHER_MAX, rgbbuf, IMAGE_WIDTH * 3);
 }



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