1 #include <string>
2
3 #include "opengl_helpers.h"
4
5 #include "layout.h"
6
7 using namespace Layout;
8
9 static const int border_sz = 10; // pixels
10 static const int header_sz = 20; // pixels
11
12 static struct info state;
13
setup(int image_width,int image_height)14 const struct info &Layout::setup(int image_width, int image_height) {
15 state.window_width = 2 * image_width + 3 * border_sz;
16 state.window_height = 2 * image_height + border_sz + 2 * header_sz;
17 return state;
18 }
19
draw_texture(enum location location,GLuint texture_id,int width,int height,const std::string & label)20 void Layout::draw_texture(enum location location, GLuint texture_id, int width, int height, const std::string &label) {
21 int x0, x1, y0, y1, lx, ly;
22 switch (location) { // set X coords
23 case LL:
24 case UL:
25 x0 = border_sz;
26 x1 = x0 + width;
27 lx = x0 + 2;
28 break;
29 case LR:
30 case UR:
31 x1 = state.window_width - border_sz;
32 x0 = x1 - width;
33 lx = x0 + 2;
34 break;
35 }
36 switch (location) { // set Y coords
37 case LL:
38 case LR:
39 y0 = header_sz;
40 y1 = y0 + height;
41 ly = 6;
42 break;
43 case UL:
44 case UR:
45 y1 = state.window_height - header_sz;
46 y0 = y1 - height;
47 ly = y1 + 6;
48 break;
49 }
50
51 OpenGLHelpers::display_texture(texture_id, 2.0 * x0 / state.window_width - 1.0, 2.0 * x1 / state.window_width - 1.0, 2.0 * y0 / state.window_height - 1.0, 2.0 * y1 / state.window_height - 1.0);
52 OpenGLHelpers::draw_text(label, 2.0 * lx / state.window_width - 1.0, 2.0 * ly / state.window_height - 1.0);
53 }
54
draw_image(enum location location,const uint8_t * data,int width,int height,const std::string & label)55 void Layout::draw_image(enum location location, const uint8_t *data, int width, int height, const std::string &label) {
56 const auto texture_id = OpenGLHelpers::create_texture(width, height, data);
57 draw_texture(location, texture_id, width, height, label);
58 OpenGLHelpers::delete_texture(texture_id);
59 }
60