summaryrefslogtreecommitdiff
path: root/libeog
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@redhat.com>1999-09-17 18:51:05 +0000
committerArturo Espinosa <unammx@src.gnome.org>1999-09-17 18:51:05 +0000
commit5673c8f06ff9c65a486e73c5a7140596c3bf3d47 (patch)
treea573ca10982e45855e6a5295d10b60b51e2b07dc /libeog
parent6844390535a1b66ed9cda7755dfd305acf0a9312 (diff)
downloadeog-5673c8f06ff9c65a486e73c5a7140596c3bf3d47.tar.gz
Set the canvas scroll region based on the image size.
1999-09-17 Federico Mena Quintero <federico@redhat.com> * ui-image.c (ui_image_set_image): Set the canvas scroll region based on the image size. * zoom.[ch]: New files with utilitiy functions for computing zoom factors. * Makefile.am (eog_SOURCES): Added zoom.[ch] to the sources. * window.c (WindowPrivate): Added a bin field. Now we put the contents in a simple bin because GnomeApp does not like its contents to be removed and added again. (window_construct): Create the bin. (set_mode): Put the real contents in the bin.
Diffstat (limited to 'libeog')
-rw-r--r--libeog/ui-image.c9
-rw-r--r--libeog/zoom.c109
-rw-r--r--libeog/zoom.h40
3 files changed, 157 insertions, 1 deletions
diff --git a/libeog/ui-image.c b/libeog/ui-image.c
index 1bf3b00b..1bcc7e87 100644
--- a/libeog/ui-image.c
+++ b/libeog/ui-image.c
@@ -215,6 +215,7 @@ void
ui_image_set_image (UIImage *ui, Image *image)
{
UIImagePrivate *priv;
+ int w, h;
g_return_if_fail (ui != NULL);
g_return_if_fail (IS_UI_IMAGE (ui));
@@ -236,5 +237,11 @@ ui_image_set_image (UIImage *ui, Image *image)
"image", image,
NULL);
- /* FIXME: set the scroll region and zoom */
+ if (image->buf) {
+ w = image->buf->art_pixbuf->width;
+ h = image->buf->art_pixbuf->height;
+ } else
+ w = h = 0;
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS (priv->canvas), 0.0, 0.0, w, h);
}
diff --git a/libeog/zoom.c b/libeog/zoom.c
new file mode 100644
index 00000000..a246b606
--- /dev/null
+++ b/libeog/zoom.c
@@ -0,0 +1,109 @@
+/* Eye of Gnome image viewer - utility functions for computing zoom factors
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Author: Federico Mena-Quintero <federico@gimp.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "zoom.h"
+
+
+
+/**
+ * zoom_fit_size:
+ * @dest_width: Width of destination area.
+ * @dest_height: Height of destination area.
+ * @src_width: Width of source image.
+ * @src_height: Height of source image.
+ * @upscale_smaller: Whether to scale up images smaller than the destination size.
+ * @width: Return value for image width.
+ * @height: Return value for image height.
+ *
+ * Computes the final dimensions of an image that is to be scaled to fit to a
+ * certain size. If @upscale_smaller is TRUE, then images smaller than the
+ * destination size will be scaled up; otherwise, they will be left at their
+ * original size.
+ **/
+void
+zoom_fit_size (guint dest_width, guint dest_height,
+ guint src_width, guint src_height,
+ gboolean upscale_smaller,
+ guint *width, guint *height)
+{
+ guint w, h;
+
+ g_return_if_fail (width != NULL);
+ g_return_if_fail (height != NULL);
+
+ if (src_width == 0 || src_height == 0) {
+ *width = 0;
+ *height = 0;
+ return;
+ }
+
+ if (src_width <= dest_width && src_height <= dest_height && !upscale_smaller) {
+ *width = src_width;
+ *height = src_height;
+ return;
+ }
+
+ w = dest_width;
+ h = (src_height * w) / src_width;
+
+ if (h > dest_height) {
+ h = dest_height;
+ w = (src_width * h) / src_height;
+ }
+
+ g_assert (w <= dest_width);
+ g_assert (h <= dest_height);
+
+ *width = w;
+ *height = h;
+}
+
+/**
+ * zoom_fit_scale:
+ * @dest_width: Width of destination area.
+ * @dest_height: Height of destination area.
+ * @src_width: Width of source image.
+ * @src_height: Height of source image.
+ * @upscale_smaller: Whether to scale up images smaller than the destination size.
+ *
+ * Similar to zoom_fit_size(), but returns the zoom factor of the final image
+ * with respect to the original image's size.
+ *
+ * Return value: Zoom factor with respect to the original size.
+ **/
+double
+zoom_fit_scale (guint dest_width, guint dest_height,
+ guint src_width, guint src_height,
+ gboolean upscale_smaller)
+{
+ guint w, h;
+ double wfactor, hfactor;
+
+ if (src_width == 0 || src_height == 0)
+ return 1.0;
+
+ zoom_fit_size (dest_width, dest_height, src_width, src_height, upscale_smaller, &w, &h);
+
+ wfactor = (double) w / src_width;
+ hfactor = (double) h / src_height;
+
+ return MIN (wfactor, hfactor);
+}
diff --git a/libeog/zoom.h b/libeog/zoom.h
new file mode 100644
index 00000000..73ddfff4
--- /dev/null
+++ b/libeog/zoom.h
@@ -0,0 +1,40 @@
+/* Eye of Gnome image viewer - utility functions for computing zoom factors
+ *
+ * Copyright (C) 1999 The Free Software Foundation
+ *
+ * Author: Federico Mena-Quintero <federico@gimp.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef ZOOM_H
+#define ZOOM_H
+
+#include <glib.h>
+
+
+
+void zoom_fit_size (guint dest_width, guint dest_height,
+ guint src_width, guint src_height,
+ gboolean upscale_smaller,
+ guint *width, guint *height);
+
+double zoom_fit_scale (guint dest_width, guint dest_height,
+ guint src_width, guint src_height,
+ gboolean upscale_smaller);
+
+
+
+#endif