From b4e554153a104511d1ceacf3ee1e1a13b0ad74aa Mon Sep 17 00:00:00 2001 From: Sir_Leon Date: Tue, 2 Jul 2013 16:51:33 +0200 Subject: [PATCH 1/2] Moved Opacity logic to GuiComponent Moved Opacity logic from ImageComponent to GuiComponent so any extender of GuiComponent che implement its opacity logic. Implemented Opacity logic for TextComponent (now text can have fade animation) --- src/GuiComponent.cpp | 11 +++++++++++ src/GuiComponent.h | 3 +++ src/components/ImageComponent.cpp | 2 -- src/components/ImageComponent.h | 5 ----- src/components/TextComponent.cpp | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/GuiComponent.cpp b/src/GuiComponent.cpp index 4a5ee0195..88830b9d0 100644 --- a/src/GuiComponent.cpp +++ b/src/GuiComponent.cpp @@ -156,3 +156,14 @@ GuiComponent* GuiComponent::getParent() { return mParent; } + + +unsigned char GuiComponent::getOpacity() +{ + return mOpacity; +} + +void GuiComponent::setOpacity(unsigned char opacity) +{ + mOpacity = opacity; +} \ No newline at end of file diff --git a/src/GuiComponent.h b/src/GuiComponent.h index b7f36af64..6e09b5383 100644 --- a/src/GuiComponent.h +++ b/src/GuiComponent.h @@ -45,11 +45,14 @@ public: void clearChildren(); unsigned int getChildCount(); GuiComponent* getChild(unsigned int i); + unsigned char getOpacity(); + void setOpacity(unsigned char opacity); protected: //Default implementation just renders children - you should probably always call GuiComponent::onRender at some point in your custom onRender. virtual void onRender(); + unsigned char mOpacity; Window* mWindow; GuiComponent* mParent; Vector2i mOffset; diff --git a/src/components/ImageComponent.cpp b/src/components/ImageComponent.cpp index 238c9019e..dc8021ef8 100644 --- a/src/components/ImageComponent.cpp +++ b/src/components/ImageComponent.cpp @@ -352,8 +352,6 @@ bool ImageComponent::hasImage() return !mPath.empty(); } -unsigned char ImageComponent::getOpacity() { return mOpacity; } -void ImageComponent::setOpacity(unsigned char opacity) { mOpacity = opacity; } void ImageComponent::copyScreen() { diff --git a/src/components/ImageComponent.h b/src/components/ImageComponent.h index 3cf0204b1..ca6939509 100644 --- a/src/components/ImageComponent.h +++ b/src/components/ImageComponent.h @@ -38,9 +38,6 @@ public: void init(); void deinit(); - unsigned char getOpacity(); - void setOpacity(unsigned char opacity); - protected: void onRender(); @@ -51,8 +48,6 @@ private: bool mAllowUpscale, mTiled, mFlipX, mFlipY; - unsigned char mOpacity; - void loadImage(std::string path); void resize(); void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs, float percentageX = 1, float percentageY = 1); //writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position diff --git a/src/components/TextComponent.cpp b/src/components/TextComponent.cpp index 477a19417..6b455881c 100644 --- a/src/components/TextComponent.cpp +++ b/src/components/TextComponent.cpp @@ -74,7 +74,7 @@ void TextComponent::onRender() Renderer::pushClipRect(getGlobalOffset(), getSize()); - Renderer::drawWrappedText(mText, (int)-mScrollPos.x, (int)-mScrollPos.y, mSize.x, mColor, font); + Renderer::drawWrappedText(mText, (int)-mScrollPos.x, (int)-mScrollPos.y, mSize.x, mColor >> 8 << 8 | getOpacity(), font); Renderer::popClipRect(); From df78b5352ddadcc4911c8acc87099d939b96a0b3 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Tue, 2 Jul 2013 18:13:55 -0500 Subject: [PATCH 2/2] Changed AnimationComponent to use GuiComponent instead of ImageComponent. Possible now that the opacity logic has been moved to GuiComponent. --- src/components/AnimationComponent.cpp | 4 ++-- src/components/AnimationComponent.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/AnimationComponent.cpp b/src/components/AnimationComponent.cpp index 31c4c327e..1c400b4d3 100644 --- a/src/components/AnimationComponent.cpp +++ b/src/components/AnimationComponent.cpp @@ -76,7 +76,7 @@ void AnimationComponent::update(int deltaTime) } } -void AnimationComponent::addChild(ImageComponent* gui) +void AnimationComponent::addChild(GuiComponent* gui) { mChildren.push_back(gui); } @@ -86,7 +86,7 @@ void AnimationComponent::moveChildren(int offsetx, int offsety) Vector2i move(offsetx, offsety); for(unsigned int i = 0; i < mChildren.size(); i++) { - ImageComponent* comp = mChildren.at(i); + GuiComponent* comp = mChildren.at(i); comp->setOffset(comp->getOffset() + move); } } diff --git a/src/components/AnimationComponent.h b/src/components/AnimationComponent.h index 99cbd35b7..4591c10c2 100644 --- a/src/components/AnimationComponent.h +++ b/src/components/AnimationComponent.h @@ -2,7 +2,6 @@ #define _ANIMATIONCOMPONENT_H_ #include "../GuiComponent.h" -#include "ImageComponent.h" #include #define ANIMATION_TICK_SPEED 16 @@ -18,12 +17,12 @@ public: void update(int deltaTime); - void addChild(ImageComponent* gui); + void addChild(GuiComponent* gui); private: unsigned char mOpacity; - std::vector mChildren; + std::vector mChildren; void moveChildren(int offsetx, int offsety); void setChildrenOpacity(unsigned char opacity);