From ea4ed72e88f75049ba37830f0f82985731d62574 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 7 Feb 2007 08:13:44 +0000 Subject: [PATCH] app/actions/view-actions.c app/actions/view-commands.[ch] 2007-02-07 Sven Neumann * app/actions/view-actions.c * app/actions/view-commands.[ch] * app/display/gimpdisplayshell.[ch] * app/display/gimpdisplayshell-scale.[ch] * app/widgets/gimphelp-ids.h * menus/image-menu.xml.in: applied patch from Robert Helgesson that adds "Revert Zoom" functionality (bug #338168). svn path=/trunk/; revision=21855 --- ChangeLog | 10 ++++++ app/actions/view-actions.c | 33 +++++++++++++++--- app/actions/view-commands.c | 10 ++++++ app/actions/view-commands.h | 2 ++ app/display/gimpdisplayshell-scale.c | 50 +++++++++++++++++++++++++++- app/display/gimpdisplayshell-scale.h | 3 ++ app/display/gimpdisplayshell.c | 4 +++ app/display/gimpdisplayshell.h | 4 +++ app/widgets/gimphelp-ids.h | 1 + menus/image-menu.xml.in | 3 +- 10 files changed, 114 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1323ed116d..1874f45acd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-02-07 Sven Neumann + + * app/actions/view-actions.c + * app/actions/view-commands.[ch] + * app/display/gimpdisplayshell.[ch] + * app/display/gimpdisplayshell-scale.[ch] + * app/widgets/gimphelp-ids.h + * menus/image-menu.xml.in: applied patch from Robert Helgesson that + adds "Revert Zoom" functionality (bug #338168). + 2007-02-06 Sven Neumann * app/core/gimpundo.[ch]: made time a property and added utility diff --git a/app/actions/view-actions.c b/app/actions/view-actions.c index 81b3513d86..5db2db73ff 100644 --- a/app/actions/view-actions.c +++ b/app/actions/view-actions.c @@ -40,6 +40,7 @@ #include "display/gimpdisplayoptions.h" #include "display/gimpdisplayshell.h" #include "display/gimpdisplayshell-appearance.h" +#include "display/gimpdisplayshell-scale.h" #include "display/gimpdisplayshell-selection.h" #include "actions.h" @@ -93,6 +94,12 @@ static const GimpActionEntry view_actions[] = G_CALLBACK (view_zoom_fit_to_cmd_callback), GIMP_HELP_VIEW_ZOOM_FIT_TO }, + { "view-zoom-revert", NULL, + N_("Re_vert Zoom"), "grave", + N_("Restore the previous zoom level"), + G_CALLBACK (view_zoom_revert_cmd_callback), + GIMP_HELP_VIEW_ZOOM_REVERT }, + { "view-navigation-window", GIMP_STOCK_NAVIGATION, N_("Na_vigation Window"), NULL, N_("Show an overview window for this image"), @@ -497,10 +504,12 @@ void view_actions_update (GimpActionGroup *group, gpointer data) { - GimpDisplay *display = action_data_get_display (data); - GimpDisplayShell *shell = NULL; - GimpDisplayOptions *options = NULL; - gboolean fullscreen = FALSE; + GimpDisplay *display = action_data_get_display (data); + GimpDisplayShell *shell = NULL; + GimpDisplayOptions *options = NULL; + gchar *label = NULL; + gboolean fullscreen = FALSE; + gboolean revert_enabled = FALSE; /* able to revert zoom? */ if (display) { @@ -509,6 +518,8 @@ view_actions_update (GimpActionGroup *group, fullscreen = gimp_display_shell_get_fullscreen (shell); options = fullscreen ? shell->fullscreen_options : shell->options; + + revert_enabled = gimp_display_shell_scale_can_revert (shell); } #define SET_ACTIVE(action,condition) \ @@ -524,6 +535,20 @@ view_actions_update (GimpActionGroup *group, SET_SENSITIVE ("view-dot-for-dot", display); SET_ACTIVE ("view-dot-for-dot", display && shell->dot_for_dot); + SET_SENSITIVE ("view-zoom-revert", revert_enabled); + if (revert_enabled) + { + label = g_strdup_printf (_("Re_vert Zoom (%d%%)"), + ROUND (shell->last_scale * 100)); + gimp_action_group_set_action_label (group, "view-zoom-revert", label); + g_free (label); + } + else + { + gimp_action_group_set_action_label (group, "view-zoom-revert", + N_("Re_vert Zoom")); + } + SET_SENSITIVE ("view-zoom-out", display); SET_SENSITIVE ("view-zoom-in", display); SET_SENSITIVE ("view-zoom-fit-in", display); diff --git a/app/actions/view-commands.c b/app/actions/view-commands.c index fb88330608..5841e82818 100644 --- a/app/actions/view-commands.c +++ b/app/actions/view-commands.c @@ -108,6 +108,16 @@ view_zoom_fit_to_cmd_callback (GtkAction *action, gimp_display_shell_scale_fit_to (GIMP_DISPLAY_SHELL (display->shell)); } +void +view_zoom_revert_cmd_callback (GtkAction *action, + gpointer data) +{ + GimpDisplay *display; + return_if_no_display (display, data); + + gimp_display_shell_scale_revert (GIMP_DISPLAY_SHELL (display->shell)); +} + void view_zoom_cmd_callback (GtkAction *action, gint value, diff --git a/app/actions/view-commands.h b/app/actions/view-commands.h index 60764f29a0..592ce1e569 100644 --- a/app/actions/view-commands.h +++ b/app/actions/view-commands.h @@ -27,6 +27,8 @@ void view_zoom_fit_in_cmd_callback (GtkAction *action, gpointer data); void view_zoom_fit_to_cmd_callback (GtkAction *action, gpointer data); +void view_zoom_revert_cmd_callback (GtkAction *action, + gpointer data); void view_zoom_cmd_callback (GtkAction *action, gint value, gpointer data); diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index 1fc427b3b2..59466fe30a 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -44,6 +44,8 @@ #include "gimp-intl.h" +#define SCALE_EPSILON 0.0001 + typedef struct _ScaleDialogData ScaleDialogData; struct _ScaleDialogData @@ -184,6 +186,47 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) #endif } +/** + * gimp_display_shell_scale_revert: + * @shell: the #GimpDisplayShell + * + * Reverts the display to the previously used scale. If no previous scale + * exist then the call does nothing. + * + * Return value: %TRUE if the scale was reverted, otherwise %FALSE. + **/ +gboolean +gimp_display_shell_scale_revert (GimpDisplayShell *shell) +{ + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); + + /* don't bother if no scale has been set */ + if (shell->last_scale < SCALE_EPSILON) + return FALSE; + + gimp_display_shell_scale_by_values (shell, + shell->last_scale, + shell->last_offset_x, + shell->last_offset_y, + FALSE); /* don't resize the window */ + + return TRUE; +} + +/** + * gimp_display_shell_scale_can_revert: + * @shell: the #GimpDisplayShell + * + * Return value: %TRUE if a previous display scale exists, otherwise %FALSE. + **/ +gboolean +gimp_display_shell_scale_can_revert (GimpDisplayShell *shell) +{ + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); + + return (shell->last_scale > SCALE_EPSILON); +} + void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, gboolean dot_for_dot) @@ -390,6 +433,11 @@ gimp_display_shell_scale_by_values (GimpDisplayShell *shell, shell->offset_y == offset_y) return; + /* remember the current scale and offsets to allow reverting the scaling */ + shell->last_scale = gimp_zoom_model_get_factor (shell->zoom); + shell->last_offset_x = shell->offset_x; + shell->last_offset_y = shell->offset_y; + /* freeze the active tool */ gimp_display_shell_pause (shell); @@ -459,7 +507,7 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell) return; } - if (fabs (shell->other_scale) <= 0.0001) + if (fabs (shell->other_scale) < SCALE_EPSILON) { /* other_scale not yet initialized */ shell->other_scale = gimp_zoom_model_get_factor (shell->zoom); diff --git a/app/display/gimpdisplayshell-scale.h b/app/display/gimpdisplayshell-scale.h index 05acca3781..354f6c8a32 100644 --- a/app/display/gimpdisplayshell-scale.h +++ b/app/display/gimpdisplayshell-scale.h @@ -22,6 +22,9 @@ void gimp_display_shell_scale_setup (GimpDisplayShell *shell); +gboolean gimp_display_shell_scale_revert (GimpDisplayShell *shell); +gboolean gimp_display_shell_scale_can_revert (GimpDisplayShell *shell); + void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, gboolean dot_for_dot); diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index b28c344577..32d5149101 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -220,6 +220,10 @@ gimp_display_shell_init (GimpDisplayShell *shell) shell->offset_x = 0; shell->offset_y = 0; + shell->last_scale = 0.0; + shell->last_offset_x = 0; + shell->last_offset_y = 0; + shell->disp_width = 0; shell->disp_height = 0; shell->disp_xoffset = 0; diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index 0c708eb36f..8ea395c697 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -83,6 +83,10 @@ struct _GimpDisplayShell gint offset_x; /* offset of display image into raw image */ gint offset_y; + gdouble last_scale; /* scale used when reverting zoom */ + gint last_offset_x; /* offsets used when reverting zoom */ + gint last_offset_y; + gint disp_width; /* width of drawing area */ gint disp_height; /* height of drawing area */ gint disp_xoffset; diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h index 2f0b8c995d..97d4a1e9a5 100644 --- a/app/widgets/gimphelp-ids.h +++ b/app/widgets/gimphelp-ids.h @@ -74,6 +74,7 @@ #define GIMP_HELP_VIEW_NEW "gimp-view-new" #define GIMP_HELP_VIEW_DOT_FOR_DOT "gimp-view-dot-for-dot" +#define GIMP_HELP_VIEW_ZOOM_REVERT "gimp-view-zoom-revert" #define GIMP_HELP_VIEW_ZOOM_OUT "gimp-view-zoom-out" #define GIMP_HELP_VIEW_ZOOM_IN "gimp-view-zoom-in" #define GIMP_HELP_VIEW_ZOOM_100 "gimp-view-zoom-100" diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in index 037b2723d5..7081a133da 100644 --- a/menus/image-menu.xml.in +++ b/menus/image-menu.xml.in @@ -219,11 +219,12 @@ + - + -- GitLab