[Sugar-devel] [PATCH] New suggestion for arrow drawing in Paint activity.olpc4170

Anurag Chowdhury anurag at seeta.in
Wed Oct 20 17:32:31 EDT 2010


In the paint activity's shape tool we were able to make only horizontal arrows,
so now we have added a new tool which makes vertical arrows.

---
 Area.py    |    8 ++++++++
 Desenho.py |   31 +++++++++++++++++++++++++++++++
 toolbox.py |   21 +++++++++++++++++++++
 3 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/Area.py b/Area.py
index 2dca7da..56c4267 100644
--- a/Area.py
+++ b/Area.py
@@ -438,6 +438,10 @@ class Area(gtk.DrawingArea):
                 elif self.tool['name'] == 'arrow':
                     self.configure_line(self.line_size)
                     self.d.arrow(widget,coords,True,self.tool['fill'])
+
+                elif self.tool['name'] == 'vertical arrow':
+                    self.d.arrow_vertical(widget,coords,False,\
+                    self.tool['fill'])
+                    self.enableUndo(widget)

                 elif self.tool['name'] == 'parallelogram':
                     self.configure_line(self.line_size)
@@ -541,6 +545,10 @@ class Area(gtk.DrawingArea):
             elif self.tool['name'] == 'arrow':
                 self.d.arrow(widget,coords,False,self.tool['fill'])
                 self.enableUndo(widget)
+
+            elif self.tool['name'] == 'vertical arrow':
+                self.d.arrow_vertical(widget,coords,False,self.tool['fill'])
+                self.enableUndo(widget)

             elif self.tool['name'] == 'parallelogram':
                 self.d.parallelogram(widget,coords,False,self.tool['fill'])
diff --git a/Desenho.py b/Desenho.py
index c9a134b..e90a45c 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -298,6 +298,37 @@ class Desenho:
         pixmap.draw_polygon(widget.gc_line,False,points)
         widget.queue_draw()
         
+    def arrow_vertical(self, widget, coords, temp, fill):
+        """Draw a arrow.
+
+            @param  self -- Desenho.Desenho instance
+            @param  widget -- Area object (GtkDrawingArea)
+            @param  coords -- Two value tuple
+            @param  temp -- switch between pixmap and pixmap_temp
+            @param  fill -- Fill object
+
+        """
+        if temp == True:
+            pixmap = widget.pixmap_temp
+        else:
+            pixmap = widget.pixmap
+        width, height = widget.window.get_size()
+
+        x = widget.oldx - coords[0]
+        y = widget.oldy - coords[1]
+        points = [(widget.oldx,widget.oldy),\
+(widget.oldx+x,widget.oldy-int(y/6)),\
+(widget.oldx+int(x/2),widget.oldy-int(y/6)),\
+(widget.oldx+int(x/2),widget.oldy-y),\
+(widget.oldx-int(x/2),widget.oldy-y),\
+(widget.oldx-int(x/2),widget.oldy-int(y/6)),\
+(widget.oldx-x,widget.oldy-int(y/6))]
+        pixmap.draw_drawable(widget.gc,widget.pixmap,0,0,0,0,width,height)
+        if fill == True:
+            pixmap.draw_polygon(widget.gc,True,points)
+        pixmap.draw_polygon(widget.gc_line,False,points)
+        widget.queue_draw()
+        
         
     def parallelogram(self, widget, coords, temp, fill):
         """Draw a parallelogram.
diff --git a/toolbox.py b/toolbox.py
index 299181b..520e5f0 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -613,6 +613,15 @@ class ShapesToolbar(gtk.Toolbar):
         'fill'          : True,
         'vertices'      : 5
     }
+    _SHAPE_ARROW_VERTICAL= {
+        'name'          : 'vertical arrow',
+        'line size'     : 5,
+        'fill color'    : None,
+        'stroke color'  : None,
+        'line shape'    : 'circle',
+        'fill'          : True,
+        'vertices'      : 5
+    }
     _SHAPE_CURVE = {
         'name'          : 'curve',
         'line size'     : 2,
@@ -795,6 +804,13 @@ class ShapesToolbar(gtk.Toolbar):
             self._configure_palette_shape_arrow()
         except:
             logging.debug('Could not create palette for Shape Arrow')
+        
+        self._shape_arrow_vertical = DrawToolButton\
+        ('tool-shape-arrow-vertical',activity.tool_group,_('Arrow-Vertical'))
+        self.insert(self._shape_arrow_vertical, -1)
+        try:
+            self._configure_palette_shape_arrow_vertical()
+        except:
+            logging.debug('Could not create palette for Shape Vertical Arrow')
 
         self._shape_star = DrawToolButton('tool-shape-star', activity.tool_group,_('Star'))
         self.insert(self._shape_star, -1)
@@ -819,6 +835,7 @@ class ShapesToolbar(gtk.Toolbar):
         
         
         self._shape_arrow.connect('clicked', self.set_tool, self._SHAPE_ARROW)
+        self._shape_arrow_vertical.connect('clicked', self.set_tool,\
+        self._SHAPE_ARROW_VERTICAL)
         self._shape_ellipse.connect('clicked', self.set_tool, self._SHAPE_ELLIPSE)
         self._shape_freeform.connect('clicked', self.set_tool, self._SHAPE_FREEFORM)
         self._shape_heart.connect('clicked', self.set_tool, self._SHAPE_HEART)
@@ -908,6 +925,10 @@ class ShapesToolbar(gtk.Toolbar):
         logging.debug('Creating palette to shape arrow')
         self._create_simple_palette(self._shape_arrow, self._SHAPE_ARROW)
     
+    def _configure_palette_shape_arrow_vertical(self):
+        logging.debug('Creating palette to shape Vertical arrow')
+        self._create_simple_palette(self._shape_arrow_vertical,\
+        self._SHAPE_ARROW_VERTICAL)
+       
     def _configure_palette_shape_star(self):
         logging.debug('Creating palette to shape star')
         
-- 
1.7.2.3


More information about the Sugar-devel mailing list