From 1aa291ebe76d38ea808ff32bca3f085541bea3e5 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 7 Feb 2014 21:45:28 -0600 Subject: [PATCH] ImageGridComponent & TextListComponent have had common list functionality refactored into IList. --- CMakeLists.txt | 1 - src/components/GuiMenu.cpp | 2 +- src/components/IList.cpp | 81 -------- src/components/IList.h | 216 ++++++++++++++++++-- src/components/ImageGridComponent.h | 127 ++---------- src/components/TextListComponent.h | 174 ++++------------ src/views/gamelist/BasicGameListView.cpp | 8 +- src/views/gamelist/DetailedGameListView.cpp | 4 +- src/views/gamelist/GridGameListView.cpp | 10 +- 9 files changed, 261 insertions(+), 362 deletions(-) delete mode 100644 src/components/IList.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ba440e90..673a4c7ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,6 @@ set(ES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentListComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/DateTimeComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/components/IList.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/RatingComponent.cpp diff --git a/src/components/GuiMenu.cpp b/src/components/GuiMenu.cpp index 5c6f2e437..afd8dbac1 100644 --- a/src/components/GuiMenu.cpp +++ b/src/components/GuiMenu.cpp @@ -62,7 +62,7 @@ bool GuiMenu::input(InputConfig* config, Input input) Sound::getFromTheme(mTheme, "menu", "menuClose")->play(); delete this; return true; - }else if(config->isMappedTo("a", input) && mList.getList().size() > 0) + }else if(config->isMappedTo("a", input) && mList.size() > 0) { mList.getSelected()(); delete this; diff --git a/src/components/IList.cpp b/src/components/IList.cpp deleted file mode 100644 index 148cd429e..000000000 --- a/src/components/IList.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "IList.h" - -const IList::ScrollTier IList::SCROLL_SPEED[IList::SCROLL_SPEED_COUNT] = { - {500, 500}, - {2600, 150}, - {0, 100} -}; - -IList::IList() -{ - mScrollTier = 0; - mScrollVelocity = 0; - mScrollTierAccumulator = 0; - mScrollCursorAccumulator = 0; -} - -void IList::listInput(int velocity) -{ - mScrollVelocity = velocity; - mScrollTier = 0; - mScrollTierAccumulator = 0; - mScrollCursorAccumulator = 0; - scroll(mScrollVelocity); -} - -void IList::listUpdate(int deltaTime) -{ - if(mScrollVelocity == 0 || getLength() < 2) - return; - - mScrollCursorAccumulator += deltaTime; - mScrollTierAccumulator += deltaTime; - - while(mScrollCursorAccumulator >= SCROLL_SPEED[mScrollTier].scrollDelay) - { - mScrollCursorAccumulator -= SCROLL_SPEED[mScrollTier].scrollDelay; - scroll(mScrollVelocity); - } - - // are we ready to go even FASTER? - while(mScrollTier < SCROLL_SPEED_COUNT - 1 && mScrollTierAccumulator >= SCROLL_SPEED[mScrollTier].length) - { - mScrollTierAccumulator -= SCROLL_SPEED[mScrollTier].length; - mScrollTier++; - } -} - -void IList::scroll(int amt) -{ - if(mScrollVelocity == 0 || getLength() < 2) - return; - - int cursor = getCursorIndex() + amt; - int absAmt = amt < 0 ? -amt : amt; - - // stop at the end if we've been holding down the button for a long time or - // we're scrolling faster than one item at a time (e.g. page up/down) - // otherwise, loop around - if(mScrollTier > 0 || absAmt > 1) - { - if(cursor < 0) - cursor = 0; - else if(cursor >= getLength()) - cursor = getLength() - 1; - }else{ - if(cursor < 0) - cursor += getLength(); - else if(cursor >= getLength()) - cursor -= getLength(); - } - - if(cursor != getCursorIndex()) - onScroll(absAmt); - - setCursorIndex(cursor); -} - -bool IList::isScrolling() const -{ - return (mScrollVelocity != 0 && mScrollTier > 0); -} diff --git a/src/components/IList.h b/src/components/IList.h index 04417584c..469f7f06d 100644 --- a/src/components/IList.h +++ b/src/components/IList.h @@ -1,36 +1,210 @@ #pragma once +#include +#include + +enum CursorState +{ + CURSOR_STOPPED, + CURSOR_SCROLLING +}; + +struct ScrollTier +{ + int length; // how long we stay on this level before going to the next + int scrollDelay; // how long between scrolls +}; + +const int SCROLL_SPEED_COUNT = 3; +const ScrollTier SCROLL_SPEED[SCROLL_SPEED_COUNT] = { + {500, 500}, + {2600, 150}, + {0, 100} +}; + +template class IList { public: - IList(); - - bool isScrolling() const; - -protected: - void listInput(int velocity); // a velocity of 0 = stop scrolling - void listUpdate(int deltaTime); - - virtual int getCursorIndex() = 0; - virtual void setCursorIndex(int index) = 0; // (index >= 0 && index < getLength()) is guaranteed to be true - virtual int getLength() = 0; - - void scroll(int amt); - virtual void onScroll(int amt) {}; - -private: - struct ScrollTier + struct Entry { - int length; // how long we stay on this level before going to the next - int scrollDelay; // how long between scrolls + std::string name; + UserData object; + EntryData data; }; - static const int SCROLL_SPEED_COUNT = 3; - static const ScrollTier SCROLL_SPEED[SCROLL_SPEED_COUNT]; +protected: + int mCursor; int mScrollTier; int mScrollVelocity; int mScrollTierAccumulator; int mScrollCursorAccumulator; + + std::vector mEntries; + +public: + IList() + { + mCursor = 0; + mScrollTier = 0; + mScrollVelocity = 0; + mScrollTierAccumulator = 0; + mScrollCursorAccumulator = 0; + } + + bool isScrolling() const + { + return (mScrollVelocity != 0 && mScrollTier > 0); + } + + void stopScrolling() + { + listInput(0); + onCursorChanged(CURSOR_STOPPED); + } + + void clear() + { + mEntries.clear(); + mCursor = 0; + listInput(0); + onCursorChanged(CURSOR_STOPPED); + } + + inline const std::string& getSelectedName() + { + assert(size() > 0); + return mEntries.at(mCursor).name; + } + + inline const UserData& getSelected() const + { + assert(size() > 0); + return mEntries.at(mCursor).object; + } + + void setCursor(typename std::vector::iterator& it) + { + assert(it != mEntries.end()); + mCursor = it - mEntries.begin(); + onCursorChanged(CURSOR_STOPPED); + } + + // returns true if successful (select is in our list), false if not + bool setCursor(const UserData& obj) + { + for(auto it = mEntries.begin(); it != mEntries.end(); it++) + { + if((*it).object == obj) + { + mCursor = it - mEntries.begin(); + onCursorChanged(CURSOR_STOPPED); + return true; + } + } + + return false; + } + + // entry management + void add(Entry e) + { + mEntries.push_back(e); + } + + bool remove(const UserData& obj) + { + for(auto it = mEntries.begin(); it != mEntries.end(); it++) + { + if((*it).object == obj) + { + remove(it); + return true; + } + } + + return false; + } + + inline int size() const { return mEntries.size(); } + +protected: + void remove(typename std::vector::iterator& it) + { + if(getCursorIndex() > 0 && it - mEntries.begin() <= getCursorIndex()) + { + setCursorIndex(mCursor - 1); + onCursorChanged(CURSOR_STOPPED); + } + + mEntries.erase(it); + } + + + void listInput(int velocity) // a velocity of 0 = stop scrolling + { + mScrollVelocity = velocity; + mScrollTier = 0; + mScrollTierAccumulator = 0; + mScrollCursorAccumulator = 0; + scroll(mScrollVelocity); + } + + void listUpdate(int deltaTime) + { + if(mScrollVelocity == 0 || size() < 2) + return; + + mScrollCursorAccumulator += deltaTime; + mScrollTierAccumulator += deltaTime; + + while(mScrollCursorAccumulator >= SCROLL_SPEED[mScrollTier].scrollDelay) + { + mScrollCursorAccumulator -= SCROLL_SPEED[mScrollTier].scrollDelay; + scroll(mScrollVelocity); + } + + // are we ready to go even FASTER? + while(mScrollTier < SCROLL_SPEED_COUNT - 1 && mScrollTierAccumulator >= SCROLL_SPEED[mScrollTier].length) + { + mScrollTierAccumulator -= SCROLL_SPEED[mScrollTier].length; + mScrollTier++; + } + } + + void scroll(int amt) + { + if(mScrollVelocity == 0 || size() < 2) + return; + + int cursor = mCursor + amt; + int absAmt = amt < 0 ? -amt : amt; + + // stop at the end if we've been holding down the button for a long time or + // we're scrolling faster than one item at a time (e.g. page up/down) + // otherwise, loop around + if(mScrollTier > 0 || absAmt > 1) + { + if(cursor < 0) + cursor = 0; + else if(cursor >= size()) + cursor = size() - 1; + }else{ + if(cursor < 0) + cursor += size(); + else if(cursor >= size()) + cursor -= size(); + } + + if(cursor != mCursor) + onScroll(absAmt); + + mCursor = cursor; + onCursorChanged((mScrollTier > 0) ? CURSOR_SCROLLING : CURSOR_STOPPED); + } + + virtual void onCursorChanged(const CursorState& state) {} + virtual void onScroll(int amt) {} }; diff --git a/src/components/ImageGridComponent.h b/src/components/ImageGridComponent.h index d2f8529cf..012c3e655 100644 --- a/src/components/ImageGridComponent.h +++ b/src/components/ImageGridComponent.h @@ -5,49 +5,25 @@ #include "../components/ImageComponent.h" #include "../Log.h" +struct ImageGridData +{ + std::shared_ptr texture; +}; + template -class ImageGridComponent : public GuiComponent, public IList +class ImageGridComponent : public GuiComponent, public IList { public: ImageGridComponent(Window* window); - struct Entry - { - std::shared_ptr texture; - T object; - - Entry() {} - Entry(std::shared_ptr t, const T& o) : texture(t), object(o) {} - }; - - void add(const std::string& imagePath, const T& obj); - void remove(const T& obj); - void clear(); - - void setCursor(const T& select); - void setCursor(typename std::vector::const_iterator& it); - - inline const T& getSelected() const { return mEntries.at(mCursor).object; } - inline const std::vector& getList() const { return mEntries; } - - enum CursorState { - CURSOR_STOPPED, - CURSOR_SCROLLING - }; - - void stopScrolling(); - + void add(const std::string& name, const std::string& imagePath, const T& obj); + void onSizeChanged() override; bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Eigen::Affine3f& parentTrans) override; -protected: - virtual int getCursorIndex() { return mCursor; } - virtual void setCursorIndex(int index) { mCursor = index; onCursorChanged(CURSOR_STOPPED); } - virtual int getLength() { return mEntries.size(); } - private: Eigen::Vector2f getSquareSize(std::shared_ptr tex = nullptr) const { @@ -73,7 +49,7 @@ private: // calc biggest square size for(auto it = mEntries.begin(); it != mEntries.end(); it++) { - Eigen::Vector2f chkSize = getSquareSize(it->texture); + Eigen::Vector2f chkSize = getSquareSize(it->data.texture); if(chkSize.x() > squareSize.x()) squareSize[0] = chkSize[0]; if(chkSize.y() > squareSize.y()) @@ -95,13 +71,10 @@ private: void buildImages(); void updateImages(); - void onCursorChanged(CursorState state); - - int mCursor; + virtual void onCursorChanged(const CursorState& state); bool mEntriesDirty; - std::vector mEntries; std::vector mImages; }; @@ -109,79 +82,19 @@ template ImageGridComponent::ImageGridComponent(Window* window) : GuiComponent(window) { mEntriesDirty = true; - mCursor = 0; } template -void ImageGridComponent::add(const std::string& imagePath, const T& obj) +void ImageGridComponent::add(const std::string& name, const std::string& imagePath, const T& obj) { - Entry e(ResourceManager::getInstance()->fileExists(imagePath) ? TextureResource::get(imagePath) : TextureResource::get(":/button.png"), obj); - mEntries.push_back(e); + Entry entry; + entry.name = name; + entry.object = obj; + entry.data.texture = ResourceManager::getInstance()->fileExists(imagePath) ? TextureResource::get(imagePath) : TextureResource::get(":/button.png"); + static_cast*>(this)->add(entry); mEntriesDirty = true; } -template -void ImageGridComponent::remove(const T& obj) -{ - for(auto it = mEntries.begin(); it != mEntries.end(); it++) - { - if((*it).object == obj) - { - if(mCursor > 0 && it - mEntries.begin() >= mCursor) - { - mCursor--; - onCursorChanged(CURSOR_STOPPED); - } - - mEntriesDirty = true; - mEntries.erase(it); - return; - } - } - - LOG(LogError) << "Tried to remove an object we couldn't find"; -} - -template -void ImageGridComponent::clear() -{ - mEntries.clear(); - mCursor = 0; - onCursorChanged(CURSOR_STOPPED); - mEntriesDirty = true; -} - -template -void ImageGridComponent::setCursor(const T& obj) -{ - for(auto it = mEntries.begin(); it != mEntries.end(); it++) - { - if((*it).object == obj) - { - mCursor = it - mEntries.begin(); - onCursorChanged(CURSOR_STOPPED); - return; - } - } - - LOG(LogError) << "Tried to set cursor to object we couldn't find"; -} - -template -void ImageGridComponent::setCursor(typename std::vector::const_iterator& it) -{ - assert(it != mEntries.end()); - mCursor = it - mEntries.begin(); - onCursorChanged(CURSOR_STOPPED); -} - -template -void ImageGridComponent::stopScrolling() -{ - listInput(0); - onCursorChanged(CURSOR_STOPPED); -} - template bool ImageGridComponent::input(InputConfig* config, Input input) { @@ -239,7 +152,7 @@ void ImageGridComponent::render(const Eigen::Affine3f& parentTrans) } template -void ImageGridComponent::onCursorChanged(CursorState state) +void ImageGridComponent::onCursorChanged(const CursorState& state) { updateImages(); } @@ -305,13 +218,13 @@ void ImageGridComponent::updateImages() for(unsigned int img = 0; img < mImages.size(); img++) { ImageComponent& image = mImages.at(img); - if(i >= mEntries.size()) + if(i >= (unsigned int)size()) { image.setImage(""); continue; } - Eigen::Vector2f squareSize = getSquareSize(mEntries.at(i).texture); + Eigen::Vector2f squareSize = getSquareSize(mEntries.at(i).data.texture); if(i == mCursor) { image.setColorShift(0xFFFFFFFF); @@ -321,7 +234,7 @@ void ImageGridComponent::updateImages() image.setResize(squareSize.x(), squareSize.y()); } - image.setImage(mEntries.at(i).texture); + image.setImage(mEntries.at(i).data.texture); i++; } } diff --git a/src/components/TextListComponent.h b/src/components/TextListComponent.h index 74246c15f..2af7f703b 100644 --- a/src/components/TextListComponent.h +++ b/src/components/TextListComponent.h @@ -13,46 +13,26 @@ #include "../ThemeData.h" #include +struct TextListData +{ + unsigned int colorId; + std::shared_ptr textCache; +}; + //A graphical list. Supports multiple colors for rows and scrolling. template -class TextListComponent : public GuiComponent, public IList +class TextListComponent : public GuiComponent, public IList { public: TextListComponent(Window* window); - virtual ~TextListComponent(); - + bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Eigen::Affine3f& parentTrans) override; void applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, unsigned int properties) override; - struct ListRow - { - std::string name; - T object; - unsigned int colorId; - std::shared_ptr textCache; - }; - void add(const std::string& name, const T& obj, unsigned int colorId); - void remove(const T& obj); - void clear(); - - inline const std::string& getSelectedName() const { return mRowVector.at(mCursor).name; } - inline T getSelected() const { return mRowVector.at(mCursor).object; } - inline const std::vector& getList() const { return mRowVector; } - - void setCursor(const T& select); - void setCursor(typename std::vector::const_iterator& it); - - void stopScrolling(); - enum CursorState - { - CURSOR_STOPPED, - CURSOR_SCROLLING - }; - enum Alignment { ALIGN_LEFT, @@ -67,8 +47,8 @@ public: inline void setFont(const std::shared_ptr& font) { mFont = font; - for(auto it = mRowVector.begin(); it != mRowVector.end(); it++) - it->textCache.reset(); + for(auto it = mEntries.begin(); it != mEntries.end(); it++) + it->data.textCache.reset(); } inline void setSelectorColor(unsigned int color) { mSelectorColor = color; } @@ -78,28 +58,20 @@ public: inline void setSound(const std::shared_ptr& sound) { mScrollSound = sound; } protected: - // IList implementations - virtual int getCursorIndex() { return mCursor; } - virtual void setCursorIndex(int index) { mCursor = index; onCursorChanged(isScrolling() ? CURSOR_SCROLLING : CURSOR_STOPPED); } - virtual int getLength() { return mRowVector.size(); } virtual void onScroll(int amt) { if(mScrollSound) mScrollSound->play(); } + virtual void onCursorChanged(const CursorState& state); private: static const int MARQUEE_DELAY = 900; static const int MARQUEE_SPEED = 16; static const int MARQUEE_RATE = 3; - void onCursorChanged(CursorState state); - int mMarqueeOffset; int mMarqueeTime; Alignment mAlignment; float mHorizontalMargin; - std::vector mRowVector; - int mCursor; - std::function mCursorChangedCallback; std::shared_ptr mFont; @@ -114,8 +86,6 @@ template TextListComponent::TextListComponent(Window* window) : GuiComponent(window) { - mCursor = 0; - mMarqueeOffset = 0; mMarqueeTime = -MARQUEE_DELAY; @@ -129,11 +99,6 @@ TextListComponent::TextListComponent(Window* window) : mColors[1] = 0x00FF00FF; } -template -TextListComponent::~TextListComponent() -{ -} - template void TextListComponent::render(const Eigen::Affine3f& parentTrans) { @@ -141,6 +106,13 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) std::shared_ptr& font = mFont; + if(size() == 0) + { + Renderer::setMatrix(trans); + font->drawText("The list is empty.", Eigen::Vector2f(0, 0), 0xFF0000FF); + return; + } + const int cutoff = 0; const int entrySize = font->getHeight() + 5; @@ -149,26 +121,20 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) //number of entries that can fit on the screen simultaniously int screenCount = (int)mSize.y() / entrySize; - if((int)mRowVector.size() >= screenCount) + if(size() >= screenCount) { startEntry = mCursor - (int)(screenCount * 0.5); if(startEntry < 0) startEntry = 0; - if(startEntry >= (int)mRowVector.size() - screenCount) - startEntry = mRowVector.size() - screenCount; + if(startEntry >= size() - screenCount) + startEntry = size() - screenCount; } float y = (float)cutoff; - if(mRowVector.size() == 0) - { - font->drawCenteredText("The list is empty.", 0, y, 0xFF0000FF); - return; - } - int listCutoff = startEntry + screenCount; - if(listCutoff > (int)mRowVector.size()) - listCutoff = mRowVector.size(); + if(listCutoff > size()) + listCutoff = size(); Eigen::Vector3f dim(getSize().x(), getSize().y(), 0); dim = trans * dim - trans.translation(); @@ -183,18 +149,18 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) Renderer::drawRect(0, (int)y, (int)getSize().x(), font->getHeight(), mSelectorColor); } - ListRow& row = mRowVector.at((unsigned int)i); + Entry& entry = mEntries.at((unsigned int)i); unsigned int color; if(mCursor == i && mSelectedColor) color = mSelectedColor; else - color = mColors[row.colorId]; + color = mColors[entry.data.colorId]; - if(!row.textCache) - row.textCache = std::unique_ptr(font->buildTextCache(row.name, 0, 0, 0x000000FF)); + if(!entry.data.textCache) + entry.data.textCache = std::unique_ptr(font->buildTextCache(entry.name, 0, 0, 0x000000FF)); - row.textCache->setColor(color); + entry.data.textCache->setColor(color); Eigen::Vector3f offset(0, y, 0); @@ -204,12 +170,12 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) offset[0] = mHorizontalMargin; break; case ALIGN_CENTER: - offset[0] = (mSize.x() - row.textCache->metrics.size.x()) / 2; + offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x()) / 2; if(offset[0] < 0) offset[0] = 0; break; case ALIGN_RIGHT: - offset[0] = (mSize.x() - row.textCache->metrics.size.x()); + offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x()); offset[0] -= mHorizontalMargin; if(offset[0] < 0) offset[0] = 0; @@ -224,7 +190,7 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) drawTrans.translate(offset); Renderer::setMatrix(drawTrans); - font->renderTextCache(row.textCache.get()); + font->renderTextCache(entry.data.textCache.get()); y += entrySize; } @@ -237,7 +203,7 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) template bool TextListComponent::input(InputConfig* config, Input input) { - if(mRowVector.size() > 0) + if(size() > 0) { if(input.value != 0) { @@ -279,10 +245,10 @@ template void TextListComponent::update(int deltaTime) { listUpdate(deltaTime); - if(!isScrolling()) + if(!isScrolling() && size() > 0) { //if we're not scrolling and this object's text goes outside our size, marquee it! - std::string text = getSelectedName(); + const std::string& text = mEntries.at((unsigned int)mCursor).name; Eigen::Vector2f textSize = mFont->sizeText(text); @@ -307,68 +273,15 @@ void TextListComponent::add(const std::string& name, const T& obj, unsigned i { assert(color < COLOR_ID_COUNT); - ListRow row = {name, obj, color}; - mRowVector.push_back(row); + Entry entry; + entry.name = name; + entry.object = obj; + entry.data.colorId = color; + static_cast*>(this)->add(entry); } template -void TextListComponent::remove(const T& obj) -{ - for(auto it = mRowVector.begin(); it != mRowVector.end(); it++) - { - if((*it).object == obj) - { - if(mCursor > 0 && it - mRowVector.begin() >= mCursor) - { - mCursor--; - onCursorChanged(CURSOR_STOPPED); - } - - mRowVector.erase(it); - return; - } - } - - LOG(LogError) << "Tried to remove an object we couldn't find"; -} - -template -void TextListComponent::clear() -{ - mRowVector.clear(); - mCursor = 0; - mMarqueeOffset = 0; - mMarqueeTime = -MARQUEE_DELAY; - onCursorChanged(CURSOR_STOPPED); -} - -template -void TextListComponent::setCursor(const T& obj) -{ - for(auto it = mRowVector.begin(); it != mRowVector.end(); it++) - { - if((*it).object == obj) - { - mCursor = it - mRowVector.begin(); - onCursorChanged(CURSOR_STOPPED); - return; - } - } - - LOG(LogError) << "Tried to set cursor to object we couldn't find"; -} - - -template -void TextListComponent::setCursor(typename std::vector::const_iterator& it) -{ - assert(it != mRowVector.end()); - mCursor = it - mRowVector.begin(); - onCursorChanged(CURSOR_STOPPED); -} - -template -void TextListComponent::onCursorChanged(CursorState state) +void TextListComponent::onCursorChanged(const CursorState& state) { mMarqueeOffset = 0; mMarqueeTime = -MARQUEE_DELAY; @@ -377,13 +290,6 @@ void TextListComponent::onCursorChanged(CursorState state) mCursorChangedCallback(state); } -template -void TextListComponent::stopScrolling() -{ - listInput(0); - onCursorChanged(CURSOR_STOPPED); -} - template void TextListComponent::applyTheme(const std::shared_ptr& theme, const std::string& view, const std::string& element, unsigned int properties) { diff --git a/src/views/gamelist/BasicGameListView.cpp b/src/views/gamelist/BasicGameListView.cpp index 62fc6e7cb..24a3fa62f 100644 --- a/src/views/gamelist/BasicGameListView.cpp +++ b/src/views/gamelist/BasicGameListView.cpp @@ -53,14 +53,8 @@ FileData* BasicGameListView::getCursor() void BasicGameListView::setCursor(FileData* cursor) { - typedef TextListComponent::ListRow Row; - const std::vector& list = mList.getList(); - auto found = std::find_if(list.begin(), list.end(), [&](const Row& row) { return (row.object == cursor); }); - - if(found != list.end()) + if(!mList.setCursor(cursor)) { - mList.setCursor(found); - }else{ populateList(cursor->getParent()->getChildren()); mList.setCursor(cursor); } diff --git a/src/views/gamelist/DetailedGameListView.cpp b/src/views/gamelist/DetailedGameListView.cpp index 7eefa51c9..d4b8f2dda 100644 --- a/src/views/gamelist/DetailedGameListView.cpp +++ b/src/views/gamelist/DetailedGameListView.cpp @@ -21,7 +21,7 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) : mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y()); mList.setSize(mSize.x() * (0.50f - 2*padding), mList.getSize().y()); mList.setAlignment(TextListComponent::ALIGN_LEFT); - mList.setCursorChangedCallback([&](TextListComponent::CursorState state) { updateInfoPanel(); }); + mList.setCursorChangedCallback([&](const CursorState& state) { updateInfoPanel(); }); // image mImage.setOrigin(0.5f, 0.5f); @@ -179,7 +179,7 @@ void DetailedGameListView::initMDValues() void DetailedGameListView::updateInfoPanel() { - FileData* file = (mList.getList().size() == 0 || mList.isScrolling()) ? NULL : mList.getSelected(); + FileData* file = (mList.size() == 0 || mList.isScrolling()) ? NULL : mList.getSelected(); bool fadingOut; if(file == NULL) diff --git a/src/views/gamelist/GridGameListView.cpp b/src/views/gamelist/GridGameListView.cpp index 42978ee74..bebd20c67 100644 --- a/src/views/gamelist/GridGameListView.cpp +++ b/src/views/gamelist/GridGameListView.cpp @@ -20,14 +20,8 @@ FileData* GridGameListView::getCursor() void GridGameListView::setCursor(FileData* file) { - typedef ImageGridComponent::Entry Entry; - auto& list = mGrid.getList(); - auto found = std::find_if(list.begin(), list.end(), [&] (const Entry& e) { return (e.object == file); }); - - if(found != list.end()) + if(!mGrid.setCursor(file)) { - mGrid.setCursor(found); - }else{ populateList(file->getParent()->getChildren()); mGrid.setCursor(file); } @@ -46,7 +40,7 @@ void GridGameListView::populateList(const std::vector& files) mGrid.clear(); for(auto it = files.begin(); it != files.end(); it++) { - mGrid.add((*it)->getThumbnailPath(), *it); + mGrid.add((*it)->getName(), (*it)->getThumbnailPath(), *it); } }