curvedraw
changeset 1:7dcd0f6113e5
some ui and feedback stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 16 Dec 2015 04:49:16 +0200 |
parents | 8e524989c904 |
children | ce7aa9a0594c |
files | src/app.cc src/app.h src/widgets.cc |
diffstat | 3 files changed, 63 insertions(+), 24 deletions(-) [+] |
line diff
1.1 --- a/src/app.cc Tue Dec 15 07:15:53 2015 +0200 1.2 +++ b/src/app.cc Wed Dec 16 04:49:16 2015 +0200 1.3 @@ -7,13 +7,13 @@ 1.4 #include "curve.h" 1.5 #include "widgets.h" 1.6 1.7 +int win_width, win_height; 1.8 +float win_aspect; 1.9 + 1.10 static void draw_grid(float sz, float sep, float alpha = 1.0f); 1.11 static void draw_curve(const Curve *curve); 1.12 static void on_click(int bn, float u, float v); 1.13 1.14 -static int win_width, win_height; 1.15 -static float win_aspect; 1.16 - 1.17 static float view_pan_x, view_pan_y; 1.18 static float view_scale = 1.0f; 1.19 1.20 @@ -41,7 +41,7 @@ 1.21 1.22 void app_draw() 1.23 { 1.24 - glClearColor(0.16, 0.16, 0.16, 1); 1.25 + glClearColor(0.1, 0.1, 0.1, 1); 1.26 glClear(GL_COLOR_BUFFER_BIT); 1.27 1.28 glMatrixMode(GL_MODELVIEW); 1.29 @@ -75,7 +75,7 @@ 1.30 glColor4f(0.2, 0.3, 0.6, alpha); 1.31 glVertex2f(0, -sz); 1.32 glVertex2f(0, sz); 1.33 - glColor4f(0.4, 0.4, 0.4, alpha); 1.34 + glColor4f(0.35, 0.35, 0.35, alpha); 1.35 while(x < sz) { 1.36 x += sep; 1.37 glVertex2f(-sz, x); 1.38 @@ -95,14 +95,15 @@ 1.39 int numpt = curve->get_point_count(); 1.40 int segm = numpt * 16.0f; 1.41 1.42 + glLineWidth(2.0); 1.43 + if(curve == sel_curve) { 1.44 + glColor3f(0.3, 0.4, 1.0); 1.45 + } else if(curve == new_curve) { 1.46 + glColor3f(1.0, 0.75, 0.3); 1.47 + } else { 1.48 + glColor3f(0.75, 0.75, 0.75); 1.49 + } 1.50 glBegin(GL_LINE_STRIP); 1.51 - if(curve == sel_curve) { 1.52 - glLineWidth(3.0); 1.53 - glColor3f(0.2, 0.8, 0.3); 1.54 - } else { 1.55 - glLineWidth(2.0); 1.56 - glColor3f(0.8, 0.75, 0.3); 1.57 - } 1.58 for(int i=0; i<segm; i++) { 1.59 float t = (float)i / (float)(segm - 1); 1.60 Vector2 v = curve->interpolate(t); 1.61 @@ -111,10 +112,21 @@ 1.62 glEnd(); 1.63 glLineWidth(1.0); 1.64 1.65 - glPointSize(5.0); 1.66 + glPointSize(7.0); 1.67 glBegin(GL_POINTS); 1.68 - glColor3f(1.0, 0.5, 0.2); 1.69 + if(curve == new_curve) { 1.70 + glColor3f(1.0, 0.0, 0.0); 1.71 + } else { 1.72 + glColor3f(0.6, 0.3, 0.2); 1.73 + } 1.74 for(int i=0; i<numpt; i++) { 1.75 + if(curve == sel_curve) { 1.76 + if(i == sel_pidx) { 1.77 + glColor3f(1.0, 0.2, 0.1); 1.78 + } else { 1.79 + glColor3f(0.2, 1.0, 0.2); 1.80 + } 1.81 + } 1.82 Vector2 pt = curve->get_point(i); 1.83 glVertex2f(pt.x, pt.y); 1.84 } 1.85 @@ -138,8 +150,17 @@ 1.86 { 1.87 if(pressed) { 1.88 switch(key) { 1.89 + case 'q': 1.90 + case 'Q': 1.91 + exit(0); 1.92 + 1.93 case 27: 1.94 - exit(0); 1.95 + if(new_curve) { 1.96 + delete new_curve; 1.97 + new_curve = 0; 1.98 + post_redisplay(); 1.99 + } 1.100 + break; 1.101 1.102 case 'l': 1.103 case 'L': 1.104 @@ -147,6 +168,10 @@ 1.105 sel_curve->set_type(CURVE_LINEAR); 1.106 post_redisplay(); 1.107 } 1.108 + if(new_curve) { 1.109 + new_curve->set_type(CURVE_LINEAR); 1.110 + post_redisplay(); 1.111 + } 1.112 break; 1.113 1.114 case 'b': 1.115 @@ -155,6 +180,10 @@ 1.116 sel_curve->set_type(CURVE_BSPLINE); 1.117 post_redisplay(); 1.118 } 1.119 + if(new_curve) { 1.120 + new_curve->set_type(CURVE_BSPLINE); 1.121 + post_redisplay(); 1.122 + } 1.123 break; 1.124 1.125 case 'h': 1.126 @@ -163,6 +192,10 @@ 1.127 sel_curve->set_type(CURVE_HERMITE); 1.128 post_redisplay(); 1.129 } 1.130 + if(new_curve) { 1.131 + new_curve->set_type(CURVE_HERMITE); 1.132 + post_redisplay(); 1.133 + } 1.134 break; 1.135 } 1.136 } 1.137 @@ -213,7 +246,7 @@ 1.138 1.139 static void hover(int x, int y) 1.140 { 1.141 - float thres = pixel_to_uv(5, 0).x - pixel_to_uv(0, 0).x; 1.142 + float thres = 0.02; 1.143 1.144 Vector2 uv = pixel_to_uv(x, y); 1.145 for(size_t i=0; i<curves.size(); i++) { 1.146 @@ -255,7 +288,7 @@ 1.147 1.148 if(bnstate & BNBIT(2)) { 1.149 float w = sel_curve->get_weight(sel_pidx); 1.150 - w -= dy * 0.1; 1.151 + w -= dy * 0.01; 1.152 if(w < FLT_MIN) w = FLT_MIN; 1.153 sel_curve->set_weight(sel_pidx, w); 1.154
2.1 --- a/src/app.h Tue Dec 15 07:15:53 2015 +0200 2.2 +++ b/src/app.h Wed Dec 16 04:49:16 2015 +0200 2.3 @@ -1,6 +1,9 @@ 2.4 #ifndef APP_H_ 2.5 #define APP_H_ 2.6 2.7 +extern int win_width, win_height; 2.8 +extern float win_aspect; 2.9 + 2.10 bool app_init(int argc, char **argv); 2.11 void app_cleanup(); 2.12
3.1 --- a/src/widgets.cc Tue Dec 15 07:15:53 2015 +0200 3.2 +++ b/src/widgets.cc Wed Dec 16 04:49:16 2015 +0200 3.3 @@ -12,11 +12,10 @@ 3.4 { 3.5 if(font) return; 3.6 3.7 - if(!(font = dtx_open_font("data/droid_sans.ttf", 16))) { 3.8 + if(!(font = dtx_open_font("data/droid_sans.ttf", 24))) { 3.9 fprintf(stderr, "failed to load font\n"); 3.10 abort(); 3.11 } 3.12 - dtx_use_font(font, 16); 3.13 } 3.14 3.15 Widget::Widget() 3.16 @@ -41,18 +40,21 @@ 3.17 3.18 void Widget::set_text(const char *str) 3.19 { 3.20 - text = new char[strlen(str) + 1]; 3.21 - strcpy(text, str); 3.22 + char *newtext = new char[strlen(str) + 1]; 3.23 + strcpy(newtext, str); 3.24 + 3.25 + delete [] text; 3.26 + text = newtext; 3.27 } 3.28 3.29 void Widget::set_textf(const char *str, ...) 3.30 { 3.31 va_list ap; 3.32 int sz = strlen(str) * 4; 3.33 - char *buf = (char*)alloca(sz); 3.34 + char *buf = (char*)alloca(sz + 1); 3.35 3.36 va_start(ap, str); 3.37 - vsnprintf(buf, sz - 1, text, ap); 3.38 + vsnprintf(buf, sz, str, ap); 3.39 va_end(ap); 3.40 3.41 set_text(buf); 3.42 @@ -72,8 +74,9 @@ 3.43 glMatrixMode(GL_MODELVIEW); 3.44 glPushMatrix(); 3.45 glTranslatef(pos.x, pos.y, 0); 3.46 - glScalef(0.1, 0.1, 1); 3.47 + glScalef(0.003, 0.003, 1); 3.48 3.49 + glColor4f(1, 1, 1, 1); 3.50 dtx_string(text); 3.51 dtx_flush(); 3.52