gcompris r3472 - branches/gcomprixogoo/src/anim-activity
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3472 - branches/gcomprixogoo/src/anim-activity
- Date: Wed, 9 Jul 2008 22:39:56 +0000 (UTC)
Author: bcoudoin
Date: Wed Jul 9 22:39:55 2008
New Revision: 3472
URL: http://svn.gnome.org/viewvc/gcompris?rev=3472&view=rev
Log:
initial work for drawing lines in anim.
it does not fit the model very well and this show evidence
that I need to rework the code to make the items know
how to draw themself in a bounding box. With this I could
keep the resize code easy in all cases, just resizing the
bounding box.
Modified:
branches/gcomprixogoo/src/anim-activity/AnimItem.py
branches/gcomprixogoo/src/anim-activity/anim.py
Modified: branches/gcomprixogoo/src/anim-activity/AnimItem.py
==============================================================================
--- branches/gcomprixogoo/src/anim-activity/AnimItem.py (original)
+++ branches/gcomprixogoo/src/anim-activity/AnimItem.py Wed Jul 9 22:39:55 2008
@@ -161,6 +161,7 @@
# Given two points p1 and p2, return the
# boundings coordinates (x1, y2, x2, y2)
# all snaped to the grid
+ # Coord are returned so that p1 < p2
def snap_obj_to_grid(self, p1, p2):
x = min(p1[0], p2[0])
y = min(p1[1], p2[1])
@@ -170,6 +171,19 @@
(x2, y2) = self.snap_to_grid(x+w, y+h)
return (x1, y1, x2, y2)
+ # Given two points p1 and p2, return the
+ # boundings coordinates (x1, y2, x2, y2)
+ # all snaped to the grid
+ # Points are not reordered
+ def snap_point_to_grid(self, p1, p2):
+ x = p1[0]
+ y = p1[1]
+ (x1, y1) = self.snap_to_grid(x, y)
+ x = p2[0]
+ y = p2[1]
+ (x2, y2) = self.snap_to_grid(x, y)
+ return (x1, y1, x2, y2)
+
# Selecting the item creates and display its anchors
def select(self):
if not self.anchor:
@@ -536,25 +550,19 @@
#
class AnimItemRect(AnimItem):
- x = 0
- y = 0
- width = 0
- height = 0
filled = False
def __init__(self, anim, x, y, color_fill, color_stroke, line_width):
AnimItem.__init__(self, anim)
x,y = self.snap_to_grid(x, y)
- self.x = x
- self.y = y
self.item = \
goocanvas.Rect(
parent = self.rootitem,
- x = self.x,
- y = self.y,
- width = self.width,
- height = self.height,
+ x = x,
+ y = y,
+ width = 0,
+ height = 0,
stroke_color_rgba = color_stroke,
line_width = line_width)
@@ -622,30 +630,24 @@
self.item.set_properties(stroke_color_rgba = stroke)
#
-# The elliopse (filled or not)
+# The ellipse (filled or not)
#
class AnimItemEllipse(AnimItem):
- center_x = 0
- canter_y = 0
- radius_x = 0
- radius_y = 0
filled = False
def __init__(self, anim, center_x, center_y,
color_fill, color_stroke, line_width):
AnimItem.__init__(self, anim)
center_x, center_y = self.snap_to_grid(center_x, center_y)
- self.center_x = center_x
- self.center_y = center_y
self.item = \
goocanvas.Ellipse(
parent = self.rootitem,
- center_x = self.center_x,
- center_y = self.center_y,
- radius_x = self.radius_x,
- radius_y = self.radius_y,
+ center_x = center_x,
+ center_y = center_y,
+ radius_x = 0,
+ radius_y = 0,
stroke_color_rgba = color_stroke,
line_width = line_width)
@@ -658,16 +660,6 @@
self.item.connect("button_release_event", anim.item_event)
self.item.connect("motion_notify_event", anim.item_event)
- # Fixme, should replace set_bounds in resize cases
- def scale_bounds(self, p1, p2):
- (x1, y1, x2, y2) = self.snap_obj_to_grid(p1, p2)
- bounds = self.item.get_bounds()
- sx = (x2 - x1) / (bounds.x2 - bounds.x1)
- sy = (y2 - y1) / (bounds.y2 - bounds.y1)
- print "sx=%f sy=%f" %(sx, sy)
- self.item.scale(sx, sy)
-
-
def set_bounds(self, p1, p2):
(x1, y1, x2, y2) = self.snap_obj_to_grid(p1, p2)
radius_x = abs((x2 - x1) / 2)
@@ -716,3 +708,54 @@
else:
self.item.set_properties(stroke_color_rgba = stroke)
+
+#
+# The Line
+#
+class AnimItemLine(AnimItem):
+
+
+ def __init__(self, anim, x, y,
+ color_fill, color_stroke, line_width):
+ AnimItem.__init__(self, anim)
+ x, y = self.snap_to_grid(x, y)
+
+ self.item = \
+ goocanvas.Polyline(
+ parent = self.rootitem,
+ stroke_color_rgba = color_stroke,
+ points = goocanvas.Points([(x , y), (x , y)]),
+ line_width = line_width,
+ line_cap = cairo.LINE_CAP_ROUND)
+
+ self.item.set_data("AnimItem", self)
+ self.item.connect("button_press_event", anim.item_event)
+ self.item.connect("button_release_event", anim.item_event)
+ self.item.connect("motion_notify_event", anim.item_event)
+
+ def set_bounds(self, p1, p2):
+ (x1, y1, x2, y2) = self.snap_point_to_grid(p1, p2)
+ self.item.set_properties(points = goocanvas.Points([(x1 , y1), (x2 , y2)]))
+ points = [(x1 , y1), (x2 , y2)]
+ print points
+
+ def get_x1y1(self):
+ points = self.item.get_property("points").coords
+ return(points[0][0], points[0][1])
+
+ def get_x2y2(self):
+ points = self.item.get_property("points").coords
+ return(points[1][0], points[1][1])
+
+ # Return the list of properties that have to be saved for
+ # this object
+ def get_properties(self):
+ return('points',
+ 'stroke_color_rgba',
+ 'line_width',
+ 'line_cap')
+
+ def fill(self, fill, stroke):
+ gcompris.sound.play_ogg("sounds/paint1.wav")
+ self.item.set_properties(stroke_color_rgba = stroke)
+
Modified: branches/gcomprixogoo/src/anim-activity/anim.py
==============================================================================
--- branches/gcomprixogoo/src/anim-activity/anim.py (original)
+++ branches/gcomprixogoo/src/anim-activity/anim.py Wed Jul 9 22:39:55 2008
@@ -125,11 +125,11 @@
["IMAGE", "draw/tool-image.png", "draw/tool-image_on.png", gcompris.CURSOR_DEFAULT],
["FILL", "draw/tool-fill.png", "draw/tool-fill_on.png", gcompris.CURSOR_FILL],
["DEL", "draw/tool-del.png", "draw/tool-del_on.png", gcompris.CURSOR_DEL],
+ ["FLIP", "draw/tool-flip.png", "draw/tool-flip_on.png", gcompris.CURSOR_DEFAULT],
["RAISE", "draw/tool-up.png", "draw/tool-up_on.png", gcompris.CURSOR_DEFAULT],
["LOWER", "draw/tool-down.png", "draw/tool-down_on.png", gcompris.CURSOR_DEFAULT],
["CCW", "draw/tool-rotation-ccw.png", "draw/tool-rotation-ccw_on.png", gcompris.CURSOR_DEFAULT],
["CW", "draw/tool-rotation-cw.png", "draw/tool-rotation-cw_on.png", gcompris.CURSOR_DEFAULT],
- ["FLIP", "draw/tool-flip.png", "draw/tool-flip_on.png", gcompris.CURSOR_DEFAULT],
]
# keep the tool selected
@@ -693,31 +693,29 @@
elif self.tools[self.current_tool][0] == "FLIP":
animItem.flip()
+ self.created_object = None
if self.tools[self.current_tool][0] == "FILL_RECT":
self.created_object = AnimItemRect(self,
event.x, event.y,
self.color.fill, self.color.stroke, 2)
- self.created_object.create_item_event(item,
- target,
- event)
elif self.tools[self.current_tool][0] == "RECT":
self.created_object = AnimItemRect(self,
event.x, event.y,
None, self.color.stroke, 7)
- self.created_object.create_item_event(item,
- target,
- event)
elif self.tools[self.current_tool][0] == "FILL_CIRCLE":
self.created_object = AnimItemEllipse(self,
event.x, event.y,
self.color.fill, self.color.stroke, 2)
- self.created_object.create_item_event(item,
- target,
- event)
elif self.tools[self.current_tool][0] == "CIRCLE":
self.created_object = AnimItemEllipse(self,
event.x, event.y,
None, self.color.stroke, 7)
+ elif self.tools[self.current_tool][0] == "LINE":
+ self.created_object = AnimItemLine(self,
+ event.x, event.y,
+ None, self.color.stroke, 7)
+
+ if self.created_object:
self.created_object.create_item_event(item,
target,
event)
@@ -751,7 +749,7 @@
self.created_object.create_item_event(item,
target,
event)
- self.created_object = False
+ self.created_object = None
return True
else:
if self.selected:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]