--- 02-line.py 2006-01-03 16:08:57.000000000 -0200 +++ 03-tools.py 2006-01-03 17:29:22.000000000 -0200 @@ -35,8 +35,93 @@ +class Pencil( Tool ): + def __init__( self ): + self.last_point = None + # __init__() + + + def mouse( self, app, canvas, buttons, x, y ): + if buttons & Canvas.MOUSE_BUTTON_1: + color = app[ "fg" ] + size = app[ "size" ] + if self.last_point is not None: + x0, y0 = self.last_point + else: + x0 = x + 1 + y0 = y + + if size == 1: + canvas.draw_point( x, y, color ) + else: + half = size / 2 + canvas.draw_rectangle( x-half, y-half, size, size, color, 1, + color, True ) + canvas.draw_line( x0, y0, x, y, color, size ) + self.last_point = ( x, y ) + else: + # Button 1 was released, reset last point + self.last_point = None + # mouse() +# Pencil + + + +class Rectangle( Tool ): + def __init__( self ): + self.first_point = None + # __init__() + + + def mouse( self, app, canvas, buttons, x, y ): + if buttons & Canvas.MOUSE_BUTTON_1: + if self.first_point is None: + self.first_point = ( x, y ) + else: + fg = app[ "fg" ] + bg = app[ "bg" ] + size = app[ "size" ] + fill = app[ "rectfill" ] + + x0, y0 = self.first_point + + if x0 > x: + x0, x = x, x0 + if y0 > y: + y0, y = y, y0 + + w = x - x0 + h = y - y0 + + canvas.draw_rectangle( x0, y0, w, h, fg, size, bg, fill ) + self.first_point = None + # mouse() +# Rectangle + + + +class Text( Tool ): + def mouse( self, app, canvas, buttons, x, y ): + if buttons & Canvas.MOUSE_BUTTON_1 and app[ "text" ]: + text = app[ "text" ] + fg = app[ "fg" ] + bg = app[ "bg" ] + font = app[ "font" ] + + if app[ "textbgtransp" ]: + bg = None + + canvas.draw_text( text, x, y, fg, bg, font ) + # mouse() +# Text + + + tools = { "Line": Line(), + "Pencil": Pencil(), + "Rectangle": Rectangle(), + "Text": Text(), } def_tool="Line"