Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2010-05-31 03:56:59 (GMT)
committer James Cameron <quozl@laptop.org>2010-05-31 10:15:53 (GMT)
commit0516bbb77741f33e8a82ba0e910294d38a15a9b5 (patch)
treeab8db29b65a3c00b35406a66d3854cd2fe60a8a7
parent4a60d01d45c143f22a0022e61cc0d3e09ec052a4 (diff)
fix OLPC #296
-rw-r--r--Area.py29
-rw-r--r--Desenho.py78
2 files changed, 60 insertions, 47 deletions
diff --git a/Area.py b/Area.py
index 8af2b9b..7b8c8b4 100644
--- a/Area.py
+++ b/Area.py
@@ -176,6 +176,11 @@ class Area(gtk.DrawingArea):
##Shapes will be filled or not?
self.fill = True
+ # variables to show the tool shape
+ self.drawing = False
+ self.x_cursor = 0
+ self.y_cursor = 0
+
def setup(self, width, height):
"""Configure the Area object."""
@@ -256,8 +261,22 @@ class Area(gtk.DrawingArea):
widget.window.draw_drawable(self.gc,self.pixmap_temp,area[0],area[1],area[0],area[1],area[2],area[3])
else:
widget.window.draw_drawable(self.gc,self.pixmap,area[0],area[1],area[0],area[1],area[2],area[3])
+ self.show_tool_shape(widget)
return False
+ def show_tool_shape(self,widget):
+ """
+ Show the shape of the tool selected for pencil, brush, rainbow and eraser
+ """
+ if self.tool['name'] in ['pencil','eraser','brush','rainbow']:
+ if not self.drawing:
+ size = self.tool['line size']
+ if self.tool['line shape'] == 'circle':
+ widget.window.draw_arc(self.gc_brush, False, self.x_cursor - size/2, self.y_cursor - size/2, size, size, 0, 360*64)
+ else:
+ widget.window.draw_rectangle(self.gc_brush, False, self.x_cursor - size/2, self.y_cursor - size/2, size, size)
+
+
def mousedown(self,widget,event):
"""Make the Area object (GtkDrawingArea) recognize that the mouse button has been pressed.
@@ -304,14 +323,17 @@ class Area(gtk.DrawingArea):
self.last = []
self.d.eraser(widget, coords, self.last, self.line_size, self.tool['line shape'])
self.last = coords
+ self.drawing = True
elif self.tool['name'] == 'brush':
self.last = []
self.d.brush(widget, coords, self.last, self.line_size, self.tool['line shape'])
self.last = coords
+ self.drawing = True
elif self.tool['name'] == 'rainbow':
self.last = []
self.d.rainbow(widget, coords, self.last, self.rainbow_counter,self.line_size, self.tool['line shape'])
self.last = coords
+ self.drawing = True
elif self.tool['name'] == 'polygon':
self.configure_line(self.line_size)
if self.polygon_start == False:
@@ -347,6 +369,8 @@ class Area(gtk.DrawingArea):
y = event.y
state = event.state
+ self.x_cursor,self.y_cursor = int(x), int(y)
+
coords = int(x), int(y)
if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:
@@ -419,6 +443,8 @@ class Area(gtk.DrawingArea):
self.configure_line(self.line_size)
self.d.heart(widget,coords,True,self.tool['fill'])
else:
+ if self.tool['name'] in ['brush','eraser','rainbow','pencil'] :
+ widget.queue_draw()
if self.tool['name'] == 'marquee-rectangular' and self.selmove:
size = self.pixmap_sel.get_size()
xi = self.orig_x
@@ -520,10 +546,11 @@ class Area(gtk.DrawingArea):
self.d.heart(widget,coords,False,self.tool['fill'])
self.enableUndo(widget)
- if self.tool['name'] == 'brush' or self.tool['name'] == 'eraser' or self.tool['name'] == 'rainbow' or self.tool['name'] == 'pencil' :
+ if self.tool['name'] in ['brush','eraser','rainbow','pencil'] :
self.last = []
widget.queue_draw()
self.enableUndo(widget)
+ self.drawing = False
self.desenha = False
def undo(self):
diff --git a/Desenho.py b/Desenho.py
index e5ecf48..c9a134b 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -110,20 +110,8 @@ class Desenho:
"""
widget.desenha = False
- if(shape == 'circle'):
- widget.pixmap.draw_arc(widget.gc_eraser, True, coords[0], coords[1], size, size, 0, 360*64)
- if last:
- widget.gc_eraser.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- widget.pixmap.draw_line(widget.gc_eraser,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2)
- widget.gc_eraser.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- if(shape == 'square'):
- widget.pixmap.draw_rectangle(widget.gc_eraser, True, coords[0], coords[1], size, size)
- if last:
- points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)]
- widget.pixmap.draw_polygon(widget.gc_eraser,True,points)
- points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)]
- widget.pixmap.draw_polygon(widget.gc_eraser,True,points)
- widget.queue_draw()
+ self._trace(widget,widget.gc_eraser, coords, last, size, shape)
+ #widget.queue_draw()
def brush(self, widget, coords, last, size = 5, shape = 'circle'):
"""Paint with brush.
@@ -137,28 +125,9 @@ class Desenho:
"""
widget.desenha = False
- if(shape == 'circle'):
- widget.pixmap.draw_arc(widget.gc_brush, True, coords[0], coords[1], size, size, 0, 360*64)
- if last:
- widget.gc_brush.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- widget.pixmap.draw_line(widget.gc_brush,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2)
- widget.gc_brush.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- if(shape == 'square'):
- widget.pixmap.draw_rectangle(widget.gc_brush, True, coords[0], coords[1], size, size)
- if last:
- points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)]
- widget.pixmap.draw_polygon(widget.gc_brush,True,points)
- points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)]
- widget.pixmap.draw_polygon(widget.gc_brush,True,points)
+ self._trace(widget,widget.gc_brush, coords, last, size, shape)
+
- if last:
- x = min(coords[0], last[0])
- width = max(coords[0], last[0]) - x
- y = min(coords[1], last[1])
- height = max(coords[1], last[1]) - y
- widget.queue_draw_area(x, y, width+size, height+size) # We add size to avoid drawing dotted lines
- else:
- widget.queue_draw()
def rainbow(self, widget, coords, last, color, size = 5, shape = 'circle'):
"""Paint with rainbow.
@@ -190,23 +159,40 @@ class Desenho:
widget.gc_rainbow.set_foreground(rainbow_colors[color])
widget.desenha = False
+ self._trace(widget,widget.gc_rainbow, coords, last, size, shape)
+
+
+ def _trace(self, widget,gc, coords, last, size, shape):
if(shape == 'circle'):
- widget.pixmap.draw_arc(widget.gc_rainbow, True, coords[0], coords[1], size, size, 0, 360*64)
+ widget.pixmap.draw_arc(gc, True, coords[0] - size/2, coords[1] - size/2, size, size, 0, 360*64)
if last:
- widget.gc_rainbow.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
- widget.pixmap.draw_line(widget.gc_rainbow,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2)
- widget.gc_rainbow.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
+ gc.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
+ widget.pixmap.draw_line(gc, last[0], last[1], coords[0], coords[1])
+ gc.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
if(shape == 'square'):
+ widget.pixmap.draw_rectangle(gc, True, coords[0] - size/2, coords[1] - size/2, size, size)
if last:
- widget.pixmap.draw_rectangle(widget.gc_rainbow, True, last[0], last[1], size, size)
- points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)]
- widget.pixmap.draw_polygon(widget.gc_rainbow,True,points)
- points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)]
- widget.pixmap.draw_polygon(widget.gc_rainbow,True,points)
- widget.pixmap.draw_rectangle(widget.gc_rainbow, True, coords[0], coords[1], size, size)
- widget.queue_draw()
+ points = [(last[0] - size/2,last[1] - size/2), (coords[0] - size/2, coords[1] - size/2),
+ (coords[0] + size/2, coords[1] + size/2) , (last[0] + size/2,last[1] + size/2)]
+ widget.pixmap.draw_polygon(gc,True,points)
+ points = [(last[0] + size/2,last[1] - size/2), (coords[0] + size/2, coords[1] - size/2),
+ (coords[0] - size/2, coords[1] + size/2) , (last[0] - size/2,last[1] + size/2)]
+ widget.pixmap.draw_polygon(gc,True,points)
+
+
+ if last:
+ x = min(coords[0], last[0])
+ width = max(coords[0], last[0]) - x
+ y = min(coords[1], last[1])
+ height = max(coords[1] , last[1]) - y
+ widget.queue_draw_area(x-size, y-size, width+size*2, height+size*2) # We add size to avoid drawing dotted lines
+ else:
+ widget.queue_draw()
+
+
+
def square(self, widget, event, coords, temp, fill):
"""Draw a square.