From b41118fe929cabb050c8a9bf7b670934cdb37f6c Mon Sep 17 00:00:00 2001 From: jrassa Date: Mon, 22 Jan 2018 19:31:18 -0500 Subject: [PATCH 1/2] implement debug rects for images similar to text components --- es-core/src/Settings.cpp | 1 + es-core/src/Window.cpp | 5 +++++ es-core/src/components/ImageComponent.cpp | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index a18f002f3..37bb88fdf 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -13,6 +13,7 @@ std::vector settings_dont_save { { "Debug" }, { "DebugGrid" }, { "DebugText" }, + { "DebugImage" }, { "ForceKid" }, { "ForceKiosk" }, { "IgnoreGamelist" }, diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index bc4267e8b..47a8cd622 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -168,6 +168,11 @@ void Window::input(InputConfig* config, Input input) // toggle TextComponent debug view with Ctrl-T Settings::getInstance()->setBool("DebugText", !Settings::getInstance()->getBool("DebugText")); } + else if(config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_i && SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) + { + // toggle TextComponent debug view with Ctrl-I + Settings::getInstance()->setBool("DebugImage", !Settings::getInstance()->getBool("DebugImage")); + } else { if (peekGui()) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index f51581547..aefa065ad 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -3,6 +3,7 @@ #include "resources/TextureResource.h" #include "Log.h" #include "Renderer.h" +#include "Settings.h" #include "ThemeData.h" Vector2i ImageComponent::getTextureSize() const @@ -229,6 +230,11 @@ void ImageComponent::render(const Transform4x4f& parentTrans) if(mTexture && mOpacity > 0) { + if(Settings::getInstance()->getBool("DebugImage")) { + Vector2f targetSizePos = (mTargetSize - mSize) * mOrigin * -1; + Renderer::drawRect(targetSizePos.x(), targetSizePos.y(), mTargetSize.x(), mTargetSize.y(), 0xFF000033); + Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x00000033); + } if(mTexture->isInitialized()) { // actually draw the image From e9403b6b0065022ffc5c5b0adea71242624c69c7 Mon Sep 17 00:00:00 2001 From: jrassa Date: Mon, 22 Jan 2018 19:34:30 -0500 Subject: [PATCH 2/2] implement horizontal wheel for system carousel. fix image rotation bug in carousel --- es-app/src/views/SystemView.cpp | 27 ++++++++++++++++++----- es-app/src/views/SystemView.h | 3 ++- es-core/src/GuiComponent.cpp | 5 +++-- es-core/src/GuiComponent.h | 2 ++ es-core/src/components/ImageComponent.cpp | 12 +++++++++- es-core/src/components/ImageComponent.h | 5 +++++ 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 5976226e0..dd5fdfcd6 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -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(logo); } } @@ -71,9 +72,13 @@ void SystemView::populate() e.data.logo = std::shared_ptr(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 SystemView::getHelpPrompts() { std::vector 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 &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("type").compare("vertical_wheel"))) mCarousel.type = VERTICAL_WHEEL; + else if (!(elem->get("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("zIndex"); if (elem->has("logoRotation")) mCarousel.logoRotation = elem->get("logoRotation"); - if (elem->has("logoRotationOrigin")) + if (elem->has("logoRotationOrigin")) mCarousel.logoRotationOrigin = elem->get("logoRotationOrigin"); if (elem->has("logoAlignment")) { diff --git a/es-app/src/views/SystemView.h b/es-app/src/views/SystemView.h index 02fdf1def..db1205424 100644 --- a/es-app/src/views/SystemView.h +++ b/es-app/src/views/SystemView.h @@ -15,7 +15,8 @@ enum CarouselType : unsigned int { HORIZONTAL = 0, VERTICAL = 1, - VERTICAL_WHEEL = 2 + VERTICAL_WHEEL = 2, + HORIZONTAL_WHEEL = 3 }; struct SystemViewData diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index 336b92d68..5d9379fe8 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -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) diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index e53f63a15..ff291e54b 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -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)); } diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index aefa065ad..aa82dce37 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -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; diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index d95fd6c18..b557c9b5c 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -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