implement horizontal wheel for system carousel. fix image rotation bug in carousel

This commit is contained in:
jrassa 2018-01-22 19:34:30 -05:00
parent b41118fe92
commit e9403b6b00
6 changed files with 45 additions and 9 deletions

View file

@ -55,6 +55,7 @@ void SystemView::populate()
ImageComponent* logo = new ImageComponent(mWindow, false, false); ImageComponent* logo = new ImageComponent(mWindow, false, false);
logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale); logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale);
logo->applyTheme(theme, "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR); logo->applyTheme(theme, "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR);
logo->setRotateByTargetSize(true);
e.data.logo = std::shared_ptr<GuiComponent>(logo); e.data.logo = std::shared_ptr<GuiComponent>(logo);
} }
} }
@ -71,10 +72,14 @@ void SystemView::populate()
e.data.logo = std::shared_ptr<GuiComponent>(text); e.data.logo = std::shared_ptr<GuiComponent>(text);
if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL) if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL)
{
text->setHorizontalAlignment(mCarousel.logoAlignment); text->setHorizontalAlignment(mCarousel.logoAlignment);
else text->setVerticalAlignment(ALIGN_CENTER);
} else {
text->setHorizontalAlignment(ALIGN_CENTER);
text->setVerticalAlignment(mCarousel.logoAlignment); text->setVerticalAlignment(mCarousel.logoAlignment);
} }
}
if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL) if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL)
{ {
@ -157,6 +162,7 @@ bool SystemView::input(InputConfig* config, Input input)
} }
break; break;
case HORIZONTAL: case HORIZONTAL:
case HORIZONTAL_WHEEL:
default: default:
if (config->isMappedTo("left", input)) if (config->isMappedTo("left", input))
{ {
@ -369,7 +375,7 @@ void SystemView::render(const Transform4x4f& parentTrans)
std::vector<HelpPrompt> SystemView::getHelpPrompts() std::vector<HelpPrompt> SystemView::getHelpPrompts()
{ {
std::vector<HelpPrompt> prompts; std::vector<HelpPrompt> prompts;
if (mCarousel.type == VERTICAL) if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL)
prompts.push_back(HelpPrompt("up/down", "choose")); prompts.push_back(HelpPrompt("up/down", "choose"));
else else
prompts.push_back(HelpPrompt("left/right", "choose")); prompts.push_back(HelpPrompt("left/right", "choose"));
@ -458,6 +464,15 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
else else
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2; xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2;
break; break;
case HORIZONTAL_WHEEL:
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2 - (mCamOffset * logoSpacing[1]);
if (mCarousel.logoAlignment == ALIGN_TOP)
yOff = mCarousel.logoSize.y() / 10;
else if (mCarousel.logoAlignment == ALIGN_BOTTOM)
yOff = mCarousel.size.y() - (mCarousel.logoSize.y() * 1.1f);
else
yOff = (mCarousel.size.y() - mCarousel.logoSize.y()) / 2;
break;
case HORIZONTAL: case HORIZONTAL:
default: default:
logoSpacing[0] = ((mCarousel.size.x() - (mCarousel.logoSize.x() * mCarousel.maxLogoCount)) / (mCarousel.maxLogoCount)) + mCarousel.logoSize.x(); logoSpacing[0] = ((mCarousel.size.x() - (mCarousel.logoSize.x() * mCarousel.maxLogoCount)) / (mCarousel.maxLogoCount)) + mCarousel.logoSize.x();
@ -506,7 +521,7 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
opacity = Math::max((int) 0x80, opacity); opacity = Math::max((int) 0x80, opacity);
const std::shared_ptr<GuiComponent> &comp = mEntries.at(index).data.logo; const std::shared_ptr<GuiComponent> &comp = mEntries.at(index).data.logo;
if (mCarousel.type == VERTICAL_WHEEL) { if (mCarousel.type == VERTICAL_WHEEL || mCarousel.type == HORIZONTAL_WHEEL) {
comp->setRotationDegrees(mCarousel.logoRotation * distance); comp->setRotationDegrees(mCarousel.logoRotation * distance);
comp->setRotationOrigin(mCarousel.logoRotationOrigin); comp->setRotationOrigin(mCarousel.logoRotationOrigin);
} }
@ -545,7 +560,7 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
if (mShowing || index == mCursor) if (mShowing || index == mCursor)
{ {
Transform4x4f extrasTrans = trans; Transform4x4f extrasTrans = trans;
if (mCarousel.type == HORIZONTAL) if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL)
extrasTrans.translate(Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0)); extrasTrans.translate(Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0));
else else
extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0)); extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0));
@ -616,6 +631,8 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
mCarousel.type = VERTICAL; mCarousel.type = VERTICAL;
else if (!(elem->get<std::string>("type").compare("vertical_wheel"))) else if (!(elem->get<std::string>("type").compare("vertical_wheel")))
mCarousel.type = VERTICAL_WHEEL; mCarousel.type = VERTICAL_WHEEL;
else if (!(elem->get<std::string>("type").compare("horizontal_wheel")))
mCarousel.type = HORIZONTAL_WHEEL;
else else
mCarousel.type = HORIZONTAL; mCarousel.type = HORIZONTAL;
} }

View file

@ -15,7 +15,8 @@ enum CarouselType : unsigned int
{ {
HORIZONTAL = 0, HORIZONTAL = 0,
VERTICAL = 1, VERTICAL = 1,
VERTICAL_WHEEL = 2 VERTICAL_WHEEL = 2,
HORIZONTAL_WHEEL = 3
}; };
struct SystemViewData struct SystemViewData

View file

@ -252,8 +252,9 @@ const Transform4x4f& GuiComponent::getTransform()
if (mRotation != 0.0) if (mRotation != 0.0)
{ {
// Calculate offset as difference between origin and rotation origin // Calculate offset as difference between origin and rotation origin
float xOff = (mOrigin.x() - mRotationOrigin.x()) * mSize.x(); Vector2f rotationSize = getRotationSize();
float yOff = (mOrigin.y() - mRotationOrigin.y()) * mSize.y(); float xOff = (mOrigin.x() - mRotationOrigin.x()) * rotationSize.x();
float yOff = (mOrigin.y() - mRotationOrigin.y()) * rotationSize.y();
// transform to offset point // transform to offset point
if (xOff != 0.0 || yOff != 0.0) if (xOff != 0.0 || yOff != 0.0)

View file

@ -61,6 +61,8 @@ public:
void setSize(float w, float h); void setSize(float w, float h);
virtual void onSizeChanged() {}; virtual void onSizeChanged() {};
virtual Vector2f getRotationSize() const { return getSize(); };
float getRotation() const; float getRotation() const;
void setRotation(float rotation); void setRotation(float rotation);
inline void setRotationDegrees(float rotation) { setRotation((float)ES_DEG_TO_RAD(rotation)); } inline void setRotationDegrees(float rotation) { setRotation((float)ES_DEG_TO_RAD(rotation)); }

View file

@ -16,7 +16,7 @@ Vector2i ImageComponent::getTextureSize() const
ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic) : GuiComponent(window), ImageComponent::ImageComponent(Window* window, bool forceLoad, bool dynamic) : GuiComponent(window),
mTargetIsMax(false), mFlipX(false), mFlipY(false), mTargetSize(0, 0), mColorShift(0xFFFFFFFF), mTargetIsMax(false), mFlipX(false), mFlipY(false), mTargetSize(0, 0), mColorShift(0xFFFFFFFF),
mForceLoad(forceLoad), mDynamic(dynamic), mFadeOpacity(0), mFading(false) mForceLoad(forceLoad), mDynamic(dynamic), mFadeOpacity(0), mFading(false), mRotateByTargetSize(false)
{ {
updateColors(); updateColors();
} }
@ -142,6 +142,16 @@ void ImageComponent::setMaxSize(float width, float height)
resize(); resize();
} }
Vector2f ImageComponent::getRotationSize() const
{
return mRotateByTargetSize ? mTargetSize : mSize;
}
void ImageComponent::setRotateByTargetSize(bool rotate)
{
mRotateByTargetSize = rotate;
}
void ImageComponent::setFlipX(bool flip) void ImageComponent::setFlipX(bool flip)
{ {
mFlipX = flip; mFlipX = flip;

View file

@ -40,12 +40,16 @@ public:
void setMaxSize(float width, float height); void setMaxSize(float width, float height);
inline void setMaxSize(const Vector2f& size) { setMaxSize(size.x(), size.y()); } inline void setMaxSize(const Vector2f& size) { setMaxSize(size.x(), size.y()); }
Vector2f getRotationSize() const override;
// Multiply all pixels in the image by this color when rendering. // Multiply all pixels in the image by this color when rendering.
void setColorShift(unsigned int color); void setColorShift(unsigned int color);
void setFlipX(bool flip); // Mirror on the X axis. void setFlipX(bool flip); // Mirror on the X axis.
void setFlipY(bool flip); // Mirror on the Y axis. void setFlipY(bool flip); // Mirror on the Y axis.
void setRotateByTargetSize(bool rotate); // Flag indicating if rotation should be based on target size vs. actual size.
// Returns the size of the current texture, or (0, 0) if none is loaded. May be different than drawn size (use getSize() for that). // Returns the size of the current texture, or (0, 0) if none is loaded. May be different than drawn size (use getSize() for that).
Vector2i getTextureSize() const; Vector2i getTextureSize() const;
@ -86,6 +90,7 @@ private:
bool mFading; bool mFading;
bool mForceLoad; bool mForceLoad;
bool mDynamic; bool mDynamic;
bool mRotateByTargetSize;
}; };
#endif // ES_CORE_COMPONENTS_IMAGE_COMPONENT_H #endif // ES_CORE_COMPONENTS_IMAGE_COMPONENT_H