-rw-r--r-- | src/controller/actions/set_ortho.c | 13 | ||||
-rw-r--r-- | src/controller/actions/zoom.c | 70 | ||||
-rw-r--r-- | src/controller/actions/zoom.h | 4 | ||||
-rw-r--r-- | src/controller/callbacks/display.c | 6 | ||||
-rw-r--r-- | src/controller/callbacks/keyboard.c | 7 | ||||
-rw-r--r-- | src/controller/callbacks/mouse.c | 49 | ||||
-rw-r--r-- | src/controller/callbacks/mouse_wheel.c | 66 | ||||
-rw-r--r-- | src/controller/callbacks/reshape.c | 68 | ||||
-rw-r--r-- | src/model/geometry/density_legend_geometry.c | 18 | ||||
-rw-r--r-- | src/model/state/zoom_info.h | 1 | ||||
-rw-r--r-- | src/model/state/zoom_info_init.c | 6 |
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 @@ | |||
1 | #include "mouse_wheel.h" | 1 | #include "mouse_wheel.h" |
2 | #include "../actions/zoom.h" | 2 | #include "../actions/zoom.h" |
3 | #include "../../view/state0.h" | ||
3 | #include <GL/glut.h> | 4 | #include <GL/glut.h> |
5 | #include <math.h> | ||
6 | |||
7 | #define S state0 | ||
4 | 8 | ||
5 | void | 9 | void |
6 | mouse_wheel (int button, int dir, int x, int y) | 10 | mouse_wheel (int button, int dir, int x, int y) |
7 | { | 11 | { |
8 | /* | 12 | /* |
9 | * Get the current coordinates, substract some fixed amount and | 13 | * Start at the origin of the window. An alternative would be to |
10 | * then perform the zoom. | 14 | * start at the position of the mouse. Calculate a bounding box |
15 | * that will be the selection and zoom to it. | ||
11 | */ | 16 | */ |
12 | GLint viewport[4]; | 17 | double width = fabs(S.ortho.max_x - S.ortho.min_x); |
13 | glGetIntegerv (GL_VIEWPORT, viewport); | 18 | double height = fabs(S.ortho.max_y - S.ortho.min_y); |
14 | 19 | ||
15 | /* | 20 | /* |
16 | * The step size could be either a fixed number of pixels or a percentage. | 21 | * Box the smaller of the two dimensions. |
17 | */ | 22 | */ |
18 | // int step = 5; | 23 | double box = 0.0; |
19 | int step = (viewport[3] - viewport[1]) * 0.10; | 24 | if (width <= height) |
25 | box = width; | ||
26 | else | ||
27 | box = height; | ||
20 | 28 | ||
21 | /* | 29 | /* |
22 | * Not that the focus of the zoom is currently the center of the | 30 | * The step size could be either a fixed number of pixels or a |
23 | * window but could alternatively be the mouse pointer's position. | 31 | * percentage. Here we take 10% of the size of the box. |
24 | */ | 32 | */ |
33 | double step = box * 0.10; | ||
34 | |||
35 | double x1 = 0.0; | ||
36 | double y1 = 0.0; | ||
37 | double x2 = 0.0; | ||
38 | double y2 = 0.0; | ||
39 | |||
40 | if (width < height) | ||
41 | { | ||
42 | x1 = S.ortho.min_x; | ||
43 | x2 = S.ortho.max_x; | ||
44 | y1 = ((S.ortho.max_y + S.ortho.min_y) / 2.0) - (0.5 * width); | ||
45 | y2 = ((S.ortho.max_y + S.ortho.min_y) / 2.0) + (0.5 * width); | ||
46 | } | ||
47 | else if (width > height) | ||
48 | { | ||
49 | x1 = ((S.ortho.max_x + S.ortho.min_x) / 2.0) - (0.5 * height); | ||
50 | x2 = ((S.ortho.max_x + S.ortho.min_x) / 2.0) + (0.5 * height); | ||
51 | y1 = S.ortho.min_y; | ||
52 | y2 = S.ortho.max_y; | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | x1 = S.ortho.min_x; | ||
57 | x2 = S.ortho.max_x; | ||
58 | y1 = S.ortho.min_y; | ||
59 | y2 = S.ortho.max_y; | ||
60 | } | ||
25 | 61 | ||
26 | // Zoom in | 62 | // Zoom in |
27 | if (dir > 0) | 63 | if (dir > 0) |
28 | { | 64 | { |
29 | zoom (step, | 65 | zoom (x1 + step, y1 + step, x2 - step, y2 - step); |
30 | step, | ||
31 | viewport[3] - step, | ||
32 | viewport[3] - step); | ||
33 | } | 66 | } |
34 | 67 | ||
35 | // Zoom out | 68 | // Zoom out |
36 | else | 69 | else |
37 | { | 70 | { |
38 | zoom (-step, | 71 | zoom (x1 - step, y1 - step, x2 + step, y2 + step); |
39 | -step, | ||
40 | viewport[3] + step, | ||
41 | viewport[3] + step); | ||
42 | } | 72 | } |
43 | 73 | ||
44 | return; | 74 | return; |