istereo2
view src/uitheme.cc @ 10:2a0ef5efb8e2
fixed macosx build
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 27 Sep 2015 04:55:30 +0300 |
parents | 64e15874f3bd |
children | 57188f7d9304 |
line source
1 #include <map>
2 #include <string>
3 #include "goatkit/goatkit.h"
4 #include "opengl.h"
5 #include "sanegl.h"
6 #include "drawtext.h"
7 #include "sdr.h"
9 #define VIS_THRES 0.005
11 using namespace goatkit;
13 extern int view_xsz, view_ysz;
14 extern unsigned int prog_ui, prog_font;
15 extern struct dtx_font *font;
17 static void draw_label(const Widget *w);
18 static void draw_text(float x, float y, const char *text);
20 static struct {
21 const char *name;
22 WidgetDrawFunc func;
23 } widget_funcs[] = {
24 { "label", draw_label },
25 {0, 0}
26 };
28 static std::map<std::string, WidgetDrawFunc> funcmap;
31 extern "C" __attribute__ ((used))
32 WidgetDrawFunc get_widget_func(const char *name)
33 {
34 static bool initialized;
36 if(!initialized) {
37 for(int i=0; widget_funcs[i].func; i++) {
38 funcmap[widget_funcs[i].name] = widget_funcs[i].func;
39 }
40 initialized = true;
41 }
42 return funcmap[name];
43 }
45 static void begin_drawing(const Widget *w)
46 {
47 Vec2 pos = w->get_position();
49 glEnable(GL_BLEND);
50 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
52 gl_matrix_mode(GL_MODELVIEW);
53 gl_push_matrix();
54 gl_load_identity();
55 gl_translatef(pos.x, pos.y, 0);
56 }
58 static void end_drawing(const Widget *w)
59 {
60 gl_matrix_mode(GL_MODELVIEW);
61 gl_pop_matrix();
62 }
64 static void draw_label(const Widget *w)
65 {
66 Vec2 pos = w->get_position();
67 float vis = w->get_visibility();
68 if(vis < VIS_THRES) return;
70 begin_drawing(w);
71 draw_text(pos.x, pos.y, w->get_text());
72 end_drawing(w);
73 }
75 static void draw_text(float x, float y, const char *text)
76 {
77 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0);
78 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap));
80 float aspect = (float)view_xsz / (float)view_ysz;
81 float virt_xsz = 420.0 * aspect;
82 float virt_ysz = 420.0;
84 gl_matrix_mode(GL_PROJECTION);
85 gl_push_matrix();
86 gl_load_identity();
87 gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1);
89 gl_matrix_mode(GL_MODELVIEW);
90 gl_push_matrix();
91 gl_load_identity();
92 gl_translatef(x * virt_xsz, y * virt_ysz, 0);
94 bind_program(prog_font);
95 set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0);
96 gl_apply_xform(prog_ui);
98 dtx_string(text);
100 gl_matrix_mode(GL_PROJECTION);
101 gl_pop_matrix();
102 gl_matrix_mode(GL_MODELVIEW);
103 gl_pop_matrix();
104 }