changeset 2404:e909987593f2

Implement resizing.
author William Pitcock <nenolod@atheme.org>
date Mon, 18 Feb 2008 00:27:21 -0600
parents 3528a910a034
children 4f1dd5b277f6
files src/projectm-1.0/main.cxx
diffstat 1 files changed, 45 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/projectm-1.0/main.cxx	Mon Feb 18 00:15:40 2008 -0600
+++ b/src/projectm-1.0/main.cxx	Mon Feb 18 00:27:21 2008 -0600
@@ -56,6 +56,11 @@
       GdkEventExpose *event,
       gpointer        data);
 
+static gboolean
+projectM_reconfigure(GtkWidget         *widget,
+         GdkEventConfigure *event,
+         gpointer           data);
+
 class projectMPlugin
 {
   public:
@@ -68,6 +73,8 @@
     gboolean is_sync;
     gboolean error;
     gint idle_id;
+    GTimer *timer;
+    gint frames;
 
     projectMPlugin()
     {
@@ -96,10 +103,13 @@
         gtk_widget_add_events(this->drawing_area, GDK_VISIBILITY_NOTIFY_MASK);
         gtk_box_pack_start(GTK_BOX(this->vbox), this->drawing_area, TRUE, TRUE, 0);
 
-        g_signal_connect(G_OBJECT(this->drawing_area), "realize",
-                          G_CALLBACK(projectM_draw_init), NULL);
+        g_signal_connect_after(G_OBJECT(this->drawing_area), "realize",
+                         G_CALLBACK(projectM_draw_init), NULL);
         g_signal_connect(G_OBJECT(this->drawing_area), "expose_event",
-                          G_CALLBACK(projectM_draw_impl), NULL);
+                         G_CALLBACK(projectM_draw_impl), NULL);
+
+        this->timer = g_timer_new();
+        this->frames = 0;
     }
 
     ~projectMPlugin()
@@ -157,6 +167,28 @@
 
     gdk_gl_drawable_swap_buffers(gldrawable);
     gdk_gl_drawable_gl_end(gldrawable);
+
+    g_signal_connect(G_OBJECT(widget), "configure_event",
+                     G_CALLBACK(projectM_reconfigure), NULL);
+}
+
+static gboolean
+projectM_reconfigure(GtkWidget         *widget,
+      GdkEventConfigure *event,
+      gpointer           data)
+{
+    GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
+    GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);
+
+    if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
+        return FALSE;
+
+    thePlugin->pm->projectM_resetGL(widget->allocation.width, widget->allocation.height);
+
+    gdk_gl_drawable_swap_buffers(gldrawable);
+    gdk_gl_drawable_gl_end(gldrawable);
+
+    return TRUE;
 }
 
 static gboolean
@@ -171,10 +203,20 @@
         return FALSE;
 
     thePlugin->pm->renderFrame();
+    thePlugin->frames++;
 
     gdk_gl_drawable_swap_buffers(gldrawable);
     gdk_gl_drawable_gl_end(gldrawable);
 
+    gdouble seconds = g_timer_elapsed (thePlugin->timer, NULL);
+    if (seconds >= 5.0)
+    {
+        gdouble fps = thePlugin->frames / seconds;
+        g_print ("%d frames in %6.3f seconds = %6.3f FPS\n", thePlugin->frames, seconds, fps);
+        g_timer_reset (thePlugin->timer);
+        thePlugin->frames = 0;
+    }
+
     return TRUE;
 }
 
@@ -187,7 +229,6 @@
     return TRUE;
 }
 
-
 void handle_playback_trigger(gpointer plentry_p, gpointer unused)
 {
     PlaylistEntry *entry = reinterpret_cast<PlaylistEntry *>(plentry_p);