From: Kevin A. <ka...@us...> - 2004-05-09 16:26:33
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13856 Modified Files: turtle.py Log Message: added saveState and restoreState and cleaned up reset Index: turtle.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/turtle.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** turtle.py 9 May 2004 05:42:25 -0000 1.16 --- turtle.py 9 May 2004 16:26:24 -0000 1.17 *************** *** 15,19 **** def __init__(self, size): """ this should be called after a subclass has done its init """ ! self.__size = size self._tracing = False self._degrees() --- 15,19 ---- def __init__(self, size): """ this should be called after a subclass has done its init """ ! self._size = size self._tracing = False self._degrees() *************** *** 305,334 **** def reset(self): """ this should be called after a subclass has done its reset """ - """ but currently it needs to be overridden""" - #canvas = self.canvas - # just get the width and height from the window? - #width = FRAME_WIDTH #canvas.winfo_width() - #height = FRAME_HEIGHT # canvas.winfo_height() - #self._color = "black" - #self._color = wx.Pen(wx.NamedColour("black")) ! width, height = self.__size self._origin = width/2.0, height/2.0 self._position = self._origin self._odometer = 0.0 # don't waste time tracking unless requested self._odometerOn = False ! self._angle = 0.0 self._drawing = True self._width = 1 ! self._filling = 0 ! self._path = [] ! self._tofill = [] ! self._dirty = False self._visible = False self._drawingTurtle = False self._turtleDelay = 0 # implicit save of pen state, penUp, pen state restore def moveTo(self, x=None, y=None): """move the turtle to position x, y""" --- 305,338 ---- def reset(self): """ this should be called after a subclass has done its reset """ ! width, height = self._size self._origin = width/2.0, height/2.0 + #print "width: %d, height: %d" % (width, height) + #print "_origin.x: %f, _origin.y: %f" % (self._origin[0], self._origin[1]) self._position = self._origin + self._angle = 0.0 + # used for saveState and restoreState methods + self._savePosition = self._position + self._saveAngle = self._angle self._odometer = 0.0 # don't waste time tracking unless requested self._odometerOn = False ! # whether the pen is down self._drawing = True + # the pen width self._width = 1 ! # whether the turtle is visible, independent of the pen state self._visible = False + # if _dirty then erase old turtle before drawing + self._dirty = False + # only true while drawing the turtle self._drawingTurtle = False + # number of seconds to pause after drawing the turtle self._turtleDelay = 0 # implicit save of pen state, penUp, pen state restore + # KEA 2004-05-09 + # why the heck did I not require both x and y to be specified? + # is that the way Logo works? def moveTo(self, x=None, y=None): """move the turtle to position x, y""" *************** *** 356,359 **** --- 360,371 ---- self._position = (float(x1), float(y1)) + def saveState(self): + self._savePosition = self._position + self._saveAngle = self._angle + + def restoreState(self): + self.moveTo(self._savePosition[0], self._savePosition[1]) + self.setHeading(self._saveAngle) + class BitmapTurtle(AbstractTurtle): *************** *** 403,407 **** # Logo functions to implement # see http://www.embry.com/rLogo/rLogoReference.html ! # and http://www.embry.com/rLogo/Index.html for a working logo applet # setpencolor will be handled by color() --- 415,419 ---- # Logo functions to implement # see http://www.embry.com/rLogo/rLogoReference.html ! # and http://www.embry.com/rLogo/ for a working logo applet # setpencolor will be handled by color() *************** *** 499,510 **** """set the background pen color both (r, g, b) values and named colors are valid""" - ###brush = self.dc.GetBackground() if len(args) == 1: - ###brush.SetColour(wx.NamedColour(args[0])) self.canvas.backgroundColor = args[0] else: - ###brush.SetColour(wx.Colour(args[0], args[1], args[2])) self.canvas.backgroundColor = (args[0], args[1], args[2]) - ###self.dc.SetBackground(brush) # non-optimized turtle --- 511,518 ---- *************** *** 559,598 **** def reset(self): """reset the turtle to its initial state""" ! #canvas = self.canvas ! # just get the width and height from the window? ! #width = FRAME_WIDTH #canvas.winfo_width() ! #height = FRAME_HEIGHT # canvas.winfo_height() ! ! #width, height = self.canvas._deviceSize ! width, height = self.canvas.size ! ! #self._color = "black" self._color = wx.Pen(wx.NamedColour("black")) self._pen = wx.Pen('black', 1, wx.SOLID) self.setBackColor('white') ! ! #AbstractTurtle.reset() ! self._origin = width/2.0, height/2.0 ! #print "width: %d, height: %d" % (width, height) ! #print "_origin.x: %f, _origin.y: %f" % (self._origin[0], self._origin[1]) ! self._position = self._origin ! self._odometer = 0.0 ! # don't waste time tracking unless requested ! self._odometerOn = False ! self._angle = 0.0 ! # whether the pen is down ! self._drawing = True ! self._width = 1 ! #self._filling = 0 ! #self._path = [] ! #self._tofill = [] ! # whether the turtle is visible, independent of the pen state ! self._visible = False ! # if _dirty then erase old turtle before drawing ! self._dirty = False ! # only true while drawing the turtle ! self._drawingTurtle = False ! # number of seconds to pause after drawing the turtle ! self._turtleDelay = 0 def _goto(self, x1, y1): --- 567,575 ---- def reset(self): """reset the turtle to its initial state""" ! self._size = self.canvas.size self._color = wx.Pen(wx.NamedColour("black")) self._pen = wx.Pen('black', 1, wx.SOLID) self.setBackColor('white') ! AbstractTurtle.reset(self) def _goto(self, x1, y1): *************** *** 610,616 **** x0, y0 = start = self._position self._position = (float(x1), float(y1)) - #if self._filling: - # self._path.append(self._position) - #print self._drawing if self._drawing: """ --- 587,590 ---- |