# HG changeset patch # User John Tsiombikas # Date 1450234156 -7200 # Node ID 7dcd0f6113e5411de8a9535e74d6940811e7b4a3 # Parent 8e524989c904488362f606d3e01a12e46a7842ef some ui and feedback stuff diff -r 8e524989c904 -r 7dcd0f6113e5 src/app.cc --- a/src/app.cc Tue Dec 15 07:15:53 2015 +0200 +++ b/src/app.cc Wed Dec 16 04:49:16 2015 +0200 @@ -7,13 +7,13 @@ #include "curve.h" #include "widgets.h" +int win_width, win_height; +float win_aspect; + static void draw_grid(float sz, float sep, float alpha = 1.0f); static void draw_curve(const Curve *curve); static void on_click(int bn, float u, float v); -static int win_width, win_height; -static float win_aspect; - static float view_pan_x, view_pan_y; static float view_scale = 1.0f; @@ -41,7 +41,7 @@ void app_draw() { - glClearColor(0.16, 0.16, 0.16, 1); + glClearColor(0.1, 0.1, 0.1, 1); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); @@ -75,7 +75,7 @@ glColor4f(0.2, 0.3, 0.6, alpha); glVertex2f(0, -sz); glVertex2f(0, sz); - glColor4f(0.4, 0.4, 0.4, alpha); + glColor4f(0.35, 0.35, 0.35, alpha); while(x < sz) { x += sep; glVertex2f(-sz, x); @@ -95,14 +95,15 @@ int numpt = curve->get_point_count(); int segm = numpt * 16.0f; + glLineWidth(2.0); + if(curve == sel_curve) { + glColor3f(0.3, 0.4, 1.0); + } else if(curve == new_curve) { + glColor3f(1.0, 0.75, 0.3); + } else { + glColor3f(0.75, 0.75, 0.75); + } glBegin(GL_LINE_STRIP); - if(curve == sel_curve) { - glLineWidth(3.0); - glColor3f(0.2, 0.8, 0.3); - } else { - glLineWidth(2.0); - glColor3f(0.8, 0.75, 0.3); - } for(int i=0; iinterpolate(t); @@ -111,10 +112,21 @@ glEnd(); glLineWidth(1.0); - glPointSize(5.0); + glPointSize(7.0); glBegin(GL_POINTS); - glColor3f(1.0, 0.5, 0.2); + if(curve == new_curve) { + glColor3f(1.0, 0.0, 0.0); + } else { + glColor3f(0.6, 0.3, 0.2); + } for(int i=0; iget_point(i); glVertex2f(pt.x, pt.y); } @@ -138,8 +150,17 @@ { if(pressed) { switch(key) { + case 'q': + case 'Q': + exit(0); + case 27: - exit(0); + if(new_curve) { + delete new_curve; + new_curve = 0; + post_redisplay(); + } + break; case 'l': case 'L': @@ -147,6 +168,10 @@ sel_curve->set_type(CURVE_LINEAR); post_redisplay(); } + if(new_curve) { + new_curve->set_type(CURVE_LINEAR); + post_redisplay(); + } break; case 'b': @@ -155,6 +180,10 @@ sel_curve->set_type(CURVE_BSPLINE); post_redisplay(); } + if(new_curve) { + new_curve->set_type(CURVE_BSPLINE); + post_redisplay(); + } break; case 'h': @@ -163,6 +192,10 @@ sel_curve->set_type(CURVE_HERMITE); post_redisplay(); } + if(new_curve) { + new_curve->set_type(CURVE_HERMITE); + post_redisplay(); + } break; } } @@ -213,7 +246,7 @@ static void hover(int x, int y) { - float thres = pixel_to_uv(5, 0).x - pixel_to_uv(0, 0).x; + float thres = 0.02; Vector2 uv = pixel_to_uv(x, y); for(size_t i=0; iget_weight(sel_pidx); - w -= dy * 0.1; + w -= dy * 0.01; if(w < FLT_MIN) w = FLT_MIN; sel_curve->set_weight(sel_pidx, w); diff -r 8e524989c904 -r 7dcd0f6113e5 src/app.h --- a/src/app.h Tue Dec 15 07:15:53 2015 +0200 +++ b/src/app.h Wed Dec 16 04:49:16 2015 +0200 @@ -1,6 +1,9 @@ #ifndef APP_H_ #define APP_H_ +extern int win_width, win_height; +extern float win_aspect; + bool app_init(int argc, char **argv); void app_cleanup(); diff -r 8e524989c904 -r 7dcd0f6113e5 src/widgets.cc --- a/src/widgets.cc Tue Dec 15 07:15:53 2015 +0200 +++ b/src/widgets.cc Wed Dec 16 04:49:16 2015 +0200 @@ -12,11 +12,10 @@ { if(font) return; - if(!(font = dtx_open_font("data/droid_sans.ttf", 16))) { + if(!(font = dtx_open_font("data/droid_sans.ttf", 24))) { fprintf(stderr, "failed to load font\n"); abort(); } - dtx_use_font(font, 16); } Widget::Widget() @@ -41,18 +40,21 @@ void Widget::set_text(const char *str) { - text = new char[strlen(str) + 1]; - strcpy(text, str); + char *newtext = new char[strlen(str) + 1]; + strcpy(newtext, str); + + delete [] text; + text = newtext; } void Widget::set_textf(const char *str, ...) { va_list ap; int sz = strlen(str) * 4; - char *buf = (char*)alloca(sz); + char *buf = (char*)alloca(sz + 1); va_start(ap, str); - vsnprintf(buf, sz - 1, text, ap); + vsnprintf(buf, sz, str, ap); va_end(ap); set_text(buf); @@ -72,8 +74,9 @@ glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(pos.x, pos.y, 0); - glScalef(0.1, 0.1, 1); + glScalef(0.003, 0.003, 1); + glColor4f(1, 1, 1, 1); dtx_string(text); dtx_flush();