complete circle drawing

This commit is contained in:
Josh Holtrop 2011-07-27 18:03:32 -04:00
parent 4ec320ff5d
commit b95e8e8789

View File

@ -246,6 +246,8 @@ class SketchWidget:
elif self.drawingShape is not None:
if self.mode == 'line':
self.do_line_motion(event.x, event.y)
elif self.mode == 'circle':
self.do_circle_motion(event.x, event.y)
def scroll_event(self, widget, event, data = None):
if event.direction == gtk.gdk.SCROLL_UP:
@ -353,8 +355,8 @@ class SketchWidget:
def do_line_left_click(self, x, y):
start = self.screenPtToPt((x, self.size[1] - y))
if self.drawingShape is not None:
self.merge_in_drawing_shape()
start = self.drawingShape.getPt(1) # start at last snap point
self.merge_in_drawing_shape()
self.drawingShape = Line(start[0], start[1], start[0], start[1])
self.queue_redraw()
@ -395,6 +397,9 @@ class SketchWidget:
pt = self.screenPtToPt((x, self.size[1] - y))
if self.drawingShape is None:
self.drawingShape = Circle(pt[0], pt[1], 0)
else:
self.merge_in_drawing_shape()
self.queue_redraw()
def do_circle_right_click(self, x, y):
if self.drawingShape is not None:
@ -402,8 +407,20 @@ class SketchWidget:
self.drawingShape = None
self.queue_redraw()
def do_circle_motion(self, x, y):
pt = self.screenPtToPt((x, self.size[1] - y))
r = self.dist_bw(self.drawingShape.getPt(0), pt)
self.drawingShape.setRadius(r)
self.queue_redraw()
def merge_in_drawing_shape(self):
self.sketch.shapes.append(self.drawingShape)
for c in self.drawingConstraints:
self.sketch.constraints.append(c)
self.drawingShape = None
self.drawingConstraints = []
def dist_bw(self, pt1, pt2):
x = pt2[0] - pt1[0]
y = pt2[1] - pt1[1]
return math.sqrt(x * x + y * y)