# HG changeset patch # User John Tsiombikas # Date 1402328430 -10800 # Node ID 5e27c85e79cab2880504d1dc9e0c0c4526ef4e5c # Parent db8a9030738644d9c790d66cbc168781bccc397d cursor handling in the console diff -r db8a90307386 -r 5e27c85e79ca liberebus/src/erebus.cc --- a/liberebus/src/erebus.cc Mon Jun 09 16:01:00 2014 +0300 +++ b/liberebus/src/erebus.cc Mon Jun 09 18:40:30 2014 +0300 @@ -43,7 +43,7 @@ ctx->tpool = 0; erb_setoptf(ctx, ERB_OPT_GAMMA, 2.2); - erb_setopti(ctx, ERB_OPT_MAX_ITER, 6); + erb_setopti(ctx, ERB_OPT_MAX_ITER, 8); erb_setopti(ctx, ERB_OPT_MAX_SAMPLES, INF_SAMPLES); erb_setopti(ctx, ERB_OPT_NUM_THREADS, -1); diff -r db8a90307386 -r 5e27c85e79ca liberebus/src/rt.cc --- a/liberebus/src/rt.cc Mon Jun 09 16:01:00 2014 +0300 +++ b/liberebus/src/rt.cc Mon Jun 09 18:40:30 2014 +0300 @@ -2,8 +2,6 @@ #include "rt.h" #include "erebus_impl.h" -#define MAX_ITER 6 - Color ray_trace(struct erebus *ctx, const Ray &ray, int iter) { const Scene *scn = ctx->scn; diff -r db8a90307386 -r 5e27c85e79ca src/console.cc --- a/src/console.cc Mon Jun 09 16:01:00 2014 +0300 +++ b/src/console.cc Mon Jun 09 18:40:30 2014 +0300 @@ -135,7 +135,7 @@ --cursor; must_redraw = true; } else if(cursor > 0) { - input.erase(cursor - 1); + input.erase(cursor - 1, 1); --cursor; must_redraw = true; } @@ -173,7 +173,11 @@ default: if(c < 256 && isprint(c)) { - input.push_back(c); + if(cursor == (int)input.size()) { + input.push_back(c); + } else { + input.insert(cursor, 1, c); + } ++cursor; must_redraw = true; } @@ -215,7 +219,8 @@ } // draw the output box - float outbox_height = nlines * dtx_line_height(); + float line_height = dtx_line_height(); + float outbox_height = nlines * line_height; glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); @@ -229,22 +234,34 @@ glVertex2f(0, 0); glColor4f(0.5, 0.2, 0.1, 0.7); - glVertex2f(0, -(outbox_height + dtx_line_height())); - glVertex2f(max_width, -(outbox_height + dtx_line_height())); + glVertex2f(0, -(outbox_height + line_height)); + glVertex2f(max_width, -(outbox_height + line_height)); glVertex2f(max_width, -outbox_height); glVertex2f(0, -outbox_height); glEnd(); // draw the output text glPushMatrix(); - glTranslatef(0, -dtx_line_height(), 0); + glTranslatef(0, -line_height, 0); glColor4f(1, 1, 1, 0.7); dtx_string(buflines.c_str()); glPopMatrix(); // draw the input line - glTranslatef(0, -outbox_height - dtx_line_height(), 0); - dtx_string((std::string("> ") + input).c_str()); + glTranslatef(0, -outbox_height - line_height, 0); + + std::string inpline = std::string("> ") + input; + dtx_string(inpline.c_str()); + glDisable(GL_TEXTURE_2D); + + float cursor_x = dtx_char_pos(inpline.c_str(), cursor + 2); + glBegin(GL_QUADS); + glColor4f(1, 1, 1, 0.7); + glVertex2f(cursor_x, 2); + glVertex2f(cursor_x + 2, 2); + glVertex2f(cursor_x + 2, line_height - 2); + glVertex2f(cursor_x, line_height - 2); + glEnd(); glPopAttrib(); diff -r db8a90307386 -r 5e27c85e79ca test/scene --- a/test/scene Mon Jun 09 16:01:00 2014 +0300 +++ b/test/scene Mon Jun 09 18:40:30 2014 +0300 @@ -1,14 +1,14 @@ # test scene sphere -position 0 0 0 -scaling 1 1 1 -diffuse 1 0.6 0.5 -brdf composite \ - -brdf lambert -brdf-weight 0.5 \ - -brdf phong -brdf-weight 0.5 + -brdf lambert -brdf-weight 0.7 \ + -brdf phong -brdf-weight 0.3 box -position 0 -1.25 0 -scaling 4 0.5 4 -diffuse 0.3 0.4 1.0 -brdf composite \ -brdf lambert -brdf-weight 0.3 \ -brdf mirror -brdf-weight 0.7 box -position 0 3.75 0 -scaling 20 10 20 -diffuse 1.0 1.0 1.0 -brdf lambert -box -position 0 4 0 -scaling 3 0.1 3 -emissive 6 6 6 +box -position 0 4 0 -scaling 3 0.1 3 -emissive 8 8 8 camera -position 0 3 -6 -target 0 0 0