Allow bounding boxes to be calculated fom free-hand painted items
This commit is contained in:
parent
694d075ed8
commit
4f089f1789
@ -120,7 +120,7 @@ def create_window(canvas, title, zoom=1.0):
|
||||
.append(FocusedItemPainter())
|
||||
.append(ToolPainter())
|
||||
)
|
||||
view.bounding_box_painter = FreeHandPainter(BoundingBoxPainter(ItemPainter()))
|
||||
view.bounding_box_painter = BoundingBoxPainter(FreeHandPainter(ItemPainter()))
|
||||
w = Gtk.Window()
|
||||
w.set_title(title)
|
||||
w.set_default_size(400, 120)
|
||||
|
@ -13,7 +13,7 @@ See: http://stevehanov.ca/blog/index.php?id=33 and
|
||||
from math import sqrt
|
||||
from random import Random
|
||||
|
||||
from gaphas.painter import Context
|
||||
from gaphas.painter import Context, Painter
|
||||
|
||||
|
||||
class FreeHandCairoContext:
|
||||
@ -133,16 +133,20 @@ class FreeHandCairoContext:
|
||||
self.close_path()
|
||||
|
||||
|
||||
class FreeHandPainter:
|
||||
class FreeHandPainter(Painter):
|
||||
def __init__(self, subpainter, sloppiness=1.0, view=None):
|
||||
self.subpainter = subpainter
|
||||
self.view = view
|
||||
self.sloppiness = sloppiness
|
||||
if view:
|
||||
self.set_view(view)
|
||||
|
||||
def set_view(self, view):
|
||||
self.view = view
|
||||
self.subpainter.set_view(view)
|
||||
|
||||
def draw_item(self, item, cairo):
|
||||
# Bounding box painter requires painting per item
|
||||
self.subpainter.draw_item(item, cairo)
|
||||
|
||||
def paint(self, context):
|
||||
subcontext = Context(
|
||||
cairo=FreeHandCairoContext(context.cairo, self.sloppiness),
|
||||
|
Loading…
Reference in New Issue
Block a user