ScummVM API documentation
grid.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_GRID_H
23 #define GUI_WIDGETS_GRID_H
24 
25 #include "gui/dialog.h"
26 #include "gui/widgets/scrollbar.h"
27 #include "common/str.h"
28 
29 #include "image/bmp.h"
30 #include "image/png.h"
31 #include "graphics/svg.h"
32 
33 namespace GUI {
34 
35 class ScrollBarWidget;
36 class GridItemWidget;
37 class GridWidget;
38 
39 enum {
40  kPlayButtonCmd = 'PLAY',
41  kEditButtonCmd = 'EDIT',
42  kLoadButtonCmd = 'LOAD',
43  kOpenTrayCmd = 'OPTR',
44  kItemClicked = 'LBX1',
45  kItemDoubleClickedCmd = 'LBX2',
46  kItemSizeCmd = 'SIZE'
47 };
48 
49 /* GridItemInfo */
50 struct GridItemInfo {
51  bool isHeader, validEntry;
52  int entryID;
53  Common::String engineid;
54  Common::String gameid;
55  Common::String title;
56  Common::String description;
57  Common::String extra;
58  Common::String thumbPath;
59  // Generic attribute value, may be any piece of metadata
60  Common::String attribute;
61  Common::Language language;
62  Common::Platform platform;
63 
64  int32 x, y, w, h;
65 
66  GridItemInfo(int id, const Common::String &eid, const Common::String &gid, const Common::String &t,
67  const Common::String &d, const Common::String &e, Common::Language l, Common::Platform p, bool v)
68  : entryID(id), gameid(gid), engineid(eid), title(t), description(d), extra(e), language(l), platform(p), validEntry(v), isHeader(false) {
69  thumbPath = Common::String::format("icons/%s-%s.png", engineid.c_str(), gameid.c_str());
70  }
71 
72  GridItemInfo(const Common::String &groupHeader, int groupID) : title(groupHeader), description(groupHeader),
73  isHeader(true), validEntry(true), entryID(groupID), language(Common::UNK_LANG), platform(Common::kPlatformUnknown) {
74  thumbPath = Common::String("");
75  }
76 };
77 
78 /* GridItemTray */
79 class GridItemTray: public Dialog, public CommandSender {
80  int _entryID;
81  GridWidget *_grid;
82  GuiObject *_boss;
83  PicButtonWidget *_playButton;
84  PicButtonWidget *_loadButton;
85  PicButtonWidget *_editButton;
86 public:
87  GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid);
88 
89  void reflowLayout() override;
90 
91  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
92  void handleMouseDown(int x, int y, int button, int clickCount) override;
93  void handleMouseUp(int x, int y, int button, int clickCount) override;
94  void handleMouseWheel(int x, int y, int direction) override;
95  void handleMouseMoved(int x, int y, int button) override;
96 };
97 
98 
99 /* GridWidget */
100 class GridWidget : public ContainerWidget, public CommandSender {
101 protected:
105  Common::HashMap<int, Graphics::AlphaType> _platformIconsAlpha;
106  Common::HashMap<int, Graphics::AlphaType> _languageIconsAlpha;
108  Graphics::ManagedSurface *_disabledIconOverlay;
109  // Images are mapped by filename -> surface.
111 
112  Common::Array<GridItemInfo> _dataEntryList;
113  Common::Array<GridItemInfo> _headerEntryList;
114  Common::Array<GridItemInfo *> _sortedEntryList;
115  Common::Array<GridItemInfo *> _visibleEntryList;
116 
117  Common::String _groupingAttribute;
119  Common::Array<bool> _groupExpanded;
120  Common::U32String _groupHeaderPrefix;
121  Common::U32String _groupHeaderSuffix;
122  Common::Array<Common::U32String> _groupHeaders;
123  Common::StringMap _metadataNames;
125 
127 
128  ScrollBarWidget *_scrollBar;
129 
130  int _scrollBarWidth;
131  int _scrollWindowHeight;
132  int _scrollWindowWidth;
133  int _scrollSpeed;
134  int _scrollPos;
135  int _innerHeight;
136  int _innerWidth;
137  int _thumbnailHeight;
138  int _thumbnailWidth;
139  int _flagIconHeight;
140  int _flagIconWidth;
141  int _platformIconHeight;
142  int _platformIconWidth;
143  int _extraIconHeight;
144  int _extraIconWidth;
145  int _minGridXSpacing;
146  int _minGridYSpacing;
147  int _rows;
148  int _itemsPerRow;
149  int _firstVisibleItem;
150  int _lastVisibleItem;
151  bool _isGridInvalid;
152 
153  int _scrollWindowPaddingX;
154  int _scrollWindowPaddingY;
155  int _gridHeaderHeight;
156  int _gridHeaderWidth;
157  int _trayHeight;
158 
159 public:
160  int _gridItemHeight;
161  int _gridItemWidth;
162  int _gridXSpacing;
163  int _gridYSpacing;
164  int _thumbnailMargin;
165 
166  bool _isTitlesVisible;
167 
168  GridItemInfo *_selectedEntry;
169 
170  Common::U32String _filter;
171 
172  GridWidget(GuiObject *boss, const Common::String &name);
173  ~GridWidget();
174 
175  template<typename T>
176  void unloadSurfaces(Common::HashMap<T, const Graphics::ManagedSurface *> &surfaces);
177 
178  const Graphics::ManagedSurface *filenameToSurface(const Common::String &name);
179  const Graphics::ManagedSurface *languageToSurface(Common::Language languageCode, Graphics::AlphaType &alphaType);
180  const Graphics::ManagedSurface *platformToSurface(Common::Platform platformCode, Graphics::AlphaType &alphaType);
181  const Graphics::ManagedSurface *demoToSurface(const Common::String extraString, Graphics::AlphaType &alphaType);
182  const Graphics::ManagedSurface *disabledThumbnail();
183 
185  bool calcVisibleEntries();
186  void setEntryList(Common::Array<GridItemInfo> *list);
187  void setAttributeValues(const Common::Array<Common::U32String> &attrs);
188  void setMetadataNames(const Common::StringMap &metadata);
189  void setTitlesVisible(bool vis);
190  void markGridAsInvalid() { _isGridInvalid = true; }
191  void setGroupHeaderFormat(const Common::U32String &prefix, const Common::U32String &suffix);
192 
193  void groupEntries();
194  void sortGroups();
195  bool groupExpanded(int groupID) { return _groupExpanded[groupID]; }
196  void toggleGroup(int groupID);
197  void loadClosedGroups(const Common::U32String &groupName);
198  void saveClosedGroups(const Common::U32String &groupName);
199 
200  void reloadThumbnails();
201  void loadFlagIcons();
202  void loadPlatformIcons();
203  void loadExtraIcons();
204 
205  void destroyItems();
206  void calcInnerHeight();
207  void calcEntrySizes();
208  void updateGrid();
209  void move(int x, int y);
210  void scrollToEntry(int id, bool forceToTop);
211  void assignEntriesToItems();
212 
213  int getNextPos(int oldSel);
214  int getNewSel(int index);
215  int getScrollPos() const { return _scrollPos; }
216  int getSelected() const { return ((_selectedEntry == nullptr) ? -1 : _selectedEntry->entryID); }
217  int getThumbnailHeight() const { return _thumbnailHeight; }
218  int getThumbnailWidth() const { return _thumbnailWidth; }
219 
220  void handleMouseWheel(int x, int y, int direction) override;
221  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
222  void reflowLayout() override;
223 
224  bool wantsFocus() override { return true; }
225 
226  void openTray(int x, int y, int entryID);
227  void openTrayAtSelected();
228  void scrollBarRecalc();
229 
230  void setSelected(int id);
231  void setFilter(const Common::U32String &filter);
232 };
233 
234 /* GridItemWidget */
236 protected:
237  Graphics::ManagedSurface _thumbGfx;
238  Graphics::AlphaType _thumbAlpha;
239 
240  GridItemInfo *_activeEntry;
241  GridWidget *_grid;
242  bool _isHighlighted;
243 
244 public:
245  GridItemWidget(GridWidget *boss);
246 
247  void move(int x, int y);
248  void update();
249  void updateThumb();
250  void setActiveEntry(GridItemInfo &entry);
251 
252  void drawWidget() override;
253 
254  void handleMouseWheel(int x, int y, int direction) override;
255  void handleMouseEntered(int button) override;
256  void handleMouseLeft(int button) override;
257  void handleMouseDown(int x, int y, int button, int clickCount) override;
258  void handleMouseMoved(int x, int y, int button) override;
259 };
260 
261 } // End of namespace GUI
262 
263 #endif
Definition: managed_surface.h:51
Definition: grid.h:50
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: grid.h:235
Definition: array.h:52
Definition: grid.h:100
Definition: widget.h:306
Definition: scrollbar.h:34
Definition: system.h:46
Definition: object.h:60
Definition: grid.h:79
Definition: hashmap.h:85
Definition: ustr.h:57
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
Definition: dialog.h:49
Definition: widget.h:514
Definition: object.h:40
Platform
Definition: platform.h:46
Language
Definition: language.h:45