[dia] Introduce ddisplay_zoom_middle() to reduce code duplication
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Introduce ddisplay_zoom_middle() to reduce code duplication
- Date: Sun, 29 Jul 2012 20:49:01 +0000 (UTC)
commit efde1a7bc403407673f50025ed5c7b791c0580e8
Author: Hans Breuer <hans breuer org>
Date: Fri Jul 27 22:27:26 2012 +0200
Introduce ddisplay_zoom_middle() to reduce code duplication
app/commands.c | 14 ++------------
app/disp_callbacks.c | 12 ++----------
app/display.c | 15 ++++++++++++++-
app/display.h | 2 ++
app/interface.c | 16 ++--------------
5 files changed, 22 insertions(+), 37 deletions(-)
---
diff --git a/app/commands.c b/app/commands.c
index 542af9f..0bdb7aa 100644
--- a/app/commands.c
+++ b/app/commands.c
@@ -979,32 +979,22 @@ void
view_zoom_in_callback (GtkAction *action)
{
DDisplay *ddisp;
- Point middle;
- Rectangle *visible;
ddisp = ddisplay_active();
if (!ddisp) return;
- visible = &ddisp->visible;
- middle.x = visible->left*0.5 + visible->right*0.5;
- middle.y = visible->top*0.5 + visible->bottom*0.5;
- ddisplay_zoom(ddisp, &middle, M_SQRT2);
+ ddisplay_zoom_middle(ddisp, M_SQRT2);
}
void
view_zoom_out_callback (GtkAction *action)
{
DDisplay *ddisp;
- Point middle;
- Rectangle *visible;
ddisp = ddisplay_active();
if (!ddisp) return;
- visible = &ddisp->visible;
- middle.x = visible->left*0.5 + visible->right*0.5;
- middle.y = visible->top*0.5 + visible->bottom*0.5;
- ddisplay_zoom(ddisp, &middle, M_SQRT1_2);
+ ddisplay_zoom_middle(ddisp, M_SQRT1_2);
}
void
diff --git a/app/disp_callbacks.c b/app/disp_callbacks.c
index e83b26d..c17299f 100644
--- a/app/disp_callbacks.c
+++ b/app/disp_callbacks.c
@@ -906,19 +906,11 @@ ddisplay_canvas_events (GtkWidget *canvas,
break;
case GDK_KP_Add:
case GDK_plus:
- visible = &ddisp->visible;
- middle.x = visible->left*0.5 + visible->right*0.5;
- middle.y = visible->top*0.5 + visible->bottom*0.5;
-
- ddisplay_zoom(ddisp, &middle, M_SQRT2);
+ ddisplay_zoom_middle(ddisp, M_SQRT2);
break;
case GDK_KP_Subtract:
case GDK_minus:
- visible = &ddisp->visible;
- middle.x = visible->left*0.5 + visible->right*0.5;
- middle.y = visible->top*0.5 + visible->bottom*0.5;
-
- ddisplay_zoom(ddisp, &middle, M_SQRT1_2);
+ ddisplay_zoom_middle(ddisp, M_SQRT1_2);
break;
case GDK_Shift_L:
case GDK_Shift_R:
diff --git a/app/display.c b/app/display.c
index 3c1d8fc..ce929a6 100644
--- a/app/display.c
+++ b/app/display.c
@@ -807,6 +807,19 @@ ddisplay_zoom(DDisplay *ddisp, Point *point, real magnify)
update_zoom_status (ddisp);
}
+/* Zoom around the middle point of the visible area
+ */
+void
+ddisplay_zoom_middle(DDisplay *ddisp, real magnify)
+{
+ Point middle;
+ Rectangle *visible;
+
+ visible = &ddisp->visible;
+ middle.x = visible->left*0.5 + visible->right*0.5;
+ middle.y = visible->top*0.5 + visible->bottom*0.5;
+}
+
/*
When using the mouse wheel button to zoom in and out, it is more
intuitive to maintain the drawing zoom center-point based on the
@@ -819,7 +832,7 @@ ddisplay_zoom_centered(DDisplay *ddisp, Point *point, real magnify)
Rectangle *visible;
real width, height;
/* cursor position ratios */
- real rx,ry;
+ real rx,ry;
if ((ddisp->zoom_factor <= DDISPLAY_MIN_ZOOM) && (magnify<=1.0))
return;
diff --git a/app/display.h b/app/display.h
index 4bf9541..cdc8e4e 100644
--- a/app/display.h
+++ b/app/display.h
@@ -145,6 +145,8 @@ void ddisplay_set_origo(DDisplay *ddisp,
coord x, coord y);
void ddisplay_zoom(DDisplay *ddisp, Point *point,
real zoom_factor);
+void ddisplay_zoom_middle(DDisplay *ddisp, real magnify);
+
void ddisplay_zoom_centered(DDisplay *ddisp, Point *point, real magnify);
void ddisplay_set_snap_to_grid(DDisplay *ddisp, gboolean snap);
void ddisplay_set_snap_to_objects(DDisplay *ddisp, gboolean magnetic);
diff --git a/app/interface.c b/app/interface.c
index d09a42a..6cd9a75 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -179,19 +179,13 @@ view_zoom_set (float factor)
{
DDisplay *ddisp;
real scale;
- Point middle;
- Rectangle *visible;
ddisp = ddisplay_active();
if (!ddisp) return;
- visible = &ddisp->visible;
- middle.x = visible->left*0.5 + visible->right*0.5;
- middle.y = visible->top*0.5 + visible->bottom*0.5;
-
scale = ((real) factor)/1000.0 * DDISPLAY_NORMAL_ZOOM;
- ddisplay_zoom(ddisp, &middle, scale / ddisp->zoom_factor);
+ ddisplay_zoom_middle(ddisp, scale / ddisp->zoom_factor);
}
static void
@@ -207,9 +201,6 @@ zoom_activate_callback(GtkWidget *item, gpointer user_data)
}
if (sscanf(zoom_text, "%f", &zoom_amount) == 1) {
- Point middle;
- Rectangle *visible;
-
/* Set limits to avoid crashes, see bug #483384 */
if (zoom_amount < .1) {
zoom_amount = .1;
@@ -221,10 +212,7 @@ zoom_activate_callback(GtkWidget *item, gpointer user_data)
g_free(zoomamount);
magnify = (zoom_amount*DDISPLAY_NORMAL_ZOOM/100.0)/ddisp->zoom_factor;
if (fabs(magnify - 1.0) > 0.000001) {
- visible = &ddisp->visible;
- middle.x = visible->left*0.5 + visible->right*0.5;
- middle.y = visible->top*0.5 + visible->bottom*0.5;
- ddisplay_zoom(ddisp, &middle, magnify);
+ ddisplay_zoom_middle(ddisp, magnify);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]