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);
logo->setMaxSize(mCarousel.logoSize * mCarousel.logoScale);
logo->applyTheme(theme, "system", "logo", ThemeFlags::PATH | ThemeFlags::COLOR);
logo->setRotateByTargetSize(true);
e.data.logo = std::shared_ptr<GuiComponent>(logo);
}
}
@ -71,9 +72,13 @@ void SystemView::populate()
e.data.logo = std::shared_ptr<GuiComponent>(text);
if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL)
{
text->setHorizontalAlignment(mCarousel.logoAlignment);
else
text->setVerticalAlignment(ALIGN_CENTER);
} else {
text->setHorizontalAlignment(ALIGN_CENTER);
text->setVerticalAlignment(mCarousel.logoAlignment);
}
}
if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL)
@ -157,6 +162,7 @@ bool SystemView::input(InputConfig* config, Input input)
}
break;
case HORIZONTAL:
case HORIZONTAL_WHEEL:
default:
if (config->isMappedTo("left", input))
{
@ -369,7 +375,7 @@ void SystemView::render(const Transform4x4f& parentTrans)
std::vector<HelpPrompt> SystemView::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
if (mCarousel.type == VERTICAL)
if (mCarousel.type == VERTICAL || mCarousel.type == VERTICAL_WHEEL)
prompts.push_back(HelpPrompt("up/down", "choose"));
else
prompts.push_back(HelpPrompt("left/right", "choose"));
@ -458,6 +464,15 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
else
xOff = (mCarousel.size.x() - mCarousel.logoSize.x()) / 2;
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:
default:
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);
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->setRotationOrigin(mCarousel.logoRotationOrigin);
}
@ -545,7 +560,7 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
if (mShowing || index == mCursor)
{
Transform4x4f extrasTrans = trans;
if (mCarousel.type == HORIZONTAL)
if (mCarousel.type == HORIZONTAL || mCarousel.type == HORIZONTAL_WHEEL)
extrasTrans.translate(Vector3f((i - mExtrasCamOffset) * mSize.x(), 0, 0));
else
extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0));
@ -616,6 +631,8 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
mCarousel.type = VERTICAL;
else if (!(elem->get<std::string>("type").compare("vertical_wheel")))
mCarousel.type = VERTICAL_WHEEL;
else if (!(elem->get<std::string>("type").compare("horizontal_wheel")))
mCarousel.type = HORIZONTAL_WHEEL;
else
mCarousel.type = HORIZONTAL;
}
@ -637,7 +654,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
mCarousel.zIndex = elem->get<float>("zIndex");
if (elem->has("logoRotation"))
mCarousel.logoRotation = elem->get<float>("logoRotation");
if (elem->has("logoRotationOrigin"))
if (elem->has("logoRotationOrigin"))
mCarousel.logoRotationOrigin = elem->get<Vector2f>("logoRotationOrigin");
if (elem->has("logoAlignment"))
{

View file

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

View file

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

View file

@ -61,6 +61,8 @@ public:
void setSize(float w, float h);
virtual void onSizeChanged() {};
virtual Vector2f getRotationSize() const { return getSize(); };
float getRotation() const;
void setRotation(float 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),
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();
}
@ -142,6 +142,16 @@ void ImageComponent::setMaxSize(float width, float height)
resize();
}
Vector2f ImageComponent::getRotationSize() const
{
return mRotateByTargetSize ? mTargetSize : mSize;
}
void ImageComponent::setRotateByTargetSize(bool rotate)
{
mRotateByTargetSize = rotate;
}
void ImageComponent::setFlipX(bool flip)
{
mFlipX = flip;

View file

@ -40,12 +40,16 @@ public:
void setMaxSize(float width, float height);
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.
void setColorShift(unsigned int color);
void setFlipX(bool flip); // Mirror on the X 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).
Vector2i getTextureSize() const;
@ -86,6 +90,7 @@ private:
bool mFading;
bool mForceLoad;
bool mDynamic;
bool mRotateByTargetSize;
};
#endif // ES_CORE_COMPONENTS_IMAGE_COMPONENT_H