OSDN Git Service

Refactoring drawing iteration in ThreadView.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 1 May 2009 15:34:20 +0000 (00:34 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Fri, 1 May 2009 15:34:20 +0000 (00:34 +0900)
src/FukuiNoNamari/thread_view.py

index a6ff9cd..ebecefe 100644 (file)
@@ -20,6 +20,7 @@ pygtk.require('2.0')
 import gtk
 import pango
 import gobject
+import itertools
 from FukuiNoNamariExt import thread_view_extend
 
 
@@ -664,26 +665,18 @@ class ThreadView(gtk.HBox):
 
         selection_start, selection_end = self._get_selection_start_end()
 
-
         top_layout = self.get_layout_on_y(view_y)
-        index = 0
-        if top_layout:
-            index = top_layout.list_index
-        while index < len(self.res_layout_list):
-            layout = self.res_layout_list[index]
-            w, h = layout.get_pixel_size()
-            layout_top = layout.posY
-            layout_bottom = layout.posY + h
-            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),
-                            selection_start, selection_end)
-            if layout_top > area_bottom:
-                break
-
-            index += 1
+        if top_layout is None:
+            return
+        #area_top = view_y + area.y
+        area_bottom = view_y + area.y + area.height
+
+        iter = range(top_layout.list_index, len(self.res_layout_list))
+        iter = itertools.imap(lambda index: self.res_layout_list[index], iter)
+        iter = itertools.takewhile(lambda lay: lay.posY <= area_bottom, iter)
+        for layout in iter:
+            layout.draw(self.drawingarea, 0, layout.posY - int(view_y),
+                selection_start, selection_end)
 
     def transform_coordinate_gdk_to_adj(self, y):
         return y + self.vscrollbar.get_value()