#include "mouse_wheel.h" #include "../actions/zoom.h" #include "../../view/state0.h" #include #include #define S state0 void mouse_wheel (int button, int dir, int x, int y) { /* * 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. */ double width = fabs(S.ortho.max_x - S.ortho.min_x); double height = fabs(S.ortho.max_y - S.ortho.min_y); /* * Box the smaller of the two dimensions. */ double box = 0.0; if (width <= height) box = width; else box = height; /* * 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) { zoom (x1 + step, y1 + step, x2 - step, y2 - step); } // Zoom out else { zoom (x1 - step, y1 - step, x2 + step, y2 + step); } return; }