istereo2

annotate src/uitheme.cc @ 8:661bf09db398

- replaced Quartz timer with cross-platform timer code - protected goatkit builtin theme function from being optimized out
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 07:09:37 +0300
parents a3c4fcc9f8f3
children 64e15874f3bd
rev   line source
nuclear@7 1 #include <map>
nuclear@7 2 #include <string>
nuclear@7 3 #include "goatkit/goatkit.h"
nuclear@7 4 #include "opengl.h"
nuclear@7 5 #include "drawtext.h"
nuclear@7 6 #include "sdr.h"
nuclear@7 7
nuclear@7 8 #define VIS_THRES 0.005
nuclear@7 9
nuclear@7 10 using namespace goatkit;
nuclear@7 11
nuclear@7 12 extern int view_xsz, view_ysz;
nuclear@7 13 extern unsigned int prog_ui, prog_font;
nuclear@7 14 extern struct dtx_font *font;
nuclear@7 15
nuclear@7 16 static void draw_label(const Widget *w);
nuclear@7 17 static void draw_text(float x, float y, const char *text);
nuclear@7 18
nuclear@7 19 static struct {
nuclear@7 20 const char *name;
nuclear@7 21 WidgetDrawFunc func;
nuclear@7 22 } widget_funcs[] = {
nuclear@7 23 { "label", draw_label },
nuclear@7 24 {0, 0}
nuclear@7 25 };
nuclear@7 26
nuclear@7 27 static std::map<std::string, WidgetDrawFunc> funcmap;
nuclear@7 28
nuclear@8 29 __attribute__ ((used))
nuclear@7 30 extern "C" WidgetDrawFunc get_widget_func(const char *name)
nuclear@7 31 {
nuclear@7 32 static bool initialized;
nuclear@7 33
nuclear@7 34 if(!initialized) {
nuclear@7 35 for(int i=0; widget_funcs[i].func; i++) {
nuclear@7 36 funcmap[widget_funcs[i].name] = widget_funcs[i].func;
nuclear@7 37 }
nuclear@7 38 initialized = true;
nuclear@7 39 }
nuclear@7 40 return funcmap[name];
nuclear@7 41 }
nuclear@7 42
nuclear@7 43 static void begin_drawing(const Widget *w)
nuclear@7 44 {
nuclear@7 45 Vec2 pos = w->get_position();
nuclear@7 46
nuclear@7 47 glEnable(GL_BLEND);
nuclear@7 48 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
nuclear@7 49
nuclear@7 50 gl_matrix_mode(GL_MODELVIEW);
nuclear@7 51 gl_push_matrix();
nuclear@7 52 gl_load_identity();
nuclear@7 53 gl_translatef(pos.x, pos.y, 0);
nuclear@7 54 }
nuclear@7 55
nuclear@7 56 static void end_drawing(const Widget *w)
nuclear@7 57 {
nuclear@7 58 gl_matrix_mode(GL_MODELVIEW);
nuclear@7 59 gl_pop_matrix();
nuclear@7 60 }
nuclear@7 61
nuclear@7 62 static void draw_label(const Widget *w)
nuclear@7 63 {
nuclear@7 64 Vec2 pos = w->get_position();
nuclear@7 65 float vis = w->get_visibility();
nuclear@7 66 if(vis < VIS_THRES) return;
nuclear@7 67
nuclear@7 68 begin_drawing(w);
nuclear@7 69 draw_text(pos.x, pos.y, w->get_text());
nuclear@7 70 end_drawing(w);
nuclear@7 71 }
nuclear@7 72
nuclear@7 73 static void draw_text(float x, float y, const char *text)
nuclear@7 74 {
nuclear@7 75 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0);
nuclear@7 76 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap));
nuclear@7 77
nuclear@7 78 float aspect = (float)view_xsz / (float)view_ysz;
nuclear@7 79 float virt_xsz = 420.0 * aspect;
nuclear@7 80 float virt_ysz = 420.0;
nuclear@7 81
nuclear@7 82 gl_matrix_mode(GL_PROJECTION);
nuclear@7 83 gl_push_matrix();
nuclear@7 84 gl_load_identity();
nuclear@7 85 gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1);
nuclear@7 86
nuclear@7 87 gl_matrix_mode(GL_MODELVIEW);
nuclear@7 88 gl_push_matrix();
nuclear@7 89 gl_load_identity();
nuclear@7 90 gl_translatef(x * virt_xsz, y * virt_ysz, 0);
nuclear@7 91
nuclear@7 92 bind_program(prog_font);
nuclear@7 93 set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0);
nuclear@7 94 gl_apply_xform(prog_ui);
nuclear@7 95
nuclear@7 96 dtx_string(text);
nuclear@7 97
nuclear@7 98 gl_matrix_mode(GL_PROJECTION);
nuclear@7 99 gl_pop_matrix();
nuclear@7 100 gl_matrix_mode(GL_MODELVIEW);
nuclear@7 101 gl_pop_matrix();
nuclear@7 102 }