]> git.sur5r.net Git - glabels/commitdiff
2004-02-02 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 3 Feb 2004 02:11:36 +0000 (02:11 +0000)
committerJim Evins <evins@snaught.com>
Tue, 3 Feb 2004 02:11:36 +0000 (02:11 +0000)
* src/label-object.h:
* src/label-object.c: (gl_label_object_set_size),
(gl_label_object_set_size_honor_aspect):
Added gl_label_object_set_size_honor_aspect() which will maintain the
current aspect ratio by modifying the supplied w or h apropriately.

* src/view-highlight.c: (tl_resize_event_handler),
(tr_resize_event_handler), (bl_resize_event_handler),
(br_resize_event_handler):
Corner handles will now maintain the current aspect ratio if the
control key is pressed while resizing.  This addresses feature
request #816603.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@409 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/ChangeLog
glabels2/src/label-object.c
glabels2/src/label-object.h
glabels2/src/view-highlight.c

index 829ba633a8655a64192d3157e4f435c215e4777f..165c759696211ef8c0f5fc539214832c0cc1ebe6 100644 (file)
@@ -1,3 +1,19 @@
+2004-02-02  Jim Evins  <evins@snaught.com>
+
+       * src/label-object.h:
+       * src/label-object.c: (gl_label_object_set_size),
+       (gl_label_object_set_size_honor_aspect):
+               Added gl_label_object_set_size_honor_aspect() which will maintain the
+               current aspect ratio by modifying the supplied w or h apropriately.
+       
+       * src/view-highlight.c: (tl_resize_event_handler),
+       (tr_resize_event_handler), (bl_resize_event_handler),
+       (br_resize_event_handler):
+               Corner handles will now maintain the current aspect ratio if the
+               control key is pressed while resizing.  This addresses feature
+               request #816603.
+       
+
 2004-01-31  Jim Evins  <evins@snaught.com>
 
        * AUTHORS:
index 1f9b95387411b346bd356ca109e0eced59fa9203..3274873f9f80b269de0ebd395c172f87a65b743d 100644 (file)
@@ -38,6 +38,8 @@ struct _glLabelObjectPrivate {
        gdouble            x, y;
        gdouble            w, h;
        gdouble            affine[6];
+
+       gdouble            aspect_ratio;
 };
 
 enum {
@@ -464,6 +466,46 @@ gl_label_object_set_size (glLabelObject *object,
 
        }
 
+       object->private->aspect_ratio = h / w;
+
+       g_signal_emit (G_OBJECT(object), signals[CHANGED], 0);
+
+       gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Set size of object honoring current aspect ratio.                         */
+/*****************************************************************************/
+void
+gl_label_object_set_size_honor_aspect (glLabelObject *object,
+                                      gdouble        w,
+                                      gdouble        h)
+{
+       gl_debug (DEBUG_LABEL, "START");
+
+       g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+       if ( h > w*object->private->aspect_ratio ) {
+
+               h = w * object->private->aspect_ratio;
+
+       } else {
+
+               w = h / object->private->aspect_ratio;
+
+       }
+
+       if ( GL_LABEL_OBJECT_GET_CLASS(object)->set_size != NULL ) {
+
+               /* We have an object specific method, use it */
+               GL_LABEL_OBJECT_GET_CLASS(object)->set_size (object, w, h);
+
+       } else {
+
+               set_size (object, w, h);
+
+       }
+
        g_signal_emit (G_OBJECT(object), signals[CHANGED], 0);
 
        gl_debug (DEBUG_LABEL, "END");
index 1ffa6209d82bfc99a13922d447b065e5cb0e584c..afc17708faa7b8b062bda001f280fb8f04089102 100644 (file)
@@ -191,6 +191,10 @@ void           gl_label_object_set_size              (glLabelObject     *object,
                                                      gdouble            w,
                                                      gdouble            h);
 
+void           gl_label_object_set_size_honor_aspect (glLabelObject     *object,
+                                                     gdouble            w,
+                                                     gdouble            h);
+
 void           gl_label_object_get_size              (glLabelObject     *object,
                                                      gdouble           *w,
                                                      gdouble           *h);
index 247190a565d64ab1414c6cb4c57d8bec84a45f96..67659800adb122bdd310574b9a3eb2442cfbf3f1 100644 (file)
@@ -982,11 +982,12 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item,
                         GdkEvent        *event,
                         glViewHighlight *view_highlight)
 {
-       gdouble x0, y0, w, h;
-       gdouble x1, y1, x2, y2;
-       static gboolean dragging = FALSE;
-       glLabelObject *object;
-       GdkCursor *cursor;
+       gdouble          x0, y0, w, h;
+       gdouble          x1, y1, x2, y2;
+       static gboolean  dragging = FALSE;
+       glLabelObject   *object;
+       GdkCursor       *cursor;
+       gboolean         is_control_pressed;
 
        if ( view_highlight->private->view->state != GL_VIEW_STATE_ARROW ) {
                /* don't interfere with object creation modes */
@@ -1015,6 +1016,7 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item,
        case GDK_BUTTON_RELEASE:
                switch (event->button.button) {
                case 1:
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        dragging = FALSE;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
@@ -1022,15 +1024,20 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item,
                                                  event->button.time);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE);
-                       y1 = MIN (event->button.y, y2 - MIN_ITEM_SIZE);
                        w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
                        h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       gl_label_object_get_size (object, &w, &h);
+                       x1 = x2 - w;
+                       y1 = y2 - h;
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
 
                default:
@@ -1039,19 +1046,25 @@ tl_resize_event_handler (GnomeCanvasItem *handle_item,
 
        case GDK_MOTION_NOTIFY:
                if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       x1 = MIN (event->motion.x, x2 - MIN_ITEM_SIZE);
-                       y1 = MIN (event->motion.y, y2 - MIN_ITEM_SIZE);
                        w = MAX (x2 - event->motion.x, MIN_ITEM_SIZE);
                        h = MAX (y2 - event->motion.y, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       gl_label_object_get_size (object, &w, &h);
+                       x1 = x2 - w;
+                       y1 = y2 - h;
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
                } else {
                        return FALSE;
@@ -1085,11 +1098,12 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item,
                         GdkEvent        *event,
                         glViewHighlight *view_highlight)
 {
-       gdouble x0, y0, w, h;
-       gdouble x1, y1, x2, y2;
-       static gboolean dragging = FALSE;
-       glLabelObject *object;
-       GdkCursor *cursor;
+       gdouble          x0, y0, w, h;
+       gdouble          x1, y1, x2, y2;
+       static gboolean  dragging = FALSE;
+       glLabelObject   *object;
+       GdkCursor       *cursor;
+       gboolean         is_control_pressed;
 
        if ( view_highlight->private->view->state != GL_VIEW_STATE_ARROW ) {
                /* don't interfere with object creation modes */
@@ -1118,6 +1132,7 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item,
        case GDK_BUTTON_RELEASE:
                switch (event->button.button) {
                case 1:
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        dragging = FALSE;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
@@ -1125,15 +1140,20 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item,
                                                  event->button.time);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       /* x1 unchanged */
-                       y1 = MIN (event->button.y, y2 - MIN_ITEM_SIZE);
                        w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
                        h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       gl_label_object_get_size (object, &w, &h);
+                       /* x1 unchanged */
+                       y1 = y2 - h;
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
 
                default:
@@ -1142,19 +1162,25 @@ tr_resize_event_handler (GnomeCanvasItem *handle_item,
 
        case GDK_MOTION_NOTIFY:
                if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       /* x1 unchanged */
-                       y1 = MIN (event->button.y, y2 - MIN_ITEM_SIZE);
                        w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
                        h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       gl_label_object_get_size (object, &w, &h);
+                       /* x1 unchanged */
+                       y1 = y2 - h;
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
                } else {
                        return FALSE;
@@ -1188,11 +1214,12 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item,
                         GdkEvent        *event,
                         glViewHighlight *view_highlight)
 {
-       gdouble x0, y0, w, h;
-       gdouble x1, y1, x2, y2;
-       static gboolean dragging = FALSE;
-       glLabelObject *object;
-       GdkCursor *cursor;
+       gdouble          x0, y0, w, h;
+       gdouble          x1, y1, x2, y2;
+       static gboolean  dragging = FALSE;
+       glLabelObject   *object;
+       GdkCursor       *cursor;
+       gboolean         is_control_pressed;
 
        if ( view_highlight->private->view->state != GL_VIEW_STATE_ARROW ) {
                /* don't interfere with object creation modes */
@@ -1221,6 +1248,7 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item,
        case GDK_BUTTON_RELEASE:
                switch (event->button.button) {
                case 1:
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        dragging = FALSE;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
@@ -1228,15 +1256,20 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item,
                                                  event->button.time);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE);
-                       /* y1 unchanged */
                        w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
                        h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       gl_label_object_get_size (object, &w, &h);
+                       x1 = x2 - w;
+                       /* y1 unchanged */
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
 
                default:
@@ -1245,19 +1278,25 @@ bl_resize_event_handler (GnomeCanvasItem *handle_item,
 
        case GDK_MOTION_NOTIFY:
                if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE);
-                       /* y1 unchanged */
                        w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
                        h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       gl_label_object_get_size (object, &w, &h);
+                       x1 = x2 - w;
+                       /* y1 unchanged */
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
                } else {
                        return FALSE;
@@ -1291,11 +1330,12 @@ br_resize_event_handler (GnomeCanvasItem *handle_item,
                         GdkEvent        *event,
                         glViewHighlight *view_highlight)
 {
-       gdouble x0, y0, w, h;
-       gdouble x1, y1, x2, y2;
-       static gboolean dragging = FALSE;
-       glLabelObject *object;
-       GdkCursor *cursor;
+       gdouble          x0, y0, w, h;
+       gdouble          x1, y1, x2, y2;
+       static gboolean  dragging = FALSE;
+       glLabelObject   *object;
+       GdkCursor       *cursor;
+       gboolean         is_control_pressed;
 
        if ( view_highlight->private->view->state != GL_VIEW_STATE_ARROW ) {
                /* don't interfere with object creation modes */
@@ -1326,6 +1366,7 @@ br_resize_event_handler (GnomeCanvasItem *handle_item,
                gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
                switch (event->button.button) {
                case 1:
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        dragging = FALSE;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
@@ -1333,15 +1374,19 @@ br_resize_event_handler (GnomeCanvasItem *handle_item,
                                                  event->button.time);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       /* x1 unchanged */
-                       /* y1 unchanged */
                        w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
                        h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
+                       /* x1 unchanged */
+                       /* y1 unchanged */
                        x0 = x0 + x1;
                        y0 = y0 + y1;
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
 
                default:
@@ -1351,19 +1396,24 @@ br_resize_event_handler (GnomeCanvasItem *handle_item,
        case GDK_MOTION_NOTIFY:
                gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
                if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+                       is_control_pressed = event->button.state & GDK_CONTROL_MASK;
                        get_origin_and_corners (view_highlight,
                                                &x0, &y0, &x1, &y1, &x2, &y2);
                        gnome_canvas_item_w2i (view_highlight->private->group,
                                               &event->button.x, &event->button.y);
-                       /* x1 unchanged */
-                       /* y1 unchanged */
                        w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
                        h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
+                       if (is_control_pressed) {
+                               gl_label_object_set_size_honor_aspect (object, w, h);
+                       } else {
+                               gl_label_object_set_size (object, w, h);
+                       }
                        x0 = x0 + x1;
                        y0 = y0 + y1;
+                       /* x1 unchanged */
+                       /* y1 unchanged */
                        gnome_canvas_item_i2w (view_highlight->private->group, &x0, &y0);
                        gl_label_object_set_position (object, x0, y0);
-                       gl_label_object_set_size (object, w, h);
                        return TRUE;
                } else {
                        return FALSE;