1 #include <Interface/Menu/Menu.hpp> 2 #include <Misc/Utils.hpp> 3 #include <Config/Globals.hpp> 4 #include <Flow/InputManager.hpp> 18 for (
unsigned int i = 0; i < (this->
item.size()); i++)
19 SAFE_DELETE(this->
item[i]);
25 this->item.push_back(item);
28 if (this->item.size() == 1)
30 this->
current = this->item.back();
36 for (i = 0; i < (this->item.size()); i++)
45 this->item.push_back(NULL);
49 std::vector<MenuItem*>::iterator it = this->item.begin();
51 while (it != this->item.end())
73 std::vector<MenuItem*>::iterator it = this->item.begin();
75 while (it != this->item.end())
80 if ((*it)->label == label)
102 unsigned int draw_begin = 0;
103 unsigned int draw_end = this->item.size();
105 if (this->height < (
int)this->item.size())
109 draw_end = this->height - 1;
111 else if ((
int)this->
currentIndex < ((int)this->item.size() - this->height/2) - 1)
118 draw_begin = this->item.size() - this->height;
123 for (
unsigned int curitem = draw_begin, yoffset = 0;
125 curitem++, yoffset++)
129 if ((curitem == draw_begin) && (curitem != 0))
131 window->
print(
"(more)",
132 this->x + this->width/2 - 3,
134 Colors::pair(COLOR_WHITE, COLOR_DEFAULT));
139 if ((curitem == draw_end - 1) && (curitem != this->item.size() - 1))
141 window->
print(
"(more)",
142 this->x + this->width/2 - 3,
143 this->y + yoffset + 1,
144 Colors::pair(COLOR_WHITE, COLOR_DEFAULT));
160 if (! this->item[curitem])
162 for (
int j = 0; j < (this->width); j++)
163 window->
printChar(((Globals::Screen::fancy_borders) ?
168 Colors::pair(COLOR_WHITE, COLOR_DEFAULT));
172 this->item[curitem]->
draw(window,
179 (this->item[curitem] == this->
current));
185 if (InputManager::noKeyPressed())
188 if (InputManager::isPressed(
"down") ||
189 InputManager::isPressed(KEY_DOWN) ||
190 InputManager::isPressed(
'\t'))
193 else if (InputManager::isPressed(
"up") ||
194 InputManager::isPressed(KEY_UP) ||
195 InputManager::isPressed(KEY_BTAB))
198 else if (InputManager::isPressed(KEY_HOME) ||
199 InputManager::isPressed(KEY_PPAGE))
202 else if (InputManager::isPressed(KEY_END) ||
203 InputManager::isPressed(KEY_NPAGE))
206 else if (InputManager::isPressed(KEY_ENTER) ||
207 InputManager::isPressed(
'\n'))
212 this->current->type == MenuItem::LABEL)
229 if (this->item.size() == 0)
233 if (this->item.size() == 1)
235 this->
current = *(this->item.begin());
243 if (this->
current == this->item.back())
261 if (this->item.size() == 0)
264 if (this->item.size() == 1)
266 this->
current = this->item.front();
271 if (this->
current == this->item.front())
288 if (this->item.size() == 0)
291 if (this->item.size() == 1)
293 this->
current = this->item.front();
298 this->
current = this->item.front();
306 if (this->item.size() == 0)
309 if (this->item.size() == 1)
311 this->
current = this->item.front();
316 this->
current = this->item.back();
322 void Menu::goRandom()
324 if (this->item.size() == 0)
352 for (
unsigned int i = 0; i < (this->item.size()); i++)
357 if (this->item[i]->
id ==
id)
361 if (this->item[i]->type != MenuItem::CHECKBOX)
367 return c->isChecked();
374 for (
unsigned int i = 0; i < (this->item.size()); i++)
379 if (this->item[i]->
id ==
id)
383 if (this->item[i]->type != MenuItem::NUMBERBOX)
396 for (
unsigned int i = 0; i < (this->item.size()); i++)
401 if (this->item[i]->
id ==
id)
405 if (this->item[i]->type == MenuItem::TEXTBOX)
408 return c->currentText;
410 else if (this->item[i]->type == MenuItem::TEXTLIST)
413 return c->currentText();
A segment of the terminal screen (2D char matrix).
int between(int min, int max)
Random number between min and max.
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.