ScummVM API documentation
button_container.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_BUTTON_CONTAINER_H
23 #define MM1_VIEWS_ENH_BUTTON_CONTAINER_H
24 
25 #include "common/array.h"
26 #include "common/stack.h"
27 #include "common/rect.h"
28 #include "mm/shared/xeen/sprites.h"
29 #include "mm/mm1/views/text_view.h"
30 #include "mm/mm1/events.h"
31 #include "mm/mm1/metaengine.h"
32 
33 namespace MM {
34 namespace MM1 {
35 namespace ViewsEnh {
36 
37 class ButtonContainer;
38 
39 class UIButton {
40 public:
41  Common::Rect _bounds;
43  KeybindingAction _action;
44  uint _frameNum, _selectedFrame;
45  bool _draw;
46 
50  UIButton(ButtonContainer *owner, const Common::Rect &bounds,
51  KeybindingAction action, uint frameNum, Shared::Xeen::SpriteResource *sprites,
52  bool draw) :
53  _bounds(bounds), _action(action), _frameNum(frameNum),
54  _selectedFrame(frameNum | 1), _sprites(sprites), _draw(draw) {
55  }
56 
60  UIButton() : _action(KEYBIND_NONE), _frameNum(0), _selectedFrame(0),
61  _sprites(nullptr), _draw(false) {
62  }
63 
67  void setFrame(uint frameNum) {
68  _frameNum = frameNum;
69  _selectedFrame = frameNum | 1;
70  }
71 
75  void setFrame(uint frameNum, uint selectedFrame) {
76  _frameNum = frameNum;
77  _selectedFrame = selectedFrame;
78  }
79 
83  void draw(bool pressed = false);
84 };
85 
87 private:
89  KeybindingAction _selectedAction = KEYBIND_NONE;
90 protected:
91  Common::Array<UIButton> _buttons;
92 
93  bool doScroll(bool fadeIn);
94 public:
95  ButtonContainer(const Common::String &name, UIElement *owner);
96 
100  void saveButtons();
101 
102  void clearButtons();
103 
104  void restoreButtons();
105 
106  void addButton(const Common::Rect &bounds, KeybindingAction action,
107  Shared::Xeen::SpriteResource *sprites = nullptr);
108  void addButton(const Common::Rect &bounds, KeybindingAction action,
109  int frameNum, Shared::Xeen::SpriteResource *sprites = nullptr);
110 
111  void draw() override;
112  bool msgMouseDown(const MouseDownMessage &msg) override;
113  bool msgMouseUp(const MouseUpMessage &msg) override;
114 };
115 
116 } // namespace ViewsEnh
117 } // namespace MM1
118 } // namespace MM
119 
120 #endif
void setFrame(uint frameNum, uint selectedFrame)
Definition: button_container.h:75
Definition: str.h:59
Definition: array.h:52
Definition: messages.h:79
UIButton()
Definition: button_container.h:60
void draw(bool pressed=false)
Definition: sprites.h:52
Definition: rect.h:144
Definition: text_view.h:35
Definition: messages.h:72
Definition: detection.h:27
void setFrame(uint frameNum)
Definition: button_container.h:67
UIButton(ButtonContainer *owner, const Common::Rect &bounds, KeybindingAction action, uint frameNum, Shared::Xeen::SpriteResource *sprites, bool draw)
Definition: button_container.h:50
Definition: button_container.h:39
Definition: events.h:68
Definition: button_container.h:86
Definition: stack.h:102