Commited, thanks.<br><br>Gonzalo<br><br><br><div class="gmail_quote">On Thu, Oct 28, 2010 at 5:17 PM, Ayush Goyal <span dir="ltr"><<a href="mailto:ayush@seeta.in">ayush@seeta.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">Added fixed aspect ratio mode for line,ellipse and rectangle tool using Shift<br>
</div>key as mask or using a keep aspect ratio checkbox from palette.This allows<br>
<div class="im">drawing of straight lines & 45 degree lines from line tool,circle from<br>
ellipse tool and square from rectangle tool<br>
<br>
Signed-off-by: Ayush Goyal <<a href="mailto:ayush@seeta.in">ayush@seeta.in</a>><br>
---<br>
</div> Area.py    |   40 +++++++++++++++++++++++++++++++++++++++-<br>
 toolbox.py |   11 +++++++++++<br>
 2 files changed, 50 insertions(+), 1 deletions(-)<br>
 v1->v2:Added checkbox for keep aspect in shape menu palette<br>
<div class="im"><br>
diff --git a/Area.py b/Area.py<br>
</div>index ba06758..db84e65 100644<br>
<div class="im">--- a/Area.py<br>
+++ b/Area.py<br>
</div>@@ -173,6 +173,10 @@ class Area(gtk.DrawingArea):<br>
         self.last = []<br>
         self.rainbow_counter = 0<br>
         self.keep_aspect_ratio = False<br>
+        self.keep_ratio = {<br>
+            'line': False,<br>
+            'rectangle': False,<br>
+            'ellipse': False}<br>
<br>
         self.font = pango.FontDescription('Sans 9')<br>
         self._set_selection_bounds(0, 0, 0, 0)<br>
@@ -411,6 +415,13 @@ class Area(gtk.DrawingArea):<br>
         self.x_cursor, self.y_cursor = int(x), int(y)<br>
<div class="im"><br>
         coords = int(x), int(y)<br>
</div>+        if self.tool['name'] in ['rectangle', 'ellipse', 'line']:<br>
+            if (state & gtk.gdk.SHIFT_MASK) or \<br>
+                self.keep_ratio[self.tool['name']]:<br>
<div class="im">+                if self.tool['name'] in ['rectangle', 'ellipse']:<br>
+                    coords = self._keep_selection_ratio(coords)<br>
+                elif self.tool['name'] == 'line':<br>
+                    coords = self._keep_line_ratio(coords)<br>
<br>
         if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None:<br>
             if self.tool['name'] == 'pencil':<br>
</div>@@ -530,11 +541,19 @@ class Area(gtk.DrawingArea):<br>
<div class="im">             @param  event -- GdkEvent<br>
         """<br>
         coords = int(event.x), int(event.y)<br>
</div>+        if self.tool['name'] in ['rectangle', 'ellipse', 'line']:<br>
+            if (event.state & gtk.gdk.SHIFT_MASK) or \<br>
+                self.keep_ratio[self.tool['name']]:<br>
<div class="im">+                if self.tool['name'] in ['rectangle', 'ellipse']:<br>
+                    coords = self._keep_selection_ratio(coords)<br>
+                if self.tool['name'] == 'line':<br>
+                    coords = self._keep_line_ratio(coords)<br>
+<br>
         width, height = self.window.get_size()<br>
         if self.desenha or self.sel_get_out:<br>
             if self.tool['name'] == 'line':<br>
                 self.pixmap.draw_line(self.gc_line, self.oldx, self.oldy,<br>
-                    int(event.x), int(event.y))<br>
+                    coords[0], coords[1])<br>
                 widget.queue_draw()<br>
                 self.enableUndo(widget)<br>
<br>
</div>@@ -1411,3 +1430,22 @@ class Area(gtk.DrawingArea):<br>
<div class="im"><br>
         return (self.oldx + sign(dx) * size,<br>
                 self.oldy + sign(dy) * size)<br>
+<br>
+    def _keep_line_ratio(self, coords):<br>
+<br>
+        def sign(x):<br>
+            return x and x / abs(x) or 0<br>
+<br>
+        dx = int(coords[0]) - self.oldx<br>
+        dy = int(coords[1]) - self.oldy<br>
+        size = max(abs(dx), abs(dy))<br>
+<br>
+        if abs(dx) > 0.5 * size and abs(dy) > 0.5 * size:<br>
+            return (self.oldx + sign(dx) * size,<br>
+                   self.oldy + sign(dy) * size)<br>
+        elif abs(dx) < 0.5 * size and abs(dy) > 0.5 * size:<br>
+            return (self.oldx,<br>
+                   self.oldy + sign(dy) * size)<br>
+        elif abs(dx) > 0.5 * size and abs(dy) < 0.5 * size:<br>
+            return (self.oldx + sign(dx) * size,<br>
+                   self.oldy)<br>
</div>diff --git a/toolbox.py b/toolbox.py<br>
index 3c8ab92..e8569c8 100644<br>
--- a/toolbox.py<br>
+++ b/toolbox.py<br>
@@ -855,6 +855,10 @@ class ShapesToolbar(gtk.Toolbar):<br>
         tool['fill'] = checkbutton.get_active()<br>
         self.set_tool(tool=tool)<br>
<br>
+    def _on_keep_aspect_checkbutton_toggled(self, checkbutton, tool):<br>
+        self._activity.area.keep_ratio[tool['name']] = checkbutton.get_active()<br>
+        self.set_tool(tool=tool)<br>
+<br>
     def _configure_palette_shape_ellipse(self):<br>
         logging.debug('Creating palette to shape ellipse')<br>
         self._create_simple_palette(self._shape_ellipse, self._SHAPE_ELLIPSE)<br>
@@ -960,6 +964,13 @@ class ShapesToolbar(gtk.Toolbar):<br>
         palette.content_box = gtk.VBox()<br>
         palette.set_content(palette.content_box)<br>
<br>
+        if tool['name'] in ['rectangle', 'ellipse', 'line']:<br>
+            keep_aspect_checkbutton = gtk.CheckButton(_('Keep Aspect'))<br>
+            ratio = self._activity.area.keep_ratio[tool['name']]<br>
+            keep_aspect_checkbutton.set_active(ratio)<br>
+            keep_aspect_checkbutton.connect('toggled',<br>
+                self._on_keep_aspect_checkbutton_toggled, tool)<br>
+            palette.content_box.pack_start(keep_aspect_checkbutton)<br>
         # Fill option<br>
         if not line_size_only:<br>
             fill_checkbutton = gtk.CheckButton(_('Fill'))<br>
<font color="#888888">--<br>
1.7.1<br>
<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Gonzalo Odiard<br><br><br>