draw a border around main view with current label
authorgc <gc>
Mon, 23 Jul 2007 20:35:52 +0000 (20:35 +0000)
committergc <gc>
Mon, 23 Jul 2007 20:35:52 +0000 (20:35 +0000)
bin/booh-classifier

index 4720476442920a105f310a6a1d122f97f6dc5ebd..c9aad3ffd2d1e98c3efb0169a1a865553a666526 100644 (file)
@@ -210,6 +210,7 @@ class Gdk::Color
     end
 end
 
+$color_red = Gdk::Color.new(65535, 0, 0)
 $colors = [ Gdk::Color.new(0, 65535, 0),
             Gdk::Color.new(0, 0, 65535),
             Gdk::Color.new(65535, 65535, 0),
@@ -320,20 +321,25 @@ class Entry
         }
     end
 
-    def show_bg
+    def outline_color
         if removed
-            red = Gdk::Color.new(65535, 0, 0)
-            button.modify_bg(Gtk::StateType::NORMAL, red)
-            button.modify_bg(Gtk::StateType::PRELIGHT, red.lighter)
-            button.modify_bg(Gtk::StateType::ACTIVE, red)
+            return $color_red
         elsif labeled
-            button.modify_bg(Gtk::StateType::NORMAL, labeled.color)
-            button.modify_bg(Gtk::StateType::PRELIGHT, labeled.color.lighter)
-            button.modify_bg(Gtk::StateType::ACTIVE, labeled.color)
+            return labeled.color
         else
+            return nil
+        end
+    end
+
+    def show_bg
+        if outline_color.nil?
             button.modify_bg(Gtk::StateType::NORMAL, nil)
             button.modify_bg(Gtk::StateType::PRELIGHT, nil)
             button.modify_bg(Gtk::StateType::ACTIVE, nil)
+        else
+            button.modify_bg(Gtk::StateType::NORMAL, outline_color)
+            button.modify_bg(Gtk::StateType::PRELIGHT, outline_color.lighter)
+            button.modify_bg(Gtk::StateType::ACTIVE, outline_color)
         end
     end
 
@@ -395,6 +401,17 @@ end
 
 class MainView < Gtk::DrawingArea
 
+    @@borders_thickness = 5
+    @@borders_length = 25
+
+    def MainView.get_usable_width(available_width)
+        return available_width - ($videoborder_pixbuf.width + @@borders_thickness) * 2
+    end
+
+    def MainView.get_usable_height(available_height)
+        return available_height - @@borders_thickness * 2
+    end
+    
     def initialize
         super()
         signal_connect('expose-event') { draw }
@@ -407,7 +424,8 @@ class MainView < Gtk::DrawingArea
                     if ! @entry.nil?
                         index = $allentries.index(@entry)
                         w, h = window.size
-                        w -= $videoborder_pixbuf.width * 2
+                        w = MainView.get_usable_width(w)
+                        h = MainView.get_usable_height(h)
                         for j in 1 .. $config['preload-distance'].to_i
                             i = index + j
                             if i < $allentries.size
@@ -473,15 +491,11 @@ class MainView < Gtk::DrawingArea
     def update_shown
         if @entry
             width, height = window.size 
-            usable_width = width - $videoborder_pixbuf.width * 2
-            @pixbuf = @entry.pixbuf_main(usable_width, height)
-            if @pixbuf.width == usable_width
-                @xpos = $videoborder_pixbuf.width
-                @ypos = (height-@pixbuf.height)/2
-            else
-                @xpos = (width-@pixbuf.width)/2
-                @ypos = (height-@pixbuf.height)/2
-            end
+            usable_width = MainView.get_usable_width(width)
+            usable_height = MainView.get_usable_height(height)
+            @pixbuf = @entry.pixbuf_main(usable_width, usable_height)
+            @xpos = (width - @pixbuf.width)/2
+            @ypos = (height - @pixbuf.height)/2
             @preloader.run
         else
             @pixbuf = nil
@@ -494,6 +508,21 @@ class MainView < Gtk::DrawingArea
             if @entry && @entry.type == 'video'
                 window.draw_borders($videoborder_pixbuf, @xpos - $videoborder_pixbuf.width, @xpos + @pixbuf.width, @ypos, @ypos + @pixbuf.height)
             end
+            if ! @entry.outline_color.nil?
+                gc = Gdk::GC.new(window)
+                colormap.alloc_color(@entry.outline_color, false, true)
+                gc.set_foreground(@entry.outline_color)
+                window.draw_polygon(gc, true, [[@xpos - @@borders_thickness, @ypos - @@borders_thickness],
+                                               [@xpos + @pixbuf.width + @@borders_thickness, @ypos - @@borders_thickness],
+                                               [@xpos + @pixbuf.width + @@borders_thickness, @ypos + @pixbuf.height + @@borders_thickness],
+                                               [@xpos - @@borders_thickness, @ypos + @pixbuf.height + @@borders_thickness],
+                                               [@xpos - @@borders_thickness, @ypos - 1],
+                                               [@xpos - 1, @ypos - 1],
+                                               [@xpos - 1, @ypos + @pixbuf.height + 1],
+                                               [@xpos + @pixbuf.width + 1, @ypos + @pixbuf.height + 1],
+                                               [@xpos + @pixbuf.width + 1, @ypos - 1],
+                                               [@xpos - @@borders_thickness, @ypos - 1]])
+            end
         end
     end
 end