1#include <Interface/Menu/MenuItemNumberbox.hpp>
2#include <Config/Globals.hpp>
3#include <Misc/Utils.hpp>
4#include <Misc/Timer.hpp>
5#include <Flow/InputManager.hpp>
15 this->
type = MenuItem::NUMBERBOX;
19 std::string number = Utils::String::toString(this->current);
29 (width - number.size() - 5),
32 int rightmost = x + width;
34 window->
print(((hilite)?
37 rightmost - number.size() - 2,
40 Globals::Theme::hilite_text:
41 Globals::Theme::text));
43 window->
print(((hilite)?
49 Globals::Theme::hilite_text:
50 Globals::Theme::text));
53 rightmost - number.size() - 1,
55 Globals::Theme::hilite_text);
59 if (InputManager::noKeyPressed())
69 static Timer lastKeyTimer;
70 static int lastKeyDelay = 500;
71 static bool firstDigit =
false;
72 static bool secondDigit =
false;
73 static bool thirdDigit =
false;
75 int input = InputManager::pressedKey;
78 if (input >=
'0' && input <=
'9')
82 this->set(input -
'0');
88 if (lastKeyTimer.
delta_ms() < lastKeyDelay)
92 this->set(this->current * 10 + (input -
'0'));
99 this->set(this->current * 10 + (input -
'0'));
101 lastKeyTimer.
start();
108 this->set(input -
'0');
112 lastKeyTimer.
start();
119 if (InputManager::isPressed(
"left") ||
120 InputManager::isPressed(KEY_LEFT))
123 else if (InputManager::isPressed(
"right") ||
124 InputManager::isPressed(KEY_RIGHT))
127 else if (InputManager::isPressed(
'r') ||
128 InputManager::isPressed(
'R') ||
129 InputManager::isPressed(
' ') ||
130 InputManager::isPressed(
'\n') ||
131 InputManager::isPressed(KEY_ENTER))
134void MenuItemNumberbox::set(
int value)
136 this->current = value;
139void MenuItemNumberbox::increase()
141 this->current += this->jump;
144void MenuItemNumberbox::decrease()
146 this->current -= this->jump;
149void MenuItemNumberbox::reset()
151 this->current = this->initial;
153void MenuItemNumberbox::cap()
155 if (this->current > this->max)
156 this->current = this->max;
158 if (this->current < this->min)
159 this->current = this->min;
void start()
Sets a starting point for the timer.
suseconds_t delta_ms()
Returns the milisseconds part of the timer's difference.
A segment of the terminal screen (2D char matrix).
void print(std::string str, int x, int y, ColorPair pair=0)
Shows text #str at x y on the window with color #pair.