GUI: Remove gridFromList() to move code to reflowLayout()
This commit is contained in:
parent
b6ccca78c0
commit
823474faaf
2 changed files with 35 additions and 49 deletions
|
@ -1158,12 +1158,12 @@ GridWidget::GridWidget(GuiObject *boss, const Common::String &name) :
|
||||||
_scrollBar = new ScrollBarWidget(this, 0, 0, 20, 100);
|
_scrollBar = new ScrollBarWidget(this, 0, 0, 20, 100);
|
||||||
_scrollBar->setTarget(this);
|
_scrollBar->setTarget(this);
|
||||||
_scrollPos = 0;
|
_scrollPos = 0;
|
||||||
_scrollWindowHeight = 500;
|
|
||||||
_scrollWindowWidth = 500;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidget::setEntryList(Common::Array<LauncherEntry> *list) {
|
void GridWidget::setEntryList(Common::Array<LauncherEntry> *list) {
|
||||||
_allEntries = Common::Array<LauncherEntry>(*list);
|
for (auto entryIter = list->begin(); entryIter != list->end(); ++entryIter) {
|
||||||
|
_allEntries.push_back(*entryIter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidget::destroyItems() {
|
void GridWidget::destroyItems() {
|
||||||
|
@ -1175,37 +1175,6 @@ void GridWidget::destroyItems() {
|
||||||
_gridItems.clear();
|
_gridItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridWidget::gridFromGameList() {
|
|
||||||
reloadThumbnails();
|
|
||||||
Common::HashMap<Common::String, GridItemWidget *> entryById;
|
|
||||||
int row = 0, col = 0;
|
|
||||||
_itemsPerRow = 6;
|
|
||||||
int k = 0;
|
|
||||||
for (Common::Array<LauncherEntry>::iterator i = _allEntries.begin(); i != _allEntries.end(); ++i) {
|
|
||||||
k = row * _itemsPerRow + col;
|
|
||||||
GridItemWidget *newEntry = entryById[i->domain->getVal("gameid")];
|
|
||||||
if (!newEntry) {
|
|
||||||
newEntry = new GridItemWidget(this, 0,0, kThumbnailWidth,kThumbnailHeight);
|
|
||||||
newEntry->setSize(kThumbnailWidth, kThumbnailHeight+kLineHeight*2);
|
|
||||||
newEntry->setPos(50 + col * (kThumbnailWidth + 50), 50 + row * (kThumbnailHeight + 80));
|
|
||||||
// newEntry = new GridItemWidget(this, 50 + col * (kThumbnailWidth + 50), 50 + row * (kThumbnailHeight + 80), kThumbnailWidth, kThumbnailHeight+kLineHeight*2);
|
|
||||||
|
|
||||||
_gridItems.push_back(newEntry);
|
|
||||||
if (++col >= _itemsPerRow) {
|
|
||||||
++row;
|
|
||||||
col = 0;
|
|
||||||
}
|
|
||||||
++k;
|
|
||||||
}
|
|
||||||
newEntry->attachEntry(*i);
|
|
||||||
newEntry->update();
|
|
||||||
entryById[i->domain->getVal("gameid")] = newEntry;
|
|
||||||
}
|
|
||||||
_innerHeight = 100 + ((row + 1) * (kThumbnailHeight + 80));
|
|
||||||
_innerWidth = 100 + (col * (kThumbnailWidth + 50));
|
|
||||||
// warning("%d %d", _innerWidth, _innerHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GridWidget::loadPlatformIcons() {
|
void GridWidget::loadPlatformIcons() {
|
||||||
for (auto iter = _platformIcons.begin(); iter != _platformIcons.end(); ++iter) {
|
for (auto iter = _platformIcons.begin(); iter != _platformIcons.end(); ++iter) {
|
||||||
delete *iter;
|
delete *iter;
|
||||||
|
@ -1224,9 +1193,10 @@ void GridWidget::loadPlatformIcons() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Array<Common::String> GridWidget::visibleEntries() {
|
Common::Array<Common::String> GridWidget::visibleEntries() {
|
||||||
Common::Array<Common::String> placeholder;
|
|
||||||
Common::Array<Common::String> thumbList;
|
Common::Array<Common::String> thumbList;
|
||||||
Common::String pathPrefix("./icons/");
|
Common::String pathPrefix("./icons/");
|
||||||
|
int startingEntry = 0;
|
||||||
|
int totalVisibleEntries = 0;
|
||||||
for (auto iter = _allEntries.begin(); iter != _allEntries.end(); ++iter) {
|
for (auto iter = _allEntries.begin(); iter != _allEntries.end(); ++iter) {
|
||||||
Common::String gameid = iter->domain->getVal("gameid");
|
Common::String gameid = iter->domain->getVal("gameid");
|
||||||
Common::String engineid = iter->domain->getVal("engineid");
|
Common::String engineid = iter->domain->getVal("engineid");
|
||||||
|
@ -1300,35 +1270,50 @@ void GridWidget::handleMouseWheel(int x, int y, int direction) {
|
||||||
void GridWidget::reflowLayout() {
|
void GridWidget::reflowLayout() {
|
||||||
Widget::reflowLayout();
|
Widget::reflowLayout();
|
||||||
destroyItems();
|
destroyItems();
|
||||||
gridFromGameList();
|
|
||||||
_scrollWindowHeight = _h;
|
_scrollWindowHeight = _h;
|
||||||
_scrollWindowWidth = _w;
|
_scrollWindowWidth = _w;
|
||||||
int row = 0, col = 0;
|
_itemsPerRow = MAX((((int)_scrollWindowWidth - 100) / kThumbnailWidth) - 1, 1);
|
||||||
_itemsPerRow = MAX((((int)_w-100) / kThumbnailWidth) -1 , 1);
|
|
||||||
int rows = _gridItems.size() / _itemsPerRow;
|
int rows = _allEntries.size() / _itemsPerRow; // change this to be calced using eindow sizes
|
||||||
|
|
||||||
_innerHeight = 100 + ((rows + 1) * (kThumbnailHeight + 80));
|
_innerHeight = 100 + ((rows + 1) * (kThumbnailHeight + 80));
|
||||||
_innerWidth = 100 + (_itemsPerRow * (kThumbnailWidth + 50));
|
_innerWidth = 100 + (_itemsPerRow * (kThumbnailWidth + 50));
|
||||||
|
|
||||||
if (_scrollPos < -(_innerHeight - _scrollWindowHeight))
|
if (_scrollPos < -(_innerHeight - _scrollWindowHeight))
|
||||||
_scrollPos = -(_innerHeight - _scrollWindowHeight);
|
_scrollPos = -(_innerHeight - _scrollWindowHeight);
|
||||||
int k = 0;
|
|
||||||
for (Common::Array<GridItemWidget *>::iterator i = _gridItems.begin(); i != _gridItems.end(); ++i) {
|
int row = 0;
|
||||||
k = row * _itemsPerRow + col;
|
int col = 0;
|
||||||
if (*i) {
|
|
||||||
(*i)->setPos(50 + col * (kThumbnailWidth + 50), _scrollPos + 50 + row * (kThumbnailHeight + 80));
|
Common::HashMap<Common::String, GridItemWidget *> entryById;
|
||||||
if (((*i)->getRelY() <= -_gridItemHeight) || ((*i)->getRelY() >= _h)) {
|
|
||||||
(*i)->setVisible(false);
|
for (Common::Array<LauncherEntry>::iterator i = _allEntries.begin(); i != _allEntries.end(); ++i) {
|
||||||
|
GridItemWidget *newEntry = entryById[i->domain->getVal("gameid")];
|
||||||
|
if (!newEntry) {
|
||||||
|
newEntry = new GridItemWidget(this,
|
||||||
|
50 + col * (kThumbnailWidth + 50),
|
||||||
|
_scrollPos + 50 + row * (kThumbnailHeight + 80),
|
||||||
|
kThumbnailWidth,
|
||||||
|
kThumbnailHeight+kLineHeight*2);
|
||||||
|
// newEntry = new GridItemWidget(this, 50 + col * (kThumbnailWidth + 50), 50 + row * (kThumbnailHeight + 80), kThumbnailWidth, kThumbnailHeight+kLineHeight*2);
|
||||||
|
|
||||||
|
_gridItems.push_back(newEntry);
|
||||||
|
|
||||||
|
if ((newEntry->getRelY() <= -_gridItemHeight) || (newEntry->getRelY() >= _h)) {
|
||||||
|
newEntry->setVisible(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(*i)->setVisible(true);
|
newEntry->setVisible(true);
|
||||||
}
|
}
|
||||||
// newEntry = new GridItemWidget(this, 50 + col * (kThumbnailWidth + 50), 50 + row * (kThumbnailHeight + 80), kThumbnailWidth, kThumbnailHeight+kLineHeight*2);
|
|
||||||
|
|
||||||
if (++col >= _itemsPerRow) {
|
if (++col >= _itemsPerRow) {
|
||||||
++row;
|
++row;
|
||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
++k;
|
|
||||||
}
|
}
|
||||||
|
newEntry->attachEntry(*i);
|
||||||
|
newEntry->update();
|
||||||
|
entryById[i->domain->getVal("gameid")] = newEntry;
|
||||||
}
|
}
|
||||||
markAsDirty();
|
markAsDirty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,6 +487,7 @@ private:
|
||||||
// Fixing it to 30 for now, 6 items * (4 rows + 1 extra row);
|
// Fixing it to 30 for now, 6 items * (4 rows + 1 extra row);
|
||||||
Common::Array<GridItemWidget *> _gridItems;
|
Common::Array<GridItemWidget *> _gridItems;
|
||||||
Common::Array<LauncherEntry> _allEntries;
|
Common::Array<LauncherEntry> _allEntries;
|
||||||
|
Common::Array<LauncherEntry> _visibleEntries;
|
||||||
Common::HashMap<Common::String, Graphics::ManagedSurface *> _loadedSurfaces;
|
Common::HashMap<Common::String, Graphics::ManagedSurface *> _loadedSurfaces;
|
||||||
// Common::HashMap<Common::String, EntryContainerWidget *> _entryById;
|
// Common::HashMap<Common::String, EntryContainerWidget *> _entryById;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue