From 3a98bd38471bd2ae3fff2ad67b92bd3ed9b9c171 Mon Sep 17 00:00:00 2001 From: jrassa Date: Sun, 28 May 2017 21:08:07 -0400 Subject: [PATCH] fixes for gamelist bugs; added option to specify image for selctor bar --- THEMES.md | 8 +++ es-app/src/components/TextListComponent.h | 62 +++++++++++++++++++---- es-core/src/ThemeData.cpp | 4 ++ 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/THEMES.md b/THEMES.md index 6b7db4714..1cd0f5f65 100644 --- a/THEMES.md +++ b/THEMES.md @@ -539,6 +539,14 @@ Can be created as an extra. * `size` - type: NORMALIZED_PAIR. * `selectorColor` - type: COLOR. - Color of the "selector bar." +* `selectorImagePath` - type: PATH. + - Path to image to render in place of "selector bar." +* `selectorImageTile` - type: BOOLEAN. + - If true, the selector image will be tiled instead of stretched to fit its size. +* `selectorHeight` - type: FLOAT. + - Height of the "selector bar". +* `selectorOffsetY` - type: FLOAT. + - Allows moving of the "selector bar" up or down from its computed position. Useful for fine tuning the position of the "selector bar" relative to the text. * `selectedColor` - type: COLOR. - Color of the highlighted entry text. * `primaryColor` - type: COLOR. diff --git a/es-app/src/components/TextListComponent.h b/es-app/src/components/TextListComponent.h index 8067cd739..f6a1313b7 100644 --- a/es-app/src/components/TextListComponent.h +++ b/es-app/src/components/TextListComponent.h @@ -72,6 +72,8 @@ public: it->data.textCache.reset(); } + inline void setSelectorHeight(float selectorScale) { mSelectorHeight = selectorScale; } + inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; } inline void setSelectorColor(unsigned int color) { mSelectorColor = color; } inline void setSelectedColor(unsigned int color) { mSelectedColor = color; } inline void setScrollSound(const std::shared_ptr& sound) { mScrollSound = sound; } @@ -99,16 +101,20 @@ private: std::shared_ptr mFont; bool mUppercase; float mLineSpacing; + float mSelectorHeight; + float mSelectorOffsetY; unsigned int mSelectorColor; unsigned int mSelectedColor; std::shared_ptr mScrollSound; static const unsigned int COLOR_ID_COUNT = 2; unsigned int mColors[COLOR_ID_COUNT]; + + ImageComponent mSelectorImage; }; template TextListComponent::TextListComponent(Window* window) : - IList(window) + IList(window), mSelectorImage(window) { mMarqueeOffset = 0; mMarqueeTime = -MARQUEE_DELAY; @@ -119,6 +125,8 @@ TextListComponent::TextListComponent(Window* window) : mFont = Font::get(FONT_SIZE_MEDIUM); mUppercase = false; mLineSpacing = 1.5f; + mSelectorHeight = mFont->getSize() * 1.5f; + mSelectorOffsetY = 0; mSelectorColor = 0x000000FF; mSelectedColor = 0; mColors[0] = 0x0000FFFF; @@ -135,7 +143,7 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) if(size() == 0) return; - const float entrySize = round(font->getHeight(mLineSpacing)); + const float entrySize = font->getSize() * mLineSpacing; int startEntry = 0; @@ -160,8 +168,13 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) // draw selector bar if(startEntry < listCutoff) { - Renderer::setMatrix(trans); - Renderer::drawRect(0.f, (mCursor - startEntry)*entrySize + (entrySize - font->getHeight())/2, mSize.x(), font->getHeight(), mSelectorColor); + if (mSelectorImage.hasImage()) { + mSelectorImage.setPosition(0.f, (mCursor - startEntry)*entrySize + mSelectorOffsetY, 0.f); + mSelectorImage.render(trans); + } else { + Renderer::setMatrix(trans); + Renderer::drawRect(0.f, (mCursor - startEntry)*entrySize + mSelectorOffsetY, mSize.x(), mSelectorHeight, mSelectorColor); + } } // clip to inside margins @@ -194,14 +207,14 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) break; case ALIGN_CENTER: offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x()) / 2; - if(offset[0] < 0) - offset[0] = 0; + if(offset[0] < mHorizontalMargin) + offset[0] = mHorizontalMargin; break; case ALIGN_RIGHT: offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x()); offset[0] -= mHorizontalMargin; - if(offset[0] < 0) - offset[0] = 0; + if(offset[0] < mHorizontalMargin) + offset[0] = mHorizontalMargin; break; } @@ -277,7 +290,7 @@ void TextListComponent::update(int deltaTime) Eigen::Vector2f textSize = mFont->sizeText(text); //it's long enough to marquee - if(textSize.x() - mMarqueeOffset > mSize.x() - 12 - (mAlignment != ALIGN_CENTER ? mHorizontalMargin : 0)) + if(textSize.x() - mMarqueeOffset > mSize.x() - 12 - mHorizontalMargin * 2) { mMarqueeTime += deltaTime; while(mMarqueeTime > MARQUEE_SPEED) @@ -364,6 +377,33 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, c if(properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase")); - if(properties & LINE_SPACING && elem->has("lineSpacing")) - setLineSpacing(elem->get("lineSpacing")); + if(properties & LINE_SPACING) + { + if(elem->has("lineSpacing")) + setLineSpacing(elem->get("lineSpacing")); + if(elem->has("selectorHeight")) + { + setSelectorHeight(elem->get("selectorHeight") * Renderer::getScreenHeight()); + } else { + setSelectorHeight(mFont->getSize() * 1.5); + } + if(elem->has("selectorOffsetY")) + { + float scale = this->mParent ? this->mParent->getSize().y() : (float)Renderer::getScreenHeight(); + setSelectorOffsetY(elem->get("selectorOffsetY") * scale); + } else { + setSelectorOffsetY(0.0); + } + } + + if (elem->has("selectorImagePath")) + { + std::string path = elem->get("selectorImagePath"); + bool tile = elem->has("selectorImageTile") && elem->get("selectorImageTile"); + mSelectorImage.setImage(path, tile); + mSelectorImage.setSize(mSize.x(), mSelectorHeight); + mSelectorImage.setColorShift(mSelectorColor); + } else { + mSelectorImage.setImage(""); + } } diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index b54299d10..ed6980613 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -52,7 +52,11 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign:: ("textlist", makeMap(boost::assign::map_list_of ("pos", NORMALIZED_PAIR) ("size", NORMALIZED_PAIR) + ("selectorHeight", FLOAT) + ("selectorOffsetY", FLOAT) ("selectorColor", COLOR) + ("selectorImagePath", PATH) + ("selectorImageTile", BOOLEAN) ("selectedColor", COLOR) ("primaryColor", COLOR) ("secondaryColor", COLOR)