diff options
-rw-r--r-- | crawl-ref/source/libdos.cc | 17 | ||||
-rw-r--r-- | crawl-ref/source/libdos.h | 7 | ||||
-rw-r--r-- | crawl-ref/source/libunix.cc | 71 | ||||
-rw-r--r-- | crawl-ref/source/libunix.h | 9 | ||||
-rw-r--r-- | crawl-ref/source/libw32c.cc | 10 | ||||
-rw-r--r-- | crawl-ref/source/libw32c.h | 7 | ||||
-rw-r--r-- | crawl-ref/source/menu.cc | 6 | ||||
-rw-r--r-- | crawl-ref/source/menu.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/message.cc | 100 | ||||
-rw-r--r-- | crawl-ref/source/travel.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 38 | ||||
-rw-r--r-- | crawl-ref/source/view.h | 5 |
12 files changed, 150 insertions, 125 deletions
diff --git a/crawl-ref/source/libdos.cc b/crawl-ref/source/libdos.cc index b105896ba9..ba1e177c77 100644 --- a/crawl-ref/source/libdos.cc +++ b/crawl-ref/source/libdos.cc @@ -23,6 +23,13 @@ void init_libdos() tcsetattr (0, TCSANOW, &charmode); } +void clear_message_window() +{ + window(1, 18, 78, 25); + clrscr(); + window(1, 1, 80, 25); +} + void set_cursor_enabled(bool enabled) { cursor_is_enabled = enabled; @@ -42,3 +49,13 @@ void clear_to_end_of_line() if (pos <= cols) cprintf("%*s", cols - pos + 1, ""); } + +int get_number_of_lines() +{ + return (25); +} + +int get_number_of_cols() +{ + return (80); +} diff --git a/crawl-ref/source/libdos.h b/crawl-ref/source/libdos.h index 72872acdd5..1b8ae87e75 100644 --- a/crawl-ref/source/libdos.h +++ b/crawl-ref/source/libdos.h @@ -3,10 +3,17 @@ void init_libdos(); +int get_number_of_lines(); +int get_number_of_cols(); + inline void enable_smart_cursor(bool ) { } inline bool is_smart_cursor_enabled() { return (false); } void set_cursor_enabled(bool enabled); bool is_cursor_enabled(); void clear_to_end_of_line(); +void message_out(int mline, int colour, const char *str, int firstcol = 0, + bool newline = true); +void clear_message_window(); + #endif diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc index a02ffbf7c4..55273b343f 100644 --- a/crawl-ref/source/libunix.cc +++ b/crawl-ref/source/libunix.cc @@ -70,6 +70,9 @@ int Character_Set = CHARACTER_SET; short FG_COL = WHITE; short BG_COL = BLACK; +static int curs_fg_attr(int col); +static int curs_bg_attr(int col); + static bool cursor_is_enabled = true; static unsigned int convert_to_curses_attr( int chattr ) @@ -228,6 +231,50 @@ static void handle_hangup(int) #endif // USE_UNIX_SIGNALS && SIGHUP_SAVE +static WINDOW *Message_Window; +static void setup_message_window() +{ + extern int get_message_window_height(); + + Message_Window = newwin( get_message_window_height(), get_number_of_cols(), + VIEW_EY, 0 ); + if (!Message_Window) + { + fprintf(stderr, "Unable to create message window!"); + exit(1); + } + + scrollok(Message_Window, true); + idlok(Message_Window, true); +} + +void clear_message_window() +{ + wattrset( Message_Window, curs_fg_attr(LIGHTGREY) ); + werase( Message_Window ); + wrefresh( Message_Window ); +} + +void message_out(int which_line, int color, const char *s, int firstcol, + bool newline) +{ + extern int get_message_window_height(); + + wattrset( Message_Window, curs_fg_attr(color) ); + + if (!firstcol) + firstcol = Options.delay_message_clear? 1 : 0; + else + firstcol--; + + mvwaddstr(Message_Window, which_line, firstcol, s); + + if (newline && which_line == get_message_window_height() - 1) + scroll(Message_Window); + + wrefresh(Message_Window); +} + void unixcurses_startup( void ) { termio_init(); @@ -266,8 +313,9 @@ void unixcurses_startup( void ) setup_colour_pairs(); scrollok(stdscr, TRUE); -} + setup_message_window(); +} void unixcurses_shutdown() { @@ -406,12 +454,12 @@ void clear_to_end_of_screen(void) clrtobot(); } -int get_number_of_lines_from_curses(void) +int get_number_of_lines(void) { return (LINES); } -int get_number_of_cols_from_curses(void) +int get_number_of_cols(void) { return (COLS); } @@ -464,7 +512,7 @@ void textattr(int col) textcolor(col); } -void textcolor(int col) +static int curs_fg_attr(int col) { short fg, bg; @@ -518,11 +566,15 @@ void textcolor(int col) // figure out which colour pair we want const int pair = (fg == 0 && bg == 0) ? 63 : (bg * 8 + fg); - attrset( COLOR_PAIR(pair) | flags | Character_Set ); + return ( COLOR_PAIR(pair) | flags | Character_Set ); } +void textcolor(int col) +{ + attrset( curs_fg_attr(col) ); +} -void textbackground(int col) +static int curs_bg_attr(int col) { short fg, bg; @@ -573,7 +625,12 @@ void textbackground(int col) // figure out which colour pair we want const int pair = (fg == 0 && bg == 0) ? 63 : (bg * 8 + fg); - attrset( COLOR_PAIR(pair) | flags | Character_Set ); + return ( COLOR_PAIR(pair) | flags | Character_Set ); +} + +void textbackground(int col) +{ + attrset( curs_bg_attr(col) ); } diff --git a/crawl-ref/source/libunix.h b/crawl-ref/source/libunix.h index c619cf114d..52ecc4f72b 100644 --- a/crawl-ref/source/libunix.h +++ b/crawl-ref/source/libunix.h @@ -9,6 +9,13 @@ char *strlwr(char *str); char getche(void); +void message_out(int mline, int colour, const char *str, int firstcol = 0, + bool newline = true); +void clear_message_window(); + +int get_number_of_lines(); +int get_number_of_cols(); + int getch_ck(void); int clrscr(void); int cprintf(const char *format,...); @@ -24,8 +31,6 @@ int window(int x1, int y1, int x2, int y2); void update_screen(void); void clear_to_end_of_line(void); void clear_to_end_of_screen(void); -int get_number_of_lines_from_curses(void); -int get_number_of_cols_from_curses(void); void get_input_line_from_curses( char *const buff, int len ); void delay(unsigned long time); diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc index 7dc5b696e3..4e778b7aab 100644 --- a/crawl-ref/source/libw32c.cc +++ b/crawl-ref/source/libw32c.cc @@ -881,3 +881,13 @@ bool setBuffering( bool value ) return oldValue; } + +int get_number_of_lines() +{ + return (25); +} + +int get_number_of_cols() +{ + return (80); +} diff --git a/crawl-ref/source/libw32c.h b/crawl-ref/source/libw32c.h index 758b854e9e..730c1ea0b8 100644 --- a/crawl-ref/source/libw32c.h +++ b/crawl-ref/source/libw32c.h @@ -18,6 +18,13 @@ typedef std::basic_string<char> string; void init_libw32c(void); void deinit_libw32c(void); +void message_out(int mline, int colour, const char *str, int firstcol = 0, + bool newline = true); +void clear_message_window(); + +int get_number_of_lines(); +int get_number_of_cols(); + void set_cursor_enabled(bool enabled); bool is_cursor_enabled(); diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 28e5973ef8..bd68b3b188 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -941,11 +941,11 @@ int MenuHighlighter::entry_colour(const MenuEntry *entry) const // formatted_string // -formatted_string::formatted_string(const std::string &s, bool init_style) +formatted_string::formatted_string(const std::string &s, int init_colour) : ops() { - if (init_style) - ops.push_back(LIGHTGREY); + if (init_colour) + ops.push_back(init_colour); ops.push_back(s); } diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 19fb8d4370..de1032f99b 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -48,7 +48,7 @@ class formatted_string { public: formatted_string() : ops() { } - formatted_string(const std::string &s, bool init_style = false); + formatted_string(const std::string &s, int init_colour = 0); operator std::string() const; void display(int start = 0, int end = -1) const; diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc index c9c3bef60a..ece8b189c6 100644 --- a/crawl-ref/source/message.cc +++ b/crawl-ref/source/message.cc @@ -39,7 +39,8 @@ message_item Store_Message[ NUM_STORED_MESSAGES ]; // buffer of old messages int Next_Message = 0; // end of messages -char Message_Line = 0; // line of next (previous?) message +int Message_Line = 0; // line of next (previous?) message +int New_Message_Count = 0; static bool suppress_messages = false; static void base_mpr(const char *inf, int channel, int param); @@ -301,6 +302,7 @@ void mpr(const char *inf, int channel, int param) } } +static bool need_prefix = false; static void base_mpr(const char *inf, int channel, int param) { if (suppress_messages) @@ -357,33 +359,31 @@ static void base_mpr(const char *inf, int channel, int param) window(1, 1, 80, 25); #endif - textcolor(LIGHTGREY); + const int num_lines = get_message_window_height(); + + if (New_Message_Count == num_lines - 1) + more(); + + if (need_prefix) + { + message_out( Message_Line, colour, "-", 1, false ); + need_prefix = false; + } - const int num_lines = get_number_of_lines(); + message_out( Message_Line, colour, inf, + Options.delay_message_clear? 2 : 1 ); - if (Message_Line == num_lines - 18) // ( Message_Line == 8 ) - more(); + New_Message_Count++; + if (Message_Line < num_lines - 1) + Message_Line++; - gotoxy( (Options.delay_message_clear) ? 2 : 1, Message_Line + 18 ); - textcolor( colour ); - cprintf("%s", inf); - // // reset colour textcolor(LIGHTGREY); - Message_Line++; - - if (Options.delay_message_clear - && channel != MSGCH_PROMPT - && Message_Line == num_lines - 18) - { - more(); - } - // equipment lists just waste space in the message recall if (channel != MSGCH_EQUIPMENT) { - /* Put the message into Store_Message, and move the '---' line forward */ + // Put the message into Store_Message, and move the '---' line forward Store_Message[ Next_Message ].text = inf; Store_Message[ Next_Message ].channel = channel; Store_Message[ Next_Message ].param = param; @@ -401,55 +401,23 @@ bool any_messages(void) void mesclr( bool force ) { + New_Message_Count = 0; + // if no messages, return. if (!any_messages()) return; if (!force && Options.delay_message_clear) { - gotoxy( 1, Message_Line + 18 ); - textcolor( channel_to_colour( MSGCH_PLAIN, 0 ) ); - cprintf( ">" ); + need_prefix = true; return; } // turn cursor off -- avoid 'cursor dance' cursor_control cs(false); - -#ifdef DOS_TERM - window(1, 18, 78, 25); - clrscr(); - window(1, 1, 80, 25); -#endif - -#ifdef PLAIN_TERM - int startLine = 18; - - gotoxy(1, startLine); - -#ifdef UNIX - clear_to_end_of_screen(); -#else - - int numLines = get_number_of_lines() - startLine + 1; - - char blankline[81]; - memset(blankline, ' ', sizeof blankline); - blankline[80] = 0; - - for (int i = 0; i < numLines; i++) - { - cprintf( blankline ); - - if (i < numLines - 1) - { - cprintf(EOL); - } - } -#endif -#endif - + clear_message_window(); + need_prefix = false; Message_Line = 0; } // end mseclr() @@ -457,21 +425,8 @@ void more(void) { char keypress = 0; -#ifdef PLAIN_TERM - gotoxy( 2, get_number_of_lines() ); -#endif - -#ifdef DOS_TERM - window(1, 18, 80, 25); - gotoxy(2, 7); -#endif - - textcolor(LIGHTGREY); - -#ifdef DOS - cprintf(EOL); -#endif - cprintf("--more--"); + message_out(get_message_window_height() - 1, + LIGHTGREY, "--more--", 2, false); do { @@ -479,7 +434,8 @@ void more(void) } while (keypress != ' ' && keypress != '\r' && keypress != '\n'); - mesclr( (Message_Line >= get_number_of_lines() - 18) ); + mesclr( !Options.delay_message_clear && + Message_Line >= get_message_window_height() - 1 ); } // end more() std::string get_last_messages(int mcount) diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 673e17db04..1807dca9d6 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -1609,6 +1609,8 @@ static int prompt_travel_branch() int waycount = travel_cache.get_waypoint_count(); for ( ; ; ) { + mesclr(true); + char buf[100]; if (waypoint_list) travel_cache.list_waypoints(); @@ -1685,7 +1687,6 @@ static int prompt_travel_branch() return (-1 - (keyin - '0')); return (ID_CANCEL); } - mesclr(); } } diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index b91cfab4cb..d32464664c 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -97,43 +97,9 @@ static void set_show_backup( int ex, int ey ); static unsigned fix_colour(unsigned raw_colour); static int get_viewobj_flags(int viewobj); -//--------------------------------------------------------------- -// -// get_number_of_lines -// -// Made this a function instead of a #define. This should help -// considering the fact that the curses version is a macro -// (curses tends to be implemented with a large number of -// preprocessor macros, which can wreak havoc with things -// like the C++ string class, so we want to isolate that -// away to keep portability up). -// -// Other OSes might want to hook into reading system environment -// variables or player set options to determine the screen size -// (see the Options and SysEnv structures, as well as initfile.cc). -// -// This might be better to move to the lib*.cc files, but we -// don't really have a standard API defined for them, or the -// all important libdos.cc. It would be a good idea to eventually -// head that way. -- bwr -// -//--------------------------------------------------------------- -int get_number_of_lines(void) +int get_message_window_height() { -#ifdef UNIX - return (get_number_of_lines_from_curses()); -#else - return (25); -#endif -} - -int get_number_of_cols(void) -{ -#ifdef UNIX - return (get_number_of_cols_from_curses()); -#else - return (80); -#endif + return (get_number_of_lines() - VIEW_EY); } unsigned get_envmap_char(int x, int y) diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h index 4b7b37f1f7..399f0c00e1 100644 --- a/crawl-ref/source/view.h +++ b/crawl-ref/source/view.h @@ -21,10 +21,9 @@ #define BORDER_COLOR BROWN void init_char_table(char_set_type set); -void init_feature_table( void ); +void init_feature_table(); -int get_number_of_lines(void); -int get_number_of_cols(void); +int get_message_window_height(); /* *********************************************************************** * called from: dump_screenshot - chardump |