1 #include <Interface/Window.hpp> 8 #define mvwhline my_mvwhline 17 void my_mvwhline(WINDOW* win,
int y,
int x, chtype ch,
int num)
20 for (i = 0; i < num; i++)
21 mvwaddch(win, y, (x + i), ch);
24 Window::Window(
int x,
int y,
int w,
int h):
31 borderType(BORDER_NONE),
37 this->win = newwin(height, width, y, x);
42 Window::Window(
Window* parent,
int x,
int y,
int width,
int height):
45 borderType(BORDER_NONE),
55 if (parent->borderType == BORDER_NONE)
57 if (width == 0) width = parent->width;
58 if (height == 0) height = parent->height;
66 if (width == 0) width = parent->width - 2;
67 if (height == 0) height = parent->height - 2;
73 this->height = height;
75 this->win = derwin(parent->
win, height, width, y, x);
84 bool Window::isValid()
86 return !(this->error);
88 void Window::resize(
int w,
int h)
90 wresize(this->win, h, w);
96 Colors::pairActivate(this->win, pair);
98 mvwaddstr(this->win, y, x, str.c_str());
100 void Window::print(std::vector<std::string> lines,
int x,
int y, ColorPair pair)
102 for (
size_t i = 0; i < lines.size(); i++)
103 this->print(lines[i], x, y + i, pair);
107 Colors::pairActivate(this->win, pair);
109 mvwaddch(this->win, y, x, c);
111 void Window::setBackground(chtype ch, ColorPair pair)
113 wbkgd(this->win, ch | pair);
115 void Window::refresh()
126 wnoutrefresh(this->win);
133 if (this->borderType != BORDER_NONE)
134 this->borders(this->borderType);
137 if (! this->topLeftTitle.empty())
139 this->print(this->topLeftTitle,
141 Colors::pair(COLOR_BLUE, COLOR_DEFAULT));
143 if (! this->bottomLeftTitle.empty())
145 this->print(this->bottomLeftTitle,
147 Colors::pair(COLOR_BLUE, COLOR_DEFAULT));
149 if (! this->topRightTitle.empty())
151 int x = (this->getW() - 1);
152 int w = this->topRightTitle.size();
154 this->print(this->topRightTitle,
156 Colors::pair(COLOR_BLUE, COLOR_DEFAULT));
158 if (! this->bottomRightTitle.empty())
160 int x = (this->getW() - 1);
161 int w = this->bottomRightTitle.size();
163 this->print(this->bottomRightTitle,
164 x - w, this->getH() - 1,
165 Colors::pair(COLOR_BLUE, COLOR_DEFAULT));
168 int Window::getW()
const 172 int Window::getH()
const 176 int Window::getX()
const 180 int Window::getY()
const 184 void Window::borders(BorderType type)
186 this->borderType = type;
188 if (type == Window::BORDER_NONE)
191 if (type == Window::BORDER_FANCY)
194 ACS_VLINE | Colors::pair(COLOR_WHITE, COLOR_DEFAULT),
195 ACS_VLINE | Colors::pair(COLOR_BLACK, COLOR_DEFAULT,
true),
196 ACS_HLINE | Colors::pair(COLOR_WHITE, COLOR_DEFAULT),
197 ACS_HLINE | Colors::pair(COLOR_BLACK, COLOR_DEFAULT,
true),
198 ACS_ULCORNER | Colors::pair(COLOR_WHITE, COLOR_DEFAULT,
true),
199 ACS_URCORNER | Colors::pair(COLOR_WHITE, COLOR_DEFAULT),
200 ACS_LLCORNER | Colors::pair(COLOR_WHITE, COLOR_DEFAULT),
201 ACS_LRCORNER | Colors::pair(COLOR_BLACK, COLOR_DEFAULT,
true));
203 else if (type == Window::BORDER_REGULAR)
205 wattrset(this->win, Colors::pair(COLOR_BLACK, COLOR_DEFAULT,
true));
206 wborder(this->win,
'|',
'|',
'-',
'-',
'+',
'+',
'+',
'+');
209 void Window::horizontalLine(
int x,
int y,
int c,
int width, ColorPair pair)
211 Colors::pairActivate(this->win, pair);
212 mvwhline(this->win, y, x, c, width);
218 case TOP_LEFT: this->topLeftTitle = title;
break;
219 case TOP_RIGHT: this->topRightTitle = title;
break;
220 case BOTTOM_LEFT: this->bottomLeftTitle = title;
break;
221 case BOTTOM_RIGHT: this->bottomRightTitle = title;
break;
WINDOW * win
Ncurses' internal data structure.
A segment of the terminal screen (2D char matrix).
void setTitle(std::string title, WindowTitlePosition position=Window::TOP_LEFT)
Sets a text that will appear at the top of the Window.
void printChar(int c, int x, int y, ColorPair pair=0)
Shows #c at #x #y with color #pair.
void print(std::string str, int x, int y, ColorPair pair=0)
Shows text #str at #x #y on the window with color #pair.