-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/reshape.c b/src/controller/callbacks/reshape.c index 2455ea3..fec5443 100644 --- a/src/controller/callbacks/reshape.c +++ b/src/controller/callbacks/reshape.c @@ -3,6 +3,8 @@ #include "../actions/set_ortho.h" #include "reshape.h" #include <GL/glut.h> +#include <math.h> +#include <stdio.h> #define S state0 @@ -13,26 +15,60 @@ reshape (int w, int h) glLoadIdentity (); /* - * This scaling produces an odd effect when the coordinates are not - * centered at 0,0. When 0,0 is the lower left rather than the - * center this reshape is a bit unnatural since the image is not - * centered in the middle of the window. + * Scale the zoom region to the aspect ratio of the window. */ - - if (w <= h) + if (S.zoom.active) { - S.ortho.min_x = S.ortho_min; - S.ortho.max_x = S.ortho_max; - S.ortho.min_y = S.ortho_min * (double) h / (double) w; - S.ortho.max_y = S.ortho_max * (double) h / (double) w; + if (w >= h) + { + double scale + = ( ( (S.zoom.coords[1] - S.zoom.coords[0]) * ((double) w / (double) h) ) + - (S.zoom.coords[1] - S.zoom.coords[0]) ) + * 0.5; + + S.ortho.min_x = S.zoom.coords[0] - scale; + S.ortho.max_x = S.zoom.coords[1] + scale; + S.ortho.min_y = S.zoom.coords[2]; + S.ortho.max_y = S.zoom.coords[3]; + } + else + { + double scale + = ( ( (S.zoom.coords[3] - S.zoom.coords[2]) * ((double) h / (double) w) ) + - (S.zoom.coords[3] - S.zoom.coords[2]) ) + * 0.5; + + S.ortho.min_x = S.zoom.coords[0]; + S.ortho.max_x = S.zoom.coords[1]; + S.ortho.min_y = S.zoom.coords[2] - scale; + S.ortho.max_y = S.zoom.coords[3] + scale; + } } - else + + else { - S.ortho.min_x = S.ortho_min * (double) w / (double) h; - S.ortho.max_x = S.ortho_max * (double) w / (double) h; - S.ortho.min_y = S.ortho_min; - S.ortho.max_y = S.ortho_max; - } + /* + * This scaling produces an odd effect when the coordinates are + * not centered at 0,0. When 0,0 is the lower left rather than + * the center this reshape is a bit unnatural since the image is + * not centered in the middle of the window. Try chaning this + * to use the method used above for the zoom region scaling. + */ + if (w <= h) + { + S.ortho.min_x = S.ortho_min; + S.ortho.max_x = S.ortho_max; + S.ortho.min_y = S.ortho_min * (double) h / (double) w; + S.ortho.max_y = S.ortho_max * (double) h / (double) w; + } + else + { + S.ortho.min_x = S.ortho_min * (double) w / (double) h; + S.ortho.max_x = S.ortho_max * (double) w / (double) h; + S.ortho.min_y = S.ortho_min; + S.ortho.max_y = S.ortho_max; + } + } set_ortho (); |