From: Jim Evins Date: Tue, 3 Feb 2004 02:11:36 +0000 (+0000) Subject: 2004-02-02 Jim Evins X-Git-Tag: glabels-2_3_0~487 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6c3073bcc36e8c9e2c46e743b48f559970a14e12;p=glabels 2004-02-02 Jim Evins * 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 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 829ba633..165c7596 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,19 @@ +2004-02-02 Jim Evins + + * 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 * AUTHORS: diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index 1f9b9538..3274873f 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -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"); diff --git a/glabels2/src/label-object.h b/glabels2/src/label-object.h index 1ffa6209..afc17708 100644 --- a/glabels2/src/label-object.h +++ b/glabels2/src/label-object.h @@ -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); diff --git a/glabels2/src/view-highlight.c b/glabels2/src/view-highlight.c index 247190a5..67659800 100644 --- a/glabels2/src/view-highlight.c +++ b/glabels2/src/view-highlight.c @@ -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;