istereo2
diff src/uitheme.cc @ 13:ea928c313344
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Sep 2015 19:04:50 +0300 |
parents | 57188f7d9304 |
children | 018f997dc646 |
line diff
1.1 --- a/src/uitheme.cc Mon Sep 28 06:53:31 2015 +0300 1.2 +++ b/src/uitheme.cc Mon Sep 28 19:04:50 2015 +0300 1.3 @@ -11,10 +11,13 @@ 1.4 using namespace goatkit; 1.5 1.6 extern int view_xsz, view_ysz; 1.7 -extern unsigned int prog_ui, prog_font; 1.8 +extern float view_aspect; 1.9 +extern unsigned int prog_ui, prog_font, prog_color; 1.10 extern struct dtx_font *font; 1.11 1.12 static void draw_label(const Widget *w); 1.13 +static void draw_button(const Widget *w); 1.14 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a = 1.0f); 1.15 static void draw_text(float x, float y, const char *text); 1.16 1.17 static struct { 1.18 @@ -22,6 +25,7 @@ 1.19 WidgetDrawFunc func; 1.20 } widget_funcs[] = { 1.21 { "label", draw_label }, 1.22 + { "button", draw_button }, 1.23 {0, 0} 1.24 }; 1.25 1.26 @@ -75,13 +79,47 @@ 1.27 end_drawing(w); 1.28 } 1.29 1.30 +static void draw_button(const Widget *w) 1.31 +{ 1.32 + Vec2 pos = w->get_position(); 1.33 + Vec2 sz = w->get_size(); 1.34 + float vis = w->get_visibility(); 1.35 + if(vis < VIS_THRES) return; 1.36 + 1.37 + begin_drawing(w); 1.38 + 1.39 + draw_rect(pos, sz, 1.0, 0.3, 0.2); 1.40 + draw_text(pos.x, pos.y, w->get_text()); 1.41 + 1.42 + end_drawing(w); 1.43 +} 1.44 + 1.45 +static void draw_rect(const Vec2 &pos, const Vec2 &sz, float r, float g, float b, float a) 1.46 +{ 1.47 + float aspect = sz.x / sz.y; 1.48 + 1.49 + bind_program(prog_color); 1.50 + gl_apply_xform(prog_color); 1.51 + 1.52 + gl_begin(GL_QUADS); 1.53 + gl_color4f(r, g, b, a); 1.54 + gl_texcoord2f(0, 1); 1.55 + gl_vertex2f(pos.x, pos.y); 1.56 + gl_texcoord2f(aspect, 1); 1.57 + gl_vertex2f(pos.x + sz.x, pos.y); 1.58 + gl_texcoord2f(aspect, 0); 1.59 + gl_vertex2f(pos.x + sz.x, pos.y + sz.y); 1.60 + gl_texcoord2f(0, 0); 1.61 + gl_vertex2f(pos.x, pos.y + sz.y); 1.62 + gl_end(); 1.63 +} 1.64 + 1.65 static void draw_text(float x, float y, const char *text) 1.66 { 1.67 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); 1.68 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); 1.69 1.70 - float aspect = (float)view_xsz / (float)view_ysz; 1.71 - float virt_xsz = 420.0 * aspect; 1.72 + float virt_xsz = 420.0 * view_aspect; 1.73 float virt_ysz = 420.0; 1.74 1.75 gl_matrix_mode(GL_PROJECTION);