2021-06-12 15:59:42 +05:30
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/system.h"
|
2021-06-26 17:20:15 +05:30
|
|
|
#include "common/file.h"
|
2021-06-26 21:05:21 +05:30
|
|
|
#include "common/language.h"
|
2021-06-26 17:20:15 +05:30
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
#include "gui/gui-manager.h"
|
|
|
|
#include "gui/widgets/grid.h"
|
|
|
|
|
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
GridItemWidget::GridItemWidget(GridWidget *boss, int x, int y, int w, int h)
|
2021-06-23 01:22:18 +05:30
|
|
|
: ContainerWidget(boss, x, y, w, h), CommandSender(boss) {
|
2021-06-22 17:30:20 +05:30
|
|
|
|
2021-06-18 15:54:33 +05:30
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG);
|
2021-06-12 15:59:42 +05:30
|
|
|
_activeEntry = nullptr;
|
|
|
|
_grid = boss;
|
2021-06-18 15:54:33 +05:30
|
|
|
isHighlighted = false;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-23 01:22:18 +05:30
|
|
|
GridItemWidget::GridItemWidget(GridWidget *boss)
|
|
|
|
: GridItemWidget(boss, 0, 0, 0, 0) {}
|
2021-06-12 15:59:42 +05:30
|
|
|
|
|
|
|
void GridItemWidget::setActiveEntry(GridItemInfo &entry) {
|
|
|
|
_activeEntry = &entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridItemWidget::updateThumb() {
|
|
|
|
const Graphics::ManagedSurface *gfx = _grid->filenameToSurface(_activeEntry->thumbPath);
|
2021-06-15 18:11:31 +05:30
|
|
|
_thumbGfx.free();
|
|
|
|
if (gfx)
|
|
|
|
_thumbGfx.copyFrom(*gfx);
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void GridItemWidget::update() {
|
2021-06-22 17:30:20 +05:30
|
|
|
if (_activeEntry) {
|
|
|
|
updateThumb();
|
|
|
|
markAsDirty();
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-22 17:30:20 +05:30
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridItemWidget::move(int x, int y) {
|
|
|
|
Widget::setPos(getRelX() + x, getRelY() + y);
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void GridItemWidget::drawWidget() {
|
2021-06-22 17:30:20 +05:30
|
|
|
int thumbHeight = _grid->getThumbnailHeight();
|
|
|
|
int thumbWidth = _grid->getThumbnailWidth();
|
|
|
|
|
|
|
|
if (isHighlighted) {
|
|
|
|
// Draw a highlighted BG on hover
|
2021-06-26 17:30:23 +05:30
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x - (_grid->_gridXSpacing / 3), _y - (_grid->_gridYSpacing / 3),
|
|
|
|
_x + _w + (_grid->_gridXSpacing / 3), _y + _h + (_grid->_gridYSpacing / 3)),
|
2021-06-18 15:54:33 +05:30
|
|
|
ThemeEngine::WidgetBackground::kGridItemHighlight);
|
2021-06-22 17:30:20 +05:30
|
|
|
} else {
|
|
|
|
// Draw a BG of the same color as grid area
|
|
|
|
// when it is not highlighted to cover up
|
|
|
|
// the highlight shadow
|
|
|
|
// FIXME: Find a way to redraw the area around the widget
|
|
|
|
// instead of just drawing a cover-up
|
2021-06-26 17:30:23 +05:30
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x - 2 * (_grid->_gridXSpacing / 3), _y - 2 * (_grid->_gridYSpacing / 3),
|
|
|
|
_x + _w + 2 * (_grid->_gridXSpacing / 3), _y + _h + 2 * (_grid->_gridYSpacing / 3)),
|
2021-06-18 15:54:33 +05:30
|
|
|
ThemeEngine::WidgetBackground::kGridItemBackground);
|
2021-06-22 17:30:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Draw Thumbnail Background
|
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _grid->getThumbnailWidth(), _y + thumbHeight),
|
2021-06-15 18:11:31 +05:30
|
|
|
ThemeEngine::WidgetBackground::kThumbnailBackground);
|
2021-06-19 19:37:51 +05:30
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
// Draw Thumbnail
|
2021-06-26 18:37:30 +05:30
|
|
|
if (_thumbGfx.empty()) {
|
|
|
|
// Draw Title when thumbnail is missing
|
|
|
|
g_gui.theme()->drawText(Common::Rect(_x, _y, _x + thumbWidth, _y + thumbHeight),
|
|
|
|
_activeEntry->title, GUI::ThemeEngine::kStateEnabled ,Graphics::kTextAlignCenter,
|
|
|
|
ThemeEngine::kTextInversion, 0, true, ThemeEngine::kFontStyleBold,
|
|
|
|
ThemeEngine::kFontColorAlternate, false);
|
|
|
|
}
|
|
|
|
else g_gui.theme()->drawSurface(Common::Point(_x, _y), _thumbGfx, true);
|
2021-06-15 18:11:31 +05:30
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
// Draw Platform Icon
|
2021-06-15 18:11:31 +05:30
|
|
|
if (_activeEntry->platform != kPlatformUnknown) {
|
|
|
|
const Graphics::ManagedSurface *platGfx = _grid->platformToSurface(_activeEntry->platform);
|
2021-06-22 17:30:20 +05:30
|
|
|
g_gui.theme()->drawSurface(Common::Point(_x + thumbWidth - 32, _y + thumbHeight - 32),
|
2021-06-15 18:11:31 +05:30
|
|
|
*platGfx, true);
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
// Draw Flag
|
2021-06-17 15:25:49 +05:30
|
|
|
const Graphics::ManagedSurface *flagGfx = _grid->languageToSurface(_activeEntry->language);
|
|
|
|
if (flagGfx)
|
2021-06-22 17:30:20 +05:30
|
|
|
g_gui.theme()->drawSurface(Common::Point(_x + thumbWidth - flagGfx -> w - 5, _y + 5),
|
2021-06-17 15:25:49 +05:30
|
|
|
*flagGfx, true);
|
2021-06-15 18:11:31 +05:30
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
// Draw Title
|
2021-06-26 21:06:34 +05:30
|
|
|
if (_grid->_isTitlesVisible)
|
|
|
|
g_gui.theme()->drawText(Common::Rect(_x, _y + thumbHeight, _x + thumbWidth, _y + thumbHeight + kLineHeight),
|
|
|
|
_activeEntry->title, GUI::ThemeEngine::kStateEnabled ,Graphics::kTextAlignLeft);
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-15 18:13:20 +05:30
|
|
|
void GridItemWidget::handleMouseWheel(int x, int y, int direction) {
|
|
|
|
_grid->handleMouseWheel(x, y, direction);
|
2021-06-26 17:34:37 +05:30
|
|
|
_grid->_selectedEntry = nullptr;
|
|
|
|
isHighlighted = false;
|
2021-06-15 18:13:20 +05:30
|
|
|
}
|
|
|
|
|
2021-06-18 15:54:33 +05:30
|
|
|
void GridItemWidget::handleMouseEntered(int button) {
|
|
|
|
if (!isHighlighted) {
|
2021-06-22 17:30:20 +05:30
|
|
|
_grid->_selectedEntry = _activeEntry;
|
2021-06-18 15:54:33 +05:30
|
|
|
isHighlighted = true;
|
|
|
|
markAsDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridItemWidget::handleMouseLeft(int button) {
|
|
|
|
if (isHighlighted) {
|
2021-06-22 17:30:20 +05:30
|
|
|
_grid->_selectedEntry = nullptr;
|
2021-06-18 15:54:33 +05:30
|
|
|
isHighlighted = false;
|
|
|
|
markAsDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-26 17:28:10 +05:30
|
|
|
void GridItemWidget::handleMouseMoved(int x, int y, int button) {
|
|
|
|
if (!isHighlighted) {
|
|
|
|
handleMouseEntered(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-19 19:37:51 +05:30
|
|
|
void GridItemWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
2021-06-28 18:13:24 +05:30
|
|
|
if (isHighlighted && isVisible()) {
|
2021-06-22 17:30:20 +05:30
|
|
|
// Work in progress
|
2021-06-28 19:25:50 +05:30
|
|
|
// Since user expected to click on "entry" and not the "widget", we
|
|
|
|
// must open the tray where the user expects it to be, which might
|
|
|
|
// not be at the new widget location.
|
|
|
|
int oldX = getAbsX(), oldY = getAbsY();
|
|
|
|
int offsetY = 0;
|
|
|
|
if (_y > (_grid->getHeight() - _h - _grid->_trayHeight)) {
|
|
|
|
offsetY = _y - (_grid->getHeight() - _h - _grid->_trayHeight);
|
|
|
|
sendCommand(kSetPositionCmd, _grid->getScrollPos() + offsetY);
|
|
|
|
_grid->markAsDirty();
|
|
|
|
_grid->draw();
|
|
|
|
}
|
|
|
|
_grid->openTray(oldX, oldY - offsetY + _h, _activeEntry->entryID);
|
2021-06-23 01:22:18 +05:30
|
|
|
_grid->_tray->runModal();
|
2021-06-19 19:37:51 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
#pragma mark -
|
|
|
|
|
2021-06-27 12:57:59 +05:30
|
|
|
GridItemTray::GridItemTray(GuiObject *boss, int x, int y, int w, int h, int entryID, GridWidget *grid)
|
2021-06-23 01:22:18 +05:30
|
|
|
: Dialog(x, y, w, h), CommandSender(boss) {
|
|
|
|
|
|
|
|
_entryID = entryID;
|
|
|
|
_boss = boss;
|
2021-06-27 12:57:59 +05:30
|
|
|
_grid = grid;
|
2021-06-23 01:22:18 +05:30
|
|
|
|
2021-06-23 16:19:02 +05:30
|
|
|
int buttonWidth = w / 3;
|
|
|
|
int buttonHeight = h / 3;
|
2021-06-23 01:22:18 +05:30
|
|
|
|
2021-06-23 16:19:02 +05:30
|
|
|
PicButtonWidget *playButton = new PicButtonWidget(this, (buttonWidth / 3), buttonHeight / 3, (buttonWidth / 3) + buttonWidth * 2, buttonHeight, U32String("Play"), kStartCmd);
|
|
|
|
PicButtonWidget *loadButton = new PicButtonWidget(this, (buttonWidth / 3), (buttonHeight * 5) / 3, buttonWidth, buttonHeight, U32String("Saves"), kLoadGameCmd);
|
|
|
|
PicButtonWidget *editButton = new PicButtonWidget(this, buttonWidth + 2 * (buttonWidth / 3), (buttonHeight * 5) / 3, buttonWidth, buttonHeight, U32String("Edit"), kEditGameCmd);
|
2021-06-23 01:22:18 +05:30
|
|
|
|
2021-06-26 18:02:06 +05:30
|
|
|
playButton->setGfxFromTheme("button_play.bmp", 0, false);
|
|
|
|
loadButton->setGfxFromTheme("button_load.bmp", 0, false);
|
|
|
|
editButton->setGfxFromTheme("button_options.bmp", 0, false);
|
2021-06-23 01:22:18 +05:30
|
|
|
}
|
|
|
|
|
2021-06-19 19:37:51 +05:30
|
|
|
void GridItemTray::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case kStartCmd:
|
2021-06-23 01:22:18 +05:30
|
|
|
close();
|
|
|
|
sendCommand(kStartCmd, _entryID);
|
|
|
|
break;
|
|
|
|
case kLoadGameCmd:
|
|
|
|
close();
|
|
|
|
sendCommand(kLoadGameCmd, _entryID);
|
|
|
|
break;
|
|
|
|
case kEditGameCmd:
|
|
|
|
close();
|
|
|
|
sendCommand(kEditGameCmd, _entryID);
|
|
|
|
break;
|
|
|
|
case kCloseCmd:
|
2021-06-19 19:37:51 +05:30
|
|
|
close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:19:02 +05:30
|
|
|
void GridItemTray::handleMouseDown(int x, int y, int button, int clickCount) {
|
|
|
|
Dialog::handleMouseDown(x, y, button, clickCount);
|
2021-06-27 12:57:59 +05:30
|
|
|
if ((x < 0 || x > _w) || (y > _h || y < -(_grid->_gridItemHeight))) {
|
2021-06-23 16:19:02 +05:30
|
|
|
// Close on clicking outside
|
|
|
|
close();
|
|
|
|
} else if (y < 0 && clickCount >= 2) {
|
|
|
|
// Run on double clicking thumbnail
|
|
|
|
close();
|
|
|
|
sendCommand(kStartCmd, _entryID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridItemTray::handleMouseWheel(int x, int y, int direction) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
#pragma mark -
|
|
|
|
|
2021-06-23 17:57:18 +05:30
|
|
|
Graphics::ManagedSurface *loadSurfaceFromFile(const Common::String &name) {
|
2021-06-12 15:59:42 +05:30
|
|
|
Graphics::ManagedSurface *surf = nullptr;
|
|
|
|
const Graphics::Surface *srcSurface = nullptr;
|
|
|
|
if (name.hasSuffix(".png")) {
|
|
|
|
#ifdef USE_PNG
|
|
|
|
Image::PNGDecoder decoder;
|
|
|
|
Common::FSNode fileNode(name);
|
2021-06-17 15:25:49 +05:30
|
|
|
Common::SeekableReadStream *stream = fileNode.createReadStream();
|
2021-06-12 15:59:42 +05:30
|
|
|
if (stream) {
|
|
|
|
if (!decoder.loadStream(*stream))
|
|
|
|
warning("Error decoding PNG");
|
|
|
|
|
|
|
|
srcSurface = decoder.getSurface();
|
|
|
|
delete stream;
|
|
|
|
if (!srcSurface) {
|
|
|
|
warning("Failed to load surface : %s", name.c_str());
|
|
|
|
}
|
|
|
|
if (srcSurface && srcSurface->format.bytesPerPixel != 1) {
|
|
|
|
surf = new Graphics::ManagedSurface(srcSurface->convertTo(g_system->getOverlayFormat()));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
warning("No such file : %s", name.c_str());
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
error("No PNG support compiled");
|
|
|
|
#endif
|
2021-06-22 17:30:20 +05:30
|
|
|
} else if (name.hasSuffix(".svg")) {
|
2021-06-17 15:25:49 +05:30
|
|
|
Graphics::SVGBitmap *image = nullptr;
|
|
|
|
Common::FSNode fileNode(name);
|
|
|
|
Common::SeekableReadStream *stream = fileNode.createReadStream();
|
|
|
|
if (stream) {
|
|
|
|
image = new Graphics::SVGBitmap(stream);
|
|
|
|
surf = new Graphics::ManagedSurface(60, 30, *image->getPixelFormat());
|
|
|
|
image->render(*surf, 60, 30);
|
|
|
|
delete image;
|
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
return surf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
GridWidget::GridWidget(GuiObject *boss, int x, int y, int w, int h)
|
|
|
|
: ContainerWidget(boss, x, y, w, h) {
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
loadPlatformIcons();
|
2021-06-17 15:25:49 +05:30
|
|
|
loadFlagIcons();
|
2021-06-22 17:30:20 +05:30
|
|
|
|
|
|
|
_thumbnailHeight = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Height");
|
|
|
|
_thumbnailWidth = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Width");
|
|
|
|
_minGridXSpacing = g_gui.xmlEval()->getVar("Globals.Grid.XSpacing");
|
|
|
|
_gridYSpacing = g_gui.xmlEval()->getVar("Globals.Grid.YSpacing");
|
|
|
|
|
|
|
|
_gridItemHeight = _thumbnailHeight + (2 * kLineHeight);
|
|
|
|
_gridItemWidth = _thumbnailWidth;
|
|
|
|
|
|
|
|
_scrollBar = new ScrollBarWidget(this, 0, 0, 20, 200);
|
|
|
|
_scrollBar->setTarget(this);
|
|
|
|
_scrollPos = 0;
|
|
|
|
_firstVisibleItem = 0;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
GridWidget::GridWidget(GuiObject *boss, const String &name)
|
|
|
|
: ContainerWidget(boss, name) {
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
loadPlatformIcons();
|
2021-06-17 15:25:49 +05:30
|
|
|
loadFlagIcons();
|
2021-06-22 17:30:20 +05:30
|
|
|
|
2021-06-14 13:20:54 +05:30
|
|
|
_thumbnailHeight = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Height");
|
|
|
|
_thumbnailWidth = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Width");
|
2021-06-15 15:45:56 +05:30
|
|
|
_minGridXSpacing = g_gui.xmlEval()->getVar("Globals.Grid.XSpacing");
|
2021-06-14 13:20:54 +05:30
|
|
|
_gridYSpacing = g_gui.xmlEval()->getVar("Globals.Grid.YSpacing");
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
_gridItemHeight = _thumbnailHeight + (2 * kLineHeight);
|
2021-06-14 13:20:54 +05:30
|
|
|
_gridItemWidth = _thumbnailWidth;
|
|
|
|
|
2021-06-21 17:03:38 +05:30
|
|
|
_scrollBar = new ScrollBarWidget(this, 0, 0, 20, 200);
|
|
|
|
_scrollBar->setTarget(this);
|
2021-06-22 17:30:20 +05:30
|
|
|
_scrollPos = 0;
|
2021-06-18 13:20:10 +05:30
|
|
|
_firstVisibleItem = 0;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-26 17:21:58 +05:30
|
|
|
GridWidget::~GridWidget() {
|
|
|
|
_platformIcons.clear();
|
|
|
|
_loadedSurfaces.clear();
|
|
|
|
_gridItems.clear();
|
|
|
|
_allEntries.clear();
|
|
|
|
_visibleEntries.clear();
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
const Graphics::ManagedSurface *GridWidget::filenameToSurface(const String &name) {
|
|
|
|
String path = String("./icons/")+name;
|
|
|
|
|
|
|
|
for (auto l = _visibleEntries.begin(); l!=_visibleEntries.end(); ++l) {
|
|
|
|
if (l->thumbPath == name) {
|
2021-06-26 18:37:30 +05:30
|
|
|
return _loadedSurfaces[path];
|
2021-06-22 17:30:20 +05:30
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-22 17:30:20 +05:30
|
|
|
return nullptr;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
const Graphics::ManagedSurface *GridWidget::languageToSurface(const String &lang) {
|
|
|
|
String path = String::format("./icons/%s.svg", lang.c_str());
|
|
|
|
return _loadedSurfaces[path];
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
const Graphics::ManagedSurface *GridWidget::platformToSurface(Platform platformCode) {
|
2021-06-26 21:05:21 +05:30
|
|
|
if ((platformCode == kPlatformUnknown) || (platformCode < 0 || platformCode >= (int)_platformIcons.size())) {
|
2021-06-22 17:30:20 +05:30
|
|
|
warning("Unknown Platform");
|
|
|
|
return nullptr;
|
2021-06-17 15:25:49 +05:30
|
|
|
}
|
2021-06-22 17:30:20 +05:30
|
|
|
return _platformIcons[platformCode];
|
2021-06-17 15:25:49 +05:30
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridWidget::setEntryList(Common::Array<GridItemInfo> *list) {
|
2021-06-26 17:57:52 +05:30
|
|
|
_allEntries.clear();
|
2021-06-22 17:30:20 +05:30
|
|
|
for (auto entryIter = list->begin(); entryIter != list->end(); ++entryIter) {
|
|
|
|
_allEntries.push_back(*entryIter);
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GridWidget::calcVisibleEntries() {
|
|
|
|
bool needsReload = false;
|
|
|
|
|
|
|
|
int nItemsOnScreen = 0;
|
|
|
|
|
2021-06-14 13:20:54 +05:30
|
|
|
nItemsOnScreen = (3 + (_scrollWindowHeight / (_gridItemHeight + _gridYSpacing))) * (_itemsPerRow);
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-18 13:20:10 +05:30
|
|
|
needsReload = true;
|
|
|
|
_itemsOnScreen = nItemsOnScreen;
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-27 13:44:51 +05:30
|
|
|
int toRender = MIN(_firstVisibleItem + _itemsOnScreen, (int)_allEntries.size());
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-18 13:20:10 +05:30
|
|
|
_visibleEntries.clear();
|
|
|
|
for (int ind = _firstVisibleItem; ind < toRender; ++ind) {
|
|
|
|
GridItemInfo *iter = _allEntries.begin() + ind;
|
|
|
|
_visibleEntries.push_back(*iter);
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
return needsReload;
|
|
|
|
}
|
|
|
|
|
2021-06-26 21:06:34 +05:30
|
|
|
void GridWidget::setTitlesVisible(bool vis) {
|
|
|
|
_isTitlesVisible = vis;
|
|
|
|
}
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
void GridWidget::reloadThumbnails() {
|
|
|
|
Graphics::ManagedSurface *surf = nullptr;
|
2021-06-22 17:30:20 +05:30
|
|
|
String gameid;
|
|
|
|
String engineid;
|
|
|
|
String path;
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
for (Common::Array<GridItemInfo>::iterator iter = _visibleEntries.begin(); iter != _visibleEntries.end(); ++iter) {
|
2021-06-22 17:30:20 +05:30
|
|
|
path = String("./icons/")+iter->thumbPath;
|
2021-06-12 15:59:42 +05:30
|
|
|
if (_loadedSurfaces.contains(path)) {
|
|
|
|
// warning("Thumbnail already loaded, skipping...");
|
2021-06-22 17:30:20 +05:30
|
|
|
} else {
|
2021-06-12 15:59:42 +05:30
|
|
|
surf = loadSurfaceFromFile(path);
|
|
|
|
if (surf) {
|
2021-06-22 17:30:20 +05:30
|
|
|
const Graphics::ManagedSurface *scSurf(scaleGfx(surf, _thumbnailWidth, 512));
|
2021-06-12 15:59:42 +05:30
|
|
|
_loadedSurfaces[path] = scSurf;
|
2021-06-23 18:07:40 +05:30
|
|
|
surf->free();
|
|
|
|
delete surf;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-26 18:37:30 +05:30
|
|
|
else {
|
|
|
|
_loadedSurfaces[path] = nullptr;
|
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridWidget::loadFlagIcons() {
|
2021-06-26 21:05:21 +05:30
|
|
|
const Common::LanguageDescription *l =Common::g_languages;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
String path = String::format("./icons/%s.svg", l->code);
|
|
|
|
Graphics::ManagedSurface *gfx = loadSurfaceFromFile(path);
|
2021-06-22 17:30:20 +05:30
|
|
|
if (gfx) {
|
|
|
|
const Graphics::ManagedSurface *scGfx = scaleGfx(gfx, 32, 32);
|
2021-06-26 21:05:21 +05:30
|
|
|
_loadedSurfaces[path] = scGfx;
|
2021-06-22 17:30:20 +05:30
|
|
|
gfx->free();
|
|
|
|
delete gfx;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-26 21:05:21 +05:30
|
|
|
else {
|
|
|
|
_loadedSurfaces[path] = nullptr;
|
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-22 17:30:20 +05:30
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridWidget::loadPlatformIcons() {
|
|
|
|
for (auto iter = _platformIcons.begin(); iter != _platformIcons.end(); ++iter) {
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
_platformIcons.clear();
|
|
|
|
String pathPrefix("./icons/");
|
|
|
|
StringArray iconFilenames;
|
|
|
|
|
|
|
|
// TODO: Can we make a list of all platforms?
|
|
|
|
iconFilenames.push_back(String("dos.png"));
|
|
|
|
iconFilenames.push_back(String("amiga.png"));
|
|
|
|
iconFilenames.push_back(String("apple2.png"));
|
|
|
|
|
|
|
|
for (auto i = iconFilenames.begin(); i != iconFilenames.end(); ++i) {
|
|
|
|
String fullPath = pathPrefix + (*i);
|
|
|
|
Graphics::ManagedSurface *gfx = loadSurfaceFromFile(fullPath);
|
|
|
|
if (gfx) {
|
|
|
|
const Graphics::ManagedSurface *scGfx = scaleGfx(gfx, 32, 32);
|
|
|
|
_platformIcons.push_back(scGfx);
|
|
|
|
_loadedSurfaces[fullPath] = scGfx;
|
|
|
|
gfx->free();
|
|
|
|
delete gfx;
|
|
|
|
}
|
|
|
|
}
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridWidget::destroyItems() {
|
|
|
|
for (Common::Array<GridItemWidget *>::iterator i = _gridItems.begin(), end = _gridItems.end(); i != end; ++i) {
|
|
|
|
removeWidget((*i));
|
|
|
|
delete (*i);
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
2021-06-22 17:30:20 +05:30
|
|
|
|
|
|
|
_gridItems.clear();
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-26 17:25:41 +05:30
|
|
|
void GridWidget::move(int x, int y) {
|
|
|
|
for (auto i = _gridItems.begin(); i != _gridItems.end(); ++i) {
|
|
|
|
(*i)->move(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridWidget::updateGrid() {
|
|
|
|
for (auto i = _gridItems.begin(); i != _gridItems.end(); ++i) {
|
|
|
|
(*i)->update();
|
|
|
|
}
|
2021-06-17 15:25:49 +05:30
|
|
|
}
|
|
|
|
|
2021-06-23 18:33:20 +05:30
|
|
|
void GridWidget::assignEntriesToItems() {
|
|
|
|
// Assign entries from _visibleEntries to each GridItem in _gridItems
|
|
|
|
auto entry = _visibleEntries.begin();
|
|
|
|
// Start assigning from the second row as the first row is supposed
|
|
|
|
// to be offscreen.
|
|
|
|
auto it = _gridItems.begin() + _itemsPerRow;
|
|
|
|
|
|
|
|
for (int k = 0; k < _itemsOnScreen; ++k) {
|
|
|
|
GridItemWidget *item = *it;
|
|
|
|
if (entry != _visibleEntries.end()) {
|
|
|
|
// Assign entry and update
|
|
|
|
item->setActiveEntry(*entry);
|
|
|
|
item->update();
|
|
|
|
item->setVisible(true);
|
|
|
|
++entry;
|
|
|
|
} else {
|
|
|
|
// If we run out of visible entries to display.
|
|
|
|
// e.g., scrolled to the very bottom, we make items invisible.
|
|
|
|
item->setActiveEntry(_visibleEntries.front());
|
|
|
|
item->update();
|
|
|
|
item->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++it == _gridItems.end())
|
|
|
|
it = _gridItems.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
void GridWidget::handleMouseWheel(int x, int y, int direction) {
|
2021-06-28 17:59:48 +05:30
|
|
|
_scrollBar->handleMouseWheel(x, y, direction);
|
|
|
|
_scrollPos = -_scrollBar->_currentPos;
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
2021-06-21 17:03:38 +05:30
|
|
|
void GridWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
2021-06-22 17:30:20 +05:30
|
|
|
// Work in progress
|
2021-06-21 17:03:38 +05:30
|
|
|
switch (cmd) {
|
|
|
|
case kSetPositionCmd:
|
2021-06-28 17:59:48 +05:30
|
|
|
if (-_scrollPos != (int)data) {
|
|
|
|
_scrollPos = -data;
|
|
|
|
_firstVisibleItem = _itemsPerRow * (-_scrollPos / (_gridItemHeight + _gridYSpacing));
|
|
|
|
_firstVisibleItem = (_firstVisibleItem < 0) ? 0 : _firstVisibleItem;
|
2021-06-23 15:52:37 +05:30
|
|
|
if (calcVisibleEntries()) {
|
|
|
|
reloadThumbnails();
|
|
|
|
}
|
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
int col = 0;
|
|
|
|
|
|
|
|
for (auto it = _gridItems.begin(); it != _gridItems.end(); ++it) {
|
2021-06-28 17:59:48 +05:30
|
|
|
(*it)->setPos(2 * _minGridXSpacing + col * (_gridItemWidth + _gridXSpacing),
|
|
|
|
_gridYSpacing + (row - 1) * (_gridItemHeight + _gridYSpacing) - (-_scrollPos % (_gridItemHeight + _gridYSpacing)));
|
2021-06-23 15:52:37 +05:30
|
|
|
if (++col >= _itemsPerRow) {
|
|
|
|
++row;
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
}
|
2021-06-23 18:33:20 +05:30
|
|
|
assignEntriesToItems();
|
2021-06-21 17:03:38 +05:30
|
|
|
markAsDirty();
|
|
|
|
|
|
|
|
((GUI::Dialog *)_boss)->setFocusWidget(this);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
void GridWidget::reflowLayout() {
|
|
|
|
Widget::reflowLayout();
|
|
|
|
destroyItems();
|
2021-06-28 17:59:48 +05:30
|
|
|
|
2021-06-12 15:59:42 +05:30
|
|
|
_scrollWindowHeight = _h;
|
|
|
|
_scrollWindowWidth = _w;
|
2021-06-15 15:45:56 +05:30
|
|
|
|
2021-06-27 13:46:04 +05:30
|
|
|
int oldThumbnailHeight = _thumbnailHeight;
|
|
|
|
int oldThumbnailWidth = _thumbnailWidth;
|
2021-06-26 17:31:55 +05:30
|
|
|
_thumbnailHeight = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Height");
|
|
|
|
_thumbnailWidth = g_gui.xmlEval()->getVar("Globals.GridItemThumbnail.Width");
|
2021-06-27 13:46:04 +05:30
|
|
|
if ((oldThumbnailHeight != _thumbnailHeight) || (oldThumbnailWidth != _thumbnailWidth)) {
|
|
|
|
_loadedSurfaces.clear();
|
|
|
|
reloadThumbnails();
|
|
|
|
loadFlagIcons();
|
|
|
|
}
|
2021-06-26 17:31:55 +05:30
|
|
|
_minGridXSpacing = g_gui.xmlEval()->getVar("Globals.Grid.XSpacing");
|
|
|
|
_gridYSpacing = g_gui.xmlEval()->getVar("Globals.Grid.YSpacing");
|
|
|
|
|
2021-06-26 21:06:34 +05:30
|
|
|
_isTitlesVisible = g_gui.xmlEval()->getVar("Globals.Grid.ShowTitles");
|
|
|
|
|
2021-06-26 17:24:06 +05:30
|
|
|
_scrollBarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0);
|
|
|
|
|
2021-06-28 19:25:50 +05:30
|
|
|
_trayHeight = kLineHeight * 3;
|
2021-06-26 21:06:34 +05:30
|
|
|
_gridItemHeight = _thumbnailHeight + (2 * kLineHeight * _isTitlesVisible);
|
2021-06-26 17:31:55 +05:30
|
|
|
_gridItemWidth = _thumbnailWidth;
|
|
|
|
|
2021-06-26 17:24:06 +05:30
|
|
|
_itemsPerRow = MAX(((_scrollWindowWidth - (2 * _minGridXSpacing) - _scrollBarWidth) / (_gridItemWidth + _minGridXSpacing)), 1);
|
|
|
|
_gridXSpacing = MAX(((_scrollWindowWidth - (2 * _minGridXSpacing) - _scrollBarWidth) - (_itemsPerRow * _gridItemWidth)) / _itemsPerRow, _minGridXSpacing);
|
2021-06-15 15:45:56 +05:30
|
|
|
|
2021-06-21 17:03:38 +05:30
|
|
|
_rows = ceil(_allEntries.size() / (float)_itemsPerRow);
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-28 19:25:50 +05:30
|
|
|
_innerHeight = _trayHeight + _gridYSpacing + _rows * (_gridItemHeight + _gridYSpacing);
|
2021-06-23 16:49:22 +05:30
|
|
|
_innerWidth = (2 * _minGridXSpacing) + (_itemsPerRow * (_gridItemWidth + _gridXSpacing));
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-28 17:59:48 +05:30
|
|
|
_scrollBar->checkBounds(_scrollBar->_currentPos);
|
|
|
|
_scrollPos = _scrollBar->_currentPos;
|
2021-06-12 15:59:42 +05:30
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
int col = 0;
|
|
|
|
|
2021-06-28 17:59:48 +05:30
|
|
|
_firstVisibleItem = _itemsPerRow * ((-_scrollPos) / (_gridItemHeight + _gridYSpacing));
|
2021-06-18 13:20:10 +05:30
|
|
|
_firstVisibleItem = (_firstVisibleItem < 0) ? 0 : _firstVisibleItem;
|
|
|
|
|
2021-06-26 17:24:06 +05:30
|
|
|
_scrollBar->resize(_w - _scrollBarWidth, 0, _scrollBarWidth, _h, false);
|
2021-06-12 15:59:42 +05:30
|
|
|
if (calcVisibleEntries()) {
|
|
|
|
reloadThumbnails();
|
|
|
|
}
|
|
|
|
|
2021-06-14 13:20:54 +05:30
|
|
|
for (int k = 0; k < _itemsOnScreen; ++k) {
|
2021-06-16 22:51:59 +05:30
|
|
|
GridItemWidget *newItem = new GridItemWidget(this,
|
2021-06-27 12:57:59 +05:30
|
|
|
2 * _minGridXSpacing + col * (_gridItemWidth + _gridXSpacing),
|
2021-06-28 17:59:48 +05:30
|
|
|
_gridYSpacing + (row - 1) * (_gridItemHeight + _gridYSpacing) - ((-_scrollPos) % (_gridItemHeight + _gridYSpacing)),
|
2021-06-16 22:51:59 +05:30
|
|
|
_gridItemWidth,
|
|
|
|
_gridItemHeight);
|
2021-06-14 13:20:54 +05:30
|
|
|
|
2021-06-16 22:51:59 +05:30
|
|
|
_gridItems.push_back(newItem);
|
2021-06-12 15:59:42 +05:30
|
|
|
|
2021-06-14 13:20:54 +05:30
|
|
|
if (++col >= _itemsPerRow) {
|
|
|
|
++row;
|
|
|
|
col = 0;
|
|
|
|
}
|
2021-06-16 22:51:59 +05:30
|
|
|
}
|
|
|
|
|
2021-06-23 18:33:20 +05:30
|
|
|
assignEntriesToItems();
|
2021-06-21 17:03:38 +05:30
|
|
|
scrollBarRecalc();
|
2021-06-12 15:59:42 +05:30
|
|
|
markAsDirty();
|
|
|
|
}
|
|
|
|
|
2021-06-28 19:25:50 +05:30
|
|
|
void GridWidget::openTray(int x, int y, int entryId) {
|
|
|
|
_tray = new GridItemTray(_boss, x - _gridXSpacing / 3, y, _gridItemWidth + 2 * (_gridXSpacing / 3), _trayHeight, entryId, this);
|
2021-06-23 01:22:18 +05:30
|
|
|
}
|
|
|
|
|
2021-06-22 17:30:20 +05:30
|
|
|
void GridWidget::scrollBarRecalc() {
|
2021-06-28 17:59:48 +05:30
|
|
|
_scrollBar->_numEntries = _innerHeight;
|
|
|
|
_scrollBar->_entriesPerPage = _scrollWindowHeight - _gridYSpacing;
|
|
|
|
_scrollBar->_currentPos = -_scrollPos;
|
|
|
|
_scrollBar->_singleStep = kLineHeight;
|
2021-06-23 15:52:37 +05:30
|
|
|
|
2021-06-28 17:59:48 +05:30
|
|
|
_scrollBar->checkBounds(_scrollBar->_currentPos);
|
|
|
|
_scrollPos = _scrollBar->_currentPos;
|
2021-06-22 17:30:20 +05:30
|
|
|
_scrollBar->recalc();
|
2021-06-12 15:59:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace GUI
|