[gimp] plug-ins: separate preview computation from drawing in map-object



commit 9912e3f4eeede5182c2c5edadbf8fce75c1bf2f5
Author: Michael Natterer <mitch gimp org>
Date:   Sun Feb 13 14:12:08 2011 +0100

    plug-ins: separate preview computation from drawing in map-object

 plug-ins/map-object/map-object-preview.c |   60 +++++++++++++++++------------
 plug-ins/map-object/map-object-preview.h |    9 +---
 plug-ins/map-object/map-object-ui.c      |   32 +++++++++++----
 3 files changed, 60 insertions(+), 41 deletions(-)
---
diff --git a/plug-ins/map-object/map-object-preview.c b/plug-ins/map-object/map-object-preview.c
index b2c2ebe..7d39342 100644
--- a/plug-ins/map-object/map-object-preview.c
+++ b/plug-ins/map-object/map-object-preview.c
@@ -32,8 +32,14 @@ static BackBuffer backbuf = { 0, 0, 0, 0, NULL };
 /* Protos */
 /* ====== */
 
-static void draw_light_marker       (gint        xpos,
-				     gint        ypos);
+static void compute_preview         (gint x,
+                                     gint y,
+                                     gint w,
+                                     gint h,
+                                     gint pw,
+                                     gint ph);
+static void draw_light_marker       (gint xpos,
+				     gint ypos);
 static void clear_light_marker      (void);
 
 /**************************************************************/
@@ -41,7 +47,7 @@ static void clear_light_marker      (void);
 /* dimensions (w,h), placing the result in preview_RGB_data.  */
 /**************************************************************/
 
-void
+static void
 compute_preview (gint x,
 		 gint y,
 		 gint w,
@@ -330,7 +336,32 @@ update_light (gint xpos,
 /******************************************************************/
 
 void
-draw_preview_image (gint docompute)
+compute_preview_image (void)
+{
+  GdkDisplay *display = gtk_widget_get_display (previewarea);
+  GdkCursor  *cursor;
+  gint       startx, starty, pw, ph;
+
+  pw = PREVIEW_WIDTH * mapvals.zoom;
+  ph = PREVIEW_HEIGHT * mapvals.zoom;
+  startx = (PREVIEW_WIDTH - pw) / 2;
+  starty = (PREVIEW_HEIGHT - ph) / 2;
+
+  cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
+  gdk_window_set_cursor (gtk_widget_get_window (previewarea), cursor);
+  gdk_cursor_unref (cursor);
+
+  compute_preview (0, 0, width - 1, height - 1, pw, ph);
+
+  cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
+  gdk_window_set_cursor(gtk_widget_get_window (previewarea), cursor);
+  gdk_cursor_unref (cursor);
+
+  clear_light_marker ();
+}
+
+void
+draw_preview_image (void)
 {
   gint startx, starty, pw, ph;
   GdkColor  color;
@@ -348,27 +379,6 @@ draw_preview_image (gint docompute)
   startx = (PREVIEW_WIDTH - pw) / 2;
   starty = (PREVIEW_HEIGHT - ph) / 2;
 
-  if (docompute == TRUE)
-    {
-      GdkDisplay *display = gtk_widget_get_display (previewarea);
-      GdkCursor  *cursor;
-
-      cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
-      gdk_window_set_cursor (gtk_widget_get_window (previewarea), cursor);
-      gdk_cursor_unref (cursor);
-
-      compute_preview (0, 0, width - 1, height - 1, pw, ph);
-
-      cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
-      gdk_window_set_cursor(gtk_widget_get_window (previewarea), cursor);
-      gdk_cursor_unref (cursor);
-
-      clear_light_marker ();
-    }
-
-  if (pw != PREVIEW_WIDTH || ph != PREVIEW_HEIGHT)
-    gdk_window_clear (gtk_widget_get_window (previewarea));
-
   cairo_set_source_surface (cr, preview_surface, startx, starty);
   cairo_rectangle (cr, startx, starty, pw, ph);
   cairo_clip (cr);
diff --git a/plug-ins/map-object/map-object-preview.h b/plug-ins/map-object/map-object-preview.h
index ccf90e1..46d4e25 100644
--- a/plug-ins/map-object/map-object-preview.h
+++ b/plug-ins/map-object/map-object-preview.h
@@ -13,13 +13,8 @@ extern gint       lightx,lighty;
 /* Externally visible functions */
 /* ============================ */
 
-void compute_preview        (gint x,
-			     gint y,
-			     gint w,
-			     gint h,
-			     gint pw,
-			     gint ph);
-void draw_preview_image     (gint docompute);
+void compute_preview_image  (void);
+void draw_preview_image     (void);
 gint check_light_hit        (gint xpos,
 			     gint ypos);
 void update_light           (gint xpos,
diff --git a/plug-ins/map-object/map-object-ui.c b/plug-ins/map-object/map-object-ui.c
index 35054f3..d07c829 100644
--- a/plug-ins/map-object/map-object-ui.c
+++ b/plug-ins/map-object/map-object-ui.c
@@ -80,7 +80,9 @@ double_adjustment_update (GtkAdjustment *adjustment,
   gimp_double_adjustment_update (adjustment, data);
 
   if (mapvals.livepreview)
-    draw_preview_image (TRUE);
+    compute_preview_image ();
+
+  gtk_widget_queue_draw (previewarea);
 }
 
 static void
@@ -124,7 +126,8 @@ toggle_update (GtkWidget *widget,
 {
   gimp_toggle_button_update (widget, data);
 
-  draw_preview_image (TRUE);
+  compute_preview_image ();
+  gtk_widget_queue_draw (previewarea);
 }
 
 /*****************************************/
@@ -154,7 +157,9 @@ lightmenu_callback (GtkWidget *widget,
     }
 
   if (mapvals.livepreview)
-    draw_preview_image (TRUE);
+    compute_preview_image ();
+
+  gtk_widget_queue_draw (previewarea);
 }
 
 /***************************************/
@@ -170,7 +175,9 @@ mapmenu_callback (GtkWidget *widget,
 
   gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) data);
 
-  draw_preview_image (TRUE);
+  compute_preview_image ();
+
+  gtk_widget_queue_draw (previewarea);
 
   children = gtk_container_get_children (GTK_CONTAINER (options_note_book));
   n_children = g_list_length (children);
@@ -234,7 +241,9 @@ static void
 preview_callback (GtkWidget *widget,
 		  gpointer   data)
 {
-  draw_preview_image (TRUE);
+  compute_preview_image ();
+
+  gtk_widget_queue_draw (previewarea);
 }
 
 static void
@@ -242,7 +251,9 @@ zoomed_callback (GimpZoomModel *model)
 {
   mapvals.zoom = gimp_zoom_model_get_factor (model);
 
-  draw_preview_image (TRUE);
+  compute_preview_image ();
+
+  gtk_widget_queue_draw (previewarea);
 }
 
 /**********************************************/
@@ -289,7 +300,7 @@ preview_events (GtkWidget *area,
   switch (event->type)
     {
       case GDK_EXPOSE:
-        draw_preview_image (FALSE);
+        draw_preview_image ();
         break;
 
       case GDK_ENTER_NOTIFY:
@@ -315,7 +326,9 @@ preview_events (GtkWidget *area,
       case GDK_BUTTON_RELEASE:
         if (light_hit == TRUE)
 	  {
-	    draw_preview_image (TRUE);
+            compute_preview_image ();
+
+	    gtk_widget_queue_draw (previewarea);
 	  }
         else
           {
@@ -1360,7 +1373,8 @@ main_dialog (GimpDrawable *drawable)
   }
 
   image_setup (drawable, TRUE);
-  draw_preview_image (TRUE);
+
+  compute_preview_image ();
 
   if (gimp_dialog_run (GIMP_DIALOG (appwin)) == GTK_RESPONSE_OK)
     run = TRUE;



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