Commit ffe359dc authored by John Rassa's avatar John Rassa Committed by Subs

carousel enhancements

parent 095628c6
......@@ -674,17 +674,32 @@ EmulationStation borrows the concept of "nine patches" from Android (or "9-Slice
#### carousel
* `type` - type: STRING.
- Accepted values are "horizontal" or "vertical". Sets the scoll direction of the carousel.
- Default is "horizontal".
- Sets the scoll direction of the carousel.
- Accepted values are "horizontal", "vertical" or "vertical_wheel".
- Default is "horizontal".
* `size` - type: NORMALIZED_PAIR. Default is "1 0.2325"
* `pos` - type: NORMALIZED_PAIR. Default is "0 0.38375".
* `origin` - type: NORMALIZED_PAIR.
- Where on the carousel `pos` refers to. For example, an origin of `0.5 0.5` and a `pos` of `0.5 0.5` would place the carousel exactly in the middle of the screen. If the "POSITION" and "SIZE" attributes are themable, "ORIGIN" is implied.
* `color` - type: COLOR.
- Controls the color of the carousel background.
- Default is FFFFFFD8
* `logoSize` - type: NORMALIZED_PAIR. Default is "0.25 0.155"
* `logoScale` - type: FLOAT.
* Selected logo is increased in size by this scale
* Default is 1.2
- Selected logo is increased in size by this scale
- Default is 1.2
* `logoRotation` - type: FLOAT.
- Angle in degrees that the logos should be rotated. Value should be positive.
- Default is 7.5
- This property only applies when `type` is "vertical_wheel".
* `logoRotationOrigin` - type: NORMALIZED_PAIR.
- Point around which the logos will be rotated. Defaults to `-5 0.5`.
- This property only applies when `type` is "vertical_wheel".
* `logoAlignment` - type: STRING.
- Sets the alignment of the logos relative to the carousel.
- Accepted values are "top", "bottom" or "center" when `type` is "horizontal".
- Accepted values are "left", "right" or "center" when `type` is "vertical" or "vertical_wheel".
- Default is "center"
* `maxLogoCount` - type: FLOAT.
- Sets the number of logos to display in the carousel.
- Default is 3
......
......@@ -19,14 +19,14 @@ GuiFastSelect::GuiFastSelect(Window* window, IGameListView* gamelist) : GuiCompo
addChild(&mBackground);
mLetterText.setSize(mSize.x(), mSize.y() * 0.75f);
mLetterText.setAlignment(ALIGN_CENTER);
mLetterText.setHorizontalAlignment(ALIGN_CENTER);
mLetterText.applyTheme(theme, "fastSelect", "letter", FONT_PATH | COLOR);
// TODO - set font size
addChild(&mLetterText);
mSortText.setPosition(0, mSize.y() * 0.75f);
mSortText.setSize(mSize.x(), mSize.y() * 0.25f);
mSortText.setAlignment(ALIGN_CENTER);
mSortText.setHorizontalAlignment(ALIGN_CENTER);
mSortText.applyTheme(theme, "fastSelect", "subtext", FONT_PATH | COLOR);
// TODO - set font size
addChild(&mSortText);
......
......@@ -1378,7 +1378,7 @@ GuiMenu::GuiMenu(Window *window) : GuiComponent(window), mMenu(window, _("MAIN M
mVersion.setColor(menuTheme->menuFooter.color);
mVersion.setText("RB EMULATIONSTATION V" + strToUpper(PROGRAM_VERSION_STRING));
mVersion.setAlignment(ALIGN_CENTER);
mVersion.setHorizontalAlignment(ALIGN_CENTER);
addChild(&mMenu);
addChild(&mVersion);
......
This diff is collapsed.
......@@ -13,13 +13,13 @@ class AnimatedImageComponent;
enum CarouselType : unsigned int
{
HORIZONTAL = 0,
VERTICAL = 1
VERTICAL = 1,
VERTICAL_WHEEL = 2
};
struct SystemViewData
{
std::shared_ptr<GuiComponent> logo;
std::shared_ptr<GuiComponent> logoSelected;
std::vector<GuiComponent*> backgroundExtras;
};
......@@ -28,8 +28,11 @@ struct SystemViewCarousel
CarouselType type;
Eigen::Vector2f pos;
Eigen::Vector2f size;
Eigen::Vector2f origin;
float logoScale;
Eigen::Vector2f logoSpacing;
float logoRotation;
Eigen::Vector2f logoRotationOrigin;
Alignment logoAlignment;
unsigned int color;
int maxLogoCount; // number of logos shown on the carousel
Eigen::Vector2f logoSize;
......@@ -41,6 +44,9 @@ class SystemView : public IList<SystemViewData, SystemData*>
public:
SystemView(Window* window);
virtual void onShow() override ;
virtual void onHide() override ;
void goToSystem(SystemData* system, bool animate);
bool input(InputConfig* config, Input input) override;
......@@ -80,4 +86,5 @@ private:
float mExtrasFadeOpacity;
SystemData * lastSystem;
bool mViewNeedsReload;
bool mShowing;
};
......@@ -74,6 +74,7 @@ void ViewController::goToSystemView(SystemData* system)
systemList->setPosition(getSystemId(system) * (float)Renderer::getScreenWidth(), systemList->getPosition().y());
systemList->goToSystem(system, false);
mCurrentView = systemList;
mCurrentView->onShow();
playViewTransition();
}
......
......@@ -16,7 +16,7 @@ mHeaderText(window), mHeaderImage(window), mBackground(window), mFavoriteChange(
mHeaderText.setText("Logo Text");
mHeaderText.setSize(mSize.x(), 0);
mHeaderText.setPosition(0, 0);
mHeaderText.setAlignment(ALIGN_CENTER);
mHeaderText.setHorizontalAlignment(ALIGN_CENTER);
mHeaderText.setDefaultZIndex(50);
mHeaderImage.setResize(0, mSize.y() * 0.185f);
......
This diff is collapsed.
......@@ -132,7 +132,6 @@ float GuiComponent::getScale() const
void GuiComponent::setScale(float scale)
{
mScale = scale;
onSizeChanged();
}
float GuiComponent::getZIndex() const
......@@ -455,3 +454,15 @@ bool GuiComponent::isProcessing() const
{
return mIsProcessing;
}
void GuiComponent::onShow()
{
for(unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->onShow();
}
void GuiComponent::onHide()
{
for(unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->onHide();
}
......@@ -107,6 +107,9 @@ public:
virtual void onFocusGained() {};
virtual void onFocusLost() {};
virtual void onShow();
virtual void onHide();
// Default implementation just handles <pos> and <size> tags as normalized float pairs.
// You probably want to keep this behavior for any derived classes as well as add your own.
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties);
......
......@@ -125,9 +125,13 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::
("type", STRING)
("size", NORMALIZED_PAIR)
("pos", NORMALIZED_PAIR)
("origin", NORMALIZED_PAIR)
("color", COLOR)
("logoScale", FLOAT)
("logoRotation", FLOAT)
("logoRotationOrigin", NORMALIZED_PAIR)
("logoSize", NORMALIZED_PAIR)
("logoAlignment", STRING)
("maxLogoCount", FLOAT)
("zIndex", FLOAT)))
("menuBackground", makeMap(boost::assign::map_list_of
......
......@@ -24,7 +24,7 @@ MenuComponent::MenuComponent(Window* window, const char* title, const std::share
// set up title
mTitle = std::make_shared<TextComponent>(mWindow);
mTitle->setAlignment(ALIGN_CENTER);
mTitle->setHorizontalAlignment(ALIGN_CENTER);
setTitle(title, menuTheme->menuTitle.font);
mTitle->setColor(menuTheme->menuTitle.color);
......
......@@ -159,7 +159,7 @@ public:
mText.setFont(font);
mText.setColor(color);
mText.setAlignment(ALIGN_CENTER);
mText.setHorizontalAlignment(ALIGN_CENTER);
addChild(&mText);
if(mMultiSelect)
......
......@@ -8,13 +8,13 @@
#include "Locale.h"
TextComponent::TextComponent(Window* window) : GuiComponent(window),
mFont(Font::get(FONT_SIZE_MEDIUM)), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mAlignment(ALIGN_LEFT), mLineSpacing(1.5f), mBgColor(0), mRenderBackground(false)
mFont(Font::get(FONT_SIZE_MEDIUM)), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mHorizontalAlignment(ALIGN_LEFT), mVerticalAlignment(ALIGN_CENTER), mLineSpacing(1.5f), mBgColor(0), mRenderBackground(false)
{
}
TextComponent::TextComponent(Window* window, const std::string& text, const std::shared_ptr<Font>& font, unsigned int color, Alignment align,
Eigen::Vector3f pos, Eigen::Vector2f size, unsigned int bgcolor) : GuiComponent(window),
mFont(NULL), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mAlignment(align), mLineSpacing(1.5f), mBgColor(0), mRenderBackground(false)
mFont(NULL), mUppercase(false), mColor(0x000000FF), mAutoCalcExtent(true, true), mHorizontalAlignment(ALIGN_LEFT), mVerticalAlignment(ALIGN_CENTER), mLineSpacing(1.5f), mBgColor(0), mRenderBackground(false)
{
setFont(font);
setColor(color);
......@@ -108,7 +108,20 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans)
if(mTextCache)
{
const Eigen::Vector2f& textSize = mTextCache->metrics.size;
Eigen::Vector3f off(0, (getSize().y() - textSize.y()) / 2.0f, 0);
float yOff;
switch(mVerticalAlignment)
{
case ALIGN_TOP:
yOff = 0;
break;
case ALIGN_BOTTOM:
yOff = (getSize().y() - textSize.y());
break;
case ALIGN_CENTER:
yOff = (getSize().y() - textSize.y()) / 2.0f;
break;
}
Eigen::Vector3f off(0, yOff, 0);
if(Settings::getInstance()->getBool("DebugText"))
{
......@@ -124,7 +137,7 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans)
// draw the text area, where the text actually is going
if(Settings::getInstance()->getBool("DebugText"))
{
switch(mAlignment)
switch(mHorizontalAlignment)
{
case ALIGN_LEFT:
Renderer::drawRect(0.0f, 0.0f, mTextCache->metrics.size.x(), mTextCache->metrics.size.y(), 0x00000033);
......@@ -195,9 +208,9 @@ void TextComponent::onTextChanged()
text.append(abbrev);
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(text, Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mAlignment, mLineSpacing));
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(text, Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mHorizontalAlignment, mLineSpacing));
}else{
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(f->wrapText(text, mSize.x()), Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mAlignment, mLineSpacing));
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(f->wrapText(text, mSize.x()), Eigen::Vector2f(0, 0), (mColor >> 8 << 8) | mOpacity, mSize.x(), mHorizontalAlignment, mLineSpacing));
}
}
......@@ -209,12 +222,17 @@ void TextComponent::onColorChanged()
}
}
void TextComponent::setAlignment(Alignment align)
void TextComponent::setHorizontalAlignment(Alignment align)
{
mAlignment = align;
mHorizontalAlignment = align;
onTextChanged();
}
void TextComponent::setVerticalAlignment(Alignment align)
{
mVerticalAlignment = align;
}
void TextComponent::setLineSpacing(float spacing)
{
mLineSpacing = spacing;
......@@ -254,11 +272,11 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const st
{
std::string str = elem->get<std::string>("alignment");
if(str == "left")
setAlignment(ALIGN_LEFT);
setHorizontalAlignment(ALIGN_LEFT);
else if(str == "center")
setAlignment(ALIGN_CENTER);
setHorizontalAlignment(ALIGN_CENTER);
else if(str == "right")
setAlignment(ALIGN_RIGHT);
setHorizontalAlignment(ALIGN_RIGHT);
else
LOG(LogError) << "Unknown text alignment string: " << str;
}
......
......@@ -23,7 +23,8 @@ public:
void onSizeChanged() override;
void setText(const std::string& text);
void setColor(unsigned int color);
void setAlignment(Alignment align);
void setHorizontalAlignment(Alignment align);
void setVerticalAlignment(Alignment align);
void setLineSpacing(float spacing);
void setBackgroundColor(unsigned int color);
void setRenderBackground(bool render);
......@@ -56,7 +57,8 @@ private:
Eigen::Matrix<bool, 1, 2> mAutoCalcExtent;
std::string mText;
std::shared_ptr<TextCache> mTextCache;
Alignment mAlignment;
Alignment mHorizontalAlignment;
Alignment mVerticalAlignment;
float mLineSpacing;
};
......
#include "components/VideoComponent.h"
#include "Renderer.h"
#include "ThemeData.h"
#include "Util.h"
#include "Window.h"
#ifdef WIN32
#include <codecvt>
#endif
#define FADE_TIME_MS 200
std::string getTitlePath() {
std::string titleFolder = getTitleFolder();
return titleFolder + "last_title.srt";
}
std::string getTitleFolder() {
std::string home = getHomePath();
return home + "/.emulationstation/tmp/";
}
void writeSubtitle(const char* gameName, const char* systemName, bool always)
{
FILE* file = fopen(getTitlePath().c_str(), "w");
if (always) {
fprintf(file, "1\n00:00:01,000 --> 00:00:30,000\n");
}
else
{
fprintf(file, "1\n00:00:01,000 --> 00:00:08,000\n");
}
fprintf(file, "%s\n", gameName);
fprintf(file, "<i>%s</i>\n\n", systemName);
if (!always) {
fprintf(file, "2\n00:00:26,000 --> 00:00:30,000\n");
fprintf(file, "%s\n", gameName);
fprintf(file, "<i>%s</i>\n", systemName);
}
fflush(file);
fclose(file);
file = NULL;
}
void VideoComponent::setScreensaverMode(bool isScreensaver)
{
mScreensaverMode = isScreensaver;
}
VideoComponent::VideoComponent(Window* window) :
GuiComponent(window),
mStaticImage(window),
mVideoHeight(0),
mVideoWidth(0),
mStartDelayed(false),
mIsPlaying(false),
mShowing(false),
mScreensaverActive(false),
mDisable(false),
mScreensaverMode(false),
mTargetIsMax(false),
mTargetSize(0, 0)
{
// Setup the default configuration
mConfig.showSnapshotDelay = false;
mConfig.showSnapshotNoVideo = false;
mConfig.startDelay = 0;
if (mWindow->getGuiStackSize() > 1) {
topWindow(false);
}
std::string path = getTitleFolder();
if(!boost::filesystem::exists(path))
boost::filesystem::create_directory(path);
}
VideoComponent::~VideoComponent()
{
// Stop any currently running video
stopVideo();
// Delete subtitle file, if existing
remove(getTitlePath().c_str());
}
void VideoComponent::onOriginChanged()
{
// Update the embeded static image
mStaticImage.setOrigin(mOrigin);
}
void VideoComponent::onSizeChanged()
{
// Update the embeded static image
mStaticImage.onSizeChanged();
}
bool VideoComponent::setVideo(std::string path)
{
// Convert the path into a generic format
boost::filesystem::path fullPath = getCanonicalPath(path);
fullPath.make_preferred().native();
// Check that it's changed
if (fullPath == mVideoPath)
return !path.empty();
// Store the path
mVideoPath = fullPath;
// If the file exists then set the new video
if (!fullPath.empty() && ResourceManager::getInstance()->fileExists(fullPath.generic_string()))
{
// Return true to show that we are going to attempt to play a video
return true;
}
// Return false to show that no video will be displayed
return false;
}
void VideoComponent::setImage(std::string path)
{
// Check that the image has changed
if (path == mStaticImagePath)
return;
mStaticImage.setImage(path);
mFadeIn = 0.0f;
mStaticImagePath = path;
}
void VideoComponent::setDefaultVideo()
{
setVideo(mConfig.defaultVideoPath);
}
void VideoComponent::setOpacity(unsigned char opacity)
{
mOpacity = opacity;
// Update the embeded static image
mStaticImage.setOpacity(opacity);
}
void VideoComponent::render(const Eigen::Affine3f& parentTrans)
{
float x, y;
Eigen::Affine3f trans = parentTrans * getTransform();
GuiComponent::renderChildren(trans);
Renderer::setMatrix(trans);
// Handle the case where the video is delayed
handleStartDelay();
// Handle looping of the video
handleLooping();
}
void VideoComponent::renderSnapshot(const Eigen::Affine3f& parentTrans)
{
// This is the case where the video is not currently being displayed. Work out
// if we need to display a static image
if ((mConfig.showSnapshotNoVideo && mVideoPath.empty()) || (mStartDelayed && mConfig.showSnapshotDelay))
{
// Display the static image instead
mStaticImage.setOpacity((unsigned char)(mFadeIn * 255.0f));
mStaticImage.render(parentTrans);
}
}
void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties)
{
using namespace ThemeFlags;
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "video");
if(!elem)
{
return;
}
Eigen::Vector2f scale = getParent() ? getParent()->getSize() : Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
if ((properties & POSITION) && elem->has("pos"))
{
Eigen::Vector2f denormalized = elem->get<Eigen::Vector2f>("pos").cwiseProduct(scale);
setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
mStaticImage.setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
}
if(properties & ThemeFlags::SIZE)
{
if(elem->has("size"))
setResize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale));
else if(elem->has("maxSize"))
setMaxSize(elem->get<Eigen::Vector2f>("maxSize").cwiseProduct(scale));
}
// position + size also implies origin
if (((properties & ORIGIN) || ((properties & POSITION) && (properties & ThemeFlags::SIZE))) && elem->has("origin"))
setOrigin(elem->get<Eigen::Vector2f>("origin"));
if(elem->has("default"))
mConfig.defaultVideoPath = elem->get<std::string>("default");
if((properties & ThemeFlags::DELAY) && elem->has("delay"))
mConfig.startDelay = (unsigned)(elem->get<float>("delay") * 1000.0f);
if (elem->has("showSnapshotNoVideo"))
mConfig.showSnapshotNoVideo = elem->get<bool>("showSnapshotNoVideo");
if (elem->has("showSnapshotDelay"))
mConfig.showSnapshotDelay = elem->get<bool>("showSnapshotDelay");
if(properties & ThemeFlags::ROTATION) {
if(elem->has("rotation"))
setRotationDegrees(elem->get<float>("rotation"));
if(elem->has("rotationOrigin"))
setRotationOrigin(elem->get<Eigen::Vector2f>("rotationOrigin"));
}
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
setZIndex(elem->get<float>("zIndex"));
else
setZIndex(getDefaultZIndex());
}
std::vector<HelpPrompt> VideoComponent::getHelpPrompts()
{
std::vector<HelpPrompt> ret;
ret.push_back(HelpPrompt("a", "select"));
return ret;
}
void VideoComponent::handleStartDelay()
{
// Only play if any delay has timed out
if (mStartDelayed)
{
if (mStartTime > SDL_GetTicks())
{
// Timeout not yet completed
return;
}
// Completed
mStartDelayed = false;
// Clear the playing flag so startVideo works
mIsPlaying = false;
startVideo();
}
}
void VideoComponent::handleLooping()
{
}
void VideoComponent::startVideoWithDelay()
{
// If not playing then either start the video or initiate the delay
if (!mIsPlaying)
{
// Set the video that we are going to be playing so we don't attempt to restart it
mPlayingVideoPath = mVideoPath;
if (mConfig.startDelay == 0)
{
// No delay. Just start the video
mStartDelayed = false;
startVideo();
}
else
{
// Configure the start delay
mStartDelayed = true;
mFadeIn = 0.0f;
mStartTime = SDL_GetTicks() + mConfig.startDelay;
}
mIsPlaying = true;
}
}
void VideoComponent::update(int deltaTime)
{
manageState();
// If the video start is delayed and there is less than the fade time then set the image fade
// accordingly
if (mStartDelayed)
{
Uint32 ticks = SDL_GetTicks();
if (mStartTime > ticks)
{
Uint32 diff = mStartTime - ticks;
if (diff < FADE_TIME_MS)
{
mFadeIn = (float)diff / (float)FADE_TIME_MS;
return;
}
}
}
// If the fade in is less than 1 then increment it
if (mFadeIn < 1.0f)
{
mFadeIn += deltaTime / (float)FADE_TIME_MS;
if (mFadeIn > 1.0f)
mFadeIn = 1.0f;
}
GuiComponent::update(deltaTime);
}
void VideoComponent::manageState()
{
// We will only show if the component is on display and the screensaver
// is not active
bool show = mShowing && !mScreensaverActive && !mDisable;
// See if we're already playing
if (mIsPlaying)
{
// If we are not on display then stop the video from playing
if (!show)
{
stopVideo();
}
else
{
if (mVideoPath != mPlayingVideoPath)
{
// Path changed. Stop the video. We will start it again below because
// mIsPlaying will be modified by stopVideo to be false
stopVideo();
}
}
}
// Need to recheck variable rather than 'else' because it may be modified above
if (!mIsPlaying)
{
// If we are on display then see if we should start the video
if (show && !mVideoPath.empty())
{
startVideoWithDelay();
}
}
}
void VideoComponent::onShow()
{
mShowing = true;
manageState();
}
void VideoComponent::onHide()
{
mShowing = false;
manageState();
}
void VideoComponent::onScreenSaverActivate()
{
mScreensaverActive = true;
manageState();
}
void VideoComponent::onScreenSaverDeactivate()
{
mScreensaverActive = false;
manageState();
}
void VideoComponent::topWindow(bool isTop)
{
mDisable = !isTop;
manageState();
}
#ifndef _VIDEOCOMPONENT_H_
#define _VIDEOCOMPONENT_H_
#include "platform.h"
#include GLHEADER
#include "GuiComponent.h"
#include "ImageComponent.h"
#include <string>
#include <memory>
#include <SDL.h>
#include <SDL_mutex.h>
#include <boost/filesystem.hpp>
std::string getTitlePath();
std::string getTitleFolder();
void writeSubtitle(const char* gameName, const char* systemName, bool always);
class VideoComponent : public GuiComponent
{
// Structure that groups together the configuration of the video component
struct Configuration
{
unsigned startDelay;
bool showSnapshotNoVideo;