]> git.sur5r.net Git - glabels/commitdiff
2004-02-02 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 3 Feb 2004 04:31:17 +0000 (04:31 +0000)
committerJim Evins <evins@snaught.com>
Tue, 3 Feb 2004 04:31:17 +0000 (04:31 +0000)
* src/label-image.c: (gl_label_image_set_filename):
When setting a new filename adjust size such that the aspect ratio of
the image is preserved using the current size as a bounding box.

* src/view-image.c: (update_object_from_editor_cb):
When updating object from editor, feed back possible size changes to
editor as a result of a possible change in image.

* src/object-editor-size-page.c: (size_reset_cb):
Fixed typo when blocking spin handlers.  If the base size is larger than
the max size, treat max size as a bounding box while keeping aspect
ratio.

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

glabels2/ChangeLog
glabels2/src/label-image.c
glabels2/src/object-editor-size-page.c
glabels2/src/view-image.c

index 165c759696211ef8c0f5fc539214832c0cc1ebe6..00aa3a24043322bf3016edcf5c3f80f933a89539 100644 (file)
@@ -1,3 +1,19 @@
+2004-02-02  Jim Evins  <evins@snaught.com>
+
+       * src/label-image.c: (gl_label_image_set_filename):
+               When setting a new filename adjust size such that the aspect ratio of
+               the image is preserved using the current size as a bounding box.
+               
+       * src/view-image.c: (update_object_from_editor_cb):
+               When updating object from editor, feed back possible size changes to
+               editor as a result of a possible change in image.
+       
+       * src/object-editor-size-page.c: (size_reset_cb):
+               Fixed typo when blocking spin handlers.  If the base size is larger than
+               the max size, treat max size as a bounding box while keeping aspect
+               ratio.
+               
+
 2004-02-02  Jim Evins  <evins@snaught.com>
 
        * src/label-object.h:
index 1ab49aa47747ea47ac2c55249e1452374d13bc42..0f51bc8994e5784e90b8e2a5a9bd29b87e881c45 100644 (file)
@@ -199,6 +199,7 @@ gl_label_image_set_filename (glLabelImage *limage,
        glTextNode  *old_filename;
        GHashTable  *pixbuf_cache;
        GdkPixbuf   *pixbuf;
+       gdouble      image_w, image_h, aspect_ratio, w, h;
 
        gl_debug (DEBUG_LABEL, "START");
 
@@ -242,6 +243,19 @@ gl_label_image_set_filename (glLabelImage *limage,
                }
        }
 
+       /* Treat current size as a bounding box, scale image to maintain aspect
+        * ratio while fitting it in this bounding box. */
+       image_w = gdk_pixbuf_get_width (limage->private->pixbuf);
+       image_h = gdk_pixbuf_get_height (limage->private->pixbuf);
+       aspect_ratio = image_h / image_w;
+       gl_label_object_get_size (GL_LABEL_OBJECT(limage), &w, &h);
+       if ( h > w*aspect_ratio ) {
+               h = w * aspect_ratio;
+       } else {
+               w = h / aspect_ratio;
+       }
+       gl_label_object_set_size (GL_LABEL_OBJECT(limage), w, h);
+
        gl_label_object_emit_changed (GL_LABEL_OBJECT(limage));
 
        gl_debug (DEBUG_LABEL, "END");
index 85b26cec2cdafb737f748becd7f1731ffbe88697..9b28938748f117886d2f27e9e89501356dd9fd94 100644 (file)
@@ -230,16 +230,38 @@ static void
 size_reset_cb (glObjectEditor *editor)
 {
        gdouble w_base, h_base;
+       gdouble w_max, h_max;
+       gdouble aspect_ratio;
 
        g_signal_handlers_block_by_func (G_OBJECT (editor->priv->size_w_spin),
-                                        G_CALLBACK (h_spin_cb),
+                                        G_CALLBACK (w_spin_cb),
                                         editor);
        g_signal_handlers_block_by_func (G_OBJECT (editor->priv->size_h_spin),
                                         G_CALLBACK (h_spin_cb),
                                         editor);
 
-       w_base = editor->priv->w_base * editor->priv->units_per_point;
-       h_base = editor->priv->h_base * editor->priv->units_per_point;
+       w_base = editor->priv->w_base;
+       h_base = editor->priv->h_base;
+
+       w_max = editor->priv->w_max;
+       h_max = editor->priv->h_max;
+
+       if ( (w_base > w_max) || (h_base > h_max) ) {
+
+               aspect_ratio = h_base / w_base;
+
+               if ( h_max > w_max*aspect_ratio ) {
+                       w_base = w_max;
+                       h_base = w_max * aspect_ratio;
+
+               } else {
+                       w_base = h_max / aspect_ratio;
+                       h_base = h_max;
+               }
+       }
+
+       w_base *= editor->priv->units_per_point;
+       h_base *= editor->priv->units_per_point;
 
        gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->size_w_spin),
                                   w_base);
@@ -247,7 +269,7 @@ size_reset_cb (glObjectEditor *editor)
                                   h_base);
 
        g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->size_w_spin),
-                                          G_CALLBACK (h_spin_cb),
+                                          G_CALLBACK (w_spin_cb),
                                           editor);
        g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->size_h_spin),
                                           G_CALLBACK (h_spin_cb),
index 287d0e8865f0803ef252edee100e15282b727197..1521b300c00f2294d62d15c7289127ddb2596236 100644 (file)
@@ -283,6 +283,8 @@ update_object_from_editor_cb (glObjectEditor *editor,
 {
        gdouble            x, y, w, h;
        glTextNode        *filename;
+       const GdkPixbuf   *pixbuf;
+       gdouble            image_w, image_h;
 
        gl_debug (DEBUG_VIEW, "START");
 
@@ -303,6 +305,16 @@ update_object_from_editor_cb (glObjectEditor *editor,
        filename = gl_object_editor_get_image (editor);
        gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename);
 
+       /* Setting filename may have modified the size. */
+       gl_label_object_get_size (object, &w, &h);
+       gl_object_editor_set_size (editor, w, h);
+
+       /* It may also have a new base size. */
+        pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object), NULL);
+        image_w = gdk_pixbuf_get_width (pixbuf);
+        image_h = gdk_pixbuf_get_height (pixbuf);
+       gl_object_editor_set_base_size (editor, image_w, image_h);
+
        g_signal_handlers_unblock_by_func (G_OBJECT(object),
                                           update_editor_from_object_cb,
                                           editor);