From 831211da35ee52a97dd32167ffe7e1b8b7fa1401 Mon Sep 17 00:00:00 2001 From: rez Date: Sun, 2 Sep 2012 15:35:13 +0000 Subject: [PATCH] scrollable option list in setup --- neercs/neercs.cpp | 3 +- neercs/term/term.cpp | 13 +++--- neercs/video/copper.lolfx | 9 ++-- neercs/video/render.cpp | 94 +++++++++++++++++++++++++++------------ 4 files changed, 76 insertions(+), 43 deletions(-) diff --git a/neercs/neercs.cpp b/neercs/neercs.cpp index 0afa742..4774b9e 100644 --- a/neercs/neercs.cpp +++ b/neercs/neercs.cpp @@ -87,5 +87,4 @@ int main(int argc, char **argv) app.Run(); return EXIT_SUCCESS; -} - +} \ No newline at end of file diff --git a/neercs/term/term.cpp b/neercs/term/term.cpp index e0a6269..953d2bc 100644 --- a/neercs/term/term.cpp +++ b/neercs/term/term.cpp @@ -94,7 +94,7 @@ void Term::DrawFancyShit() int logo_x = (w - 46) / 2; int logo_y = h / 2 - 2; - caca_set_color_argb(m_caca, 0x8ac, bg_color); + caca_set_color_argb(m_caca, 0xbac, bg_color); //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 ), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 )), bg_color); caca_put_str(m_caca, logo_x + 3, logo_y ,"__ _________ ______ ______ ______ ______"); //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 1), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color); @@ -103,10 +103,10 @@ void Term::DrawFancyShit() caca_put_str(m_caca, logo_x + 1, logo_y + 2, "/ / ____/ ____/ __ < <____\\___ \\"); //caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::cos(m_time * 3 + M_PI / 4 * 3), 0.5f, 0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color); caca_put_str(m_caca, logo_x , logo_y + 3, "/__/\\__/\\_______________/ \\________________\\"); - caca_set_color_argb(m_caca, 0xdef, bg_color); + caca_set_color_argb(m_caca, 0x269, bg_color); caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US"); - caca_set_color_argb(m_caca, 0x666, bg_color); + caca_set_color_argb(m_caca, 0x777, bg_color); caca_printf(m_caca, 2, h - 3, "W=%i", w); caca_printf(m_caca, 2, h - 2, "H=%i", h); @@ -125,7 +125,7 @@ void Term::DrawFancyShit() int lolcube_x = w / 2 - 5 + (w - 10) * lol::cos(m_time / 2); int lolcube_y = h - 5 - abs ((h - 5) * lol::sin(m_time * 4)); - caca_set_color_argb(m_caca, hex_color(0.75f + 0.25f * lol::sin(m_time * 2), 0.75f + 0.25f * lol::cos(m_time * 3), 0.75f + 0.25f * lol::sin(m_time * 5)), bg_color); + caca_set_color_argb(m_caca, hex_color(0.5f + 0.5f * lol::sin(m_time * 2), 0.5f + 0.5f * lol::cos(m_time * 3), 0.5f + 0.5f * lol::sin(m_time * 5)), bg_color); caca_put_str(m_caca, lolcube_x + 2, lolcube_y , "_______"); caca_put_str(m_caca, lolcube_x + 1, lolcube_y + 1, "/ /|"); caca_put_str(m_caca, lolcube_x , lolcube_y + 2, "/______/ |"); @@ -133,11 +133,10 @@ void Term::DrawFancyShit() caca_put_str(m_caca, lolcube_x , lolcube_y + 4, "| :D | /"); caca_put_str(m_caca, lolcube_x , lolcube_y + 5, "|______|/"); - caca_set_color_argb(m_caca, 0xdef, bg_color); + caca_set_color_argb(m_caca, 0x777, bg_color); caca_put_str(m_caca, 0, 0, "rez@lol:~/ sudo -s"); caca_put_str(m_caca, 0, 1, "[sudo] password for rez:"); caca_put_str(m_caca, 0, 2, "root@lol:~/ echo LOL"); caca_put_str(m_caca, 0, 3, "LOL"); caca_put_str(m_caca, 0, 4, "root@lol:~/"); -} - +} \ No newline at end of file diff --git a/neercs/video/copper.lolfx b/neercs/video/copper.lolfx index 6cba9f1..2eaeac5 100644 --- a/neercs/video/copper.lolfx +++ b/neercs/video/copper.lolfx @@ -23,16 +23,15 @@ void main(void) vec3 color=texture2D(texture,p).xyz; vec3 copper=vec3(0.5); + copper.x+=0.5*cos(p.y*float(screen_size.y/64)+time*2.0); copper.z+=0.5*sin(p.y*float(screen_size.y/64)+time*2.0); - copper*=0.75+0.375*cos(p.y*float(screen_size.y/6)-time*2.0); + copper*=0.75+0.375*cos(p.y*float(screen_size.x/8)-time*2.0); - /* copper.x=float(int(copper.x*8.0)*32)/256.0; copper.y=float(int(copper.y*8.0)*32)/256.0; copper.z=float(int(copper.z*8.0)*32)/256.0; - */ - gl_FragColor=vec4((dot(color,color)==1.0)?copper:color,1.0); - } + gl_FragColor=vec4((color==1.0)?copper:color,1.0); + } \ No newline at end of file diff --git a/neercs/video/render.cpp b/neercs/video/render.cpp index 7198a38..3594fd8 100644 --- a/neercs/video/render.cpp +++ b/neercs/video/render.cpp @@ -119,14 +119,18 @@ ivec2 canvas_char(0,0); // canvas char number ivec2 canvas_size(0,0); // caca size /* setup variable */ bool setup_switch = false; // switch [option/item] -int setup_option = 0; // selected option +int setup_n = 0; // item/option number +int setup_h = 6; // height +int setup_cursor = 0; // cursor position +int setup_option_i = 0; // selected option int setup_option_n = 10; // option number -int setup_item = 0; // selected item +int setup_option_p = 0; // option position +int setup_item_i = 0; // selected item int setup_item_n = 8; // item number +int setup_item_p = 0; // item position int setup_item_key = 0; // item array key -int setup_n = 0; // contextual option/item number ivec2 setup_p(1,1); // position [x,y] -ivec3 setup_size(30,0,12); // size [w,h,split] +ivec3 setup_size(30,7,12); // size [w,h,split] ivec2 setup_color(0x678,0x234); // color [foreground,background] char const *setup_text[] = { "theme", @@ -359,7 +363,7 @@ int calc_item_length() int n = !setup_switch ? setup_option_n : setup_item_n; for (int i = 0; i < n; i++) { - int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option * (setup_item_n + 1) + 1 + i); + int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option_i * (setup_item_n + 1) + 1 + i); if (setup_text[k] == "") return i - 1; } return n - 1; @@ -530,9 +534,7 @@ int Render::CreateGLWindow() caca_set_canvas_size(m_caca, canvas_char.x, canvas_char.y); - setup_size.y = ((setup_option_n > setup_item_n) ? setup_option_n : setup_item_n) + 1; setup_p = (canvas_char - setup_size.xy) / 2; - setup_n = calc_item_length(); InitDraw(); @@ -600,14 +602,30 @@ void Render::TickDraw(float seconds) { if (!setup_switch) { - setup_option--; - if (setup_option < 0) setup_option = setup_n; - setup_item = 0; + if (setup_cursor > 0) + { + setup_cursor--; + } + else + { + if ((setup_option_p > 0) && setup_cursor == 0) setup_option_p--; + } + if (setup_option_i > 0) + { + setup_option_i--; + } + else + { + setup_option_i = setup_option_n - 1; + setup_option_p = setup_option_n - setup_h; + setup_cursor = setup_h - 1; + } + setup_item_i = 0; } else { - setup_item--; - if (setup_item < 0) setup_item = setup_n; + setup_item_i--; + if (setup_item_i < 0) setup_item_i = setup_n; } } } @@ -617,14 +635,30 @@ void Render::TickDraw(float seconds) { if (!setup_switch) { - setup_option++; - if (setup_option > setup_n) setup_option = 0; - setup_item = 0; + if (setup_cursor < setup_h - 1) + { + setup_cursor++; + } + else + { + if ((setup_option_p + setup_h < setup_option_n) && setup_cursor == setup_h - 1) setup_option_p++; + } + if (setup_option_i < setup_option_n - 1) + { + setup_option_i++; + } + else + { + setup_option_i = 0; + setup_option_p = 0; + setup_cursor = 0; + } + setup_item_i = 0; } else { - setup_item++; - if (setup_item > setup_n) setup_item = 0; + setup_item_i++; + if (setup_item_i > setup_n) setup_item_i = 0; } } } @@ -634,11 +668,12 @@ void Render::TickDraw(float seconds) { if (!setup_switch) { - setup_option = 0; + setup_option_i -= setup_cursor; + setup_cursor = 0; + setup_item_i = 0; } else { - setup_item = 0; } } } @@ -648,12 +683,13 @@ void Render::TickDraw(float seconds) { if (!setup_switch) { - setup_option = setup_n; - setup_item = 0; + setup_option_i += setup_h - setup_cursor - 1; + setup_cursor = setup_h - 1; + setup_item_i = 0; } else { - setup_item = setup_n; + setup_item_i = setup_n; } } } @@ -764,11 +800,11 @@ void Render::TickDraw(float seconds) caca_draw_line(m_caca, setup_p.x, setup_p.y, setup_p.x + setup_size.x, setup_p.y,' '); caca_put_str(m_caca, setup_p.x + setup_size.x / 2 - 3, setup_p.y, "SETUP"); /* display option */ - for (int i = 0; i < setup_option_n; i++) + for (int i = 0; i < setup_h; i++) { int y = setup_p.y + 1 + i; - int k = i * (setup_item_n + 1); - if (setup_option != i || setup_switch) + int k = (setup_option_p + i) * (setup_item_n + 1); + if (setup_option_i != setup_option_p + i || setup_switch) { caca_set_color_argb(m_caca, setup_color.x, setup_color.y); caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]); @@ -781,11 +817,11 @@ void Render::TickDraw(float seconds) } } /* display item */ - for (int i = 0; i < setup_item_n; i++) + for (int i = 0; i < setup_h; i++) { int y = setup_p.y + 1 + i; - int k = setup_option * (setup_item_n + 1) + 1 + i; - if (setup_item != i || !setup_switch) + int k = setup_option_i * (setup_item_n + 1) + 1 + setup_item_p + i; + if (setup_item_i != i || !setup_switch) { caca_set_color_argb(m_caca, setup_color.x, setup_color.y); caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k]); @@ -799,7 +835,7 @@ void Render::TickDraw(float seconds) } /* display variable */ int y = setup_p.y + setup_size.y; - setup_item_key = setup_option * (setup_item_n + 1) + 1 + setup_item; + setup_item_key = setup_option_i * (setup_item_n + 1) + 1 + setup_item_i; caca_set_color_argb(m_caca, setup_color.y, setup_color.x); caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.x, y,' '); if (setup_switch)