ScummVM API documentation
menu_input.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef ULTIMA3_VIEWS_MENU_INPUT_H
23#define ULTIMA3_VIEWS_MENU_INPUT_H
24
25#include "common/keyboard.h"
26#include "common/str.h"
27#include "graphics/views/view.h"
28
29namespace Ultima {
30namespace Ultima3 {
31namespace Views {
32
33using namespace Graphics::Views;
34
35constexpr int GLYPH_UP_ARROW = 0x1E;
36
40bool isModifierKey(Common::KeyCode key);
41
46char commandKey(const KeypressMessage &msg);
47
54private:
55 const char *_keys = nullptr;
56 const char *const *_words = nullptr;
57 int _count = 0;
58 int _col = 0, _row = 0;
59 int _choice = -1;
60
61public:
66 void setup(const char *keys, const char *const *words, int count, int col, int row);
67
68 void reset() {
69 _choice = -1;
70 }
71
75 bool hasChoice() const {
76 return _choice >= 0;
77 }
78
82 const char *word() const {
83 return _words[_choice];
84 }
85
89 int index() const {
90 return _choice;
91 }
92
96 char key() const {
97 return _keys[_choice];
98 }
99
103 bool handleKey(const KeypressMessage &msg);
104
108 void draw(GfxSurface &s, bool active) const;
109};
110
115protected:
116 Common::String _text;
117 uint _maxLength = 0;
118 int _col = 0, _row = 0;
119
120public:
121 virtual ~LineInput() {}
122
123 void setup(uint maxLength, int col, int row);
124
125 void reset() {
126 _text.clear();
127 }
128
129 const Common::String &text() const {
130 return _text;
131 }
132
136 virtual bool handleKey(const KeypressMessage &msg);
137
138 void draw(GfxSurface &s, bool active) const;
139};
140
145class NumberInput : public LineInput {
146private:
147 byte _bcd = 0;
148 int _decimal = 0;
149
150public:
151 void setup(int col, int row) {
152 LineInput::setup(2, col, row);
153 }
154
155 bool handleKey(const KeypressMessage &msg) override;
156
157 byte bcd() const {
158 return _bcd;
159 }
160
161 int decimal() const {
162 return _decimal;
163 }
164};
165
166} // namespace Views
167} // namespace Ultima3
168} // namespace Ultima
169
170#endif
Definition: str.h:59
Definition: gfx_surface.h:34
Definition: menu_input.h:114
virtual bool handleKey(const KeypressMessage &msg)
Definition: menu_input.h:53
bool hasChoice() const
Definition: menu_input.h:75
void draw(GfxSurface &s, bool active) const
int index() const
Definition: menu_input.h:89
char key() const
Definition: menu_input.h:96
bool handleKey(const KeypressMessage &msg)
void setup(const char *keys, const char *const *words, int count, int col, int row)
const char * word() const
Definition: menu_input.h:82
Definition: menu_input.h:145
bool handleKey(const KeypressMessage &msg) override
Definition: messages.h:54