From 12c74347aceca5cdaf35e17b77b75ae1e0f77fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Wed, 29 Mar 2017 03:02:59 -0300 Subject: [PATCH] RectangleDrawable WIP. Drawables now can keep a position. Some code clean up. --HG-- branch : dev --- include/eepp/graphics.hpp | 2 + include/eepp/graphics/arcdrawable.hpp | 2 + include/eepp/graphics/drawable.hpp | 9 + include/eepp/graphics/primitivedrawable.hpp | 2 + include/eepp/graphics/rectangledrawable.hpp | 37 ++++- include/eepp/graphics/sprite.hpp | 34 +--- include/eepp/graphics/subtexture.hpp | 2 + include/eepp/graphics/texture.hpp | 2 + include/eepp/system/color.hpp | 8 + src/eepp/graphics/arcdrawable.cpp | 4 + src/eepp/graphics/drawable.cpp | 14 ++ src/eepp/graphics/primitivedrawable.cpp | 4 + src/eepp/graphics/rectangledrawable.cpp | 174 +++++++++++++++++++- src/eepp/graphics/sprite.cpp | 67 +++----- src/eepp/graphics/subtexture.cpp | 4 + src/eepp/graphics/texture.cpp | 4 + src/eepp/physics/shapecirclesprite.cpp | 2 +- src/eepp/physics/shapepolysprite.cpp | 2 +- src/eepp/ui/uisprite.cpp | 2 +- src/examples/empty_window/empty_window.cpp | 7 + src/examples/sprites/sprites.cpp | 9 +- src/test/eetest.cpp | 10 +- 22 files changed, 307 insertions(+), 94 deletions(-) diff --git a/include/eepp/graphics.hpp b/include/eepp/graphics.hpp index 07ad2ed3f..2770c3c92 100644 --- a/include/eepp/graphics.hpp +++ b/include/eepp/graphics.hpp @@ -40,5 +40,7 @@ #include #include #include +#include +#include #endif diff --git a/include/eepp/graphics/arcdrawable.hpp b/include/eepp/graphics/arcdrawable.hpp index ccc9b0488..c91637e85 100644 --- a/include/eepp/graphics/arcdrawable.hpp +++ b/include/eepp/graphics/arcdrawable.hpp @@ -14,6 +14,8 @@ class ArcDrawable : public PrimitiveDrawable { virtual Sizef getSize(); + virtual void draw(); + virtual void draw( const Vector2f& position ); virtual void draw( const Vector2f& position, const Sizef& size ); diff --git a/include/eepp/graphics/drawable.hpp b/include/eepp/graphics/drawable.hpp index 68409bc53..1feb65945 100644 --- a/include/eepp/graphics/drawable.hpp +++ b/include/eepp/graphics/drawable.hpp @@ -15,6 +15,8 @@ class EE_API Drawable { virtual Sizef getSize() = 0; + virtual void draw() = 0; + virtual void draw( const Vector2f& position ) = 0; virtual void draw( const Vector2f& position, const Sizef& size ) = 0; @@ -38,13 +40,20 @@ class EE_API Drawable { void resetAlpha(); EE_DRAWABLE_TYPE getDrawableType() const; + + const Vector2f& getPosition() const; + + void setPosition( const Vector2f& position ); protected: EE_DRAWABLE_TYPE mDrawableType; ColorA mColor; + Vector2f mPosition; virtual void onAlphaChange(); virtual void onColorFilterChange(); + + virtual void onPositionChange(); }; }} diff --git a/include/eepp/graphics/primitivedrawable.hpp b/include/eepp/graphics/primitivedrawable.hpp index d404aeced..fd7ca138e 100644 --- a/include/eepp/graphics/primitivedrawable.hpp +++ b/include/eepp/graphics/primitivedrawable.hpp @@ -45,6 +45,8 @@ class PrimitiveDrawable : public Drawable { virtual void onColorFilterChange(); + virtual void onPositionChange(); + void prepareVertexBuffer( const EE_DRAW_MODE& drawableType ); virtual void updateVertex() = 0; diff --git a/include/eepp/graphics/rectangledrawable.hpp b/include/eepp/graphics/rectangledrawable.hpp index 4152419da..6effd6a7b 100644 --- a/include/eepp/graphics/rectangledrawable.hpp +++ b/include/eepp/graphics/rectangledrawable.hpp @@ -2,21 +2,54 @@ #define EE_GRAPHICS_RECTANGLEDRAWABLE #include +#include namespace EE { namespace Graphics { -class RectangleDrawable : PrimitiveDrawable { +class RectangleDrawable : public PrimitiveDrawable { public: RectangleDrawable(); - ~RectangleDrawable(); + RectangleDrawable( const Vector2f& position, const Sizef& size ); virtual Sizef getSize(); + virtual void draw(); + virtual void draw( const Vector2f& position ); virtual void draw( const Vector2f& position, const Sizef& size ); + Float getRotation() const; + + void setRotation(const Float & rotation); + + Vector2f getScale() const; + + void setScale(const Vector2f & scale); + + void setSize(const Sizef & size); + + Uint32 getCorners() const; + + void setCorners(const Uint32 & corners); + + RectColors getRectColors() const; + + void setRectColors(const RectColors & rectColors); + protected: + Sizef mSize; + Float mRotation; + Vector2f mScale; + Uint32 mCorners; + RectColors mRectColors; + bool mUsingRectColors; + + void drawRectangle( const Rectf& R, const ColorA& TopLeft, const ColorA& BottomLeft, const ColorA& BottomRight, const ColorA& TopRight, const Float& Angle, const Vector2f& Scale ); + + void updateVertex(); + + virtual void onColorFilterChange(); }; }} diff --git a/include/eepp/graphics/sprite.hpp b/include/eepp/graphics/sprite.hpp index 1a4b19ed7..e7d970d83 100755 --- a/include/eepp/graphics/sprite.hpp +++ b/include/eepp/graphics/sprite.hpp @@ -51,18 +51,6 @@ class EE_API Sprite : public Drawable { Sprite& operator =( const Sprite& Other ); - /** Set the x axis position */ - void setX( const Float& getX ); - - /** @return The x axis position */ - Float getX() const; - - /** Set the y axis position */ - void setY( const Float& y ); - - /** @return The y axis position */ - Float getY() const; - /** Set the Angle for the rendered sprite */ void setRotation( const Float& rotation ); @@ -162,15 +150,6 @@ class EE_API Sprite : public Drawable { /** @return The AABB (axis-aligned bounding box) */ eeAABB getAABB(); - /** Set the sprite position */ - void setPosition( const Float& getX, const Float& y ); - - /** Set the sprite position from a Vector */ - void setPosition( const Vector2f& NewPos ); - - /** @return The Position of the sprite */ - const Vector2f getPosition() const; - /** Update the colors of every vertex rendered of the sprite ( this will override the default color ) * @param Color0 The Left - Top vertex color * @param Color1 The Left - Bottom vertex color @@ -341,24 +320,23 @@ class EE_API Sprite : public Drawable { }; Uint32 mFlags; - Vector2f mPos; - OriginPoint mOrigin; + OriginPoint mOrigin; Float mRotation; Vector2f mScale; Float mAnimSpeed; ColorA * mVertexColors; - int mRepetitions; //!< Number of repetions of the animation, default -1 that equals to loop. + int mRepetitions; //!< Number of repetions of the animation, default -1 that equals to loop. EE_BLEND_MODE mBlend; EE_RENDER_MODE mEffect; - unsigned int mCurrentFrame; + unsigned int mCurrentFrame; Float mfCurrentFrame; - unsigned int mCurrentSubFrame; - unsigned int mSubFrames; - unsigned int mAnimTo; + unsigned int mCurrentSubFrame; + unsigned int mSubFrames; + unsigned int mAnimTo; SpriteCallback mCb; void * mUserData; diff --git a/include/eepp/graphics/subtexture.hpp b/include/eepp/graphics/subtexture.hpp index 0437ed7a3..2266e670e 100644 --- a/include/eepp/graphics/subtexture.hpp +++ b/include/eepp/graphics/subtexture.hpp @@ -87,6 +87,8 @@ class EE_API SubTexture : public Drawable { void draw( const Quad2f Q, const Vector2f& offset = Vector2f(), const Float& Angle = 0.f, const Vector2f& Scale = Vector2f::One, const ColorA& Color0 = ColorA(), const ColorA& Color1 = ColorA(), const ColorA& Color2 = ColorA(), const ColorA& Color3 = ColorA(), const EE_BLEND_MODE& Blend = ALPHA_NORMAL ); + virtual void draw(); + virtual void draw( const Vector2f& position ); virtual void draw(const Vector2f& position, const Sizef & size ); diff --git a/include/eepp/graphics/texture.hpp b/include/eepp/graphics/texture.hpp index 60e2c718a..85e02cdb4 100755 --- a/include/eepp/graphics/texture.hpp +++ b/include/eepp/graphics/texture.hpp @@ -220,6 +220,8 @@ class EE_API Texture : public Image, public Drawable, private NonCopyable { Sizei getPixelSize(); + void draw(); + void draw(const Vector2f & position); void draw(const Vector2f & position, const Sizef & size); diff --git a/include/eepp/system/color.hpp b/include/eepp/system/color.hpp index 665116eb8..e1ef74e8f 100755 --- a/include/eepp/system/color.hpp +++ b/include/eepp/system/color.hpp @@ -249,6 +249,14 @@ typedef Colorf RGBf; typedef ColorA RGBA; typedef ColorAf RGBAf; +class RectColors { + public: + ColorA TopLeft; + ColorA TopRight; + ColorA BottomLeft; + ColorA BottomRight; +}; + }} #endif diff --git a/src/eepp/graphics/arcdrawable.cpp b/src/eepp/graphics/arcdrawable.cpp index 2038299ef..5aac24b28 100644 --- a/src/eepp/graphics/arcdrawable.cpp +++ b/src/eepp/graphics/arcdrawable.cpp @@ -27,6 +27,10 @@ Sizef ArcDrawable::getSize() { return Sizef( mRadius * 2, mRadius * 2 ); } +void ArcDrawable::draw() { + draw( mPosition ); +} + void ArcDrawable::draw(const Vector2f & position) { draw( position, getSize() ); } diff --git a/src/eepp/graphics/drawable.cpp b/src/eepp/graphics/drawable.cpp index 5757d7569..a16b5d091 100644 --- a/src/eepp/graphics/drawable.cpp +++ b/src/eepp/graphics/drawable.cpp @@ -72,10 +72,24 @@ EE_DRAWABLE_TYPE Drawable::getDrawableType() const { return mDrawableType; } +const Vector2f& Drawable::getPosition() const { + return mPosition; +} + +void Drawable::setPosition( const Vector2f& position ) { + if ( position != mPosition ) { + mPosition = position; + onPositionChange(); + } +} + void Drawable::onAlphaChange() { } void Drawable::onColorFilterChange() { } +void Drawable::onPositionChange() { +} + }} diff --git a/src/eepp/graphics/primitivedrawable.cpp b/src/eepp/graphics/primitivedrawable.cpp index f88453f78..933fed58a 100644 --- a/src/eepp/graphics/primitivedrawable.cpp +++ b/src/eepp/graphics/primitivedrawable.cpp @@ -75,6 +75,10 @@ void PrimitiveDrawable::onColorFilterChange() { mNeedsUpdate = true; } +void PrimitiveDrawable::onPositionChange() { + mNeedsUpdate = true; +} + void PrimitiveDrawable::prepareVertexBuffer( const EE_DRAW_MODE& drawableType ) { if ( mRecreateVertexBuffer ) { eeSAFE_DELETE( mVertexBuffer ); diff --git a/src/eepp/graphics/rectangledrawable.cpp b/src/eepp/graphics/rectangledrawable.cpp index 74502389f..1cbc24bcd 100644 --- a/src/eepp/graphics/rectangledrawable.cpp +++ b/src/eepp/graphics/rectangledrawable.cpp @@ -1,27 +1,191 @@ #include +#include +#include namespace EE { namespace Graphics { RectangleDrawable::RectangleDrawable() : - PrimitiveDrawable( DRAWABLE_RECTANGLE ) + PrimitiveDrawable( DRAWABLE_RECTANGLE ), + mRotation( 0 ), + mScale( 1, 1 ), + mCorners( 0 ), + mUsingRectColors( false ) { } -RectangleDrawable::~RectangleDrawable() { - +RectangleDrawable::RectangleDrawable(const Vector2f & position, const Sizef & size) : + PrimitiveDrawable( DRAWABLE_RECTANGLE ), + mSize( size ), + mRotation( 0 ), + mScale( 1, 1 ), + mCorners( 0 ), + mUsingRectColors( false ) +{ + mPosition = position; } Sizef RectangleDrawable::getSize() { - return Sizef(); + return mSize; +} + +void RectangleDrawable::draw() { + draw( mPosition ); } void RectangleDrawable::draw(const Vector2f & position) { - + draw( mPosition, mSize ); } void RectangleDrawable::draw(const Vector2f & position, const Sizef & size) { + if ( size != mSize ) { + mSize = size; + mNeedsUpdate = true; + } + if ( mCorners == 0 ) { + if ( mUsingRectColors ) { + drawRectangle( Rectf( mPosition, mSize ), mRectColors.TopLeft, mRectColors.BottomLeft, mRectColors.BottomRight, mRectColors.TopRight, mRotation, mScale ); + } else { + drawRectangle( Rectf( mPosition, mSize ), mColor, mColor, mColor, mColor, mRotation, mScale ); + } + } else { + PrimitiveDrawable::draw( position, size ); + } } +Float RectangleDrawable::getRotation() const { + return mRotation; +} + +void RectangleDrawable::setRotation(const Float & rotation) { + mRotation = rotation; + mNeedsUpdate = true; +} + +Vector2f RectangleDrawable::getScale() const { + return mScale; +} + +void RectangleDrawable::setScale(const Vector2f & scale) { + mScale = scale; + mNeedsUpdate = true; +} + +void RectangleDrawable::setSize(const Sizef & size) { + mSize = size; + mNeedsUpdate = true; +} + +Uint32 RectangleDrawable::getCorners() const { + return mCorners; +} + +void RectangleDrawable::setCorners(const Uint32 & corners) { + mCorners = corners; + mNeedsUpdate = true; + mRecreateVertexBuffer = true; +} + +RectColors RectangleDrawable::getRectColors() const { + return mRectColors; +} + +void RectangleDrawable::setRectColors(const RectColors & rectColors) { + mRectColors = rectColors; + mUsingRectColors = true; +} + +void RectangleDrawable::drawRectangle( const Rectf& R, const ColorA& TopLeft, const ColorA& BottomLeft, const ColorA& BottomRight, const ColorA& TopRight, const Float& Angle, const Vector2f& Scale ) { + BatchRenderer * sBR = GlobalBatchRenderer::instance(); + sBR->setTexture( NULL ); + sBR->setBlendMode( mBlendMode ); + + switch( mFillMode ) { + case DRAW_FILL: + { + sBR->quadsBegin(); + sBR->quadsSetColorFree( TopLeft, BottomLeft, BottomRight, TopRight ); + + Sizef size = const_cast(&R)->getSize(); + + sBR->batchQuadEx( R.Left, R.Top, size.getWidth(), size.getHeight(), Angle, Scale ); + break; + } + case DRAW_LINE: + { + sBR->setLineWidth( mLineWidth ); + + sBR->lineLoopBegin(); + sBR->lineLoopSetColorFree( TopLeft, BottomLeft ); + + if ( Scale != 1.0f || Angle != 0.0f ) { + Quad2f Q( R ); + Sizef size = const_cast(&R)->getSize(); + + Q.scale( Scale ); + Q.rotate( Angle, Vector2f( R.Left + size.getWidth() * 0.5f, R.Top + size.getHeight() * 0.5f ) ); + + sBR->batchLineLoop( Q[0].x, Q[0].y, Q[1].x, Q[1].y ); + sBR->lineLoopSetColorFree( BottomRight, TopRight ); + sBR->batchLineLoop( Q[2].x, Q[2].y, Q[3].x, Q[3].y ); + } else { + sBR->batchLineLoop( R.Left, R.Top, R.Left, R.Bottom ); + sBR->lineLoopSetColorFree( BottomRight, TopRight ); + sBR->batchLineLoop( R.Right, R.Bottom, R.Right, R.Top ); + } + + break; + } + } + + sBR->draw(); +} + +void RectangleDrawable::updateVertex() { + if ( mCorners == 0 ) + return; + + prepareVertexBuffer( mFillMode == DRAW_LINE ? DM_LINE_LOOP : DM_POLYGON ); + + unsigned int i; + Sizef size = mSize; + Float xscalediff = size.getWidth() * mScale.x - size.getWidth(); + Float yscalediff = size.getHeight() * mScale.y - size.getHeight(); + Vector2f Center( mPosition.x + size.getWidth() * 0.5f + xscalediff, mPosition.y + size.getHeight() * 0.5f + yscalediff ); + Polygon2f Poly = Polygon2f::createRoundedRectangle( mPosition.x - xscalediff, mPosition.y - yscalediff, size.getWidth() + xscalediff, size.getHeight() + yscalediff, mCorners ); + Vector2f poly; + Poly.rotate( mRotation, Center ); + + if ( !mUsingRectColors ) { + for ( i = 0; i < Poly.getSize(); i++ ) { + mVertexBuffer->addVertex( Poly[i] ); + mVertexBuffer->addColor( mColor ); + } + } else { + for ( i = 0; i < Poly.getSize(); i++ ) { + poly = Poly[i]; + + if ( poly.x <= Center.x && poly.y <= Center.y ) + mVertexBuffer->addColor( mRectColors.TopLeft ); + else if ( poly.x <= Center.x && poly.y >= Center.y ) + mVertexBuffer->addColor( mRectColors.BottomLeft ); + else if ( poly.x > Center.x && poly.y > Center.y ) + mVertexBuffer->addColor( mRectColors.BottomRight ); + else if ( poly.x > Center.x && poly.y < Center.y ) + mVertexBuffer->addColor( mRectColors.TopRight ); + else + mVertexBuffer->addColor( mRectColors.TopLeft ); + + mVertexBuffer->addVertex( poly ); + } + } + + mNeedsUpdate = false; +} + +void RectangleDrawable::onColorFilterChange() { + PrimitiveDrawable::onColorFilterChange(); + mUsingRectColors = false; +} }} diff --git a/src/eepp/graphics/sprite.cpp b/src/eepp/graphics/sprite.cpp index 3a422f037..a6646ca02 100755 --- a/src/eepp/graphics/sprite.cpp +++ b/src/eepp/graphics/sprite.cpp @@ -13,7 +13,6 @@ namespace EE { namespace Graphics { Sprite::Sprite() : Drawable( DRAWABLE_SPRITE ), mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mPos(), mRotation( 0.f ), mScale( 1.f, 1.f ), mAnimSpeed( 16.f ), @@ -34,7 +33,6 @@ Sprite::Sprite() : Sprite::Sprite( const std::string& name, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) : Drawable( DRAWABLE_SPRITE ), mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mPos(), mRotation( 0.f ), mScale( 1.f, 1.f ), mAnimSpeed( 16.f ), @@ -56,7 +54,6 @@ Sprite::Sprite( const std::string& name, const std::string& extension, TextureAt Sprite::Sprite( SubTexture * SubTexture ) : Drawable( DRAWABLE_SPRITE ), mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mPos(), mRotation( 0.f ), mScale( 1.f, 1.f ), mAnimSpeed( 16.f ), @@ -78,7 +75,6 @@ Sprite::Sprite( SubTexture * SubTexture ) : Sprite::Sprite( const Uint32& TexId, const Sizef &DestSize, const Vector2i &Offset, const Recti& TexSector ) : Drawable( DRAWABLE_SPRITE ), mFlags( SPRITE_FLAG_AUTO_ANIM | SPRITE_FLAG_EVENTS_ENABLED ), - mPos(), mRotation( 0.f ), mScale( 1.f, 1.f ), mAnimSpeed( 16.f ), @@ -102,14 +98,16 @@ Sprite::~Sprite() { } Sprite& Sprite::operator =( const Sprite& Other ) { + mDrawableType = Other.mDrawableType; mFrames = Other.mFrames; mFlags = Other.mFlags; - mPos = Other.mPos; - mRotation = Other.mRotation; + mColor = Other.mColor; + mPosition = Other.mPosition; + mRotation = Other.mRotation; mScale = Other.mScale; mAnimSpeed = Other.mAnimSpeed; mColor = Other.mColor; - mRepetitions = Other.mRepetitions; + mRepetitions = Other.mRepetitions; mBlend = Other.mBlend; mEffect = Other.mEffect; mCurrentFrame = Other.mCurrentFrame; @@ -135,9 +133,11 @@ Sprite& Sprite::operator =( const Sprite& Other ) { Sprite Sprite::clone() { Sprite Spr; + Spr.mDrawableType = mDrawableType; + Spr.mColor = mColor; Spr.mFrames = mFrames; Spr.mFlags = mFlags; - Spr.mPos = mPos; + Spr.mPosition = mPosition; Spr.mRotation = mRotation; Spr.mScale = mScale; Spr.mAnimSpeed = mAnimSpeed; @@ -224,10 +224,10 @@ Quad2f Sprite::getQuad() { SubTexture * S; if ( mFrames.size() && ( S = getCurrentSubTexture() ) ) { - Rectf TmpR( mPos.x, - mPos.y, - mPos.x + S->getDestSize().x, - mPos.y + S->getDestSize().y + Rectf TmpR( mPosition.x, + mPosition.y, + mPosition.x + S->getDestSize().x, + mPosition.y + S->getDestSize().y ); Quad2f Q = Quad2f( Vector2f( TmpR.Left, TmpR.Top ), @@ -241,9 +241,9 @@ Quad2f Sprite::getQuad() { if ( mOrigin.OriginType == OriginPoint::OriginCenter ) { Center = TmpR.getCenter(); } else if ( mOrigin.OriginType == OriginPoint::OriginTopLeft ) { - Center = mPos; + Center = mPosition; } else { - Center += mPos; + Center += mPosition; } switch ( mEffect ) { @@ -285,16 +285,16 @@ eeAABB Sprite::getAABB() { if ( mRotation != 0 || mEffect >= 4 ) { return getQuad().toAABB(); } else { // The method used if mAngle != 0 works for mAngle = 0, but i prefer to use the faster way - TmpR = Rectf( mPos.x, mPos.y, mPos.x + S->getDestSize().x, mPos.y + S->getDestSize().y ); + TmpR = Rectf( mPosition.x, mPosition.y, mPosition.x + S->getDestSize().x, mPosition.y + S->getDestSize().y ); Vector2f Center; if ( mOrigin.OriginType == OriginPoint::OriginCenter ) { Center = TmpR.getCenter(); } else if ( mOrigin.OriginType == OriginPoint::OriginTopLeft ) { - Center = mPos; + Center = mPosition; } else { - Center = mPos + mOrigin; + Center = mPosition + mOrigin; } TmpR.scale( mScale, Center ); @@ -304,19 +304,6 @@ eeAABB Sprite::getAABB() { return TmpR; } -const Vector2f Sprite::getPosition() const { - return mPos; -} - -void Sprite::setPosition(const Float& x, const Float& y) { - mPos.x = x; - mPos.y = y; -} - -void Sprite::setPosition( const Vector2f& NewPos ) { - mPos = NewPos; -} - void Sprite::updateVertexColors( const ColorA& Color0, const ColorA& Color1, const ColorA& Color2, const ColorA& Color3 ) { if ( NULL == mVertexColors ) mVertexColors = eeNewArray( ColorA, 4 ); @@ -589,9 +576,9 @@ void Sprite::draw( const EE_BLEND_MODE& Blend, const EE_RENDER_MODE& Effect ) { return; if ( NULL == mVertexColors ) - S->draw( mPos.x, mPos.y, mColor, mRotation, mScale, Blend, Effect, mOrigin ); + S->draw( mPosition.x, mPosition.y, mColor, mRotation, mScale, Blend, Effect, mOrigin ); else - S->draw( mPos.x, mPos.y, mRotation, mScale, mVertexColors[0], mVertexColors[1], mVertexColors[2], mVertexColors[3], Blend, Effect, mOrigin ); + S->draw( mPosition.x, mPosition.y, mRotation, mScale, mVertexColors[0], mVertexColors[1], mVertexColors[2], mVertexColors[3], Blend, Effect, mOrigin ); } void Sprite::draw() { @@ -722,22 +709,6 @@ SubTexture * Sprite::getSubTexture( const unsigned int& frame, const unsigned in return NULL; } -void Sprite::setX( const Float& X ) { - mPos.x = X; -} - -Float Sprite::getX() const { - return mPos.x; -} - -void Sprite::setY( const Float& Y ) { - mPos.y = Y; -} - -Float Sprite::getY() const { - return mPos.y; -} - void Sprite::setRotation( const Float& rotation ) { mRotation = rotation; } diff --git a/src/eepp/graphics/subtexture.cpp b/src/eepp/graphics/subtexture.cpp index 3350198c2..112a83fa5 100644 --- a/src/eepp/graphics/subtexture.cpp +++ b/src/eepp/graphics/subtexture.cpp @@ -173,6 +173,10 @@ void SubTexture::draw( const Quad2f Q, const Vector2f& Offset, const Float& Angl mTexture->drawQuadEx( Q, Offset, Angle, Scale, Color0, Color1, Color2, Color3, Blend, mSrcRect ); } +void SubTexture::draw() { + draw( mPosition ); +} + void SubTexture::draw( const Vector2f& position ) { draw( position.x, position.y, getColor() ); } diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index b84c4b917..67ec7ffce 100755 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -738,6 +738,10 @@ Sizei EE::Graphics::Texture::getPixelSize() { return Sizei( mImgWidth, mImgHeight ); } +void EE::Graphics::Texture::draw() { + drawFast( mPosition.x, mPosition.y ); +} + void EE::Graphics::Texture::draw( const Vector2f & position ) { drawFast( position.x, position.y ); } diff --git a/src/eepp/physics/shapecirclesprite.cpp b/src/eepp/physics/shapecirclesprite.cpp index c351ec62b..eb333bef6 100644 --- a/src/eepp/physics/shapecirclesprite.cpp +++ b/src/eepp/physics/shapecirclesprite.cpp @@ -26,7 +26,7 @@ ShapeCircleSprite::~ShapeCircleSprite() { void ShapeCircleSprite::draw( Space * space ) { cVect Pos = getBody()->getPos(); - mSprite->setPosition( Pos.x, Pos.y ); + mSprite->setPosition( Vector2f( Pos.x, Pos.y ) ); mSprite->setRotation( getBody()->getAngleDeg() ); mSprite->draw(); } diff --git a/src/eepp/physics/shapepolysprite.cpp b/src/eepp/physics/shapepolysprite.cpp index 18c534d75..b7f461f47 100644 --- a/src/eepp/physics/shapepolysprite.cpp +++ b/src/eepp/physics/shapepolysprite.cpp @@ -40,7 +40,7 @@ void ShapePolySprite::draw( Space * space ) { cVect Pos = getBody()->getPos(); mSprite->setOffset( mOffset ); - mSprite->setPosition( Pos.x, Pos.y ); + mSprite->setPosition( Vector2f( Pos.x, Pos.y ) ); mSprite->setRotation( getBody()->getAngleDeg() ); mSprite->draw(); } diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index 629f696d8..f9c7e1772 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -52,7 +52,7 @@ void UISprite::draw() { if ( NULL != mSprite && 0.f != mAlpha ) { checkSubTextureUpdate(); - mSprite->setPosition( (Float)( mScreenPos.x + mAlignOffset.x ), (Float)( mScreenPos.y + mAlignOffset.y ) ); + mSprite->setPosition( Vector2f( (Float)( mScreenPos.x + mAlignOffset.x ), (Float)( mScreenPos.y + mAlignOffset.y ) ) ); SubTexture * subTexture = mSprite->getCurrentSubTexture(); diff --git a/src/examples/empty_window/empty_window.cpp b/src/examples/empty_window/empty_window.cpp index 25cfff8f2..ccaa0d597 100644 --- a/src/examples/empty_window/empty_window.cpp +++ b/src/examples/empty_window/empty_window.cpp @@ -10,6 +10,7 @@ EE::Window::Window * win = NULL; float circ = 0, circ2 = 0; int op = 1; ArcDrawable arcDrawable( 100, 64 ); +RectangleDrawable rectDrawable( Vector2f(0,0), Sizef(250,250) ); void mainLoop() { @@ -84,6 +85,8 @@ void mainLoop() arcDrawable.setArcStartAngle( circ2 ); arcDrawable.draw( winCenter ); + rectDrawable.draw(); + // Draw frame win->display(); } @@ -102,6 +105,10 @@ EE_MAIN_FUNC int main (int argc, char * argv []) arcDrawable.setColorFilter( ColorA( 0, 255, 0, 150 ) ); arcDrawable.setFillMode( DRAW_FILL ); + rectDrawable.setColorFilter( ColorA( 255, 0, 0, 150 ) ); + rectDrawable.setFillMode( DRAW_FILL ); + rectDrawable.setCorners( 64 ); + // Set the MainLoop function and run it // This is the application loop, it will loop until the window is closed. // This is only a requirement if you want to support Emscripten builds ( WebGL + Canvas ). diff --git a/src/examples/sprites/sprites.cpp b/src/examples/sprites/sprites.cpp index d52f2d54e..d9184571c 100644 --- a/src/examples/sprites/sprites.cpp +++ b/src/examples/sprites/sprites.cpp @@ -139,11 +139,14 @@ EE_MAIN_FUNC int main (int argc, char * argv []) // Set the sprites position to the screen center Vector2i ScreenCenter( Engine::instance()->getCurrentWindow()->getWidth() / 2, Engine::instance()->getCurrentWindow()->getHeight() / 2 ); - Planet.setPosition( ScreenCenter.x - Planet.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Planet.getAABB().getSize().getHeight() / 2 ); + Planet.setPosition( Vector2f( ScreenCenter.x - Planet.getAABB().getSize().getWidth() / 2, + ScreenCenter.y - Planet.getAABB().getSize().getHeight() / 2 ) ); - Rock.setPosition( ScreenCenter.x - Rock.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Rock.getAABB().getSize().getHeight() / 2 ); + Rock.setPosition( Vector2f( ScreenCenter.x - Rock.getAABB().getSize().getWidth() / 2, + ScreenCenter.y - Rock.getAABB().getSize().getHeight() / 2 ) ); - Blindy.setPosition( ScreenCenter.x - Blindy.getAABB().getSize().getWidth() / 2, ScreenCenter.y - Blindy.getAABB().getSize().getHeight() / 2 ); + Blindy.setPosition( Vector2f( ScreenCenter.x - Blindy.getAABB().getSize().getWidth() / 2, + ScreenCenter.y - Blindy.getAABB().getSize().getHeight() / 2 ) ); // Set the planet angle interpolation PlanetAngle.addWaypoint( 0 ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 4ae0b944c..54696701c 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1104,7 +1104,7 @@ void EETest::loadTextures() { CurMan->set( EE_CURSOR_ARROW ); CL1.addFrame( TN[2] ); - CL1.setPosition( 500, 400 ); + CL1.setPosition( Vector2f( 500, 400 ) ); CL1.setScale( 0.5f ); CL2.addFrame(TN[0], Sizef(96, 96) ); @@ -1113,7 +1113,7 @@ void EETest::loadTextures() { mTGL = eeNew( TextureAtlasLoader, ( MyPath + "atlases/bnb" + EE_TEXTURE_ATLAS_EXTENSION ) ); mBlindy.addFramesByPattern( "rn" ); - mBlindy.setPosition( 320.f, 0.f ); + mBlindy.setPosition( Vector2f( 320.f, 0.f ) ); mBoxSprite = eeNew( Sprite, ( GlobalTextureAtlas::instance()->add( eeNew( SubTexture, ( TN[3], "ilmare" ) ) ) ) ); mCircleSprite = eeNew( Sprite, ( GlobalTextureAtlas::instance()->add( eeNew( SubTexture, ( TN[1], "thecircle" ) ) ) ) ); @@ -1242,7 +1242,7 @@ void EETest::screen2() { ColorA Col(255,255,255,(int)alpha); TNP[1]->drawEx( (Float)mWindow->getWidth() - 128.f, (Float)mWindow->getHeight() - 128.f, 128.f, 128.f, ang, Vector2f::One, Col, Col, Col, Col, ALPHA_BLENDONE, RN_FLIPMIRROR); - SP.setPosition( alpha, alpha ); + SP.setPosition( Vector2f( alpha, alpha ) ); SP.draw(); #ifndef EE_GLES @@ -1262,7 +1262,7 @@ void EETest::screen2() { CL1.setRotation(ang); CL1.setScale(scale * 0.5f); - CL2.setPosition( (Float)Mousef.x - 64.f, (Float)Mousef.y + 128.f ); + CL2.setPosition( Vector2f( (Float)Mousef.x - 64.f, (Float)Mousef.y + 128.f ) ); CL2.setRotation(-ang); CL1.draw(); @@ -1348,7 +1348,7 @@ void EETest::screen4() { } if ( NULL != mVBO ) { - mBlindy.setPosition( 128-16, 128-16 ); + mBlindy.setPosition( Vector2f( 128-16, 128-16 ) ); mBlindy.draw(); mVBO->bind();