18 files changed, 106 insertions, 47 deletions
diff --git a/src/model/geometry/density_legend_geometry.c b/src/model/geometry/density_legend_geometry.c new file mode 100644 index 0000000..83f34d9 --- a/dev/null +++ b/src/model/geometry/density_legend_geometry.c | |||
@@ -0,0 +1,83 @@ | |||
1 | #include "density_legend_geometry.h" | ||
2 | #include "../../view/exp004state0.h" | ||
3 | #include "../../controller/exp004reshape.h" | ||
4 | #include <GL/glut.h> | ||
5 | |||
6 | #define S exp004state0 | ||
7 | |||
8 | void | ||
9 | density_legend_geometry (void) | ||
10 | { | ||
11 | glNewList (S.list_offset + DENSITY_LEGEND_GEOMETRY, GL_COMPILE); | ||
12 | glPolygonMode (GL_FRONT, GL_FILL); | ||
13 | glColor4f (DEFAULT_COLOR_R, DEFAULT_COLOR_G, DEFAULT_COLOR_B, | ||
14 | DEFAULT_COLOR_A); | ||
15 | |||
16 | /* | ||
17 | * Calculate the bounding box for the legend. | ||
18 | */ | ||
19 | |||
20 | double a[2]; | ||
21 | double b[2]; | ||
22 | double c[2]; | ||
23 | double d[2]; | ||
24 | |||
25 | const double *left; | ||
26 | const double *right; | ||
27 | const double *top; | ||
28 | const double *bottom; | ||
29 | |||
30 | if (S.zoom.active) | ||
31 | { | ||
32 | left = &S.zoom.coords[0]; | ||
33 | right = &S.zoom.coords[1]; | ||
34 | bottom = &S.zoom.coords[2]; | ||
35 | top = &S.zoom.coords[3]; | ||
36 | } | ||
37 | else | ||
38 | { | ||
39 | left = &S.ortho.min_x; | ||
40 | right = &S.ortho.max_x; | ||
41 | bottom = &S.ortho.min_y; | ||
42 | top = &S.ortho.max_y; | ||
43 | } | ||
44 | |||
45 | /* | ||
46 | * This value should be a percentage of the world height so that it | ||
47 | * remains a fixed number of pixels tall when the window is resized | ||
48 | * or zoomed. | ||
49 | */ | ||
50 | double legend_height = (*top - *bottom) / S.viewport.h * 10.0; | ||
51 | |||
52 | a[0] = *left; | ||
53 | a[1] = *top; | ||
54 | b[0] = *right; | ||
55 | b[1] = *top; | ||
56 | c[0] = *right; | ||
57 | c[1] = *top - legend_height; | ||
58 | d[0] = *left; | ||
59 | d[1] = *top - legend_height; | ||
60 | |||
61 | /* | ||
62 | * Overlay a legend from default saturation / alpha to full saturation. | ||
63 | */ | ||
64 | for (int i = 1; i <= 1 / DEFAULT_COLOR_A; i++) | ||
65 | { | ||
66 | glBegin (GL_QUADS); | ||
67 | glVertex2dv (a); | ||
68 | glVertex2dv (b); | ||
69 | glVertex2dv (c); | ||
70 | glVertex2dv (d); | ||
71 | glEnd (); | ||
72 | |||
73 | /* | ||
74 | * Step left to right along the x-coordinate. | ||
75 | */ | ||
76 | a[0] = *left + (*right - *left) * (DEFAULT_COLOR_A * i); | ||
77 | d[0] = a[0]; | ||
78 | } | ||
79 | |||
80 | glEndList (); | ||
81 | |||
82 | return; | ||
83 | } | ||