This patch change:<br>* Show the shape and the size with the pencil, brush, eraser and rainbow.<br>* Center this tools at the cursor coordinates<br>I think it's more usable than before.<br>My idea is enable the change of the size of the selected tool from the unused keys whith the circles in the XO.<br>
<br>There are other bugs related like OLPC #8864 and OLPC #2154 <br><br>Sorry, the comment say OLC 296, but its Sugarlabs #296<br><br>Gonzalo<br><br><br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2. doesn't properly fix <a href="http://sugarlabs.org" target="_blank">sugarlabs.org</a> #296, some additional tuning of<br>
coordinates may be needed; drawing effect still appears at an offset,<br>
</blockquote></div><br><br><br>From 91f7f7e3ad0311c030c18052654f061f3df3e1df Mon Sep 17 00:00:00 2001<br>From: Gonzalo Odiard <<a href="mailto:godiard@gmail.com">godiard@gmail.com</a>><br>Date: Mon, 31 May 2010 00:56:59 -0300<br>
Subject: [PATCH] fix OLPC #296<br><br>---<br> Area.py | 29 +++++++++++++++++++++-<br> Desenho.py | 78 ++++++++++++++++++++++++-----------------------------------<br> 2 files changed, 60 insertions(+), 47 deletions(-)<br>
<br>diff --git a/Area.py b/Area.py<br>index 44edebb..e81fcdc 100644<br>--- a/Area.py<br>+++ b/Area.py<br>@@ -176,6 +176,11 @@ class Area(gtk.DrawingArea):<br> ##Shapes will be filled or not?<br> self.fill = True<br>
<br>+ # variables to show the tool shape<br>+ self.drawing = False<br>+ self.x_cursor = 0<br>+ self.y_cursor = 0<br>+<br> <br> def setup(self, width, height):<br> """Configure the Area object."""<br>
@@ -256,8 +261,22 @@ class Area(gtk.DrawingArea):<br> widget.window.draw_drawable(self.gc,self.pixmap_temp,area[0],area[1],area[0],area[1],area[2],area[3])<br> else:<br> widget.window.draw_drawable(self.gc,self.pixmap,area[0],area[1],area[0],area[1],area[2],area[3])<br>
+ self.show_tool_shape(widget) <br> return False<br> <br>+ def show_tool_shape(self,widget):<br>+ """ <br>+ Show the shape of the tool selected for pencil, brush, rainbow and eraser<br>
+ """<br>+ if self.tool['name'] in ['pencil','eraser','brush','rainbow']:<br>+ if not self.drawing:<br>+ size = self.tool['line size']<br>
+ if self.tool['line shape'] == 'circle':<br>+ widget.window.draw_arc(self.gc_brush, False, self.x_cursor - size/2, self.y_cursor - size/2, size, size, 0, 360*64)<br>+ else:<br>
+ widget.window.draw_rectangle(self.gc_brush, False, self.x_cursor - size/2, self.y_cursor - size/2, size, size)<br>+<br>+<br> def mousedown(self,widget,event):<br> """Make the Area object (GtkDrawingArea) recognize that the mouse button has been pressed.<br>
<br>@@ -304,14 +323,17 @@ class Area(gtk.DrawingArea):<br> self.last = []<br> self.d.eraser(widget, coords, self.last, self.line_size, self.tool['line shape'])<br> self.last = coords<br>
+ self.drawing = True<br> elif self.tool['name'] == 'brush':<br> self.last = []<br> self.d.brush(widget, coords, self.last, self.line_size, self.tool['line shape'])<br>
self.last = coords<br>+ self.drawing = True<br> elif self.tool['name'] == 'rainbow':<br> self.last = []<br> self.d.rainbow(widget, coords, self.last, self.rainbow_counter,self.line_size, self.tool['line shape'])<br>
self.last = coords<br>+ self.drawing = True<br> elif self.tool['name'] == 'polygon':<br> self.configure_line(self.line_size)<br> if self.polygon_start == False:<br>
@@ -347,6 +369,8 @@ class Area(gtk.DrawingArea):<br> y = event.y<br> state = event.state<br> <br>+ self.x_cursor,self.y_cursor = int(x), int(y)<br>+<br> coords = int(x), int(y)<br> <br>
if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:<br>@@ -419,6 +443,8 @@ class Area(gtk.DrawingArea):<br> self.configure_line(self.line_size)<br> self.d.heart(widget,coords,True,self.tool['fill'])<br>
else:<br>+ if self.tool['name'] in ['brush','eraser','rainbow','pencil'] :<br>+ widget.queue_draw()<br> if self.tool['name'] == 'marquee-rectangular' and self.selmove:<br>
size = self.pixmap_sel.get_size()<br> xi = self.orig_x<br>@@ -520,10 +546,11 @@ class Area(gtk.DrawingArea):<br> self.d.heart(widget,coords,False,self.tool['fill'])<br>
self.enableUndo(widget)<br> <br>- if self.tool['name'] == 'brush' or self.tool['name'] == 'eraser' or self.tool['name'] == 'rainbow' or self.tool['name'] == 'pencil' :<br>
+ if self.tool['name'] in ['brush','eraser','rainbow','pencil'] :<br> self.last = []<br> widget.queue_draw() <br> self.enableUndo(widget)<br>
+ self.drawing = False<br> self.desenha = False<br> <br> def undo(self):<br>diff --git a/Desenho.py b/Desenho.py<br>index e5ecf48..c9a134b 100644<br>--- a/Desenho.py<br>+++ b/Desenho.py<br>@@ -110,20 +110,8 @@ class Desenho:<br>
<br> """<br> widget.desenha = False<br>- if(shape == 'circle'):<br>- widget.pixmap.draw_arc(widget.gc_eraser, True, coords[0], coords[1], size, size, 0, 360*64)<br>
- if last:<br>- widget.gc_eraser.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>- widget.pixmap.draw_line(widget.gc_eraser,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2)<br>
- widget.gc_eraser.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>- if(shape == 'square'):<br>- widget.pixmap.draw_rectangle(widget.gc_eraser, True, coords[0], coords[1], size, size)<br>
- if last:<br>- points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)]<br>- widget.pixmap.draw_polygon(widget.gc_eraser,True,points)<br>- points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)]<br>
- widget.pixmap.draw_polygon(widget.gc_eraser,True,points)<br>- widget.queue_draw()<br>+ self._trace(widget,widget.gc_eraser, coords, last, size, shape)<br>+ #widget.queue_draw()<br> <br>
def brush(self, widget, coords, last, size = 5, shape = 'circle'):<br> """Paint with brush.<br>@@ -137,28 +125,9 @@ class Desenho:<br> <br> """<br> widget.desenha = False<br>
- if(shape == 'circle'):<br>- widget.pixmap.draw_arc(widget.gc_brush, True, coords[0], coords[1], size, size, 0, 360*64)<br>- if last:<br>- widget.gc_brush.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>
- widget.pixmap.draw_line(widget.gc_brush,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2)<br>- widget.gc_brush.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>
- if(shape == 'square'):<br>- widget.pixmap.draw_rectangle(widget.gc_brush, True, coords[0], coords[1], size, size)<br>- if last:<br>- points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)]<br>
- widget.pixmap.draw_polygon(widget.gc_brush,True,points)<br>- points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)]<br>- widget.pixmap.draw_polygon(widget.gc_brush,True,points)<br>
+ self._trace(widget,widget.gc_brush, coords, last, size, shape)<br>+<br> <br>- if last:<br>- x = min(coords[0], last[0])<br>- width = max(coords[0], last[0]) - x<br>- y = min(coords[1], last[1])<br>
- height = max(coords[1], last[1]) - y<br>- widget.queue_draw_area(x, y, width+size, height+size) # We add size to avoid drawing dotted lines<br>- else:<br>- widget.queue_draw()<br>
<br> def rainbow(self, widget, coords, last, color, size = 5, shape = 'circle'):<br> """Paint with rainbow.<br>@@ -190,23 +159,40 @@ class Desenho:<br> <br> widget.gc_rainbow.set_foreground(rainbow_colors[color])<br>
widget.desenha = False<br>+ self._trace(widget,widget.gc_rainbow, coords, last, size, shape)<br>+<br>+<br>+ def _trace(self, widget,gc, coords, last, size, shape):<br> if(shape == 'circle'):<br>
- widget.pixmap.draw_arc(widget.gc_rainbow, True, coords[0], coords[1], size, size, 0, 360*64)<br>+ widget.pixmap.draw_arc(gc, True, coords[0] - size/2, coords[1] - size/2, size, size, 0, 360*64)<br>
if last:<br>- widget.gc_rainbow.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>- widget.pixmap.draw_line(widget.gc_rainbow,last[0]+size/2,last[1]+size/2,coords[0]+size/2,coords[1]+size/2)<br>
- widget.gc_rainbow.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>+ gc.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>
+ widget.pixmap.draw_line(gc, last[0], last[1], coords[0], coords[1])<br>+ gc.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br> if(shape == 'square'):<br>
+ widget.pixmap.draw_rectangle(gc, True, coords[0] - size/2, coords[1] - size/2, size, size)<br> if last:<br>- widget.pixmap.draw_rectangle(widget.gc_rainbow, True, last[0], last[1], size, size)<br>
- points = [coords, last, (last[0]+size,last[1]+size), (coords[0]+size,coords[1]+size)]<br>- widget.pixmap.draw_polygon(widget.gc_rainbow,True,points)<br>- points = [(last[0]+size,last[1]), (coords[0]+size,coords[1]), (coords[0],coords[1]+size), (last[0],last[1]+size)]<br>
- widget.pixmap.draw_polygon(widget.gc_rainbow,True,points)<br>- widget.pixmap.draw_rectangle(widget.gc_rainbow, True, coords[0], coords[1], size, size)<br>- widget.queue_draw()<br>+ points = [(last[0] - size/2,last[1] - size/2), (coords[0] - size/2, coords[1] - size/2), <br>
+ (coords[0] + size/2, coords[1] + size/2) , (last[0] + size/2,last[1] + size/2)]<br>+ widget.pixmap.draw_polygon(gc,True,points)<br>+ points = [(last[0] + size/2,last[1] - size/2), (coords[0] + size/2, coords[1] - size/2), <br>
+ (coords[0] - size/2, coords[1] + size/2) , (last[0] - size/2,last[1] + size/2)]<br>+ widget.pixmap.draw_polygon(gc,True,points)<br>+<br>+<br>+ if last:<br>+ x = min(coords[0], last[0])<br>
+ width = max(coords[0], last[0]) - x<br>+ y = min(coords[1], last[1])<br>+ height = max(coords[1] , last[1]) - y<br>+ widget.queue_draw_area(x-size, y-size, width+size*2, height+size*2) # We add size to avoid drawing dotted lines<br>
+ else:<br>+ widget.queue_draw()<br>+<br> <br> <br>+<br>+<br> def square(self, widget, event, coords, temp, fill):<br> """Draw a square.<br> <br>-- <br>1.6.6.1<br><br>