This patch change:
* Show the shape and the size with the pencil, brush, eraser and rainbow.
* Center this tools at the cursor coordinates
I think it's more usable than before.
My idea is enable the change of the size of the selected tool from the
unused keys whith the circles in the XO.

There are other bugs related like OLPC #8864 and OLPC #2154

Sorry, the comment say OLC 296, but its Sugarlabs #296

Gonzalo



2.  doesn't properly fix sugarlabs.org #296, some additional tuning of
> coordinates may be needed; drawing effect still appears at an offset,
>



>From 91f7f7e3ad0311c030c18052654f061f3df3e1df Mon Sep 17 00:00:00 2001
From: Gonzalo Odiard <godi...@gmail.com>
Date: Mon, 31 May 2010 00:56:59 -0300
Subject: [PATCH] fix OLPC #296

---
 Area.py    |   29 +++++++++++++++++++++-
 Desenho.py |   78
++++++++++++++++++++++++-----------------------------------
 2 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/Area.py b/Area.py
index 44edebb..e81fcdc 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.

-- 
1.6.6.1

Attachment: 0001-fix-OLPC-296.patch
Description: Binary data

_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to