~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpzoommodel.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpzoommodel.c
 
5
 * Copyright (C) 2005  David Odin <dindinx@gimp.org>
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <gtk/gtk.h>
 
26
 
 
27
#include "gimpwidgetstypes.h"
 
28
 
 
29
#include "libgimpbase/gimpbase.h"
 
30
#include "libgimpmath/gimpmath.h"
 
31
 
 
32
#include "gimphelpui.h"
 
33
#include "gimpwidgetsmarshal.h"
 
34
#include "gimpzoommodel.h"
 
35
 
 
36
 
 
37
#define ZOOM_MIN  (1.0 / 256.0)
 
38
#define ZOOM_MAX  (256.0)
 
39
 
 
40
enum
 
41
{
 
42
  ZOOMED,
 
43
  LAST_SIGNAL
 
44
};
 
45
 
 
46
enum
 
47
{
 
48
  PROP_0,
 
49
  PROP_VALUE,
 
50
  PROP_MINIMUM,
 
51
  PROP_MAXIMUM,
 
52
  PROP_FRACTION,
 
53
  PROP_PERCENTAGE
 
54
};
 
55
 
 
56
 
 
57
typedef struct
 
58
{
 
59
  gdouble  value;
 
60
  gdouble  minimum;
 
61
  gdouble  maximum;
 
62
} GimpZoomModelPrivate;
 
63
 
 
64
#define GIMP_ZOOM_MODEL_GET_PRIVATE(obj) \
 
65
  ((GimpZoomModelPrivate *) ((GimpZoomModel *) (obj))->priv)
 
66
 
 
67
 
 
68
static void  gimp_zoom_model_set_property (GObject      *object,
 
69
                                           guint         property_id,
 
70
                                           const GValue *value,
 
71
                                           GParamSpec   *pspec);
 
72
static void  gimp_zoom_model_get_property (GObject      *object,
 
73
                                           guint         property_id,
 
74
                                           GValue       *value,
 
75
                                           GParamSpec   *pspec);
 
76
 
 
77
 
 
78
static guint zoom_model_signals[LAST_SIGNAL] = { 0, };
 
79
 
 
80
G_DEFINE_TYPE (GimpZoomModel, gimp_zoom_model, G_TYPE_OBJECT)
 
81
 
 
82
#define parent_class gimp_zoom_model_parent_class
 
83
 
 
84
 
 
85
static void
 
86
gimp_zoom_model_class_init (GimpZoomModelClass *klass)
 
87
{
 
88
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
89
 
 
90
  /**
 
91
   * GimpZoomModel::zoomed:
 
92
   * @model: the object that received the signal
 
93
   * @old_factor: the zoom factor before it changes
 
94
   * @new_factor: the zoom factor after it has changed.
 
95
   *
 
96
   * Emitted when the zoom factor of the zoom model changes.
 
97
   */
 
98
  zoom_model_signals[ZOOMED] =
 
99
      g_signal_new ("zoomed",
 
100
                    G_TYPE_FROM_CLASS (klass),
 
101
                    G_SIGNAL_RUN_LAST,
 
102
                    G_STRUCT_OFFSET (GimpZoomModelClass,
 
103
                                     zoomed),
 
104
                    NULL, NULL,
 
105
                    _gimp_widgets_marshal_VOID__DOUBLE_DOUBLE,
 
106
                    G_TYPE_NONE, 2,
 
107
                    G_TYPE_DOUBLE, G_TYPE_DOUBLE);
 
108
 
 
109
  object_class->set_property = gimp_zoom_model_set_property;
 
110
  object_class->get_property = gimp_zoom_model_get_property;
 
111
 
 
112
  g_object_class_install_property (object_class, PROP_VALUE,
 
113
                                   g_param_spec_double ("value",
 
114
                                                        "Zoom factor", NULL,
 
115
                                                        ZOOM_MIN, ZOOM_MAX,
 
116
                                                        1.0,
 
117
                                                        GIMP_PARAM_READWRITE));
 
118
  g_object_class_install_property (object_class, PROP_MINIMUM,
 
119
                                   g_param_spec_double ("minimum",
 
120
                                                        "Lower limit for the zoom factor", NULL,
 
121
                                                        ZOOM_MIN, ZOOM_MAX,
 
122
                                                        ZOOM_MIN,
 
123
                                                        GIMP_PARAM_READWRITE));
 
124
  g_object_class_install_property (object_class, PROP_MAXIMUM,
 
125
                                   g_param_spec_double ("maximum",
 
126
                                                        "Upper limit for the zoom factor", NULL,
 
127
                                                        ZOOM_MIN, ZOOM_MAX,
 
128
                                                        ZOOM_MAX,
 
129
                                                        GIMP_PARAM_READWRITE));
 
130
 
 
131
  g_object_class_install_property (object_class, PROP_FRACTION,
 
132
                                   g_param_spec_string ("fraction",
 
133
                                                        "The zoom factor expressed as a fraction", NULL,
 
134
                                                        "1:1",
 
135
                                                        GIMP_PARAM_READABLE));
 
136
  g_object_class_install_property (object_class, PROP_PERCENTAGE,
 
137
                                   g_param_spec_string ("percentage",
 
138
                                                        "The zoom factor expressed as a percentage", NULL,
 
139
                                                        "100%",
 
140
                                                        GIMP_PARAM_READABLE));
 
141
 
 
142
  g_type_class_add_private (object_class, sizeof (GimpZoomModelPrivate));
 
143
}
 
144
 
 
145
static void
 
146
gimp_zoom_model_init (GimpZoomModel *model)
 
147
{
 
148
  GimpZoomModelPrivate *priv;
 
149
 
 
150
  model->priv = G_TYPE_INSTANCE_GET_PRIVATE (model,
 
151
                                             GIMP_TYPE_ZOOM_MODEL,
 
152
                                             GimpZoomModelPrivate);
 
153
 
 
154
  priv = GIMP_ZOOM_MODEL_GET_PRIVATE (model);
 
155
 
 
156
  priv->value   = 1.0;
 
157
  priv->minimum = ZOOM_MIN;
 
158
  priv->maximum = ZOOM_MAX;
 
159
}
 
160
 
 
161
static void
 
162
gimp_zoom_model_set_property (GObject      *object,
 
163
                              guint         property_id,
 
164
                              const GValue *value,
 
165
                              GParamSpec   *pspec)
 
166
{
 
167
  GimpZoomModelPrivate *priv  = GIMP_ZOOM_MODEL_GET_PRIVATE (object);
 
168
  gdouble               previous_value;
 
169
 
 
170
  previous_value = priv->value;
 
171
  g_object_freeze_notify (object);
 
172
 
 
173
  switch (property_id)
 
174
    {
 
175
    case PROP_VALUE:
 
176
      priv->value = g_value_get_double (value);
 
177
 
 
178
      g_object_notify (object, "value");
 
179
      g_object_notify (object, "fraction");
 
180
      g_object_notify (object, "percentage");
 
181
      break;
 
182
 
 
183
    case PROP_MINIMUM:
 
184
      priv->minimum = MIN (g_value_get_double (value), priv->maximum);
 
185
      break;
 
186
 
 
187
    case PROP_MAXIMUM:
 
188
      priv->maximum = MAX (g_value_get_double (value), priv->minimum);
 
189
      break;
 
190
 
 
191
    default:
 
192
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
193
      break;
 
194
    }
 
195
 
 
196
  if (priv->value > priv->maximum || priv->value < priv->minimum)
 
197
    {
 
198
      priv->value = CLAMP (priv->value, priv->minimum, priv->maximum);
 
199
 
 
200
      g_object_notify (object, "value");
 
201
      g_object_notify (object, "fraction");
 
202
      g_object_notify (object, "percentage");
 
203
    }
 
204
 
 
205
  g_object_thaw_notify (object);
 
206
 
 
207
  if (priv->value != previous_value)
 
208
    {
 
209
      g_signal_emit (object, zoom_model_signals[ZOOMED],
 
210
                     0, previous_value, priv->value);
 
211
    }
 
212
}
 
213
 
 
214
static void
 
215
gimp_zoom_model_get_property (GObject    *object,
 
216
                              guint       property_id,
 
217
                              GValue     *value,
 
218
                              GParamSpec *pspec)
 
219
{
 
220
  GimpZoomModelPrivate *priv  = GIMP_ZOOM_MODEL_GET_PRIVATE (object);
 
221
  gchar                *tmp;
 
222
 
 
223
  switch (property_id)
 
224
    {
 
225
    case PROP_VALUE:
 
226
      g_value_set_double (value, priv->value);
 
227
      break;
 
228
 
 
229
    case PROP_MINIMUM:
 
230
      g_value_set_double (value, priv->minimum);
 
231
      break;
 
232
 
 
233
    case PROP_MAXIMUM:
 
234
      g_value_set_double (value, priv->maximum);
 
235
      break;
 
236
 
 
237
    case PROP_FRACTION:
 
238
      {
 
239
        gint  numerator;
 
240
        gint  denominator;
 
241
 
 
242
        gimp_zoom_model_get_fraction (GIMP_ZOOM_MODEL (object),
 
243
                                      &numerator, &denominator);
 
244
 
 
245
        tmp = g_strdup_printf ("%d:%d", numerator, denominator);
 
246
        g_value_set_string (value, tmp);
 
247
        g_free (tmp);
 
248
      }
 
249
      break;
 
250
 
 
251
    case PROP_PERCENTAGE:
 
252
      tmp = g_strdup_printf (priv->value >= 0.15 ? "%.0f%%" : "%.2f%%",
 
253
                             priv->value * 100.0);
 
254
      g_value_set_string (value, tmp);
 
255
      g_free (tmp);
 
256
      break;
 
257
 
 
258
    default:
 
259
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
260
      break;
 
261
    }
 
262
}
 
263
 
 
264
static void
 
265
gimp_zoom_model_zoom_in (GimpZoomModel *model)
 
266
{
 
267
  GimpZoomModelPrivate *priv = GIMP_ZOOM_MODEL_GET_PRIVATE (model);
 
268
 
 
269
  if (priv->value < priv->maximum)
 
270
    gimp_zoom_model_zoom (model, GIMP_ZOOM_IN, 0.0);
 
271
}
 
272
 
 
273
static void
 
274
gimp_zoom_model_zoom_out (GimpZoomModel *model)
 
275
{
 
276
  GimpZoomModelPrivate *priv = GIMP_ZOOM_MODEL_GET_PRIVATE (model);
 
277
 
 
278
  if (priv->value > priv->minimum)
 
279
    gimp_zoom_model_zoom (model, GIMP_ZOOM_OUT, 0.0);
 
280
}
 
281
 
 
282
/**
 
283
 * gimp_zoom_model_new:
 
284
 *
 
285
 * Creates a new #GimpZoomModel.
 
286
 *
 
287
 * Return value: a new #GimpZoomModel.
 
288
 *
 
289
 * Since GIMP 2.4
 
290
 **/
 
291
GimpZoomModel *
 
292
gimp_zoom_model_new (void)
 
293
{
 
294
  return g_object_new (GIMP_TYPE_ZOOM_MODEL, NULL);
 
295
}
 
296
 
 
297
 
 
298
/**
 
299
 * gimp_zoom_model_set_range:
 
300
 * @model: a #GimpZoomModel
 
301
 * @min: new lower limit for zoom factor
 
302
 * @max: new upper limit for zoom factor
 
303
 *
 
304
 * Sets the allowed range of the @model.
 
305
 *
 
306
 * Since GIMP 2.4
 
307
 **/
 
308
void
 
309
gimp_zoom_model_set_range (GimpZoomModel *model,
 
310
                           gdouble        min,
 
311
                           gdouble        max)
 
312
{
 
313
  g_return_if_fail (GIMP_IS_ZOOM_MODEL (model));
 
314
  g_return_if_fail (min < max);
 
315
  g_return_if_fail (min >= ZOOM_MIN);
 
316
  g_return_if_fail (max <= ZOOM_MAX);
 
317
 
 
318
  g_object_set (model,
 
319
                "minimum", min,
 
320
                "maximum", max,
 
321
                NULL);
 
322
}
 
323
 
 
324
/**
 
325
 * gimp_zoom_model_zoom:
 
326
 * @model:     a #GimpZoomModel
 
327
 * @zoom_type: the #GimpZoomType
 
328
 * @scale:     ignored unless @zoom_type == %GIMP_ZOOM_TO
 
329
 *
 
330
 * Since GIMP 2.4
 
331
 **/
 
332
void
 
333
gimp_zoom_model_zoom (GimpZoomModel *model,
 
334
                      GimpZoomType   zoom_type,
 
335
                      gdouble        scale)
 
336
{
 
337
  g_return_if_fail (GIMP_IS_ZOOM_MODEL (model));
 
338
 
 
339
  if (zoom_type != GIMP_ZOOM_TO)
 
340
    scale = gimp_zoom_model_get_factor (model);
 
341
 
 
342
  g_object_set (model,
 
343
                "value", gimp_zoom_model_zoom_step (zoom_type, scale),
 
344
                NULL);
 
345
}
 
346
 
 
347
/**
 
348
 * gimp_zoom_model_get_factor:
 
349
 * @model: a #GimpZoomModel
 
350
 *
 
351
 * Retrieves the current zoom factor of @model.
 
352
 *
 
353
 * Return value: the current scale factor
 
354
 *
 
355
 * Since GIMP 2.4
 
356
 **/
 
357
gdouble
 
358
gimp_zoom_model_get_factor (GimpZoomModel *model)
 
359
{
 
360
  g_return_val_if_fail (GIMP_IS_ZOOM_MODEL (model), 1.0);
 
361
 
 
362
  return GIMP_ZOOM_MODEL_GET_PRIVATE (model)->value;
 
363
}
 
364
 
 
365
 
 
366
/**
 
367
 * gimp_zoom_model_get_fraction
 
368
 * @model:       a #GimpZoomModel
 
369
 * @numerator:   return location for numerator
 
370
 * @denominator: return location for denominator
 
371
 *
 
372
 * Retrieves the current zoom factor of @model as a fraction.
 
373
 *
 
374
 * Since GIMP 2.4
 
375
 **/
 
376
void
 
377
gimp_zoom_model_get_fraction (GimpZoomModel *model,
 
378
                              gint          *numerator,
 
379
                              gint          *denominator)
 
380
{
 
381
  gint     p0, p1, p2;
 
382
  gint     q0, q1, q2;
 
383
  gdouble  zoom_factor;
 
384
  gdouble  remainder, next_cf;
 
385
  gboolean swapped = FALSE;
 
386
 
 
387
  g_return_if_fail (GIMP_IS_ZOOM_MODEL (model));
 
388
  g_return_if_fail (numerator != NULL && denominator != NULL);
 
389
 
 
390
  zoom_factor = gimp_zoom_model_get_factor (model);
 
391
 
 
392
  /* make sure that zooming behaves symmetrically */
 
393
  if (zoom_factor < 1.0)
 
394
    {
 
395
      zoom_factor = 1.0 / zoom_factor;
 
396
      swapped = TRUE;
 
397
    }
 
398
 
 
399
  /* calculate the continued fraction for the desired zoom factor */
 
400
 
 
401
  p0 = 1;
 
402
  q0 = 0;
 
403
  p1 = floor (zoom_factor);
 
404
  q1 = 1;
 
405
 
 
406
  remainder = zoom_factor - p1;
 
407
 
 
408
  while (fabs (remainder) >= 0.0001 &&
 
409
         fabs (((gdouble) p1 / q1) - zoom_factor) > 0.0001)
 
410
    {
 
411
      remainder = 1.0 / remainder;
 
412
 
 
413
      next_cf = floor (remainder);
 
414
 
 
415
      p2 = next_cf * p1 + p0;
 
416
      q2 = next_cf * q1 + q0;
 
417
 
 
418
      /* Numerator and Denominator are limited by 256 */
 
419
      /* also absurd ratios like 170:171 are excluded */
 
420
      if (p2 > 256 || q2 > 256 || (p2 > 1 && q2 > 1 && p2 * q2 > 200))
 
421
        break;
 
422
 
 
423
      /* remember the last two fractions */
 
424
      p0 = p1;
 
425
      p1 = p2;
 
426
      q0 = q1;
 
427
      q1 = q2;
 
428
 
 
429
      remainder = remainder - next_cf;
 
430
    }
 
431
 
 
432
  zoom_factor = (gdouble) p1 / q1;
 
433
 
 
434
  /* hard upper and lower bounds for zoom ratio */
 
435
 
 
436
  if (zoom_factor > 256.0)
 
437
    {
 
438
      p1 = 256;
 
439
      q1 = 1;
 
440
    }
 
441
  else if (zoom_factor < 1.0 / 256.0)
 
442
    {
 
443
      p1 = 1;
 
444
      q1 = 256;
 
445
    }
 
446
 
 
447
  if (swapped)
 
448
    {
 
449
      *numerator = q1;
 
450
      *denominator = p1;
 
451
    }
 
452
  else
 
453
    {
 
454
      *numerator = p1;
 
455
      *denominator = q1;
 
456
    }
 
457
}
 
458
 
 
459
static GtkWidget *
 
460
zoom_button_new (const gchar *stock_id,
 
461
                 GtkIconSize  icon_size)
 
462
{
 
463
  GtkWidget *button;
 
464
 
 
465
  if (icon_size > 0)
 
466
    {
 
467
      GtkWidget *image = gtk_image_new_from_stock (stock_id, icon_size);
 
468
 
 
469
      button = gtk_button_new ();
 
470
      gtk_container_add (GTK_CONTAINER (button), image);
 
471
      gtk_widget_show (image);
 
472
    }
 
473
  else
 
474
    {
 
475
      button = gtk_button_new_from_stock (stock_id);
 
476
    }
 
477
 
 
478
  return button;
 
479
}
 
480
 
 
481
static void
 
482
zoom_in_button_callback (GimpZoomModel *model,
 
483
                         gdouble        old,
 
484
                         gdouble        new,
 
485
                         GtkWidget     *button)
 
486
{
 
487
  GimpZoomModelPrivate *priv = GIMP_ZOOM_MODEL_GET_PRIVATE (model);
 
488
 
 
489
  gtk_widget_set_sensitive (button, priv->value != priv->maximum);
 
490
}
 
491
 
 
492
static void
 
493
zoom_out_button_callback (GimpZoomModel *model,
 
494
                          gdouble        old,
 
495
                          gdouble        new,
 
496
                          GtkWidget     *button)
 
497
{
 
498
  GimpZoomModelPrivate *priv = GIMP_ZOOM_MODEL_GET_PRIVATE (model);
 
499
 
 
500
  gtk_widget_set_sensitive (button, priv->value != priv->minimum);
 
501
}
 
502
 
 
503
/**
 
504
 * gimp_zoom_button_new:
 
505
 * @model:     a #GimpZoomModel
 
506
 * @zoom_type:
 
507
 * @icon_size: use 0 for a button with text labels
 
508
 *
 
509
 * Return value: a newly created GtkButton
 
510
 *
 
511
 * Since GIMP 2.4
 
512
 **/
 
513
GtkWidget *
 
514
gimp_zoom_button_new (GimpZoomModel *model,
 
515
                      GimpZoomType   zoom_type,
 
516
                      GtkIconSize    icon_size)
 
517
{
 
518
  GtkWidget *button = NULL;
 
519
 
 
520
  g_return_val_if_fail (GIMP_IS_ZOOM_MODEL (model), NULL);
 
521
 
 
522
  switch (zoom_type)
 
523
    {
 
524
    case GIMP_ZOOM_IN:
 
525
      button = zoom_button_new (GTK_STOCK_ZOOM_IN, icon_size);
 
526
      g_signal_connect_swapped (button, "clicked",
 
527
                                G_CALLBACK (gimp_zoom_model_zoom_in),
 
528
                                model);
 
529
      g_signal_connect_object (model, "zoomed",
 
530
                               G_CALLBACK (zoom_in_button_callback),
 
531
                               button, 0);
 
532
      break;
 
533
 
 
534
    case GIMP_ZOOM_OUT:
 
535
      button = zoom_button_new (GTK_STOCK_ZOOM_OUT, icon_size);
 
536
      g_signal_connect_swapped (button, "clicked",
 
537
                                G_CALLBACK (gimp_zoom_model_zoom_out),
 
538
                                model);
 
539
      g_signal_connect_object (model, "zoomed",
 
540
                               G_CALLBACK (zoom_out_button_callback),
 
541
                               button, 0);
 
542
      break;
 
543
 
 
544
    default:
 
545
      g_warning ("sorry, no button for this zoom type (%d)", zoom_type);
 
546
      break;
 
547
    }
 
548
 
 
549
  if (button)
 
550
    {
 
551
      gdouble zoom = gimp_zoom_model_get_factor (model);
 
552
 
 
553
      /*  set initial button sensitivity  */
 
554
      g_signal_emit (model, zoom_model_signals[ZOOMED], 0, zoom, zoom);
 
555
 
 
556
      if (icon_size > 0)
 
557
        {
 
558
          const gchar *desc;
 
559
 
 
560
          if (gimp_enum_get_value (GIMP_TYPE_ZOOM_TYPE, zoom_type,
 
561
                                   NULL, NULL, &desc, NULL))
 
562
            {
 
563
              gimp_help_set_help_data (button, desc, NULL);
 
564
            }
 
565
        }
 
566
    }
 
567
 
 
568
  return button;
 
569
}
 
570
 
 
571
/**
 
572
 * gimp_zoom_model_zoom_step:
 
573
 * @zoom_type:
 
574
 * @scale:     ignored unless @zoom_type == %GIMP_ZOOM_TO
 
575
 *
 
576
 * Utility function to calculate a new scale factor.
 
577
 *
 
578
 * Return value: the new scale factor
 
579
 *
 
580
 * Since GIMP 2.4
 
581
 **/
 
582
gdouble
 
583
gimp_zoom_model_zoom_step (GimpZoomType zoom_type,
 
584
                           gdouble      scale)
 
585
{
 
586
  gint    i, n_presets;
 
587
  gdouble new_scale = 1.0;
 
588
 
 
589
  /* This table is constructed to have fractions, that approximate
 
590
   * sqrt(2)^k. This gives a smooth feeling regardless of the starting
 
591
   * zoom level.
 
592
   *
 
593
   * Zooming in/out always jumps to a zoom step from the list below.
 
594
   * However, we try to guarantee a certain size of the step, to
 
595
   * avoid silly jumps from 101% to 100%.
 
596
   *
 
597
   * The factor 1.1 is chosen a bit arbitrary, but feels better
 
598
   * than the geometric median of the zoom steps (2^(1/4)).
 
599
   */
 
600
 
 
601
#define ZOOM_MIN_STEP 1.1
 
602
 
 
603
  const gdouble presets[] = {
 
604
    1.0 / 256, 1.0 / 180, 1.0 / 128, 1.0 / 90,
 
605
    1.0 / 64,  1.0 / 45,  1.0 / 32,  1.0 / 23,
 
606
    1.0 / 16,  1.0 / 11,  1.0 / 8,   2.0 / 11,
 
607
    1.0 / 4,   1.0 / 3,   1.0 / 2,   2.0 / 3,
 
608
      1.0,
 
609
               3.0 / 2,      2.0,      3.0,
 
610
      4.0,    11.0 / 2,      8.0,     11.0,
 
611
      16.0,     23.0,       32.0,     45.0,
 
612
      64.0,     90.0,      128.0,    180.0,
 
613
      256.0,
 
614
  };
 
615
 
 
616
  n_presets = G_N_ELEMENTS (presets);
 
617
 
 
618
  switch (zoom_type)
 
619
    {
 
620
    case GIMP_ZOOM_IN:
 
621
      scale *= ZOOM_MIN_STEP;
 
622
 
 
623
      new_scale = presets[n_presets - 1];
 
624
      for (i = n_presets - 1; i >= 0 && presets[i] > scale; i--)
 
625
        new_scale = presets[i];
 
626
 
 
627
      break;
 
628
 
 
629
    case GIMP_ZOOM_OUT:
 
630
      scale /= ZOOM_MIN_STEP;
 
631
 
 
632
      new_scale = presets[0];
 
633
      for (i = 0; i < n_presets && presets[i] < scale; i++)
 
634
        new_scale = presets[i];
 
635
 
 
636
      break;
 
637
 
 
638
    case GIMP_ZOOM_IN_MORE:
 
639
      scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_IN, scale);
 
640
      scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_IN, scale);
 
641
      scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_IN, scale);
 
642
      new_scale = scale;
 
643
      break;
 
644
 
 
645
    case GIMP_ZOOM_OUT_MORE:
 
646
      scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, scale);
 
647
      scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, scale);
 
648
      scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, scale);
 
649
      new_scale = scale;
 
650
      break;
 
651
 
 
652
    case GIMP_ZOOM_IN_MAX:
 
653
      new_scale = ZOOM_MAX;
 
654
      break;
 
655
 
 
656
    case GIMP_ZOOM_OUT_MAX:
 
657
      new_scale = ZOOM_MIN;
 
658
      break;
 
659
 
 
660
    case GIMP_ZOOM_TO:
 
661
      new_scale = scale;
 
662
      break;
 
663
    }
 
664
 
 
665
  return CLAMP (new_scale, ZOOM_MIN, ZOOM_MAX);
 
666
 
 
667
#undef ZOOM_MIN_STEP
 
668
}