OSDN Git Service

draw efficiently, ThreadView
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 25 Dec 2007 17:38:17 +0000 (02:38 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 25 Dec 2007 17:38:17 +0000 (02:38 +0900)
src/FukuiNoNamari/thread_view.py

index 313b06c..46a2911 100644 (file)
@@ -504,13 +504,11 @@ class ThreadView(gtk.HBox):
 
         return self.button_pressed_pt, self.button_moving_pt
 
-    def draw_viewport(self):
+    def draw_viewport(self, area):
         view_y = self.vscrollbar.get_value()
         self.drawingarea.window.draw_rectangle(
             self.drawingarea.style.base_gc[0],
-            True, 0, 0,
-            self.drawingarea.allocation.width,
-            self.drawingarea.allocation.height)
+            True, area.x, area.y, area.width, area.height)
 
         selection_start, selection_end = self._get_selection_start_end()
 
@@ -524,8 +522,8 @@ class ThreadView(gtk.HBox):
             w, h = layout.get_pixel_size()
             layout_top = layout.posY
             layout_bottom = layout.posY + h
-            area_top = view_y
-            area_bottom = view_y + self.drawingarea.allocation.height
+            area_top = view_y + area.y
+            area_bottom = view_y + area.y + area.height
             if layout_top <= area_bottom and layout_bottom >= area_top:
                 layout.draw(self.drawingarea,
                             0, layout.posY - int(view_y),
@@ -633,7 +631,7 @@ class ThreadView(gtk.HBox):
         self.button_moving_pt = (layout, element, index)
 
     def on_drawingarea_expose_event(self, widget, event, data=None):
-        self.draw_viewport()
+        self.draw_viewport(event.area)
 
     def on_drawingarea_configure_event(self, widget, event, data=None):
         if event.width != self.drawingarea_prev_width:
@@ -680,7 +678,20 @@ class ThreadView(gtk.HBox):
             if (old_lay != new_lay
                 or old_elem != new_elem
                 or old_idx != new_idx):
-                self.drawingarea.queue_draw()
+                view_y = self.vscrollbar.get_value()
+                o_y = old_lay.posY
+                n_y = new_lay.posY
+                o_width, o_height = old_lay.get_pixel_size()
+                n_width, n_height = new_lay.get_pixel_size()
+
+                y = min(o_y, n_y)
+                height = max(o_y, n_y) - y
+                if o_y > n_y: height += o_height
+                else: height += n_height
+
+                y -= view_y
+
+                self.drawingarea.queue_draw_area(0, y, n_width, height+1)
                 #self.drawingarea.window.process_updates(False)
 
         cursor = ThreadView.regular_cursor