window: adjust indentation
This commit is contained in:
942
src/window.h
942
src/window.h
@@ -123,497 +123,497 @@
|
|||||||
///
|
///
|
||||||
namespace NC
|
namespace NC
|
||||||
{
|
{
|
||||||
/// Colors used by NCurses
|
/// Colors used by NCurses
|
||||||
|
///
|
||||||
|
enum Color { clDefault, clBlack, clRed, clGreen, clYellow, clBlue, clMagenta, clCyan, clWhite, clEnd };
|
||||||
|
|
||||||
|
/// Format flags used by NCurses
|
||||||
|
///
|
||||||
|
enum Format {
|
||||||
|
fmtNone = clEnd+1,
|
||||||
|
fmtBold, fmtBoldEnd,
|
||||||
|
fmtUnderline, fmtUnderlineEnd,
|
||||||
|
fmtReverse, fmtReverseEnd,
|
||||||
|
fmtAltCharset, fmtAltCharsetEnd
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Available border colors for window
|
||||||
|
///
|
||||||
|
enum Border { brNone, brBlack, brRed, brGreen, brYellow, brBlue, brMagenta, brCyan, brWhite };
|
||||||
|
|
||||||
|
/// This indicates how much the window has to be scrolled
|
||||||
|
///
|
||||||
|
enum Where { wUp, wDown, wPageUp, wPageDown, wHome, wEnd };
|
||||||
|
|
||||||
|
/// Helper function that is invoked each time one will want
|
||||||
|
/// to obtain string from Window::GetString() function
|
||||||
|
/// @see Window::GetString()
|
||||||
|
///
|
||||||
|
typedef std::function<void(const std::wstring &)> GetStringHelper;
|
||||||
|
|
||||||
|
/// Initializes curses screen and sets some additional attributes
|
||||||
|
/// @param window_title title of the window (has an effect only if pdcurses lib is used)
|
||||||
|
/// @param enable_colors enables colors
|
||||||
|
///
|
||||||
|
void InitScreen(const char *window_title, bool enable_colors);
|
||||||
|
|
||||||
|
/// Destroys the screen
|
||||||
|
///
|
||||||
|
void DestroyScreen();
|
||||||
|
|
||||||
|
/// Struct used to set color of both foreground and background of window
|
||||||
|
/// @see Window::operator<<()
|
||||||
|
///
|
||||||
|
struct Colors
|
||||||
|
{
|
||||||
|
Colors(Color one, Color two = clDefault) : fg(one), bg(two) { }
|
||||||
|
Color fg;
|
||||||
|
Color bg;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Struct used for going to given coordinates
|
||||||
|
/// @see Window::operator<<()
|
||||||
|
///
|
||||||
|
struct XY
|
||||||
|
{
|
||||||
|
XY(int xx, int yy) : x(xx), y(yy) { }
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Main class of NCurses namespace, used as base for other specialized windows
|
||||||
|
///
|
||||||
|
struct Window
|
||||||
|
{
|
||||||
|
/// Constructs an empty window with given parameters
|
||||||
|
/// @param startx X position of left upper corner of constructed window
|
||||||
|
/// @param starty Y position of left upper corner of constructed window
|
||||||
|
/// @param width width of constructed window
|
||||||
|
/// @param height height of constructed window
|
||||||
|
/// @param title title of constructed window
|
||||||
|
/// @param color base color of constructed window
|
||||||
|
/// @param border border of constructed window
|
||||||
///
|
///
|
||||||
enum Color { clDefault, clBlack, clRed, clGreen, clYellow, clBlue, clMagenta, clCyan, clWhite, clEnd };
|
Window(size_t startx, size_t starty, size_t width, size_t height,
|
||||||
|
const std::string &title, Color color, Border border);
|
||||||
|
|
||||||
/// Format flags used by NCurses
|
/// Copies thw window
|
||||||
|
/// @param w copied window
|
||||||
///
|
///
|
||||||
enum Format {
|
Window(const Window &w);
|
||||||
fmtNone = clEnd+1,
|
|
||||||
fmtBold, fmtBoldEnd,
|
|
||||||
fmtUnderline, fmtUnderlineEnd,
|
|
||||||
fmtReverse, fmtReverseEnd,
|
|
||||||
fmtAltCharset, fmtAltCharsetEnd
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Available border colors for window
|
/// Destroys the window and frees memory
|
||||||
///
|
///
|
||||||
enum Border { brNone, brBlack, brRed, brGreen, brYellow, brBlue, brMagenta, brCyan, brWhite };
|
virtual ~Window();
|
||||||
|
|
||||||
/// This indicates how much the window has to be scrolled
|
/// Allows for direct access to internal WINDOW pointer in case there
|
||||||
|
/// is no wrapper for a function from curses library one may want to use
|
||||||
|
/// @return internal WINDOW pointer
|
||||||
///
|
///
|
||||||
enum Where { wUp, wDown, wPageUp, wPageDown, wHome, wEnd };
|
WINDOW *Raw() const { return itsWindow; }
|
||||||
|
|
||||||
/// Helper function that is invoked each time one will want
|
/// @return window's width
|
||||||
/// to obtain string from Window::GetString() function
|
|
||||||
/// @see Window::GetString()
|
|
||||||
///
|
///
|
||||||
typedef std::function<void(const std::wstring &)> GetStringHelper;
|
size_t GetWidth() const;
|
||||||
|
|
||||||
/// Initializes curses screen and sets some additional attributes
|
/// @return window's height
|
||||||
/// @param window_title title of the window (has an effect only if pdcurses lib is used)
|
|
||||||
/// @param enable_colors enables colors
|
|
||||||
///
|
///
|
||||||
void InitScreen(const char *window_title, bool enable_colors);
|
size_t GetHeight() const;
|
||||||
|
|
||||||
/// Destroys the screen
|
/// @return X position of left upper window's corner
|
||||||
///
|
///
|
||||||
void DestroyScreen();
|
size_t GetStartX() const;
|
||||||
|
|
||||||
/// Struct used to set color of both foreground and background of window
|
/// @return Y position of left upper window's corner
|
||||||
/// @see Window::operator<<()
|
|
||||||
///
|
///
|
||||||
struct Colors
|
size_t GetStartY() const;
|
||||||
|
|
||||||
|
/// @return window's title
|
||||||
|
///
|
||||||
|
const std::string &getTitle() const;
|
||||||
|
|
||||||
|
/// @return current window's color
|
||||||
|
///
|
||||||
|
Color GetColor() const;
|
||||||
|
|
||||||
|
/// @return current window's border
|
||||||
|
///
|
||||||
|
Border GetBorder() const;
|
||||||
|
|
||||||
|
/// @return current window's timeout
|
||||||
|
///
|
||||||
|
int GetTimeout() const;
|
||||||
|
|
||||||
|
/// Reads the string from standard input. Note that this is much more complex
|
||||||
|
/// function than getstr() from curses library. It allows for moving through
|
||||||
|
/// letters with arrows, supports scrolling if string's length is bigger than
|
||||||
|
/// given area, supports history of previous strings and each time it receives
|
||||||
|
/// an input from the keyboard or the timeout is reached, it calls helper function
|
||||||
|
/// (if it's set) that takes as an argument currently edited string.
|
||||||
|
/// @param base base string that has to be edited
|
||||||
|
/// @param length max length of string, unlimited by default
|
||||||
|
/// @param width width of area that entry field can take. if it's reached, string
|
||||||
|
/// will be scrolled. if value is 0, field will be from cursor position to the end
|
||||||
|
/// of current line wide.
|
||||||
|
/// @param encrypted if set to true, '*' characters will be displayed instead of
|
||||||
|
/// actual text.
|
||||||
|
/// @return edited string
|
||||||
|
///
|
||||||
|
/// @see SetGetStringHelper()
|
||||||
|
/// @see SetTimeout()
|
||||||
|
/// @see CreateHistory()
|
||||||
|
///
|
||||||
|
std::string GetString(const std::string &base, size_t length = -1,
|
||||||
|
size_t width = 0, bool encrypted = 0);
|
||||||
|
|
||||||
|
/// Wrapper for above function that doesn't take base string (it will be empty).
|
||||||
|
/// Taken parameters are the same as for above.
|
||||||
|
///
|
||||||
|
std::string GetString(size_t length = -1, size_t width = 0, bool encrypted = 0)
|
||||||
{
|
{
|
||||||
Colors(Color one, Color two = clDefault) : fg(one), bg(two) { }
|
return GetString("", length, width, encrypted);
|
||||||
Color fg;
|
}
|
||||||
Color bg;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Struct used for going to given coordinates
|
/// Moves cursor to given coordinates
|
||||||
/// @see Window::operator<<()
|
/// @param x given X position
|
||||||
|
/// @param y given Y position
|
||||||
///
|
///
|
||||||
struct XY
|
void GotoXY(int x, int y);
|
||||||
{
|
|
||||||
XY(int xx, int yy) : x(xx), y(yy) { }
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Main class of NCurses namespace, used as base for other specialized windows
|
/// @return x window coordinate
|
||||||
|
/// @see GetXY()
|
||||||
///
|
///
|
||||||
class Window
|
int X();
|
||||||
{
|
|
||||||
public:
|
/// @return y windows coordinate
|
||||||
/// Constructs an empty window with given parameters
|
/// @see GetXY()
|
||||||
/// @param startx X position of left upper corner of constructed window
|
///
|
||||||
/// @param starty Y position of left upper corner of constructed window
|
int Y();
|
||||||
/// @param width width of constructed window
|
|
||||||
/// @param height height of constructed window
|
/// Used to indicate whether given coordinates of main screen lies within
|
||||||
/// @param title title of constructed window
|
/// window area or not and if they do, transform them into in-window coords.
|
||||||
/// @param color base color of constructed window
|
/// Otherwise function doesn't modify its arguments.
|
||||||
/// @param border border of constructed window
|
/// @param x X position of main screen to be checked
|
||||||
///
|
/// @param y Y position of main screen to be checked
|
||||||
Window(size_t startx, size_t starty, size_t width, size_t height,
|
/// @return true if it transformed variables, false otherwise
|
||||||
const std::string &title, Color color, Border border);
|
///
|
||||||
|
bool hasCoords(int &x, int &y);
|
||||||
/// Copies thw window
|
|
||||||
/// @param w copied window
|
/// Sets helper function used in GetString()
|
||||||
///
|
/// @param helper pointer to function that matches GetStringHelper prototype
|
||||||
Window(const Window &w);
|
/// @see GetString()
|
||||||
|
///
|
||||||
/// Destroys the window and frees memory
|
void SetGetStringHelper(GetStringHelper helper) { itsGetStringHelper = helper; }
|
||||||
///
|
|
||||||
virtual ~Window();
|
/// Sets window's base color
|
||||||
|
/// @param fg foregound base color
|
||||||
/// Allows for direct access to internal WINDOW pointer in case there
|
/// @param bg background base color
|
||||||
/// is no wrapper for a function from curses library one may want to use
|
///
|
||||||
/// @return internal WINDOW pointer
|
void SetBaseColor(Color fg, Color bg = clDefault);
|
||||||
///
|
|
||||||
WINDOW *Raw() const { return itsWindow; }
|
/// Sets window's border
|
||||||
|
/// @param border new window's border
|
||||||
/// @return window's width
|
///
|
||||||
///
|
void SetBorder(Border border);
|
||||||
size_t GetWidth() const;
|
|
||||||
|
/// Sets window's timeout
|
||||||
/// @return window's height
|
/// @param timeout window's timeout
|
||||||
///
|
///
|
||||||
size_t GetHeight() const;
|
void SetTimeout(int timeout);
|
||||||
|
|
||||||
/// @return X position of left upper window's corner
|
/// Sets window's title
|
||||||
///
|
/// @param new_title new title for window
|
||||||
size_t GetStartX() const;
|
///
|
||||||
|
void SetTitle(const std::string &new_title);
|
||||||
/// @return Y position of left upper window's corner
|
|
||||||
///
|
/// Creates internal container that stores all previous
|
||||||
size_t GetStartY() const;
|
/// strings that were edited using this window.
|
||||||
|
///
|
||||||
/// @return window's title
|
void CreateHistory();
|
||||||
///
|
|
||||||
const std::string &getTitle() const;
|
/// Deletes container with all previous history entries
|
||||||
|
///
|
||||||
/// @return current window's color
|
void DeleteHistory();
|
||||||
///
|
|
||||||
Color GetColor() const;
|
/// "Hides" the window by filling its area with given character
|
||||||
|
/// @param ch character to fill the area
|
||||||
/// @return current window's border
|
/// @see Clear()
|
||||||
///
|
///
|
||||||
Border GetBorder() const;
|
void Hide(char ch = 32) const;
|
||||||
|
|
||||||
/// @return current window's timeout
|
/// Refreshed whole window and its border
|
||||||
///
|
/// @see Refresh()
|
||||||
int GetTimeout() const;
|
///
|
||||||
|
void Display();
|
||||||
/// Reads the string from standard input. Note that this is much more complex
|
|
||||||
/// function than getstr() from curses library. It allows for moving through
|
/// Refreshes whole window, but not the border
|
||||||
/// letters with arrows, supports scrolling if string's length is bigger than
|
/// @see Display()
|
||||||
/// given area, supports history of previous strings and each time it receives
|
///
|
||||||
/// an input from the keyboard or the timeout is reached, it calls helper function
|
virtual void Refresh();
|
||||||
/// (if it's set) that takes as an argument currently edited string.
|
|
||||||
/// @param base base string that has to be edited
|
/// Moves the window to new coordinates
|
||||||
/// @param length max length of string, unlimited by default
|
/// @param new_x new X position of left upper corner of window
|
||||||
/// @param width width of area that entry field can take. if it's reached, string
|
/// @param new_y new Y position of left upper corner of window
|
||||||
/// will be scrolled. if value is 0, field will be from cursor position to the end
|
///
|
||||||
/// of current line wide.
|
virtual void MoveTo(size_t new_x, size_t new_y);
|
||||||
/// @param encrypted if set to true, '*' characters will be displayed instead of
|
|
||||||
/// actual text.
|
/// Resizes the window
|
||||||
/// @return edited string
|
/// @param new_width new window's width
|
||||||
///
|
/// @param new_height new window's height
|
||||||
/// @see SetGetStringHelper()
|
///
|
||||||
/// @see SetTimeout()
|
virtual void Resize(size_t new_width, size_t new_height);
|
||||||
/// @see CreateHistory()
|
|
||||||
///
|
/// Cleares the window
|
||||||
std::string GetString(const std::string &base, size_t length = -1,
|
///
|
||||||
size_t width = 0, bool encrypted = 0);
|
virtual void Clear();
|
||||||
|
|
||||||
/// Wrapper for above function that doesn't take base string (it will be empty).
|
/// Adds given file descriptor to the list that will be polled in
|
||||||
/// Taken parameters are the same as for above.
|
/// ReadKey() along with stdin and callback that will be invoked
|
||||||
///
|
/// when there is data waiting for reading in it
|
||||||
std::string GetString(size_t length = -1, size_t width = 0, bool encrypted = 0)
|
/// @param fd file descriptor
|
||||||
{
|
/// @param callback callback
|
||||||
return GetString("", length, width, encrypted);
|
///
|
||||||
}
|
void AddFDCallback(int fd, void (*callback)());
|
||||||
|
|
||||||
/// Moves cursor to given coordinates
|
/// Clears list of file descriptors and their callbacks
|
||||||
/// @param x given X position
|
///
|
||||||
/// @param y given Y position
|
void ClearFDCallbacksList();
|
||||||
///
|
|
||||||
void GotoXY(int x, int y);
|
/// Checks if list of file descriptors is empty
|
||||||
|
/// @return true if list is empty, false otherwise
|
||||||
/// @return x window coordinate
|
///
|
||||||
/// @see GetXY()
|
bool FDCallbacksListEmpty() const;
|
||||||
///
|
|
||||||
int X();
|
/// Reads key from standard input (or takes it from input queue)
|
||||||
|
/// and writes it into read_key variable
|
||||||
/// @return y windows coordinate
|
///
|
||||||
/// @see GetXY()
|
int ReadKey();
|
||||||
///
|
|
||||||
int Y();
|
/// Push single character into input queue, so it can get consumed by ReadKey
|
||||||
|
void PushChar(int ch);
|
||||||
/// Used to indicate whether given coordinates of main screen lies within
|
|
||||||
/// window area or not and if they do, transform them into in-window coords.
|
/// Scrolls the window by amount of lines given in its parameter
|
||||||
/// Otherwise function doesn't modify its arguments.
|
/// @param where indicates how many lines it has to scroll
|
||||||
/// @param x X position of main screen to be checked
|
///
|
||||||
/// @param y Y position of main screen to be checked
|
virtual void Scroll(Where where);
|
||||||
/// @return true if it transformed variables, false otherwise
|
|
||||||
///
|
/// Applies function of compatible prototype to internal WINDOW pointer
|
||||||
bool hasCoords(int &x, int &y);
|
/// The mostly used function in this case seem to be wclrtoeol(), which
|
||||||
|
/// clears the window from current cursor position to the end of line.
|
||||||
/// Sets helper function used in GetString()
|
/// Note that delwin() also matches that prototype, but I wouldn't
|
||||||
/// @param helper pointer to function that matches GetStringHelper prototype
|
/// recommend anyone passing this pointer here ;)
|
||||||
/// @see GetString()
|
/// @param f pointer to function to call with internal WINDOW pointer
|
||||||
///
|
/// @return reference to itself
|
||||||
void SetGetStringHelper(GetStringHelper helper) { itsGetStringHelper = helper; }
|
///
|
||||||
|
Window &operator<<(int (*f)(WINDOW *));
|
||||||
/// Sets window's base color
|
|
||||||
/// @param fg foregound base color
|
/// Applies foreground and background colors to window
|
||||||
/// @param bg background base color
|
/// @param colors struct that holds new colors information
|
||||||
///
|
/// @return reference to itself
|
||||||
void SetBaseColor(Color fg, Color bg = clDefault);
|
///
|
||||||
|
Window &operator<<(Colors colors);
|
||||||
/// Sets window's border
|
|
||||||
/// @param border new window's border
|
/// Applies foregound color to window. Note that colors applied
|
||||||
///
|
/// that way are stacked, i.e if you applied clRed, then clGreen
|
||||||
void SetBorder(Border border);
|
/// and clEnd, current color would be clRed. If you want to discard
|
||||||
|
/// all colors and fall back to base one, pass clDefault.
|
||||||
/// Sets window's timeout
|
/// @param color new color value
|
||||||
/// @param timeout window's timeout
|
/// @return reference to itself
|
||||||
///
|
///
|
||||||
void SetTimeout(int timeout);
|
Window &operator<<(Color color);
|
||||||
|
|
||||||
/// Sets window's title
|
/// Applies format flag to window. Note that these attributes are
|
||||||
/// @param new_title new title for window
|
/// also stacked, so if you applied fmtBold twice, to get rid of
|
||||||
///
|
/// it you have to pass fmtBoldEnd also twice.
|
||||||
void SetTitle(const std::string &new_title);
|
/// @param format format flag
|
||||||
|
/// @return reference to itself
|
||||||
/// Creates internal container that stores all previous
|
///
|
||||||
/// strings that were edited using this window.
|
Window &operator<<(Format format);
|
||||||
///
|
|
||||||
void CreateHistory();
|
/// Moves current cursor position to given coordinates.
|
||||||
|
/// @param coords struct that holds information about new coordinations
|
||||||
/// Deletes container with all previous history entries
|
/// @return reference to itself
|
||||||
///
|
///
|
||||||
void DeleteHistory();
|
Window &operator<<(XY coords);
|
||||||
|
|
||||||
/// "Hides" the window by filling its area with given character
|
/// Prints string to window
|
||||||
/// @param ch character to fill the area
|
/// @param s const pointer to char array to be printed
|
||||||
/// @see Clear()
|
/// @return reference to itself
|
||||||
///
|
///
|
||||||
void Hide(char ch = 32) const;
|
Window &operator<<(const char *s);
|
||||||
|
|
||||||
/// Refreshed whole window and its border
|
/// Prints single character to window
|
||||||
/// @see Refresh()
|
/// @param c character to be printed
|
||||||
///
|
/// @return reference to itself
|
||||||
void Display();
|
///
|
||||||
|
Window &operator<<(char c);
|
||||||
/// Refreshes whole window, but not the border
|
|
||||||
/// @see Display()
|
/// Prints wide string to window
|
||||||
///
|
/// @param ws const pointer to wchar_t array to be printed
|
||||||
virtual void Refresh();
|
/// @return reference to itself
|
||||||
|
///
|
||||||
/// Moves the window to new coordinates
|
Window &operator<<(const wchar_t *ws);
|
||||||
/// @param new_x new X position of left upper corner of window
|
|
||||||
/// @param new_y new Y position of left upper corner of window
|
/// Prints single wide character to window
|
||||||
///
|
/// @param wc wide character to be printed
|
||||||
virtual void MoveTo(size_t new_x, size_t new_y);
|
/// @return reference to itself
|
||||||
|
///
|
||||||
/// Resizes the window
|
Window &operator<<(wchar_t wc);
|
||||||
/// @param new_width new window's width
|
|
||||||
/// @param new_height new window's height
|
/// Prints int to window
|
||||||
///
|
/// @param i integer value to be printed
|
||||||
virtual void Resize(size_t new_width, size_t new_height);
|
/// @return reference to itself
|
||||||
|
///
|
||||||
/// Cleares the window
|
Window &operator<<(int i);
|
||||||
///
|
|
||||||
virtual void Clear();
|
/// Prints double to window
|
||||||
|
/// @param d double value to be printed
|
||||||
/// Adds given file descriptor to the list that will be polled in
|
/// @return reference to itself
|
||||||
/// ReadKey() along with stdin and callback that will be invoked
|
///
|
||||||
/// when there is data waiting for reading in it
|
Window &operator<<(double d);
|
||||||
/// @param fd file descriptor
|
|
||||||
/// @param callback callback
|
/// Prints size_t to window
|
||||||
///
|
/// @param s size value to be printed
|
||||||
void AddFDCallback(int fd, void (*callback)());
|
/// @return reference to itself
|
||||||
|
///
|
||||||
/// Clears list of file descriptors and their callbacks
|
Window &operator<<(size_t s);
|
||||||
///
|
|
||||||
void ClearFDCallbacksList();
|
/// Prints std::string to window
|
||||||
|
/// @param s string to be printed
|
||||||
/// Checks if list of file descriptors is empty
|
/// @return reference to itself
|
||||||
/// @return true if list is empty, false otherwise
|
///
|
||||||
///
|
Window &operator<<(const std::string &s);
|
||||||
bool FDCallbacksListEmpty() const;
|
|
||||||
|
/// Prints std::wstring to window
|
||||||
/// Reads key from standard input (or takes it from input queue)
|
/// @param ws wide string to be printed
|
||||||
/// and writes it into read_key variable
|
/// @return reference to itself
|
||||||
///
|
///
|
||||||
int ReadKey();
|
Window &operator<<(const std::wstring &ws);
|
||||||
|
|
||||||
/// Push single character into input queue, so it can get consumed by ReadKey
|
/// Fallback for Length() for wide strings used if unicode support is disabled
|
||||||
void PushChar(int ch);
|
/// @param s string that real length has to be measured
|
||||||
|
/// @return standard std::string::length() result since it's only fallback
|
||||||
/// Scrolls the window by amount of lines given in its parameter
|
///
|
||||||
/// @param where indicates how many lines it has to scroll
|
static size_t Length(const std::string &s) { return s.length(); }
|
||||||
///
|
|
||||||
virtual void Scroll(Where where);
|
/// Measures real length of wide string (required if e.g. asian characters are used)
|
||||||
|
/// @param ws wide string that real length has to be measured
|
||||||
/// Applies function of compatible prototype to internal WINDOW pointer
|
/// @return real length of wide string
|
||||||
/// The mostly used function in this case seem to be wclrtoeol(), which
|
///
|
||||||
/// clears the window from current cursor position to the end of line.
|
static size_t Length(const std::wstring &ws);
|
||||||
/// Note that delwin() also matches that prototype, but I wouldn't
|
|
||||||
/// recommend anyone passing this pointer here ;)
|
/// Cuts string so it fits desired length on the screen. Note that it uses
|
||||||
/// @param f pointer to function to call with internal WINDOW pointer
|
/// wcwidth to check real width of all characters it contains. If string
|
||||||
/// @return reference to itself
|
/// fits requested length it's not modified at all.
|
||||||
///
|
/// @param ws wide string to be cut
|
||||||
Window &operator<<(int (*f)(WINDOW *));
|
/// @param max_len maximal length of string
|
||||||
|
static void Cut(std::wstring &ws, size_t max_len);
|
||||||
/// Applies foreground and background colors to window
|
|
||||||
/// @param colors struct that holds new colors information
|
protected:
|
||||||
/// @return reference to itself
|
/// Sets colors of window (interal use only)
|
||||||
///
|
/// @param fg foregound color
|
||||||
Window &operator<<(Colors colors);
|
/// @param bg background color
|
||||||
|
///
|
||||||
/// Applies foregound color to window. Note that colors applied
|
void SetColor(Color fg, Color bg = clDefault);
|
||||||
/// that way are stacked, i.e if you applied clRed, then clGreen
|
|
||||||
/// and clEnd, current color would be clRed. If you want to discard
|
/// Refreshes window's border
|
||||||
/// all colors and fall back to base one, pass clDefault.
|
///
|
||||||
/// @param color new color value
|
void ShowBorder() const;
|
||||||
/// @return reference to itself
|
|
||||||
///
|
/// Changes dimensions of window, called from Resize()
|
||||||
Window &operator<<(Color color);
|
/// @param width new window's width
|
||||||
|
/// @param height new window's height
|
||||||
/// Applies format flag to window. Note that these attributes are
|
/// @see Resize()
|
||||||
/// also stacked, so if you applied fmtBold twice, to get rid of
|
///
|
||||||
/// it you have to pass fmtBoldEnd also twice.
|
void AdjustDimensions(size_t width, size_t height);
|
||||||
/// @param format format flag
|
|
||||||
/// @return reference to itself
|
/// Deletes old window and creates new. It's called by Resize(),
|
||||||
///
|
/// SetBorder() or SetTitle() since internally windows are
|
||||||
Window &operator<<(Format format);
|
/// handled as curses pads and change in size requires to delete
|
||||||
|
/// them and create again, there is no way to change size of pad.
|
||||||
/// Moves current cursor position to given coordinates.
|
/// @see SetBorder()
|
||||||
/// @param coords struct that holds information about new coordinations
|
/// @see SetTitle()
|
||||||
/// @return reference to itself
|
/// @see Resize()
|
||||||
///
|
///
|
||||||
Window &operator<<(XY coords);
|
virtual void Recreate(size_t width, size_t height);
|
||||||
|
|
||||||
/// Prints string to window
|
/// internal WINDOW pointers
|
||||||
/// @param s const pointer to char array to be printed
|
WINDOW *itsWindow;
|
||||||
/// @return reference to itself
|
WINDOW *itsWinBorder;
|
||||||
///
|
|
||||||
Window &operator<<(const char *s);
|
/// start points and dimensions
|
||||||
|
size_t itsStartX;
|
||||||
/// Prints single character to window
|
size_t itsStartY;
|
||||||
/// @param c character to be printed
|
size_t itsWidth;
|
||||||
/// @return reference to itself
|
size_t itsHeight;
|
||||||
///
|
|
||||||
Window &operator<<(char c);
|
/// window timeout
|
||||||
|
int itsWindowTimeout;
|
||||||
/// Prints wide string to window
|
|
||||||
/// @param ws const pointer to wchar_t array to be printed
|
/// current colors
|
||||||
/// @return reference to itself
|
Color itsColor;
|
||||||
///
|
Color itsBgColor;
|
||||||
Window &operator<<(const wchar_t *ws);
|
|
||||||
|
/// base colors
|
||||||
/// Prints single wide character to window
|
Color itsBaseColor;
|
||||||
/// @param wc wide character to be printed
|
Color itsBaseBgColor;
|
||||||
/// @return reference to itself
|
|
||||||
///
|
/// current border
|
||||||
Window &operator<<(wchar_t wc);
|
Border itsBorder;
|
||||||
|
|
||||||
/// Prints int to window
|
private:
|
||||||
/// @param i integer value to be printed
|
/// Sets state of bold attribute (internal use only)
|
||||||
/// @return reference to itself
|
/// @param bold_state state of bold attribute
|
||||||
///
|
///
|
||||||
Window &operator<<(int i);
|
void Bold(bool bold_state) const;
|
||||||
|
|
||||||
/// Prints double to window
|
/// Sets state of underline attribute (internal use only)
|
||||||
/// @param d double value to be printed
|
/// @param underline_state state of underline attribute
|
||||||
/// @return reference to itself
|
///
|
||||||
///
|
void Underline(bool underline_state) const;
|
||||||
Window &operator<<(double d);
|
|
||||||
|
/// Sets state of reverse attribute (internal use only)
|
||||||
/// Prints size_t to window
|
/// @param reverse_state state of reverse attribute
|
||||||
/// @param s size value to be printed
|
///
|
||||||
/// @return reference to itself
|
void Reverse(bool reverse_state) const;
|
||||||
///
|
|
||||||
Window &operator<<(size_t s);
|
/// Sets state of altcharset attribute (internal use only)
|
||||||
|
/// @param altcharset_state state of altcharset attribute
|
||||||
/// Prints std::string to window
|
///
|
||||||
/// @param s string to be printed
|
void AltCharset(bool altcharset_state) const;
|
||||||
/// @return reference to itself
|
|
||||||
///
|
/// pointer to helper function used by GetString()
|
||||||
Window &operator<<(const std::string &s);
|
/// @see GetString()
|
||||||
|
///
|
||||||
/// Prints std::wstring to window
|
GetStringHelper itsGetStringHelper;
|
||||||
/// @param ws wide string to be printed
|
|
||||||
/// @return reference to itself
|
/// window title
|
||||||
///
|
std::string itsTitle;
|
||||||
Window &operator<<(const std::wstring &ws);
|
|
||||||
|
/// stack of colors
|
||||||
/// Fallback for Length() for wide strings used if unicode support is disabled
|
std::stack<Colors> itsColors;
|
||||||
/// @param s string that real length has to be measured
|
|
||||||
/// @return standard std::string::length() result since it's only fallback
|
/// input queue of a window. you can put characters there using
|
||||||
///
|
/// PushChar and they will be immediately consumed and
|
||||||
static size_t Length(const std::string &s) { return s.length(); }
|
/// returned by ReadKey
|
||||||
|
std::queue<int> itsInputQueue;
|
||||||
/// Measures real length of wide string (required if e.g. asian characters are used)
|
|
||||||
/// @param ws wide string that real length has to be measured
|
/// containter used for additional file descriptors that have
|
||||||
/// @return real length of wide string
|
/// to be polled in ReadKey() and correspondent callbacks that
|
||||||
///
|
/// are invoked if there is data available in them
|
||||||
static size_t Length(const std::wstring &ws);
|
typedef std::vector< std::pair<int, void (*)()> > FDCallbacks;
|
||||||
|
FDCallbacks itsFDs;
|
||||||
/// Cuts string so it fits desired length on the screen. Note that it uses
|
|
||||||
/// wcwidth to check real width of all characters it contains. If string
|
/// pointer to container used as history
|
||||||
/// fits requested length it's not modified at all.
|
std::list<std::wstring> *itsHistory;
|
||||||
/// @param ws wide string to be cut
|
|
||||||
/// @param max_len maximal length of string
|
/// counters for format flags
|
||||||
static void Cut(std::wstring &ws, size_t max_len);
|
int itsBoldCounter;
|
||||||
|
int itsUnderlineCounter;
|
||||||
protected:
|
int itsReverseCounter;
|
||||||
/// Sets colors of window (interal use only)
|
int itsAltCharsetCounter;
|
||||||
/// @param fg foregound color
|
};
|
||||||
/// @param bg background color
|
|
||||||
///
|
|
||||||
void SetColor(Color fg, Color bg = clDefault);
|
|
||||||
|
|
||||||
/// Refreshes window's border
|
|
||||||
///
|
|
||||||
void ShowBorder() const;
|
|
||||||
|
|
||||||
/// Changes dimensions of window, called from Resize()
|
|
||||||
/// @param width new window's width
|
|
||||||
/// @param height new window's height
|
|
||||||
/// @see Resize()
|
|
||||||
///
|
|
||||||
void AdjustDimensions(size_t width, size_t height);
|
|
||||||
|
|
||||||
/// Deletes old window and creates new. It's called by Resize(),
|
|
||||||
/// SetBorder() or SetTitle() since internally windows are
|
|
||||||
/// handled as curses pads and change in size requires to delete
|
|
||||||
/// them and create again, there is no way to change size of pad.
|
|
||||||
/// @see SetBorder()
|
|
||||||
/// @see SetTitle()
|
|
||||||
/// @see Resize()
|
|
||||||
///
|
|
||||||
virtual void Recreate(size_t width, size_t height);
|
|
||||||
|
|
||||||
/// internal WINDOW pointers
|
|
||||||
WINDOW *itsWindow;
|
|
||||||
WINDOW *itsWinBorder;
|
|
||||||
|
|
||||||
/// start points and dimensions
|
|
||||||
size_t itsStartX;
|
|
||||||
size_t itsStartY;
|
|
||||||
size_t itsWidth;
|
|
||||||
size_t itsHeight;
|
|
||||||
|
|
||||||
/// window timeout
|
|
||||||
int itsWindowTimeout;
|
|
||||||
|
|
||||||
/// current colors
|
|
||||||
Color itsColor;
|
|
||||||
Color itsBgColor;
|
|
||||||
|
|
||||||
/// base colors
|
|
||||||
Color itsBaseColor;
|
|
||||||
Color itsBaseBgColor;
|
|
||||||
|
|
||||||
/// current border
|
|
||||||
Border itsBorder;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Sets state of bold attribute (internal use only)
|
|
||||||
/// @param bold_state state of bold attribute
|
|
||||||
///
|
|
||||||
void Bold(bool bold_state) const;
|
|
||||||
|
|
||||||
/// Sets state of underline attribute (internal use only)
|
|
||||||
/// @param underline_state state of underline attribute
|
|
||||||
///
|
|
||||||
void Underline(bool underline_state) const;
|
|
||||||
|
|
||||||
/// Sets state of reverse attribute (internal use only)
|
|
||||||
/// @param reverse_state state of reverse attribute
|
|
||||||
///
|
|
||||||
void Reverse(bool reverse_state) const;
|
|
||||||
|
|
||||||
/// Sets state of altcharset attribute (internal use only)
|
|
||||||
/// @param altcharset_state state of altcharset attribute
|
|
||||||
///
|
|
||||||
void AltCharset(bool altcharset_state) const;
|
|
||||||
|
|
||||||
/// pointer to helper function used by GetString()
|
|
||||||
/// @see GetString()
|
|
||||||
///
|
|
||||||
GetStringHelper itsGetStringHelper;
|
|
||||||
|
|
||||||
/// window title
|
|
||||||
std::string itsTitle;
|
|
||||||
|
|
||||||
/// stack of colors
|
|
||||||
std::stack<Colors> itsColors;
|
|
||||||
|
|
||||||
/// input queue of a window. you can put characters there using
|
|
||||||
/// PushChar and they will be immediately consumed and
|
|
||||||
/// returned by ReadKey
|
|
||||||
std::queue<int> itsInputQueue;
|
|
||||||
|
|
||||||
/// containter used for additional file descriptors that have
|
|
||||||
/// to be polled in ReadKey() and correspondent callbacks that
|
|
||||||
/// are invoked if there is data available in them
|
|
||||||
typedef std::vector< std::pair<int, void (*)()> > FDCallbacks;
|
|
||||||
FDCallbacks itsFDs;
|
|
||||||
|
|
||||||
/// pointer to container used as history
|
|
||||||
std::list<std::wstring> *itsHistory;
|
|
||||||
|
|
||||||
/// counters for format flags
|
|
||||||
int itsBoldCounter;
|
|
||||||
int itsUnderlineCounter;
|
|
||||||
int itsReverseCounter;
|
|
||||||
int itsAltCharsetCounter;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user