plug-ins: Allow Zoom Out in ImageMap

This patch converts the image map
plug-in to use a floating point ratio rather
than an integer zoom factor. This allows
us to zoom out past the 1:1 ratio.
Additionally, it fixes the statusbar display
so that it shows 2:1 for zoomed in rather
than 1:2.
This commit is contained in:
Alx Sa 2024-07-23 04:08:18 +00:00
parent c700e7d48f
commit b7532766ad
6 changed files with 71 additions and 60 deletions

View File

@ -115,6 +115,21 @@
<submenu>
<attribute name="label" translatable="yes">Zoom To</attribute>
<section>
<item>
<attribute name="label" translatable="yes">8:1</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">8</attribute>
</item>
<item>
<attribute name="label" translatable="yes">4:1</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">4</attribute>
</item>
<item>
<attribute name="label" translatable="yes">2:1</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">2</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:1</attribute>
<attribute name="action">app.zoom</attribute>
@ -123,37 +138,17 @@
<item>
<attribute name="label" translatable="yes">1:2</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">2</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:3</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">3</attribute>
<attribute name="target">0</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:4</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">4</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:5</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">5</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:6</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">6</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:7</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">7</attribute>
<attribute name="target">-2</attribute>
</item>
<item>
<attribute name="label" translatable="yes">1:8</attribute>
<attribute name="action">app.zoom</attribute>
<attribute name="target">8</attribute>
<attribute name="target">-6</attribute>
</item>
</section>
</submenu>

View File

@ -58,8 +58,9 @@
#define MAX_ZOOM_FACTOR 8
#define ZOOMED(x) (_zoom_factor * (x))
#define GET_REAL_COORD(x) ((x) / _zoom_factor)
#define MIN_ZOOM_FACTOR -6
#define ZOOMED(x) (_zoom_ratio * (x))
#define GET_REAL_COORD(x) ((x) / _zoom_ratio)
GType imap_get_type (void) G_GNUC_CONST;
@ -115,6 +116,7 @@ static Selection_t *_selection;
static StatusBar_t *_statusbar;
static ObjectList_t *_shapes;
static gint _zoom_factor = 1;
static gfloat _zoom_ratio = 1;
static gboolean (*_button_press_func)(GtkWidget*, GdkEventButton*, gpointer);
static gpointer _button_press_param;
@ -398,7 +400,7 @@ zoom_in (gpointer data)
static gint
zoom_out (gpointer data)
{
if (_zoom_factor > 1)
if (_zoom_factor > MIN_ZOOM_FACTOR)
{
set_zoom (_zoom_factor - 1);
menu_set_zoom (data, _zoom_factor);
@ -407,13 +409,19 @@ zoom_out (gpointer data)
}
void
set_zoom(gint zoom_factor)
set_zoom (gint zoom_factor)
{
set_busy_cursor();
_zoom_factor = zoom_factor;
preview_zoom(_preview, zoom_factor);
statusbar_set_zoom(_statusbar, zoom_factor);
remove_busy_cursor();
set_busy_cursor();
_zoom_factor = zoom_factor;
if (zoom_factor > 0)
_zoom_ratio = zoom_factor;
else
_zoom_ratio = 1.0f / ((zoom_factor - 2.0f) * -1.0f);
preview_zoom (_preview, _zoom_ratio);
statusbar_set_zoom (_statusbar, zoom_factor);
remove_busy_cursor ();
}
gint

View File

@ -52,7 +52,7 @@ menu_set_zoom_sensitivity (gpointer data,
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), factor < 8);
action = g_action_map_lookup_action (G_ACTION_MAP (imap->app), "zoom-out");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), factor > 1);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), factor > -6);
}
void

View File

@ -176,15 +176,17 @@ preview_unset_tmp_obj (Object_t *obj)
}
void
preview_zoom(Preview_t *preview, gint zoom_factor)
preview_zoom (Preview_t *preview,
gfloat zoom_factor)
{
preview->widget_width = preview->width * zoom_factor;
preview->widget_height = preview->height * zoom_factor;
gtk_widget_set_size_request (preview->preview, preview->widget_width,
preview->widget_height);
gtk_widget_queue_resize(preview->window);
render_preview(preview, preview->drawable);
preview_redraw();
preview->widget_width = ceil (preview->width * zoom_factor);
preview->widget_height = ceil (preview->height * zoom_factor);
gtk_widget_set_size_request (preview->preview, preview->widget_width,
preview->widget_height);
gtk_widget_queue_resize (preview->window);
render_preview (preview, preview->drawable);
preview_redraw ();
}
GdkCursorType

View File

@ -31,26 +31,27 @@ typedef struct {
GtkWidget *preview;
GtkWidget *hruler;
GtkWidget *vruler;
gint width;
gint height;
gint widget_width;
gint widget_height;
gint width;
gint height;
gint widget_width;
gint widget_height;
GdkCursorType cursor;
GdkCursorType cursor;
} Preview_t;
Preview_t *make_preview (GimpDrawable *drawable,
gpointer imap);
void preview_redraw (void);
Preview_t * make_preview (GimpDrawable *drawable,
gpointer imap);
void preview_redraw (void);
void preview_unset_tmp_obj (Object_t *obj);
void preview_set_tmp_obj (Object_t *obj);
void preview_unset_tmp_obj (Object_t *obj);
void preview_set_tmp_obj (Object_t *obj);
gint preview_get_width(GtkWidget *preview);
gint preview_get_height(GtkWidget *preview);
gint preview_get_width (GtkWidget *preview);
gint preview_get_height (GtkWidget *preview);
void preview_zoom(Preview_t *preview, gint zoom_factor);
GdkCursorType preview_set_cursor(Preview_t *preview,
GdkCursorType cursor_type);
void preview_zoom (Preview_t *preview,
gfloat zoom_factor);
GdkCursorType preview_set_cursor (Preview_t *preview,
GdkCursorType cursor_type);
#endif /* _IMAP_PREVIEW_H */

View File

@ -143,11 +143,16 @@ statusbar_clear_dimension(StatusBar_t *statusbar)
}
void
statusbar_set_zoom(StatusBar_t *statusbar, gint factor)
statusbar_set_zoom (StatusBar_t *statusbar,
gint factor)
{
char scratch[16];
char scratch[16];
sprintf(scratch, "1:%d", factor);
gtk_statusbar_push(GTK_STATUSBAR(statusbar->zoom), statusbar->zoom_id,
if (factor > 0)
sprintf (scratch, "%d:1", factor);
else
sprintf (scratch, "1:%d", ((factor - 2) * -1));
gtk_statusbar_push (GTK_STATUSBAR (statusbar->zoom), statusbar->zoom_id,
scratch);
}