GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 22, 2014 11:37 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: gtk_update
PostPosted: Fri Jan 09, 2009 6:52 am 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
Hey guys and girls,

I'm a new user of gtk and c. I am trying to write a program wherein the window updates its self based on the current data input in real time. Currently, I am using
Code:
static gboolean motion_notify_event (GtkWidget *widget,
                 GdkEventMotion *motion_event)
{
int x, y;
GdkModifierType state;
//GdkEventFunc state
gtk_widget_draw(GTK_WIDGET(widget), NULL);

if  (motion_event -> is_hint)
   gdk_event_request_motions (motion_event);

   else {
      x = motion_event->x;
      y = motion_event->y;
      state = (GdkModifierType) motion_event->state;
        }

if (state &&pixmap !=NULL)
   draw_brush (widget, x, y);
return TRUE;
}
and gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
         // | GDK_LEAVE_NOTIFY_MASK
|GDK_ENTER_NOTIFY_MASK
          | GDK_ALL_EVENTS_MASK
          | GDK_BUTTON_PRESS_MASK);

(in main). I have also tried using
Code:
gtk_window_begin_move_drag(widget);
and
Code:
gtk_widget_draw(GTK_WIDGET(widget), NULL);
added codebb -dreblen
Non of them seem to work the way i want them to work. In the best instance, the object in the window is only updated once i move the move. Is there a way of notifying the motion based on data it is obtaining based on time without having to use a mouse?
cheers, Moses


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2009 7:40 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi and welcome to the Gtk+ forums.

I think that the best way of updating you GUI without blocking normal operation is to use timeout or idle function.

You can read more about them at http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-timeout-add and http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html#g-idle-add

If you post more specific data regarding what are you trying to achieve, we may be able to provide more specific help.


Top
 Profile  
 
 Post subject: Thx
PostPosted: Sun Jan 11, 2009 11:06 pm 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
Dear Tad,
Thanks for your quick response. With the code, I am trying to display on a widget the position of a vehicle as it moves. The function moslaserout obtains its x and y coordinates. The problem is, I can't see the exact position or new position of the vehicle without moving my mouse. Moving my mouse faster leads to segmentation fault. I would need help with the automatic display of the position of the vehicle without having to move the mouse. Here is a section of the code again.
Code:
/* Backing pixmap for drawing area */
static GdkPixmap *pixmap = NULL;

/* Create a new backing pixmap of the appropriate size */
static gboolean configure_event( GtkWidget         *widget,
                                 GdkEventConfigure *event )
{
  if (pixmap)
    g_object_unref (pixmap);

  pixmap = gdk_pixmap_new (widget->window,
            widget->allocation.width,
            widget->allocation.height,
            -1);
  gdk_draw_rectangle (pixmap,
            widget->style->white_gc,
            TRUE,
            0, 0,
            widget->allocation.width,
            widget->allocation.height);

  return TRUE;
}


/* This is my version of redrawing the screen from a backed pixmap. */
static gboolean expose_event(GtkWidget *widget, GdkEventExpose *motion_event)

{//moslaserout(int argc, char *argv[]);   
 
gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], pixmap,
        motion_event->area.x, motion_event->area.y,
        motion_event->area.x, motion_event->area.y,
        motion_event->area.width, motion_event->area.height);
return FALSE;
}

/* Draw a rectangle on the screen (since we need event update) */

static void draw_brush (GtkWidget *widget,
                        gdouble x,
         gdouble y)

{
unsigned int num[scnsz];
   float  xu[scnsz], yu[scnsz];

//while (! done) {
moslaserout(0, 0, xu, yu);

//

int counter2 = 0;

/*while (counter2 <scnsz)
{
printf(" hope %f %f",xu[counter2],yu[counter2]);
counter2 ++; }
//}*/



GdkRectangle coords;

coords.x  = 6; //xu[counter2];
coords.y = 7; //yu[counter2];
coords.width = 5;
coords.height = 5;

gdk_draw_rectangle(pixmap,
         widget->style->black_gc,
         TRUE,
         coords.x, coords.y,
         coords.width, coords.height);

gtk_widget_queue_draw_area (widget,
             coords.x, coords.y,
             coords.width, coords.height);
//printf(" hope %d %d",coords.x, coords.y);
}   

/* Notifying the motion (this is useful inorder that the update is done */
/*static gboolean expose_event_callback7 (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{

gdk_draw_arc (widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
TRUE,
xu, yu,5,5
,0, 360*64);


return TRUE;
} */
static gboolean motion_notify_event (GtkWidget *widget,
                 GdkEventMotion *motion_event)
{
int x, y;
GdkModifierType state;
//GdkEventFunc state


if  (motion_event -> is_hint)
   gdk_event_request_motions (motion_event);

   else {
      x = motion_event->x;
      y = motion_event->y;
      state = (GdkModifierType) motion_event->state;
        }

if (state &&pixmap !=NULL)
   draw_brush (widget, x, y);
return TRUE;
}



void quit ()
{
  exit (0);
}

int main( int   argc, char **argv )
{
  GtkWidget *window, *drawing_area, *drawing_area2, *fixed, *vbox;
 

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_name (window, "PDA Current Position"); //pls note i havent set window size

  vbox = gtk_vbox_new (FALSE, 1);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (quit), NULL);

  /* Create the drawing area */

  drawing_area = gtk_drawing_area_new ();
  gtk_widget_set_size_request (GTK_WIDGET (drawing_area), 750, 480);
  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);

  gtk_widget_show (drawing_area);

  /* Signals used to handle backing pixmap */

  g_signal_connect (G_OBJECT (drawing_area), "expose_event",
          G_CALLBACK (expose_event), NULL);
  g_signal_connect (G_OBJECT (drawing_area),"configure_event",
          G_CALLBACK (configure_event), NULL);

  /* Event signals */

  g_signal_connect (G_OBJECT (drawing_area), "motion_notify_event",
          G_CALLBACK (motion_notify_event), NULL);
 

  gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
          | GDK_LEAVE_NOTIFY_MASK
          | GDK_BUTTON_PRESS_MASK
          | GDK_POINTER_MOTION_MASK
          | GDK_POINTER_MOTION_HINT_MASK);

/* Displaying the vehicle position */

g_signal_connect (G_OBJECT (drawing_area), "expose_event",
G_CALLBACK (expose_event_callback), NULL);

/*g_signal_connect (G_OBJECT (drawing_area), "expose_event",
G_CALLBACK (expose_event_callback7), NULL); */


gtk_widget_show_all (GTK_WIDGET(window));

gtk_widget_show(vbox);

  gtk_main ();

  return 0;
}
added codebb -dreblen

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 4:04 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I think that by using cairo you can greatly simplify your code that is responsible for drawing vehicle's position. I created a simple example that demonstrates some useful techniques, among other timeout functions and some cairo drawing.

Official documentation can be found at http://library.gnome.org/devel/cairo/1.8/index.html and http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add

Code:
#include <gtk/gtk.h>

static gboolean
timeout( GtkWidget *area )
{
   gtk_widget_queue_draw( area );

   return( TRUE );
}

static void
get_cur_loc( gint *x,
          gint *y )
{
   static gint reference = 0;

   if( reference == 3000 )
      reference = 0;

   reference += 10;

   *y = reference / 10;
   *x = reference % 350;
}

static gboolean
cb_expose_event( GtkWidget      *draw,
             GdkEventExpose *event,
             gpointer        data )
{
   cairo_t          *cr;
   static GdkPixbuf *pixbuf = NULL;
   gint              x, y;

   if( ! pixbuf )
   {
      pixbuf = gdk_pixbuf_new_from_file_at_size( "test.png", 400, 400, NULL );
   }

   /* Paint background map */
   cr = gdk_cairo_create( draw->window );
   gdk_cairo_set_source_pixbuf( cr, pixbuf, 0, 0 );
   cairo_paint( cr );

   /* Draw our current location */
   get_cur_loc( &x, &y );
   cairo_set_line_width( cr, 20 );
   cairo_set_source_rgb( cr, 1, 0, 0 );
   cairo_set_line_cap( cr, CAIRO_LINE_CAP_ROUND );
   cairo_move_to( cr, x, y );
   cairo_close_path( cr );
   cairo_stroke( cr );

   cairo_destroy( cr );

   return( FALSE );
}

int
main( int    argc,
     char **argv )
{
   GtkWidget *window;
   GtkWidget *draw;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   gtk_window_set_default_size( GTK_WINDOW( window ), 400, 400 );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   draw = gtk_drawing_area_new();
   g_signal_connect( G_OBJECT( draw ), "expose-event",
                 G_CALLBACK( cb_expose_event ), NULL );
   gtk_container_add( GTK_CONTAINER( window ), draw );

   gtk_widget_show_all( window );

   g_timeout_add( 100, (GSourceFunc)timeout, draw );

   gtk_main();

   return( 0 );
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 1:21 am 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
Thanks Tad,

My code now works with the timeout function. There is only one problem though, i.e. if the streaming/ update time changes, i get segmentation fault. I think an if loop should be able to resolve this problem.

Another question is, is it possible to shift the origin of the drawing area so that i can plot negative coords. I have tried putting it into vbox then move it but the origin doesnt change.

Cheers,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 9:25 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

You don't need to do anything with drawing area. You just need to transform cairo's current transformation matrix. The function needed to move the origin would be cairo_translate (you may want to look at other transformation functions too, since they are most useful for eg. drawing lines at an angle without the need to use heavy geometric calculations to obtain x and y coordinates).

I modified my example to demonstrate the translation transformation.

Code:
#include <gtk/gtk.h>

static gboolean
timeout( GtkWidget *area )
{
   gtk_widget_queue_draw( area );

   return( TRUE );
}

static void
get_cur_loc( gint *x,
          gint *y )
{
   static gint reference = 150;
   static gint increment = 1;

   if( reference == 150 || reference == -150 )
      increment *= -1;

   reference += increment * 5;

   *x = reference;
   if( reference >= 0 )
      *y = increment * ( 150 - reference );
   else
      *y = increment * ( 150 + reference );
}

static gboolean
cb_expose_event( GtkWidget      *draw,
             GdkEventExpose *event,
             gpointer        data )
{
   cairo_t          *cr;
   static GdkPixbuf *pixbuf = NULL;
   gint              x, y;

   if( ! pixbuf )
   {
      pixbuf = gdk_pixbuf_new_from_file_at_size( "test.png", 400, 400, NULL );
   }

   /* Paint background map */
   cr = gdk_cairo_create( draw->window );
   gdk_cairo_set_source_pixbuf( cr, pixbuf, 0, 0 );
   cairo_paint( cr );

   /* Draw our current location */
   get_cur_loc( &x, &y );
   g_print( "Coords: (%d, %d)\n", x, y );
   cairo_translate( cr, 200, 200 );
   cairo_set_line_width( cr, 20 );
   cairo_set_source_rgb( cr, 1, 0, 0 );
   cairo_set_line_cap( cr, CAIRO_LINE_CAP_ROUND );
   cairo_move_to( cr, x, y );
   cairo_close_path( cr );
   cairo_stroke( cr );

   cairo_destroy( cr );

   return( FALSE );
}

int
main( int    argc,
     char **argv )
{
   GtkWidget *window;
   GtkWidget *draw;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   gtk_window_set_default_size( GTK_WINDOW( window ), 400, 400 );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   draw = gtk_drawing_area_new();
   g_signal_connect( G_OBJECT( draw ), "expose-event",
                 G_CALLBACK( cb_expose_event ), NULL );
   gtk_container_add( GTK_CONTAINER( window ), draw );

   gtk_widget_show_all( window );

   g_timeout_add( 100, (GSourceFunc)timeout, draw );

   gtk_main();

   return( 0 );
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 12:22 pm 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
Thanks Tad,
I've got it right without using cairo library. The problem now is how to change the color of each image in the widget say for e.g. if I display a rectangle, circle and points and do want to use the colors red, black and yellow. I have tried using GdkColor color but changes the color of everything in the widget.

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 12:44 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

I cannot give you the exact answer to this question, since you haven't revealed your method of drawing. But if you use GDK's functions to draw, you can set colors by modifying foreground color property of GdkGC object.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 5:10 am 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
Dear Tad,

Thanks once again for your quick response. I am using purely gtk to draw my lines. My project does not require the use of cairo library. The function that I use to draw each of my lines, points and shapes is similar to this
Code:
         gdk_draw_rectangle (pixmap,
            widget->style->white_gc,
            TRUE,
            0, 0,
            widget->allocation.width,
            widget->allocation.height);
added codebb -dreblen
To change the colors, i have used GdkColor but this changes the color of the container (widhet/window). So I wonder if there is a better way of doing it .i.e. changing the color of individual geometries.
Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 11:46 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

I think that you need to do something like this.

Code:
GdkGC    *gc;
GdkColor  color;

gc = gdk_gc_new( widget->window );

/* White rectange */
color.red   = 65535;
color.green = 65535;
color.blue  = 65535;
gdk_gc_set_rgb_fg_color( gc, &color );
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, widget->allocation.width,
               widget->allocation.height);

/* Black rectange */
color.red   = 0;
color.green = 0;
color.blue  = 0;
gdk_gc_set_rgb_fg_color( gc, &color );
gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, widget->allocation.width,
               widget->allocation.height);

g_object_unref( G_OBJECT( gc ) );


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 6:02 am 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
I tried using
Code:
static gboolean expose_event_callback7 (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
GdkGC *gc;
GdkColor color;
gc = gdk_gc_new( widget->window );


GdkRectangle rect;

rect.x = 50;
rect.y = 100;
rect.width = 100;
rect.height = 60;



color.red   = 65535;
color.green =65535 ;
color.blue  = 65535;

gdk_gc_set_rgb_fg_color( gc, &color );
gdk_draw_rectangle (pixmap, gc, TRUE, rect.x, rect.y, rect.width, rect.height);

g_object_unref( G_OBJECT( gc ) );

return TRUE;
}
added codebb -dreblen

It doesn't work and i wont worry about it since its not that important for my project. I dont get how you set the colors color.red = 65535; above.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 7:25 am 
Offline
Familiar Face

Joined: Fri Jan 09, 2009 6:42 am
Posts: 16
Thanks very much.
Here is the most part of my code.
Code:
#include <stdio.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <gdk/gdkkeysyms.h>
#define size 4

static gboolean expose_event_callback7 (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
gdk_draw_arc (widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
TRUE,
100, 100,5,5
,0, 360*64);

return TRUE;
}

static gboolean expose_event_callback2 (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{

GdkPoint points[size];

unsigned int xmap[size] = {50,400,200,80};
unsigned int ymap[size] = {60,110,400,300};

gint i = 0;
while (i < size)
{
points[i].x = xmap[i];
points[i].y = ymap[i];
i++;
}




gdk_draw_polygon (widget->window,
         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
         FALSE,points, 4);

//gtk_widget_draw();//(widget->window, &points);
gdk_threads_leave();

/*
gdk_draw_polygon (pixmap, gc, TRUE, points, 4); */
return FALSE;
}

/* Backing pixmap for drawing area */
static GdkPixmap *pixmap = NULL;

/* Create a new backing pixmap of the appropriate size */
static gboolean configure_event( GtkWidget         *widget,
                                 GdkEventConfigure *event )
{
  if (pixmap)
    g_object_unref (pixmap);

  pixmap = gdk_pixmap_new (widget->window,
            widget->allocation.width,
            widget->allocation.height,
            -1);
  gdk_draw_rectangle (pixmap,
            widget->style->white_gc,
            TRUE,
            0, 0,
            widget->allocation.width,
            widget->allocation.height);

  return TRUE;
}

/* Redraw the screen from the backing pixmap */
static gboolean expose_event( GtkWidget      *widget,
                              GdkEventExpose *event )
{
  gdk_draw_drawable (widget->window,
           widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
           pixmap,
           event->area.x, event->area.y,
           event->area.x, event->area.y,
           event->area.width, event->area.height);

  return FALSE;
}

/* Draw a rectangle on the screen */
static void draw_brush( GtkWidget *widget,
                        gdouble    x,
                        gdouble    y)
{
  GdkRectangle update_rect;

  update_rect.x = x - 5;
  update_rect.y = y - 5;
  update_rect.width = 5;
  update_rect.height = 5;
  gdk_draw_rectangle (pixmap,
            widget->style->black_gc,
            TRUE,
            update_rect.x, update_rect.y,
            update_rect.width, update_rect.height);
  gtk_widget_queue_draw_area (widget,
                    update_rect.x, update_rect.y,
                    update_rect.width, update_rect.height);
printf("\n %d is %d",update_rect.x, update_rect.y);
}

static gboolean button_press_event( GtkWidget      *widget,
                                    GdkEventButton *event )
{
  if (event->button == 1 && pixmap != NULL)
    draw_brush (widget, event->x, event->y);
g_print("clicked\n");

  return TRUE;
}

static gboolean button_press_event2( GtkWidget      *widget,
                                    GdkEventButton *event )
{g_print("hello");
//snprintf( should be able to display stuffs on the screen
}

static gboolean motion_notify_event( GtkWidget *widget,
                                     GdkEventMotion *event )
{
  int x, y;
  GdkModifierType state;

  if (event->is_hint)
    gdk_window_get_pointer (event->window, &x, &y, &state);
  else
    {
      x = event->x;
      y = event->y;
      state = event->state;
    }
   
  if (state & GDK_BUTTON1_MASK && pixmap != NULL)
    draw_brush (widget, x, y);
 
  return TRUE;
}
/* This crap to show vehicle status */
void vehicle_status(GtkWindow *window,
     GdkEvent *event, gpointer data)
{
   int x, y;
   char buf[100];
   x = event->configure.x;
   y = event->configure.y;
   sprintf(buf, "%d, %d", x, y);
   gtk_window_set_title(window, buf);
}



void quit ()
{
  exit (0);
}

int main( int   argc,
          char *argv[] )
{
  GtkWidget *window, *drawing_area, *fixed, *vbox, *filemenu, *file, *quit, *sep, *menubar, *position, *cruc;
    GtkAccelGroup *accel_group = NULL;


  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
// gtk_widget_set_name (window, "Test Draw 9");

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);

menubar = gtk_menu_bar_new();
  filemenu = gtk_menu_new();

accel_group = gtk_accel_group_new();
  gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);


file = gtk_menu_item_new_with_label("TASKS");
position = gtk_menu_item_new_with_label("HMC Position");
cruc = gtk_menu_item_new_with_label("Pick Crucible");


  sep = gtk_separator_menu_item_new();
  quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);

  gtk_widget_add_accelerator(quit, "activate", accel_group,
      GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);


gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), position);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu),cruc);
 

  gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), sep);
  gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
   
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
      G_CALLBACK(gtk_main_quit), NULL);
/*
g_signal_connect_swapped(G_OBJECT(window), "destroy",
      G_CALLBACK(expose_event_callback2), NULL); */

  g_signal_connect(G_OBJECT(quit), "activate",
      G_CALLBACK(gtk_main_quit), NULL);

g_signal_connect(G_OBJECT(position), "button_press_event",
      G_CALLBACK(expose_event_callback2), NULL);//NULL);

/*g_signal_connect(G_OBJECT(position), "clicked",
      G_CALLBACK(expose_event_callback2), G_OBJECT(window)); */
  gtk_widget_show_all(window);




  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (quit), NULL);

g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (position), NULL);

  /* Create the drawing area */

  drawing_area = gtk_drawing_area_new ();


  gtk_widget_set_size_request (GTK_WIDGET (drawing_area), 750, 480);


  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);


  gtk_widget_show (drawing_area);
//gtk_widget_show (drawing_area2);
  /* Signals used to handle backing pixmap */

  g_signal_connect (G_OBJECT (drawing_area), "expose_event",
          G_CALLBACK (expose_event), NULL);



  g_signal_connect (G_OBJECT (drawing_area),"configure_event",
          G_CALLBACK (configure_event), NULL);

  /* Event signals */

  g_signal_connect (G_OBJECT (drawing_area), "motion_notify_event",
          G_CALLBACK (motion_notify_event), NULL);

  g_signal_connect (G_OBJECT (drawing_area), "button_press_event",
          G_CALLBACK (button_press_event), NULL);

gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);

  gtk_widget_add_events (drawing_area, GDK_EXPOSURE_MASK
          | GDK_LEAVE_NOTIFY_MASK
          | GDK_BUTTON_PRESS_MASK
          | GDK_POINTER_MOTION_MASK
          | GDK_POINTER_MOTION_HINT_MASK);

/* Displaying the vehicle position */
/*
g_signal_connect(G_OBJECT(window), "configure-event",
        G_CALLBACK(vehicle_status), NULL); */



gtk_widget_show_all (GTK_WIDGET(window));
gtk_widget_show(vbox);

  gtk_main ();

  return 0;
}
added codebb -dreblen

There is a problem though hitting hmcposition calls expose_event_callback2 but only lasts for some seconds and then dissappears. The purpose of the code is to open a different page when a menu is hit. I have also tried using "activate" instead of "expose_even" but it just doesnt seem to work. Is there an alternative way of doing it or my approach is totally wrong?

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 7:55 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
I won't lock either topic, since they both can serve a purpose, but please pick either the current topic, or this one:
viewtopic.php?t=2596
to discuss the above piece of code.
Thank you...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group