From 4520a74b1be5503f3fd579cf6e20d9862c387c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 13 Sep 2023 00:48:26 -0300 Subject: [PATCH] setFontSize and all its relatives are now in pixels (instead of dp) TextureLoader can now report of loaded files. Some minor refactor in TextureFactory and UIWidget. Added UITextureViewer tool. A very simple tool to display current loaded textures, added this util to the UIWidgetInspector. --- include/eepp/graphics/drawableresource.hpp | 8 +- include/eepp/graphics/fonttruetype.hpp | 2 +- include/eepp/graphics/text.hpp | 3 - include/eepp/graphics/texturefactory.hpp | 12 +- include/eepp/graphics/textureloader.hpp | 18 ++- include/eepp/ui/uicodeeditor.hpp | 2 +- include/eepp/ui/uiconsole.hpp | 2 +- include/eepp/ui/uitextview.hpp | 2 - include/eepp/ui/uiwidget.hpp | 16 +-- projects/linux/ee.files | 2 + src/eepp/graphics/drawableresource.cpp | 7 +- src/eepp/graphics/fonttruetype.cpp | 12 +- src/eepp/graphics/text.cpp | 126 ++++++++++----------- src/eepp/graphics/texturefactory.cpp | 16 +-- src/eepp/graphics/textureloader.cpp | 41 +++++-- src/eepp/ui/tools/uitextureviewer.cpp | 74 ++++++++++++ src/eepp/ui/tools/uitextureviewer.hpp | 36 ++++++ src/eepp/ui/tools/uiwidgetinspector.cpp | 11 +- src/eepp/ui/uicodeeditor.cpp | 16 +-- src/eepp/ui/uiconsole.cpp | 14 +-- src/eepp/ui/uiimage.cpp | 5 +- src/eepp/ui/uinodedrawable.cpp | 21 ++-- src/eepp/ui/uitextinput.cpp | 4 +- src/eepp/ui/uitextview.cpp | 12 +- src/eepp/ui/uitheme.cpp | 5 +- src/eepp/ui/uithememanager.cpp | 2 +- src/eepp/ui/uitooltip.cpp | 4 +- src/eepp/ui/uiwidget.cpp | 21 ++-- src/eepp/ui/uiwidgetcreator.cpp | 2 + src/tests/test_all/test.cpp | 23 ++-- src/tools/ecode/applayout.xml.hpp | 9 ++ src/tools/ecode/ecode.cpp | 14 +-- src/tools/ecode/uitreeviewglobalsearch.cpp | 5 +- 33 files changed, 354 insertions(+), 193 deletions(-) create mode 100644 src/eepp/ui/tools/uitextureviewer.cpp create mode 100644 src/eepp/ui/tools/uitextureviewer.hpp diff --git a/include/eepp/graphics/drawableresource.hpp b/include/eepp/graphics/drawableresource.hpp index ed4c690fa..e68a48194 100644 --- a/include/eepp/graphics/drawableresource.hpp +++ b/include/eepp/graphics/drawableresource.hpp @@ -8,11 +8,11 @@ namespace EE { namespace Graphics { class EE_API DrawableResource : public Drawable { public: - enum Event { Load, Change, Unload }; + enum Event { Change, Unload }; virtual ~DrawableResource(); - typedef std::function OnResourceChangeCallback; + typedef std::function OnResourceChangeCallback; /** @return The DrawableResource Id. The Id is the String::hash of the name. */ const String::HashType& getId() const; @@ -32,13 +32,13 @@ class EE_API DrawableResource : public Drawable { Uint32 pushResourceChangeCallback( const OnResourceChangeCallback& cb ); /** Pop the on resource change callback id indicated. */ - void popResourceChangeCallback( const Uint32& callbackId ); + bool popResourceChangeCallback( const Uint32& callbackId ); protected: std::string mName; String::HashType mId; Uint32 mNumCallBacks; - std::map mCallbacks; + UnorderedMap mCallbacks; explicit DrawableResource( Type drawableType ); diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index ef5c1da23..3683f2081 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -144,7 +144,7 @@ class EE_API FontTrueType : public Font { typedef UnorderedMap GlyphDrawableTable; struct Page { - explicit Page( const Uint32 fontInternalId ); + explicit Page( const Uint32 fontInternalId, const std::string& pageName ); ~Page(); diff --git a/include/eepp/graphics/text.hpp b/include/eepp/graphics/text.hpp index 6a455d2ae..f652c8de3 100644 --- a/include/eepp/graphics/text.hpp +++ b/include/eepp/graphics/text.hpp @@ -80,8 +80,6 @@ class EE_API Text { unsigned int getCharacterSize() const; - unsigned int getCharacterSizePx() const; - const Uint32& getFontHeight() const; Uint32 getStyle() const; @@ -189,7 +187,6 @@ class EE_API Text { String mString; ///< String to display FontStyleConfig mFontStyleConfig; - Uint32 mRealFontSize; Color mBackgroundColor{ Color::Transparent }; mutable Rectf mBounds; ///< Bounding rectangle of the text (in local coordinates) diff --git a/include/eepp/graphics/texturefactory.hpp b/include/eepp/graphics/texturefactory.hpp index 671ea299e..6c867404c 100644 --- a/include/eepp/graphics/texturefactory.hpp +++ b/include/eepp/graphics/texturefactory.hpp @@ -230,12 +230,12 @@ class EE_API TextureFactory : protected Mutex { * @param MemSize The size of the texture in memory ( just if you need to specify the real size * in memory, just useful to calculate the total texture memory ). */ - Uint32 pushTexture( const std::string& Filepath, const Uint32& TexId, const unsigned int& Width, - const unsigned int& Height, const unsigned int& ImgWidth, - const unsigned int& ImgHeight, const bool& Mipmap, - const unsigned int& Channels, const Texture::ClampMode& ClampMode, - const bool& CompressTexture, const bool& LocalCopy = false, - const Uint32& MemSize = 0 ); + Texture* pushTexture( const std::string& Filepath, const Uint32& TexId, + const unsigned int& Width, const unsigned int& Height, + const unsigned int& ImgWidth, const unsigned int& ImgHeight, + const bool& Mipmap, const unsigned int& Channels, + const Texture::ClampMode& ClampMode, const bool& CompressTexture, + const bool& LocalCopy = false, const Uint32& MemSize = 0 ); /** Return a texture by it file path name * @param Name File path name diff --git a/include/eepp/graphics/textureloader.hpp b/include/eepp/graphics/textureloader.hpp index 121ea1117..6f99a5224 100644 --- a/include/eepp/graphics/textureloader.hpp +++ b/include/eepp/graphics/textureloader.hpp @@ -1,9 +1,10 @@ #ifndef EE_GRAPHICS_TEXTURELOADER #define EE_GRAPHICS_TEXTURELOADER +#include + #include #include - #include #include using namespace EE::System; @@ -13,6 +14,12 @@ namespace EE { namespace Graphics { /** @brief The Texture loader loads a texture in synchronous or asynchronous mode. */ class EE_API TextureLoader { public: + typedef std::function OnTextureLoaded; + + static Uint32 pushLoadedCallback( const OnTextureLoaded& cb ); + + static void popLoadedCallback( const Uint32& cbId ); + /** Load a Texture from stream * @param Stream The io stream instance * @param Mipmap Use mipmaps? @@ -98,7 +105,7 @@ class EE_API TextureLoader { const std::string& getFilepath() const; /** @return The texture internal id */ - const Uint32& getId() const; + Uint32 getId() const; /** @return The texture instance ( if it was loaded ). */ Texture* getTexture() const; @@ -113,7 +120,7 @@ class EE_API TextureLoader { protected: Uint32 mLoadType{ 0 }; // From memory, from path, from pack Uint8* mPixels{ nullptr }; // Texture Info - Uint32 mTexId{ 0 }; + Texture* mTexture{ nullptr }; Int32 mImgWidth{ 0 }; Int32 mImgHeight{ 0 }; @@ -137,6 +144,9 @@ class EE_API TextureLoader { void reset(); private: + static UnorderedMap sCbs; + static std::atomic sNumCbs; + bool mLoaded{ false }; bool mTexLoaded{ false }; bool mDirectUpload{ false }; @@ -151,6 +161,8 @@ class EE_API TextureLoader { void loadFromPack(); void loadFromPixels(); void loadFromStream(); + + void notifyLoaded(); }; }} // namespace EE::Graphics diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 3f7d1ddd9..e8cfed416 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -194,7 +194,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { UICodeEditor* setFont( Font* font ); - UICodeEditor* setFontSize( const Float& dpSize ); + UICodeEditor* setFontSize( const Float& size ); const Float& getFontSize() const; diff --git a/include/eepp/ui/uiconsole.hpp b/include/eepp/ui/uiconsole.hpp index b0214400d..e5f1a4b93 100644 --- a/include/eepp/ui/uiconsole.hpp +++ b/include/eepp/ui/uiconsole.hpp @@ -42,7 +42,7 @@ class EE_API UIConsole : public UIWidget, UIConsole* setFont( Font* font ); - UIConsole* setFontSize( const Float& dpSize ); + UIConsole* setFontSize( const Float& size ); const Float& getFontSize() const; diff --git a/include/eepp/ui/uitextview.hpp b/include/eepp/ui/uitextview.hpp index 1571948e5..e7d6b92a2 100644 --- a/include/eepp/ui/uitextview.hpp +++ b/include/eepp/ui/uitextview.hpp @@ -31,8 +31,6 @@ class EE_API UITextView : public UIWidget { Uint32 getFontSize() const; - Uint32 getPixelsFontSize() const; - UITextView* setFontSize( const Uint32& characterSize ); const Uint32& getFontStyle() const; diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index ceef58141..38bf63736 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -141,21 +141,21 @@ class EE_API UIWidget : public UINode { const std::vector& getStyleSheetPseudoClasses() const; - void resetClass(); + UIWidget* resetClass(); /** Resets all classes and assign a class */ - void setClass( const std::string& cls ); + UIWidget* setClass( const std::string& cls ); /** Resets all classes and assign vector of classes */ - void setClasses( const std::vector& classes ); + UIWidget* setClasses( const std::vector& classes ); - void addClass( const std::string& cls ); + UIWidget* addClass( const std::string& cls ); - void addClasses( const std::vector& classes ); + UIWidget* addClasses( const std::vector& classes ); - void removeClass( const std::string& cls ); + UIWidget* removeClass( const std::string& cls ); - void removeClasses( const std::vector& classes ); + UIWidget* removeClasses( const std::vector& classes ); bool hasClass( const std::string& cls ) const; @@ -252,6 +252,7 @@ class EE_API UIWidget : public UINode { String i18n( const std::string& str ); String i18n( const std::string& str, const String& defaultValue ); + protected: friend class UIManager; friend class UISceneNode; @@ -351,7 +352,6 @@ class EE_API UIWidget : public UINode { void disableCSSAnimations(); void reloadFontFamily(); - }; }} // namespace EE::UI diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 73d0021aa..e56f542bb 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -962,6 +962,8 @@ ../../src/eepp/ui/tools/uicodeeditorsplitter.cpp ../../src/eepp/ui/tools/uicolorpicker.cpp ../../src/eepp/ui/tools/uidocfindreplace.cpp +../../src/eepp/ui/tools/uitextureviewer.cpp +../../src/eepp/ui/tools/uitextureviewer.hpp ../../src/eepp/ui/tools/uiwidgetinspector.cpp ../../src/eepp/ui/uiabstractview.cpp ../../src/eepp/ui/uibackgrounddrawable.cpp diff --git a/src/eepp/graphics/drawableresource.cpp b/src/eepp/graphics/drawableresource.cpp index 295130d29..cff407930 100644 --- a/src/eepp/graphics/drawableresource.cpp +++ b/src/eepp/graphics/drawableresource.cpp @@ -44,7 +44,7 @@ void DrawableResource::onResourceChange() { void DrawableResource::sendEvent( const Event& event ) { for ( const auto& cb : mCallbacks ) { - cb.second( event, this ); + cb.second( cb.first, event, this ); } } @@ -54,9 +54,8 @@ Uint32 DrawableResource::pushResourceChangeCallback( const OnResourceChangeCallb return mNumCallBacks; } -void DrawableResource::popResourceChangeCallback( const Uint32& callbackId ) { - mCallbacks[callbackId] = 0; - mCallbacks.erase( mCallbacks.find( callbackId ) ); +bool DrawableResource::popResourceChangeCallback( const Uint32& callbackId ) { + return mCallbacks.erase( callbackId ) > 0; } }} // namespace EE::Graphics diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index cd0b5fa79..62df4f3b5 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -1157,7 +1157,14 @@ bool FontTrueType::setCurrentSize( unsigned int characterSize ) const { FontTrueType::Page& FontTrueType::getPage( unsigned int characterSize ) const { auto pageIt = mPages.find( characterSize ); if ( pageIt == mPages.end() ) { - mPages.insert( std::make_pair( characterSize, std::make_unique( mFontInternalId ) ) ); + std::string name = + String::format( "@font:TrueType:%s:%d", mInfo.family.c_str(), characterSize ); + if ( mIsBold ) + name += ":bold"; + if ( mIsItalic ) + name += ":italic"; + mPages.insert( + std::make_pair( characterSize, std::make_unique( mFontInternalId, name ) ) ); pageIt = mPages.find( characterSize ); } return *pageIt->second; @@ -1311,7 +1318,7 @@ void FontTrueType::setBoldItalicFont( FontTrueType* fontBoldItalic ) { updateMonospaceState(); } -FontTrueType::Page::Page( const Uint32 fontInternalId ) : +FontTrueType::Page::Page( const Uint32 fontInternalId, const std::string& pageName ) : texture( NULL ), nextRow( 3 ), fontInternalId( fontInternalId ) { // Make sure that the texture is initialized by default Image image; @@ -1327,6 +1334,7 @@ FontTrueType::Page::Page( const Uint32 fontInternalId ) : image.getPixelsPtr(), image.getWidth(), image.getHeight(), image.getChannels(), false, Texture::ClampMode::ClampToEdge, false, true ); texture->setCoordinateType( Texture::CoordinateType::Pixels ); + texture->setName( pageName ); } FontTrueType::Page::~Page() { diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 76ea6f283..1cecb6342 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -90,27 +90,22 @@ Text::Text( const String& string, Font* font, unsigned int characterSize ) : invalidate(); } -Text::Text( Font* font, unsigned int characterSize ) : - mRealFontSize( PixelDensity::dpToPxI( characterSize ) ) { +Text::Text( Font* font, unsigned int characterSize ) { mFontStyleConfig.Font = font; mFontStyleConfig.CharacterSize = characterSize; - mFontHeight = mFontStyleConfig.Font->getFontHeight( mRealFontSize ); - if ( !mFontStyleConfig.Font->isScalable() ) { + mFontHeight = mFontStyleConfig.Font->getFontHeight( mFontStyleConfig.CharacterSize ); + if ( !mFontStyleConfig.Font->isScalable() ) mFontStyleConfig.CharacterSize = mFontHeight; - mRealFontSize = mFontHeight; - } } void Text::create( Font* font, const String& text, Color FontColor, Color FontShadowColor, Uint32 characterSize ) { mFontStyleConfig.Font = font; mFontStyleConfig.CharacterSize = characterSize; - mRealFontSize = PixelDensity::dpToPxI( characterSize ); - mFontHeight = mFontStyleConfig.Font->getFontHeight( mRealFontSize ); - if ( !mFontStyleConfig.Font->isScalable() ) { + + mFontHeight = mFontStyleConfig.Font->getFontHeight( mFontStyleConfig.CharacterSize ); + if ( !mFontStyleConfig.Font->isScalable() ) mFontStyleConfig.CharacterSize = mFontHeight; - mRealFontSize = mFontHeight; - } mString = text; setFillColor( FontColor ); setShadowColor( FontShadowColor ); @@ -138,12 +133,9 @@ void Text::setFont( Font* font ) { if ( NULL != font && mFontStyleConfig.Font != font ) { mFontStyleConfig.Font = font; - mRealFontSize = PixelDensity::dpToPxI( mFontStyleConfig.CharacterSize ); - mFontHeight = mFontStyleConfig.Font->getFontHeight( mRealFontSize ); - if ( !mFontStyleConfig.Font->isScalable() ) { + mFontHeight = mFontStyleConfig.Font->getFontHeight( mFontStyleConfig.CharacterSize ); + if ( !mFontStyleConfig.Font->isScalable() ) mFontStyleConfig.CharacterSize = mFontHeight; - mRealFontSize = mFontHeight; - } mGeometryNeedUpdate = true; mCachedWidthNeedUpdate = true; } @@ -153,12 +145,9 @@ void Text::setFontSize( unsigned int size ) { if ( NULL != mFontStyleConfig.Font && mFontStyleConfig.CharacterSize != size ) { mFontStyleConfig.CharacterSize = size; - mRealFontSize = PixelDensity::dpToPxI( mFontStyleConfig.CharacterSize ); - mFontHeight = mFontStyleConfig.Font->getFontHeight( mRealFontSize ); - if ( !mFontStyleConfig.Font->isScalable() ) { + mFontHeight = mFontStyleConfig.Font->getFontHeight( mFontStyleConfig.CharacterSize ); + if ( !mFontStyleConfig.Font->isScalable() ) mFontStyleConfig.CharacterSize = mFontHeight; - mRealFontSize = mFontHeight; - } mGeometryNeedUpdate = true; mCachedWidthNeedUpdate = true; @@ -229,10 +218,6 @@ unsigned int Text::getCharacterSize() const { return mFontStyleConfig.CharacterSize; } -unsigned int Text::getCharacterSizePx() const { - return mRealFontSize; -} - const Uint32& Text::getFontHeight() const { return mFontHeight; } @@ -274,8 +259,8 @@ Vector2f Text::findCharacterPos( std::size_t index ) const { if ( index > mString.size() ) index = mString.size(); - return Text::findCharacterPos( index, mFontStyleConfig.Font, mRealFontSize, mString, - mFontStyleConfig.Style, mTabWidth, + return Text::findCharacterPos( index, mFontStyleConfig.Font, mFontStyleConfig.CharacterSize, + mString, mFontStyleConfig.Style, mTabWidth, mFontStyleConfig.OutlineThickness ); } @@ -283,9 +268,9 @@ Int32 Text::findCharacterFromPos( const Vector2i& pos, bool nearest ) const { if ( NULL == mFontStyleConfig.Font || mString.empty() ) return 0; - return Text::findCharacterFromPos( pos, nearest, mFontStyleConfig.Font, mRealFontSize, mString, - mFontStyleConfig.Style, mTabWidth, - mFontStyleConfig.OutlineThickness ); + return Text::findCharacterFromPos( + pos, nearest, mFontStyleConfig.Font, mFontStyleConfig.CharacterSize, mString, + mFontStyleConfig.Style, mTabWidth, mFontStyleConfig.OutlineThickness ); } static bool isStopSelChar( Uint32 c ) { @@ -493,19 +478,20 @@ void Text::updateWidthCache() { bool bold = ( mFontStyleConfig.Style & Bold ) != 0; bool italic = ( mFontStyleConfig.Style & Italic ) != 0; - Float hspace = static_cast( - mFontStyleConfig.Font - ->getGlyph( L' ', mRealFontSize, bold, italic, mFontStyleConfig.OutlineThickness ) - .advance ); + Float hspace = static_cast( mFontStyleConfig.Font + ->getGlyph( L' ', mFontStyleConfig.CharacterSize, bold, + italic, mFontStyleConfig.OutlineThickness ) + .advance ); size_t size = mString.size(); for ( std::size_t i = 0; i < size; ++i ) { rune = mString[i]; - const Glyph& glyph = mFontStyleConfig.Font->getGlyph( rune, mRealFontSize, bold, italic, - mFontStyleConfig.OutlineThickness ); + const Glyph& glyph = mFontStyleConfig.Font->getGlyph( + rune, mFontStyleConfig.CharacterSize, bold, italic, mFontStyleConfig.OutlineThickness ); if ( rune != '\r' && rune != '\t' ) { - width += mFontStyleConfig.Font->getKerning( prevChar, rune, mRealFontSize, bold, italic, - mFontStyleConfig.OutlineThickness ); + width += mFontStyleConfig.Font->getKerning( prevChar, rune, + mFontStyleConfig.CharacterSize, bold, + italic, mFontStyleConfig.OutlineThickness ); width += glyph.advance; } else if ( rune == '\t' ) { width += hspace * mTabWidth; @@ -540,14 +526,14 @@ void Text::wrapText( const Uint32& maxWidth ) { bool bold = ( mFontStyleConfig.Style & Bold ) != 0; bool italic = ( mFontStyleConfig.Style & Italic ) != 0; - Float hspace = static_cast( - mFontStyleConfig.Font - ->getGlyph( L' ', mRealFontSize, bold, italic, mFontStyleConfig.OutlineThickness ) - .advance ); + Float hspace = static_cast( mFontStyleConfig.Font + ->getGlyph( L' ', mFontStyleConfig.CharacterSize, bold, + italic, mFontStyleConfig.OutlineThickness ) + .advance ); while ( *tChar ) { - Glyph pChar = mFontStyleConfig.Font->getGlyph( *tChar, mRealFontSize, bold, italic, - mFontStyleConfig.OutlineThickness ); + Glyph pChar = mFontStyleConfig.Font->getGlyph( *tChar, mFontStyleConfig.CharacterSize, bold, + italic, mFontStyleConfig.OutlineThickness ); Float fCharWidth = (Float)pChar.advance; @@ -561,7 +547,8 @@ void Text::wrapText( const Uint32& maxWidth ) { if ( *tChar != '\r' ) { tWordWidth += mFontStyleConfig.Font->getKerning( - prevChar, *tChar, mRealFontSize, bold, italic, mFontStyleConfig.OutlineThickness ); + prevChar, *tChar, mFontStyleConfig.CharacterSize, bold, italic, + mFontStyleConfig.OutlineThickness ); prevChar = *tChar; } @@ -662,14 +649,16 @@ Float Text::getTextWidth() { Float Text::getTextHeight() { cacheWidth(); - return NULL != mFontStyleConfig.Font ? mFontStyleConfig.Font->getLineSpacing( mRealFontSize ) * - ( mLinesWidth.empty() ? 1 : mLinesWidth.size() ) - : 0; + return NULL != mFontStyleConfig.Font + ? mFontStyleConfig.Font->getLineSpacing( mFontStyleConfig.CharacterSize ) * + ( mLinesWidth.empty() ? 1 : mLinesWidth.size() ) + : 0; } Float Text::getLineSpacing() { - return NULL != mFontStyleConfig.Font ? mFontStyleConfig.Font->getLineSpacing( mRealFontSize ) - : 0; + return NULL != mFontStyleConfig.Font + ? mFontStyleConfig.Font->getLineSpacing( mFontStyleConfig.CharacterSize ) + : 0; } void Text::draw( const Float& X, const Float& Y, const Vector2f& scale, const Float& rotation, @@ -720,7 +709,7 @@ void Text::draw( const Float& X, const Float& Y, const Vector2f& scale, const Fl p.drawRectangle( getLocalBounds() ); } - Texture* texture = mFontStyleConfig.Font->getTexture( mRealFontSize ); + Texture* texture = mFontStyleConfig.Font->getTexture( mFontStyleConfig.CharacterSize ); if ( !texture ) return; texture->bind(); @@ -824,8 +813,10 @@ void Text::ensureGeometryUpdate() { bool underlined = ( mFontStyleConfig.Style & Underlined ) != 0; bool strikeThrough = ( mFontStyleConfig.Style & StrikeThrough ) != 0; Float italic = reqItalic && !mFontStyleConfig.Font->hasItalic() ? 0.208f : 0.f; // 12 degrees - Float underlineOffset = mFontStyleConfig.Font->getUnderlinePosition( mRealFontSize ); - Float underlineThickness = mFontStyleConfig.Font->getUnderlineThickness( mRealFontSize ); + Float underlineOffset = + mFontStyleConfig.Font->getUnderlinePosition( mFontStyleConfig.CharacterSize ); + Float underlineThickness = + mFontStyleConfig.Font->getUnderlineThickness( mFontStyleConfig.CharacterSize ); // Compute the location of the strike through dynamically // We use the center point of the lowercase 'x' glyph as the reference @@ -833,20 +824,23 @@ void Text::ensureGeometryUpdate() { Float strikeThroughOffset = 0; if ( strikeThrough ) { Rectf xBounds = - mFontStyleConfig.Font->getGlyph( L'x', mRealFontSize, bold, reqItalic ).bounds; + mFontStyleConfig.Font->getGlyph( L'x', mFontStyleConfig.CharacterSize, bold, reqItalic ) + .bounds; strikeThroughOffset = xBounds.Top + xBounds.Bottom / 2.f; } // Precompute the variables needed by the algorithm Float hspace = static_cast( - mFontStyleConfig.Font->getGlyph( L' ', mRealFontSize, bold, reqItalic ).advance ); - Float vspace = static_cast( mFontStyleConfig.Font->getLineSpacing( mRealFontSize ) ); + mFontStyleConfig.Font->getGlyph( L' ', mFontStyleConfig.CharacterSize, bold, reqItalic ) + .advance ); + Float vspace = static_cast( + mFontStyleConfig.Font->getLineSpacing( mFontStyleConfig.CharacterSize ) ); Float x = 0.f; - Float y = static_cast( mRealFontSize ); + Float y = static_cast( mFontStyleConfig.CharacterSize ); // Create one quad for each character - Float minX = static_cast( mRealFontSize ); - Float minY = static_cast( mRealFontSize ); + Float minX = static_cast( mFontStyleConfig.CharacterSize ); + Float minY = static_cast( mFontStyleConfig.CharacterSize ); Float maxX = 0.f; Float maxY = 0.f; Float maxW = 0.f; @@ -873,8 +867,9 @@ void Text::ensureGeometryUpdate() { Uint32 curChar = mString[i]; // Apply the kerning offset - x += mFontStyleConfig.Font->getKerning( prevChar, curChar, mRealFontSize, bold, reqItalic, - mFontStyleConfig.OutlineThickness ); + x += + mFontStyleConfig.Font->getKerning( prevChar, curChar, mFontStyleConfig.CharacterSize, + bold, reqItalic, mFontStyleConfig.OutlineThickness ); prevChar = curChar; // If we're using the underlined style and there's a new line, draw a line @@ -951,8 +946,9 @@ void Text::ensureGeometryUpdate() { // Apply the outline if ( mFontStyleConfig.OutlineThickness != 0 ) { - const Glyph& glyph = mFontStyleConfig.Font->getGlyph( - curChar, mRealFontSize, bold, italic, mFontStyleConfig.OutlineThickness ); + const Glyph& glyph = + mFontStyleConfig.Font->getGlyph( curChar, mFontStyleConfig.CharacterSize, bold, + italic, mFontStyleConfig.OutlineThickness ); Float left = glyph.bounds.Left; Float top = glyph.bounds.Top; @@ -974,8 +970,8 @@ void Text::ensureGeometryUpdate() { } // Extract the current glyph's description - const Glyph& glyph = - mFontStyleConfig.Font->getGlyph( curChar, mRealFontSize, bold, reqItalic ); + const Glyph& glyph = mFontStyleConfig.Font->getGlyph( + curChar, mFontStyleConfig.CharacterSize, bold, reqItalic ); // Add the glyph to the vertices addGlyphQuad( mVertices, Vector2f( x, y ), glyph, italic, 0, centerDiffX ); diff --git a/src/eepp/graphics/texturefactory.cpp b/src/eepp/graphics/texturefactory.cpp index febca3d49..d11e04946 100644 --- a/src/eepp/graphics/texturefactory.cpp +++ b/src/eepp/graphics/texturefactory.cpp @@ -97,13 +97,13 @@ TextureFactory::loadFromFile( const std::string& Filepath, const bool& Mipmap, return myTex.getTexture(); } -Uint32 TextureFactory::pushTexture( const std::string& Filepath, const Uint32& TexId, - const unsigned int& Width, const unsigned int& Height, - const unsigned int& ImgWidth, const unsigned int& ImgHeight, - const bool& Mipmap, const unsigned int& Channels, - const Texture::ClampMode& ClampMode, - const bool& CompressTexture, const bool& LocalCopy, - const Uint32& MemSize ) { +Texture* TextureFactory::pushTexture( const std::string& Filepath, const Uint32& TexId, + const unsigned int& Width, const unsigned int& Height, + const unsigned int& ImgWidth, const unsigned int& ImgHeight, + const bool& Mipmap, const unsigned int& Channels, + const Texture::ClampMode& ClampMode, + const bool& CompressTexture, const bool& LocalCopy, + const Uint32& MemSize ) { lock(); Texture* Tex = NULL; @@ -129,7 +129,7 @@ Uint32 TextureFactory::pushTexture( const std::string& Filepath, const Uint32& T unlock(); - return Pos; + return Tex; } Uint32 TextureFactory::findFreeSlot() { diff --git a/src/eepp/graphics/textureloader.cpp b/src/eepp/graphics/textureloader.cpp index fd3871c7d..8044ffd6b 100644 --- a/src/eepp/graphics/textureloader.cpp +++ b/src/eepp/graphics/textureloader.cpp @@ -23,6 +23,19 @@ using namespace EE::Graphics::Private; namespace EE { namespace Graphics { +UnorderedMap TextureLoader::sCbs = {}; +std::atomic TextureLoader::sNumCbs = 0; + +Uint32 TextureLoader::pushLoadedCallback( const OnTextureLoaded& cb ) { + Uint32 newCb = ++sNumCbs; + sCbs.insert( { newCb, cb } ); + return newCb; +} + +void TextureLoader::popLoadedCallback( const Uint32& cbId ) { + sCbs.erase( cbId ); +} + TextureLoader::TextureLoader( IOStream& Stream, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) : @@ -261,6 +274,11 @@ void TextureLoader::loadFromStream() { } } +void TextureLoader::notifyLoaded() { + for ( const auto& cb : sCbs ) + cb.second( cb.first, mTexture ); +} + void TextureLoader::loadFromPixels() { if ( !mLoaded && mTexLoaded ) { Uint32 tTexId = 0; @@ -345,17 +363,19 @@ void TextureLoader::loadFromPixels() { } } - mTexId = TextureFactory::instance()->pushTexture( + mTexture = TextureFactory::instance()->pushTexture( mFilepath, tTexId, width, height, mImgWidth, mImgHeight, mMipmap, mChannels, mClampMode, mCompressTexture || mIsCompressed, mLocalCopy, mSize ); if ( mFilepath.empty() ) { - Log::info( "Texture ID %d loaded in %4.3f ms.", mTexId, + Log::info( "Texture ID %d loaded in %4.3f ms.", mTexture->getTextureId(), mTE.getElapsedTimeAndReset().asMilliseconds() ); } else { Log::info( "Texture %s loaded in %4.3f ms.", mFilepath.c_str(), mTE.getElapsedTimeAndReset().asMilliseconds() ); } + + notifyLoaded(); } else { Log::warning( "Failed to create texture. Reason: %s", SOIL_last_result() ); } @@ -387,8 +407,8 @@ void TextureLoader::loadFromPixels() { } } -const Uint32& TextureLoader::getId() const { - return mTexId; +Uint32 TextureLoader::getId() const { + return mTexture != nullptr ? mTexture->getTextureId() : 0; } void TextureLoader::setColorKey( RGB Color ) { @@ -401,10 +421,7 @@ const std::string& TextureLoader::getFilepath() const { } Texture* TextureLoader::getTexture() const { - if ( 0 != mTexId ) - return TextureFactory::instance()->getTexture( mTexId ); - - return NULL; + return mTexture; } Image::FormatConfiguration TextureLoader::getFormatConfiguration() const { @@ -417,16 +434,16 @@ void TextureLoader::setFormatConfiguration( } void TextureLoader::unload() { - if ( mLoaded ) { - TextureFactory::instance()->remove( mTexId ); + if ( mLoaded && mTexture != nullptr ) { + TextureFactory::instance()->remove( mTexture->getTextureId() ); reset(); } } void TextureLoader::reset() { - mPixels = NULL; - mTexId = 0; + mPixels = nullptr; + mTexture = nullptr; mImgWidth = 0; mImgHeight = 0; mWidth = 0; diff --git a/src/eepp/ui/tools/uitextureviewer.cpp b/src/eepp/ui/tools/uitextureviewer.cpp new file mode 100644 index 000000000..83c760f8f --- /dev/null +++ b/src/eepp/ui/tools/uitextureviewer.cpp @@ -0,0 +1,74 @@ +#include "uitextureviewer.hpp" +#include +#include +#include +#include + +namespace EE { namespace UI { namespace Tools { + +UITextureViewer* UITextureViewer::New() { + return eeNew( UITextureViewer, () ); +} + +UITextureViewer::~UITextureViewer() { + TextureLoader::popLoadedCallback( mLoaderCb ); + for ( const auto& cb : mCbs ) { + if ( !cb.first->popResourceChangeCallback( cb.second ) ) { + eePRINTL( "UITextureViewer::~UITextureViewer popResourceChangeCallback failed" ); + eeASSERT( false ); + } + } +} + +UITextureViewer::UITextureViewer() : UILinearLayout( "textureviewer", UIOrientation::Vertical ) { + init(); +} + +void UITextureViewer::init() { + mUISceneNode->loadLayoutFromString( + R"xml( + + + + )xml", + this ); + + mGridLayout = findByType( UI_TYPE_GRID_LAYOUT ); + + std::vector textures = TextureFactory::instance()->getTextures(); + for ( Texture* texture : textures ) + insertTexture( texture ); + + mLoaderCb = TextureLoader::pushLoadedCallback( + [this]( Uint32, Texture* tex ) { insertTexture( tex ); } ); +} + +static std::string getTextureDescription( Texture* tex ) { + return String::format( "Name: %s\nSize: %dx%d", tex->getName().c_str(), tex->getWidth(), + tex->getHeight() ); +} + +void UITextureViewer::insertTexture( Texture* tex ) { + UIImage* img = UIImage::New(); + std::string uid( String::format( "%llu", reinterpret_cast( tex ) ) ); + img->setDrawable( tex ) + ->setScaleType( UIScaleType::FitInside ) + ->setClasses( { "texture-preview", uid } ) + ->setTooltipText( getTextureDescription( tex ) ) + ->setGravity( UI_HALIGN_CENTER | UI_VALIGN_CENTER ) + ->setEnabled( true ) + ->setParent( mGridLayout ); + Uint32 cb = tex->pushResourceChangeCallback( + [this, uid]( Uint32, DrawableResource::Event event, DrawableResource* res ) { + if ( event == DrawableResource::Event::Unload ) { + auto found = mGridLayout->findByClass( uid ); + if ( found && mCbs.erase( static_cast( res ) ) ) + found->close(); + } else if ( event == DrawableResource::Change ) { + getTextureDescription( static_cast( res ) ); + } + } ); + mCbs.insert( { tex, cb } ); +} + +}}} // namespace EE::UI::Tools diff --git a/src/eepp/ui/tools/uitextureviewer.hpp b/src/eepp/ui/tools/uitextureviewer.hpp new file mode 100644 index 000000000..a81fd43be --- /dev/null +++ b/src/eepp/ui/tools/uitextureviewer.hpp @@ -0,0 +1,36 @@ +#ifndef EE_UITEXTUREVIEWER_HPP +#define EE_UITEXTUREVIEWER_HPP + +#include +#include + +using namespace EE::UI; + +namespace EE { namespace UI { + +class UIGridLayout; + +namespace Tools { + +class EE_API UITextureViewer : public UILinearLayout { + public: + static UITextureViewer* New(); + + ~UITextureViewer(); + + protected: + UIGridLayout* mGridLayout; + UnorderedMap mCbs; + Uint32 mLoaderCb; + + UITextureViewer(); + + void init(); + + void insertTexture( Texture* tex ); +}; + +} // namespace Tools +}} // namespace EE::UI + +#endif // EE_UITEXTUREVIEWER_HPP diff --git a/src/eepp/ui/tools/uiwidgetinspector.cpp b/src/eepp/ui/tools/uiwidgetinspector.cpp index e76cfce28..772d16cfe 100644 --- a/src/eepp/ui/tools/uiwidgetinspector.cpp +++ b/src/eepp/ui/tools/uiwidgetinspector.cpp @@ -29,12 +29,13 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc static const auto WIDGET_LAYOUT = R"xml( - + " + @@ -120,6 +121,14 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc } } ); + cont->find( "open-texture-viewer" )->onClick( []( auto ) { + SceneManager::instance()->getUISceneNode()->loadLayoutFromString( R"xml( + + + + )xml" )->center(); + } ); + uiWin->center(); Uint32 winCb = sceneNode->addEventListener( Event::OnWindowAdded, [&, sceneNode, uiWin]( diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 7e8f2c5f4..a066c8b1c 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -238,7 +238,7 @@ void UICodeEditor::draw() { Color col; auto lineRange = getVisibleLineRange(); - Float charSize = PixelDensity::pxToDp( getCharacterSize() ); + Float charSize = getCharacterSize(); Float lineHeight = getLineHeight(); int lineNumberDigits = getLineNumberDigits(); Float gutterWidth = getGutterWidth(); @@ -613,11 +613,11 @@ void UICodeEditor::setShowIndentationGuides( bool showIndentationGuides ) { } } -UICodeEditor* UICodeEditor::setFontSize( const Float& dpSize ) { - if ( mFontStyleConfig.CharacterSize != dpSize ) { +UICodeEditor* UICodeEditor::setFontSize( const Float& size ) { + if ( mFontStyleConfig.CharacterSize != size ) { mFontStyleConfig.CharacterSize = - eeabs( dpSize - (int)dpSize ) == 0.5f || (int)dpSize == dpSize ? dpSize - : eefloor( dpSize ); + eeabs( size - (int)size ) == 0.5f || (int)size == size ? size + : eefloor( size ); mFontSize = mFontStyleConfig.CharacterSize; udpateGlyphWidth(); invalidateDraw(); @@ -2116,7 +2116,7 @@ bool UICodeEditor::applyProperty( const StyleSheetProperty& attribute ) { break; } case PropertyId::FontSize: - setFontSize( lengthFromValueAsDp( attribute ) ); + setFontSize( lengthFromValue( attribute ) ); break; case PropertyId::FontStyle: { setFontStyle( attribute.asFontStyle() ); @@ -2163,7 +2163,7 @@ std::string UICodeEditor::getPropertyString( const PropertyDefinition* propertyD case PropertyId::FontFamily: return NULL != getFont() ? getFont()->getName() : ""; case PropertyId::FontSize: - return String::format( "%.2fdp", getFontSize() ); + return String::format( "%.2fpx", getFontSize() ); case PropertyId::FontStyle: return Text::styleFlagToString( getFontStyle() ); case PropertyId::TextStrokeWidth: @@ -2412,7 +2412,7 @@ bool UICodeEditor::unregisterTopSpace( UICodeEditorPlugin* plugin ) { } Float UICodeEditor::getCharacterSize() const { - return PixelDensity::dpToPx( mFontStyleConfig.getFontCharacterSize() ); + return mFontStyleConfig.getFontCharacterSize(); } Float UICodeEditor::getGlyphWidth() const { diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index ac9b31657..bfabaf056 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -164,7 +164,7 @@ bool UIConsole::applyProperty( const StyleSheetProperty& attribute ) { break; } case PropertyId::FontSize: - setFontSize( lengthFromValueAsDp( attribute ) ); + setFontSize( lengthFromValue( attribute ) ); break; case PropertyId::FontStyle: { setFontStyle( attribute.asFontStyle() ); @@ -203,7 +203,7 @@ std::string UIConsole::getPropertyString( const PropertyDefinition* propertyDef, case PropertyId::FontFamily: return NULL != getFont() ? getFont()->getName() : ""; case PropertyId::FontSize: - return String::format( "%.2fdp", getFontSize() ); + return String::format( "%.2fpx", getFontSize() ); case PropertyId::FontStyle: return Text::styleFlagToString( getFontStyleConfig().getFontStyle() ); case PropertyId::TextStrokeWidth: @@ -226,11 +226,10 @@ std::vector UIConsole::getPropertiesImplemented() const { return props; } -UIConsole* UIConsole::setFontSize( const Float& dpSize ) { - if ( mFontStyleConfig.CharacterSize != dpSize ) { +UIConsole* UIConsole::setFontSize( const Float& size ) { + if ( mFontStyleConfig.CharacterSize != size ) { mFontStyleConfig.CharacterSize = - eeabs( dpSize - (int)dpSize ) == 0.5f || (int)dpSize == dpSize ? dpSize - : eefloor( dpSize ); + eeabs( size - (int)size ) == 0.5f || (int)size == size ? size : eefloor( size ); invalidateDraw(); onFontChanged(); } @@ -1208,8 +1207,7 @@ void UIConsole::pushText( const char* format, ... ) { } Float UIConsole::getLineHeight() const { - return mFontStyleConfig.Font->getFontHeight( - PixelDensity::dpToPx( mFontStyleConfig.CharacterSize ) ); + return mFontStyleConfig.Font->getFontHeight( mFontStyleConfig.CharacterSize ); } bool UIConsole::getQuakeMode() const { diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index edad491bf..7ffeabe02 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -56,8 +56,9 @@ UIImage* UIImage::setDrawable( Drawable* drawable, bool ownIt ) { if ( NULL != mDrawable && mDrawable->isDrawableResource() ) { mResourceChangeCb = static_cast( mDrawable ) - ->pushResourceChangeCallback( - cb::Make2( this, &UIImage::onDrawableResourceEvent ) ); + ->pushResourceChangeCallback( [this]( auto, auto event, auto res ) { + onDrawableResourceEvent( event, res ); + } ); } onAutoSize(); diff --git a/src/eepp/ui/uinodedrawable.cpp b/src/eepp/ui/uinodedrawable.cpp index bf9280639..fc43358a2 100644 --- a/src/eepp/ui/uinodedrawable.cpp +++ b/src/eepp/ui/uinodedrawable.cpp @@ -406,16 +406,17 @@ void UINodeDrawable::LayerDrawable::setDrawable( Drawable* drawable, const bool& invalidate(); if ( NULL != mDrawable && mDrawable->isDrawableResource() ) { - mResourceChangeCbId = reinterpret_cast( mDrawable ) - ->pushResourceChangeCallback( - [this]( DrawableResource::Event event, DrawableResource* ) { - invalidate(); - if ( event == DrawableResource::Event::Unload ) { - mResourceChangeCbId = 0; - mDrawable = NULL; - mOwnsDrawable = false; - } - } ); + mResourceChangeCbId = + reinterpret_cast( mDrawable ) + ->pushResourceChangeCallback( + [this]( Uint32, DrawableResource::Event event, DrawableResource* ) { + invalidate(); + if ( event == DrawableResource::Event::Unload ) { + mResourceChangeCbId = 0; + mDrawable = NULL; + mOwnsDrawable = false; + } + } ); } } diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 472fcf8a5..38f046f07 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -111,7 +111,7 @@ void UITextInput::drawWaitingCursor() { primitives.setColor( Color( mFontStyleConfig.FontColor ).blendAlpha( mAlpha ) ); primitives.drawRectangle( Rectf( cursor, Sizef( PixelDensity::dpToPx( 1 ), mTextCache->getFont()->getFontHeight( - mTextCache->getCharacterSizePx() ) ) ) ); + mTextCache->getCharacterSize() ) ) ) ); } } @@ -524,7 +524,7 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { setHintShadowOffset( attribute.asVector2f() ); break; case PropertyId::HintFontSize: - setHintFontSize( attribute.asDpDimensionI() ); + setHintFontSize( lengthFromValue( attribute ) ); break; case PropertyId::HintFontFamily: setHintFont( FontManager::instance()->getByName( attribute.asString() ) ); diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index 0faffd782..bdb7b8e28 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -120,10 +120,6 @@ Uint32 UITextView::getFontSize() const { return mTextCache->getCharacterSize(); } -Uint32 UITextView::getPixelsFontSize() const { - return mTextCache->getCharacterSizePx(); -} - UITextView* UITextView::setFontSize( const Uint32& characterSize ) { if ( mTextCache->getCharacterSize() != characterSize ) { mFontStyleConfig.CharacterSize = characterSize; @@ -562,7 +558,7 @@ void UITextView::drawSelection( Text* textCache ) { if ( !mSelPosCache.empty() ) { Primitives P; P.setColor( mFontStyleConfig.FontSelectionBackColor ); - Float vspace = textCache->getFont()->getLineSpacing( textCache->getCharacterSizePx() ); + Float vspace = textCache->getFont()->getLineSpacing( textCache->getCharacterSize() ); for ( size_t i = 0; i < mSelPosCache.size(); i++ ) { initPos = mSelPosCache[i].initPos; @@ -655,7 +651,7 @@ const Int32& UITextView::getFontLineCenter() { } void UITextView::recalculate() { - int fontHeight = mTextCache->getCharacterSizePx(); + int fontHeight = mTextCache->getCharacterSize(); mFontLineCenter = eefloor( (Float)( ( mTextCache->getFont()->getLineSpacing( fontHeight ) - fontHeight ) / 2 ) ); @@ -706,7 +702,7 @@ bool UITextView::applyProperty( const StyleSheetProperty& attribute ) { break; } case PropertyId::FontSize: - setFontSize( lengthFromValueAsDp( attribute ) ); + setFontSize( lengthFromValue( attribute ) ); break; case PropertyId::FontStyle: { Uint32 flags = attribute.asFontStyle(); @@ -777,7 +773,7 @@ std::string UITextView::getPropertyString( const PropertyDefinition* propertyDef case PropertyId::FontFamily: return NULL != getFont() ? getFont()->getName() : ""; case PropertyId::FontSize: - return String::format( "%ddp", getFontSize() ); + return String::format( "%dpx", getFontSize() ); case PropertyId::FontStyle: return Text::styleFlagToString( getFontStyle() ); case PropertyId::TextStrokeWidth: diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 5915ff4a4..8f18faf81 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -251,7 +251,8 @@ UITheme* UITheme::loadFromDirectroy( UITheme* tTheme, const std::string& Path, else eeSAFE_DELETE( tSG ); - Log::info( "UI Theme Loaded in: %4.3f ms ( from path )", TE.getElapsedTimeAndReset().asMilliseconds() ); + Log::info( "UI Theme Loaded in: %4.3f ms ( from path )", + TE.getElapsedTimeAndReset().asMilliseconds() ); return tTheme; } @@ -273,7 +274,7 @@ UITheme::UITheme( const std::string& name, const std::string& Abbr, Graphics::Fo mAbbr( Abbr ), mTextureAtlas( NULL ), mDefaultFont( defaultFont ), - mDefaultFontSize( PixelDensity::getPixelDensity() > 1.4 ? 11 : 12 ), + mDefaultFontSize( PixelDensity::dpToPx( PixelDensity::getPixelDensity() > 1.4 ? 11 : 12 ) ), mIconTheme( UIIconTheme::New( name ) ) {} UITheme::~UITheme() { diff --git a/src/eepp/ui/uithememanager.cpp b/src/eepp/ui/uithememanager.cpp index 4b7d2f9c8..ff322973e 100644 --- a/src/eepp/ui/uithememanager.cpp +++ b/src/eepp/ui/uithememanager.cpp @@ -10,7 +10,7 @@ UIThemeManager* UIThemeManager::New() { UIThemeManager::UIThemeManager() : ResourceManager(), mFont( NULL ), - mFontSize( PixelDensity::getPixelDensity() > 1.4 ? 11 : 12 ), + mFontSize( PixelDensity::dpToPx( PixelDensity::getPixelDensity() > 1.4 ? 11 : 12 ) ), mThemeDefault( NULL ), mAutoApplyDefaultTheme( true ), mEnableDefaultEffects( false ), diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index a6213f453..85a8bfdfb 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -424,7 +424,7 @@ std::string UITooltip::getPropertyString( const PropertyDefinition* propertyDef, case PropertyId::FontFamily: return NULL != getFont() ? getFont()->getName() : ""; case PropertyId::FontSize: - return String::format( "%ddp", getCharacterSize() ); + return String::format( "%dpx", getCharacterSize() ); case PropertyId::FontStyle: return Text::styleFlagToString( getFontStyle() ); case PropertyId::TextStrokeWidth: @@ -529,7 +529,7 @@ bool UITooltip::applyProperty( const StyleSheetProperty& attribute ) { } case PropertyId::FontSize: if ( !mUsingCustomStyling ) - setFontSize( attribute.asDpDimensionI() ); + setFontSize( lengthFromValue( attribute ) ); break; case PropertyId::FontStyle: if ( !mUsingCustomStyling ) diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index a5f1997b3..0638134cf 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -713,7 +713,7 @@ void UIWidget::updatePseudoClasses() { invalidateDraw(); } -void UIWidget::resetClass() { +UIWidget* UIWidget::resetClass() { if ( !mClasses.empty() ) { mClasses.clear(); if ( !isSceneNodeLoading() && !isLoadingState() ) { @@ -723,9 +723,10 @@ void UIWidget::resetClass() { onClassChange(); } + return this; } -void UIWidget::setClass( const std::string& cls ) { +UIWidget* UIWidget::setClass( const std::string& cls ) { if ( mClasses.size() != 1 || mClasses[0] != cls ) { mClasses.clear(); mClasses.push_back( cls ); @@ -737,9 +738,10 @@ void UIWidget::setClass( const std::string& cls ) { onClassChange(); } + return this; } -void UIWidget::setClasses( const std::vector& classes ) { +UIWidget* UIWidget::setClasses( const std::vector& classes ) { if ( mClasses != classes ) { mClasses = classes; @@ -750,9 +752,10 @@ void UIWidget::setClasses( const std::vector& classes ) { onClassChange(); } + return this; } -void UIWidget::addClass( const std::string& cls ) { +UIWidget* UIWidget::addClass( const std::string& cls ) { if ( !cls.empty() && !hasClass( cls ) ) { mClasses.push_back( cls ); @@ -763,9 +766,10 @@ void UIWidget::addClass( const std::string& cls ) { onClassChange(); } + return this; } -void UIWidget::addClasses( const std::vector& classes ) { +UIWidget* UIWidget::addClasses( const std::vector& classes ) { if ( !classes.empty() ) { for ( auto cit = classes.begin(); cit != classes.end(); ++cit ) { const std::string& cls = *cit; @@ -782,9 +786,10 @@ void UIWidget::addClasses( const std::vector& classes ) { onClassChange(); } + return this; } -void UIWidget::removeClass( const std::string& cls ) { +UIWidget* UIWidget::removeClass( const std::string& cls ) { if ( hasClass( cls ) ) { mClasses.erase( std::find( mClasses.begin(), mClasses.end(), cls ) ); @@ -795,9 +800,10 @@ void UIWidget::removeClass( const std::string& cls ) { onClassChange(); } + return this; } -void UIWidget::removeClasses( const std::vector& classes ) { +UIWidget* UIWidget::removeClasses( const std::vector& classes ) { if ( !classes.empty() ) { for ( auto cit = classes.begin(); cit != classes.end(); ++cit ) { const std::string& cls = *cit; @@ -818,6 +824,7 @@ void UIWidget::removeClasses( const std::vector& classes ) { onClassChange(); } + return this; } bool UIWidget::hasClass( const std::string& cls ) const { diff --git a/src/eepp/ui/uiwidgetcreator.cpp b/src/eepp/ui/uiwidgetcreator.cpp index 0811c7335..614f216ce 100644 --- a/src/eepp/ui/uiwidgetcreator.cpp +++ b/src/eepp/ui/uiwidgetcreator.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -97,6 +98,7 @@ void UIWidgetCreator::createBaseWidgetList() { registeredWidget["menuradiobutton"] = UIMenuRadioButton::New; registeredWidget["menuseparator"] = UIMenuSeparator::New; registeredWidget["anchor"] = UIAnchor::New; + registeredWidget["textureviewer"] = Tools::UITextureViewer::New; registeredWidget["hbox"] = UILinearLayout::NewHorizontal; registeredWidget["vbox"] = UILinearLayout::NewVertical; diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index 171540b43..9fd5c9542 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -1744,10 +1744,11 @@ void EETest::screen3() { } void EETest::screen4() { - if ( NULL != mFBO ) { - mFBO->bind(); - mFBO->clear(); - } + if ( NULL == mFBO ) + return; + + mFBO->bind(); + mFBO->clear(); if ( NULL != mVBO ) { mBlindy.setPosition( Vector2f( 128 - 16, 128 - 16 ) ); @@ -1776,15 +1777,13 @@ void EETest::screen4() { p.drawCircle( center, 32 ); GLi->getClippingMask()->stencilMaskDisable(); - if ( NULL != mFBO ) { - mFBO->unbind(); + mFBO->unbind(); - if ( NULL != mFBO->getTexture() ) { - mFBO->getTexture()->draw( - (Float)mWindow->getWidth() * 0.5f - (Float)mFBO->getWidth() * 0.5f, - (Float)mWindow->getHeight() * 0.5f - (Float)mFBO->getHeight() * 0.5f, Ang ); - GlobalBatchRenderer::instance()->draw(); - } + if ( NULL != mFBO->getTexture() ) { + mFBO->getTexture()->draw( + (Float)mWindow->getWidth() * 0.5f - (Float)mFBO->getWidth() * 0.5f, + (Float)mWindow->getHeight() * 0.5f - (Float)mFBO->getHeight() * 0.5f, Ang ); + GlobalBatchRenderer::instance()->draw(); } } diff --git a/src/tools/ecode/applayout.xml.hpp b/src/tools/ecode/applayout.xml.hpp index ba89512c7..41f61eaac 100644 --- a/src/tools/ecode/applayout.xml.hpp +++ b/src/tools/ecode/applayout.xml.hpp @@ -373,6 +373,15 @@ Anchor.error:hover { #build_output_issues TableView::cell.theme-error > TableView::cell::icon { tint: var(--theme-error); } +#build_output_issues TableView::row:selected TableView::cell.theme-error > TableView::cell::text { + color: var(--font); +} +#build_output_issues TableView::row:selected TableView::cell.theme-error > TableView::cell::icon { + tint: var(--font); +} +.texture-preview { + border: 1dp solid var(--list-back); +} diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 44f0aca99..72c8694cd 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -1021,7 +1021,7 @@ void App::setEditorFontSize() { msgBox->on( Event::OnConfirm, [&, msgBox]( const Event* ) { mConfig.editor.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() ); mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { - editor->setFontSize( mConfig.editor.fontSize.asDp( 0, Sizef(), mDisplayDPI ) ); + editor->setFontSize( mConfig.editor.fontSize.asPixels( 0, Sizef(), mDisplayDPI ) ); } ); } ); setFocusEditorOnClose( msgBox ); @@ -1054,7 +1054,7 @@ void App::setUIFontSize() { msgBox->showWhenReady(); msgBox->on( Event::OnConfirm, [&, msgBox]( const Event* ) { mConfig.ui.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() ); - Float fontSize = mConfig.ui.fontSize.asDp( 0, Sizef(), mDisplayDPI ); + Float fontSize = mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ); UIThemeManager* manager = mUISceneNode->getUIThemeManager(); manager->setDefaultFontSize( fontSize ); manager->getDefaultTheme()->setDefaultFontSize( fontSize ); @@ -1063,8 +1063,8 @@ void App::setUIFontSize() { UITextView* textView = node->asType(); if ( !textView->getUIStyle()->hasProperty( PropertyId::FontSize ) ) { textView->setFontSize( - mConfig.ui.fontSize.asDp( node->getParent()->getPixelsSize().getWidth(), - Sizef(), mUISceneNode->getDPI() ) ); + mConfig.ui.fontSize.asPixels( node->getParent()->getPixelsSize().getWidth(), + Sizef(), mUISceneNode->getDPI() ) ); } } } ); @@ -1683,7 +1683,7 @@ std::string App::getDefaultThemePath() const { void App::setTheme( const std::string& path ) { UITheme* theme = UITheme::load( "uitheme", "uitheme", "", mFont, path ); - theme->setDefaultFontSize( mConfig.ui.fontSize.asDp( 0, Sizef(), mDisplayDPI ) ); + theme->setDefaultFontSize( mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ) ); if ( path != getDefaultThemePath() ) { auto style = theme->getStyleSheet().getStyleFromSelector( ":root" ); @@ -1717,7 +1717,7 @@ void App::setTheme( const std::string& path ) { //->setDefaultEffectsEnabled( true ) ->setDefaultTheme( theme ) ->setDefaultFont( mFont ) - ->setDefaultFontSize( mConfig.ui.fontSize.asDp( 0, Sizef(), mDisplayDPI ) ) + ->setDefaultFontSize( mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ) ) ->add( theme ); mUISceneNode->getRoot()->addClass( "appbackground" ); @@ -2192,7 +2192,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { const DocumentConfig& docc = !mCurrentProject.empty() && !mProjectDocConfig.useGlobalSettings ? mProjectDocConfig.doc : mConfig.doc; - editor->setFontSize( config.fontSize.asDp( 0, Sizef(), mUISceneNode->getDPI() ) ); + editor->setFontSize( config.fontSize.asPixels( 0, Sizef(), mUISceneNode->getDPI() ) ); editor->setEnableColorPickerOnSelection( true ); editor->setColorScheme( mSplitter->getCurrentColorScheme() ); editor->setShowLineNumber( config.showLineNumbers ); diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 2d315347d..309383c84 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -194,9 +194,8 @@ void UITreeViewCellGlobalSearch::draw() { if ( getCurIndex().internalId() != -1 && mSearchStrPos.first != std::string::npos && mSearchStrPos.second > 0 && mSearchStrPos.second <= mTextBox->getText().length() ) { UITreeViewGlobalSearch* pp = getParent()->getParent()->asType(); - auto hspace = mTextBox->getFont() - ->getGlyph( L' ', mTextBox->getPixelsFontSize(), false, false ) - .advance; + auto hspace = + mTextBox->getFont()->getGlyph( L' ', mTextBox->getFontSize(), false, false ).advance; Primitives p; p.setColor( pp->getColorScheme().getEditorSyntaxStyle( "selection" ).color ); Vector2f screenPos( mScreenPos );