path:
root/
src/
controller/
actions/
zoom.c (
plain)
blob: 53da49bb86bc7c4e37badfb86f7e2b173df9d4a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "zoom.h"
#include "../callbacks/reshape.h"
#include "../../util/check_error.h"
#include "../../view/state0.h"
#include <GL/glut.h>
#include <math.h>
/*
* A simple alias to make the code more readable.
*/
#define S state0
void
zoom (double x1, double y1, double x2, double y2)
{
S.zoom.active = true;
S.zoom.coords[0] = x1;
S.zoom.coords[1] = x2;
S.zoom.coords[2] = y1;
S.zoom.coords[3] = y2;
/*
* Preserve the aspect ratio. First convert the selection to the
* aspect ratio of the original geometry. The world is a square so
* convert the zoom region to a square. The reshape callback
* performs step two of converting the squarified zoom region to the
* aspect ratio of the window. This is done in reshape as the window
* may change while the zoom region is held the same.
*/
double width = S.zoom.coords[1] - S.zoom.coords[0];
double height = S.zoom.coords[3] - S.zoom.coords[2];
double difference = fabs (width - height);
if (width > height)
{
S.zoom.coords[2] -= 0.5 * difference;
S.zoom.coords[3] += 0.5 * difference;
}
else
{
S.zoom.coords[0] -= 0.5 * difference;
S.zoom.coords[1] += 0.5 * difference;
}
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
reshape (viewport[2], viewport[3]);
glutPostRedisplay ();
return;
}
|