istereo2
view src/uitheme.cc @ 12:57188f7d9304
merged changes from macosx
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Sep 2015 06:53:31 +0300 |
parents | 03cc3b1884d1 2a0ef5efb8e2 |
children | ea928c313344 |
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 // register ourselves as a built-in theme
46 GOATKIT_BUILTIN_THEME("istereo", get_widget_func);
48 static void begin_drawing(const Widget *w)
49 {
50 Vec2 pos = w->get_position();
52 glEnable(GL_BLEND);
53 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
55 gl_matrix_mode(GL_MODELVIEW);
56 gl_push_matrix();
57 gl_load_identity();
58 gl_translatef(pos.x, pos.y, 0);
59 }
61 static void end_drawing(const Widget *w)
62 {
63 gl_matrix_mode(GL_MODELVIEW);
64 gl_pop_matrix();
65 }
67 static void draw_label(const Widget *w)
68 {
69 Vec2 pos = w->get_position();
70 float vis = w->get_visibility();
71 if(vis < VIS_THRES) return;
73 begin_drawing(w);
74 draw_text(pos.x, pos.y, w->get_text());
75 end_drawing(w);
76 }
78 static void draw_text(float x, float y, const char *text)
79 {
80 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0);
81 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap));
83 float aspect = (float)view_xsz / (float)view_ysz;
84 float virt_xsz = 420.0 * aspect;
85 float virt_ysz = 420.0;
87 gl_matrix_mode(GL_PROJECTION);
88 gl_push_matrix();
89 gl_load_identity();
90 gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1);
92 gl_matrix_mode(GL_MODELVIEW);
93 gl_push_matrix();
94 gl_load_identity();
95 gl_translatef(x * virt_xsz, y * virt_ysz, 0);
97 bind_program(prog_font);
98 set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0);
99 gl_apply_xform(prog_ui);
101 dtx_string(text);
103 gl_matrix_mode(GL_PROJECTION);
104 gl_pop_matrix();
105 gl_matrix_mode(GL_MODELVIEW);
106 gl_pop_matrix();
107 }