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 
27 namespace MM {
28 namespace MM1 {
29 namespace ViewsEnh {
30 
31 #define FRAME_BORDER_SIZE 8
32 #define GLYPH_W 24
33 #define GLYPH_H 20
34 
35 class ScrollView : public TextView {
36  struct Button {
38  Common::Rect _bounds;
39  int _frame = -1;
40  Common::KeyState _key;
41  KeybindingAction _action = KEYBIND_NONE;
42  bool _enabled = true;
43  bool _halfSize = false;
44 
45  Button(Shared::Xeen::SpriteResource *sprites,
46  const Common::Point &pos, int frame,
47  const Common::KeyState &key, bool halfSize = false) :
48  _sprites(sprites), _frame(frame), _key(key), _halfSize(halfSize),
49  _bounds(Common::Rect(pos.x, pos.y,
50  pos.x + (halfSize ? GLYPH_W / 2 : GLYPH_W),
51  pos.y + (halfSize ? GLYPH_H / 2 : GLYPH_H))
52  ) {
53  }
54  Button(Shared::Xeen::SpriteResource *sprites,
55  const Common::Point &pos, int frame,
56  KeybindingAction action, bool halfSize = false) :
57  _sprites(sprites), _frame(frame), _action(action), _halfSize(halfSize),
58  _bounds(Common::Rect(pos.x, pos.y,
59  pos.x + (halfSize ? GLYPH_W / 2 : GLYPH_W),
60  pos.y + (halfSize ? GLYPH_H / 2 : GLYPH_H))
61  ) {
62  }
63  Button(const Common::Rect &r, const Common::KeyState &key) :
64  _sprites(nullptr), _bounds(r), _key(key) {
65  }
66  Button(const Common::Rect &r, const KeybindingAction action) :
67  _sprites(nullptr), _bounds(r), _action(action) {
68  }
69  };
70 private:
71  Common::Array<Button> _buttons;
72  int _selectedButton = -1;
73 protected:
74  Common::Point _symbolPos;
75 protected:
79  void frame();
80 
84  void fill();
85 
89  void writeSymbol(int symbolId);
90 
94  int getButtonAt(const Common::Point &pos);
95 
99  size_t getButtonCount() const {
100  return _buttons.size();
101  }
102 
106  void drawButtons();
107 
108 public:
109  ScrollView(const Common::String &name);
110  ScrollView(const Common::String &name, UIElement *owner);
111  virtual ~ScrollView() {}
112 
116  void clearButtons() {
117  _buttons.clear();
118  }
119 
124  const Common::Point &pos, int frame,
125  const Common::KeyState &key, bool halfSize = false);
126 
131  const Common::Point &pos, int frame, KeybindingAction action,
132  bool halfSize = false);
133 
137  int addButton(const Common::Rect &r, const Common::KeyState &key);
138 
142  int addButton(const Common::Rect &r, KeybindingAction action);
143 
147  void setButtonEnabled(int buttonNum, bool enabled) {
148  _buttons[buttonNum]._enabled = enabled;
149  }
150 
154  bool isButtonEnabled(int buttonNum) const {
155  return _buttons[buttonNum]._enabled;
156  }
157 
161  void setButtonPos(int buttonNum, const Common::Point &pos) {
162  _buttons[buttonNum]._bounds.moveTo(pos);
163  }
164 
168  void removeButtons(int start, int end = -2);
169 
173  void resetSelectedButton();
174 
178  void draw() override;
179 
183  bool msgFocus(const FocusMessage &msg) override;
184 
188  bool msgMouseDown(const MouseDownMessage &msg) override;
189 
193  bool msgMouseUp(const MouseUpMessage &msg) override;
194 };
195 
196 } // namespace ViewsEnh
197 } // namespace MM1
198 } // namespace MM
199 
200 #endif
Definition: str.h:59
void clearButtons()
Definition: scroll_view.h:116
int addButton(Shared::Xeen::SpriteResource *sprites, const Common::Point &pos, int frame, const Common::KeyState &key, bool halfSize=false)
Definition: messages.h:79
void setButtonEnabled(int buttonNum, bool enabled)
Definition: scroll_view.h:147
void clear()
Definition: array.h:320
void writeSymbol(int symbolId)
bool msgFocus(const FocusMessage &msg) override
Definition: sprites.h:52
Definition: rect.h:144
void removeButtons(int start, int end=-2)
Definition: scroll_view.h:35
bool msgMouseUp(const MouseUpMessage &msg) override
Definition: messages.h:72
int getButtonAt(const Common::Point &pos)
bool msgMouseDown(const MouseDownMessage &msg) override
Definition: detection.h:27
Definition: rect.h:45
Definition: text_view.h:33
size_type size() const
Definition: array.h:315
int16 x
Definition: rect.h:46
void setButtonPos(int buttonNum, const Common::Point &pos)
Definition: scroll_view.h:161
int16 y
Definition: rect.h:47
Definition: keyboard.h:294
Definition: events.h:68
bool isButtonEnabled(int buttonNum) const
Definition: scroll_view.h:154
size_t getButtonCount() const
Definition: scroll_view.h:99
Definition: messages.h:41