Changeset 884

Show
Ignore:
Timestamp:
05/16/06 00:21:52 (3 years ago)
Author:
arjanmol
Message:

all bb calc. in idle handler.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gaphas/ChangeLog

    r882 r884  
     12006-05-16  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
     2 
     3        * painter.py: separate BoundingBoxPainter, for calcing bb's. 
     4        * view.py: No more bounding box calculation in do_expose_event() 
     5 
    162006-05-15  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    27 
    3         * decorators.py: moved nonrecursive to this file. added async 
    4         decorator. 
    5         * canvas.py, view.py: do canvas updates in @async method. 
     8       * decorators.py: moved nonrecursive to this file. added async 
     9       decorator. 
     10       * canvas.py, view.py: do canvas updates in @async method. 
    611 
    7122006-05-11  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
     
    17222006-05-09  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    1823 
    19         * demo.py: connection protocol partly works. 
    20         * constraint.py, solver.py: redone constraints, added new constraint 
    21         types. 
     24       * demo.py: connection protocol partly works. 
     25       * constraint.py, solver.py: redone constraints, added new constraint 
     26       types. 
    2227 
    23282006-05-02  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    2429 
    25         * tool.py: made CTRL work (select/deselect) 
    26         * demo.py: added example glue implementation 
     30       * tool.py: made CTRL work (select/deselect) 
     31       * demo.py: added example glue implementation 
    2732 
    28332006-05-01  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    2934 
    30         * tool.py, painter.py, view.py: show handles for hovered item. 
     35       * tool.py, painter.py, view.py: show handles for hovered item. 
    3136 
    32372006-04-28  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    3338 
    34         * view.py, demo.py: demonstrate multi-view modus of the canvas. 
    35         * constraint.py: added few simple constraint types 
    36         * solver.py, constraint.py: defined Constraint protocol. 
     39       * view.py, demo.py: demonstrate multi-view modus of the canvas. 
     40       * constraint.py: added few simple constraint types 
     41       * solver.py, constraint.py: defined Constraint protocol. 
    3742        * tool.py, demo.py: PlacementTool. the first button press on the test 
    3843        canvas will place a Box element on the canvas. 
    39         * demo.py: added some buttons. 
     44       * demo.py: added some buttons. 
    4045 
    41462006-04-24  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    4247 
    43         * item.py: Added Line item. 
    44         * pylintrc: new file. 
     48       * item.py: Added Line item. 
     49       * pylintrc: new file. 
    4550 
    46512006-04-21  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
     
    4853        * painter.py: moved drawing code out of the view, into special 
    4954        Painters. 
    50         * cleaned up code with pylint 
     55       * cleaned up code with pylint 
    5156 
    52572006-04-20  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    5358 
    54         * tool.py: added runnerband selection tool. 
     59       * tool.py: added runnerband selection tool. 
    5560 
    56612006-04-18  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    5762 
    58         * demo.py: moved demo code from view.py to demo.py 
     63       * demo.py: moved demo code from view.py to demo.py 
    5964        * view.py: implemented adjustment objects (for scrollbars). 1st attempt. 
    6065        * view.py, tool.py: use a context in stead of view directly. 
  • trunk/gaphas/painter.py

    r879 r884  
    6363        self.painter._draw_items(self.children, 
    6464                                 self.view, 
    65                                  self.cairo, 
    66                                  self.update_bounds) 
     65                                 self.cairo) 
    6766 
    6867 
    6968class ItemPainter(Painter): 
    7069 
    71     def _draw_items(self, items, view, cairo, update_bounds): 
    72         """Draw the items. This method can also be called from DrawContext 
    73         to draw sub-items. 
    74         """ 
    75         for item in items: 
     70    def _draw_item(self, item, view, cairo): 
    7671            cairo.save() 
    7772            try: 
     
    7974                cairo.transform(view.canvas.get_matrix_i2w(item)) 
    8075 
    81                 if update_bounds: 
    82                     the_context = view.wrap_cairo_context(cairo) 
    83                 else: 
    84                     # No wrapper: 
    85                     the_context = cairo 
    86  
    8776                item.draw(DrawContext(painter=self, 
    88                                       update_bounds=update_bounds, 
    8977                                      view=view, 
    90                                       cairo=the_context
     78                                      cairo=cairo
    9179                                      parent=view.canvas.get_parent(item), 
    9280                                      children=view.canvas.get_children(item), 
     
    9482                                      focused=(item is view.focused_item), 
    9583                                      hovered=(item is view.hovered_item))) 
    96  
    97                 if update_bounds: 
    98                     view.set_item_bounding_box(item, the_context.get_bounds()) 
    9984 
    10085                if DEBUG_DRAW_BOUNDING_BOX: 
     
    11095                cairo.restore() 
    11196 
     97    def _draw_items(self, items, view, cairo): 
     98        """Draw the items. This method can also be called from DrawContext 
     99        to draw sub-items. 
     100        """ 
     101        for item in items: 
     102            self._draw_item(item, view, cairo) 
     103 
    112104    def paint(self, context): 
    113105        cairo = context.cairo 
    114106        view = context.view 
    115107        items = view.canvas.get_root_items() 
    116         update_bounds = context.update_bounds 
    117         self._draw_items(items, view, cairo, update_bounds) 
     108        self._draw_items(items, view, cairo) 
     109 
     110 
     111class BoundingBoxPainter(ItemPainter): 
     112    """This specific case of an ItemPainter is used to calculate the bounding 
     113    boxes for the items. 
     114    """ 
     115 
     116    def _draw_items(self, items, view, cairo): 
     117        """Draw the items. This method can also be called from DrawContext 
     118        to draw sub-items. 
     119        """ 
     120        for item in items: 
     121            context = view.wrap_cairo_context(cairo) 
     122            self._draw_item(item, view, context) 
     123            view.set_item_bounding_box(item, context.get_bounds()) 
     124 
     125    def paint(self, context): 
     126        cairo = context.cairo 
     127        view = context.view 
     128        #items = context.items 
     129        items = view.canvas.get_root_items() 
     130        self._draw_items(items, view, cairo) 
    118131 
    119132 
  • trunk/gaphas/view.py

    r882 r884  
    1616from geometry import Rectangle 
    1717from tool import DefaultTool 
    18 from painter import DefaultPainter 
     18from painter import DefaultPainter, BoundingBoxPainter 
    1919from decorators import async, PRIORITY_HIGH_IDLE 
    2020from decorators import nonrecursive 
     
    157157        self._tool = DefaultTool() 
    158158        self._painter = DefaultPainter() 
    159         self._calculate_bounding_box = False 
    160159 
    161160    matrix = property(lambda s: s._matrix) 
     
    300299 
    301300        # Make sure everything's updated 
    302         self._calculate_bounding_box = True 
     301        self.request_update(self.canvas.get_all_items()) 
    303302        a = self.allocation 
    304303        super(View, self).queue_draw_area(0, 0, a.width, a.height) 
     
    397396        """Wrap draw_area to convert all values to ints. 
    398397        """ 
    399         #if self._canvas: 
    400         #    for view in self._canvas._view_views: 
    401         #        super(View, view).queue_draw_area(int(x), int(y), 
    402         #                                          int(w+1), int(h+1)) 
    403         #else: 
    404398        super(View, self).queue_draw_area(int(x), int(y), int(w+1), int(h+1)) 
    405399 
     
    416410        """Get the bounding box for the item, in canvas coordinates. 
    417411        """ 
    418         try: 
    419             return self._item_bounds[item] 
    420         except KeyError, e: 
    421             self._calculate_bounding_box = True 
    422             a = self.allocation 
    423             super(View, self).queue_draw_area(a.x, a.y, a.width, a.height) 
    424             raise e 
     412        return self._item_bounds[item] 
    425413 
    426414    def wrap_cairo_context(self, cairo): 
     
    432420 
    433421    @async(single=False, priority=PRIORITY_HIGH_IDLE) 
     422    #@nonrecursive 
    434423    def request_update(self, items): 
    435424        """Update view status according to the items updated by the canvas. 
    436425        """ 
     426        if not self.window: return True 
     427 
    437428        with_handles = set(self._selected_items) 
    438429        with_handles.add(self._hovered_item) 
    439430        with_handles.add(self._focused_item) 
    440431 
    441         for i in items: 
     432        for i in items: 
    442433            self.queue_draw_item(i, handles=(i in with_handles)) 
    443434 
    444         # TODO: pseudo-draw 
    445         self._calculate_bounding_box = True 
     435        # Pseudo-draw 
    446436        context = self.window.cairo_create() 
    447437        context.rectangle(0,0,0,0) 
    448438        context.clip() 
    449439 
    450         self._painter.paint(Context(view=self, 
    451                                     cairo=context, 
    452                                     update_bounds=self._calculate_bounding_box)) 
    453         #self.queue_draw_item(*items) 
    454         for i in  items: 
     440        self._item_bounds = dict() 
     441        self._bounds = Rectangle() 
     442 
     443        painter = BoundingBoxPainter() 
     444        painter.paint(Context(view=self, 
     445                              cairo=context)) 
     446 
     447        for i in items: 
    455448            self.queue_draw_item(i, handles=(i in with_handles)) 
    456449 
    457         #self.update_adjustments() 
    458         #self._calculate_bounding_box = False 
     450        self.update_adjustments() 
    459451 
    460452    @nonrecursive 
     
    473465            return 
    474466 
    475         # Set this to some idle function 
    476         #if self._canvas.require_update(): 
    477         #    self._canvas.update_now() 
    478         #    self._calculate_bounding_box = True 
    479  
    480467        area = event.area 
    481468        self.window.draw_rectangle(self.style.white_gc, True, 
     
    485472        context = self.window.cairo_create() 
    486473 
    487         if self._calculate_bounding_box: 
    488             self._item_bounds = dict() 
    489             self._bounds = Rectangle() 
    490  
    491474        # Draw no more than nessesary. 
    492475        context.rectangle(area.x, area.y, area.width, area.height) 
     
    494477 
    495478        self._painter.paint(Context(view=self, 
    496                                     cairo=context, 
    497                                     update_bounds=self._calculate_bounding_box)) 
     479                                    cairo=context)) 
    498480 
    499481        if DEBUG_DRAW_BOUNDING_BOX: 
     
    507489            context.restore() 
    508490 
    509         if self._calculate_bounding_box: 
    510             self.update_adjustments() 
    511         self._calculate_bounding_box = False 
    512491        return False 
    513492 
     
    530509 
    531510        # Force recalculation of the bounding boxes: 
    532         self._calculate_bounding_box = True 
     511        self.request_update(self.canvas.get_all_items()) 
    533512 
    534513        a = self.allocation