From d50861625e4c51e02ccb2ee86530a31cdfa2d1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 18 Jun 2020 19:56:54 -0300 Subject: [PATCH] Added Graphics::GlyphDrawable. Some minor refactor in Graphics::Texture. --- TODO.md | 7 +-- include/eepp/graphics.hpp | 1 + include/eepp/graphics/batchrenderer.hpp | 3 + include/eepp/graphics/drawable.hpp | 1 + include/eepp/graphics/font.hpp | 7 +++ include/eepp/graphics/fontbmfont.hpp | 14 ++++- include/eepp/graphics/fontsprite.hpp | 15 ++++- include/eepp/graphics/fonttruetype.hpp | 16 +++-- include/eepp/graphics/glyphdrawable.hpp | 45 ++++++++++++++ include/eepp/graphics/texture.hpp | 30 +++++++--- include/eepp/graphics/textureatlasloader.hpp | 2 +- include/eepp/graphics/texturepacker.hpp | 8 +-- include/eepp/graphics/textureregion.hpp | 7 +-- include/eepp/math/rect.hpp | 12 ++++ projects/linux/ee.files | 2 + src/eepp/graphics/batchrenderer.cpp | 11 +++- src/eepp/graphics/fontbmfont.cpp | 50 ++++++++++++---- src/eepp/graphics/fontsprite.cpp | 45 ++++++++++---- src/eepp/graphics/fonttruetype.cpp | 25 ++++++++ src/eepp/graphics/glyphdrawable.cpp | 63 ++++++++++++++++++++ src/eepp/graphics/text.cpp | 6 +- src/eepp/graphics/texture.cpp | 50 ++++++++++------ src/eepp/graphics/textureatlasloader.cpp | 6 +- src/eepp/graphics/texturepacker.cpp | 10 ++-- src/eepp/graphics/textureregion.cpp | 14 ++--- src/eepp/ui/doc/syntaxdefinitionmanager.cpp | 3 +- src/eepp/ui/tools/textureatlaseditor.cpp | 6 +- src/eepp/ui/tools/textureatlasnew.cpp | 6 +- src/eepp/ui/uitheme.cpp | 2 +- src/tools/texturepacker/texturepacker.cpp | 8 +-- 30 files changed, 367 insertions(+), 108 deletions(-) create mode 100644 include/eepp/graphics/glyphdrawable.hpp create mode 100644 src/eepp/graphics/glyphdrawable.cpp diff --git a/TODO.md b/TODO.md index 6157e2333..7ac6a0724 100644 --- a/TODO.md +++ b/TODO.md @@ -29,11 +29,6 @@ Implement icon themes separated from the `UITheme` and customizable from a CSS f * On Save: Allow to select line endings type. -## GlyphDrawable - -Implement a `GlyphDrawable`. This should render any glyph as a drawable type. -It should be very useful to use font icons in buttons and menues. - ## UITreeView Implement a simple tree view widget, to at least cover the most common use cases. @@ -48,6 +43,8 @@ Keep improving it: * Support single instance (when a new file is opened while a previous instance exists, open it in the first instance). +* Allow to open a document in any number of tabs. + ## UI Editor * Integrate the `UICodeEditor` into the editor in order to be able to edit the layouts and CSS in app. diff --git a/include/eepp/graphics.hpp b/include/eepp/graphics.hpp index 9ee8ff2c5..44bbac4ec 100644 --- a/include/eepp/graphics.hpp +++ b/include/eepp/graphics.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/include/eepp/graphics/batchrenderer.hpp b/include/eepp/graphics/batchrenderer.hpp index 33acd5698..1a2138446 100644 --- a/include/eepp/graphics/batchrenderer.hpp +++ b/include/eepp/graphics/batchrenderer.hpp @@ -118,6 +118,9 @@ class EE_API BatchRenderer { void quadsSetTexCoord( const Float& tl_u, const Float& tl_v, const Float& br_u, const Float& br_v ); + /** Set the texture sector to be rendered */ + void quadsSetTexCoord( const Rectf& region ); + /** Set the texture sector to be rendered but freely seted */ void quadsSetTexCoordFree( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2, const Float& x3, const Float& y3 ); diff --git a/include/eepp/graphics/drawable.hpp b/include/eepp/graphics/drawable.hpp index ede7346e6..69cae7984 100644 --- a/include/eepp/graphics/drawable.hpp +++ b/include/eepp/graphics/drawable.hpp @@ -26,6 +26,7 @@ class EE_API Drawable { NINEPATCH, STATELIST, SKIN, + GLYPH, UINODEDRAWABLE, UINODEDRAWABLE_LAYERDRAWABLE, UIBORDERDRAWABLE, diff --git a/include/eepp/graphics/font.hpp b/include/eepp/graphics/font.hpp index 4c6df1d8c..912c4cd42 100644 --- a/include/eepp/graphics/font.hpp +++ b/include/eepp/graphics/font.hpp @@ -2,7 +2,9 @@ #define EE_GRAPHICSCFONT_H #include +#include #include +#include namespace EE { namespace Graphics { @@ -72,6 +74,11 @@ class EE_API Font { virtual const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const = 0; + /** @return The glyph drawable that represents the glyph in a texture. The glyph drawable + * allocation is managed by the font. */ + virtual GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold, Float outlineThickness = 0 ) const = 0; + virtual Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const = 0; virtual Float getLineSpacing( unsigned int characterSize ) const = 0; diff --git a/include/eepp/graphics/fontbmfont.hpp b/include/eepp/graphics/fontbmfont.hpp index 17dc0b560..a2b6b056b 100644 --- a/include/eepp/graphics/fontbmfont.hpp +++ b/include/eepp/graphics/fontbmfont.hpp @@ -15,9 +15,9 @@ namespace EE { namespace Graphics { /** @brief Implementation of AngelCode BMFont fonts. */ class EE_API FontBMFont : public Font { public: - static FontBMFont* New( const std::string FontName ); + static FontBMFont* New( const std::string fontName ); - static FontBMFont* New( const std::string FontName, const std::string& filename ); + static FontBMFont* New( const std::string fontName, const std::string& filename ); ~FontBMFont(); @@ -35,6 +35,9 @@ class EE_API FontBMFont : public Font { const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const; + GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, bool bold, + Float outlineThickness = 0 ) const; + Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const; Float getLineSpacing( unsigned int characterSize ) const; @@ -55,10 +58,15 @@ class EE_API FontBMFont : public Font { FontBMFont( const std::string FontName ); typedef std::map GlyphTable; ///< Table mapping a codepoint to its glyph + typedef std::map GlyphDrawableTable; struct Page { + ~Page(); + GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph - Texture* texture; ///< Texture containing the pixels of the glyphs + GlyphDrawableTable + drawables; ///> Table mapping code points to their corresponding glyph drawables. + Texture* texture; ///< Texture containing the pixels of the glyphs }; void cleanup(); diff --git a/include/eepp/graphics/fontsprite.hpp b/include/eepp/graphics/fontsprite.hpp index 2632c396a..3cea08627 100644 --- a/include/eepp/graphics/fontsprite.hpp +++ b/include/eepp/graphics/fontsprite.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace EE { namespace System { @@ -15,9 +16,9 @@ namespace EE { namespace Graphics { /** @brief Implementation of XNA Font Sprites */ class EE_API FontSprite : public Font { public: - static FontSprite* New( const std::string FontName ); + static FontSprite* New( const std::string fontName ); - static FontSprite* New( const std::string FontName, const std::string& filename ); + static FontSprite* New( const std::string fontName, const std::string& filename ); ~FontSprite(); @@ -38,6 +39,9 @@ class EE_API FontSprite : public Font { const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const; + GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, bool bold, + Float outlineThickness = 0 ) const; + Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const; Float getLineSpacing( unsigned int characterSize ) const; @@ -58,10 +62,15 @@ class EE_API FontSprite : public Font { FontSprite( const std::string FontName ); typedef std::map GlyphTable; ///< Table mapping a codepoint to its glyph + typedef std::map GlyphDrawableTable; struct Page { + ~Page(); + GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph - Texture* texture; ///< Texture containing the pixels of the glyphs + GlyphDrawableTable + drawables; ///> Table mapping code points to their corresponding glyph drawables. + Texture* texture; ///< Texture containing the pixels of the glyphs }; void cleanup(); diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 5c05ce34d..19036134f 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -33,6 +33,9 @@ class EE_API FontTrueType : public Font { const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const; + GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, bool bold, + Float outlineThickness = 0 ) const; + Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const; Float getLineSpacing( unsigned int characterSize ) const; @@ -62,15 +65,18 @@ class EE_API FontTrueType : public Font { }; typedef std::map GlyphTable; ///< Table mapping a codepoint to its glyph + typedef std::map GlyphDrawableTable; struct Page { Page(); ~Page(); - GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph - Texture* texture; ///< Texture containing the pixels of the glyphs - unsigned int nextRow; ///< Y position of the next new row in the texture + GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph + GlyphDrawableTable + drawables; ///> Table mapping code points to their corresponding glyph drawables. + Texture* texture; ///< Texture containing the pixels of the glyphs + unsigned int nextRow; ///< Y position of the next new row in the texture std::vector rows; ///< List containing the position of all the existing rows }; @@ -88,8 +94,8 @@ class EE_API FontTrueType : public Font { void* mLibrary; ///< Pointer to the internal library interface (it is typeless to avoid exposing ///< implementation details) - void* mFace; ///< Pointer to the internal font face (it is typeless to avoid exposing - ///< implementation details) + void* mFace; ///< Pointer to the internal font face (it is typeless to avoid exposing + ///< implementation details) void* mStreamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing ///< implementation details) void* mStroker; ///< Pointer to the stroker (it is typeless to avoid exposing implementation diff --git a/include/eepp/graphics/glyphdrawable.hpp b/include/eepp/graphics/glyphdrawable.hpp new file mode 100644 index 000000000..5c4dff0e5 --- /dev/null +++ b/include/eepp/graphics/glyphdrawable.hpp @@ -0,0 +1,45 @@ +#ifndef EE_GRAPHICS_GLYPHDRAWABLE_HPP +#define EE_GRAPHICS_GLYPHDRAWABLE_HPP + +#include +#include +#include + +namespace EE { namespace Graphics { + +class EE_API GlyphDrawable : public DrawableResource { + public: + static GlyphDrawable* New( Texture* texture, const Rect& srcRect, + const std::string& resourceName = "" ); + + GlyphDrawable( Texture* texture, const Rect& srcRect, const std::string& resourceName = "" ); + + virtual void draw(); + + virtual void draw( const Vector2f& position ); + + virtual void draw( const Vector2f& position, const Sizef& size ); + + virtual bool isStateful(); + + /** @return The texture instance used by the GlyphDrawable. */ + Texture* getTexture(); + + /** @return The Texture sector that represents the GlyphDrawable */ + const Rect& getSrcRect() const; + + /** @return This is the same as Destination Size but with the values rounded as integers. */ + Sizef getSize(); + + const Float& getPixelDensity() const; + void setPixelDensity(const Float& pixelDensity); + + protected: + Texture* mTexture; + Rectf mSrcRect; + Float mPixelDensity; +}; + +}} // namespace EE::Graphics + +#endif // EE_GRAPHICS_GLYPHDRAWABLE_HPP diff --git a/include/eepp/graphics/texture.hpp b/include/eepp/graphics/texture.hpp index eb3853d8b..8dbe34bdc 100644 --- a/include/eepp/graphics/texture.hpp +++ b/include/eepp/graphics/texture.hpp @@ -13,15 +13,15 @@ namespace EE { namespace Graphics { class EE_API Texture : public DrawableResource, public Image, private NonCopyable { public: /** @enum TextureFilter Defines the texture filter used. */ - enum TextureFilter { + enum class Filter : Uint32 { Linear, //!< Linear filtering (Smoothed Zoom) Nearest //!< No filtering (Pixeled Zoom) }; /** @enum ClampMode Set the clamp mode of the texture. */ - enum ClampMode { ClampToEdge, ClampRepeat }; + enum class ClampMode : Uint32 { ClampToEdge, ClampRepeat }; - enum CoordinateType { + enum class CoordinateType : Uint32 { Normalized, ///< Texture coordinates in range [0 .. 1] Pixels ///< Texture coordinates in range [0 .. size] }; @@ -84,10 +84,10 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl const Uint8* getPixelsPtr(); /** Set the Texture Filter Mode */ - void setFilter( const TextureFilter& filter ); + void setFilter( const Filter& filter ); /** @return The texture filter used by the texture */ - const TextureFilter& getFilter() const; + const Filter& getFilter() const; /** Save the Texture to a new File */ bool saveToFile( const std::string& filepath, const Image::SaveType& Format ); @@ -299,11 +299,22 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl * @param coordinateType Type of texture coordinates to use * @param textureUnit The Texture unit that want to be used to bind ( usually 0 ) */ - void bind( CoordinateType coordinateType = Texture::CoordinateType::Normalized, - const Uint32& textureUnit = 0 ); + void bind( CoordinateType coordinateType, const Uint32& textureUnit = 0 ); + + /** Bind the texture. Activate the texture for rendering. + * @param textureUnit The Texture unit that want to be used to bind ( usually 0 ) + */ + void bind( const Uint32& textureUnit = 0 ); virtual ~Texture(); + /** return The reference coordinate type. */ + const CoordinateType& getCoordinateType() const; + + /** Sets the default coordinate type. This value is not forced when binded, but used as a + reference for binding in the case of textures with a reference coordinate type. */ + void setCoordinateType( const CoordinateType& coordinateType ); + protected: enum TEXTURE_FLAGS { TEX_FLAG_MIPMAP = ( 1 << 0 ), @@ -341,7 +352,8 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl Uint32 mFlags; ClampMode mClampMode; - TextureFilter mFilter; + Filter mFilter; + CoordinateType mCoordinateType; int mInternalFormat; @@ -349,7 +361,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl Uint8* iLock( const bool& ForceRGBA, const bool& KeepFormat ); - void iTextureFilter( const TextureFilter& filter ); + void iTextureFilter( const Filter& filter ); }; }} // namespace EE::Graphics diff --git a/include/eepp/graphics/textureatlasloader.hpp b/include/eepp/graphics/textureatlasloader.hpp index bc8a4ca62..7beb11cb1 100644 --- a/include/eepp/graphics/textureatlasloader.hpp +++ b/include/eepp/graphics/textureatlasloader.hpp @@ -159,7 +159,7 @@ class EE_API TextureAtlasLoader { sTextureAtlasHdr getTextureAtlasHeader(); - void setTextureFilter( const Texture::TextureFilter& textureFilter ); + void setTextureFilter( const Texture::Filter& textureFilter ); protected: ResourceLoader mRL; diff --git a/include/eepp/graphics/texturepacker.hpp b/include/eepp/graphics/texturepacker.hpp index 522fbc559..0be4b2c19 100644 --- a/include/eepp/graphics/texturepacker.hpp +++ b/include/eepp/graphics/texturepacker.hpp @@ -75,7 +75,7 @@ class EE_API TexturePacker { const Float& pixelDensity = 1, const bool& forcePowOfTwo = true, const bool& scalableSVG = false, const Uint32& pixelBorder = 2, - const Texture::TextureFilter& textureFilter = Texture::TextureFilter::Linear, + const Texture::Filter& textureFilter = Texture::Filter::Linear, const bool& allowChilds = false, const bool& allowFlipping = false ); /** Creates a new texture packer ( you will need to call SetOptions before adding any texture or @@ -106,7 +106,7 @@ class EE_API TexturePacker { const Float& pixelDensity = 1, const bool& forcePowOfTwo = true, const bool& scalableSVG = false, const Uint32& pixelBorder = 2, - const Texture::TextureFilter& textureFilter = Texture::TextureFilter::Linear, + const Texture::Filter& textureFilter = Texture::Filter::Linear, const bool& allowChilds = false, const bool& allowFlipping = false ); ~TexturePacker(); @@ -172,7 +172,7 @@ class EE_API TexturePacker { const Float& pixelDensity = 1, const bool& forcePowOfTwo = true, const bool& scalableSVG = false, const Uint32& pixelBorder = 2, - const Texture::TextureFilter& textureFilter = Texture::TextureFilter::Linear, + const Texture::Filter& textureFilter = Texture::Filter::Linear, const bool& allowChilds = false, const bool& allowFlipping = false ); /** @return The texture atlas to generate width. */ @@ -207,7 +207,7 @@ class EE_API TexturePacker { bool mForcePowOfTwo; Int32 mPixelBorder; Uint32 mPixelDensity; /* The multiplier value * 100 ( example: PD = 2, here is 200 ) */ - Texture::TextureFilter mTextureFilter; + Texture::Filter mTextureFilter; bool mKeepExtensions; bool mScalableSVG; Image::SaveType mFormat; diff --git a/include/eepp/graphics/textureregion.hpp b/include/eepp/graphics/textureregion.hpp index 1c980a1d1..22c12418d 100644 --- a/include/eepp/graphics/textureregion.hpp +++ b/include/eepp/graphics/textureregion.hpp @@ -62,12 +62,12 @@ class EE_API TextureRegion : public DrawableResource { virtual ~TextureRegion(); - /** @return The Texture Id that holds the TextureRegion. */ - const Uint32& getTextureId(); - /** Set the Texture Id that holds the TextureRegion. */ void setTextureId( const Uint32& TexId ); + /** Set the Texture that holds the TextureRegion. */ + void setTexture( Texture* texture ); + /** @return The Texture sector that represents the TextureRegion */ const Rect& getSrcRect() const; @@ -192,7 +192,6 @@ class EE_API TextureRegion : public DrawableResource { protected: Uint8* mPixels; Uint8* mAlphaMask; - Uint32 mTexId; Graphics::Texture* mTexture; Rect mSrcRect; Sizef mOriDestSize; diff --git a/include/eepp/math/rect.hpp b/include/eepp/math/rect.hpp index e051f8bdf..30d745034 100644 --- a/include/eepp/math/rect.hpp +++ b/include/eepp/math/rect.hpp @@ -68,8 +68,20 @@ template class tRECT { void scale( Vector2 scale, const Vector2& center ); void scale( Vector2 scale ); + + tRECT asFloat() const; + + tRECT asInt() const; }; +template tRECT tRECT::asFloat() const { + return tRECT( Left, Top, Right, Bottom ); +} + +template tRECT tRECT::asInt() const { + return tRECT( Left, Top, Right, Bottom ); +} + template bool operator==( const tRECT& R1, const tRECT& R2 ) { return ( R1.Left == R2.Left ) && ( R1.Right == R2.Right ) && ( R1.Top == R2.Top ) && ( R1.Bottom == R2.Bottom ); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index d1883ad9b..3f833599c 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -63,6 +63,7 @@ ../../include/eepp/graphics/globalbatchrenderer.hpp ../../include/eepp/graphics/globaltextureatlas.hpp ../../include/eepp/graphics.hpp +../../include/eepp/graphics/glyphdrawable.hpp ../../include/eepp/graphics/image.hpp ../../include/eepp/graphics/ninepatch.hpp ../../include/eepp/graphics/ninepatchmanager.hpp @@ -507,6 +508,7 @@ ../../src/eepp/graphics/framebuffermanager.hpp ../../src/eepp/graphics/globalbatchrenderer.cpp ../../src/eepp/graphics/globaltextureatlas.cpp +../../src/eepp/graphics/glyphdrawable.cpp ../../src/eepp/graphics/image.cpp ../../src/eepp/graphics/ninepatch.cpp ../../src/eepp/graphics/ninepatchmanager.cpp diff --git a/src/eepp/graphics/batchrenderer.cpp b/src/eepp/graphics/batchrenderer.cpp index 059dd8252..91cb47e07 100644 --- a/src/eepp/graphics/batchrenderer.cpp +++ b/src/eepp/graphics/batchrenderer.cpp @@ -475,16 +475,20 @@ void BatchRenderer::quadsSetColorFree( const Color& Color0, const Color& Color1, void BatchRenderer::quadsSetTexCoord( const Float& tl_u, const Float& tl_v, const Float& br_u, const Float& br_v ) { mTexCoord[0].x = tl_u; - mTexCoord[1].x = tl_u; mTexCoord[0].y = tl_v; + mTexCoord[1].x = tl_u; mTexCoord[1].y = br_v; mTexCoord[2].x = br_u; - mTexCoord[3].x = br_u; mTexCoord[2].y = br_v; + mTexCoord[3].x = br_u; mTexCoord[3].y = tl_v; } +void BatchRenderer::quadsSetTexCoord( const Rectf& region ) { + quadsSetTexCoord( region.Left, region.Top, region.Right, region.Bottom ); +} + void BatchRenderer::quadsSetTexCoordFree( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2, const Float& x3, const Float& y3 ) { @@ -546,7 +550,8 @@ void BatchRenderer::batchPointList( const std::vector& points, addVertexs( points.size() ); - memcpy( (void*)&mVertex[curNumVertex], (void*)&points[0], sizeof( VertexData ) * points.size() ); + memcpy( (void*)&mVertex[curNumVertex], (void*)&points[0], + sizeof( VertexData ) * points.size() ); } void BatchRenderer::linesBegin() { diff --git a/src/eepp/graphics/fontbmfont.cpp b/src/eepp/graphics/fontbmfont.cpp index aab12060c..649c346a8 100644 --- a/src/eepp/graphics/fontbmfont.cpp +++ b/src/eepp/graphics/fontbmfont.cpp @@ -9,12 +9,12 @@ namespace EE { namespace Graphics { -FontBMFont* FontBMFont::New( const std::string FontName ) { - return eeNew( FontBMFont, ( FontName ) ); +FontBMFont* FontBMFont::New( const std::string fontName ) { + return eeNew( FontBMFont, ( fontName ) ); } -FontBMFont* FontBMFont::New( const std::string FontName, const std::string& filename ) { - FontBMFont* fontBMFont = New( FontName ); +FontBMFont* FontBMFont::New( const std::string fontName, const std::string& filename ) { + FontBMFont* fontBMFont = New( fontName ); fontBMFont->loadFromFile( filename ); return fontBMFont; } @@ -127,8 +127,10 @@ bool FontBMFont::loadFromStream( IOStream& stream ) { mPages[mFontSize].texture = TF->getTexture( texId ); } - if ( NULL != mPages[mFontSize].texture ) - mPages[mFontSize].texture->setFilter( Texture::TextureFilter::Nearest ); + if ( NULL != mPages[mFontSize].texture ) { + mPages[mFontSize].texture->setFilter( Texture::Filter::Nearest ); + mPages[mFontSize].texture->setCoordinateType( Texture::CoordinateType::Pixels ); + } } GlyphTable& glyphs = mPages[mFontSize].glyphs; @@ -184,8 +186,24 @@ const Glyph& FontBMFont::getGlyph( Uint32 codePoint, unsigned int characterSize, } } -Glyph FontBMFont::loadGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness ) const { +GlyphDrawable* FontBMFont::getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold, Float outlineThickness ) const { + GlyphDrawableTable& drawables = mPages[characterSize].drawables; + auto it = drawables.find( codePoint ); + if ( it != drawables.end() ) { + return it->second; + } else { + const Glyph& glyph = getGlyph( codePoint, characterSize, bold, outlineThickness ); + auto& page = mPages[characterSize]; + GlyphDrawable* region = GlyphDrawable::New( + page.texture, glyph.textureRect, + String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); + drawables[codePoint] = region; + return region; + } +} + +Glyph FontBMFont::loadGlyph( Uint32 codePoint, unsigned int characterSize, bool, Float ) const { Glyph glyph; GlyphTable& glyphs = mPages[mFontSize].glyphs; @@ -204,7 +222,7 @@ Glyph FontBMFont::loadGlyph( Uint32 codePoint, unsigned int characterSize, bool return glyph; } -Float FontBMFont::getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const { +Float FontBMFont::getKerning( Uint32, Uint32, unsigned int ) const { return 0; } @@ -216,15 +234,15 @@ Uint32 FontBMFont::getFontHeight( const Uint32& characterSize ) { return ( Uint32 )( (Float)characterSize / mFontSize ) * mFontSize; } -Float FontBMFont::getUnderlinePosition( unsigned int characterSize ) const { +Float FontBMFont::getUnderlinePosition( unsigned int ) const { return 0.f; } -Float FontBMFont::getUnderlineThickness( unsigned int characterSize ) const { +Float FontBMFont::getUnderlineThickness( unsigned int ) const { return 0.f; } -Texture* FontBMFont::getTexture( unsigned int characterSize ) const { +Texture* FontBMFont::getTexture( unsigned int ) const { return mPages[mFontSize].texture; } @@ -241,4 +259,12 @@ FontBMFont& FontBMFont::operator=( const FontBMFont& right ) { return *this; } +FontBMFont::Page::~Page() { + for ( auto drawable : drawables ) + eeDelete( drawable.second ); + + if ( NULL != texture && TextureFactory::existsSingleton() ) + TextureFactory::instance()->remove( texture->getTextureId() ); +} + }} // namespace EE::Graphics diff --git a/src/eepp/graphics/fontsprite.cpp b/src/eepp/graphics/fontsprite.cpp index c9746a490..58b41f4ee 100644 --- a/src/eepp/graphics/fontsprite.cpp +++ b/src/eepp/graphics/fontsprite.cpp @@ -9,12 +9,12 @@ namespace EE { namespace Graphics { -FontSprite* FontSprite::New( const std::string FontName ) { - return eeNew( FontSprite, ( FontName ) ); +FontSprite* FontSprite::New( const std::string fontName ) { + return eeNew( FontSprite, ( fontName ) ); } -FontSprite* FontSprite::New( const std::string FontName, const std::string& filename ) { - FontSprite* fontSprite = New( FontName ); +FontSprite* FontSprite::New( const std::string fontName, const std::string& filename ) { + FontSprite* fontSprite = New( fontName ); fontSprite->loadFromFile( filename ); return fontSprite; } @@ -141,12 +141,12 @@ bool FontSprite::loadFromStream( IOStream& stream, Color key, Uint32 firstChar, Uint32 texId = TextureFactory::instance()->loadFromPixels( img.getPixelsPtr(), img.getWidth(), img.getHeight(), img.getChannels() ); - - mPages[mFontSize].texture = TextureFactory::instance()->getTexture( texId ); - - if ( NULL != mPages[mFontSize].texture ) - mPages[mFontSize].texture->setFilter( Texture::TextureFilter::Nearest ); - + Texture* texture = TextureFactory::instance()->getTexture( texId ); + mPages[mFontSize].texture = texture; + if ( NULL != texture ) { + texture->setFilter( Texture::Filter::Nearest ); + texture->setCoordinateType( Texture::CoordinateType::Pixels ); + } sendEvent( Event::Load ); return true; @@ -177,6 +177,23 @@ const Glyph& FontSprite::getGlyph( Uint32 codePoint, unsigned int characterSize, } } +GlyphDrawable* FontSprite::getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold, Float outlineThickness ) const { + GlyphDrawableTable& drawables = mPages[characterSize].drawables; + auto it = drawables.find( codePoint ); + if ( it != drawables.end() ) { + return it->second; + } else { + const Glyph& glyph = getGlyph( codePoint, characterSize, bold, outlineThickness ); + auto& page = mPages[characterSize]; + GlyphDrawable* region = GlyphDrawable::New( + page.texture, glyph.textureRect, + String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); + drawables[codePoint] = region; + return region; + } +} + Glyph FontSprite::loadGlyph( Uint32 codePoint, unsigned int characterSize ) const { Glyph glyph; @@ -233,4 +250,12 @@ FontSprite& FontSprite::operator=( const FontSprite& right ) { return *this; } +FontSprite::Page::~Page() { + for ( auto drawable : drawables ) + eeDelete( drawable.second ); + + if ( NULL != texture && TextureFactory::existsSingleton() ) + TextureFactory::instance()->remove( texture->getTextureId() ); +} + }} // namespace EE::Graphics diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 88a28f575..cb13953c5 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -303,6 +303,27 @@ const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSiz } } +GlyphDrawable* FontTrueType::getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold, Float outlineThickness ) const { + GlyphDrawableTable& drawables = mPages[characterSize].drawables; + + Uint64 key = combine( outlineThickness, bold, + FT_Get_Char_Index( static_cast( mFace ), codePoint ) ); + + auto it = drawables.find( key ); + if ( it != drawables.end() ) { + return it->second; + } else { + const Glyph& glyph = getGlyph( codePoint, characterSize, bold, outlineThickness ); + auto& page = mPages[characterSize]; + GlyphDrawable* region = GlyphDrawable::New( + page.texture, glyph.textureRect, + String::format( "%s_%d_%u", mFontName.c_str(), characterSize, codePoint ) ); + drawables[key] = region; + return region; + } +} + Float FontTrueType::getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const { // Special case where first or second is 0 (null character) if ( first == 0 || second == 0 ) @@ -738,9 +759,13 @@ FontTrueType::Page::Page() : texture( NULL ), nextRow( 3 ) { image.getPixelsPtr(), image.getWidth(), image.getHeight(), image.getChannels(), false, Texture::ClampMode::ClampToEdge, false, true ); texture = TextureFactory::instance()->getTexture( texId ); + texture->setCoordinateType( Texture::CoordinateType::Pixels ); } FontTrueType::Page::~Page() { + for ( auto drawable : drawables ) + eeDelete( drawable.second ); + if ( NULL != texture && TextureFactory::existsSingleton() ) TextureFactory::instance()->remove( texture->getTextureId() ); } diff --git a/src/eepp/graphics/glyphdrawable.cpp b/src/eepp/graphics/glyphdrawable.cpp new file mode 100644 index 000000000..b322b3ac3 --- /dev/null +++ b/src/eepp/graphics/glyphdrawable.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +namespace EE { namespace Graphics { + +GlyphDrawable* GlyphDrawable::New( Texture* texture, const Rect& srcRect, + const std::string& resourceName ) { + return eeNew( GlyphDrawable, ( texture, srcRect, resourceName ) ); +} + +GlyphDrawable::GlyphDrawable( Texture* texture, const Rect& srcRect, + const std::string& resourceName ) : + DrawableResource( Drawable::GLYPH, resourceName ), + mTexture( texture ), + mSrcRect( srcRect.asFloat() ) { + mPixelDensity = PixelDensity::getPixelDensity(); +} + +void GlyphDrawable::draw() { + draw( mPosition ); +} + +void GlyphDrawable::draw( const Vector2f& position ) { + draw( position, Sizef( mSrcRect.Right, mSrcRect.Bottom ) ); +} + +void GlyphDrawable::draw( const Vector2f& position, const Sizef& size ) { + if ( position != mPosition ) + mPosition = position; + + BatchRenderer* BR = GlobalBatchRenderer::instance(); + BR->setTexture( mTexture, mTexture->getCoordinateType() ); + BR->setBlendMode( BlendAlpha ); + BR->quadsBegin(); + BR->quadsSetColor( mColor ); + BR->quadsSetTexCoord( mSrcRect.Left, mSrcRect.Top, mSrcRect.Left + mSrcRect.Right, + mSrcRect.Top + mSrcRect.Bottom ); + BR->batchQuad( position.x, position.y, size.getWidth(), size.getHeight() ); + BR->drawOpt(); +} + +bool GlyphDrawable::isStateful() { + return false; +} + +Texture* GlyphDrawable::getTexture() { + return mTexture; +} + +Sizef GlyphDrawable::getSize() { + return Sizef( mSrcRect.Right / mPixelDensity, mSrcRect.Bottom / mPixelDensity ); +} + +const Float& GlyphDrawable::getPixelDensity() const { + return mPixelDensity; +} + +void GlyphDrawable::setPixelDensity( const Float& pixelDensity ) { + mPixelDensity = pixelDensity; +} + +}} // namespace EE::Graphics diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 46584835b..75b4e19fc 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -552,8 +552,10 @@ void Text::draw( const Float& X, const Float& Y, const Vector2f& Scale, const Fl return; GlobalBatchRenderer::instance()->draw(); - TextureFactory::instance()->bind( mFont->getTexture( mRealFontSize ), - Texture::CoordinateType::Pixels ); + Texture* texture = mFont->getTexture( mRealFontSize ); + if ( !texture ) + return; + texture->bind(); BlendMode::setMode( Effect ); if ( mStyle & Shadow ) { diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index 940ed1d5c..168332db9 100644 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -37,8 +37,9 @@ Texture::Texture() : mImgWidth( 0 ), mImgHeight( 0 ), mFlags( 0 ), - mClampMode( ClampToEdge ), - mFilter( Linear ) { + mClampMode( ClampMode::ClampToEdge ), + mFilter( Filter::Linear ), + mCoordinateType( CoordinateType::Normalized ) { if ( NULL == sBR ) { sBR = GlobalBatchRenderer::instance(); } @@ -116,7 +117,7 @@ void Texture::create( const Uint32& texture, const unsigned int& width, const un mImgHeight = imgheight; mSize = MemSize; mClampMode = ClampMode; - mFilter = Linear; + mFilter = Filter::Linear; if ( UseMipmap ) mFlags |= TEX_FLAG_MIPMAP; @@ -129,6 +130,14 @@ void Texture::create( const Uint32& texture, const unsigned int& width, const un onResourceChange(); } +const Texture::CoordinateType& Texture::getCoordinateType() const { + return mCoordinateType; +} + +void Texture::setCoordinateType( const CoordinateType& coordinateType ) { + mCoordinateType = coordinateType; +} + Uint8* Texture::iLock( const bool& ForceRGBA, const bool& KeepFormat ) { bool threaded = Engine::instance()->isSharedGLContextEnabled() && Thread::getCurrentThreadId() != Engine::instance()->getMainThreadId(); @@ -233,7 +242,8 @@ bool Texture::unlock( const bool& KeepData, const bool& Modified ) { ScopedTexture saver( mTexture ); Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0; - flags = ( mClampMode == ClampRepeat ) ? ( flags | SOIL_FLAG_TEXTURE_REPEATS ) : flags; + flags = ( mClampMode == ClampMode::ClampRepeat ) ? ( flags | SOIL_FLAG_TEXTURE_REPEATS ) + : flags; NTexId = SOIL_create_OGL_texture( reinterpret_cast( &mPixels[0] ), &width, &height, mChannels, mTexture, flags ); @@ -285,6 +295,10 @@ void Texture::bind( CoordinateType coordinateType, const Uint32& textureUnit ) { TextureFactory::instance()->bind( this, coordinateType, textureUnit ); } +void Texture::bind( const Uint32& textureUnit ) { + TextureFactory::instance()->bind( this, mCoordinateType, textureUnit ); +} + bool Texture::saveToFile( const std::string& filepath, const SaveType& Format ) { bool Res = false; @@ -299,13 +313,13 @@ bool Texture::saveToFile( const std::string& filepath, const SaveType& Format ) return Res; } -void Texture::setFilter( const TextureFilter& filter ) { +void Texture::setFilter( const Filter& filter ) { if ( mFilter != filter ) { iTextureFilter( filter ); } } -void Texture::iTextureFilter( const TextureFilter& filter ) { +void Texture::iTextureFilter( const Filter& filter ) { if ( mTexture ) { mFilter = filter; @@ -318,21 +332,21 @@ void Texture::iTextureFilter( const TextureFilter& filter ) { ScopedTexture saver( mTexture ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, - ( mFilter == Linear ) ? GL_LINEAR : GL_NEAREST ); + ( mFilter == Filter::Linear ) ? GL_LINEAR : GL_NEAREST ); if ( mFlags & TEX_FLAG_MIPMAP ) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - ( mFilter == Linear ) ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST ); + ( mFilter == Filter::Linear ) ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST ); else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - ( mFilter == Linear ) ? GL_LINEAR : GL_NEAREST ); + ( mFilter == Filter::Linear ) ? GL_LINEAR : GL_NEAREST ); if ( threaded ) Engine::instance()->getCurrentWindow()->unsetGLContextThread(); } } -const Texture::TextureFilter& Texture::getFilter() const { +const Texture::Filter& Texture::getFilter() const { return mFilter; } @@ -422,7 +436,7 @@ void Texture::applyClampMode() { if ( mTexture ) { ScopedTexture saver( mTexture ); - if ( mClampMode == ClampRepeat ) { + if ( mClampMode == ClampMode::ClampRepeat ) { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); } else { @@ -456,7 +470,8 @@ void Texture::reload() { ScopedTexture saver( mTexture ); Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0; - flags = ( mClampMode == ClampRepeat ) ? ( flags | SOIL_FLAG_TEXTURE_REPEATS ) : flags; + flags = ( mClampMode == ClampMode::ClampRepeat ) ? ( flags | SOIL_FLAG_TEXTURE_REPEATS ) + : flags; if ( ( mFlags & TEX_FLAG_COMPRESSED ) ) { if ( isGrabed() ) @@ -569,7 +584,8 @@ void Texture::replace( Image* image ) { { Uint32 flags = ( mFlags & TEX_FLAG_MIPMAP ) ? SOIL_FLAG_MIPMAPS : 0; - flags = ( mClampMode == ClampRepeat ) ? ( flags | SOIL_FLAG_TEXTURE_REPEATS ) : flags; + flags = ( mClampMode == ClampMode::ClampRepeat ) ? ( flags | SOIL_FLAG_TEXTURE_REPEATS ) + : flags; ScopedTexture scopedTexture; @@ -653,7 +669,7 @@ void Texture::drawFast( const Float& x, const Float& y, const Float& Angle, cons sBR->quadsBegin(); sBR->quadsSetColor( Color ); - if ( getClampMode() == ClampRepeat ) { + if ( getClampMode() == ClampMode::ClampRepeat ) { Float iw = (Float)getImageWidth(); Float ih = (Float)getImageHeight(); sBR->quadsSetTexCoordFree( 0, 0, 0, height / ih, width / iw, height / ih, width / iw, 0 ); @@ -695,7 +711,7 @@ void Texture::drawEx( Float x, Float y, Float width, Float height, const Float& sBR->quadsSetColorFree( Color0, Color1, Color2, Color3 ); if ( Effect <= RENDER_FLIPPED_MIRRORED ) { - if ( getClampMode() == ClampRepeat ) { + if ( getClampMode() == ClampMode::ClampRepeat ) { if ( Effect == RENDER_NORMAL ) { if ( renderSector ) { sBR->quadsSetTexCoordFree( @@ -892,7 +908,7 @@ void Texture::drawQuadEx( Quad2f Q, const Vector2f& Offset, const Float& Angle, Q.scale( Scale, QCenter ); } - if ( getClampMode() == ClampRepeat ) { + if ( getClampMode() == ClampMode::ClampRepeat ) { sBR->quadsSetTexCoordFree( 0, 0, 0, ( Q.V[0].y - Q.V[0].y ) / h, ( Q.V[0].x - Q.V[0].x ) / w, ( Q.V[0].y - Q.V[0].y ) / h, ( Q.V[0].x - Q.V[0].x ) / w, 0 ); @@ -910,7 +926,7 @@ void Texture::drawQuadEx( Quad2f Q, const Vector2f& Offset, const Float& Angle, } Sizef Texture::getSize() { - return Sizef( PixelDensity::dpToPx( mImgWidth ), PixelDensity::dpToPx( mImgHeight ) ); + return Sizef( PixelDensity::pxToDp( mImgWidth ), PixelDensity::pxToDp( mImgHeight ) ); } Sizei Texture::getPixelSize() { diff --git a/src/eepp/graphics/textureatlasloader.cpp b/src/eepp/graphics/textureatlasloader.cpp index b117bc522..8a7fc9905 100644 --- a/src/eepp/graphics/textureatlasloader.cpp +++ b/src/eepp/graphics/textureatlasloader.cpp @@ -111,7 +111,7 @@ sTextureAtlasHdr TextureAtlasLoader::getTextureAtlasHeader() { return mTexGrHdr; } -void TextureAtlasLoader::setTextureFilter( const Texture::TextureFilter& textureFilter ) { +void TextureAtlasLoader::setTextureFilter( const Texture::Filter& textureFilter ) { mTexGrHdr.TextureFilter = (char)textureFilter; size_t count = getTextureAtlas()->getTexturesCount() == 0; @@ -294,7 +294,7 @@ void TextureAtlasLoader::createTextureRegions() { if ( NULL != mTextureAtlas && mTexturesLoaded.size() ) { for ( size_t i = 0; i < mTexturesLoaded.size(); i++ ) - mTexturesLoaded[i]->setFilter( (Texture::TextureFilter)mTexGrHdr.TextureFilter ); + mTexturesLoaded[i]->setFilter( (Texture::Filter)mTexGrHdr.TextureFilter ); mTextureAtlas->setTextures( mTexturesLoaded ); } @@ -482,7 +482,7 @@ bool TextureAtlasLoader::updateTextureAtlas( std::string TextureAtlasPath, std:: maxImageSize.getHeight() == 0 ? mTexGrHdr.Height : maxImageSize.getHeight(), pixelDensity, 0 != ( mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_POW_OF_TWO ), 0 != ( mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_SCALABLE_SVG ), mTexGrHdr.PixelBorder, - (Texture::TextureFilter)mTexGrHdr.TextureFilter, + (Texture::Filter)mTexGrHdr.TextureFilter, mTexGrHdr.Flags & HDR_TEXTURE_ATLAS_ALLOW_FLIPPING ); tp.addTexturesPath( ImagesPath ); diff --git a/src/eepp/graphics/texturepacker.cpp b/src/eepp/graphics/texturepacker.cpp index 63c7aaae0..b8452111e 100644 --- a/src/eepp/graphics/texturepacker.cpp +++ b/src/eepp/graphics/texturepacker.cpp @@ -16,7 +16,7 @@ TexturePacker* TexturePacker::New() { TexturePacker* TexturePacker::New( const Uint32& maxWidth, const Uint32& maxHeight, const Float& pixelDensity, const bool& forcePowOfTwo, const bool& scalableSVG, const Uint32& pixelBorder, - const Texture::TextureFilter& textureFilter, + const Texture::Filter& textureFilter, const bool& allowChilds, const bool& allowFlipping ) { return eeNew( TexturePacker, ( maxWidth, maxHeight, pixelDensity, forcePowOfTwo, scalableSVG, pixelBorder, textureFilter, allowChilds, allowFlipping ) ); @@ -25,7 +25,7 @@ TexturePacker* TexturePacker::New( const Uint32& maxWidth, const Uint32& maxHeig TexturePacker::TexturePacker( const Uint32& maxWidth, const Uint32& maxHeight, const Float& pixelDensity, const bool& forcePowOfTwo, const bool& scalableSVG, const Uint32& pixelBorder, - const Texture::TextureFilter& textureFilter, const bool& allowChilds, + const Texture::Filter& textureFilter, const bool& allowChilds, const bool& allowFlipping ) : mTotalArea( 0 ), mFreeList( NULL ), @@ -66,7 +66,7 @@ TexturePacker::TexturePacker() : mForcePowOfTwo( true ), mPixelBorder( 0 ), mPixelDensity( 1 ), - mTextureFilter( Texture::TextureFilter::Linear ), + mTextureFilter( Texture::Filter::Linear ), mKeepExtensions( false ), mScalableSVG( false ), mFormat( Image::SaveType::SAVE_TYPE_PNG ) {} @@ -136,7 +136,7 @@ Uint32 TexturePacker::getAtlasNumChannels() { void TexturePacker::setOptions( const Uint32& maxWidth, const Uint32& maxHeight, const Float& pixelDensity, const bool& forcePowOfTwo, const bool& scalableSVG, const Uint32& pixelBorder, - const Texture::TextureFilter& textureFilter, + const Texture::Filter& textureFilter, const bool& allowChilds, const bool& allowFlipping ) { if ( !mTextures.size() ) { // only can change the dimensions before adding any texture mMaxSize.x = maxWidth; @@ -689,7 +689,7 @@ void TexturePacker::saveTextureRegions() { TexGrHdr.Height = mHeight; TexGrHdr.PixelBorder = mPixelBorder; TexGrHdr.Flags = 0; - TexGrHdr.TextureFilter = mTextureFilter; + TexGrHdr.TextureFilter = (Uint32)mTextureFilter; int reservedSize = eeARRAY_SIZE( TexGrHdr.Reserved ); memset( TexGrHdr.Reserved, 0, reservedSize ); diff --git a/src/eepp/graphics/textureregion.cpp b/src/eepp/graphics/textureregion.cpp index 2ceaf19c8..6af2d5165 100644 --- a/src/eepp/graphics/textureregion.cpp +++ b/src/eepp/graphics/textureregion.cpp @@ -37,7 +37,6 @@ TextureRegion::TextureRegion() : DrawableResource( Drawable::TEXTUREREGION ), mPixels( NULL ), mAlphaMask( NULL ), - mTexId( 0 ), mTexture( NULL ), mSrcRect( Rect( 0, 0, 0, 0 ) ), mOriDestSize( 0, 0 ), @@ -49,7 +48,6 @@ TextureRegion::TextureRegion( const Uint32& TexId, const std::string& name ) : DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect( Rect( 0, 0, NULL != mTexture ? mTexture->getImageWidth() : 0, NULL != mTexture ? mTexture->getImageHeight() : 0 ) ), @@ -63,7 +61,6 @@ TextureRegion::TextureRegion( const Uint32& TexId, const Rect& SrcRect, const st DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect( SrcRect ), mOriDestSize( PixelDensity::dpToPx( Sizef( ( Float )( mSrcRect.Right - mSrcRect.Left ), @@ -77,7 +74,6 @@ TextureRegion::TextureRegion( const Uint32& TexId, const Rect& SrcRect, const Si DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect( SrcRect ), mOriDestSize( DestSize ), @@ -90,7 +86,6 @@ TextureRegion::TextureRegion( const Uint32& TexId, const Rect& SrcRect, const Si DrawableResource( Drawable::TEXTUREREGION, name ), mPixels( NULL ), mAlphaMask( NULL ), - mTexId( TexId ), mTexture( TextureFactory::instance()->getTexture( TexId ) ), mSrcRect( SrcRect ), mOriDestSize( DestSize ), @@ -102,13 +97,12 @@ TextureRegion::~TextureRegion() { clearCache(); } -const Uint32& TextureRegion::getTextureId() { - return mTexId; +void TextureRegion::setTextureId( const Uint32& TexId ) { + mTexture = TextureFactory::instance()->getTexture( TexId ); } -void TextureRegion::setTextureId( const Uint32& TexId ) { - mTexId = TexId; - mTexture = TextureFactory::instance()->getTexture( TexId ); +void TextureRegion::setTexture( Texture* texture ) { + mTexture = texture; } const Rect& TextureRegion::getSrcRect() const { diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index 200e7ffad..79533e03b 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -250,6 +250,7 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { {{"//.-\n"}, "comment"}, {{"/%*", "%*/"}, "comment"}, {{"#", "[^\\]\n"}, "keyword2"}, + {{"R\"[%a-\"]+%(", "%)[%a-\"]+%\""}, "string"}, {{"\"", "\"", "\\"}, "string"}, {{"'", "'", "\\"}, "string"}, {{"-?0x%x+"}, "number"}, @@ -424,7 +425,7 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { {"NULL", "literal"}, {"parent", "literal"}, {"self", "literal"}, {"echo", "function"}}, "//", - {"^#!.*[ /]php"}} ); + {"^#!.*[ /]php", "^<%?php"}} ); // Add SQL std::vector keywords = { diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 19b866d86..7a64c6205 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -332,9 +332,9 @@ void TextureAtlasEditor::onTextureFilterChange( const Event* ) { !mTextureAtlasLoader->isLoaded() ) return; - Texture::TextureFilter textureFilter = mTextureFilterList->getText() == "Nearest" - ? Texture::TextureFilter::Nearest - : Texture::TextureFilter::Linear; + Texture::Filter textureFilter = mTextureFilterList->getText() == "Nearest" + ? Texture::Filter::Nearest + : Texture::Filter::Linear; mTextureAtlasLoader->setTextureFilter( textureFilter ); } diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index 9226889b2..ab51c9076 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -163,9 +163,9 @@ void TextureAtlasNew::textureAtlasSave( const Event* Event ) { bool Res1 = String::fromString( w, mComboWidth->getText() ); bool Res2 = String::fromString( h, mComboHeight->getText() ); b = static_cast( mPixelSpace->getValue() ); - Texture::TextureFilter textureFilter = mTextureFilter->getText() == "Nearest" - ? Texture::TextureFilter::Nearest - : Texture::TextureFilter::Linear; + Texture::Filter textureFilter = mTextureFilter->getText() == "Nearest" + ? Texture::Filter::Nearest + : Texture::Filter::Linear; if ( Res1 && Res2 ) { TexturePacker* texturePacker = TexturePacker::New( diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 7148d31c9..d07d77da9 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -59,7 +59,7 @@ UITheme* UITheme::loadFromTextureAtlas( UITheme* tTheme, Graphics::TextureAtlas* /** Themes use nearest filter by default, force the filter to the textures. */ for ( Uint32 tC = 0; tC < textureAtlas->getTexturesCount(); tC++ ) { - textureAtlas->getTexture( tC )->setFilter( Texture::TextureFilter::Nearest ); + textureAtlas->getTexture( tC )->setFilter( Texture::Filter::Nearest ); } Clock TE; diff --git a/src/tools/texturepacker/texturepacker.cpp b/src/tools/texturepacker/texturepacker.cpp index 76ba2d34a..8b2420d8c 100644 --- a/src/tools/texturepacker/texturepacker.cpp +++ b/src/tools/texturepacker/texturepacker.cpp @@ -65,13 +65,13 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { {'b', "pixels-border"}, 2, args::Options::Single ); args::Flag update( parser, "update", "Update texture atlas if output file already exists.", {'u', "update"}, args::Options::Single ); - std::unordered_map textureFilterMap{ - {"linear", Texture::TextureFilter::Linear}, {"nearest", Texture::TextureFilter::Nearest}}; - args::MapFlag textureFilter( + std::unordered_map textureFilterMap{ + {"linear", Texture::Filter::Linear}, {"nearest", Texture::Filter::Nearest}}; + args::MapFlag textureFilter( parser, "texture-filter", "Texture filter to use with the texture atlas. Available filters: \"linear\" or " "\"nearest\".", - {"texture-filter"}, textureFilterMap, Texture::TextureFilter::Linear, + {"texture-filter"}, textureFilterMap, Texture::Filter::Linear, args::Options::Single ); try {