diff -r 4f7c2c944637 -r 1b9c53e0c846 sources/interface.h --- a/sources/interface.h Fri May 15 18:36:22 2015 +0300 +++ b/sources/interface.h Fri May 15 20:03:35 2015 +0300 @@ -30,17 +30,91 @@ #pragma once #include "main.h" +#include "network/ipaddress.h" +#include "coloredline.h" +#include "network/rconsession.h" -namespace Interface +class Interface { - FUNCTION initialize() -> void; - FUNCTION handle_input() -> void; - FUNCTION render() -> void; - FUNCTION render_full() -> void; - FUNCTION set_title (const String& message) -> void; - FUNCTION update_statusbar() -> void; - FUNCTION connect (String address, String password) -> void; - FUNCTION set_player_names (const StringList& names) -> void; - FUNCTION need_refresh() -> void; - FUNCTION tab_complete (const String& part, String complete) -> void; +public: + enum InputState + { + INPUTSTATE_NORMAL, + INPUTSTATE_ADDRESS, + INPUTSTATE_PASSWORD, + INPUTSTATE_CONFIRM_DISCONNECTION, + }; + + Interface(); + void handle_input(); + void render(); + void render_full(); + void set_title (const String& message); + void update_statusbar(); + void connect (String address, String password); + void set_player_names (const StringList& names); + void need_refresh(); + void tab_complete (const String& part, String complete); + RCONSession* get_session() { return &Session; } + + template + void print (const String& fmtstr, const argtypes&... args) + { + print_to_console (format (fmtstr, args...)); + } + + template + void print_warning (const String& fmtstr, const argtypes&... args) + { + print_to_console (TEXTCOLOR_BrightYellow "-!- " + format (fmtstr, args...) + TEXTCOLOR_Reset); + } + + template + void print_error (const String& fmtstr, const argtypes&... args) + { + print_to_console (TEXTCOLOR_BrightRed "!!! " + format (fmtstr, args...) + TEXTCOLOR_Reset); + } + +private: + StringList InputHistory; + int InputCursor = 0; + int CursorPosition = 0; + int InputPanning = 0; + bool NeedRefresh = false; + bool NeedStatusBarRender = false; + bool NeedInputRender = false; + bool NeedOutputRender = false; + bool NeedNicklistRender = false; + struct { char ch; int x; } CursorCharacter; + Vector OutputLines; + int OutputScroll = 0; + String Title; + InputState CurrentInputState = INPUTSTATE_NORMAL; + Function DisconnectConfirmFunction = nullptr; + IPAddress CurrentAddress; + String StatusBarText; + StringList PlayerNames; + String PasteBuffer; + RCONSession Session; + + void render_titlebar(); + void safe_disconnect (Function afterwards); + int render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap); + int nicklist_width(); + void render_output(); + void render_nicklist(); + void render_input(); + void render_statusbar(); + void position_cursor(); + int color_pair (Color fg, Color bg); + const String& current_input(); + void detach_input(); + String& mutable_current_input(); + void move_input_cursor (int delta); + String prompt_string(); + void set_input_state (InputState newstate); + void print_to_console (String a); + void yank (int a, int b); + int find_previous_word(); + int find_next_word(); };