diff --git a/src/display/canvas.h b/src/display/canvas.h index 51c73f3fc..b5d7656a1 100644 --- a/src/display/canvas.h +++ b/src/display/canvas.h @@ -16,105 +16,26 @@ class Canvas { typedef std::unordered_map attributes_map; Canvas(int x = 0, int y = 0, int width = 0, int height = 0); - ~Canvas() { - if (!m_isDaemon) { - delwin(m_window); - } - } - - void refresh() { - if (!m_isDaemon) { - wnoutrefresh(m_window); - } - } - static void refresh_std() { - if (!m_isDaemon) { - wnoutrefresh(stdscr); - } - } - void redraw() { - if (!m_isDaemon) { - redrawwin(m_window); - } - } - static void redraw_std() { - if (!m_isDaemon) { - redrawwin(stdscr); - } - } - - void resize(int w, int h) { - if (!m_isDaemon) { - wresize(m_window, h, w); - } - } - void resize(int x, int y, int w, int h); - - static void resize_term(int x, int y) { - if (!m_isDaemon) { - resizeterm(y, x); - } - } - static void resize_term(std::pair dim) { - if (!m_isDaemon) { - resizeterm(dim.second, dim.first); - } - } - - unsigned int get_x() { - int x, __UNUSED y; - if (!m_isDaemon) { - getyx(m_window, y, x); - } else { - x = 1; - } - return x; - } - unsigned int get_y() { - int x, y; - if (!m_isDaemon) { - getyx(m_window, y, x); - } else { - y = 1; - } - return y; - } - - unsigned int width() { - int x, __UNUSED y; - if (!m_isDaemon) { - getmaxyx(m_window, y, x); - } else { - x = 80; - } - return x; - } - unsigned int height() { - int x, y; - if (!m_isDaemon) { - getmaxyx(m_window, y, x); - } else { - y = 24; - } - return y; - } - - void move(unsigned int x, unsigned int y) { - if (!m_isDaemon) { - wmove(m_window, y, x); - } - } - - void erase() { - if (!m_isDaemon) { - werase(m_window); - } - } - static void erase_std() { - if (!m_isDaemon) { - werase(stdscr); - } - } + ~Canvas(); + + void refresh(); + void redraw(); + void resize(int w, int h); + void resize(int x, int y, int w, int h); + + static void refresh_std(); + static void redraw_std(); + static void resize_term(int x, int y); + static void resize_term(std::pair dim); + + unsigned int get_x(); + unsigned int get_y(); + unsigned int width(); + unsigned int height(); + + void move(unsigned int x, unsigned int y); + void erase(); + static void erase_std(); // The format string is non-const, but that will not be a problem // since the string shall always be a C string choosen at @@ -122,72 +43,27 @@ class Canvas { void print(const char* str, ...); void print(unsigned int x, unsigned int y, const char* str, ...); - void print_attributes(unsigned int x, unsigned int y, const char* first, const char* last, const attributes_list* attributes); + void print_char(const chtype ch); + void print_char(unsigned int x, unsigned int y, const chtype ch); - void print_char(const chtype ch) { - if (!m_isDaemon) { - waddch(m_window, ch); - } - } - void print_char(unsigned int x, unsigned int y, const chtype ch) { - if (!m_isDaemon) { - mvwaddch(m_window, y, x, ch); - } - } - - void set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color) { - if (!m_isDaemon) { - mvwchgat(m_window, y, x, n, attr, color, NULL); - } - } - - void set_attr(unsigned int x, unsigned int y, unsigned int n, ColorKind k) { - if (!m_isDaemon) { - mvwchgat(m_window, y, x, n, m_attr_map[k], k, NULL); - } - } - - void set_default_attributes(int attr) { - if (!m_isDaemon) { - (void)wattrset(m_window, attr); - } - } + void set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color); + void set_attr(unsigned int x, unsigned int y, unsigned int n, ColorKind k); + void set_default_attributes(int attr); // Initialize stdscr. static void initialize(); static void build_colors(); static void cleanup(); - static int get_screen_width() { - int x, __UNUSED y; - if (!m_isDaemon) { - getmaxyx(stdscr, y, x); - } else { - x = 80; - } - return x; - } - static int get_screen_height() { - int x, y; - if (!m_isDaemon) { - getmaxyx(stdscr, y, x); - } else { - y = 24; - } - return y; - } + static int get_screen_width(); + static int get_screen_height(); static std::pair term_size(); - static void do_update() { - if (!m_isDaemon) { - doupdate(); - } - } + static void do_update(); static bool daemon() { return m_isDaemon; } - static const attributes_map& attr_map() { return m_attr_map; } private: @@ -203,6 +79,126 @@ class Canvas { WINDOW* m_window; }; +inline Canvas::~Canvas() { + if (!m_isDaemon) { + delwin(m_window); + } +} + +inline void +Canvas::refresh() { + if (!m_isDaemon) { + wnoutrefresh(m_window); + } +} + +inline void +Canvas::refresh_std() { + if (!m_isDaemon) { + wnoutrefresh(stdscr); + } +} + +inline void +Canvas::redraw() { + if (!m_isDaemon) { + redrawwin(m_window); + } +} + +inline void +Canvas::redraw_std() { + if (!m_isDaemon) { + redrawwin(stdscr); + } +} + +inline void +Canvas::resize(int w, int h) { + if (!m_isDaemon) { + wresize(m_window, h, w); + } +} + +inline void +Canvas::resize_term(int x, int y) { + if (!m_isDaemon) { + resizeterm(y, x); + } +} + +inline void +Canvas::resize_term(std::pair dim) { + if (!m_isDaemon) { + resizeterm(dim.second, dim.first); + } +} + +inline unsigned int +Canvas::get_x() { + int x, __UNUSED y; + if (!m_isDaemon) { + getyx(m_window, y, x); + } else { + x = 1; + } + return x; +} + +inline unsigned int +Canvas::get_y() { + int x, y; + if (!m_isDaemon) { + getyx(m_window, y, x); + } else { + y = 1; + } + return y; +} + +inline unsigned int +Canvas::width() { + int x, __UNUSED y; + if (!m_isDaemon) { + getmaxyx(m_window, y, x); + } else { + x = 80; + } + return x; +} + +inline unsigned int +Canvas::height() { + int x, y; + if (!m_isDaemon) { + getmaxyx(m_window, y, x); + } else { + y = 24; + } + return y; +} + +inline void +Canvas::move(unsigned int x, unsigned int y) { + if (!m_isDaemon) { + wmove(m_window, y, x); + } +} + +inline void +Canvas::erase() { + if (!m_isDaemon) { + werase(m_window); + } +} + +inline void +Canvas::erase_std() { + if (!m_isDaemon) { + werase(stdscr); + } +} + inline void Canvas::print(const char* str, ...) { va_list arglist; @@ -226,6 +222,70 @@ Canvas::print(unsigned int x, unsigned int y, const char* str, ...) { } } +inline void +Canvas::print_char(const chtype ch) { + if (!m_isDaemon) { + waddch(m_window, ch); + } +} + +inline void +Canvas::print_char(unsigned int x, unsigned int y, const chtype ch) { + if (!m_isDaemon) { + mvwaddch(m_window, y, x, ch); + } +} + +inline void +Canvas::set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color) { + if (!m_isDaemon) { + mvwchgat(m_window, y, x, n, attr, color, NULL); + } +} + +inline void +Canvas::set_attr(unsigned int x, unsigned int y, unsigned int n, ColorKind k) { + if (!m_isDaemon) { + mvwchgat(m_window, y, x, n, m_attr_map[k], k, NULL); + } +} + +inline void +Canvas::set_default_attributes(int attr) { + if (!m_isDaemon) { + (void)wattrset(m_window, attr); + } +} + +inline int +Canvas::get_screen_width() { + int x, __UNUSED y; + if (!m_isDaemon) { + getmaxyx(stdscr, y, x); + } else { + x = 80; + } + return x; +} + +inline int +Canvas::get_screen_height() { + int x, y; + if (!m_isDaemon) { + getmaxyx(stdscr, y, x); + } else { + y = 24; + } + return y; +} + +inline void +Canvas::do_update() { + if (!m_isDaemon) { + doupdate(); + } +} + } // namespace display #endif