From 1f7a43aba377cf617080a463dfb053d656fadfaa Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Tue, 21 Jul 2020 21:13:45 -0400 Subject: [PATCH] Revert "Remove `draw_all` from drawing context" This reverts commit 2d369f78 Signed-off-by: Dan Yeaw --- README.md | 2 ++ docs/api.rst | 1 + gaphas/item.py | 2 ++ gaphas/painter.py | 6 ++++++ 4 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 643377f..714262f 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,7 @@ The view context passed to the Items draw() method has the following properties: - focused - True if the item has the focus - hovered - True if the mouse pointer if over the item. Only the top-most item is marked as hovered. - dropzone - The item is marked as the drop zone. When this happens then an item is dragged over the item, and if it is dropped, it will become a child of this item. +- draw_all - True if everything drawable on the item should be drawn, for example, when calculating the bounding boxes of an item. The View automatically calculates the bounding box for the item, based on the items drawn in the draw (context) function (this is only done when really necessary, e.g., after an update of the item). The bounding box is in viewport coordinates. @@ -401,6 +402,7 @@ DrawContext( focused=(item is view.focused_item), hovered=(item is view.hovered_item), dropzone=(item is view.dropzone_item), + draw_all=self.draw_all, ) ``` diff --git a/docs/api.rst b/docs/api.rst index de46a49..ce9f70a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -209,6 +209,7 @@ Special context for drawing the item. It contains a cairo context and properties focused=(item is view.focused_item), hovered=(item is view.hovered_item), dropzone=(item is view.dropzone_item), + draw_all=self.draw_all, ) Class: ``gaphas.painter.ItemPainter`` diff --git a/gaphas/item.py b/gaphas/item.py index 4ceb788..fe954e0 100644 --- a/gaphas/item.py +++ b/gaphas/item.py @@ -187,6 +187,8 @@ class Item: - view: the view that is to be rendered to - selected, focused, hovered, dropzone: view state of items (True/False) + - draw_all: a request to draw everything, for bounding box + calculations """ pass diff --git a/gaphas/painter.py b/gaphas/painter.py index 600f52e..527797f 100644 --- a/gaphas/painter.py +++ b/gaphas/painter.py @@ -86,6 +86,9 @@ class DrawContext(Context): class ItemPainter(Painter): + + draw_all = False + def draw_item(self, item, cairo): view = self.view cairo.save() @@ -102,6 +105,7 @@ class ItemPainter(Painter): focused=(item is view.focused_item), hovered=(item is view.hovered_item), dropzone=(item is view.dropzone_item), + draw_all=self.draw_all, ) ) @@ -241,6 +245,8 @@ class BoundingBoxPainter(Painter): bounding boxes (in canvas coordinates) for the items. """ + draw_all = True + def __init__(self, item_painter=None, view=None): super().__init__(view) self.item_painter = item_painter or ItemPainter(view)