ScummVM API documentation
scroll_view.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 MM1_VIEWS_ENH_SCROLL_VIEW_H
23#define MM1_VIEWS_ENH_SCROLL_VIEW_H
24
25#include "mm/mm1/views_enh/text_view.h"
26
27namespace MM {
28namespace MM1 {
29namespace ViewsEnh {
30
31#define FRAME_BORDER_SIZE 8
32#define GLYPH_W 24
33#define GLYPH_H 20
34
35#ifdef MM1_NEW_GFX
36constexpr int SCROLL_BG_COLOR = 0;
37#else
38constexpr int SCROLL_BG_COLOR = 153;
39#endif
40
41class ScrollView : public TextView {
42 struct Button {
44 Common::Rect _bounds;
45 int _frame = -1;
47 KeybindingAction _action = KEYBIND_NONE;
48 bool _enabled = true;
49 bool _halfSize = false;
50
51 Button(Shared::Xeen::SpriteResource *sprites,
52 const Common::Point &pos, int frame,
53 const Common::KeyState &key, bool halfSize = false) :
54 _sprites(sprites), _frame(frame), _key(key), _halfSize(halfSize),
55 _bounds(Common::Rect(pos.x, pos.y,
56 pos.x + (halfSize ? GLYPH_W / 2 : GLYPH_W),
57 pos.y + (halfSize ? GLYPH_H / 2 : GLYPH_H))
58 ) {
59 }
60 Button(Shared::Xeen::SpriteResource *sprites,
61 const Common::Point &pos, int frame,
62 KeybindingAction action, bool halfSize = false) :
63 _sprites(sprites), _frame(frame), _action(action), _halfSize(halfSize),
64 _bounds(Common::Rect(pos.x, pos.y,
65 pos.x + (halfSize ? GLYPH_W / 2 : GLYPH_W),
66 pos.y + (halfSize ? GLYPH_H / 2 : GLYPH_H))
67 ) {
68 }
69 Button(const Common::Rect &r, const Common::KeyState &key) :
70 _sprites(nullptr), _bounds(r), _key(key) {
71 }
72 Button(const Common::Rect &r, const KeybindingAction action) :
73 _sprites(nullptr), _bounds(r), _action(action) {
74 }
75 };
76private:
77 Common::Array<Button> _buttons;
78protected:
79 int _selectedButton = -1;
80 Common::Point _symbolPos;
81protected:
85 void frame();
86
90 void fill();
91
95 void writeSymbol(int symbolId);
96
100 int getButtonAt(const Common::Point &pos);
101
105 size_t getButtonCount() const {
106 return _buttons.size();
107 }
108
113
114public:
115 ScrollView(const Common::String &name);
116 ScrollView(const Common::String &name, UIElement *owner);
117 virtual ~ScrollView() {}
118
123 _buttons.clear();
124 }
125
130 const Common::Point &pos, int frame,
131 const Common::KeyState &key, bool halfSize = false);
132
137 const Common::Point &pos, int frame, KeybindingAction action,
138 bool halfSize = false);
139
143 int addButton(const Common::Rect &r, const Common::KeyState &key);
144
148 int addButton(const Common::Rect &r, KeybindingAction action);
149
153 void setButtonEnabled(int buttonNum, bool enabled) {
154 _buttons[buttonNum]._enabled = enabled;
155 }
156
160 bool isButtonEnabled(int buttonNum) const {
161 return _buttons[buttonNum]._enabled;
162 }
163
167 void setButtonPos(int buttonNum, const Common::Point &pos) {
168 _buttons[buttonNum]._bounds.moveTo(pos);
169 }
170
174 void removeButtons(int start, int end = -2);
175
180
184 void draw() override;
185
189 bool msgFocus(const FocusMessage &msg) override;
190
194 bool msgMouseDown(const MouseDownMessage &msg) override;
195
199 bool msgMouseUp(const MouseUpMessage &msg) override;
200};
201
202} // namespace ViewsEnh
203} // namespace MM1
204} // namespace MM
205
206#endif
size_type size() const
Definition: array.h:316
void clear()
Definition: array.h:321
Definition: str.h:59
Definition: events.h:68
Definition: scroll_view.h:41
bool msgMouseDown(const MouseDownMessage &msg) override
int addButton(const Common::Rect &r, KeybindingAction action)
int addButton(Shared::Xeen::SpriteResource *sprites, const Common::Point &pos, int frame, const Common::KeyState &key, bool halfSize=false)
bool msgFocus(const FocusMessage &msg) override
void writeSymbol(int symbolId)
bool isButtonEnabled(int buttonNum) const
Definition: scroll_view.h:160
void clearButtons()
Definition: scroll_view.h:122
bool msgMouseUp(const MouseUpMessage &msg) override
void removeButtons(int start, int end=-2)
int addButton(Shared::Xeen::SpriteResource *sprites, const Common::Point &pos, int frame, KeybindingAction action, bool halfSize=false)
int getButtonAt(const Common::Point &pos)
void setButtonPos(int buttonNum, const Common::Point &pos)
Definition: scroll_view.h:167
size_t getButtonCount() const
Definition: scroll_view.h:105
int addButton(const Common::Rect &r, const Common::KeyState &key)
void setButtonEnabled(int buttonNum, bool enabled)
Definition: scroll_view.h:153
Definition: text_view.h:42
Definition: sprites.h:52
Definition: detection.h:27
Definition: keyboard.h:294
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: rect.h:536
Definition: messages.h:41
Definition: messages.h:72
Definition: messages.h:79