have autoscrolling
authorgc <gc>
Sun, 8 Jul 2007 14:38:07 +0000 (14:38 +0000)
committergc <gc>
Sun, 8 Jul 2007 14:38:07 +0000 (14:38 +0000)
bin/booh-classifier

index 63589f8a2b944ff66fb59acb318b32ef00cc5796..068a8f222ab85912bb42820aea00e3b3e5a0f075 100644 (file)
@@ -380,22 +380,6 @@ class MainView < Gtk::DrawingArea
 
 end
 
-def autoscroll_if_needed(img)
-    xpos_left = img.window.position[0]
-    xpos_right = img.window.position[0] + img.window.size[0]
-    current_minx_visible = $imagesline_sw.hadjustment.value
-    current_maxx_visible = $imagesline_sw.hadjustment.value + $imagesline_sw.hadjustment.page_size
-#    puts "xpos left: #{xpos_left}"
-#    puts "xpos right: #{xpos_right}"
-#    puts "current minx visible: #{current_minx_visible}"
-#    puts "current maxx visible: #{current_maxx_visible}"
-    if xpos_left < current_minx_visible
-        puts 'scroll_upper(scrolledwindow, ypos_top)'
-    elsif xpos_right > current_maxx_visible
-        puts 'scroll_lower(scrolledwindow, ypos_bottom)'
-    end
-end
-
 def check_memory_free_cache_if_needed
     GC.start
     mem = get_mem
@@ -423,6 +407,30 @@ def check_memory_free_cache_if_needed
     }
 end
 
+def autoscroll_if_needed(button)
+    xpos_left = button.event_window.position[0]
+    xpos_right = button.event_window.position[0] + button.event_window.size[0]
+    hadj = $imagesline_sw.hadjustment
+    current_minx_visible = hadj.value
+    current_maxx_visible = hadj.value + hadj.page_size
+    if xpos_left < current_minx_visible
+        #- autoscroll left
+        newval = hadj.value -
+            ((hadj.value - xpos_left - 1) / hadj.step_increment + 1) * hadj.step_increment
+        hadj.value = newval
+        button.queue_draw  #- TOREMOVE: the visual focus is displayed incorrectly
+    elsif xpos_right > current_maxx_visible
+        #- autoscroll right
+        newval = hadj.value +
+            ((xpos_right - (hadj.value + hadj.page_size) - 1) / hadj.step_increment + 1) * hadj.step_increment
+        if newval > hadj.upper - hadj.page_size
+            newval = hadj.upper - hadj.page_size
+        end
+        hadj.value = newval
+        button.queue_draw  #- TOREMOVE: the visual focus is displayed incorrectly
+    end
+end
+
 def show_entries
     e = Thread.new {
         t1 = Time.now
@@ -435,11 +443,11 @@ def show_entries
                 entry.pixbuf_thumbnail
                 gtk_thread_protect(proc { |i|
                                        entry = $allentries[i]
-                                       entry.button = Gtk::Button.new.set_image(img = Gtk::Image.new(entry.pixbuf_thumbnail)).show_all
+                                       entry.button = Gtk::Button.new.set_image(img = Gtk::Image.new(entry.pixbuf_thumbnail))
                                        tooltips.set_tip(entry.button, File.basename(entry.path).gsub(/\.[^.]+$/, ''), nil)
-                                       $imagesline.pack_start(entry.button, false, false)
+                                       $imagesline.pack_start(entry.button.show_all, false, false)
                                        entry.button.signal_connect('clicked') { $mainview.set_shown_entry(i) }
-                                       entry.button.signal_connect('focus-in-event') { entry.button.clicked; autoscroll_if_needed(img) }
+                                       entry.button.signal_connect('focus-in-event') { entry.button.clicked; autoscroll_if_needed(entry.button) }
                                        if i == 0
                                            entry.button.grab_focus
                                        end
@@ -479,8 +487,7 @@ def open_dir(path)
         end
         Dir.entries(dir).each { |file|
             type = entry2type(file)
-            if type
-#&& $allentries.size < 8
+            if type && $allentries.size < 5
                 $allentries << Entry.new(File.join(dir, file), type)
             end
         }