c++ - How to colorize selections in ncurses? -
i'm working on roguelike right in ncurses , c++. right i'm coding title screen, looks this:
game name company name (n)ew game (q)uit
but i'd user able use arrow keys highlight selection , maybe reuse functionality later inventory screen. problem can't figure out how colorize new game , not quit when selected , vice versa. far code this:
mvaddstr((height-1)/2, ((width-4)/2)-(newgame_button.length()/2),newgame_button.c_str()); mvaddstr((height+1)/2, ((width-4)/2)-(quit_button.length()/2),quit_button.c_str()); mvaddstr((height-10)/2, ((width-4)/2)-(titlename.length()/2), titlename.c_str()); mvaddstr((height-8)/2, ((width-4)/2)-(companyname.length()/2), companyname.c_str());
then have key handler. tried this:
if(ch == key_down) { start_color(); init_pair(1, color_blue, color_black); attron(color_pair(1)); attroff(color_pair(1)); }
but doesn't work. i'm pretty new ncurses totally obvious overlooking. thanks!
the best/easiest way accomplish simple menu redraw title screen every time change selection( press rp_arrow down_arrow, ). don't have time refresh ncurses here's pseudocode. associate variable holding selection text has highlighted. , goes that.
#selecion=0; #while(key_pressed != enter) #print game title #print company name #if selection = 0 print highlighted new game #else print new game without highlight #if selection = 1 print highlighted quit #else print quit without highlight #if uparrow selection++ #if downarrow selection--
i know it's not perfect , have work logic of getting input , drawing fresh screen that's general idea behind simple, highlighted menu.
if need write here , i'll dig deeper of code/memory details , tips. luck game!
Comments
Post a Comment