Changeset 884
- Timestamp:
- 05/16/06 00:21:52 (3 years ago)
- Files:
-
- trunk/gaphas/ChangeLog (modified) (3 diffs)
- trunk/gaphas/painter.py (modified) (4 diffs)
- trunk/gaphas/view.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gaphas/ChangeLog
r882 r884 1 2006-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 1 6 2006-05-15 Arjan Molenaar <arjan_at_yirdis_dot_nl> 2 7 3 * decorators.py: moved nonrecursive to this file. added async4 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. 6 11 7 12 2006-05-11 Arjan Molenaar <arjan_at_yirdis_dot_nl> … … 17 22 2006-05-09 Arjan Molenaar <arjan_at_yirdis_dot_nl> 18 23 19 * demo.py: connection protocol partly works.20 * constraint.py, solver.py: redone constraints, added new constraint21 types.24 * demo.py: connection protocol partly works. 25 * constraint.py, solver.py: redone constraints, added new constraint 26 types. 22 27 23 28 2006-05-02 Arjan Molenaar <arjan_at_yirdis_dot_nl> 24 29 25 * tool.py: made CTRL work (select/deselect)26 * demo.py: added example glue implementation30 * tool.py: made CTRL work (select/deselect) 31 * demo.py: added example glue implementation 27 32 28 33 2006-05-01 Arjan Molenaar <arjan_at_yirdis_dot_nl> 29 34 30 * tool.py, painter.py, view.py: show handles for hovered item.35 * tool.py, painter.py, view.py: show handles for hovered item. 31 36 32 37 2006-04-28 Arjan Molenaar <arjan_at_yirdis_dot_nl> 33 38 34 * view.py, demo.py: demonstrate multi-view modus of the canvas.35 * constraint.py: added few simple constraint types36 * 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. 37 42 * tool.py, demo.py: PlacementTool. the first button press on the test 38 43 canvas will place a Box element on the canvas. 39 * demo.py: added some buttons.44 * demo.py: added some buttons. 40 45 41 46 2006-04-24 Arjan Molenaar <arjan_at_yirdis_dot_nl> 42 47 43 * item.py: Added Line item.44 * pylintrc: new file.48 * item.py: Added Line item. 49 * pylintrc: new file. 45 50 46 51 2006-04-21 Arjan Molenaar <arjan_at_yirdis_dot_nl> … … 48 53 * painter.py: moved drawing code out of the view, into special 49 54 Painters. 50 * cleaned up code with pylint55 * cleaned up code with pylint 51 56 52 57 2006-04-20 Arjan Molenaar <arjan_at_yirdis_dot_nl> 53 58 54 * tool.py: added runnerband selection tool.59 * tool.py: added runnerband selection tool. 55 60 56 61 2006-04-18 Arjan Molenaar <arjan_at_yirdis_dot_nl> 57 62 58 * demo.py: moved demo code from view.py to demo.py63 * demo.py: moved demo code from view.py to demo.py 59 64 * view.py: implemented adjustment objects (for scrollbars). 1st attempt. 60 65 * view.py, tool.py: use a context in stead of view directly. trunk/gaphas/painter.py
r879 r884 63 63 self.painter._draw_items(self.children, 64 64 self.view, 65 self.cairo, 66 self.update_bounds) 65 self.cairo) 67 66 68 67 69 68 class ItemPainter(Painter): 70 69 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): 76 71 cairo.save() 77 72 try: … … 79 74 cairo.transform(view.canvas.get_matrix_i2w(item)) 80 75 81 if update_bounds:82 the_context = view.wrap_cairo_context(cairo)83 else:84 # No wrapper:85 the_context = cairo86 87 76 item.draw(DrawContext(painter=self, 88 update_bounds=update_bounds,89 77 view=view, 90 cairo= the_context,78 cairo=cairo, 91 79 parent=view.canvas.get_parent(item), 92 80 children=view.canvas.get_children(item), … … 94 82 focused=(item is view.focused_item), 95 83 hovered=(item is view.hovered_item))) 96 97 if update_bounds:98 view.set_item_bounding_box(item, the_context.get_bounds())99 84 100 85 if DEBUG_DRAW_BOUNDING_BOX: … … 110 95 cairo.restore() 111 96 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 112 104 def paint(self, context): 113 105 cairo = context.cairo 114 106 view = context.view 115 107 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 111 class 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) 118 131 119 132 trunk/gaphas/view.py
r882 r884 16 16 from geometry import Rectangle 17 17 from tool import DefaultTool 18 from painter import DefaultPainter 18 from painter import DefaultPainter, BoundingBoxPainter 19 19 from decorators import async, PRIORITY_HIGH_IDLE 20 20 from decorators import nonrecursive … … 157 157 self._tool = DefaultTool() 158 158 self._painter = DefaultPainter() 159 self._calculate_bounding_box = False160 159 161 160 matrix = property(lambda s: s._matrix) … … 300 299 301 300 # Make sure everything's updated 302 self. _calculate_bounding_box = True301 self.request_update(self.canvas.get_all_items()) 303 302 a = self.allocation 304 303 super(View, self).queue_draw_area(0, 0, a.width, a.height) … … 397 396 """Wrap draw_area to convert all values to ints. 398 397 """ 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:404 398 super(View, self).queue_draw_area(int(x), int(y), int(w+1), int(h+1)) 405 399 … … 416 410 """Get the bounding box for the item, in canvas coordinates. 417 411 """ 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] 425 413 426 414 def wrap_cairo_context(self, cairo): … … 432 420 433 421 @async(single=False, priority=PRIORITY_HIGH_IDLE) 422 #@nonrecursive 434 423 def request_update(self, items): 435 424 """Update view status according to the items updated by the canvas. 436 425 """ 426 if not self.window: return True 427 437 428 with_handles = set(self._selected_items) 438 429 with_handles.add(self._hovered_item) 439 430 with_handles.add(self._focused_item) 440 431 441 for i in items:432 for i in items: 442 433 self.queue_draw_item(i, handles=(i in with_handles)) 443 434 444 # TODO: pseudo-draw 445 self._calculate_bounding_box = True 435 # Pseudo-draw 446 436 context = self.window.cairo_create() 447 437 context.rectangle(0,0,0,0) 448 438 context.clip() 449 439 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: 455 448 self.queue_draw_item(i, handles=(i in with_handles)) 456 449 457 #self.update_adjustments() 458 #self._calculate_bounding_box = False 450 self.update_adjustments() 459 451 460 452 @nonrecursive … … 473 465 return 474 466 475 # Set this to some idle function476 #if self._canvas.require_update():477 # self._canvas.update_now()478 # self._calculate_bounding_box = True479 480 467 area = event.area 481 468 self.window.draw_rectangle(self.style.white_gc, True, … … 485 472 context = self.window.cairo_create() 486 473 487 if self._calculate_bounding_box:488 self._item_bounds = dict()489 self._bounds = Rectangle()490 491 474 # Draw no more than nessesary. 492 475 context.rectangle(area.x, area.y, area.width, area.height) … … 494 477 495 478 self._painter.paint(Context(view=self, 496 cairo=context, 497 update_bounds=self._calculate_bounding_box)) 479 cairo=context)) 498 480 499 481 if DEBUG_DRAW_BOUNDING_BOX: … … 507 489 context.restore() 508 490 509 if self._calculate_bounding_box:510 self.update_adjustments()511 self._calculate_bounding_box = False512 491 return False 513 492 … … 530 509 531 510 # Force recalculation of the bounding boxes: 532 self. _calculate_bounding_box = True511 self.request_update(self.canvas.get_all_items()) 533 512 534 513 a = self.allocation
