ScummVM API documentation
tab.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 GUI_WIDGETS_TAB_H
23 #define GUI_WIDGETS_TAB_H
24 
25 #include "gui/widget.h"
26 #include "common/str.h"
27 #include "common/array.h"
28 
29 namespace GUI {
30 
31 enum {
32  kTabForwards = 1,
33  kTabBackwards = -1
34 };
35 
36 class TabWidget : public Widget {
37  struct Tab {
38  Common::U32String title;
39  Common::String dialogName;
40  Widget *firstWidget;
41  int _tabWidth;
42  };
44 
45 protected:
46  int _activeTab;
47  int _firstVisibleTab;
48  int _lastVisibleTab;
49  TabList _tabs;
50  int _tabHeight;
51  int _minTabWidth;
52  int _titleSpacing;
53 
55 
56  int _bodyRP, _bodyTP, _bodyLP, _bodyBP;
57  ThemeEngine::DialogBackground _bodyBackgroundType;
58 
59  int _titleVPad;
60 
61  int _butRP, _butTP, _butW, _butH;
62 
63  ButtonWidget *_navLeft, *_navRight;
64  bool _navButtonsVisible;
65  int _lastRead;
66 
67  void recalc();
68 
69 public:
70  TabWidget(GuiObject *boss, int x, int y, int w, int h, ThemeEngine::TextAlignVertical alignV = ThemeEngine::kTextAlignVTop);
71  TabWidget(GuiObject *boss, const Common::String &name, ThemeEngine::TextAlignVertical alignV = ThemeEngine::kTextAlignVTop);
72  ~TabWidget() override;
73 
74  void init();
75 
80  int addTab(const Common::U32String &title, const Common::String &dialogName);
81 
91  void removeTab(int tabID);
92 
93  int getActiveTab() {
94  return _activeTab;
95  }
96 
102  void setActiveTab(int tabID);
103 
104  void setTabTitle(int tabID, const Common::U32String &title) {
105  assert(0 <= tabID && tabID < (int)_tabs.size());
106  _tabs[tabID].title = title;
107  }
108 
109  void handleMouseDown(int x, int y, int button, int clickCount) override;
110  void handleMouseMoved(int x, int y, int button) override;
111  void handleMouseLeft(int button) override { _lastRead = -1; };
112  bool handleKeyDown(Common::KeyState state) override;
113  void handleMouseWheel(int x, int y, int direction) override;
114  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
115  virtual int getFirstVisible() const;
116  virtual void setFirstVisible(int tabID, bool adjustIfRoom = false);
117 
118  bool containsWidget(Widget *) const override;
119 
120  void reflowLayout() override;
121 
122  void draw() override;
123  void markAsDirty() override;
124 
125 protected:
126  // We overload getChildY to make sure child widgets are positioned correctly.
127  // Essentially this compensates for the space taken up by the tab title header.
128  int16 getChildY() const override;
129  uint16 getHeight() const override;
130 
131  void drawWidget() override;
132 
133  Widget *findWidget(int x, int y) override;
134 
135  virtual void adjustTabs(int value);
136 
137  virtual void computeLastVisibleTab(bool adjustFirstIfRoom);
138 };
139 
140 } // End of namespace GUI
141 
142 #endif
Definition: str.h:59
TextAlignVertical
Vertical alignment of the text.
Definition: ThemeEngine.h:218
void setActiveTab(int tabID)
Definition: system.h:46
Definition: object.h:60
void draw() override
Definition: ustr.h:57
DialogBackground
Dialog background type.
Definition: ThemeEngine.h:239
void markAsDirty() override
int addTab(const Common::U32String &title, const Common::String &dialogName)
size_type size() const
Definition: array.h:315
Definition: widget.h:101
Definition: keyboard.h:294
Definition: tab.h:36
void removeTab(int tabID)
Definition: widget.h:233
Definition: object.h:40