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