From fe7f7f983b9637a9561b574d873fa03d9eeee7fe Mon Sep 17 00:00:00 2001 From: Aloshi Date: Wed, 14 May 2014 17:01:40 -0500 Subject: [PATCH] Added tag to text elements. Accessable with TextComponent::setLineSpacing(float spacing) in C++. --- THEMES.md | 1 + src/ThemeData.cpp | 3 ++- src/ThemeData.h | 1 + src/components/TextComponent.cpp | 23 +++++++++++++++++---- src/components/TextComponent.h | 4 +++- src/guis/GuiScraperStart.cpp | 2 +- src/views/gamelist/DetailedGameListView.cpp | 2 +- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/THEMES.md b/THEMES.md index 1394950d9..cbcf06bfb 100644 --- a/THEMES.md +++ b/THEMES.md @@ -421,6 +421,7 @@ Can be created as an extra. * `alignment` - type: STRING. - Valid values are "left", "center", or "right". Controls alignment on the X axis. "center" will also align vertically. * `forceUppercase` - type: BOOLEAN. Draw text in uppercase. +* `lineSpacing` - type: FLOAT. Controls the space between lines. Default is 1.5. #### textlist diff --git a/src/ThemeData.cpp b/src/ThemeData.cpp index e3b7ede1a..bf16d6765 100644 --- a/src/ThemeData.cpp +++ b/src/ThemeData.cpp @@ -40,7 +40,8 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign:: ("fontPath", PATH) ("fontSize", FLOAT) ("alignment", STRING) - ("forceUppercase", BOOLEAN))) + ("forceUppercase", BOOLEAN) + ("lineSpacing", FLOAT))) ("textlist", makeMap(boost::assign::map_list_of ("pos", NORMALIZED_PAIR) ("size", NORMALIZED_PAIR) diff --git a/src/ThemeData.h b/src/ThemeData.h index b9653d9ba..eea92e67f 100644 --- a/src/ThemeData.h +++ b/src/ThemeData.h @@ -36,6 +36,7 @@ namespace ThemeFlags ALIGNMENT = 256, TEXT = 512, FORCE_UPPERCASE = 1024, + LINE_SPACING = 2048, ALL = 0xFFFFFFFF }; diff --git a/src/components/TextComponent.cpp b/src/components/TextComponent.cpp index 08a711f74..a4d968b6d 100644 --- a/src/components/TextComponent.cpp +++ b/src/components/TextComponent.cpp @@ -7,13 +7,13 @@ #include "../Settings.h" TextComponent::TextComponent(Window* window) : GuiComponent(window), - mFont(Font::get(FONT_SIZE_MEDIUM)), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mAlignment(ALIGN_LEFT) + mFont(Font::get(FONT_SIZE_MEDIUM)), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mAlignment(ALIGN_LEFT), mLineSpacing(1.5f) { } TextComponent::TextComponent(Window* window, const std::string& text, const std::shared_ptr& font, unsigned int color, Alignment align, Eigen::Vector3f pos, Eigen::Vector2f size) : GuiComponent(window), - mFont(NULL), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mAlignment(align) + mFont(NULL), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mAlignment(align), mLineSpacing(1.5f) { setFont(font); setColor(color); @@ -154,9 +154,9 @@ void TextComponent::onTextChanged() text.append(abbrev); - mTextCache = std::shared_ptr(f->buildTextCache(text, Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mAlignment)); + mTextCache = std::shared_ptr(f->buildTextCache(text, Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mAlignment, mLineSpacing)); }else{ - mTextCache = std::shared_ptr(f->buildTextCache(f->wrapText(text, mSize.x()), Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mAlignment)); + mTextCache = std::shared_ptr(f->buildTextCache(f->wrapText(text, mSize.x()), Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mAlignment, mLineSpacing)); } } @@ -168,6 +168,18 @@ void TextComponent::onColorChanged() } } +void TextComponent::setAlignment(Alignment align) +{ + mAlignment = align; + onTextChanged(); +} + +void TextComponent::setLineSpacing(float spacing) +{ + mLineSpacing = spacing; + onTextChanged(); +} + void TextComponent::setValue(const std::string& value) { setText(value); @@ -210,5 +222,8 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, const st if(properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase")); + if(properties & LINE_SPACING && elem->has("lineSpacing")) + setLineSpacing(elem->get("lineSpacing")); + setFont(Font::getFromTheme(elem, properties, mFont)); } diff --git a/src/components/TextComponent.h b/src/components/TextComponent.h index 52dfcb2a0..6d288c5e6 100644 --- a/src/components/TextComponent.h +++ b/src/components/TextComponent.h @@ -23,7 +23,8 @@ public: void onSizeChanged() override; void setText(const std::string& text); void setColor(unsigned int color); - inline void setAlignment(Alignment align) { mAlignment = align; } + void setAlignment(Alignment align); + void setLineSpacing(float spacing); void render(const Eigen::Affine3f& parentTrans) override; @@ -50,6 +51,7 @@ private: std::string mText; std::shared_ptr mTextCache; Alignment mAlignment; + float mLineSpacing; }; #endif diff --git a/src/guis/GuiScraperStart.cpp b/src/guis/GuiScraperStart.cpp index 8ea805472..fc7afd651 100644 --- a/src/guis/GuiScraperStart.cpp +++ b/src/guis/GuiScraperStart.cpp @@ -44,7 +44,7 @@ void GuiScraperStart::pressedStart() if((*it)->getPlatformId() == PlatformIds::PLATFORM_UNKNOWN) { mWindow->pushGui(new GuiMsgBox(mWindow, - "Warning: some of your selected systems do not have a platform ID set. Results may be even more inaccurate than usual!\nContinue anyway?", + strToUpper("Warning: some of your selected systems do not have a platform ID set. Results may be even more inaccurate than usual!\nContinue anyway?"), "YES", std::bind(&GuiScraperStart::start, this), "NO", nullptr)); return; diff --git a/src/views/gamelist/DetailedGameListView.cpp b/src/views/gamelist/DetailedGameListView.cpp index 82bbabb93..a87492a7c 100644 --- a/src/views/gamelist/DetailedGameListView.cpp +++ b/src/views/gamelist/DetailedGameListView.cpp @@ -107,7 +107,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr& them mDescContainer.applyTheme(theme, getName(), "md_description", POSITION | ThemeFlags::SIZE); mDescription.setSize(mDescContainer.getSize().x(), 0); - mDescription.applyTheme(theme, getName(), "md_description", FONT_PATH | FONT_SIZE | COLOR | FORCE_UPPERCASE | ALIGNMENT); + mDescription.applyTheme(theme, getName(), "md_description", ALL ^ (POSITION | ThemeFlags::SIZE | TEXT)); } void DetailedGameListView::initMDLabels()