Commit 1f0aff2b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

libgimpwidgets/gimpwidgets.def added gimp_zoom_model_zoom() and changed

2005-09-25  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimpwidgets.def
	* libgimpwidgets/gimpzoommodel.[ch]: added gimp_zoom_model_zoom()
	and changed gimp_zoom_model_get_fraction() to take a model instead
	of the zoom factor.

	* app/display/gimpdisplayshell.[ch]: use a GimpZoomModel for the
	display scale factor.

	* app/actions/image-commands.c
	* app/actions/view-actions.c
	* app/actions/view-commands.c
	* app/display/gimpdisplayshell-callbacks.c
	* app/display/gimpdisplayshell-scale.c
	* app/display/gimpdisplayshell-title.c
	* app/display/gimpnavigationeditor.c
	* app/display/gimpstatusbar.c
	* app/tools/gimpeditselectiontool.c
	* app/tools/gimpmagnifytool.c: changed accordingly.
parent 13041a7e
2005-09-25 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpwidgets.def
* libgimpwidgets/gimpzoommodel.[ch]: added gimp_zoom_model_zoom()
and changed gimp_zoom_model_get_fraction() to take a model instead
of the zoom factor.
* app/display/gimpdisplayshell.[ch]: use a GimpZoomModel for the
display scale factor.
* app/actions/image-commands.c
* app/actions/view-actions.c
* app/actions/view-commands.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-scale.c
* app/display/gimpdisplayshell-title.c
* app/display/gimpnavigationeditor.c
* app/display/gimpstatusbar.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpmagnifytool.c: changed accordingly.
2005-09-25 Karine Delvare <kdelvare@nerim.net> 2005-09-25 Karine Delvare <kdelvare@nerim.net>
* app/tools/gimpcroptool.c: fixed assignment of local variable * app/tools/gimpcroptool.c: fixed assignment of local variable
......
...@@ -362,7 +362,8 @@ image_duplicate_cmd_callback (GtkAction *action, ...@@ -362,7 +362,8 @@ image_duplicate_cmd_callback (GtkAction *action,
gimp_create_display (new_gimage->gimp, gimp_create_display (new_gimage->gimp,
new_gimage, new_gimage,
shell->unit, shell->scale); shell->unit,
gimp_zoom_model_get_factor (shell->zoom));
g_object_unref (new_gimage); g_object_unref (new_gimage);
} }
......
...@@ -588,11 +588,15 @@ view_actions_set_zoom (GimpActionGroup *group, ...@@ -588,11 +588,15 @@ view_actions_set_zoom (GimpActionGroup *group,
GimpDisplayShell *shell) GimpDisplayShell *shell)
{ {
const gchar *action = NULL; const gchar *action = NULL;
guint scale; gchar *str;
gchar buf[16];
gchar *label; gchar *label;
guint scale;
g_object_get (shell->zoom,
"percentage", &str,
NULL);
scale = ROUND (shell->scale * 1000); scale = ROUND (gimp_zoom_model_get_factor (shell->zoom) * 1000);
switch (scale) switch (scale)
{ {
...@@ -608,29 +612,27 @@ view_actions_set_zoom (GimpActionGroup *group, ...@@ -608,29 +612,27 @@ view_actions_set_zoom (GimpActionGroup *group,
case 62: action = "view-zoom-1-16"; break; case 62: action = "view-zoom-1-16"; break;
} }
g_snprintf (buf, sizeof (buf), if (! action)
shell->scale >= 0.15 ? "%.0f%%" : "%.2f%%",
shell->scale * 100.0);
if (!action)
{ {
action = "view-zoom-other"; action = "view-zoom-other";
label = g_strdup_printf (_("Othe_r (%s) ..."), buf); label = g_strdup_printf (_("Othe_r (%s) ..."), str);
gimp_action_group_set_action_label (group, action, label); gimp_action_group_set_action_label (group, action, label);
g_free (label); g_free (label);
shell->other_scale = shell->scale; shell->other_scale = gimp_zoom_model_get_factor (shell->zoom);
} }
gimp_action_group_set_action_active (group, action, TRUE); gimp_action_group_set_action_active (group, action, TRUE);
label = g_strdup_printf (_("_Zoom (%s)"), buf); label = g_strdup_printf (_("_Zoom (%s)"), str);
gimp_action_group_set_action_label (group, "view-zoom-menu", label); gimp_action_group_set_action_label (group, "view-zoom-menu", label);
g_free (label); g_free (label);
/* flag as dirty */ /* flag as dirty */
shell->other_scale = - fabs (shell->other_scale); shell->other_scale = - fabs (shell->other_scale);
g_free (str);
} }
static void static void
......
...@@ -85,7 +85,7 @@ view_new_cmd_callback (GtkAction *action, ...@@ -85,7 +85,7 @@ view_new_cmd_callback (GtkAction *action,
gimp_create_display (gdisp->gimage->gimp, gimp_create_display (gdisp->gimage->gimp,
gdisp->gimage, gdisp->gimage,
shell->unit, shell->scale); shell->unit, gimp_zoom_model_get_factor (shell->zoom));
} }
void void
...@@ -125,13 +125,10 @@ view_zoom_cmd_callback (GtkAction *action, ...@@ -125,13 +125,10 @@ view_zoom_cmd_callback (GtkAction *action,
{ {
GimpDisplay *gdisp; GimpDisplay *gdisp;
GimpDisplayShell *shell; GimpDisplayShell *shell;
gdouble scale;
return_if_no_display (gdisp, data); return_if_no_display (gdisp, data);
shell = GIMP_DISPLAY_SHELL (gdisp->shell); shell = GIMP_DISPLAY_SHELL (gdisp->shell);
scale = shell->scale;
switch ((GimpActionSelectType) value) switch ((GimpActionSelectType) value)
{ {
case GIMP_ACTION_SELECT_FIRST: case GIMP_ACTION_SELECT_FIRST:
...@@ -159,18 +156,22 @@ view_zoom_cmd_callback (GtkAction *action, ...@@ -159,18 +156,22 @@ view_zoom_cmd_callback (GtkAction *action,
break; break;
default: default:
scale = action_select_value ((GimpActionSelectType) value, {
scale, gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
0.0, 512.0,
1.0, 16.0,
FALSE);
/* min = 1.0 / 256, max = 256.0 */ scale = action_select_value ((GimpActionSelectType) value,
/* scale = min * (max / min)**(i/n), i = 0..n */ scale,
scale = pow (65536.0, scale / 512.0) / 256.0; 0.0, 512.0,
1.0, 16.0,
FALSE);
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale); /* min = 1.0 / 256, max = 256.0 */
break; /* scale = min * (max / min)**(i/n), i = 0..n */
scale = pow (65536.0, scale / 512.0) / 256.0;
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
break;
}
} }
} }
...@@ -190,7 +191,7 @@ view_zoom_explicit_cmd_callback (GtkAction *action, ...@@ -190,7 +191,7 @@ view_zoom_explicit_cmd_callback (GtkAction *action,
if (value != 0 /* not Other... */) if (value != 0 /* not Other... */)
{ {
if (fabs (value - shell->scale) > 0.0001) if (fabs (value - gimp_zoom_model_get_factor (shell->zoom)) > 0.0001)
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000); gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000);
} }
} }
...@@ -209,7 +210,7 @@ view_zoom_other_cmd_callback (GtkAction *action, ...@@ -209,7 +210,7 @@ view_zoom_other_cmd_callback (GtkAction *action,
* view_actions_set_zoom() * view_actions_set_zoom()
*/ */
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) && if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) &&
shell->scale != shell->other_scale) shell->other_scale != gimp_zoom_model_get_factor (shell->zoom))
{ {
gimp_display_shell_scale_dialog (shell); gimp_display_shell_scale_dialog (shell);
} }
......
...@@ -321,7 +321,7 @@ gimp_display_shell_canvas_size_allocate (GtkWidget *widget, ...@@ -321,7 +321,7 @@ gimp_display_shell_canvas_size_allocate (GtkWidget *widget,
allocation->width > 64 && allocation->width > 64 &&
allocation->height > 64) allocation->height > 64)
{ {
gdouble scale = shell->scale; gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
gint offset_x; gint offset_x;
gint offset_y; gint offset_y;
...@@ -336,7 +336,8 @@ gimp_display_shell_canvas_size_allocate (GtkWidget *widget, ...@@ -336,7 +336,8 @@ gimp_display_shell_canvas_size_allocate (GtkWidget *widget,
offset_x = UNSCALEX (shell, shell->offset_x); offset_x = UNSCALEX (shell, shell->offset_x);
offset_y = UNSCALEX (shell, shell->offset_y); offset_y = UNSCALEX (shell, shell->offset_y);
shell->scale = scale; gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);
shell->offset_x = SCALEX (shell, offset_x); shell->offset_x = SCALEX (shell, offset_x);
shell->offset_y = SCALEY (shell, offset_y); shell->offset_y = SCALEY (shell, offset_y);
} }
......
...@@ -49,6 +49,7 @@ typedef struct _ScaleDialogData ScaleDialogData; ...@@ -49,6 +49,7 @@ typedef struct _ScaleDialogData ScaleDialogData;
struct _ScaleDialogData struct _ScaleDialogData
{ {
GimpDisplayShell *shell; GimpDisplayShell *shell;
GimpZoomModel *model;
GtkObject *scale_adj; GtkObject *scale_adj;
GtkObject *num_adj; GtkObject *num_adj;
GtkObject *denom_adj; GtkObject *denom_adj;
...@@ -280,6 +281,7 @@ gimp_display_shell_scale_to (GimpDisplayShell *shell, ...@@ -280,6 +281,7 @@ gimp_display_shell_scale_to (GimpDisplayShell *shell,
gdouble y) gdouble y)
{ {
GimpDisplayConfig *config; GimpDisplayConfig *config;
gdouble current;
gdouble offset_x; gdouble offset_x;
gdouble offset_y; gdouble offset_y;
...@@ -288,14 +290,16 @@ gimp_display_shell_scale_to (GimpDisplayShell *shell, ...@@ -288,14 +290,16 @@ gimp_display_shell_scale_to (GimpDisplayShell *shell,
if (! shell->gdisp) if (! shell->gdisp)
return; return;
current = gimp_zoom_model_get_factor (shell->zoom);
offset_x = shell->offset_x + x; offset_x = shell->offset_x + x;
offset_y = shell->offset_y + y; offset_y = shell->offset_y + y;
offset_x /= shell->scale; offset_x /= current;
offset_y /= shell->scale; offset_y /= current;
if (zoom_type != GIMP_ZOOM_TO) if (zoom_type != GIMP_ZOOM_TO)
scale = gimp_zoom_model_zoom_step (zoom_type, shell->scale); scale = gimp_zoom_model_zoom_step (zoom_type, current);
offset_x *= scale; offset_x *= scale;
offset_y *= scale; offset_y *= scale;
...@@ -377,15 +381,16 @@ gimp_display_shell_scale_by_values (GimpDisplayShell *shell, ...@@ -377,15 +381,16 @@ gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
/* Abort early if the values are all setup already. We don't /* Abort early if the values are all setup already. We don't
* want to inadvertently resize the window (bug #164281). * want to inadvertently resize the window (bug #164281).
*/ */
if (shell->scale == scale && if (gimp_zoom_model_get_factor (shell->zoom) == scale &&
shell->offset_x == offset_x && shell->offset_x == offset_x &&
shell->offset_y == offset_y) shell->offset_y == offset_y)
return; return;
/* freeze the active tool */ /* freeze the active tool */
gimp_display_shell_pause (shell); gimp_display_shell_pause (shell);
shell->scale = scale; gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);
shell->offset_x = offset_x; shell->offset_x = offset_x;
shell->offset_y = offset_y; shell->offset_y = offset_y;
...@@ -449,8 +454,18 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell) ...@@ -449,8 +454,18 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell)
return; return;
} }
if (fabs (shell->other_scale) <= 0.0001)
{
/* other_scale not yet initialized */
shell->other_scale = gimp_zoom_model_get_factor (shell->zoom);
}
data = g_new (ScaleDialogData, 1); data = g_new (ScaleDialogData, 1);
data->shell = shell; data->shell = shell;
data->model = g_object_new (GIMP_TYPE_ZOOM_MODEL,
"value", fabs (shell->other_scale),
NULL);
shell->scale_dialog = shell->scale_dialog =
gimp_viewable_dialog_new (GIMP_VIEWABLE (shell->gdisp->gimage), gimp_viewable_dialog_new (GIMP_VIEWABLE (shell->gdisp->gimage),
...@@ -473,6 +488,9 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell) ...@@ -473,6 +488,9 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell)
g_object_weak_ref (G_OBJECT (shell->scale_dialog), g_object_weak_ref (G_OBJECT (shell->scale_dialog),
(GWeakNotify) g_free, data); (GWeakNotify) g_free, data);
g_object_weak_ref (G_OBJECT (shell->scale_dialog),
(GWeakNotify) g_object_unref, data->model);
g_object_add_weak_pointer (G_OBJECT (shell->scale_dialog), g_object_add_weak_pointer (G_OBJECT (shell->scale_dialog),
(gpointer *) &shell->scale_dialog); (gpointer *) &shell->scale_dialog);
...@@ -499,11 +517,7 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell) ...@@ -499,11 +517,7 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell)
_("Zoom ratio:"), 0.0, 0.5, _("Zoom ratio:"), 0.0, 0.5,
hbox, 1, FALSE); hbox, 1, FALSE);
if (fabs (shell->other_scale) <= 0.0001) gimp_zoom_model_get_fraction (data->model, &num, &denom);
shell->other_scale = shell->scale; /* other_scale not yet initialized */
gimp_zoom_model_get_fraction (fabs (shell->other_scale),
&num, &denom);
spin = gimp_spin_button_new (&data->num_adj, spin = gimp_spin_button_new (&data->num_adj,
num, 1, 256, num, 1, 256,
...@@ -582,7 +596,7 @@ static void ...@@ -582,7 +596,7 @@ static void
update_zoom_values (GtkAdjustment *adj, update_zoom_values (GtkAdjustment *adj,
ScaleDialogData *dialog) ScaleDialogData *dialog)
{ {
gint num, denom; gint num, denom;
gdouble scale; gdouble scale;
g_signal_handlers_block_by_func (GTK_ADJUSTMENT (dialog->scale_adj), g_signal_handlers_block_by_func (GTK_ADJUSTMENT (dialog->scale_adj),
...@@ -601,7 +615,8 @@ update_zoom_values (GtkAdjustment *adj, ...@@ -601,7 +615,8 @@ update_zoom_values (GtkAdjustment *adj,
{ {
scale = gtk_adjustment_get_value (GTK_ADJUSTMENT (dialog->scale_adj)); scale = gtk_adjustment_get_value (GTK_ADJUSTMENT (dialog->scale_adj));
gimp_zoom_model_get_fraction (scale / 100.0, &num, &denom); gimp_zoom_model_zoom (dialog->model, GIMP_ZOOM_TO, scale / 100.0);
gimp_zoom_model_get_fraction (dialog->model, &num, &denom);
gtk_adjustment_set_value (GTK_ADJUSTMENT (dialog->num_adj), num); gtk_adjustment_set_value (GTK_ADJUSTMENT (dialog->num_adj), num);
gtk_adjustment_set_value (GTK_ADJUSTMENT (dialog->denom_adj), denom); gtk_adjustment_set_value (GTK_ADJUSTMENT (dialog->denom_adj), denom);
......
...@@ -162,7 +162,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, ...@@ -162,7 +162,7 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
image = shell->gdisp->gimage; image = shell->gdisp->gimage;
gimp = image->gimp; gimp = image->gimp;
gimp_zoom_model_get_fraction (shell->scale, &num, &denom); gimp_zoom_model_get_fraction (shell->zoom, &num, &denom);
while (i < title_len && *format) while (i < title_len && *format)
{ {
...@@ -247,9 +247,12 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, ...@@ -247,9 +247,12 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
break; break;
case 'z': /* user zoom factor (percentage) */ case 'z': /* user zoom factor (percentage) */
i += print (title, title_len, i, {
shell->scale >= 0.15 ? "%.0f" : "%.2f", gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
100 * shell->scale);
i += print (title, title_len, i,
scale >= 0.15 ? "%.0f" : "%.2f", 100.0 * scale);
}
break; break;
case 'D': /* dirty flag */ case 'D': /* dirty flag */
...@@ -278,14 +281,12 @@ gimp_display_shell_format_title (GimpDisplayShell *shell, ...@@ -278,14 +281,12 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
case 'B': /* dirty flag (long) */ case 'B': /* dirty flag (long) */
if (image->dirty) if (image->dirty)
i += print (title, title_len, i, "%s", i += print (title, title_len, i, "%s", _("(modified)"));
_("(modified)"));
break; break;
case 'A': /* clean flag (long) */ case 'A': /* clean flag (long) */
if (! image->dirty) if (! image->dirty)
i += print (title, title_len, i, "%s", i += print (title, title_len, i, "%s", _("(clean)"));
_("(clean)"));
break; break;
case 'm': /* memory used by image */ case 'm': /* memory used by image */
......
...@@ -74,7 +74,6 @@ ...@@ -74,7 +74,6 @@
enum enum
{ {
PROP_0, PROP_0,
PROP_SCALE,
PROP_UNIT PROP_UNIT
}; };
...@@ -208,11 +207,6 @@ gimp_display_shell_class_init (GimpDisplayShellClass *klass) ...@@ -208,11 +207,6 @@ gimp_display_shell_class_init (GimpDisplayShellClass *klass)
klass->scrolled = NULL; klass->scrolled = NULL;
klass->reconnect = NULL; klass->reconnect = NULL;
g_object_class_install_property (object_class, PROP_SCALE,
g_param_spec_double ("scale", NULL, NULL,
1.0 / 256, 256, 1.0,
G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_UNIT, g_object_class_install_property (object_class, PROP_UNIT,
gimp_param_spec_unit ("unit", NULL, NULL, gimp_param_spec_unit ("unit", NULL, NULL,
TRUE, FALSE, TRUE, FALSE,
...@@ -232,7 +226,7 @@ gimp_display_shell_init (GimpDisplayShell *shell) ...@@ -232,7 +226,7 @@ gimp_display_shell_init (GimpDisplayShell *shell)
shell->unit = GIMP_UNIT_PIXEL; shell->unit = GIMP_UNIT_PIXEL;
shell->scale = 1.0; shell->zoom = gimp_zoom_model_new ();
shell->other_scale = 0.0; shell->other_scale = 0.0;
shell->dot_for_dot = TRUE; shell->dot_for_dot = TRUE;
...@@ -358,6 +352,8 @@ gimp_display_shell_finalize (GObject *object) ...@@ -358,6 +352,8 @@ gimp_display_shell_finalize (GObject *object)
{ {
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object); GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (object);
g_object_unref (shell->zoom);
if (shell->options) if (shell->options)
g_object_unref (shell->options); g_object_unref (shell->options);
...@@ -449,16 +445,10 @@ gimp_display_shell_set_property (GObject *object, ...@@ -449,16 +445,10 @@ gimp_display_shell_set_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_SCALE:
if (shell->canvas)
gimp_display_shell_scale (shell,
GIMP_ZOOM_TO, g_value_get_double (value));
else
shell->scale = g_value_get_double (value);
break;
case PROP_UNIT: case PROP_UNIT:
gimp_display_shell_set_unit (shell, g_value_get_int (value)); gimp_display_shell_set_unit (shell, g_value_get_int (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
...@@ -475,12 +465,10 @@ gimp_display_shell_get_property (GObject *object, ...@@ -475,12 +465,10 @@ gimp_display_shell_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_SCALE:
g_value_set_double (value, shell->scale);
break;
case PROP_UNIT: case PROP_UNIT:
g_value_set_int (value, shell->unit); g_value_set_int (value, shell->unit);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
...@@ -602,9 +590,10 @@ gimp_display_shell_new (GimpDisplay *gdisp, ...@@ -602,9 +590,10 @@ gimp_display_shell_new (GimpDisplay *gdisp,
shell = g_object_new (GIMP_TYPE_DISPLAY_SHELL, shell = g_object_new (GIMP_TYPE_DISPLAY_SHELL,
"gravity", GDK_GRAVITY_CENTER, "gravity", GDK_GRAVITY_CENTER,
"unit", unit, "unit", unit,
"scale", scale,
NULL); NULL);
gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);
shell->gdisp = gdisp; shell->gdisp = gdisp;
image_width = gdisp->gimage->width; image_width = gdisp->gimage->width;
...@@ -647,18 +636,23 @@ gimp_display_shell_new (GimpDisplay *gdisp, ...@@ -647,18 +636,23 @@ gimp_display_shell_new (GimpDisplay *gdisp,
/* Limit to the size of the screen... */ /* Limit to the size of the screen... */
if (n_width > s_width || n_height > s_height) if (n_width > s_width || n_height > s_height)
{ {
new_scale = shell->scale * MIN (((gdouble) s_height) / n_height, gdouble current = gimp_zoom_model_get_factor (shell->zoom);
((gdouble) s_width) / n_width);
new_scale = current * MIN (((gdouble) s_height) / n_height,
((gdouble) s_width) / n_width);
new_scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, new_scale); new_scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, new_scale);
/* since zooming out might skip a zoom step we zoom in again /* Since zooming out might skip a zoom step we zoom in again
* and test if we are small enough. */ * and test if we are small enough.
shell->scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_IN, new_scale);