Commit c9e6ef00 authored by Taddeus Kroes's avatar Taddeus Kroes

Added margin to bounding box.

parent 3d940d14
......@@ -33,10 +33,11 @@ class Rectangle(mt.RectangularArea):
class Polygon(BoundingBoxArea):
def __init__(self, x, y, points, color=BLUE, border_color=RED):
def __init__(self, x, y, points, margin=0, color=BLUE, border_color=RED):
super(Polygon, self).__init__(x, y, points)
self.fill_color = color
self.border_color = border_color
self.margin = margin
self.on_drag(self.handle_drag)
self.on_pinch(self.handle_pinch)
......@@ -59,10 +60,17 @@ class Polygon(BoundingBoxArea):
self.update_bounds()
refresh()
def contains(self, x, y):
m = self.margin
return self.x - m <= x < self.x + self.width + m \
and self.y - m <= y < self.y + self.height + m
def draw(self, cr):
# Draw bounding box
if draw_bounding_boxes:
cr.rectangle(self.x, self.y, self.width, self.height)
m = self.margin
cr.rectangle(self.x - m, self.y - m,
self.width + 2 * m, self.height + 2 * m)
cr.set_source_rgb(*self.border_color)
cr.set_line_width(3)
cr.stroke()
......@@ -205,7 +213,7 @@ def on_show(window):
# Create blue rectangle
x, y, w, h = 0, 0, 250, 150
rect = Polygon(x, y, [(0, 0), (0, h), (w, h), (w, 0)])
rect = Polygon(x, y, [(0, 0), (0, h), (w, h), (w, 0)], margin=20)
draw_objects.append(rect)
root.add_area(rect)
......@@ -215,7 +223,8 @@ def on_show(window):
# Create green triangle
x, y, w = 400, 400, 200
h = triangle_height(w)
triangle = Polygon(x, y, [(0, h), (w, h), (w / 2, 0)], color=GREEN)
triangle = Polygon(x, y, [(0, h), (w, h), (w / 2, 0)],
margin=20, color=GREEN)
draw_objects.append(triangle)
root.add_area(triangle)
......@@ -245,8 +254,8 @@ if __name__ == '__main__':
# Parse arguments
parser = create_parser()
parser.add_argument('-f', '--fullscreen', action='store_true', default=False,
help='run in fullscreen initially')
parser.add_argument('-f', '--fullscreen', action='store_true',
default=False, help='run in fullscreen initially')
args = parse_args(parser)
fullscreen = args.fullscreen
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment