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_GUI_CHEAPO_H
24 #define M4_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 GUI {
32 
33 constexpr int16 MAX_BUTTONS = 20;
34 
35 enum ControlStatus {
36  NOTHING, IN_CONTROL, OVER_CONTROL, SELECTED, TRACKING
37 };
38 
39 enum ButtonState {
40  BUTTON_0, BUTTON_RELAXED, BUTTON_OVER, BUTTON_PICKED
41 };
42 
43 class RectClass;
44 class ButtonClass;
45 class InterfaceBox;
46 
47 class RectClass {
48 public:
49  int16 _x1 = 0, _x2 = 0, _y1 = 0, _y2 = 0;
50 public:
51  RectClass();
52  RectClass(int16 x1, int16 y1, int16 x2, int16 y2);
53  RectClass(const RectClass *);
54  virtual ~RectClass();
55  virtual int16 inside(int16 x, int16 y) const;
56 
57  void copyInto(RectClass *r) const;
58 
59  void set(int16 x1, int16 y1, int16 x2, int16 y2);
60  void set(const RectClass *r);
61 };
62 
63 class TextField : public RectClass {
64 private:
65  char *_string = nullptr;
66  int16 _string_len = 0;
67 public:
68  bool _must_redraw = false;
69 
70 public:
71  TextField(int16 x1, int16 y1, int16 x2, int16 y2);
72  ~TextField();
73 
74  void set_string(const char *string);
75  void draw(GrBuff *interface_buffer);
76 };
77 
78 class ButtonClass : public RectClass {
79 protected:
80  int16 _tag = 0;
81  int16 _unknown = 0;
82  int16 _relaxed = 0;
83  int16 _over = 0;
84  int16 _picked = 0;
85  int16 _tracking = 0;
86  int32 _sprite = 0;
87  bool _highlighted = false;
88  bool _hidden = false;
89 
90  void init();
91  void zap_resources();
92 
93 public:
94  ButtonState _state = BUTTON_RELAXED;
95  Common::String _name;
96  bool _must_redraw = false;
97 
98 public:
99  ButtonClass();
100  ButtonClass(const RectClass &r, const Common::String &btnName, int16 tag);
101  ButtonClass(const RectClass &r, const Common::String &btnName, int16 tag,
102  int16 unknown, int16 relaxed, int16 over, int16 picked, int sprite);
103  ButtonClass(const RectClass &r, const Common::String &btnName, int16 tag,
104  int16 relaxed, int16 over, int16 picked, int sprite);
105  ~ButtonClass();
106 
107  void draw(GrBuff *interface_buffer);
108  int16 inside(int16 x, int16 y) const override;
109  virtual ControlStatus track(int32 eventType, int16 x, int16 y);
110 
111  void set(const ButtonClass *b);
112  void set(int16 x1, int16 y1, int16 x2, int16 y2, int16 tag);
113  void set(int16 x1, int16 y1, int16 x2, int16 y2, int16 tag, int16 unknown,
114  int16 relaxed, int16 over, int16 picked, int32 sprite);
115  void set_name(const Common::String &btnName);
116 
117  int16 get_tag() const;
118 
119  void hide();
120  void unhide();
121  bool is_hidden() const;
122  void set_sprite_relaxed(int16 r);
123  void set_sprite_picked(int16 p);
124  void set_sprite_over(int16 o);
125  void set_sprite_unknown(int16 val);
126 };
127 
128 class Toggler : public ButtonClass {
129 public:
130  ControlStatus _toggle_state;
131 public:
132  Toggler();
133  ControlStatus track(int32 eventType, int16 x, int16 y);
134 };
135 
136 class InterfaceBox : public RectClass {
137 private:
138  bool _selected = false;
139  int16 _index = 0;
140  ButtonClass *_button[MAX_BUTTONS] = { nullptr };
141 
142 public:
143  int16 _highlight_index = 0;
144  bool _must_redraw_all = false;
145 
146 public:
147  InterfaceBox(const RectClass &r);
148  ~InterfaceBox();
149 
150  void draw(GrBuff *interface_buffer);
151  int16 inside(int16 x, int16 y) const override;
152  ControlStatus track(int32 eventType, int16 x, int16 y);
153 
154  void add(ButtonClass *b);
155  int16 check_inventory(int16 x, int16 y);
156  void highlight_button(int16 index);
157  void set_selected(bool);
158 
159 };
160 
161 } // namespace GUI
162 } // namespace M4
163 
164 #endif
Definition: str.h:59
Definition: gui_cheapo.h:63
Definition: gui_cheapo.h:47
Definition: gui_cheapo.h:128
Definition: gui_cheapo.h:136
Definition: system.h:46
Definition: database.h:28
Definition: gr_buff.h:30
Definition: gui_cheapo.h:78