istereo2
diff src/uitheme.cc @ 15:7bd4264bf74a
gui done?
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 30 Sep 2015 04:41:21 +0300 |
parents | 018f997dc646 |
children |
line diff
1.1 --- a/src/uitheme.cc Tue Sep 29 01:11:54 2015 +0300 1.2 +++ b/src/uitheme.cc Wed Sep 30 04:41:21 2015 +0300 1.3 @@ -6,7 +6,7 @@ 1.4 #include "drawtext.h" 1.5 #include "sdr.h" 1.6 1.7 -#define BEVEL 1.0 1.8 +#define BEVEL 1.5 1.9 #define VIS_THRES 0.005 1.10 1.11 using namespace goatkit; 1.12 @@ -28,6 +28,10 @@ 1.13 TEXT_COLOR, 1.14 TOP_COLOR, 1.15 BOTTOM_COLOR, 1.16 + TOP_ON_COLOR, 1.17 + BOTTOM_ON_COLOR, 1.18 + TOP_OFF_COLOR, 1.19 + BOTTOM_OFF_COLOR, 1.20 BEVEL_LIT_COLOR, 1.21 BEVEL_SHAD_COLOR, 1.22 CURSOR_COLOR, 1.23 @@ -39,8 +43,12 @@ 1.24 Color(0.0, 0.0, 0.0, 1.0), /* text color */ 1.25 Color(0.75, 0.75, 0.75, 1.0), /* top color */ 1.26 Color(0.56, 0.56, 0.56, 1.0), /* bot color */ 1.27 + Color(0.4, 0.5, 0.8, 1.0), /* top on color */ 1.28 + Color(0.15, 0.2, 0.4, 1.0), /* bottom on color */ 1.29 + Color(0.8, 0.5, 0.4, 1.0), /* top off color */ 1.30 + Color(0.4, 0.2, 0.15, 1.0), /* bottom off color */ 1.31 Color(0.8, 0.8, 0.8, 1.0), /* lit bevel */ 1.32 - Color(0.35, 0.35, 0.35, 1.0), /* shadowed bevel */ 1.33 + Color(0.35, 0.35, 0.35, 1.0), /* shadowed bevel */ 1.34 Color(0.8, 0.25, 0.18, 1.0), /* cursor color */ 1.35 Color(0.68, 0.85, 1.3, 1.0), /* selection color */ 1.36 Color(0.75, 0.1, 0.095, 1.0) /* check color */ 1.37 @@ -60,10 +68,15 @@ 1.38 1.39 static void draw_label(const Widget *w); 1.40 static void draw_button(const Widget *w); 1.41 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color); 1.42 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot); 1.43 -static void draw_text(float justify, float x, float y, const char *text); 1.44 -static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset); 1.45 +static void draw_checkbox(const Widget *w); 1.46 +static void draw_slider(const Widget *w); 1.47 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &color); 1.48 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot); 1.49 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const Color &col, const char *text, float press = 0.0); 1.50 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const char *text, float press = 0.0); 1.51 +static void draw_text(const Widget *w, float justify, float x, float y, const char *text); 1.52 +static void draw_frame(const Widget *w, const Vec2 &pos, const Vec2 &sz, float inset); 1.53 +static float lerp(float a, float b, float t); 1.54 static Color lerp(const Color &a, const Color &b, float t); 1.55 1.56 static struct { 1.57 @@ -72,6 +85,8 @@ 1.58 } widget_funcs[] = { 1.59 { "label", draw_label }, 1.60 { "button", draw_button }, 1.61 + { "checkbox", draw_checkbox }, 1.62 + { "slider", draw_slider }, 1.63 {0, 0} 1.64 }; 1.65 1.66 @@ -117,54 +132,126 @@ 1.67 static void draw_label(const Widget *w) 1.68 { 1.69 Vec2 pos = w->get_position(); 1.70 + Vec2 sz = w->get_size(); 1.71 float vis = w->get_visibility(); 1.72 if(vis < VIS_THRES) return; 1.73 1.74 begin_drawing(w); 1.75 - draw_text(JLEFT, pos.x, pos.y, w->get_text()); 1.76 + draw_shadow_text(w, JLEFT, pos.x, pos.y + sz.y / 2.0, w->get_text()); 1.77 end_drawing(w); 1.78 } 1.79 1.80 static void draw_button(const Widget *w) 1.81 { 1.82 + float vis = w->get_visibility(); 1.83 + if(vis < VIS_THRES) return; 1.84 + 1.85 Vec2 pos = w->get_position(); 1.86 Vec2 sz = w->get_size(); 1.87 - float vis = w->get_visibility(); 1.88 float press = w->get_pressed(); 1.89 - if(vis < VIS_THRES) return; 1.90 1.91 Color tcol = lerp(colors[TOP_COLOR], colors[BOTTOM_COLOR], press); 1.92 Color bcol = lerp(colors[BOTTOM_COLOR], colors[TOP_COLOR], press); 1.93 1.94 begin_drawing(w); 1.95 1.96 - draw_frame(pos, sz, press); 1.97 - draw_rect(pos, sz, tcol, bcol); 1.98 - //draw_rect(Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y), 1.99 + draw_frame(w, pos, sz, press); 1.100 + draw_rect(w, pos, sz, tcol, bcol); 1.101 + //draw_rect(w, Vec2(pos.x + sz.x / 2.0 - 2.0, pos.y), Vec2(4.0, sz.y), 1.102 // Color(0.4, 0.5, 1.0)); 1.103 - draw_text(JCENTER, pos.x + sz.x / 2.0, pos.y, w->get_text()); 1.104 + draw_shadow_text(w, JCENTER, pos.x + sz.x / 2.0, pos.y + sz.y / 2.0, w->get_text(), press); 1.105 1.106 end_drawing(w); 1.107 } 1.108 1.109 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &color) 1.110 +static void draw_checkbox(const Widget *w) 1.111 { 1.112 - draw_rect(pos, sz, color, color); 1.113 + float vis = w->get_visibility(); 1.114 + if(vis < VIS_THRES) return; 1.115 + 1.116 + Vec2 pos = w->get_position(); 1.117 + Vec2 sz = w->get_size(); 1.118 + Vec2 boxsz = Vec2(sz.y * 3.0, sz.y); 1.119 + Vec2 boxpos = Vec2(pos.x + sz.x - boxsz.x, pos.y); 1.120 + 1.121 + float checked = ((CheckBox*)w)->get_checked(); 1.122 + 1.123 + float vcenter = boxpos.y + boxsz.y / 2.0; 1.124 + 1.125 + begin_drawing(w); 1.126 + 1.127 + draw_frame(w, boxpos, boxsz, 1.0); 1.128 + Color tcol = lerp(colors[TOP_OFF_COLOR], colors[TOP_ON_COLOR], checked); 1.129 + Color bcol = lerp(colors[BOTTOM_OFF_COLOR], colors[BOTTOM_ON_COLOR], checked); 1.130 + draw_rect(w, boxpos, boxsz, bcol, tcol); 1.131 + 1.132 + draw_shadow_text(w, JLEFT, boxpos.x + 2, vcenter, "ON", 0.0); 1.133 + draw_shadow_text(w, JRIGHT, boxpos.x + boxsz.x - 3, vcenter, "OFF", 0.0); 1.134 + 1.135 + Vec2 knobpos = Vec2(0, boxpos.y + 1.0); 1.136 + Vec2 knobsz = Vec2(boxsz.x / 2.0, boxsz.y - 2.0); 1.137 + 1.138 + knobpos.x = lerp(boxpos.x + 1.0, boxpos.x + boxsz.x / 2.0, checked); 1.139 + 1.140 + draw_frame(w, knobpos, knobsz, 0.0); 1.141 + draw_rect(w, knobpos, knobsz, colors[TOP_COLOR], colors[BOTTOM_COLOR]); 1.142 + 1.143 + draw_shadow_text(w, JRIGHT, boxpos.x - 2.0, vcenter, w->get_text(), 0.0); 1.144 + 1.145 + end_drawing(w); 1.146 } 1.147 1.148 -static void draw_rect(const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) 1.149 +static void draw_slider(const Widget *w) 1.150 { 1.151 + float vis = w->get_visibility(); 1.152 + if(vis < VIS_THRES) return; 1.153 + 1.154 + float nval = ((Slider*)w)->get_value_norm(); 1.155 + 1.156 + Vec2 pos = w->get_position(); 1.157 + Vec2 sz = w->get_size(); 1.158 + Vec2 tsz = Vec2(sz.y * 0.5, sz.y); 1.159 + Vec2 tpos = Vec2(pos.x + sz.x * nval - tsz.x / 2.0, pos.y); 1.160 + 1.161 + // modify original pos/size to correspond to the trough geometry 1.162 + sz.y /= 5.0; 1.163 + pos.y += sz.y * 2.0; 1.164 + 1.165 + begin_drawing(w); 1.166 + 1.167 + // draw trough 1.168 + draw_frame(w, pos, sz, 1.0); 1.169 + draw_rect(w, pos, sz, colors[BOTTOM_COLOR], colors[TOP_COLOR]); 1.170 + 1.171 + // draw thumb 1.172 + draw_frame(w, tpos, tsz, 0.0); 1.173 + draw_rect(w, tpos, tsz, colors[TOP_COLOR], colors[BOTTOM_COLOR]); 1.174 + 1.175 + end_drawing(w); 1.176 +} 1.177 + 1.178 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &color) 1.179 +{ 1.180 + draw_rect(w, pos, sz, color, color); 1.181 +} 1.182 + 1.183 +static void draw_rect(const Widget *w, const Vec2 &pos, const Vec2 &sz, const Color &ctop, const Color &cbot) 1.184 +{ 1.185 + float vis = w ? w->get_visibility() : 1.0; 1.186 + float act = w ? w->get_active() : 1.0; 1.187 float aspect = sz.x / sz.y; 1.188 1.189 + float alpha = vis * (act * 0.5 + 0.5); 1.190 + 1.191 bind_program(prog_color); 1.192 1.193 gl_begin(GL_QUADS); 1.194 - gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a); 1.195 + gl_color4f(cbot.r, cbot.g, cbot.b, cbot.a * alpha); 1.196 gl_texcoord2f(0, 1); 1.197 gl_vertex3f(pos.x, pos.y, 0); 1.198 gl_texcoord2f(aspect, 1); 1.199 gl_vertex3f(pos.x + sz.x, pos.y, 0); 1.200 - gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a); 1.201 + gl_color4f(ctop.r, ctop.g, ctop.b, ctop.a * alpha); 1.202 gl_texcoord2f(aspect, 0); 1.203 gl_vertex3f(pos.x + sz.x, pos.y + sz.y, 0); 1.204 gl_texcoord2f(0, 0); 1.205 @@ -172,21 +259,47 @@ 1.206 gl_end(); 1.207 } 1.208 1.209 -static void draw_text(float justify, float x, float y, const char *text) 1.210 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const Color &col, const char *text, float press) 1.211 +{ 1.212 + static const Color cshad = Color(0.1, 0.1, 0.1, 1.0); 1.213 + 1.214 + float xoffs = 1.0 - press; 1.215 + float yoffs = 1.0 - press; 1.216 + 1.217 + Color orig = colors[TEXT_COLOR]; 1.218 + colors[TEXT_COLOR] = cshad; 1.219 + colors[TEXT_COLOR].a = (1.0 - press); 1.220 + draw_text(w, justify, x + xoffs, y - yoffs, text); 1.221 + colors[TEXT_COLOR] = col; 1.222 + draw_text(w, justify, x, y, text); 1.223 + colors[TEXT_COLOR] = orig; 1.224 +} 1.225 + 1.226 +static void draw_shadow_text(const Widget *w, float justify, float x, float y, const char *text, float press) 1.227 +{ 1.228 + draw_shadow_text(w, justify, x, y, Color(1.0, 1.0, 1.0, 1.0), text, press); 1.229 +} 1.230 + 1.231 +static void draw_text(const Widget *w, float justify, float x, float y, const char *text) 1.232 { 1.233 struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0); 1.234 dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap)); 1.235 1.236 + float vis = w ? w->get_visibility() : 1.0; 1.237 + float act = w ? w->get_active() : 1.0; 1.238 + 1.239 float twidth = dtx_string_width(text); 1.240 float thalf = twidth / 2.0; 1.241 + float theight = dtx_line_height(); 1.242 1.243 gl_matrix_mode(GL_MODELVIEW); 1.244 gl_push_matrix(); 1.245 gl_load_identity(); 1.246 - gl_translatef(x - thalf - justify * thalf, y + 8, 0); 1.247 + gl_translatef(x - thalf - justify * thalf, y - theight * 0.25, 0); 1.248 1.249 bind_program(prog_font); 1.250 - set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0); 1.251 + const Color &tcol = colors[TEXT_COLOR]; 1.252 + set_uniform_float4(prog_font, "ucolor", tcol.r, tcol.g, tcol.b, tcol.a * vis * (act * 0.5 + 0.5)); 1.253 gl_apply_xform(prog_font); 1.254 1.255 dtx_string(text); 1.256 @@ -195,8 +308,14 @@ 1.257 gl_pop_matrix(); 1.258 } 1.259 1.260 -static void draw_frame(const Vec2 &pos, const Vec2 &sz, float inset) 1.261 +static void draw_frame(const Widget *widget, const Vec2 &pos, const Vec2 &sz, float inset) 1.262 { 1.263 + float vis = widget ? widget->get_visibility() : 1.0; 1.264 + float act = widget ? widget->get_active() : 1.0; 1.265 + float offs = 300.0 * (1.0 - vis); 1.266 + 1.267 + float alpha = vis * (act * 0.5 + 0.5); 1.268 + 1.269 float x = pos.x - BEVEL; 1.270 float y = pos.y - BEVEL; 1.271 float w = sz.x + BEVEL * 2.0; 1.272 @@ -209,30 +328,35 @@ 1.273 bind_program(prog_color); 1.274 1.275 gl_begin(GL_QUADS); 1.276 - gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a); 1.277 - gl_vertex2f(x + b, y + h - b); 1.278 - gl_vertex2f(x + w - b, y + h - b); 1.279 - gl_vertex2f(x + w, y + h); 1.280 - gl_vertex2f(x, y + h); 1.281 + gl_color4f(tcol.r, tcol.g, tcol.b, tcol.a * alpha); 1.282 + gl_vertex2f(x + b + offs, y + h - b); 1.283 + gl_vertex2f(x + w - b + offs, y + h - b); 1.284 + gl_vertex2f(x + w + offs, y + h); 1.285 + gl_vertex2f(x + offs, y + h); 1.286 1.287 - gl_vertex2f(x + b, y + b); 1.288 - gl_vertex2f(x, y); 1.289 - gl_vertex2f(x, y + h); 1.290 - gl_vertex2f(x + b, y + h - b); 1.291 + gl_vertex2f(x + b, y + b + offs); 1.292 + gl_vertex2f(x, y + offs); 1.293 + gl_vertex2f(x, y + h + offs); 1.294 + gl_vertex2f(x + b, y + h - b + offs); 1.295 1.296 - gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a); 1.297 - gl_vertex2f(x, y); 1.298 - gl_vertex2f(x + b, y + b); 1.299 - gl_vertex2f(x + w - b, y + b); 1.300 - gl_vertex2f(x + w, y); 1.301 + gl_color4f(bcol.r, bcol.g, bcol.b, bcol.a * alpha); 1.302 + gl_vertex2f(x - offs, y); 1.303 + gl_vertex2f(x + b - offs, y + b); 1.304 + gl_vertex2f(x + w - b - offs, y + b); 1.305 + gl_vertex2f(x + w - offs, y); 1.306 1.307 - gl_vertex2f(x + w - b, y + b); 1.308 - gl_vertex2f(x + w, y); 1.309 - gl_vertex2f(x + w, y + h); 1.310 - gl_vertex2f(x + w - b, y + h - b); 1.311 + gl_vertex2f(x + w - b, y + b - offs); 1.312 + gl_vertex2f(x + w, y - offs); 1.313 + gl_vertex2f(x + w, y + h - offs); 1.314 + gl_vertex2f(x + w - b, y + h - b - offs); 1.315 gl_end(); 1.316 } 1.317 1.318 +static float lerp(float a, float b, float t) 1.319 +{ 1.320 + return a + (b - a) * t; 1.321 +} 1.322 + 1.323 static Color lerp(const Color &a, const Color &b, float t) 1.324 { 1.325 Color res;