[gtkglarea/jjardon/gtk3: 11/16] examples: In GTK+3 "expose_event" is now "draw" signal



commit 85da0b565cf07a98d812638fa662e0b5f8947327
Author: Javier Jardón <jjardon gnome org>
Date:   Mon Mar 24 18:32:46 2014 +0000

    examples: In GTK+3 "expose_event" is now "draw" signal

 examples/gtkglarea_demo.c |   22 ++++++++--------------
 examples/shaders.c        |   14 +++++---------
 examples/simple.c         |    8 ++------
 examples/viewlw.c         |   11 +++--------
 examples/zktor.c          |    8 ++------
 5 files changed, 20 insertions(+), 43 deletions(-)
---
diff --git a/examples/gtkglarea_demo.c b/examples/gtkglarea_demo.c
index db7a4fa..376efdd 100644
--- a/examples/gtkglarea_demo.c
+++ b/examples/gtkglarea_demo.c
@@ -51,7 +51,7 @@ GtkWidget* create_glarea         (void);
 gint       glarea_button_release (GtkWidget*, GdkEventButton*);
 gint       glarea_button_press   (GtkWidget*, GdkEventButton*);
 gint       glarea_motion_notify  (GtkWidget*, GdkEventMotion*);
-gint       glarea_draw           (GtkWidget*, GdkEventExpose*);
+gint       glarea_draw           (GtkWidget*, cairo_t*, gpointer);
 gint       glarea_reshape        (GtkWidget*, GdkEventConfigure*);
 gint       glarea_init           (GtkWidget*);
 gint       glarea_destroy        (GtkWidget*);
@@ -151,10 +151,10 @@ GtkWidget* create_glarea (void) {
   g_signal_connect (G_OBJECT(glarea), "motion-notify-event",
                     G_CALLBACK(glarea_motion_notify), NULL);
 
-  /* expose_event - The window was exposed and the contents   */
-  /*                need to be redrawn.                       */
+  /* draw - The window was exposed and the contents           */
+  /*        need to be redrawn.                               */
 
-  g_signal_connect (G_OBJECT(glarea), "expose-event",
+  g_signal_connect (G_OBJECT(glarea), "draw",
                     G_CALLBACK(glarea_draw), NULL);
 
   /* configure_event - The window has been resized. You will  */
@@ -299,22 +299,16 @@ gint glarea_motion_notify (GtkWidget* widget, GdkEventMotion* event) {
 
 /*****************************************************************************/
 /*                                                                           */
-/* Function: glarea_draw (GtkWidget*, GdkEventExpose*)                       */
+/* Function: glarea_draw (GtkWidget*, cairo_t *cr, gpointer user_data)       */
 /*                                                                           */
 /* This is the function that should render your scene to the GtkGLArea. It   */
-/* can be used as a callback to the 'Expose' event.                          */
+/* can be used as a callback to the 'draw' signal.                           */
 /*                                                                           */
 /*****************************************************************************/
 
-gint glarea_draw (GtkWidget* widget, GdkEventExpose* event) {
+gboolean glarea_draw (GtkWidget* widget, cairo_t *cr, gpointer user_data) {
 
-  /* Draw only on the last expose event. */
-
-  if (event->count > 0) {
-    return(TRUE);
-  }
-
-  g_print ("Expose Event\n");
+  g_print ("Draw Signal\n");
 
   /* gtk_gl_area_make_current MUST be called before rendering */
   /* into the GtkGLArea.                                      */
diff --git a/examples/shaders.c b/examples/shaders.c
index e376ee3..7ed7b48 100644
--- a/examples/shaders.c
+++ b/examples/shaders.c
@@ -41,7 +41,7 @@
 void       create_shader         (void);
 void       create_texture_2D     (void);
 GtkWidget* create_glarea         (void);
-gint       glarea_draw           (GtkWidget*, GdkEventExpose*);
+gint       glarea_draw           (GtkWidget*, cairo_t*, gpointer);
 gint       glarea_draw_scene     (void);
 gint       glarea_reshape        (GtkWidget*, GdkEventConfigure*);
 gint       glarea_init           (GtkWidget*);
@@ -245,7 +245,7 @@ GtkWidget* create_glarea (void) {
 
   gtk_widget_set_events(GTK_WIDGET(glarea), GDK_EXPOSURE_MASK);
 
-  g_signal_connect (G_OBJECT(glarea), "expose-event",
+  g_signal_connect (G_OBJECT(glarea), "draw",
                     G_CALLBACK(glarea_draw), NULL);
 
   g_signal_connect (G_OBJECT(glarea), "configure-event",
@@ -286,18 +286,14 @@ gint glarea_draw_scene (void) {
 
 /*****************************************************************************/
 /*                                                                           */
-/* Function: glarea_draw (GtkWidget*, GdkEventExpose*)                       */
+/* Function: glarea_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data)*/
 /*                                                                           */
 /* This is the function that should render your scene to the GtkGLArea. It   */
-/* can be used as a callback to the 'Expose' event.                          */
+/* can be used as a callback to the 'draw' signal.                           */
 /*                                                                           */
 /*****************************************************************************/
 
-gint glarea_draw (GtkWidget* widget, GdkEventExpose* event) {
-
-  if (event->count > 0) {
-    return(TRUE);
-  }
+gboolean glarea_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data) {
 
   if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) {
 
diff --git a/examples/simple.c b/examples/simple.c
index 4c1081c..ff08266 100644
--- a/examples/simple.c
+++ b/examples/simple.c
@@ -40,12 +40,8 @@ gint init(GtkWidget *widget)
 
 
 /* When widget is exposed it's contents are redrawn. */
-gint draw(GtkWidget *widget, GdkEventExpose *event)
+gboolean draw (GtkWidget *widget, cairo_t *cr, gpointer data)
 {
-  /* Draw only last expose. */
-  if (event->count > 0)
-    return TRUE;
-
   /* OpenGL functions can be called only if make_current returns true */
   if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     {
@@ -131,7 +127,7 @@ int main(int argc, char **argv)
 
   /* Connect signal handlers */
   /* Redraw image when exposed. */
-  g_signal_connect(G_OBJECT(glarea), "expose-event",
+  g_signal_connect(G_OBJECT(glarea), "draw",
                    G_CALLBACK(draw), NULL);
   /* When window is resized viewport needs to be resized also. */
   g_signal_connect(G_OBJECT(glarea), "configure-event",
diff --git a/examples/viewlw.c b/examples/viewlw.c
index 2d98e7c..f3862ab 100644
--- a/examples/viewlw.c
+++ b/examples/viewlw.c
@@ -93,18 +93,13 @@ void initgl(void)
   glEnable(GL_COLOR_MATERIAL);
 }
 
-gint glarea_expose(GtkWidget *widget, GdkEventExpose *event)
+gboolean glarea_draw (GtkWidget *widget, cairo_t *cr, gpointer user_data)
 {
   GLfloat m[4][4];
 
   GtkGLArea *glarea = GTK_GL_AREA(widget);
   mesh_info *info = (mesh_info*) g_object_get_data (G_OBJECT (widget), "mesh_info");
 
-  /* draw only last expose */
-  if (event->count > 0) {
-    return TRUE;
-  }
-
   /* OpenGL calls can be done only if make_current returns true */
   if (gtk_gl_area_make_current(glarea)) {
     /* basic initialization */
@@ -324,8 +319,8 @@ gint show_lwobject(char const *lwobject_name)
                        GDK_BUTTON_RELEASE_MASK|
                        GDK_POINTER_MOTION_MASK|
                        GDK_POINTER_MOTION_HINT_MASK);
-  g_signal_connect (G_OBJECT(glarea), "expose-event",
-                    G_CALLBACK(glarea_expose), NULL);
+  g_signal_connect (G_OBJECT(glarea), "draw",
+                    G_CALLBACK(glarea_draw), NULL);
   g_signal_connect (G_OBJECT(glarea), "motion-notify-event",
                     G_CALLBACK(glarea_motion_notify), NULL);
   g_signal_connect (G_OBJECT(glarea), "button-press-event",
diff --git a/examples/zktor.c b/examples/zktor.c
index c313a0d..9e87c43 100644
--- a/examples/zktor.c
+++ b/examples/zktor.c
@@ -749,12 +749,8 @@ gint init(GtkWidget *widget)
 
 
 /* When widget is exposed it's contents are redrawn. */
-gint draw(GtkWidget *widget, GdkEventExpose *event)
+gboolean  draw (GtkWidget *widget, cairo_t *cr, gpointer user_data)
 {
-  /* Draw only last expose. */
-  if (event->count > 0)
-    return TRUE;
-
   if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     game_render();
 
@@ -911,7 +907,7 @@ int main(int argc, char **argv)
 
   /* Connect signal handlers */
   /* Redraw image when exposed. */
-  g_signal_connect(G_OBJECT(glarea), "expose-event",
+  g_signal_connect(G_OBJECT(glarea), "draw",
                    G_CALLBACK(draw), NULL);
   /* When window is resized viewport needs to be resized also. */
   g_signal_connect(G_OBJECT(glarea), "configure-event",


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