Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shapeobject.py
diff options
context:
space:
mode:
authorpmoxhay <pmoxhay@earthlink.net>2009-02-16 19:03:56 (GMT)
committer pmoxhay <pmoxhay@earthlink.net>2009-02-16 19:03:56 (GMT)
commitc2ccda8e7fd359ad9829cd2b88ef0b347281a037 (patch)
tree9567af8043aa9a2dadcd99a7bc07e2fc6979dc7b /shapeobject.py
parentc0cd8b1c686e46839a33b8d7523b9b2bbef98487 (diff)
First try at comparing in amount of discrete objects.
Objects sometimes extend beyond AnswerBox.
Diffstat (limited to 'shapeobject.py')
-rw-r--r--shapeobject.py90
1 files changed, 59 insertions, 31 deletions
diff --git a/shapeobject.py b/shapeobject.py
index 59f7cda..5c7322f 100644
--- a/shapeobject.py
+++ b/shapeobject.py
@@ -32,7 +32,7 @@ RADIAL_GRID_SIZE = math.pi/4
class ShapeObject(MovableObject):
"""Movable convex shape object."""
- def __init__(self, color, symbol, points, pos, angle, area_problem):
+ def __init__(self, color, symbol, points, pos, angle, centroid_shift, area_problem):
MovableObject.__init__(self)
self.color = color
@@ -43,6 +43,7 @@ class ShapeObject(MovableObject):
self.area = 0
self.centroid = Vector(0, 0)
+ self.centroid_shift = centroid_shift
self.bounds_min = Vector(0, 0)
self.bounds_max = Vector(0, 0)
@@ -58,7 +59,12 @@ class ShapeObject(MovableObject):
self.calculate_bounds()
self.area_problem = area_problem
-
+
+ self.draw_as_circle = False
+ self.circle_radius = 35
+
+ self.symbol_visible = True
+
def calculate_area_and_centroid(self):
# Calculate the area.
self.area = 0
@@ -91,7 +97,7 @@ class ShapeObject(MovableObject):
return self.bounds_min, self.bounds_max
def transform_point(self, p):
- return p.rotate(self.angle) + self.pos
+ return p.rotate(self.angle) + self.pos + self.centroid_shift
def inside_move_area(self, point):
self.point = point
@@ -130,36 +136,57 @@ class ShapeObject(MovableObject):
def draw(self, cr):
cr.scale(self.scale, self.scale)
-
- # Transform the points.
- points = [self.transform_point(p) for p in self.points]
-
- # Generate the shape.
- cr.move_to(points[0].x, points[0].y)
- for p in points:
- cr.line_to(p.x, p.y)
- cr.line_to(points[0].x, points[0].y)
-
- # Draw the fill.
- if self.selected:
- cr.set_source_rgb(self.color[0]*1.6, self.color[1]*1.6, self.color[2]*1.6)
- else:
- cr.set_source_rgb(self.color[0], self.color[1], self.color[2])
- cr.fill_preserve()
- # Draw the outline.
- if self.selected:
- cr.set_dash((10, 10), 0)
- cr.set_source_rgb(self.color[0]*0.75, self.color[1]*0.75, self.color[2]*0.75)
- cr.set_line_width(4.0)
- cr.stroke()
+ if not self.draw_as_circle:
+ # Transform the points.
+ points = [self.transform_point(p) for p in self.points]
+
+ # Generate the shape.
+ cr.move_to(points[0].x, points[0].y)
+ for p in points:
+ cr.line_to(p.x, p.y)
+ cr.line_to(points[0].x, points[0].y)
+ cr.close_path()
+ # Draw the fill.
+ if self.selected:
+ cr.set_source_rgb(self.color[0]*1.6, self.color[1]*1.6, self.color[2]*1.6)
+ else:
+ cr.set_source_rgb(self.color[0], self.color[1], self.color[2])
+ cr.fill_preserve()
+
+ # Draw the outline.
+ if self.selected:
+ cr.set_dash((10, 10), 0)
+ cr.set_source_rgb(self.color[0]*0.75, self.color[1]*0.75, self.color[2]*0.75)
+ cr.set_line_width(4.0)
+ cr.stroke()
+ elif self.draw_as_circle:
+ #cr.arc(self.pos.x, self.pos.y, self.circle_radius, 0.0, 2.0 * math.pi)
+
+ # Draw the fill.
+ if self.selected:
+ cr.set_source_rgb(self.color[0]*1.6, self.color[1]*1.6, self.color[2]*1.6)
+ else:
+ cr.set_source_rgb(self.color[0], self.color[1], self.color[2])
+ cr.arc(self.pos.x, self.pos.y, self.circle_radius, 0.0, 2.0 * math.pi)
+ cr.fill()
+
+ # Draw the outline.
+ if self.selected:
+ cr.set_dash((10, 10), 0)
+ cr.set_source_rgb(self.color[0]*0.75, self.color[1]*0.75, self.color[2]*0.75)
+ cr.set_line_width(4.0)
+ cr.arc(self.pos.x, self.pos.y, self.circle_radius, 0.0, 2.0 * math.pi)
+ cr.stroke()
+
# Draw the symbol (capital letter representing the shapes's area).
- cr.set_source_rgb(0, 0, 0)
- cr.set_font_size(50)
- x_bearing, y_bearing, width, height = cr.text_extents(self.symbol)[:4]
- cr.move_to(self.pos.x - x_bearing - width/2, self.pos.y - y_bearing - height/2)
- cr.show_text(self.symbol)
+ if self.symbol_visible:
+ cr.set_source_rgb(0, 0, 0)
+ cr.set_font_size(50)
+ x_bearing, y_bearing, width, height = cr.text_extents(self.symbol)[:4]
+ cr.move_to(self.pos.x - x_bearing - width/2, self.pos.y - y_bearing - height/2)
+ cr.show_text(self.symbol)
# Algorithm to test whether point is inside the polygon
def contains_point(self, pos):
@@ -205,7 +232,8 @@ class ShapeObject(MovableObject):
self.calculate_bounds()
- self.container.queue_draw()
+ if self.container:
+ self.container.queue_draw()
def rotate(self, angle):
# Tentatively rotate the object to the new angle