erebus

changeset 38:5e27c85e79ca

cursor handling in the console
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 09 Jun 2014 18:40:30 +0300
parents db8a90307386
children fd45cf0fc912
files liberebus/src/erebus.cc liberebus/src/rt.cc src/console.cc test/scene
diffstat 4 files changed, 29 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/liberebus/src/erebus.cc	Mon Jun 09 16:01:00 2014 +0300
     1.2 +++ b/liberebus/src/erebus.cc	Mon Jun 09 18:40:30 2014 +0300
     1.3 @@ -43,7 +43,7 @@
     1.4  	ctx->tpool = 0;
     1.5  
     1.6  	erb_setoptf(ctx, ERB_OPT_GAMMA, 2.2);
     1.7 -	erb_setopti(ctx, ERB_OPT_MAX_ITER, 6);
     1.8 +	erb_setopti(ctx, ERB_OPT_MAX_ITER, 8);
     1.9  	erb_setopti(ctx, ERB_OPT_MAX_SAMPLES, INF_SAMPLES);
    1.10  	erb_setopti(ctx, ERB_OPT_NUM_THREADS, -1);
    1.11  
     2.1 --- a/liberebus/src/rt.cc	Mon Jun 09 16:01:00 2014 +0300
     2.2 +++ b/liberebus/src/rt.cc	Mon Jun 09 18:40:30 2014 +0300
     2.3 @@ -2,8 +2,6 @@
     2.4  #include "rt.h"
     2.5  #include "erebus_impl.h"
     2.6  
     2.7 -#define MAX_ITER	6
     2.8 -
     2.9  Color ray_trace(struct erebus *ctx, const Ray &ray, int iter)
    2.10  {
    2.11  	const Scene *scn = ctx->scn;
     3.1 --- a/src/console.cc	Mon Jun 09 16:01:00 2014 +0300
     3.2 +++ b/src/console.cc	Mon Jun 09 18:40:30 2014 +0300
     3.3 @@ -135,7 +135,7 @@
     3.4  					--cursor;
     3.5  					must_redraw = true;
     3.6  				} else if(cursor > 0) {
     3.7 -					input.erase(cursor - 1);
     3.8 +					input.erase(cursor - 1, 1);
     3.9  					--cursor;
    3.10  					must_redraw = true;
    3.11  				}
    3.12 @@ -173,7 +173,11 @@
    3.13  
    3.14  		default:
    3.15  			if(c < 256 && isprint(c)) {
    3.16 -				input.push_back(c);
    3.17 +				if(cursor == (int)input.size()) {
    3.18 +					input.push_back(c);
    3.19 +				} else {
    3.20 +					input.insert(cursor, 1, c);
    3.21 +				}
    3.22  				++cursor;
    3.23  				must_redraw = true;
    3.24  			}
    3.25 @@ -215,7 +219,8 @@
    3.26  	}
    3.27  
    3.28  	// draw the output box
    3.29 -	float outbox_height = nlines * dtx_line_height();
    3.30 +	float line_height = dtx_line_height();
    3.31 +	float outbox_height = nlines * line_height;
    3.32  
    3.33  	glPushAttrib(GL_ENABLE_BIT);
    3.34  	glEnable(GL_BLEND);
    3.35 @@ -229,22 +234,34 @@
    3.36  	glVertex2f(0, 0);
    3.37  
    3.38  	glColor4f(0.5, 0.2, 0.1, 0.7);
    3.39 -	glVertex2f(0, -(outbox_height + dtx_line_height()));
    3.40 -	glVertex2f(max_width, -(outbox_height + dtx_line_height()));
    3.41 +	glVertex2f(0, -(outbox_height + line_height));
    3.42 +	glVertex2f(max_width, -(outbox_height + line_height));
    3.43  	glVertex2f(max_width, -outbox_height);
    3.44  	glVertex2f(0, -outbox_height);
    3.45  	glEnd();
    3.46  
    3.47  	// draw the output text
    3.48  	glPushMatrix();
    3.49 -	glTranslatef(0, -dtx_line_height(), 0);
    3.50 +	glTranslatef(0, -line_height, 0);
    3.51  	glColor4f(1, 1, 1, 0.7);
    3.52  	dtx_string(buflines.c_str());
    3.53  	glPopMatrix();
    3.54  
    3.55  	// draw the input line
    3.56 -	glTranslatef(0, -outbox_height - dtx_line_height(), 0);
    3.57 -	dtx_string((std::string("> ") + input).c_str());
    3.58 +	glTranslatef(0, -outbox_height - line_height, 0);
    3.59 +
    3.60 +	std::string inpline = std::string("> ") + input;
    3.61 +	dtx_string(inpline.c_str());
    3.62 +	glDisable(GL_TEXTURE_2D);
    3.63 +
    3.64 +	float cursor_x = dtx_char_pos(inpline.c_str(), cursor + 2);
    3.65 +	glBegin(GL_QUADS);
    3.66 +	glColor4f(1, 1, 1, 0.7);
    3.67 +	glVertex2f(cursor_x, 2);
    3.68 +	glVertex2f(cursor_x + 2, 2);
    3.69 +	glVertex2f(cursor_x + 2, line_height - 2);
    3.70 +	glVertex2f(cursor_x, line_height - 2);
    3.71 +	glEnd();
    3.72  
    3.73  	glPopAttrib();
    3.74  
     4.1 --- a/test/scene	Mon Jun 09 16:01:00 2014 +0300
     4.2 +++ b/test/scene	Mon Jun 09 18:40:30 2014 +0300
     4.3 @@ -1,14 +1,14 @@
     4.4  # test scene
     4.5  
     4.6  sphere -position 0 0 0 -scaling 1 1 1 -diffuse 1 0.6 0.5 -brdf composite \
     4.7 -	-brdf lambert -brdf-weight 0.5 \
     4.8 -	-brdf phong -brdf-weight 0.5
     4.9 +	-brdf lambert -brdf-weight 0.7 \
    4.10 +	-brdf phong -brdf-weight 0.3
    4.11  
    4.12  box -position 0 -1.25 0 -scaling 4 0.5 4 -diffuse 0.3 0.4 1.0 -brdf composite \
    4.13  	-brdf lambert -brdf-weight 0.3 \
    4.14  	-brdf mirror -brdf-weight 0.7
    4.15  box -position 0 3.75 0 -scaling 20 10 20 -diffuse 1.0 1.0 1.0 -brdf lambert
    4.16  
    4.17 -box -position 0 4 0 -scaling 3 0.1 3 -emissive 6 6 6
    4.18 +box -position 0 4 0 -scaling 3 0.1 3 -emissive 8 8 8
    4.19  
    4.20  camera -position 0 3 -6 -target 0 0 0