Re: Please help a despaerate beginner



Glenn Bautista wrote:
> 
> Hi, There.
> 
>     I'm sorry but I really couldn't understand the scribble example in
> the tutorial....but can anyone of you please
> make a simplistic program that demonstrates how expose event works along
> 
> with drawing a pixmap on a gtkdrawingarea?
> Please help me with this.....I'll really appreciate any help.,
> 

Here's a small example. It draws a tiny white 'G' pixmap on a drawingarea.
Read the gdk.h and gdktypes.h file for info on the functions and 
structures involved.

Regards,

Tom

--

tomb@gimp.org

------------------------------- B< cut here ----------------------------------

#include <glib/glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>

/* Pixmap in standard XPM format */

gchar * the_pixmap[] = {
"8 8 2 1",
" 	c None",
".	c White",
"        ",
"  ..... ",
" .      ",
" . .... ",
" .    . ",
" .    . ",
"  ....  ",
"        ",
};

/* Some global variables (eek!) */

GdkGC     *graphics_context;
GdkPixmap *pixmap;
GdkBitmap *pixmap_mask;

/* Standard evewnt handler function */

gboolean event_handler (GtkWidget *drawing_area, GdkEvent *event, gpointer client_data)
{
  gboolean handled = FALSE;

  switch (event->type)
    {
      case GDK_EXPOSE:
        gdk_draw_pixmap (drawing_area->window, /* Destination drawable */
                         graphics_context,     /* Graphics context */
                         pixmap,               /* Source drawable (a pixmap or a window) */
                         0, 0,                 /* Source x and y */
                         100, 100,             /* Destination x and y */
                         8, 8);                /* Width and height of source */
        handled = TRUE;
        break;
      default:
        break;
    }

  return handled;
}

/* Guess what */

gint main (gint argc,gchar *argv[])
{
  GtkWidget *window;
  GtkWidget *drawing_area;

  /* Initialize toolkit and remove toolkit related args */

  gtk_init (&argc, &argv);

  /* Create toplevel window */

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  /* Create drawing area and set size to 200x200 */

  drawing_area = gtk_drawing_area_new ();
  gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), 200, 200);

  /* Set event mask - what events are we interested in receiving? */

  gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK);

  /* Set event handler function */

  gtk_signal_connect (GTK_OBJECT(drawing_area),
                      "event",
                      (GtkSignalFunc)event_handler,
                      window);

  /* Add drawingarea widget to window */

  gtk_container_add (GTK_CONTAINER(window), drawing_area);

  /* Realize window so we can get a valid window to use */

  gtk_widget_realize (window);

  /* Create pixmap, use background color from the window style */

  pixmap = gdk_pixmap_create_from_xpm_d (window->window,
                                         &pixmap_mask,
                                         &window->style->bg[GTK_STATE_NORMAL],
                                         the_pixmap);

  /* Create graphics context (to tell GDK how to draw things) */

  graphics_context = gdk_gc_new (window->window);

  /* Show drawingarea and window */  

  gtk_widget_show (drawing_area);
  gtk_widget_show (window);

  /* Start main event loop */

  gtk_main ();

  /* Satisfy grumpy compilers.. */

  return 0;
}

------------------------------- B< cut here ----------------------------------



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