diff --git a/bin/assets/ui/uitheme/uitheme_combobox_normal_ml.png b/bin/assets/ui/uitheme/uitheme_combobox_normal_ml.png index 6d3cef0c1..8e91d63ac 100644 Binary files a/bin/assets/ui/uitheme/uitheme_combobox_normal_ml.png and b/bin/assets/ui/uitheme/uitheme_combobox_normal_ml.png differ diff --git a/bin/assets/ui/uitheme/uitheme_combobox_normal_ul.png b/bin/assets/ui/uitheme/uitheme_combobox_normal_ul.png index 58e68887f..4d2e97923 100644 Binary files a/bin/assets/ui/uitheme/uitheme_combobox_normal_ul.png and b/bin/assets/ui/uitheme/uitheme_combobox_normal_ul.png differ diff --git a/bin/assets/ui/uitheme/uitheme_genericgrid_normal_m.png b/bin/assets/ui/uitheme/uitheme_genericgrid_normal_m.png index 7e8088deb..3ce42ac03 100644 Binary files a/bin/assets/ui/uitheme/uitheme_genericgrid_normal_m.png and b/bin/assets/ui/uitheme/uitheme_genericgrid_normal_m.png differ diff --git a/bin/assets/ui/uitheme/uitheme_listbox_normal_m.png b/bin/assets/ui/uitheme/uitheme_listbox_normal_m.png index 7e8088deb..3ce42ac03 100644 Binary files a/bin/assets/ui/uitheme/uitheme_listbox_normal_m.png and b/bin/assets/ui/uitheme/uitheme_listbox_normal_m.png differ diff --git a/bin/assets/ui/uitheme/uitheme_textedit_normal_m.png b/bin/assets/ui/uitheme/uitheme_textedit_normal_m.png index 7e8088deb..3ce42ac03 100644 Binary files a/bin/assets/ui/uitheme/uitheme_textedit_normal_m.png and b/bin/assets/ui/uitheme/uitheme_textedit_normal_m.png differ diff --git a/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ml.png b/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ml.png index aeacbbdb8..4543d4f11 100644 Binary files a/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ml.png and b/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ml.png differ diff --git a/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ul.png b/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ul.png index 26e097205..6d07a27fe 100644 Binary files a/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ul.png and b/bin/assets/ui/uitheme2x/uitheme2x_combobox_normal_ul.png differ diff --git a/bin/assets/ui/uitheme2x/uitheme2x_genericgrid_normal_m.png b/bin/assets/ui/uitheme2x/uitheme2x_genericgrid_normal_m.png index 88e10832a..adf09574f 100644 Binary files a/bin/assets/ui/uitheme2x/uitheme2x_genericgrid_normal_m.png and b/bin/assets/ui/uitheme2x/uitheme2x_genericgrid_normal_m.png differ diff --git a/bin/assets/ui/uitheme2x/uitheme2x_listbox_normal_m.png b/bin/assets/ui/uitheme2x/uitheme2x_listbox_normal_m.png index 88e10832a..adf09574f 100644 Binary files a/bin/assets/ui/uitheme2x/uitheme2x_listbox_normal_m.png and b/bin/assets/ui/uitheme2x/uitheme2x_listbox_normal_m.png differ diff --git a/bin/assets/ui/uitheme2x/uitheme2x_textedit_normal_m.png b/bin/assets/ui/uitheme2x/uitheme2x_textedit_normal_m.png index 88e10832a..adf09574f 100644 Binary files a/bin/assets/ui/uitheme2x/uitheme2x_textedit_normal_m.png and b/bin/assets/ui/uitheme2x/uitheme2x_textedit_normal_m.png differ diff --git a/include/eepp/graphics/drawableresource.hpp b/include/eepp/graphics/drawableresource.hpp new file mode 100644 index 000000000..dfec8a231 --- /dev/null +++ b/include/eepp/graphics/drawableresource.hpp @@ -0,0 +1,47 @@ +#ifndef EE_GRAPHICS_DRAWABLERESOURCE_HPP +#define EE_GRAPHICS_DRAWABLERESOURCE_HPP + +#include +#include + +namespace EE { namespace Graphics { + +class EE_API DrawableResource : public Drawable +{ + public: + /** @return The DrawableResource Id. The Id is the String::hash of the SubTexture name. */ + const Uint32& getId() const; + + /** @return The DrawableResource Name. */ + const std::string getName() const; + + /** Sets the DrawableResource Name, it will also change the Id. */ + void setName( const std::string& name ); + + /** @return The Destination Size of the DrawableResource. */ + virtual const Sizef& getDestSize() const = 0; + + /** Sets the Destination Size of the DrawableResource. + * The size can be different from the original size of the DrawableResource. + * For example if the DrawableResource width is 32 pixels, by default the destination width is 32 pixels, but it can be changed to anything want. */ + virtual void setDestSize( const Sizef& destSize ) = 0; + + /** @return The DrawableResource default offset. The offset is added to the position passed when is drawed. */ + virtual const Vector2i& getOffset() const = 0; + + /** Set the SubTexture offset. */ + virtual void setOffset( const Vector2i& offset ) = 0; + protected: + std::string mName; + Uint32 mId; + + DrawableResource( EE_DRAWABLE_TYPE drawableType ); + + DrawableResource( EE_DRAWABLE_TYPE drawableType, const std::string& name ); + + void createUnnamed(); +}; + +}} + +#endif diff --git a/include/eepp/graphics/ninepatch.hpp b/include/eepp/graphics/ninepatch.hpp index 3adc99f01..6532b0e55 100644 --- a/include/eepp/graphics/ninepatch.hpp +++ b/include/eepp/graphics/ninepatch.hpp @@ -7,7 +7,7 @@ namespace EE { namespace Graphics { -class EE_API NinePatch : public Drawable { +class EE_API NinePatch : public DrawableResource { public: enum NinePatchSides { Left = 0, @@ -22,9 +22,9 @@ class EE_API NinePatch : public Drawable { SideCount }; - NinePatch( const Uint32& TexId, int left, int top, int right, int bottom ); + NinePatch( const Uint32& TexId, int left, int top, int right, int bottom, const std::string& name = "" ); - NinePatch( SubTexture * subTexture, int left, int top, int right, int bottom ); + NinePatch( SubTexture * subTexture, int left, int top, int right, int bottom, const std::string& name = "" ); ~NinePatch(); @@ -35,10 +35,20 @@ class EE_API NinePatch : public Drawable { virtual void draw( const Vector2f& position ); virtual void draw( const Vector2f& position, const Sizef& size ); + + const Sizef& getDestSize() const; + + void setDestSize( const Sizef& destSize ); + + const Vector2i& getOffset() const; + + void setOffset( const Vector2i& offset ); protected: Drawable * mDrawable[ SideCount ]; Rect mRect; Sizei mSize; + Sizef mDestSize; + Vector2i mOffset; void createFromTexture( const Uint32& TexId, int left, int top, int right, int bottom ); }; diff --git a/include/eepp/graphics/sprite.hpp b/include/eepp/graphics/sprite.hpp index 37d84f5ed..c364c7517 100755 --- a/include/eepp/graphics/sprite.hpp +++ b/include/eepp/graphics/sprite.hpp @@ -194,12 +194,12 @@ class EE_API Sprite : public Drawable { * @param SubTexture The SubTexture used in the frame * @return The frame position or 0 if fails */ - unsigned int addFrame( SubTexture * SubTexture ); + unsigned int addFrame( DrawableResource * SubTexture ); /** Add a vector of SubTexture as an animation. * @param SubTextures The Frames */ - bool addFrames( const std::vector SubTextures ); + bool addFrames( const std::vector SubTextures ); /** @see TextureAtlasManager::GetSubTexturesByPattern */ bool addFramesByPattern( const std::string& name, const std::string& extension = "", TextureAtlas * SearchInTextureAtlas = NULL ); @@ -223,7 +223,7 @@ class EE_API Sprite : public Drawable { * @param NumSubFrame The Sub Frame Number * @return True if success */ - bool addSubFrame( SubTexture * SubTexture, const unsigned int& NumFrame, const unsigned int& NumSubFrame ); + bool addSubFrame( DrawableResource * SubTexture, const unsigned int& NumFrame, const unsigned int& NumSubFrame ); /** Draw the sprite to the screen */ void draw(); @@ -272,13 +272,13 @@ class EE_API Sprite : public Drawable { void setReverseFromStart(); /** @return The Current SubTexture */ - SubTexture * getCurrentSubTexture(); + DrawableResource * getCurrentSubTexture(); /** @return The SubTexture Frame from the current sub frame */ - SubTexture * getSubTexture( const unsigned int& frame ); + DrawableResource * getSubTexture( const unsigned int& frame ); /** @return The SubTexture Frame from the SubFrame */ - SubTexture * getSubTexture( const unsigned int& frame, const unsigned int& SubFrame ); + DrawableResource * getSubTexture( const unsigned int& frame, const unsigned int& SubFrame ); /** Start playing from ** @param GoTo Frame that goes from 1 to Number of Frames @@ -343,7 +343,7 @@ class EE_API Sprite : public Drawable { class Frame { public: - std::vector Spr; + std::vector Spr; }; std::vector mFrames; diff --git a/include/eepp/graphics/subtexture.hpp b/include/eepp/graphics/subtexture.hpp index de0e0a146..a927562c0 100644 --- a/include/eepp/graphics/subtexture.hpp +++ b/include/eepp/graphics/subtexture.hpp @@ -4,12 +4,12 @@ #include #include #include -#include +#include namespace EE { namespace Graphics { /** @brief A SubTexture is a part of a texture that represent an sprite.*/ -class EE_API SubTexture : public Drawable { +class EE_API SubTexture : public DrawableResource { public: /** Creates an empty SubTexture */ SubTexture(); @@ -46,15 +46,6 @@ class EE_API SubTexture : public Drawable { virtual ~SubTexture(); - /** @return The SubTexture Id. The Id is the String::hash of the SubTexture name. */ - const Uint32& getId() const; - - /** @return The SubTexture Name. */ - const std::string getName() const; - - /** Sets the SubTexture Name, it will also change the Id. */ - void setName( const std::string& name ); - /** @return The Texture Id that holds the SubTexture. */ const Uint32& getTextureId(); @@ -165,8 +156,6 @@ class EE_API SubTexture : public Drawable { protected: Uint8 * mPixels; Uint8 * mAlphaMask; - std::string mName; - Uint32 mId; Uint32 mTexId; Graphics::Texture * mTexture; Rect mSrcRect; @@ -174,8 +163,6 @@ class EE_API SubTexture : public Drawable { Sizef mDestSize; Vector2i mOffset; Float mPixelDensity; - - void createUnnamed(); }; }} diff --git a/include/eepp/graphics/textureatlas.hpp b/include/eepp/graphics/textureatlas.hpp index ec33064ab..1d957b215 100644 --- a/include/eepp/graphics/textureatlas.hpp +++ b/include/eepp/graphics/textureatlas.hpp @@ -9,28 +9,28 @@ namespace EE { namespace Graphics { /** @brief The texture atlas class represents a large image containing a collection of sub-images, or "atlas" which contains many smaller sub-images. * The texture atlas in eepp can represent more than one texture or image, but the common use should be a image with sub-images. * More information about Texture Atlases: http://en.wikipedia.org/wiki/Texture_atlas */ -class EE_API TextureAtlas : public ResourceManager { +class EE_API TextureAtlas : public ResourceManager { public: /** Creates a new texture atlas with the given name. */ TextureAtlas( const std::string& name = "" ); ~TextureAtlas(); - /** Adds a SubTexture to the Texture Atlas */ - SubTexture * add( SubTexture * subTexture ); + /** Adds a Drawable Resource to the Texture Atlas */ + DrawableResource * add( DrawableResource * drawableResource ); /** Creates and add to the texture atlas a SubTexture from a Texture. It will use the full Texture as a SubTexture. * @param TexId The texture id * @param Name The texture name ( if any ) */ - SubTexture * add( const Uint32& TexId, const std::string& Name = "" ); + DrawableResource * add( const Uint32& TexId, const std::string& Name = "" ); /** Creates and add to the texture atlas 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 * add( const Uint32& TexId, const Rect& SrcRect, const std::string& Name = "" ); + DrawableResource * add( const Uint32& TexId, const Rect& SrcRect, const std::string& Name = "" ); /** Creates and add to the texture atlas a SubTexture of the indicated part of the texture. * @param TexId The texture id @@ -38,7 +38,7 @@ class EE_API TextureAtlas : public ResourceManager { * @param DestSize The destination size that the SubTexture will have when rendered. * @param Name The texture name ( if any ) */ - SubTexture * add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name = "" ); + DrawableResource * add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name = "" ); /** Creates and add to the texture atlas a SubTexture of the indicated part of the texture. * @param TexId The texture id @@ -47,7 +47,7 @@ class EE_API TextureAtlas : public ResourceManager { * @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 * add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "" ); + DrawableResource * add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "" ); /** @return The texture atlas name. */ const std::string& getName() const; @@ -63,7 +63,7 @@ class EE_API TextureAtlas : public ResourceManager { /** @return The texture atlas Id. The Id is the String::hash of the texture atlas name. */ const Uint32& getId() const; - + /** @return The number of SubTextures inside the texture atlas. */ Uint32 getCount(); diff --git a/include/eepp/graphics/textureatlasmanager.hpp b/include/eepp/graphics/textureatlasmanager.hpp index 85685e8f8..ef456f0dc 100644 --- a/include/eepp/graphics/textureatlasmanager.hpp +++ b/include/eepp/graphics/textureatlasmanager.hpp @@ -29,11 +29,11 @@ class EE_API TextureAtlasManager : public ResourceManager { /** It will search for a SubTexture Name in the texture atlases loaded. * @return The first SubTexture found with the given name in any atlas. */ - SubTexture * getSubTextureByName( const std::string& Name ); + DrawableResource * getSubTextureByName( const std::string& Name ); /** It will search for a SubTexture Id in the texture atlases loaded. * @return The first SubTexture found with the given id in any atlas. */ - SubTexture * getSubTextureById( const Uint32& Id ); + DrawableResource * getSubTextureById( const Uint32& Id ); /** Search for a pattern name * For example search for name "car" with extensions "png", i will try to find car00.png car01.png car02.png, and so on, it will continue if find something, otherwise it will stop ( it will always search at least for car00.png and car01.png ) @@ -42,13 +42,13 @@ class EE_API TextureAtlasManager : public ResourceManager { * @param SearchInTextureAtlas If you want only to search in a especific atlas ( NULL if you want to search in all atlases ) * @note Texture atlases saves the SubTextures names without extension by default. */ - std::vector getSubTexturesByPattern( const std::string& name, const std::string& extension = "", TextureAtlas * SearchInTextureAtlas = NULL ); + std::vector getSubTexturesByPattern( const std::string& name, const std::string& extension = "", TextureAtlas * SearchInTextureAtlas = NULL ); /** Search for a pattern id. * This will look for the SubTexture with the id passed, and it will try to find any pattern by the SubTexture name. * @see GetSubTexturesByPattern */ - std::vector getSubTexturesByPatternId( const Uint32& SubTextureId, const std::string& extension = "", TextureAtlas * SearchInTextureAtlas = NULL ); + std::vector getSubTexturesByPatternId( const Uint32& SubTextureId, const std::string& extension = "", TextureAtlas * SearchInTextureAtlas = NULL ); /** Prints all the resources name to the screen. */ void printResources(); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index fbebf8082..74d4dada7 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -3,6 +3,7 @@ ../../include/eepp/graphics/convexshapedrawable.hpp ../../include/eepp/graphics/drawable.hpp ../../include/eepp/graphics/drawablegroup.hpp +../../include/eepp/graphics/drawableresource.hpp ../../include/eepp/graphics/drawablesearcher.hpp ../../include/eepp/graphics/font.hpp ../../include/eepp/graphics/fontstyleconfig.hpp @@ -47,6 +48,7 @@ ../../include/eepp/ui/uiwidgetcreator.hpp ../../src/eepp/graphics/convexshapedrawable.cpp ../../src/eepp/graphics/drawablegroup.cpp +../../src/eepp/graphics/drawableresource.cpp ../../src/eepp/graphics/ninepatch.cpp ../../src/eepp/maps/mapobjectlayer.cpp ../../src/eepp/graphics/arcdrawable.cpp diff --git a/src/eepp/graphics/drawableresource.cpp b/src/eepp/graphics/drawableresource.cpp new file mode 100644 index 000000000..cd4bf9d06 --- /dev/null +++ b/src/eepp/graphics/drawableresource.cpp @@ -0,0 +1,37 @@ +#include + +namespace EE { namespace Graphics { + +DrawableResource::DrawableResource( EE_DRAWABLE_TYPE drawableType ) : + Drawable( drawableType ), + mId(0) +{ + createUnnamed(); +} + +DrawableResource::DrawableResource( EE_DRAWABLE_TYPE drawableType, const std::string& name ) : + Drawable( drawableType ), + mId(0) +{ + setName( name ); +} + +const Uint32& DrawableResource::getId() const { + return mId; +} + +const std::string DrawableResource::getName() const { + return mName; +} + +void DrawableResource::setName( const std::string& name ) { + mName = name; + mId = String::hash( mName ); +} + +void DrawableResource::createUnnamed() { + if ( !mName.size() ) + setName( std::string( "unnamed" ) ); +} + +}} diff --git a/src/eepp/graphics/drawablesearcher.cpp b/src/eepp/graphics/drawablesearcher.cpp index b6ad83ba5..1fe8483a6 100644 --- a/src/eepp/graphics/drawablesearcher.cpp +++ b/src/eepp/graphics/drawablesearcher.cpp @@ -9,7 +9,7 @@ namespace EE { namespace Graphics { bool DrawableSearcher::sPrintWarnings = false; static Drawable * getSprite( const std::string& sprite ) { - std::vector tSubTextureVec = TextureAtlasManager::instance()->getSubTexturesByPattern( sprite ); + std::vector tSubTextureVec = TextureAtlasManager::instance()->getSubTexturesByPattern( sprite ); if ( tSubTextureVec.size() ) { Sprite * tSprite = eeNew( Graphics::Sprite, () ); diff --git a/src/eepp/graphics/ninepatch.cpp b/src/eepp/graphics/ninepatch.cpp index a2502fe8b..652fa1146 100644 --- a/src/eepp/graphics/ninepatch.cpp +++ b/src/eepp/graphics/ninepatch.cpp @@ -3,8 +3,8 @@ namespace EE { namespace Graphics { -NinePatch::NinePatch( const Uint32& TexId, int left, int top, int right, int bottom ) : - Drawable( DRAWABLE_NINEPATCH ), +NinePatch::NinePatch( const Uint32& TexId, int left, int top, int right, int bottom, const std::string& name ) : + DrawableResource( DRAWABLE_NINEPATCH, name ), mRect( left, top, right, bottom ) { for ( Int32 i = 0; i < SideCount; i++ ) @@ -14,13 +14,14 @@ NinePatch::NinePatch( const Uint32& TexId, int left, int top, int right, int bot if ( NULL != tex ) { mSize = tex->getPixelSize(); + mDestSize = Sizef( mSize.x, mSize.y ); createFromTexture( TexId, left, top, right, bottom ); } } -NinePatch::NinePatch( SubTexture * subTexture, int left, int top, int right, int bottom ): - Drawable( DRAWABLE_NINEPATCH ), +NinePatch::NinePatch( SubTexture * subTexture, int left, int top, int right, int bottom, const std::string& name ): + DrawableResource( DRAWABLE_NINEPATCH, name ), mRect( left, top, right, bottom ) { for ( Int32 i = 0; i < SideCount; i++ ) @@ -32,6 +33,7 @@ NinePatch::NinePatch( SubTexture * subTexture, int left, int top, int right, int Rect r( subTexture->getSrcRect() ); mSize = r.getSize(); + mDestSize = Sizef( mSize.x, mSize.y ); createFromTexture( tex->getId(), left, top, right, bottom ); @@ -59,6 +61,14 @@ Sizef NinePatch::getSize() { return Sizef( mSize.getWidth(), mSize.getHeight() ); } +const Vector2i& NinePatch::getOffset() const { + return mOffset; +} + +void NinePatch::setOffset( const Vector2i& offset ) { + mOffset = offset; +} + void NinePatch::draw() { draw( mPosition ); } @@ -68,15 +78,24 @@ void NinePatch::draw( const Vector2f& position ) { } 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 ) ); + Vector2f pos( position.x + mOffset.x, position.y + mOffset.y ); + mDrawable[ UpLeft ]->draw( pos ); + mDrawable[ Left ]->draw( Vector2f( pos.x, pos.y + mRect.Top ), Sizef( mRect.Left, size.getHeight() - mRect.Top - mRect.Bottom ) ); + mDrawable[ DownLeft ]->draw( Vector2f( pos.x, pos.y + size.getHeight() - mRect.Bottom ) ); + mDrawable[ Up ]->draw( Vector2f( pos.x + mRect.Left, pos.y ), Sizef( size.getWidth() - mRect.Left - mRect.Right, mRect.Top ) ); + mDrawable[ Center ]->draw( Vector2f( pos.x + mRect.Left, pos.y + mRect.Top ), Sizef( size.getWidth() - mRect.Left - mRect.Right, size.getHeight() - mRect.Top - mRect.Bottom ) ); + mDrawable[ Down ]->draw( Vector2f( pos.x + mRect.Left, pos.y + size.getHeight() - mRect.Bottom ), Sizef( size.getWidth() - mRect.Left - mRect.Right, mRect.Bottom ) ); + mDrawable[ UpRight ]->draw( Vector2f( pos.x + size.getWidth() - mRect.Right, pos.y ) ); + mDrawable[ Right ]->draw( Vector2f( pos.x + size.getWidth() - mRect.Right, pos.y + mRect.Top ), Vector2f( mRect.Right, size.getHeight() - mRect.Top - mRect.Bottom ) ); + mDrawable[ DownRight ]->draw( Vector2f( pos.x + size.getWidth() - mRect.Right, pos.y + size.getHeight() - mRect.Bottom ) ); +} + +const Sizef &NinePatch::getDestSize() const { + return mDestSize; +} + +void NinePatch::setDestSize(const Sizef & destSize) { + mDestSize = destSize; } void NinePatch::createFromTexture(const Uint32 & TexId, int left, int top, int right, int bottom) { diff --git a/src/eepp/graphics/sprite.cpp b/src/eepp/graphics/sprite.cpp index 290be61b1..6270a5549 100755 --- a/src/eepp/graphics/sprite.cpp +++ b/src/eepp/graphics/sprite.cpp @@ -219,7 +219,7 @@ void Sprite::setCurrentSubFrame( const unsigned int& CurSubFrame ) { } Quad2f Sprite::getQuad() { - SubTexture * S; + DrawableResource * S; if ( mFrames.size() && ( S = getCurrentSubTexture() ) ) { Rectf TmpR( mPosition.x, @@ -277,7 +277,7 @@ Quad2f Sprite::getQuad() { Rectf Sprite::getAABB() { Rectf TmpR; - SubTexture * S; + DrawableResource * S; if ( mFrames.size() && ( S = getCurrentSubTexture() ) ) { if ( mRotation != 0 || mEffect >= 4 ) { @@ -350,7 +350,7 @@ void Sprite::createAnimation( const unsigned int& SubFramesNum ) { mSubFrames = SubFramesNum; } -bool Sprite::addFrames( const std::vector SubTextures ) { +bool Sprite::addFrames( const std::vector SubTextures ) { if ( SubTextures.size() ) { for ( unsigned int i = 0; i < SubTextures.size(); i++ ) { if ( NULL != SubTextures[i] ) { @@ -365,7 +365,7 @@ bool Sprite::addFrames( const std::vector SubTextures ) { } bool Sprite::addFramesByPatternId( const Uint32& SubTextureId, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) { - std::vector SubTextures = TextureAtlasManager::instance()->getSubTexturesByPatternId( SubTextureId, extension, SearchInTextureAtlas ); + std::vector SubTextures = TextureAtlasManager::instance()->getSubTexturesByPatternId( SubTextureId, extension, SearchInTextureAtlas ); if ( SubTextures.size() ) { addFrames( SubTextures ); @@ -379,7 +379,7 @@ bool Sprite::addFramesByPatternId( const Uint32& SubTextureId, const std::string } bool Sprite::addFramesByPattern( const std::string& name, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) { - std::vector SubTextures = TextureAtlasManager::instance()->getSubTexturesByPattern( name, extension, SearchInTextureAtlas ); + std::vector SubTextures = TextureAtlasManager::instance()->getSubTexturesByPattern( name, extension, SearchInTextureAtlas ); if ( SubTextures.size() ) { addFrames( SubTextures ); @@ -392,7 +392,7 @@ bool Sprite::addFramesByPattern( const std::string& name, const std::string& ext return false; } -bool Sprite::addSubFrame( SubTexture * SubTexture, const unsigned int& NumFrame, const unsigned int& NumSubFrame ) { +bool Sprite::addSubFrame( DrawableResource * SubTexture, const unsigned int& NumFrame, const unsigned int& NumSubFrame ) { unsigned int NF, NSF; if ( NumFrame >= mFrames.size() ) @@ -417,7 +417,7 @@ bool Sprite::addSubFrame( SubTexture * SubTexture, const unsigned int& NumFrame, return false; } -unsigned int Sprite::addFrame( SubTexture * SubTexture ) { +unsigned int Sprite::addFrame( DrawableResource * SubTexture ) { unsigned int id = framePos(); addSubFrame( SubTexture, id, mCurrentSubFrame ); @@ -439,7 +439,7 @@ bool Sprite::addSubFrame(const Uint32& TexId, const unsigned int& NumFrame, cons return false; Texture * Tex = TextureFactory::instance()->getTexture( TexId ); - SubTexture * S = GlobalTextureAtlas::instance()->add( eeNew( SubTexture, () ) ); + SubTexture * S = (SubTexture*)GlobalTextureAtlas::instance()->add( eeNew( SubTexture, () ) ); S->setTextureId( TexId ); @@ -568,15 +568,20 @@ void Sprite::draw( const EE_BLEND_MODE& Blend, const EE_RENDER_MODE& Effect ) { if ( SPR_FGET( SPRITE_FLAG_AUTO_ANIM ) ) update(); - SubTexture * S = getCurrentSubTexture(); + DrawableResource * S = getCurrentSubTexture(); if ( S == NULL ) return; - if ( NULL == mVertexColors ) - S->draw( mPosition.x, mPosition.y, mColor, mRotation, mScale, Blend, Effect, mOrigin ); - else - S->draw( mPosition.x, mPosition.y, mRotation, mScale, mVertexColors[0], mVertexColors[1], mVertexColors[2], mVertexColors[3], Blend, Effect, mOrigin ); + if ( S->getDrawableType() == DRAWABLE_SUBTEXTURE ) { + SubTexture * ST = static_cast( S ); + + if ( NULL == mVertexColors ) + ST->draw( mPosition.x, mPosition.y, mColor, mRotation, mScale, Blend, Effect, mOrigin ); + else + ST->draw( mPosition.x, mPosition.y, mRotation, mScale, mVertexColors[0], mVertexColors[1], mVertexColors[2], mVertexColors[3], Blend, Effect, mOrigin ); + + } } void Sprite::draw() { @@ -591,7 +596,7 @@ void Sprite::draw( const Vector2f& position, const Sizef& size ) { if ( SPR_FGET( SPRITE_FLAG_AUTO_ANIM ) ) update(); - SubTexture * S = getCurrentSubTexture(); + DrawableResource * S = getCurrentSubTexture(); if ( S == NULL ) return; @@ -602,10 +607,14 @@ void Sprite::draw( const Vector2f& position, const Sizef& size ) { S->setDestSize( size ); } - if ( NULL == mVertexColors ) - S->draw( position.x, position.y, getColor(), mRotation, mScale, mBlend, mEffect, mOrigin ); - else - S->draw( position.x, position.y, mRotation, mScale, getColor(), getColor(), getColor(), getColor(), mBlend, mEffect, mOrigin ); + if ( S->getDrawableType() == DRAWABLE_SUBTEXTURE ) { + SubTexture * ST = static_cast( S ); + + if ( NULL == mVertexColors ) + ST->draw( position.x, position.y, getColor(), mRotation, mScale, mBlend, mEffect, mOrigin ); + else + ST->draw( position.x, position.y, mRotation, mScale, getColor(), getColor(), getColor(), getColor(), mBlend, mEffect, mOrigin ); + } if ( size != Sizef::Zero ) { S->setDestSize( oldSize ); @@ -635,7 +644,7 @@ unsigned int Sprite::getSubFrame( const unsigned int& SubFrame ) { } Vector2i Sprite::getOffset() { - SubTexture* S = getCurrentSubTexture(); + DrawableResource* S = getCurrentSubTexture(); if ( S != NULL ) return S->getOffset(); @@ -644,7 +653,7 @@ Vector2i Sprite::getOffset() { } void Sprite::setOffset( const Vector2i& offset ) { - SubTexture* S = getCurrentSubTexture(); + DrawableResource* S = getCurrentSubTexture(); if ( S != NULL ) { S->setOffset( offset ); @@ -686,21 +695,21 @@ bool Sprite::getAutoAnimate() const { return 0 != SPR_FGET( SPRITE_FLAG_AUTO_ANIM ); } -SubTexture* Sprite::getCurrentSubTexture() { +DrawableResource* Sprite::getCurrentSubTexture() { if ( mFrames.size() ) return mFrames[ mCurrentFrame ].Spr[ mCurrentSubFrame ]; return NULL; } -SubTexture * Sprite::getSubTexture( const unsigned int& frame ) { +DrawableResource * Sprite::getSubTexture( const unsigned int& frame ) { if ( frame < mFrames.size() ) return mFrames[ frame ].Spr[ mCurrentSubFrame ]; return NULL; } -SubTexture * Sprite::getSubTexture( const unsigned int& frame, const unsigned int& SubFrame ) { +DrawableResource * Sprite::getSubTexture( const unsigned int& frame, const unsigned int& SubFrame ) { if ( frame < mFrames.size() ) return mFrames[ frame ].Spr[ SubFrame ]; diff --git a/src/eepp/graphics/subtexture.cpp b/src/eepp/graphics/subtexture.cpp index ca75e82e7..e37063596 100644 --- a/src/eepp/graphics/subtexture.cpp +++ b/src/eepp/graphics/subtexture.cpp @@ -10,10 +10,9 @@ using namespace EE::Graphics::Private; namespace EE { namespace Graphics { SubTexture::SubTexture() : - Drawable( DRAWABLE_SUBTEXTURE ), + DrawableResource( DRAWABLE_SUBTEXTURE ), mPixels(NULL), mAlphaMask(NULL), - mId(0), mTexId(0), mTexture(NULL), mSrcRect( Rect(0,0,0,0) ), @@ -22,15 +21,12 @@ SubTexture::SubTexture() : mOffset(0,0), mPixelDensity(1) { - createUnnamed(); } SubTexture::SubTexture( const Uint32& TexId, const std::string& name ) : - Drawable( DRAWABLE_SUBTEXTURE ), + DrawableResource( DRAWABLE_SUBTEXTURE, name ), mPixels(NULL), mAlphaMask(NULL), - mName( name ), - mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect( Rect( 0, 0, NULL != mTexture ? mTexture->getImageWidth() : 0, NULL != mTexture ? mTexture->getImageHeight() : 0 ) ), @@ -39,15 +35,12 @@ SubTexture::SubTexture( const Uint32& TexId, const std::string& name ) : mOffset(0,0), mPixelDensity(1) { - createUnnamed(); } SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const std::string& name ) : - Drawable( DRAWABLE_SUBTEXTURE ), + DrawableResource( DRAWABLE_SUBTEXTURE, name ), mPixels(NULL), mAlphaMask(NULL), - mName( name ), - mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect( SrcRect ), @@ -56,15 +49,12 @@ SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const std::str mOffset(0,0), mPixelDensity(1) { - createUnnamed(); } SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& name ) : - Drawable( DRAWABLE_SUBTEXTURE ), + DrawableResource( DRAWABLE_SUBTEXTURE, name ), mPixels(NULL), mAlphaMask(NULL), - mName( name ), - mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect(SrcRect), @@ -73,15 +63,12 @@ SubTexture::SubTexture( const Uint32& TexId, const Rect& SrcRect, const Sizef& D mOffset(0,0), mPixelDensity(1) { - createUnnamed(); } SubTexture::SubTexture(const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i &Offset, const std::string& name ) : - Drawable( DRAWABLE_SUBTEXTURE ), + DrawableResource( DRAWABLE_SUBTEXTURE, name ), mPixels(NULL), mAlphaMask(NULL), - mName( name ), - mId( String::hash( mName ) ), mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect(SrcRect), @@ -90,31 +77,12 @@ SubTexture::SubTexture(const Uint32& TexId, const Rect& SrcRect, const Sizef& De mOffset(Offset), mPixelDensity(1) { - createUnnamed(); } SubTexture::~SubTexture() { clearCache(); } -void SubTexture::createUnnamed() { - if ( !mName.size() ) - setName( std::string( "unnamed" ) ); -} - -const Uint32& SubTexture::getId() const { - return mId; -} - -const std::string SubTexture::getName() const { - return mName; -} - -void SubTexture::setName( const std::string& name ) { - mName = name; - mId = String::hash( mName ); -} - const Uint32& SubTexture::getTextureId() { return mTexId; } diff --git a/src/eepp/graphics/textureatlas.cpp b/src/eepp/graphics/textureatlas.cpp index 39bc3ad84..33d6d2e8f 100644 --- a/src/eepp/graphics/textureatlas.cpp +++ b/src/eepp/graphics/textureatlas.cpp @@ -3,7 +3,7 @@ namespace EE { namespace Graphics { TextureAtlas::TextureAtlas( const std::string& name ) : - ResourceManager ( true ) + ResourceManager ( true ) { setName( name ); } @@ -32,28 +32,28 @@ const Uint32& TextureAtlas::getId() const { return mId; } -SubTexture * TextureAtlas::add( SubTexture * subTexture ) { - return ResourceManager::add( subTexture ); +DrawableResource * TextureAtlas::add( DrawableResource * drawableResource ) { + return ResourceManager::add( drawableResource ); } -SubTexture * TextureAtlas::add( const Uint32& TexId, const std::string& Name ) { +DrawableResource * TextureAtlas::add( const Uint32& TexId, const std::string& Name ) { return add( eeNew( SubTexture, ( TexId, Name ) ) ); } -SubTexture * TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, const std::string& Name ) { +DrawableResource * TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, const std::string& Name ) { return add( eeNew( SubTexture, ( TexId, SrcRect, Name ) ) ); } -SubTexture * TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name ) { +DrawableResource * TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name ) { return add( eeNew ( SubTexture, ( TexId, SrcRect, DestSize, Name ) ) ); } -SubTexture * TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name ) { +DrawableResource * TextureAtlas::add( const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name ) { return add( eeNew ( SubTexture, ( TexId, SrcRect, DestSize, Offset, Name ) ) ); } Uint32 TextureAtlas::getCount() { - return ResourceManager::getCount(); + return ResourceManager::getCount(); } void TextureAtlas::setTextures( std::vector textures ) { diff --git a/src/eepp/graphics/textureatlasloader.cpp b/src/eepp/graphics/textureatlasloader.cpp index 2eaeba3ca..d237065d3 100644 --- a/src/eepp/graphics/textureatlasloader.cpp +++ b/src/eepp/graphics/textureatlasloader.cpp @@ -295,9 +295,10 @@ bool TextureAtlasLoader::updateTextureAtlas() { for ( Int32 i = 0; i < tTexHdr->SubTextureCount; i++ ) { sSubTextureHdr * tSh = &tTexAtlas->SubTextures[i]; - SubTexture * tSubTexture = mTextureAtlas->getById( tSh->ResourceID ); + DrawableResource * tDrawableResource = mTextureAtlas->getById( tSh->ResourceID ); - if ( NULL != tSubTexture ) { + if ( NULL != tDrawableResource && tDrawableResource->getDrawableType() == DRAWABLE_SUBTEXTURE ) { + SubTexture * tSubTexture = static_cast( tDrawableResource ); tSh->OffsetX = tSubTexture->getOffset().x; tSh->OffsetY = tSubTexture->getOffset().x; tSh->DestWidth = (Int32)tSubTexture->getDestSize().x; diff --git a/src/eepp/graphics/textureatlasmanager.cpp b/src/eepp/graphics/textureatlasmanager.cpp index 3b2231c48..a48d3013b 100644 --- a/src/eepp/graphics/textureatlasmanager.cpp +++ b/src/eepp/graphics/textureatlasmanager.cpp @@ -39,8 +39,8 @@ TextureAtlas * TextureAtlasManager::loadFromPack( Pack * Pack, const std::string return loader.getTextureAtlas(); } -SubTexture * TextureAtlasManager::getSubTextureByName( const std::string& Name ) { - SubTexture * tSubTexture = getSubTextureById( String::hash( Name ) ); +DrawableResource * TextureAtlasManager::getSubTextureByName( const std::string& Name ) { + DrawableResource * tSubTexture = getSubTextureById( String::hash( Name ) ); if ( mWarnings ) { eePRINTC( NULL == tSubTexture, "TextureAtlasManager::GetSubTextureByName SubTexture '%s' not found\n", Name.c_str() ); @@ -49,11 +49,11 @@ SubTexture * TextureAtlasManager::getSubTextureByName( const std::string& Name ) return tSubTexture; } -SubTexture * TextureAtlasManager::getSubTextureById( const Uint32& Id ) { +DrawableResource * TextureAtlasManager::getSubTextureById( const Uint32& Id ) { std::list::iterator it; TextureAtlas * tSG = NULL; - SubTexture * tSubTexture = NULL; + DrawableResource * tSubTexture = NULL; for ( it = mResources.begin(); it != mResources.end(); it++ ) { tSG = (*it); @@ -74,8 +74,8 @@ void TextureAtlasManager::printResources() { (*it)->printNames(); } -std::vector TextureAtlasManager::getSubTexturesByPatternId( const Uint32& SubTextureId, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) { - SubTexture * tSubTexture = NULL; +std::vector TextureAtlasManager::getSubTexturesByPatternId( const Uint32& SubTextureId, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) { + DrawableResource * tSubTexture = NULL; std::string tName; if ( NULL == SearchInTextureAtlas ) @@ -92,7 +92,7 @@ std::vector TextureAtlasManager::getSubTexturesByPatternId( const U return getSubTexturesByPattern( String::removeNumbersAtEnd( tSubTexture->getName() ), "", SearchInTextureAtlas ); } - return std::vector(); + return std::vector(); } void TextureAtlasManager::setPrintWarnings( const bool& warn ) { @@ -103,11 +103,11 @@ const bool& TextureAtlasManager::getPrintWarnings() const { return mWarnings; } -std::vector TextureAtlasManager::getSubTexturesByPattern( const std::string& name, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) { - std::vector SubTextures; +std::vector TextureAtlasManager::getSubTexturesByPattern( const std::string& name, const std::string& extension, TextureAtlas * SearchInTextureAtlas ) { + std::vector SubTextures; std::string search; bool found = true; - SubTexture * tSubTexture = NULL; + DrawableResource * tSubTexture = NULL; std::string realext = ""; int c = 0; int t = 0; diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 1c44d15e1..fd7b5dfeb 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include namespace EE { namespace UI { @@ -58,13 +59,13 @@ UITheme * UITheme::loadFromTextureAtlas( UITheme * tTheme, Graphics::TextureAtla tTheme->setTextureAtlas( TextureAtlas ); - std::list& resources = TextureAtlas->getResources(); - std::list::iterator it; + std::list& resources = TextureAtlas->getResources(); + std::list::iterator it; std::string sAbbr( tTheme->getAbbr() + "_" ); std::map elemFound; for ( it = resources.begin(); it != resources.end(); it++ ) { - SubTexture* subTexture = *it; + DrawableResource* subTexture = *it; std::string name( subTexture->getName() ); @@ -124,20 +125,40 @@ UITheme * UITheme::loadFromFile( UITheme * tTheme, const std::string& Path ) { if ( String::startsWith( name, sAbbrIcon ) ) { tSG->add( eeNew( SubTexture, ( TextureFactory::instance()->loadFromFile( fpath ), name ) ) ); } else if ( String::startsWith( name, sAbbr ) ) { - std::vector nameParts = String::split( name, '_' ); + std::vector dotParts = String::split( name, '.' ); - if ( nameParts.size() >= 3 ) { - int lPart = nameParts.size() - 1; - int llPart = nameParts.size() - 2; + if ( dotParts.size() >= 3 && dotParts[ dotParts.size() - 1 ] == "9" ) { + std::vector nameParts = String::split( dotParts[0], '_' ); - if ( UISkin::isStateName( nameParts[ lPart ] ) ) { - elemFound[ elemNameFromSkinSimple( nameParts ) ] = false; + std::string srcRect = String::split( dotParts[ dotParts.size() - 2 ], '_' ); + int l = 0, t = 0, r = 0, b = 0; - tSG->add( eeNew( SubTexture, ( TextureFactory::instance()->loadFromFile( fpath ), name ) ) ); - } else if ( UISkin::isStateName( nameParts[ llPart ] ) && UISkinComplex::isSideSuffix( nameParts[ lPart ] ) ) { - elemFound[ elemNameFromSkinComplex( nameParts ) ] = true; + if ( srcRect.size() == 4 ) { + String::fromString( &l, srcRect[0] ); + String::fromString( &t, srcRect[1] ); + String::fromString( &r, srcRect[2] ); + String::fromString( &b, srcRect[3] ); + } - tSG->add( eeNew( SubTexture, ( TextureFactory::instance()->loadFromFile( fpath ), name ) ) ); + elemFound[ elemNameFromSkinSimple( nameParts ) ] = false; + + tSG->add( eeNew( NinePatch, ( TextureFactory::instance()->loadFromFile( fpath ), l, t, r, b, name ) ) ); + } else { + std::vector nameParts = String::split( name, '_' ); + + if ( nameParts.size() >= 3 ) { + int lPart = nameParts.size() - 1; + int llPart = nameParts.size() - 2; + + if ( UISkin::isStateName( nameParts[ lPart ] ) ) { + elemFound[ elemNameFromSkinSimple( nameParts ) ] = false; + + tSG->add( eeNew( SubTexture, ( TextureFactory::instance()->loadFromFile( fpath ), name ) ) ); + } else if ( UISkin::isStateName( nameParts[ llPart ] ) && UISkinComplex::isSideSuffix( nameParts[ lPart ] ) ) { + elemFound[ elemNameFromSkinComplex( nameParts ) ] = true; + + tSG->add( eeNew( SubTexture, ( TextureFactory::instance()->loadFromFile( fpath ), name ) ) ); + } } } } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index e16dece01..1358e94de 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -277,10 +277,10 @@ static std::vector getTestStringArr() { void EETest::createUI() { Clock TE; - mThemeName = "uitheme"; + mThemeName = "uitheme_new"; if ( PixelDensity::getPixelDensity() >= 1.1 ) { - mThemeName += "2x"; + mThemeName = "uitheme2x_new"; } createUIThemeTextureAtlas(); @@ -293,11 +293,10 @@ void EETest::createUI() { UIManager::instance()->init(UI_MAN_OPS); UIManager::instance()->setTranslator( mTranslator ); - //mTheme = UITheme::loadFromFile( UIThemeDefault::New( mThemeName, mThemeName ), MyPath + "ui/" + mThemeName + "/" ); + mTheme = UITheme::loadFromFile( UIThemeDefault::New( mThemeName, mThemeName ), MyPath + "ui/" + mThemeName + "/" ); - TextureAtlasLoader tgl( MyPath + "ui/" + mThemeName + EE_TEXTURE_ATLAS_EXTENSION ); - - mTheme = UITheme::loadFromTextureAtlas( UIThemeDefault::New( mThemeName, mThemeName ), TextureAtlasManager::instance()->getByName( mThemeName ) ); + //TextureAtlasLoader tgl( MyPath + "ui/" + mThemeName + EE_TEXTURE_ATLAS_EXTENSION ); + //mTheme = UITheme::loadFromTextureAtlas( UIThemeDefault::New( mThemeName, mThemeName ), TextureAtlasManager::instance()->getByName( mThemeName ) ); UIThemeManager::instance()->add( mTheme ); UIThemeManager::instance()->setDefaultEffectsEnabled( true );