diff --git a/include/eepp/graphics.hpp b/include/eepp/graphics.hpp index d9d73a4c1..87616670f 100644 --- a/include/eepp/graphics.hpp +++ b/include/eepp/graphics.hpp @@ -44,5 +44,6 @@ #include #include #include +#include #endif diff --git a/include/eepp/graphics/graphicshelper.hpp b/include/eepp/graphics/graphicshelper.hpp index a5deaba41..9c89410dc 100755 --- a/include/eepp/graphics/graphicshelper.hpp +++ b/include/eepp/graphics/graphicshelper.hpp @@ -192,6 +192,7 @@ enum EE_DRAWABLE_TYPE { DRAWABLE_RECTANGLE, DRAWABLE_CONVEXSHAPE, DRAWABLE_GROUP, + DRAWABLE_NINEPATCH, DRAWABLE_CUSTOM }; diff --git a/include/eepp/graphics/ninepatch.hpp b/include/eepp/graphics/ninepatch.hpp new file mode 100644 index 000000000..3adc99f01 --- /dev/null +++ b/include/eepp/graphics/ninepatch.hpp @@ -0,0 +1,48 @@ +#ifndef EE_GRAPHICS_NINEPATCH_HPP +#define EE_GRAPHICS_NINEPATCH_HPP + +#include +#include +#include + +namespace EE { namespace Graphics { + +class EE_API NinePatch : public Drawable { + public: + enum NinePatchSides { + Left = 0, + Right, + Down, + Up, + UpLeft, + UpRight, + DownLeft, + DownRight, + Center, + SideCount + }; + + NinePatch( const Uint32& TexId, int left, int top, int right, int bottom ); + + NinePatch( SubTexture * subTexture, int left, int top, int right, int bottom ); + + ~NinePatch(); + + virtual Sizef getSize(); + + virtual void draw(); + + virtual void draw( const Vector2f& position ); + + virtual void draw( const Vector2f& position, const Sizef& size ); + protected: + Drawable * mDrawable[ SideCount ]; + Rect mRect; + Sizei mSize; + + void createFromTexture( const Uint32& TexId, int left, int top, int right, int bottom ); +}; + +}} + +#endif diff --git a/include/eepp/graphics/subtexture.hpp b/include/eepp/graphics/subtexture.hpp index b83e03427..de0e0a146 100644 --- a/include/eepp/graphics/subtexture.hpp +++ b/include/eepp/graphics/subtexture.hpp @@ -18,14 +18,14 @@ class EE_API SubTexture : public Drawable { * @param TexId The texture id * @param Name The texture name ( if any ) */ - SubTexture( const Uint32& TexId, const std::string& getName = "" ); + SubTexture( const Uint32& TexId, const std::string& name = "" ); /** Creates a SubTexture of the indicated part of the texture. * @param TexId The texture id * @param SrcRect The texture part that will be used as the SubTexture. * @param Name The texture name ( if any ) */ - SubTexture( const Uint32& TexId, const Rect& srcRect, const std::string& getName = "" ); + SubTexture( const Uint32& TexId, const Rect& srcRect, const std::string& name = "" ); /** Creates a SubTexture of the indicated part of the texture. * @param TexId The texture id @@ -33,7 +33,7 @@ class EE_API SubTexture : public Drawable { * @param DestSize The destination size that the SubTexture will have when rendered. * @param Name The texture name ( if any ) */ - SubTexture( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const std::string& getName = "" ); + SubTexture( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const std::string& name = "" ); /** Creates a SubTexture of the indicated part of the texture. * @param TexId The texture id @@ -42,7 +42,7 @@ class EE_API SubTexture : public Drawable { * @param Offset The offset that will be added to the position passed when any Draw call is used. * @param Name The texture name ( if any ) */ - SubTexture( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const Vector2i& offset, const std::string& getName = "" ); + SubTexture( const Uint32& TexId, const Rect& srcRect, const Sizef& destSize, const Vector2i& offset, const std::string& name = "" ); virtual ~SubTexture(); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index caad1366d..fbebf8082 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -9,6 +9,7 @@ ../../include/eepp/graphics/fonttruetype.hpp ../../include/eepp/graphics/fonttruetypeloader.hpp ../../include/eepp/graphics/graphicshelper.hpp +../../include/eepp/graphics/ninepatch.hpp ../../include/eepp/graphics/primitivedrawable.hpp ../../include/eepp/graphics/rectangledrawable.hpp ../../include/eepp/graphics/renderer/base.hpp @@ -46,6 +47,7 @@ ../../include/eepp/ui/uiwidgetcreator.hpp ../../src/eepp/graphics/convexshapedrawable.cpp ../../src/eepp/graphics/drawablegroup.cpp +../../src/eepp/graphics/ninepatch.cpp ../../src/eepp/maps/mapobjectlayer.cpp ../../src/eepp/graphics/arcdrawable.cpp ../../src/eepp/graphics/circledrawable.cpp diff --git a/src/eepp/graphics/ninepatch.cpp b/src/eepp/graphics/ninepatch.cpp new file mode 100644 index 000000000..a2502fe8b --- /dev/null +++ b/src/eepp/graphics/ninepatch.cpp @@ -0,0 +1,94 @@ +#include +#include + +namespace EE { namespace Graphics { + +NinePatch::NinePatch( const Uint32& TexId, int left, int top, int right, int bottom ) : + Drawable( DRAWABLE_NINEPATCH ), + mRect( left, top, right, bottom ) +{ + for ( Int32 i = 0; i < SideCount; i++ ) + mDrawable[ i ] = NULL; + + Texture * tex = TextureFactory::instance()->getTexture( TexId ); + + if ( NULL != tex ) { + mSize = tex->getPixelSize(); + + createFromTexture( TexId, left, top, right, bottom ); + } +} + +NinePatch::NinePatch( SubTexture * subTexture, int left, int top, int right, int bottom ): + Drawable( DRAWABLE_NINEPATCH ), + mRect( left, top, right, bottom ) +{ + for ( Int32 i = 0; i < SideCount; i++ ) + mDrawable[ i ] = NULL; + + Texture * tex; + + if ( NULL != subTexture && ( tex = subTexture->getTexture() ) != NULL ) { + Rect r( subTexture->getSrcRect() ); + + mSize = r.getSize(); + + createFromTexture( tex->getId(), left, top, right, bottom ); + + for ( int i = 0; i < SideCount; i++ ) { + SubTexture * side = static_cast( mDrawable[i] ); + + Rect sideRect = side->getSrcRect(); + + sideRect.Left += r.Left; + sideRect.Right += r.Left; + sideRect.Top += r.Top; + sideRect.Bottom += r.Top; + + side->setSrcRect( sideRect ); + } + } +} + +NinePatch::~NinePatch() { + for ( Int32 i = 0; i < SideCount; i++ ) + eeSAFE_DELETE( mDrawable[ i ] ); +} + +Sizef NinePatch::getSize() { + return Sizef( mSize.getWidth(), mSize.getHeight() ); +} + +void NinePatch::draw() { + draw( mPosition ); +} + +void NinePatch::draw( const Vector2f& position ) { + draw( position, getSize() ); +} + +void NinePatch::draw( const Vector2f& position, const Sizef& size ) { + mDrawable[ UpLeft ]->draw( position ); + mDrawable[ Left ]->draw( Vector2f( position.x, position.y + mRect.Top ), Sizef( mRect.Left, size.getHeight() - mRect.Top - mRect.Bottom ) ); + mDrawable[ DownLeft ]->draw( Vector2f( position.x, position.y + size.getHeight() - mRect.Bottom ) ); + mDrawable[ Up ]->draw( Vector2f( position.x + mRect.Left, position.y ), Sizef( size.getWidth() - mRect.Left - mRect.Right, mRect.Top ) ); + mDrawable[ Center ]->draw( Vector2f( position.x + mRect.Left, position.y + mRect.Top ), Sizef( size.getWidth() - mRect.Left - mRect.Right, size.getHeight() - mRect.Top - mRect.Bottom ) ); + mDrawable[ Down ]->draw( Vector2f( position.x + mRect.Left, position.y + size.getHeight() - mRect.Bottom ), Sizef( size.getWidth() - mRect.Left - mRect.Right, mRect.Bottom ) ); + mDrawable[ UpRight ]->draw( Vector2f( position.x + size.getWidth() - mRect.Right, position.y ) ); + mDrawable[ Right ]->draw( Vector2f( position.x + size.getWidth() - mRect.Right, position.y + mRect.Top ), Vector2f( mRect.Right, size.getHeight() - mRect.Top - mRect.Bottom ) ); + mDrawable[ DownRight ]->draw( Vector2f( position.x + size.getWidth() - mRect.Right, position.y + size.getHeight() - mRect.Bottom ) ); +} + +void NinePatch::createFromTexture(const Uint32 & TexId, int left, int top, int right, int bottom) { + mDrawable[ Left ] = eeNew( SubTexture, ( TexId, Rect( 0, top, left, mSize.getHeight() - bottom ) ) ); + mDrawable[ Right ] = eeNew( SubTexture, ( TexId, Rect( mSize.getWidth() - right, top, mSize.getWidth(), mSize.getHeight() - bottom ) ) ); + mDrawable[ Down ] = eeNew( SubTexture, ( TexId, Rect( left, mSize.getHeight() - bottom, mSize.getWidth() - right, mSize.getHeight() ) ) ); + mDrawable[ Up ] = eeNew( SubTexture, ( TexId, Rect( left, 0, mSize.getWidth() - right, top ) ) ); + mDrawable[ UpLeft ] = eeNew( SubTexture, ( TexId, Rect( 0, 0, left, top ) ) ); + mDrawable[ UpRight] = eeNew( SubTexture, ( TexId, Rect( mSize.getWidth() - right, 0, mSize.getWidth(), top ) ) ); + mDrawable[ DownLeft] = eeNew( SubTexture, ( TexId, Rect( 0, mSize.getHeight() - bottom, left, mSize.getHeight() ) ) ); + mDrawable[ DownRight ] = eeNew( SubTexture, ( TexId, Rect( mSize.getWidth() - right, mSize.getHeight() - bottom, mSize.getWidth(), mSize.getHeight() ) ) ); + mDrawable[ Center ] = eeNew( SubTexture, ( TexId, Rect( left, top, mSize.getWidth() - right, mSize.getHeight() - bottom ) ) ); +} + +}} diff --git a/src/eepp/graphics/subtexture.cpp b/src/eepp/graphics/subtexture.cpp index 5a34a7fc1..ca75e82e7 100644 --- a/src/eepp/graphics/subtexture.cpp +++ b/src/eepp/graphics/subtexture.cpp @@ -25,11 +25,11 @@ SubTexture::SubTexture() : createUnnamed(); } -SubTexture::SubTexture( const Uint32& TexId, const std::string& Name ) : +SubTexture::SubTexture( const Uint32& TexId, const std::string& name ) : Drawable( DRAWABLE_SUBTEXTURE ), mPixels(NULL), mAlphaMask(NULL), - mName( Name ), + mName( name ), mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), @@ -42,11 +42,11 @@ SubTexture::SubTexture( const Uint32& TexId, const std::string& Name ) : createUnnamed(); } -SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const std::string& Name ) : +SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const std::string& name ) : Drawable( DRAWABLE_SUBTEXTURE ), mPixels(NULL), mAlphaMask(NULL), - mName( Name ), + mName( name ), mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), @@ -59,11 +59,11 @@ SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const std::str createUnnamed(); } -SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name ) : +SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& name ) : Drawable( DRAWABLE_SUBTEXTURE ), mPixels(NULL), mAlphaMask(NULL), - mName( Name ), + mName( name ), mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), @@ -76,11 +76,11 @@ SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const Sizef& D createUnnamed(); } -SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i &Offset, const std::string& Name ) : +SubTexture::SubTexture(const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i &Offset, const std::string& name ) : Drawable( DRAWABLE_SUBTEXTURE ), mPixels(NULL), mAlphaMask(NULL), - mName( Name ), + mName( name ), mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index b1e70ef85..6043abd2a 100755 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -744,24 +744,24 @@ void Texture::drawQuadEx( Quad2f Q, const Vector2f& Offset, const Float &Angle, sBR->drawOpt(); } -}} - -Sizef EE::Graphics::Texture::getSize() { +Sizef Texture::getSize() { return Sizef( PixelDensity::pxToDp( mImgWidth ), PixelDensity::pxToDp( mImgHeight ) ); } -Sizei EE::Graphics::Texture::getPixelSize() { +Sizei Texture::getPixelSize() { return Sizei( mImgWidth, mImgHeight ); } -void EE::Graphics::Texture::draw() { +void Texture::draw() { drawFast( mPosition.x, mPosition.y ); } -void EE::Graphics::Texture::draw( const Vector2f & position ) { +void Texture::draw( const Vector2f & position ) { drawFast( position.x, position.y ); } -void EE::Graphics::Texture::draw(const Vector2f & position, const Sizef & size) { +void Texture::draw(const Vector2f & position, const Sizef & size) { drawFast( position.x, position.y, 0, Vector2f::One, mColor, ALPHA_NORMAL, size.x, size.y ); } + +}} diff --git a/src/eepp/ui/uiskincomplex.cpp b/src/eepp/ui/uiskincomplex.cpp index 34c358c72..14abd5339 100644 --- a/src/eepp/ui/uiskincomplex.cpp +++ b/src/eepp/ui/uiskincomplex.cpp @@ -45,7 +45,6 @@ UISkinComplex::~UISkinComplex() { #define DRAWABLE_PX_SIZE PixelDensity::dpToPx( tDrawable->getSize() ).ceil() - void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, const Float& Height, const Uint32& Alpha, const Uint32& State ) { if ( 0 == Alpha ) return;