GUI: Reverted scaleGfx() to return const pointer
This commit is contained in:
parent
ba91762825
commit
8dcb3c298a
2 changed files with 22 additions and 21 deletions
|
@ -549,7 +549,7 @@ void DropdownButtonWidget::drawWidget() {
|
|||
|
||||
#pragma mark -
|
||||
|
||||
Graphics::ManagedSurface *scaleGfx(Graphics::ManagedSurface *gfx, int w, int h) {
|
||||
const Graphics::ManagedSurface *scaleGfx(Graphics::ManagedSurface *gfx, int w, int h) {
|
||||
int nw = w, nh = h;
|
||||
|
||||
// Maintain aspect ratio
|
||||
|
@ -569,7 +569,7 @@ Graphics::ManagedSurface *scaleGfx(Graphics::ManagedSurface *gfx, int w, int h)
|
|||
|
||||
Graphics::ManagedSurface tmp(*gfx);
|
||||
|
||||
Graphics::ManagedSurface *tmp2 = new Graphics::ManagedSurface(tmp.surfacePtr()->scale(w, h, false));
|
||||
const Graphics::ManagedSurface *tmp2 = new Graphics::ManagedSurface(tmp.surfacePtr()->scale(w, h, false));
|
||||
tmp.free();
|
||||
|
||||
return tmp2;
|
||||
|
@ -1050,7 +1050,7 @@ void GridItemWidget::setActiveEntry(GridItemInfo &entry) {
|
|||
}
|
||||
|
||||
void GridItemWidget::updateThumb() {
|
||||
Graphics::ManagedSurface *gfx = _grid->filenameToSurface(_activeEntry->thumbPath);
|
||||
const Graphics::ManagedSurface *gfx = _grid->filenameToSurface(_activeEntry->thumbPath);
|
||||
_thumb->setGfx(gfx);
|
||||
}
|
||||
|
||||
|
@ -1064,7 +1064,7 @@ void GridItemWidget::update() {
|
|||
_lang->setLabel(_activeEntry->language);
|
||||
_title->setLabel(_activeEntry->title);
|
||||
|
||||
Graphics::ManagedSurface *gfx;
|
||||
const Graphics::ManagedSurface *gfx;
|
||||
|
||||
if (_activeEntry->platform == "pc")
|
||||
gfx = _grid->platformToSurface(kPlatformDOS);
|
||||
|
@ -1105,10 +1105,6 @@ Graphics::ManagedSurface *loadSurfaceFromFile(Common::String &name) {
|
|||
}
|
||||
if (srcSurface && srcSurface->format.bytesPerPixel != 1) {
|
||||
surf = new Graphics::ManagedSurface(srcSurface->convertTo(g_system->getOverlayFormat()));
|
||||
Graphics::ManagedSurface *scSurf(scaleGfx(surf, kThumbnailWidth, 512));
|
||||
surf->free();
|
||||
delete surf;
|
||||
return scSurf;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -1170,11 +1166,13 @@ void GridWidget::loadPlatformIcons() {
|
|||
for (auto i = iconFilenames.begin(); i != iconFilenames.end(); ++i) {
|
||||
Common::String fullPath = pathPrefix + (*i);
|
||||
Graphics::ManagedSurface *gfx = loadSurfaceFromFile(fullPath);
|
||||
Graphics::ManagedSurface *scGfx = scaleGfx(gfx, 32, 32);
|
||||
if (gfx) {
|
||||
const Graphics::ManagedSurface *scGfx = scaleGfx(gfx, 32, 32);
|
||||
_platformIcons.push_back(scGfx);
|
||||
gfx->free();
|
||||
delete gfx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GridWidget::calcVisibleEntries() {
|
||||
|
@ -1211,16 +1209,19 @@ void GridWidget::reloadThumbnails() {
|
|||
for (Common::Array<GridItemInfo>::iterator iter = _visibleEntries.begin(); iter != _visibleEntries.end(); ++iter) {
|
||||
path = Common::String("./icons/")+iter->thumbPath;
|
||||
if (_loadedSurfaces.contains(path)) {
|
||||
warning("Thumbnail already loaded, skipping...");
|
||||
// warning("Thumbnail already loaded, skipping...");
|
||||
}
|
||||
else {
|
||||
surf = loadSurfaceFromFile(path);
|
||||
_loadedSurfaces[path] = surf;
|
||||
if (surf) {
|
||||
const Graphics::ManagedSurface *scSurf(scaleGfx(surf, kThumbnailWidth, 512));
|
||||
_loadedSurfaces[path] = scSurf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *GridWidget::filenameToSurface(Common::String &name) {
|
||||
const Graphics::ManagedSurface *GridWidget::filenameToSurface(Common::String &name) {
|
||||
Common::String path = Common::String("./icons/")+name;
|
||||
|
||||
for (auto l = _visibleEntries.begin(); l!=_visibleEntries.end(); ++l) {
|
||||
|
@ -1232,7 +1233,7 @@ Graphics::ManagedSurface *GridWidget::filenameToSurface(Common::String &name) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Graphics::ManagedSurface *GridWidget::platformToSurface(Platform platformCode) {
|
||||
const Graphics::ManagedSurface *GridWidget::platformToSurface(Platform platformCode) {
|
||||
if ((platformCode == kPlatformUnknown) || (platformCode < 0 || platformCode >= _platformIcons.size())) {
|
||||
warning("Unknown Platform");
|
||||
return nullptr;
|
||||
|
@ -1258,7 +1259,7 @@ void GridWidget::handleMouseWheel(int x, int y, int direction) {
|
|||
reloadThumbnails();
|
||||
}
|
||||
|
||||
warning("%d %d", _visibleEntries.size(), _gridItems.size());
|
||||
// warning("%d %d", _visibleEntries.size(), _gridItems.size());
|
||||
Common::Array<GridItemInfo>::iterator eIter = _visibleEntries.begin();
|
||||
Common::Array<GridItemWidget *>::iterator iter = _gridItems.begin() + (_firstVisibleItem % _gridItems.size());
|
||||
|
||||
|
|
|
@ -489,13 +489,13 @@ class GridItemWidget;
|
|||
/* GridWidget */
|
||||
class GridWidget : public ContainerWidget {
|
||||
private:
|
||||
Common::Array<Graphics::ManagedSurface *> _platformIcons;
|
||||
Common::Array<const Graphics::ManagedSurface *> _platformIcons;
|
||||
// _gridItems should be reserved to hold few more than visible items
|
||||
// Fixing it to 30 for now, 6 items * (4 rows + 1 extra row);
|
||||
Common::Array<GridItemWidget *> _gridItems;
|
||||
Common::Array<GridItemInfo> _allEntries;
|
||||
Common::Array<GridItemInfo> _visibleEntries;
|
||||
Common::HashMap<Common::String, Graphics::ManagedSurface *> _loadedSurfaces;
|
||||
Common::HashMap<Common::String, const Graphics::ManagedSurface *> _loadedSurfaces;
|
||||
|
||||
Common::Array<Common::Array<GridItemWidget *>> _grid;
|
||||
|
||||
|
@ -519,8 +519,8 @@ public:
|
|||
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);
|
||||
const Graphics::ManagedSurface * filenameToSurface(Common::String &name);
|
||||
const Graphics::ManagedSurface * platformToSurface(Platform platformCode);
|
||||
|
||||
|
||||
bool calcVisibleEntries(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue