ScummVM API documentation
gui_cheapo.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef M4_BURGER_GUI_CHEAPO_H
24 #define M4_BURGER_GUI_CHEAPO_H
25 
26 #include "common/str.h"
27 #include "m4/graphics/gr_buff.h"
28 #include "m4/m4_types.h"
29 
30 namespace M4 {
31 namespace Burger {
32 namespace GUI {
33 
34 constexpr int16 INVENTORY_CELLS_COUNT = 128;
35 constexpr int16 ARROW_WIDTH = 8;
36 constexpr int16 MAX_BUTTONS = 20;
37 constexpr int16 MAX_INVENTORY = 9;
38 
39 constexpr int16 LEFT_ARROW_TAG = 128;
40 constexpr int16 RIGHT_ARROW_TAG = 129;
41 
42 constexpr int16 LEFT_ARROW_TAG_DORMANT = 130;
43 constexpr int16 RIGHT_ARROW_TAG_DORMANT = 134;
44 constexpr int16 LEFT_ARROW_TAG_ROLL = 131;
45 constexpr int16 RIGHT_ARROW_TAG_ROLL = 135;
46 constexpr int16 LEFT_ARROW_TAG_DOWN = 132;
47 constexpr int16 RIGHT_ARROW_TAG_DOWN = 136;
48 constexpr int16 LEFT_ARROW_TAG_NONFUNC = 133;
49 constexpr int16 RIGHT_ARROW_TAG_NONFUNC = 137;
50 
51 enum ControlStatus {
52  NOTHING, IN_CONTROL, OVER_CONTROL, SELECTED, TRACKING
53 };
54 
55 enum ButtonState {
56  BUTTON_0, BUTTON_RELAXED, BUTTON_OVER, BUTTON_PICKED
57 };
58 
59 class RectClass;
60 class ButtonClass;
61 class InterfaceBox;
62 class Inventory;
63 
64 class RectClass {
65 public:
66  int16 _x1 = 0, _x2 = 0, _y1 = 0, _y2 = 0;
67 public:
68  RectClass();
69  RectClass(int16 x1, int16 y1, int16 x2, int16 y2);
70  RectClass(const RectClass *);
71  virtual ~RectClass();
72  virtual int16 inside(int16 x, int16 y) const;
73 
74  void copyInto(RectClass *r) const;
75 
76  void set(int16 x1, int16 y1, int16 x2, int16 y2);
77  void set(const RectClass *r);
78 };
79 
80 class TextField : public RectClass {
81 private:
82  char *_string = nullptr;
83  int16 _string_len = 0;
84 public:
85  bool _must_redraw = false;
86 
87 public:
88  TextField(int16 x1, int16 y1, int16 x2, int16 y2);
89  ~TextField();
90 
91  void set_string(const char *string);
92  void draw(GrBuff *interface_buffer);
93 };
94 
95 class ButtonClass : public RectClass {
96 protected:
97  int16 _tag = 0;
98  int16 _unknown = 0;
99  int16 _relaxed = 0;
100  int16 _over = 0;
101  int16 _picked = 0;
102  int16 _tracking = 0;
103  int32 _sprite = 0;
104  bool _highlighted = false;
105  bool _hidden = false;
106 
107  void init();
108  void zap_resources();
109 
110 public:
111  ButtonState _state = BUTTON_RELAXED;
112  Common::String _name;
113  bool _must_redraw = false;
114 
115 public:
116  ButtonClass();
117  ButtonClass(const RectClass &r, const Common::String &btnName, int16 tag);
118  ButtonClass(const RectClass &r, const Common::String &btnName, int16 tag,
119  int16 unknown, int16 relaxed, int16 over, int16 picked, int sprite);
120  ~ButtonClass();
121 
122  void draw(GrBuff *interface_buffer);
123  int16 inside(int16 x, int16 y) const override;
124  virtual ControlStatus track(int32 eventType, int16 x, int16 y);
125 
126  void set(const ButtonClass *b);
127  void set(int16 x1, int16 y1, int16 x2, int16 y2, int16 tag);
128  void set(int16 x1, int16 y1, int16 x2, int16 y2, int16 tag, int16 unknown,
129  int16 relaxed, int16 over, int16 picked, int32 sprite);
130  void set_name(const Common::String &btnName);
131 
132  int16 get_tag() const;
133 
134  void hide();
135  void unhide();
136  bool is_hidden() const;
137  void set_sprite_relaxed(int16 r);
138  void set_sprite_picked(int16 p);
139  void set_sprite_over(int16 o);
140  void set_sprite_unknown(int16 val);
141 };
142 
143 class Toggler : public ButtonClass {
144 public:
145  ControlStatus _toggle_state;
146 public:
147  Toggler();
148  ControlStatus track(int32 eventType, int16 x, int16 y);
149 };
150 
151 class InterfaceBox : public RectClass {
152 private:
153  bool _selected = false;
154  int16 _index = 0;
155  ButtonClass *_button[MAX_BUTTONS] = { nullptr };
156 
157 public:
158  int16 _highlight_index = 0;
159  bool _must_redraw_all = false;
160 
161 public:
162  InterfaceBox(const RectClass &r);
163  ~InterfaceBox();
164 
165  void draw(GrBuff *interface_buffer);
166  int16 inside(int16 x, int16 y) const override;
167  ControlStatus track(int32 eventType, int16 x, int16 y);
168 
169  void add(ButtonClass *b);
170  int16 check_inventory(int16 x, int16 y);
171  void highlight_button(int16 index);
172  void set_selected(bool);
173 
174 };
175 
176 class Inventory : public RectClass {
177  struct Entry {
178  Common::String _name;
179  Common::String _verb;
180  int16 _cell = -1;
181  int16 _cursor = -1;
182  };
183 private:
184  int32 _sprite = 0;
185  int16 _tag = 0;
186  int16 _num_cells = 0;
187  bool _right_arrow_visible = false;
188 
189  int16 cell_pos_x(int16 index);
190  int16 cell_pos_y(int16 index);
191  int16 interface_tracking = -1;
192 
193 public:
194  int16 _scroll = 0;
195  int16 _cells_h = 0, _cells_v = 0;
196  int16 _cell_w = 0, _cell_h = 0;
197  int16 _must_redraw1 = 0, _must_redraw2 = 0;
198  int16 _highlight = 0;
199  bool _must_redraw_all = false;
200 
201  Entry _items[INVENTORY_CELLS_COUNT];
202 
203 public:
204  Inventory(const RectClass &r, int32 sprite, int16 cells_h, int16 cells_v, int16 cell_w, int16 cell_h, int16 tag);
205  ~Inventory();
206 
207  void draw(GrBuff *interface_buffer);
208 
209  int16 inside(int16 x, int16 y) const override;
210  ControlStatus track(int32 eventType, int16 x, int16 y);
211 
212  bool add(const Common::String &name, const Common::String &verb, int32 cel, int32 cursor);
213  bool remove(const Common::String &name);
214  void highlight_part(int16 index);
215 
216  bool need_left() const;
217  bool need_right() const;
218  void set_scroll(int32 new_scroll);
219 };
220 
221 } // namespace GUI
222 } // namespace Burger
223 } // namespace M4
224 
225 #endif
Definition: str.h:59
Definition: system.h:46
Definition: gui_cheapo.h:176
Definition: gui_cheapo.h:64
Definition: database.h:28
Definition: gr_buff.h:30
Definition: gui_cheapo.h:151
Definition: gui_cheapo.h:80
Definition: gui_cheapo.h:143
Definition: gui_cheapo.h:95