[giv] Removed redundant redrawns on autofit.



commit ad1280ca1e5d43c52ab6c587d34d0a99fe318a62
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Sun Apr 29 22:01:06 2012 +0300

    Removed redundant redrawns on autofit.

 src/giv-win.gob                         |   28 +++++++++++++++++-----------
 src/gtkimageviewer/gtk-image-viewer.gob |   13 ++++++++++++-
 2 files changed, 29 insertions(+), 12 deletions(-)
---
diff --git a/src/giv-win.gob b/src/giv-win.gob
index 5279806..27c5c1e 100644
--- a/src/giv-win.gob
+++ b/src/giv-win.gob
@@ -552,7 +552,8 @@ class Giv:Win from Gtk:Window
     private GLibJsonRpcServer *jsonrpc_server;
     private GLibJsonRpcAsyncQuery *json_query = NULL;
     private gboolean do_pick_coordinate = FALSE;
-    private gboolean do_fit_on_load_image_when_idle = FALSE;
+    private gboolean do_fit_on_load_image = FALSE;
+    private gdouble margin = 10;
 
     public GtkWidget *
     new (int argc, char *argv[])
@@ -805,6 +806,9 @@ class Giv:Win from Gtk:Window
                            selfp->w_scrolled_win, TRUE, TRUE, 0);
 
         selfp->w_imgv = giv_widget_new(NULL);
+        gtk_image_viewer_set_fill_on_resize_margin(GTK_IMAGE_VIEWER(selfp->w_imgv),
+                                                   selfp->margin);
+
         gtk_widget_show(selfp->w_imgv);
         g_signal_connect(selfp->w_imgv, "file-reference",
                          G_CALLBACK(cb_image_reference), self);
@@ -1003,7 +1007,7 @@ class Giv:Win from Gtk:Window
         }
 
         selfp->idle_index = selfp->filename_list_index;
-        selfp->do_fit_on_load_image_when_idle = TRUE;
+        selfp->do_fit_on_load_image = TRUE;
         selfp->idle_handle = g_idle_add(cb_load_image_when_idle,
                                         self);
 #if 0
@@ -1063,6 +1067,11 @@ class Giv:Win from Gtk:Window
         ((GivParser*)selfp->giv_parser)->parse_file(filename);
         selfp->quiver_scale = ((GivParser*)selfp->giv_parser)->get_quiver_scale();
 #endif
+        if (selfp->do_fit_on_load_image || selfp->do_auto_fit_marks) {
+            fit_marks_in_window(self);
+            selfp->do_fit_on_load_image = false;
+        }
+        
         giv_win_redraw(self);
         return 0;
     }
@@ -3534,7 +3543,7 @@ fit_marks_in_window(GivWin *self)
     printf("min_x min_y max_x max_y = %f %f %f %f\n",
            min_x, min_y, max_x, max_y);
 #endif
-    double margin = 0;
+    double margin = selfp->margin;
     
 #if 0
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(selfp->w_scrolled_win),
@@ -3549,6 +3558,7 @@ fit_marks_in_window(GivWin *self)
         min_x = min_y = 0;
         max_x = img_w;
         max_y = img_h;
+        margin = 0;
     }
     else {
         margin= 10;
@@ -3568,7 +3578,7 @@ fit_marks_in_window(GivWin *self)
             min_y = avg_y - aspect_ratio*0.5*(max_x-min_x);
             max_y = avg_y + aspect_ratio*0.5*(max_x-min_x);
         }
-        
+
         gtk_image_viewer_set_scroll_region(GTK_IMAGE_VIEWER(selfp->w_imgv),
                                            min_x, min_y,
                                            max_x, max_y);
@@ -3580,9 +3590,10 @@ fit_marks_in_window(GivWin *self)
     }
     
 #if 0
-    printf("min_x min_y max_x max_y = %f %f %f %f\n",
-           min_x, min_y, max_x, max_y);
+    printf("min_x min_y max_x max_y margin = %f %f %f %f %f\n",
+           min_x, min_y, max_x, max_y,1.0*margin);
 #endif
+
     gtk_image_viewer_zoom_to_box(GTK_IMAGE_VIEWER(selfp->w_imgv),
                                  min_x,
                                  min_y,
@@ -3804,11 +3815,6 @@ cb_load_image_when_idle(gpointer user_data)
     giv_win_set_current_file(self, selfp->idle_index);
     selfp->idle_handle = -1;
 
-    if (selfp->do_fit_on_load_image_when_idle) {
-        fit_marks_in_window(self);
-        selfp->do_fit_on_load_image_when_idle = FALSE;
-    }
-
     return false;
 }
 
diff --git a/src/gtkimageviewer/gtk-image-viewer.gob b/src/gtkimageviewer/gtk-image-viewer.gob
index 04b5671..c689ced 100644
--- a/src/gtkimageviewer/gtk-image-viewer.gob
+++ b/src/gtkimageviewer/gtk-image-viewer.gob
@@ -106,6 +106,7 @@ class Gtk:Image:Viewer from Gtk:Widget
   private gboolean do_flip_horizontal = FALSE;
   private gboolean do_use_transfer_map = FALSE;
   private gboolean do_fill_on_resize = TRUE;
+  private gint fill_on_resize_margin = 0;
   /* The one shot block is used by shrink wrapping to inhibit rescaling
      on resize. Is there a better way? */
   private gboolean one_shot_block_fill_on_resize = FALSE;
@@ -1677,6 +1678,13 @@ class Gtk:Image:Viewer from Gtk:Widget
   }
 
   public void
+  set_fill_on_resize_margin(self,
+                            gboolean margin)
+  {
+      selfp->fill_on_resize_margin = margin;
+  }
+
+  public void
   one_shot_block_fill_on_resize(self)
   {
       selfp->one_shot_block_fill_on_resize = TRUE;
@@ -1759,12 +1767,15 @@ class Gtk:Image:Viewer from Gtk:Widget
   public void
   zoom_fit(self)
   {
+    gdouble margin = 0;
+    if (!selfp->image)
+        margin = selfp->fill_on_resize_margin;
     gtk_image_viewer_zoom_to_box(self,
                                  selfp->scroll_min_x,
                                  selfp->scroll_min_y,
                                  selfp->scroll_max_x,
                                  selfp->scroll_max_y,
-                                 0,
+                                 margin,
                                  TRUE);
   }
 



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