summaryrefslogtreecommitdiffstats
Side-by-side diff
-rw-r--r--src/controller/actions/set_ortho.c13
-rw-r--r--src/controller/actions/zoom.c70
-rw-r--r--src/controller/actions/zoom.h4
-rw-r--r--src/controller/callbacks/display.c6
-rw-r--r--src/controller/callbacks/keyboard.c7
-rw-r--r--src/controller/callbacks/mouse.c49
-rw-r--r--src/controller/callbacks/mouse_wheel.c66
-rw-r--r--src/controller/callbacks/reshape.c68
-rw-r--r--src/model/geometry/density_legend_geometry.c18
-rw-r--r--src/model/state/zoom_info.h1
-rw-r--r--src/model/state/zoom_info_init.c6
11 files changed, 197 insertions, 111 deletions
diff --git a/src/controller/callbacks/mouse_wheel.c b/src/controller/callbacks/mouse_wheel.c
index 52d3c8b..9ca73bc 100644
--- a/src/controller/callbacks/mouse_wheel.c
+++ b/src/controller/callbacks/mouse_wheel.c
@@ -1,44 +1,74 @@
#include "mouse_wheel.h"
#include "../actions/zoom.h"
+#include "../../view/state0.h"
#include <GL/glut.h>
+#include <math.h>
+
+#define S state0
void
mouse_wheel (int button, int dir, int x, int y)
{
/*
- * Get the current coordinates, substract some fixed amount and
- * then perform the zoom.
+ * Start at the origin of the window. An alternative would be to
+ * start at the position of the mouse. Calculate a bounding box
+ * that will be the selection and zoom to it.
*/
- GLint viewport[4];
- glGetIntegerv (GL_VIEWPORT, viewport);
+ double width = fabs(S.ortho.max_x - S.ortho.min_x);
+ double height = fabs(S.ortho.max_y - S.ortho.min_y);
/*
- * The step size could be either a fixed number of pixels or a percentage.
+ * Box the smaller of the two dimensions.
*/
- // int step = 5;
- int step = (viewport[3] - viewport[1]) * 0.10;
+ double box = 0.0;
+ if (width <= height)
+ box = width;
+ else
+ box = height;
/*
- * Not that the focus of the zoom is currently the center of the
- * window but could alternatively be the mouse pointer's position.
+ * The step size could be either a fixed number of pixels or a
+ * percentage. Here we take 10% of the size of the box.
*/
+ double step = box * 0.10;
+
+ double x1 = 0.0;
+ double y1 = 0.0;
+ double x2 = 0.0;
+ double y2 = 0.0;
+
+ if (width < height)
+ {
+ x1 = S.ortho.min_x;
+ x2 = S.ortho.max_x;
+ y1 = ((S.ortho.max_y + S.ortho.min_y) / 2.0) - (0.5 * width);
+ y2 = ((S.ortho.max_y + S.ortho.min_y) / 2.0) + (0.5 * width);
+ }
+ else if (width > height)
+ {
+ x1 = ((S.ortho.max_x + S.ortho.min_x) / 2.0) - (0.5 * height);
+ x2 = ((S.ortho.max_x + S.ortho.min_x) / 2.0) + (0.5 * height);
+ y1 = S.ortho.min_y;
+ y2 = S.ortho.max_y;
+ }
+ else
+ {
+ x1 = S.ortho.min_x;
+ x2 = S.ortho.max_x;
+ y1 = S.ortho.min_y;
+ y2 = S.ortho.max_y;
+ }
// Zoom in
- if (dir > 0)
+ if (dir > 0)
{
- zoom (step,
- step,
- viewport[3] - step,
- viewport[3] - step);
+ zoom (x1 + step, y1 + step, x2 - step, y2 - step);
}
// Zoom out
else
{
- zoom (-step,
- -step,
- viewport[3] + step,
- viewport[3] + step);
+ zoom (x1 - step, y1 - step, x2 + step, y2 + step);
}
return;

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.