243 lines
7.1 KiB
C
Raw Normal View History

/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef GUI_WIDGETS_GRID_H
#define GUI_WIDGETS_GRID_H
#include "gui/dialog.h"
2021-06-21 17:03:38 +05:30
#include "gui/widgets/scrollbar.h"
#include "common/str.h"
#include "image/bmp.h"
#include "image/png.h"
#include "graphics/svg.h"
using Common::String;
using Common::U32String;
using Common::Array;
typedef Array<String> StringArray;
namespace GUI {
class ScrollBarWidget;
class GridItemWidget;
class GridWidget;
2021-06-26 17:21:58 +05:30
const Graphics::ManagedSurface *scaleGfx(const Graphics::ManagedSurface *gfx, int w, int h);
Graphics::ManagedSurface *loadSurfaceFromFile(const Common::String &name);
enum {
kPlayButtonCmd = 'PLAY',
kEditButtonCmd = 'EDIT',
kLoadButtonCmd = 'LOAD',
kOpenTrayCmd = 'OPTR',
kItemClicked = 'LBX1',
2021-07-08 16:03:17 +05:30
kItemDoubleClickedCmd = 'LBX2'
};
/* GridItemInfo */
2021-07-08 16:03:17 +05:30
struct GridItemInfo {
2021-07-29 22:59:27 +05:30
bool isHeader;
int entryID;
String engineid;
String gameid;
String title;
String thumbPath;
2021-07-30 20:30:50 +05:30
// Generic attribute value, may be any piece of metadata
String attribute;
Common::Language language;
Common::Platform platform;
Common::Rect rect;
GridItemInfo(int id, const String &eid, const String &gid
,const String &t, Common::Language l, Common::Platform p)
2021-07-29 22:59:27 +05:30
: entryID(id), gameid(gid), engineid(eid), title(t), language(l), platform(p), isHeader(false) {
thumbPath = String::format("%s-%s.png", engineid.c_str(), gameid.c_str());
2021-07-30 20:30:50 +05:30
// TEST: Remove assignment from here
attribute = title.firstChar();
}
2021-07-29 22:59:27 +05:30
GridItemInfo(const String &groupHeader, int groupID) : title(groupHeader), isHeader(true), entryID(groupID) {
thumbPath = String("");
}
};
/* GridItemTray */
class GridItemTray: public Dialog, public CommandSender {
2021-08-01 16:48:17 +05:30
int _entryID;
GridWidget *_grid;
GuiObject *_boss;
PicButtonWidget *_playButton;
PicButtonWidget *_loadButton;
PicButtonWidget *_editButton;
public:
GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid);
2021-07-14 18:27:51 +05:30
void reflowLayout();
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
2021-06-23 16:19:02 +05:30
void handleMouseDown(int x, int y, int button, int clickCount) override;
void handleMouseWheel(int x, int y, int direction) override;
void handleMouseMoved(int x, int y, int button) override;
};
/* GridWidget */
class GridWidget : public ContainerWidget, public CommandSender {
protected:
Common::HashMap<int, const Graphics::ManagedSurface *> _platformIcons;
Common::HashMap<int, const Graphics::ManagedSurface *> _languageIcons;
2021-07-14 18:27:51 +05:30
// Images are mapped by filename -> surface.
Common::HashMap<String, const Graphics::ManagedSurface *> _loadedSurfaces;
2021-08-01 16:48:17 +05:30
Common::Array<GridItemInfo> _dataEntryList;
Common::Array<GridItemInfo> _sortedEntryList;
Common::Array<GridItemInfo *> _visibleEntryList;
2021-07-30 20:30:50 +05:30
String _groupingAttribute;
Common::HashMap<U32String, int> _groupValueIndex;
Common::Array<bool> _groupExpanded;
U32String _groupHeaderPrefix;
U32String _groupHeaderSuffix;
Common::Array<U32String> _groupHeaders;
Common::StringMap _metadataNames;
2021-08-01 21:40:42 +05:30
Common::HashMap<int, Common::Array<int> > _itemsInGroup;
2021-07-30 20:30:50 +05:30
2021-08-01 16:48:17 +05:30
Common::Array<GridItemWidget *> _gridItems;
2021-07-30 20:30:50 +05:30
ScrollBarWidget *_scrollBar;
2021-08-01 16:48:17 +05:30
int _scrollBarWidth;
int _scrollWindowHeight;
int _scrollWindowWidth;
int _scrollSpeed;
int _scrollPos;
int _innerHeight;
int _innerWidth;
int _thumbnailHeight;
int _thumbnailWidth;
int _minGridXSpacing;
int _minGridYSpacing;
int _rows;
int _itemsPerRow;
int _firstVisibleItem;
int _lastVisibleItem;
2021-08-01 16:48:17 +05:30
GridItemTray *_tray;
String _iconDir;
bool _isGridInvalid;
public:
2021-08-03 21:35:22 +05:30
int _scrollWindowPaddingX;
int _scrollWindowPaddingY;
int _gridItemHeight;
int _gridItemWidth;
int _gridHeaderHeight;
2021-08-01 16:48:17 +05:30
int _gridHeaderWidth;
int _gridXSpacing;
int _gridYSpacing;
int _trayHeight;
2021-07-14 18:27:51 +05:30
2021-08-01 16:48:17 +05:30
bool _isTitlesVisible;
GridItemInfo *_selectedEntry;
2021-07-14 18:27:51 +05:30
GridWidget(GuiObject *boss, const String &name);
2021-06-26 17:21:58 +05:30
~GridWidget();
const Graphics::ManagedSurface *filenameToSurface(const String &name);
const Graphics::ManagedSurface *languageToSurface(Common::Language languageCode);
const Graphics::ManagedSurface *platformToSurface(Common::Platform platformCode);
/// Update _visibleEntries from _allEntries and returns true if reload is required.
bool calcVisibleEntries();
void setEntryList(Common::Array<GridItemInfo> *list);
2021-07-30 20:30:50 +05:30
void setAttributeValues(const Common::Array<U32String> &attrs);
void setMetadataNames(const Common::StringMap &metadata);
void setTitlesVisible(bool vis);
void markGridAsInvalid() { _isGridInvalid = true; }
void setGroupHeaderFormat(const U32String &prefix, const U32String &suffix);
2021-07-14 18:27:51 +05:30
2021-07-30 20:30:50 +05:30
void groupEntries();
void sortGroups();
bool groupExpanded(int groupID) { return _groupExpanded[groupID]; }
void toggleGroup(int groupID);
void reloadThumbnails();
void loadFlagIcons();
void loadPlatformIcons();
2021-07-14 18:27:51 +05:30
void destroyItems();
void calcInnerHeight();
void calcEntrySizes();
void updateGrid();
void move(int x, int y);
void scrollToEntry(int id, bool forceToTop);
void assignEntriesToItems();
int getScrollPos() const { return _scrollPos; }
int getSelected() const { return ((_selectedEntry == nullptr) ? -1 : _selectedEntry->entryID); }
int getThumbnailHeight() const { return _thumbnailHeight; }
int getThumbnailWidth() const { return _thumbnailWidth; }
void handleMouseWheel(int x, int y, int direction) override;
2021-06-21 17:03:38 +05:30
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
2021-07-14 18:27:51 +05:30
void reflowLayout() override;
2021-07-14 18:27:51 +05:30
void openTray(int x, int y, int entryID);
void openTrayAtSelected();
2021-06-21 17:03:38 +05:30
void scrollBarRecalc();
};
/* GridItemWidget */
class GridItemWidget : public ContainerWidget, public CommandSender {
protected:
Graphics::ManagedSurface _thumbGfx;
2021-08-01 16:48:17 +05:30
GridItemInfo *_activeEntry;
GridWidget *_grid;
bool _isHighlighted;
public:
GridItemWidget(GridWidget *boss);
void move(int x, int y);
void update();
void updateThumb();
void setActiveEntry(GridItemInfo &entry);
void drawWidget() override;
void handleMouseWheel(int x, int y, int direction) override;
void handleMouseEntered(int button) override;
void handleMouseLeft(int button) override;
void handleMouseDown(int x, int y, int button, int clickCount) override;
void handleMouseMoved(int x, int y, int button) override;
};
} // End of namespace GUI
#endif