curvedraw

diff src/app.cc @ 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
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