gimp r26185 - in trunk: . app/display
- From: martinn svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26185 - in trunk: . app/display
- Date: Sun, 13 Jul 2008 20:23:15 +0000 (UTC)
Author: martinn
Date: Sun Jul 13 20:23:15 2008
New Revision: 26185
URL: http://svn.gnome.org/viewvc/gimp?rev=26185&view=rev
Log:
2008-07-13 Martin Nordholts <martinn svn gnome org>
* app/display/gimpdisplayshell-scale.[ch]
(gimp_display_shell_center_image): Allow to choose what axes to
center on.
(gimp_display_shell_scale_fill)
(gimp_display_shell_scale_fit_in): Explicitly center on both axes.
* app/display/gimpdisplayshell.c (gimp_display_shell_fill): Center
the image in the filled display shell. Rather hackish, but seems
to work fine.
Modified:
trunk/ChangeLog
trunk/app/display/gimpdisplayshell-scale.c
trunk/app/display/gimpdisplayshell-scale.h
trunk/app/display/gimpdisplayshell.c
Modified: trunk/app/display/gimpdisplayshell-scale.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-scale.c (original)
+++ trunk/app/display/gimpdisplayshell-scale.c Sun Jul 13 20:23:15 2008
@@ -431,7 +431,7 @@
(gdouble) shell->disp_height / (gdouble) image_height);
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
- gimp_display_shell_center_image (shell);
+ gimp_display_shell_center_image (shell, TRUE, TRUE);
}
/**
@@ -470,18 +470,22 @@
(gdouble) shell->disp_height / (gdouble) image_height);
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
- gimp_display_shell_center_image (shell);
+ gimp_display_shell_center_image (shell, TRUE, TRUE);
}
/**
* gimp_display_shell_center_image:
* @shell:
+ * @horizontally:
+ * @vertically:
*
- * Centers the image in the display shell.
+ * Centers the image in the display shell on the desired axes.
*
**/
void
-gimp_display_shell_center_image (GimpDisplayShell *shell)
+gimp_display_shell_center_image (GimpDisplayShell *shell,
+ gboolean horizontally,
+ gboolean vertically)
{
gint sw, sh;
gint target_offset_x, target_offset_y;
@@ -491,24 +495,33 @@
if (! shell->display)
return;
+ target_offset_x = shell->offset_x;
+ target_offset_y = shell->offset_y;
+
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
- if (sw < shell->disp_width)
- {
- target_offset_x = -(shell->disp_width - sw) / 2;
- }
- else
+ if (horizontally)
{
- target_offset_x = (sw - shell->disp_width) / 2;
+ if (sw < shell->disp_width)
+ {
+ target_offset_x = -(shell->disp_width - sw) / 2;
+ }
+ else
+ {
+ target_offset_x = (sw - shell->disp_width) / 2;
+ }
}
- if (sh < shell->disp_height)
+ if (vertically)
{
- target_offset_y = -(shell->disp_height - sh) / 2;
- }
- else
- {
- target_offset_y = (sh - shell->disp_height) / 2;
+ if (sh < shell->disp_height)
+ {
+ target_offset_y = -(shell->disp_height - sh) / 2;
+ }
+ else
+ {
+ target_offset_y = (sh - shell->disp_height) / 2;
+ }
}
/* Note that we can't use gimp_display_shell_scroll_private() here
Modified: trunk/app/display/gimpdisplayshell-scale.h
==============================================================================
--- trunk/app/display/gimpdisplayshell-scale.h (original)
+++ trunk/app/display/gimpdisplayshell-scale.h Sun Jul 13 20:23:15 2008
@@ -38,7 +38,9 @@
gdouble y);
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
void gimp_display_shell_scale_fill (GimpDisplayShell *shell);
-void gimp_display_shell_center_image (GimpDisplayShell *shell);
+void gimp_display_shell_center_image (GimpDisplayShell *shell,
+ gboolean horizontally,
+ gboolean vertically);
void gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
gdouble scale,
gint offset_x,
Modified: trunk/app/display/gimpdisplayshell.c
==============================================================================
--- trunk/app/display/gimpdisplayshell.c (original)
+++ trunk/app/display/gimpdisplayshell.c Sun Jul 13 20:23:15 2008
@@ -1316,6 +1316,35 @@
gimp_ui_manager_update (shell->popup_manager, shell->display);
}
+static void
+gimp_display_shell_center_image_callback (GimpDisplayShell *shell,
+ GtkAllocation *allocation,
+ GtkWidget *canvas)
+{
+ gint sw, sh;
+ gboolean center_horizontally;
+ gboolean center_vertically;
+
+ gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
+
+ /* We only want to center on the axes on which the image is smaller
+ * than the display canvas. If it is larger, it will be centered on
+ * that axis later, and if we center on all axis unconditionally, we
+ * end up with the wrong centering if the image is larger than the
+ * display canvas.
+ */
+ center_horizontally = sw < shell->disp_width;
+ center_vertically = sh < shell->disp_height;
+
+ gimp_display_shell_center_image (shell,
+ center_horizontally,
+ center_vertically);
+
+ g_signal_handlers_disconnect_by_func (canvas,
+ gimp_display_shell_center_image_callback,
+ shell);
+}
+
static gboolean
gimp_display_shell_fill_idle (GimpDisplayShell *shell)
{
@@ -1351,6 +1380,15 @@
gimp_help_set_help_data (shell->canvas, NULL, NULL);
+ /* Not pretty, but we need to center the image as soon as the canvas
+ * has got its new size allocated. The centering will be wrong if we
+ * do it too early, and if we do it too late flickering will occur
+ * due to the image being rendered twice.
+ */
+ g_signal_connect_swapped (shell->canvas, "size-allocate",
+ G_CALLBACK (gimp_display_shell_center_image_callback),
+ shell);
+
shell->fill_idle_id = g_idle_add_full (G_PRIORITY_LOW,
(GSourceFunc) gimp_display_shell_fill_idle,
shell, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]