GUI: Create new widgets for the grid system.
This commit is contained in:
parent
7cbefcd434
commit
dc878846ee
5 changed files with 418 additions and 167 deletions
|
@ -121,7 +121,7 @@ static const DrawDataInfo kDrawDataDefaults[] = {
|
|||
{kDDDefaultBackground, "default_bg", kDrawLayerBackground, kDDNone},
|
||||
{kDDTextSelectionBackground, "text_selection", kDrawLayerForeground, kDDNone},
|
||||
{kDDTextSelectionFocusBackground, "text_selection_focus", kDrawLayerForeground, kDDNone},
|
||||
{kDDThumbnailBackground, "thumb_bg", kDrawLayerBackground, kDDNone},
|
||||
{kDDThumbnailBackground, "thumb_bg", kDrawLayerForeground, kDDNone},
|
||||
|
||||
{kDDWidgetBackgroundDefault, "widget_default", kDrawLayerBackground, kDDNone},
|
||||
{kDDWidgetBackgroundSmall, "widget_small", kDrawLayerBackground, kDDNone},
|
||||
|
|
146
gui/launcher.cpp
146
gui/launcher.cpp
|
@ -146,7 +146,7 @@ LauncherDialog::LauncherDialog()
|
|||
: Dialog("Launcher") {
|
||||
|
||||
_backgroundType = GUI::ThemeEngine::kDialogBackgroundMain;
|
||||
|
||||
_grid = new GridWidget(this, "Launcher.IconArea");
|
||||
build();
|
||||
|
||||
GUI::GuiManager::instance()._launched = true;
|
||||
|
@ -236,7 +236,6 @@ void LauncherDialog::build() {
|
|||
|
||||
// Add list with game titles
|
||||
_list = new ListWidget(this, "Launcher.GameList", Common::U32String(), kListSearchCmd);
|
||||
_grid = new GridContainerWidget(this, "Launcher.IconArea");
|
||||
_list->setEditable(false);
|
||||
_list->enableDictionarySelect(true);
|
||||
_list->setNumberingMode(kListNumberingOff);
|
||||
|
@ -302,27 +301,14 @@ void LauncherDialog::close() {
|
|||
ConfMan.flushToDisk();
|
||||
Dialog::close();
|
||||
}
|
||||
struct LauncherEntry {
|
||||
Common::String key;
|
||||
Common::String description;
|
||||
const Common::ConfigManager::Domain *domain;
|
||||
|
||||
LauncherEntry(Common::String k, Common::String d, const Common::ConfigManager::Domain *v) {
|
||||
key = k; description = d, domain = v;
|
||||
}
|
||||
};
|
||||
|
||||
struct LauncherEntryComparator {
|
||||
bool operator()(const LauncherEntry &x, const LauncherEntry &y) const {
|
||||
return scumm_compareDictionary(x.description.c_str(), y.description.c_str()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
void LauncherDialog::destroyButtons() {
|
||||
|
||||
for (EntryArray::iterator i = _entries.begin(), end = _entries.end(); i != end; ++i) {
|
||||
removeWidget(i->container);
|
||||
removeWidget(i->thumb);
|
||||
delete i->container;
|
||||
delete i->thumb;
|
||||
}
|
||||
|
||||
_entries.clear();
|
||||
|
@ -330,7 +316,7 @@ void LauncherDialog::destroyButtons() {
|
|||
|
||||
void LauncherDialog::hideButtons() {
|
||||
for (EntryArray::iterator i = _entries.begin(), end = _entries.end(); i != end; ++i) {
|
||||
i->button->setGfx((Graphics::ManagedSurface *)nullptr);
|
||||
i->thumb->setGfx((Graphics::ManagedSurface *)nullptr);
|
||||
i->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +337,7 @@ void LauncherDialog::updateListing() {
|
|||
bool scanEntries = numEntries == -1 ? true : ((int)domains.size() <= numEntries);
|
||||
|
||||
// Turn it into a list of pointers
|
||||
Common::List<LauncherEntry> domainList;
|
||||
Common::Array<LauncherEntry> domainList;
|
||||
for (ConfigManager::DomainMap::const_iterator iter = domains.begin(); iter != domains.end(); ++iter) {
|
||||
// Do not list temporary targets added when starting a game from the command line
|
||||
if (iter->_value.contains("id_came_from_command_line"))
|
||||
|
@ -376,81 +362,89 @@ void LauncherDialog::updateListing() {
|
|||
// Strip platform language from the title.
|
||||
int extraPos = description.rfind("(");
|
||||
description.replace((char *)(description.c_str())+extraPos, description.end(), Common::String(""));
|
||||
|
||||
warning("%s",iter->_key.c_str());
|
||||
if (!description.empty())
|
||||
domainList.push_back(LauncherEntry(iter->_key, description, &iter->_value));
|
||||
}
|
||||
|
||||
destroyButtons();
|
||||
_entries.reserve(domainList.size());
|
||||
// destroyButtons();
|
||||
// _entries.reserve(domainList.size());
|
||||
// testPath = Common::String("adl-hires2.png");
|
||||
// warning("%p", (void *)(_grid->filenameToSurface(testPath)));
|
||||
|
||||
for (int i = 0; i < domainList.size(); ++i) {
|
||||
GameContainerWidget *container = new GameContainerWidget(_grid, 50 + i*(192+40), 50, 192, 160);
|
||||
GameThumbButton *button = new GameThumbButton(container, 0,0, 192, 128);
|
||||
StaticTextWidget *title = new StaticTextWidget(container, 0, 128, 192, 160-128, Common::U32String("Title") , Graphics::kTextAlignLeft);
|
||||
StaticTextWidget *language = new StaticTextWidget(button, container->getWidth()-32, 0, 32, 32, Common::U32String("UNK") , Graphics::kTextAlignRight);
|
||||
GraphicsWidget *platform = new GraphicsWidget(button, container->getWidth()-32, 128-32, 32, 32);
|
||||
container->setVisible(false);
|
||||
_entries.push_back(GameEntry(container, button, title, language, platform));
|
||||
}
|
||||
// for (int i = 0; i < domainList.size(); ++i) {
|
||||
// EntryContainerWidget *container = new EntryContainerWidget(_grid, 50 + i*(192+40), 50, 192, 128);
|
||||
// GraphicsWidget *button = new GraphicsWidget(container, 0,0, 192, 128);
|
||||
// button->setGfx(_grid->filenameToSurface(testPath));
|
||||
// StaticTextWidget *title = new StaticTextWidget(container, 0, 128, 192, 160-128, Common::U32String("Title") , Graphics::kTextAlignLeft);
|
||||
// StaticTextWidget *language = new StaticTextWidget(button, container->getWidth()-32, 0, 32, 32, Common::U32String("UNK") , Graphics::kTextAlignRight);
|
||||
// GraphicsWidget *platform = new GraphicsWidget(button, container->getWidth()-32, 128-32, 32, 32);
|
||||
// container->setVisible(false);
|
||||
// _entries.push_back(GameEntry(container, button, title, language, platform));
|
||||
// }
|
||||
|
||||
hideButtons();
|
||||
// hideButtons();
|
||||
|
||||
// Now sort the list in dictionary order
|
||||
Common::sort(domainList.begin(), domainList.end(), LauncherEntryComparator());
|
||||
|
||||
// Populate Grid
|
||||
int row = 0, col = 0, i = 0;
|
||||
int entriesPerRow = 6;
|
||||
for (Common::List<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
|
||||
i = entriesPerRow*row + col;
|
||||
String language = iter->domain->getValOrDefault("language");
|
||||
language.toUppercase();
|
||||
String platform = iter->domain->getValOrDefault("platform");
|
||||
platform.toLowercase();
|
||||
String engineid(iter->domain->getVal("engineid"));
|
||||
String gameid(iter->domain->getVal("gameid"));
|
||||
_grid->gridFromGameList(&domainList);
|
||||
|
||||
GraphicsWidget *testWidget = new GraphicsWidget(this, 0, 0, 192, 128);
|
||||
Common::String testPath("adl-hires2.png");
|
||||
testWidget->setGfx(_grid->filenameToSurface(testPath));
|
||||
// // Populate Grid
|
||||
// int row = 0, col = 0, i = 0;
|
||||
// int entriesPerRow = 6;
|
||||
// for (Common::Array<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
|
||||
// i = entriesPerRow*row + col;
|
||||
// String language = iter->domain->getValOrDefault("language");
|
||||
// language.toUppercase();
|
||||
// String platform = iter->domain->getValOrDefault("platform");
|
||||
// platform.toLowercase();
|
||||
// String engineid(iter->domain->getVal("engineid"));
|
||||
// String gameid(iter->domain->getVal("gameid"));
|
||||
|
||||
|
||||
if (language.empty())
|
||||
language = "UNK";
|
||||
if (platform.empty())
|
||||
platform = "UNK";
|
||||
if (engineid.empty())
|
||||
engineid = iter->key;
|
||||
if (gameid.empty())
|
||||
gameid = iter->key;
|
||||
// if (language.empty())
|
||||
// language = "UNK";
|
||||
// if (platform.empty())
|
||||
// platform = "UNK";
|
||||
// if (engineid.empty())
|
||||
// engineid = iter->key;
|
||||
// if (gameid.empty())
|
||||
// gameid = iter->key;
|
||||
|
||||
warning("%s %s %s %s", engineid.c_str(), gameid.c_str(), language.c_str(), platform.c_str());
|
||||
// warning("%s %s %s %s", engineid.c_str(), gameid.c_str(), language.c_str(), platform.c_str());
|
||||
|
||||
GameEntry &curEntry = _entries[i];
|
||||
curEntry.setVisible(true);
|
||||
// GameEntry &curEntry = _entries[i];
|
||||
// curEntry.setVisible(true);
|
||||
|
||||
Common::String thumbName = engineid + "-" + gameid + ".png";
|
||||
warning(thumbName.c_str());
|
||||
curEntry.container->setPos(50 + col*(192+40), 50 + row*(160+20));
|
||||
curEntry.button->setGfxFromTheme(thumbName.c_str(), kPicButtonStateEnabled, true);
|
||||
curEntry.language->setLabel(language);
|
||||
// char *newTit = (char *)iter->description.c_str();
|
||||
// newTit[5] = '\n';
|
||||
// curEntry.title->setLabel(Common::String(newTit));
|
||||
curEntry.title->setLabel(iter->description);
|
||||
if (platform == "pc")
|
||||
curEntry.platform->setGfxFromTheme("dos.png");
|
||||
else if (platform == "amiga")
|
||||
curEntry.platform->setGfxFromTheme("amiga.png");
|
||||
else if (platform == "apple2")
|
||||
curEntry.platform->setGfxFromTheme("apple2.png");
|
||||
else
|
||||
{}
|
||||
// Common::String thumbName = engineid + "-" + gameid + ".png";
|
||||
// warning(thumbName.c_str());
|
||||
// curEntry.container->setPos(50 + col*(192+40), 50 + row*(160+20));
|
||||
// // curEntry.thumb->setGfxFromTheme(thumbName.c_str());
|
||||
// curEntry.language->setLabel(language);
|
||||
// // char *newTit = (char *)iter->description.c_str();
|
||||
// // newTit[5] = '\n';
|
||||
// // curEntry.title->setLabel(Common::String(newTit));
|
||||
// curEntry.title->setLabel(iter->description);
|
||||
// if (platform == "pc")
|
||||
// curEntry.platform->setGfxFromTheme("dos.png");
|
||||
// else if (platform == "amiga")
|
||||
// curEntry.platform->setGfxFromTheme("amiga.png");
|
||||
// else if (platform == "apple2")
|
||||
// curEntry.platform->setGfxFromTheme("apple2.png");
|
||||
// else
|
||||
// {}
|
||||
|
||||
col++;
|
||||
if (col >= entriesPerRow) { row ++; col = 0;}
|
||||
// if (i > 4) { break; }
|
||||
}
|
||||
// col++;
|
||||
// if (col >= entriesPerRow) { row ++; col = 0;}
|
||||
// // if (i > 4) { break; }
|
||||
// }
|
||||
|
||||
// And fill out our structures
|
||||
for (Common::List<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
|
||||
for (Common::Array<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
|
||||
color = ThemeEngine::kFontColorNormal;
|
||||
|
||||
if (scanEntries) {
|
||||
|
|
|
@ -32,11 +32,10 @@ class BrowserDialog;
|
|||
class CommandSender;
|
||||
class ListWidget;
|
||||
class ContainerWidget;
|
||||
class GameContainerWidget;
|
||||
class GridContainerWidget;
|
||||
class EntryContainerWidget;
|
||||
class GridWidget;
|
||||
class ButtonWidget;
|
||||
class PicButtonWidget;
|
||||
class GameThumbButton;
|
||||
class GraphicsWidget;
|
||||
class StaticTextWidget;
|
||||
class EditTextWidget;
|
||||
|
@ -63,7 +62,7 @@ public:
|
|||
Common::String getGameConfig(int item, Common::String key);
|
||||
protected:
|
||||
EditTextWidget *_searchWidget;
|
||||
GridContainerWidget *_grid;
|
||||
GridWidget *_grid;
|
||||
ListWidget *_list;
|
||||
Widget *_startButton;
|
||||
ButtonWidget *_loadButton;
|
||||
|
@ -132,11 +131,11 @@ protected:
|
|||
void selectTarget(const String &target);
|
||||
private:
|
||||
struct GameEntry {
|
||||
GameEntry() : container(nullptr), button(nullptr), title(nullptr), language(nullptr), platform(nullptr) {}
|
||||
GameEntry(GameContainerWidget *c, GameThumbButton *b, StaticTextWidget *t, StaticTextWidget *l, GraphicsWidget *p) : container(c), button(b), title(t), language(l), platform(p) {}
|
||||
GameEntry() : container(nullptr), thumb(nullptr), title(nullptr), language(nullptr), platform(nullptr) {}
|
||||
GameEntry(EntryContainerWidget *c, GraphicsWidget *b, StaticTextWidget *t, StaticTextWidget *l, GraphicsWidget *p) : container(c), thumb(b), title(t), language(l), platform(p) {}
|
||||
|
||||
GameContainerWidget *container;
|
||||
GameThumbButton *button;
|
||||
EntryContainerWidget *container;
|
||||
GraphicsWidget *thumb;
|
||||
StaticTextWidget *title;
|
||||
StaticTextWidget *language;
|
||||
GraphicsWidget *platform;
|
||||
|
|
312
gui/widget.cpp
312
gui/widget.cpp
|
@ -36,6 +36,11 @@
|
|||
#include "gui/widgets/popup.h"
|
||||
#include "gui/widgets/scrollcontainer.h"
|
||||
|
||||
#include "image/bmp.h"
|
||||
#include "image/png.h"
|
||||
|
||||
#include "backends/fs/posix/posix-fs.h"
|
||||
|
||||
namespace GUI {
|
||||
|
||||
Widget::Widget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip)
|
||||
|
@ -673,70 +678,6 @@ void PicButtonWidget::drawWidget() {
|
|||
|
||||
#pragma mark -
|
||||
|
||||
void GameThumbButton::setGfx(const Graphics::ManagedSurface *gfx, int statenum, bool scale) {
|
||||
_gfx[statenum].free();
|
||||
|
||||
if (!gfx || !gfx->getPixels())
|
||||
return;
|
||||
|
||||
if (gfx->format.bytesPerPixel == 1) {
|
||||
warning("GameThumbButton::setGfx got paletted surface passed");
|
||||
return;
|
||||
}
|
||||
|
||||
float sf = g_gui.getScaleFactor();
|
||||
if (scale && sf != 1.0) {
|
||||
float scalingFactor = (float)gfx->w / _w;
|
||||
Graphics::Surface *tmp4 = gfx->rawSurface().scale(gfx->w * sf, gfx->h * sf, false);
|
||||
Graphics::Surface *tmp2 = tmp4->scale(_w, (uint16)(gfx->h / scalingFactor), false);
|
||||
Graphics::Surface tmp3 = tmp2->getSubArea(Common::Rect(0,(tmp2->h -_h)/2, tmp2->w, (tmp2->h + _h)/2));
|
||||
_gfx[statenum].copyFrom(tmp3);
|
||||
tmp4->free();
|
||||
delete tmp4;
|
||||
tmp2->free();
|
||||
delete tmp2;
|
||||
} else {
|
||||
_gfx[statenum].copyFrom(*gfx);
|
||||
}
|
||||
}
|
||||
|
||||
void GameThumbButton::setGfxFromTheme(const char *name, int statenum, bool scale) {
|
||||
const Graphics::ManagedSurface *gfx = g_gui.theme()->getImageSurface(name);
|
||||
|
||||
setGfx(gfx, statenum, scale);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void GameThumbButton::drawWidget() {
|
||||
if (_showButton)
|
||||
g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), Common::U32String(), _state, getFlags());
|
||||
|
||||
Graphics::ManagedSurface *gfx;
|
||||
|
||||
if (_state == ThemeEngine::kStateHighlight)
|
||||
gfx = &_gfx[kPicButtonHighlight];
|
||||
else if (_state == ThemeEngine::kStateDisabled)
|
||||
gfx = &_gfx[kPicButtonStateDisabled];
|
||||
else if (_state == ThemeEngine::kStatePressed)
|
||||
gfx = &_gfx[kPicButtonStatePressed];
|
||||
else
|
||||
gfx = &_gfx[kPicButtonStateEnabled];
|
||||
|
||||
if (!gfx->getPixels())
|
||||
gfx = &_gfx[kPicButtonStateEnabled];
|
||||
|
||||
if (gfx->getPixels()) {
|
||||
const int x = _x + (_w - gfx->w) / 2;
|
||||
const int y = _y + (_h - gfx->h) / 2;
|
||||
|
||||
g_gui.theme()->drawWidgetBackground(Common::Rect(x, y, x+_w, y+_h),ThemeEngine::WidgetBackground::kThumbnailBackground);
|
||||
g_gui.theme()->drawSurface(Common::Point(x, y), *gfx, _transparency);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey)
|
||||
: ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey), _state(false) {
|
||||
setFlags(WIDGET_ENABLED);
|
||||
|
@ -1072,6 +1013,249 @@ void ContainerWidget::drawWidget() {
|
|||
|
||||
#pragma mark -
|
||||
|
||||
EntryContainerWidget::EntryContainerWidget(GridWidget *boss, int x, int y, int w, int h) :
|
||||
ContainerWidget(boss, x, y, w, h) {
|
||||
_thumb = new GraphicsWidget(this, 0, 0 , kThumbnailWidth, kThumbnailHeight);
|
||||
_plat = new GraphicsWidget(_thumb, kThumbnailWidth - 32, kThumbnailHeight - 32, 32, 32);
|
||||
_lang = new StaticTextWidget(_thumb, kThumbnailWidth - 32, 0, 32, 32, Common::U32String("XX"), Graphics::TextAlign::kTextAlignRight);
|
||||
_title = new StaticTextWidget(this, 0, kThumbnailHeight, w , kLineHeight*2, Common::U32String("Title"), Graphics::TextAlign::kTextAlignLeft);
|
||||
_activeInstall = nullptr;
|
||||
_grid = boss;
|
||||
// setBackgroundType(ThemeEngine::kThumbnailBackground);
|
||||
}
|
||||
EntryContainerWidget::EntryContainerWidget(GridWidget *boss, GraphicsWidget *th, GraphicsWidget *p, StaticTextWidget *l, StaticTextWidget *t) :
|
||||
ContainerWidget(boss, 0, 0, 0, 0), _thumb(th), _plat(p), _lang(l), _title(t) {}
|
||||
|
||||
void EntryContainerWidget::addInstallation(Common::String key, Common::String description, Common::ConfigManager::Domain *domain) {
|
||||
_installations.push_back(LauncherEntry(key, description, domain));
|
||||
}
|
||||
|
||||
void EntryContainerWidget::addInstallation(LauncherEntry &install) {
|
||||
_installations.push_back(install);
|
||||
}
|
||||
|
||||
void EntryContainerWidget::addInstallations(Common::Array<LauncherEntry> installs) {
|
||||
_installations.push_back(installs);
|
||||
}
|
||||
|
||||
void EntryContainerWidget::setActiveInstallation(LauncherEntry &install) {
|
||||
_activeInstall = &install;
|
||||
}
|
||||
|
||||
void EntryContainerWidget::updateEntry() {
|
||||
if ((!_activeInstall) && (!_installations.empty())) {
|
||||
_activeInstall = _installations.begin();
|
||||
}
|
||||
if (_activeInstall) {
|
||||
warning("%s, %s - Install", _activeInstall->key.c_str(), _activeInstall->description.c_str());
|
||||
Common::String gameid = _activeInstall->domain->getVal("gameid");
|
||||
Common::String engineid = _activeInstall->domain->getVal("engineid");
|
||||
Common::String language = "XX";
|
||||
Common::String platform = "UNK";
|
||||
_activeInstall->domain->tryGetVal("language",language);
|
||||
_activeInstall->domain->tryGetVal("platform", platform);
|
||||
language.toUppercase();
|
||||
warning("Fields populated");
|
||||
warning("%s %s %s %s", gameid.c_str(), engineid.c_str(), language.c_str(), platform.c_str());
|
||||
Common::String thumbPath = Common::String::format("%s-%s.png",engineid.c_str(),gameid.c_str());
|
||||
warning("I will be loading: %s", thumbPath.c_str());
|
||||
warning("%d thumbs loaded", _grid->getLoadedNumber());
|
||||
Graphics::ManagedSurface *gfx = _grid->filenameToSurface(thumbPath);
|
||||
warning("Got some surface");
|
||||
_thumb->setGfx(gfx);
|
||||
|
||||
_lang->setLabel(language);
|
||||
_title->setLabel(_activeInstall->description);
|
||||
|
||||
if (platform == "pc")
|
||||
_plat->setGfx(_grid->platformToSurface(GridWidget::Platform::kPlatformDOS));
|
||||
else if (platform == "amiga")
|
||||
_plat->setGfx(_grid->platformToSurface(GridWidget::Platform::kPlatformAmiga));
|
||||
else if (platform == "apple2")
|
||||
_plat->setGfx(_grid->platformToSurface(GridWidget::Platform::kPlatformApple2));
|
||||
else
|
||||
_plat->setGfx(_grid->platformToSurface(GridWidget::Platform::kPlatformUnknown));
|
||||
}
|
||||
markAsDirty();
|
||||
}
|
||||
|
||||
void EntryContainerWidget::drawWidget() {
|
||||
g_gui.theme()->drawWidgetBackground(Common::Rect(_x,_y,_x+kThumbnailWidth,_y+kThumbnailHeight), ThemeEngine::WidgetBackground::kThumbnailBackground);
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
Graphics::ManagedSurface *loadSurfaceFromFile(Common::String &name) {
|
||||
Graphics::ManagedSurface *surf = nullptr;
|
||||
const Graphics::Surface *srcSurface = nullptr;
|
||||
if (name.hasSuffix(".png")) {
|
||||
#ifdef USE_PNG
|
||||
Image::PNGDecoder decoder;
|
||||
POSIXFilesystemNode posixfs(name);
|
||||
Common::SeekableReadStream * stream = posixfs.createReadStream();
|
||||
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());
|
||||
}
|
||||
else {
|
||||
warning("Loaded thumb : %s", name.c_str());
|
||||
}
|
||||
if (srcSurface && srcSurface->format.bytesPerPixel != 1) {
|
||||
surf = new Graphics::ManagedSurface(srcSurface->convertTo(g_system->getOverlayFormat()));
|
||||
warning("Converting : %s", name.c_str());
|
||||
}
|
||||
|
||||
} else {
|
||||
warning("No such file : %s", name.c_str());
|
||||
}
|
||||
#else
|
||||
error("No PNG support compiled");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
warning("%p", (void *)surf);
|
||||
return surf;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
GridWidget::GridWidget(GuiObject *boss, int x, int y, int w, int h) :
|
||||
ContainerWidget(boss, x, y, w, h) {
|
||||
loadPlatformIcons();
|
||||
}
|
||||
|
||||
GridWidget::GridWidget(GuiObject *boss, const Common::String &name) :
|
||||
ContainerWidget(boss, name) {
|
||||
loadPlatformIcons();
|
||||
_scrollBar = new ScrollBarWidget(this, 0, 0, 20, 100);
|
||||
_scrollBar->setTarget(this);
|
||||
_scrollPos = 0;
|
||||
_scrollWindowHeight = 500;
|
||||
_scrollWindowWidth = 500;
|
||||
}
|
||||
|
||||
void GridWidget::gridFromGameList(Common::Array<LauncherEntry> *list) {
|
||||
_allEntries = Common::Array<LauncherEntry>(*list);
|
||||
reloadThumbnails();
|
||||
warning("Thumbnails loaded");
|
||||
Common::HashMap<Common::String, EntryContainerWidget *> entryById;
|
||||
int row = 0, col = 0;
|
||||
int entriesPerRow = 3;
|
||||
int k = 0;
|
||||
for (Common::Array<LauncherEntry>::iterator i = list->begin(); i != list->end(); ++i) {
|
||||
k = row * entriesPerRow + col;
|
||||
EntryContainerWidget *newEntry = entryById[i->key];
|
||||
if (!newEntry) {
|
||||
newEntry = new EntryContainerWidget(this, 50 + col * (kThumbnailWidth + 50), 50 + row * (kThumbnailHeight + 80), kThumbnailWidth, kThumbnailHeight+kLineHeight*2);
|
||||
_entries.push_back(newEntry);
|
||||
}
|
||||
newEntry->addInstallation(*i);
|
||||
warning("Installation added");
|
||||
newEntry->updateEntry();
|
||||
warning("Entry updated");
|
||||
entryById[i->key] = newEntry;
|
||||
if (++col >= entriesPerRow) {
|
||||
++row;
|
||||
col = 0;
|
||||
}
|
||||
++k;
|
||||
}
|
||||
_innerHeight = 100 + (row * (kThumbnailHeight + 80));
|
||||
_innerWidth = 100 + (col * (kThumbnailWidth + 50));
|
||||
// warning("%d %d", _innerWidth, _innerHeight);
|
||||
}
|
||||
|
||||
void GridWidget::loadPlatformIcons() {
|
||||
for (auto iter = _platformIcons.begin(); iter != _platformIcons.end(); ++iter) {
|
||||
delete *iter;
|
||||
}
|
||||
_platformIcons.clear();
|
||||
Common::String pathPrefix("./icons/");
|
||||
Common::Array<Common::String> iconFilenames;
|
||||
iconFilenames.push_back(Common::String("dos.png"));
|
||||
iconFilenames.push_back(Common::String("amiga.png"));
|
||||
iconFilenames.push_back(Common::String("apple2.png"));
|
||||
|
||||
for (int i = 0; i < iconFilenames.size(); ++i) {
|
||||
Common::String fullPath = pathPrefix + iconFilenames[i];
|
||||
_platformIcons.push_back(loadSurfaceFromFile(fullPath));
|
||||
}
|
||||
}
|
||||
|
||||
Common::Array<Common::String> GridWidget::visibleEntries() {
|
||||
Common::Array<Common::String> placeholder;
|
||||
Common::Array<Common::String> thumbList;
|
||||
Common::String pathPrefix("./icons/");
|
||||
for (auto iter = _allEntries.begin(); iter != _allEntries.end(); ++iter) {
|
||||
Common::String gameid = iter->domain->getVal("gameid");
|
||||
Common::String engineid = iter->domain->getVal("engineid");
|
||||
thumbList.push_back(pathPrefix + Common::String::format("%s-%s.png", engineid.c_str(), gameid.c_str()));
|
||||
}
|
||||
return thumbList;
|
||||
}
|
||||
|
||||
void GridWidget::reloadThumbnails() {
|
||||
Graphics::ManagedSurface *surf = nullptr;
|
||||
_loadedSurfaces.clear(true);
|
||||
warning("cleanerd");
|
||||
Common::Array<Common::String> titleList = visibleEntries();
|
||||
warning("got array");
|
||||
for (Common::Array<Common::String>::iterator iter = titleList.begin(); iter != titleList.end(); ++iter) {
|
||||
if (_loadedSurfaces.contains(*iter)) {
|
||||
warning("Thumbnail already loaded, skipping...");
|
||||
}
|
||||
else {
|
||||
surf = loadSurfaceFromFile(*iter);
|
||||
_loadedSurfaces[*iter] = surf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface * GridWidget::filenameToSurface(Common::String &name) {
|
||||
Common::String path = Common::String("./icons/")+name;
|
||||
warning("Passing surface for : %s", path.c_str());
|
||||
auto list = visibleEntries();
|
||||
for (auto l = list.begin(); l!=list.end(); ++l) {
|
||||
if (*l == path) {
|
||||
warning("%p", (void *)_loadedSurfaces[path]);
|
||||
return _loadedSurfaces[path];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface * GridWidget::platformToSurface(Platform platformCode) {
|
||||
if ((platformCode == kPlatformUnknown) || (platformCode < 0 || platformCode >= _platformIcons.size())) {
|
||||
warning("Unknown Platform");
|
||||
}
|
||||
else {
|
||||
return _platformIcons[platformCode];
|
||||
}
|
||||
}
|
||||
|
||||
void GridWidget::handleMouseWheel(int x, int y, int direction) {
|
||||
// warning("Wheel : %d %d %d", x, y, direction);
|
||||
_scrollPos = direction*10;
|
||||
for (Common::Array<EntryContainerWidget *>::iterator iter = _entries.begin(); iter != _entries.end(); ++iter) {
|
||||
(*iter)->setPos((*iter)->getRelX(), (*iter)->getRelY() - _scrollPos);
|
||||
if ((*iter)->getRelY()< -kThumbnailHeight) {
|
||||
(*iter)->setVisible(false);
|
||||
} else {
|
||||
(*iter)->setVisible(true);
|
||||
}
|
||||
}
|
||||
markAsDirty();
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
OptionsContainerWidget::OptionsContainerWidget(GuiObject *boss, const Common::String &name, const Common::String &dialogLayout,
|
||||
bool scrollable, const Common::String &domain) :
|
||||
Widget(boss, name),
|
||||
|
|
112
gui/widget.h
112
gui/widget.h
|
@ -38,6 +38,7 @@
|
|||
namespace GUI {
|
||||
|
||||
class ScrollContainerWidget;
|
||||
class ScrollBarWidget;
|
||||
|
||||
enum {
|
||||
WIDGET_ENABLED = 1 << 0,
|
||||
|
@ -460,31 +461,104 @@ protected:
|
|||
ThemeEngine::WidgetBackground _backgroundType;
|
||||
};
|
||||
|
||||
/* GameThumbButton */
|
||||
class GameThumbButton : public PicButtonWidget {
|
||||
public:
|
||||
GameThumbButton(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0): PicButtonWidget(boss, x, y, w, h, tooltip, cmd, hotkey) {};
|
||||
GameThumbButton(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0): PicButtonWidget(boss, name, tooltip, cmd, hotkey) {};
|
||||
struct LauncherEntry {
|
||||
Common::String key;
|
||||
Common::String description;
|
||||
const Common::ConfigManager::Domain *domain;
|
||||
|
||||
void setGfx(const Graphics::ManagedSurface *gfx, int statenum = kPicButtonStateEnabled, bool scale = true);
|
||||
void setGfxFromTheme(const char *name, int statenum = kPicButtonStateEnabled, bool scale = true);
|
||||
void drawWidget(void);
|
||||
LauncherEntry(Common::String k, Common::String d, const Common::ConfigManager::Domain *v) {
|
||||
key = k; description = d, domain = v;
|
||||
}
|
||||
};
|
||||
|
||||
/* GameContainerWidget */
|
||||
class GameContainerWidget : public ContainerWidget {
|
||||
public:
|
||||
GameContainerWidget(GuiObject *boss, int x, int y, int w, int h) : ContainerWidget(boss, x, y, w, h) {};
|
||||
struct LauncherEntryComparator {
|
||||
bool operator()(const LauncherEntry &x, const LauncherEntry &y) const {
|
||||
return scumm_compareDictionary(x.description.c_str(), y.description.c_str()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
/* GridContainerWidget */
|
||||
class GridContainerWidget : public ContainerWidget {
|
||||
public:
|
||||
GridContainerWidget(GuiObject *boss, int x, int y, int w, int h) : ContainerWidget(boss, x, y, w, h) {};
|
||||
GridContainerWidget(GuiObject *boss, const Common::String &name) : ContainerWidget(boss, name) {};
|
||||
class EntryContainerWidget;
|
||||
|
||||
/* GridWidget */
|
||||
class GridWidget : public ContainerWidget {
|
||||
private:
|
||||
Common::Array<Graphics::ManagedSurface *> _platformIcons;
|
||||
Common::Array<EntryContainerWidget *> _entries;
|
||||
Common::Array<LauncherEntry> _allEntries;
|
||||
Common::HashMap<Common::String, Graphics::ManagedSurface *> _loadedSurfaces;
|
||||
// Common::HashMap<Common::String, EntryContainerWidget *> _entryById;
|
||||
|
||||
ScrollBarWidget *_scrollBar;
|
||||
ContainerWidget *_visibleWindow;
|
||||
|
||||
uint16 _scrollWindowHeight, _scrollWindowWidth, _scrollSpeed;
|
||||
uint16 _innerHeight, _innerWidth;
|
||||
uint16 _thumbnailHeight, _thumbnailWidth;
|
||||
int _scrollPos;
|
||||
int _entriesPerRow;
|
||||
int _entriesOnScreen;
|
||||
int _totalEntries;
|
||||
bool _titlesVisible;
|
||||
|
||||
public:
|
||||
|
||||
enum Platform {
|
||||
kPlatformDOS,
|
||||
kPlatformAmiga,
|
||||
kPlatformApple2,
|
||||
kPlatformUnknown = -1
|
||||
};
|
||||
|
||||
GridWidget(GuiObject *boss, int x, int y, int w, int h);
|
||||
GridWidget(GuiObject *boss, const Common::String &name);
|
||||
|
||||
Graphics::ManagedSurface * filenameToSurface(Common::String &name);
|
||||
Graphics::ManagedSurface * platformToSurface(Platform platformCode);
|
||||
|
||||
Common::Array<Common::String> visibleEntries(void);
|
||||
|
||||
void loadPlatformIcons();
|
||||
void updateEntries(void);
|
||||
void gridFromGameList(Common::Array<LauncherEntry> *list);
|
||||
int getLoadedNumber(void) {return _loadedSurfaces.size();}
|
||||
void reloadThumbnails();
|
||||
void handleMouseWheel(int x, int y, int direction) override;
|
||||
|
||||
|
||||
int selectedEntry;
|
||||
};
|
||||
|
||||
enum {
|
||||
kThumbnailWidth = 192,
|
||||
kThumbnailHeight = 128
|
||||
};
|
||||
|
||||
/* EntryContainerWidget */
|
||||
class EntryContainerWidget : public ContainerWidget {
|
||||
public:
|
||||
GraphicsWidget *_thumb;
|
||||
GraphicsWidget *_plat;
|
||||
StaticTextWidget *_lang;
|
||||
StaticTextWidget *_title;
|
||||
GridWidget *_grid;
|
||||
|
||||
Common::Array<LauncherEntry> _installations;
|
||||
LauncherEntry *_activeInstall;
|
||||
|
||||
bool isHighlighted;
|
||||
void setActiveInstallation(LauncherEntry &install);
|
||||
|
||||
public:
|
||||
EntryContainerWidget(GridWidget *boss, int x, int y, int w, int h);
|
||||
EntryContainerWidget(GridWidget *boss, GraphicsWidget *th, GraphicsWidget *p, StaticTextWidget *l, StaticTextWidget *t);
|
||||
|
||||
void addInstallation(Common::String key, Common::String description, Common::ConfigManager::Domain *domain);
|
||||
void addInstallation(LauncherEntry &install);
|
||||
void addInstallations(Common::Array<LauncherEntry> installs);
|
||||
void setActiveInstallation(int i) {setActiveInstallation(_installations[i]);};
|
||||
void updateEntry();
|
||||
void drawWidget() override;
|
||||
|
||||
int selectedGame;
|
||||
Common::Array<GameContainerWidget> _entries;
|
||||
};
|
||||
|
||||
/* OptionsContainerWidget */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue