diff --git a/include/eepp/ui/abstract/uiabstracttableview.hpp b/include/eepp/ui/abstract/uiabstracttableview.hpp index 1470617cb..770fab763 100644 --- a/include/eepp/ui/abstract/uiabstracttableview.hpp +++ b/include/eepp/ui/abstract/uiabstracttableview.hpp @@ -68,6 +68,10 @@ class EE_API UIAbstractTableView : public UIAbstractView { void moveSelection( int steps ); + const size_t& getIconSize() const; + + void setIconSize( const size_t& iconSize ); + protected: friend class EE::UI::UITableHeaderColumn; @@ -84,6 +88,7 @@ class EE_API UIAbstractTableView : public UIAbstractView { mutable std::vector> mWidgets; UILinearLayout* mHeader; Float mDragBorderDistance{8}; + size_t mIconSize{16}; bool mAutoExpandOnSingleColumn{false}; virtual ~UIAbstractTableView(); diff --git a/include/eepp/ui/models/filesystemmodel.hpp b/include/eepp/ui/models/filesystemmodel.hpp index d7ac53380..95448266c 100644 --- a/include/eepp/ui/models/filesystemmodel.hpp +++ b/include/eepp/ui/models/filesystemmodel.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace EE { namespace UI { namespace Models { @@ -96,7 +97,7 @@ class EE_API FileSystemModel : public Model { virtual ModelIndex index( int row, int column = 0, const ModelIndex& parent = ModelIndex() ) const; - virtual Drawable* iconFor( const Node& node, const ModelIndex& index ) const; + virtual UIIcon* iconFor( const Node& node, const ModelIndex& index ) const; void setMode( const Mode& mode ); diff --git a/include/eepp/ui/models/variant.hpp b/include/eepp/ui/models/variant.hpp index 8468193a5..3b2623062 100644 --- a/include/eepp/ui/models/variant.hpp +++ b/include/eepp/ui/models/variant.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include using namespace EE::Graphics; @@ -24,6 +25,7 @@ class EE_API Variant { Int64, Uint64, Drawable, + Icon, Vector2f, Rectf, cstr @@ -36,6 +38,7 @@ class EE_API Variant { mValue.asDrawable = drawable; mOwnsObject = ownDrawable; } + Variant( UIIcon* icon ) : mType( Type::Icon ) { mValue.asIcon = icon; } Variant( const Vector2f& v ) : mType( Type::Vector2f ) { mValue.asVector2f = eeNew( Vector2f, ( v ) ); } @@ -59,6 +62,7 @@ class EE_API Variant { const Vector2f& asVector2f() const { return *mValue.asVector2f; } const Rectf& asRectf() const { return *mValue.asRectf; } const char* asCStr() const { return mValue.asCStr; } + UIIcon* asIcon() const { return mValue.asIcon; } bool is( const Type& type ) const { return type == mType; } void reset() { switch ( mType ) { @@ -86,6 +90,7 @@ class EE_API Variant { union { void* asDataPtr; Drawable* asDrawable; + UIIcon* asIcon; std::string* asString; bool asBool; Float asFloat; diff --git a/include/eepp/ui/uiicon.hpp b/include/eepp/ui/uiicon.hpp new file mode 100644 index 000000000..e082781ec --- /dev/null +++ b/include/eepp/ui/uiicon.hpp @@ -0,0 +1,48 @@ +#ifndef EE_UI_UIICON_HPP +#define EE_UI_UIICON_HPP + +#include +#include + +namespace EE { namespace Graphics { +class FontTrueType; +}} // namespace EE::Graphics +using namespace EE::Graphics; + +namespace EE { namespace UI { + +class EE_API UIIcon { + public: + static UIIcon* New( const std::string& name ); + + virtual ~UIIcon(); + + const std::string& getName() const; + + virtual Drawable* getSize( const int& size ) const; + + virtual void setSize( const int& size, Drawable* drawable ); + + protected: + UIIcon( const std::string& name ); + + std::string mName; + mutable std::map mSizes; +}; + +class EE_API UIGlyphIcon : public UIIcon { + public: + static UIIcon* New( const std::string& name, FontTrueType* font, const Uint32& codePoint ); + + virtual Drawable* getSize( const int& size ) const; + + protected: + UIGlyphIcon( const std::string& name, FontTrueType* font, const Uint32& codePoint ); + + mutable FontTrueType* mFont; + Uint32 mCodePoint; +}; + +}} // namespace EE::UI + +#endif // EE_UI_UIICON_HPP diff --git a/include/eepp/ui/uiicontheme.hpp b/include/eepp/ui/uiicontheme.hpp index d589ce8b9..853cd9778 100644 --- a/include/eepp/ui/uiicontheme.hpp +++ b/include/eepp/ui/uiicontheme.hpp @@ -2,6 +2,7 @@ #define EE_UI_UIICONTHEME_HPP #include +#include #include using namespace EE::Graphics; @@ -12,17 +13,19 @@ class EE_API UIIconTheme { public: static UIIconTheme* New( const std::string& name ); - UIIconTheme* add( const std::string& name, Drawable* drawable ); + ~UIIconTheme(); - UIIconTheme* add( const std::unordered_map& icons ); + UIIconTheme* add( UIIcon* icon ); + + UIIconTheme* add( const std::unordered_map& icons ); const std::string& getName() const; - Drawable* getIcon( const std::string& name ) const; + UIIcon* getIcon( const std::string& name ) const; protected: std::string mName; - std::unordered_map mIcons; + std::unordered_map mIcons; UIIconTheme( const std::string& name ); }; diff --git a/include/eepp/ui/uiiconthememanager.hpp b/include/eepp/ui/uiiconthememanager.hpp index f328ebb7f..9019249ca 100644 --- a/include/eepp/ui/uiiconthememanager.hpp +++ b/include/eepp/ui/uiiconthememanager.hpp @@ -24,7 +24,7 @@ class EE_API UIIconThemeManager { UIIconThemeManager* setFallbackTheme( UIIconTheme* fallbackTheme ); - Drawable* findIcon( const std::string& name ); + UIIcon* findIcon( const std::string& name ); UIThemeManager* getFallbackThemeManager() const; diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index f8218872a..055194bc6 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -20,6 +20,7 @@ class UIWidget; class UIWindow; class UIWidget; class UILayout; +class UIIcon; class EE_API UISceneNode : public SceneNode { public: @@ -104,7 +105,9 @@ class EE_API UISceneNode : public SceneNode { UIIconThemeManager* getUIIconThemeManager() const; - Drawable* findIcon( const std::string& iconName ); + UIIcon* findIcon( const std::string& iconName ); + + Drawable* findIconDrawable( const std::string& iconName, const size_t& drawableSize ); typedef std::function KeyBindingCommand; diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index f4bdb820d..17e825db4 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -17,6 +17,9 @@ class Drawable; namespace EE { namespace UI { +class UIIcon; +class UIIconTheme; + class EE_API UITheme : protected ResourceManagerMulti { public: using ResourceManagerMulti::getById; @@ -43,8 +46,6 @@ class EE_API UITheme : protected ResourceManagerMulti { static UITheme* loadFromDirectroy( const std::string& Path, const std::string& Name, const std::string& NameAbbr, const Float& pixelDensity = 1 ); - UITheme( const std::string& name, const std::string& abbr, Graphics::Font* defaultFont = NULL ); - virtual ~UITheme(); const std::string& getName() const; @@ -59,7 +60,7 @@ class EE_API UITheme : protected ResourceManagerMulti { Graphics::TextureAtlas* getTextureAtlas() const; - EE::Graphics::Drawable* getIconByName( const std::string& name ); + UIIcon* getIconByName( const std::string& name ); UISkin* getSkin( const std::string& widgetName ); @@ -75,6 +76,8 @@ class EE_API UITheme : protected ResourceManagerMulti { void setDefaultFontSize( const Float& defaultFontSize ); + UIIconTheme* getIconTheme() const; + protected: std::string mName; String::HashType mNameHash; @@ -83,8 +86,11 @@ class EE_API UITheme : protected ResourceManagerMulti { Font* mDefaultFont; Float mDefaultFontSize; CSS::StyleSheet mStyleSheet; + UIIconTheme* mIconTheme; void setTextureAtlas( Graphics::TextureAtlas* SG ); + + UITheme( const std::string& name, const std::string& abbr, Graphics::Font* defaultFont = NULL ); }; }} // namespace EE::UI diff --git a/include/eepp/ui/uitreeview.hpp b/include/eepp/ui/uitreeview.hpp index ef857ccca..5fba8d1ed 100644 --- a/include/eepp/ui/uitreeview.hpp +++ b/include/eepp/ui/uitreeview.hpp @@ -2,6 +2,7 @@ #define EE_UI_UITREEVIEW_HPP #include +#include #include #include #include @@ -36,15 +37,15 @@ class EE_API UITreeView : public UIAbstractTableView { void contractAll( const ModelIndex& index = {} ); - Drawable* getExpandIcon() const; + UIIcon* getExpandIcon() const; - void setExpandedIcon( Drawable* expandIcon ); + void setExpandedIcon( EE::UI::UIIcon* expandIcon ); void setExpandedIcon( const std::string& expandIcon ); - Drawable* getContractIcon() const; + UIIcon* getContractIcon() const; - void setContractedIcon( Drawable* contractIcon ); + void setContractedIcon( EE::UI::UIIcon* contractIcon ); void setContractedIcon( const std::string& contractIcon ); @@ -54,6 +55,10 @@ class EE_API UITreeView : public UIAbstractTableView { Float getMaxColumnContentWidth( const size_t& colIndex ); + const size_t& getExpanderIconSize() const; + + void setExpanderIconSize( const size_t& expanderSize ); + protected: enum class IterationDecision { Continue, @@ -63,8 +68,9 @@ class EE_API UITreeView : public UIAbstractTableView { Float mIndentWidth; Sizef mContentSize; - Drawable* mExpandIcon{nullptr}; - Drawable* mContractIcon{nullptr}; + UIIcon* mExpandIcon{nullptr}; + UIIcon* mContractIcon{nullptr}; + size_t mExpanderIconSize{16}; bool mExpandersAsIcons{false}; UITreeView(); diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 70c35dba3..6eacdb00a 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/projects/linux/ee.files b/projects/linux/ee.files index be57fa3a2..a23b40d43 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -359,6 +359,7 @@ ../../include/eepp/ui/uifontstyleconfig.hpp ../../include/eepp/ui/uigridlayout.hpp ../../include/eepp/ui/uihelper.hpp +../../include/eepp/ui/uiicon.hpp ../../include/eepp/ui/uiicontheme.hpp ../../include/eepp/ui/uiiconthememanager.hpp ../../include/eepp/ui/uiimage.hpp @@ -831,6 +832,7 @@ ../../src/eepp/ui/uieventdispatcher.cpp ../../src/eepp/ui/uifiledialog.cpp ../../src/eepp/ui/uigridlayout.cpp +../../src/eepp/ui/uiicon.cpp ../../src/eepp/ui/uiicontheme.cpp ../../src/eepp/ui/uiiconthememanager.cpp ../../src/eepp/ui/uiimage.cpp diff --git a/projects/linux/ee.includes b/projects/linux/ee.includes index dd9c5ab1f..4292a5f8a 100644 --- a/projects/linux/ee.includes +++ b/projects/linux/ee.includes @@ -6,3 +6,6 @@ ../../src/thirdparty/libvorbis/include /usr/include/freetype2/ ../../src/thirdparty/mbedtls/include +../../include/eepp/ui/tools +../../include/eepp/ui +../../src/eepp/ui diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index df4100337..40b0127f0 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -123,15 +123,21 @@ void MapEditor::createMenuBar() { UIPopUpMenu* PU1 = UIPopUpMenu::New(); PU1->setParent( mUIContainer ); - PU1->add( "New...", PU1->getUISceneNode()->findIcon( "document-new" ) ); - PU1->add( "Open...", PU1->getUISceneNode()->findIcon( "document-open" ) ); + PU1->add( "New...", PU1->getUISceneNode()->findIconDrawable( "document-new", + PixelDensity::dpToPxI( 16 ) ) ); + PU1->add( "Open...", PU1->getUISceneNode()->findIconDrawable( "document-open", + PixelDensity::dpToPxI( 16 ) ) ); PU1->addSeparator(); - PU1->add( "Save", PU1->getUISceneNode()->findIcon( "document-save" ) ); - PU1->add( "Save As...", PU1->getUISceneNode()->findIcon( "document-save-as" ) ); + PU1->add( "Save", PU1->getUISceneNode()->findIconDrawable( "document-save", + PixelDensity::dpToPxI( 16 ) ) ); + PU1->add( "Save As...", PU1->getUISceneNode()->findIconDrawable( + "document-save-as", PixelDensity::dpToPxI( 16 ) ) ); PU1->addSeparator(); - PU1->add( "Close", PU1->getUISceneNode()->findIcon( "document-close" ) ); + PU1->add( "Close", PU1->getUISceneNode()->findIconDrawable( "document-close", + PixelDensity::dpToPxI( 16 ) ) ); PU1->addSeparator(); - PU1->add( "Quit", PU1->getUISceneNode()->findIcon( "quit" ) ); + PU1->add( "Quit", + PU1->getUISceneNode()->findIconDrawable( "quit", PixelDensity::dpToPxI( 16 ) ) ); PU1->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::fileMenuClick ) ); MenuBar->addMenuButton( "File", PU1 ); @@ -146,9 +152,12 @@ void MapEditor::createMenuBar() { PU3->addSeparator(); - PU3->add( "Zoom In", PU3->getUISceneNode()->findIcon( "zoom-in" ) ); - PU3->add( "Zoom Out", PU3->getUISceneNode()->findIcon( "zoom-out" ) ); - PU3->add( "Normal Size", PU3->getUISceneNode()->findIcon( "zoom-original" ) ); + PU3->add( "Zoom In", + PU3->getUISceneNode()->findIconDrawable( "zoom-in", PixelDensity::dpToPxI( 16 ) ) ); + PU3->add( "Zoom Out", + PU3->getUISceneNode()->findIconDrawable( "zoom-out", PixelDensity::dpToPxI( 16 ) ) ); + PU3->add( "Normal Size", PU3->getUISceneNode()->findIconDrawable( + "zoom-original", PixelDensity::dpToPxI( 16 ) ) ); addShortcut( {KEY_KP_PLUS, KEYMOD_CTRL}, "zoom-in", [&] { zoomIn(); } ); addShortcut( {KEY_KP_MINUS, KEYMOD_CTRL}, "zoom-out", [&] { zoomOut(); } ); addShortcut( {KEY_0, KEYMOD_CTRL}, "zoom-reset", [&] { mUIMap->Map()->setScale( 1 ); } ); @@ -310,7 +319,9 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setSize( 24, mGOTypeList->getSize().getHeight() ) ->setPosition( mGOTypeList->getPosition().x + mGOTypeList->getSize().getWidth() + 2, mGOTypeList->getPosition().y ); - mBtnGOTypeAdd->setIcon( mBtnGOTypeAdd->getUISceneNode()->findIcon( "add" ) ) + mBtnGOTypeAdd + ->setIcon( mBtnGOTypeAdd->getUISceneNode()->findIconDrawable( + "add", PixelDensity::dpToPxI( 16 ) ) ) ->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mBtnGOTypeAdd->setTooltipText( "Adds a new game object type\nunknown by the map editor." ); mBtnGOTypeAdd->addEventListener( Event::MouseClick, diff --git a/src/eepp/maps/mapeditor/maplayerproperties.cpp b/src/eepp/maps/mapeditor/maplayerproperties.cpp index 67a2b5441..20d899e80 100644 --- a/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -67,7 +67,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( sceneNode->findIcon( "ok" ) ); + OKButton->setIcon( sceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -81,7 +81,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapLayerProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -104,7 +104,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : UIPushButton* AddButton = UIPushButton::New(); AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - AddButton->setIcon( sceneNode->findIcon( "add" ) ); + AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapLayerProperties::onAddCellClick ) ); @@ -116,7 +116,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : UIPushButton* RemoveButton = UIPushButton::New(); RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - RemoveButton->setIcon( sceneNode->findIcon( "remove" ) ); + RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapLayerProperties::onRemoveCellClick ) ); diff --git a/src/eepp/maps/mapeditor/mapobjectproperties.cpp b/src/eepp/maps/mapeditor/mapobjectproperties.cpp index b12983b47..c5b48c91c 100644 --- a/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -85,7 +85,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); - OKButton->setIcon( sceneNode->findIcon( "ok" ) ); + OKButton->setIcon( sceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -99,7 +99,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapObjectProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -122,7 +122,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : UIPushButton* AddButton = UIPushButton::New(); AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - AddButton->setIcon( sceneNode->findIcon( "add" ) ); + AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapObjectProperties::onAddCellClick ) ); @@ -134,7 +134,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : UIPushButton* RemoveButton = UIPushButton::New(); RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - RemoveButton->setIcon( sceneNode->findIcon( "remove" ) ); + RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapObjectProperties::onRemoveCellClick ) ); diff --git a/src/eepp/maps/mapeditor/tilemapproperties.cpp b/src/eepp/maps/mapeditor/tilemapproperties.cpp index a83fb3d91..b70b36f30 100644 --- a/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -136,7 +136,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( sceneNode->findIcon( "ok" ) ); + OKButton->setIcon( sceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -150,7 +150,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &TileMapProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -173,7 +173,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : UIPushButton* AddButton = UIPushButton::New(); AddButton->setSize( 24, 0 )->setParent( mUIWindow->getContainer() )->setPosition( Pos ); - AddButton->setIcon( sceneNode->findIcon( "add" ) ); + AddButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, cb::Make1( this, &TileMapProperties::onAddCellClick ) ); @@ -185,7 +185,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : UIPushButton* RemoveButton = UIPushButton::New(); RemoveButton->setSize( 24, 0 )->setParent( mUIWindow->getContainer() )->setPosition( Pos ); - RemoveButton->setIcon( sceneNode->findIcon( "remove" ) ); + RemoveButton->setIcon( sceneNode->findIconDrawable( "remove", PixelDensity::dpToPxI( 16 ) ) ); RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( Event::MouseClick, cb::Make1( this, &TileMapProperties::onRemoveCellClick ) ); diff --git a/src/eepp/maps/mapeditor/uigotypenew.cpp b/src/eepp/maps/mapeditor/uigotypenew.cpp index 600cd310c..123aa6e2d 100644 --- a/src/eepp/maps/mapeditor/uigotypenew.cpp +++ b/src/eepp/maps/mapeditor/uigotypenew.cpp @@ -42,7 +42,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( sceneNode->findIcon( "add" ) ); + OKButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -56,7 +56,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIGOTypeNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/maps/mapeditor/uimaplayernew.cpp b/src/eepp/maps/mapeditor/uimaplayernew.cpp index 26fa9194f..7891a5a1e 100644 --- a/src/eepp/maps/mapeditor/uimaplayernew.cpp +++ b/src/eepp/maps/mapeditor/uimaplayernew.cpp @@ -52,7 +52,7 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( sceneNode->findIcon( "add" ) ); + OKButton->setIcon( sceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -67,7 +67,7 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIMapLayerNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/maps/mapeditor/uimapnew.cpp b/src/eepp/maps/mapeditor/uimapnew.cpp index 23a5ef5ce..128c5d238 100644 --- a/src/eepp/maps/mapeditor/uimapnew.cpp +++ b/src/eepp/maps/mapeditor/uimapnew.cpp @@ -281,7 +281,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) UIPushButton* OKButton = UIPushButton::New(); OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); - OKButton->setIcon( sceneNode->findIcon( "ok" ) ); + OKButton->setIcon( sceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -293,7 +293,7 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIMapNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index a6caa6aa8..c76333984 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -7,7 +7,9 @@ namespace EE { namespace UI { namespace Abstract { UIAbstractTableView::UIAbstractTableView( const std::string& tag ) : - UIAbstractView( tag ), mDragBorderDistance( PixelDensity::dpToPx( 4 ) ) { + UIAbstractView( tag ), + mDragBorderDistance( PixelDensity::dpToPx( 4 ) ), + mIconSize( PixelDensity::dpToPxI( 12 ) ) { mHeader = UILinearLayout::NewWithTag( "table::header", UIOrientation::Horizontal ); mHeader->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); mHeader->setParent( this ); @@ -356,6 +358,9 @@ UIWidget* UIAbstractTableView::updateCell( const int& rowIndex, const ModelIndex if ( icon.is( Variant::Type::Drawable ) && icon.asDrawable() ) { isVisible = true; cell->setIcon( icon.asDrawable() ); + } else if ( icon.is( Variant::Type::Icon ) && icon.asIcon() ) { + isVisible = true; + cell->setIcon( icon.asIcon()->getSize( mIconSize ) ); } cell->getIcon()->setVisible( isVisible ); } @@ -381,6 +386,14 @@ void UIAbstractTableView::moveSelection( int steps ) { } } +const size_t& UIAbstractTableView::getIconSize() const { + return mIconSize; +} + +void UIAbstractTableView::setIconSize( const size_t& iconSize ) { + mIconSize = iconSize; +} + void UIAbstractTableView::onOpenModelIndex( const ModelIndex& index ) { ModelEvent event( getModel(), index, this ); sendEvent( &event ); diff --git a/src/eepp/ui/models/filesystemmodel.cpp b/src/eepp/ui/models/filesystemmodel.cpp index 6a1507e3c..de0855a9b 100644 --- a/src/eepp/ui/models/filesystemmodel.cpp +++ b/src/eepp/ui/models/filesystemmodel.cpp @@ -264,10 +264,10 @@ ModelIndex FileSystemModel::index( int row, int column, const ModelIndex& parent return createIndex( row, column, &node.mChildren[row] ); } -Drawable* FileSystemModel::iconFor( const Node& node, const ModelIndex& index ) const { +UIIcon* FileSystemModel::iconFor( const Node& node, const ModelIndex& index ) const { if ( index.column() == (Int64)treeColumn() || Column::Icon == index.column() ) { auto* scene = SceneManager::instance()->getUISceneNode(); - Drawable* d = scene->findIcon( node.getMimeType() ); + auto* d = scene->findIcon( node.getMimeType() ); if ( !d ) { if ( !node.info().isDirectory() ) { return scene->findIcon( "file" ); diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index bdec6eb7c..7fcb829e1 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -187,7 +187,7 @@ void UIFileDialog::setTheme( UITheme* Theme ) { mFile->setTheme( Theme ); mFiletype->setTheme( Theme ); - Drawable* icon = getUISceneNode()->findIcon( "go-up" ); + Drawable* icon = getUISceneNode()->findIconDrawable( "go-up", PixelDensity::dpToPxI( 16 ) ); if ( NULL != icon ) { mButtonUp->setText( "" ); diff --git a/src/eepp/ui/uiicon.cpp b/src/eepp/ui/uiicon.cpp new file mode 100644 index 000000000..22fd32564 --- /dev/null +++ b/src/eepp/ui/uiicon.cpp @@ -0,0 +1,62 @@ +#include +#include + +namespace EE { namespace UI { + +UIIcon* UIIcon::New( const std::string& name ) { + return eeNew( UIIcon, ( name ) ); +} + +UIIcon::UIIcon( const std::string& name ) : mName( name ) {} + +UIIcon::~UIIcon() {} + +const std::string& UIIcon::getName() const { + return mName; +} + +Drawable* UIIcon::getSize( const int& size ) const { + auto it = mSizes.find( size ); + if ( it != mSizes.end() ) + return it->second; + int distance = UINT32_MAX; + Drawable* closest = nullptr; + for ( auto& it : mSizes ) { + int diff = abs( it.first - size ); + if ( diff < distance ) { + distance = diff; + closest = it.second; + } + } + return closest; +} + +void UIIcon::setSize( const int& size, Drawable* drawable ) { + mSizes[size] = drawable; +} + +UIIcon* UIGlyphIcon::New( const std::string& name, FontTrueType* font, const Uint32& codePoint ) { + return eeNew( UIGlyphIcon, ( name, font, codePoint ) ); +} + +Drawable* UIGlyphIcon::getSize( const int& size ) const { + if ( !mFont ) + return nullptr; + auto it = mSizes.find( size ); + if ( it != mSizes.end() ) + return it->second; + GlyphDrawable* drawable = mFont->getGlyphDrawable( mCodePoint, size ); + const_cast( this )->setSize( size, drawable ); + return drawable; +} + +UIGlyphIcon::UIGlyphIcon( const std::string& name, FontTrueType* font, const Uint32& codePoint ) : + UIIcon( name ), mFont( font ), mCodePoint( codePoint ) { + eeASSERT( mFont ); + mFont->pushFontEventCallback( [&]( Uint32, Font::Event event, Font* ) { + if ( event == Font::Event::Unload ) + mFont = nullptr; + } ); +} + +}} // namespace EE::UI diff --git a/src/eepp/ui/uiicontheme.cpp b/src/eepp/ui/uiicontheme.cpp index d5d3eee1e..a2db5d7cc 100644 --- a/src/eepp/ui/uiicontheme.cpp +++ b/src/eepp/ui/uiicontheme.cpp @@ -7,14 +7,19 @@ UIIconTheme* UIIconTheme::New( const std::string& name ) { return eeNew( UIIconTheme, ( name ) ); } +UIIconTheme::~UIIconTheme() { + for ( auto icon : mIcons ) + eeDelete( icon.second ); +} + UIIconTheme::UIIconTheme( const std::string& name ) : mName( name ) {} -UIIconTheme* UIIconTheme::add( const std::string& name, Drawable* drawable ) { - mIcons[name] = drawable; +UIIconTheme* UIIconTheme::add( UIIcon* icon ) { + mIcons[icon->getName()] = icon; return this; } -UIIconTheme* UIIconTheme::add( const std::unordered_map& icons ) { +UIIconTheme* UIIconTheme::add( const std::unordered_map& icons ) { mIcons.insert( icons.begin(), icons.end() ); return this; } @@ -23,7 +28,7 @@ const std::string& UIIconTheme::getName() const { return mName; } -Drawable* UIIconTheme::getIcon( const std::string& name ) const { +UIIcon* UIIconTheme::getIcon( const std::string& name ) const { auto it = mIcons.find( name ); return it != mIcons.end() ? it->second : nullptr; } diff --git a/src/eepp/ui/uiiconthememanager.cpp b/src/eepp/ui/uiiconthememanager.cpp index 8c43d2266..54169839d 100644 --- a/src/eepp/ui/uiiconthememanager.cpp +++ b/src/eepp/ui/uiiconthememanager.cpp @@ -48,8 +48,8 @@ UIIconThemeManager* UIIconThemeManager::setFallbackTheme( UIIconTheme* fallbackT return this; } -Drawable* UIIconThemeManager::findIcon( const std::string& name ) { - Drawable* icon = nullptr; +UIIcon* UIIconThemeManager::findIcon( const std::string& name ) { + UIIcon* icon = nullptr; if ( mCurrentTheme ) { icon = mCurrentTheme->getIcon( name ); if ( icon ) diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index 38f8ea613..10d9fedd5 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -256,8 +257,10 @@ bool UIImage::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::Icon: { std::string val = attribute.asString(); Drawable* icon = NULL; - if ( NULL != ( icon = getUISceneNode()->findIcon( val ) ) ) { - setDrawable( icon ); + UIIcon* iconF = getUISceneNode()->findIcon( val ); + if ( iconF ) { + setDrawable( + iconF->getSize( mSize.getHeight() - mPaddingPx.Top - mPadding.Bottom ) ); } else if ( NULL != ( icon = DrawableSearcher::searchByName( val ) ) ) { setDrawable( icon ); } diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index ddf284da6..586468127 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -518,8 +518,13 @@ Uint32 UIMenu::onKeyDown( const KeyEvent& event ) { static Drawable* getIconDrawable( const std::string& name, UIIconThemeManager* iconThemeManager ) { Drawable* iconDrawable = nullptr; - if ( nullptr != iconThemeManager ) - iconDrawable = iconThemeManager->findIcon( name ); + if ( nullptr != iconThemeManager ) { + UIIcon* icon = iconThemeManager->findIcon( name ); + if ( icon ) { + // TODO: Fix size + iconDrawable = icon->getSize( PixelDensity::dpToPx( 16 ) ); + } + } if ( nullptr == iconDrawable ) iconDrawable = DrawableSearcher::searchByName( name ); return iconDrawable; diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index 3a3220728..5dba60e38 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -105,8 +105,9 @@ void UIMessageBox::setTheme( UITheme* theme ) { mButtonCancel->setTheme( theme ); if ( "Retry" != mButtonOK->getText() ) { - Drawable* okIcon = getUISceneNode()->findIcon( "ok" ); - Drawable* cancelIcon = getUISceneNode()->findIcon( "cancel" ); + Drawable* okIcon = getUISceneNode()->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ); + Drawable* cancelIcon = + getUISceneNode()->findIconDrawable( "cancel", PixelDensity::dpToPxI( 16 ) ); if ( NULL != okIcon ) { mButtonOK->setIcon( okIcon ); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index fb6c2e56c..6420e027a 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -426,9 +427,11 @@ bool UIPushButton::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::Icon: { std::string val = attribute.asString(); Drawable* icon = NULL; - - if ( NULL != mTheme && NULL != ( icon = getUISceneNode()->findIcon( val ) ) ) { - setIcon( icon ); + UIIcon* iconF = getUISceneNode()->findIcon( val ); + if ( iconF ) { + setIcon( iconF->getSize( + eemax( mSize.getHeight() - mPaddingPx.Top - mPadding.Bottom, + PixelDensity::dpToPxI( 16 ) ) ) ); } else if ( NULL != ( icon = DrawableSearcher::searchByName( val ) ) ) { setIcon( icon ); } diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 6cf19ee12..fba53db97 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -677,10 +677,17 @@ UIIconThemeManager* UISceneNode::getUIIconThemeManager() const { return mUIIconThemeManager; } -Drawable* UISceneNode::findIcon( const std::string& iconName ) { +UIIcon* UISceneNode::findIcon( const std::string& iconName ) { return getUIIconThemeManager()->findIcon( iconName ); } +Drawable* UISceneNode::findIconDrawable( const std::string& iconName, const size_t& drawableSize ) { + UIIcon* icon = findIcon( iconName ); + if ( icon ) + return icon->getSize( drawableSize ); + return nullptr; +} + bool UISceneNode::onMediaChanged() { if ( !mStyleSheet.isMediaQueryListEmpty() ) { MediaFeatures media; diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 643819787..e07c92f38 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ UITheme* UITheme::loadFromTextureAtlas( UITheme* tTheme, Graphics::TextureAtlas* auto& resources = textureAtlas->getResources(); std::string sAbbr( tTheme->getAbbr() + "_" ); + std::string sAbbrIcon( tTheme->getAbbr() + "_icon_" ); std::map skins; for ( auto& it : resources ) { @@ -75,7 +77,11 @@ UITheme* UITheme::loadFromTextureAtlas( UITheme* tTheme, Graphics::TextureAtlas* std::string name( textureRegion->getName() ); - if ( String::startsWith( name, sAbbr ) ) { + if ( String::startsWith( name, sAbbrIcon ) ) { + auto* icon = UIIcon::New( name.substr( sAbbrIcon.size() ) ); + icon->setSize( textureRegion->getPixelsSize().getWidth(), textureRegion ); + tTheme->getIconTheme()->add( icon ); + } else if ( String::startsWith( name, sAbbr ) ) { std::vector dotParts = String::split( name, '.' ); if ( dotParts.size() >= 3 && dotParts[dotParts.size() - 1] == "9" ) { @@ -168,8 +174,12 @@ UITheme* UITheme::loadFromDirectroy( UITheme* tTheme, const std::string& Path, if ( !FileSystem::isDirectory( fpath ) ) { if ( String::startsWith( name, sAbbrIcon ) ) { - tSG->add( - TextureRegion::New( TextureFactory::instance()->loadFromFile( fpath ), name ) ); + auto* drawable = + TextureRegion::New( TextureFactory::instance()->loadFromFile( fpath ), name ); + tSG->add( drawable ); + auto* icon = UIIcon::New( name.substr( sAbbrIcon.size() ) ); + icon->setSize( drawable->getPixelsSize().getWidth(), drawable ); + tTheme->getIconTheme()->add( icon ); } else if ( String::startsWith( name, sAbbr ) ) { std::vector dotParts = String::split( name, '.' ); @@ -262,9 +272,12 @@ 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::getPixelDensity() > 1.4 ? 11 : 12 ), + mIconTheme( UIIconTheme::New( name ) ) {} -UITheme::~UITheme() {} +UITheme::~UITheme() { + eeSAFE_DELETE( mIconTheme ); +} const std::string& UITheme::getName() const { return mName; @@ -295,11 +308,8 @@ void UITheme::setTextureAtlas( Graphics::TextureAtlas* SG ) { mTextureAtlas = SG; } -Drawable* UITheme::getIconByName( const std::string& name ) { - if ( NULL != mTextureAtlas ) - return mTextureAtlas->getByName( mAbbr + "_icon_" + name ); - - return NULL; +UIIcon* UITheme::getIconByName( const std::string& name ) { + return mIconTheme->getIcon( name ); } UISkin* UITheme::getSkin( const std::string& widgetName ) { @@ -322,6 +332,10 @@ void UITheme::setDefaultFontSize( const Float& defaultFontSize ) { mDefaultFontSize = defaultFontSize; } +UIIconTheme* UITheme::getIconTheme() const { + return mIconTheme; +} + Font* UITheme::getDefaultFont() const { return mDefaultFont; } diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 085d5751f..f91ea35a9 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -13,7 +13,9 @@ UITreeView* UITreeView::New() { } UITreeView::UITreeView() : - UIAbstractTableView( "treeview" ), mIndentWidth( PixelDensity::dpToPx( 12 ) ) { + UIAbstractTableView( "treeview" ), + mIndentWidth( PixelDensity::dpToPx( 12 ) ), + mExpanderIconSize( PixelDensity::dpToPxI( 12 ) ) { clipEnable(); mExpandIcon = getUISceneNode()->findIcon( "tree-expanded" ); mContractIcon = getUISceneNode()->findIcon( "tree-contracted" ); @@ -249,11 +251,14 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, UITreeViewCell* cell = widget->asType(); UIImage* image = widget->asType()->getImage(); - Float minIndent = !mExpandersAsIcons - ? eemax( mExpandIcon->getPixelsSize().getWidth(), - mContractIcon->getPixelsSize().getWidth() ) + - PixelDensity::dpToPx( image->getLayoutMargin().Right ) - : 0; + Float minIndent = + !mExpandersAsIcons + ? eemax( mExpandIcon->getSize( mExpanderIconSize )->getPixelsSize().getWidth(), + mContractIcon->getSize( mExpanderIconSize ) + ->getPixelsSize() + .getWidth() ) + + PixelDensity::dpToPx( image->getLayoutMargin().Right ) + : 0; if ( index.column() == (Int64)getModel()->treeColumn() ) cell->setIndentation( minIndent + getIndentWidth() * indentLevel ); @@ -261,11 +266,12 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, hasChilds = getModel()->rowCount( index ) > 0; if ( hasChilds ) { - Drawable* icon = getIndexMetadata( index ).open ? mExpandIcon : mContractIcon; + UIIcon* icon = getIndexMetadata( index ).open ? mExpandIcon : mContractIcon; + Drawable* drawable = icon->getSize( mExpanderIconSize ); image->setVisible( true ); - image->setPixelsSize( icon->getPixelsSize() ); - image->setDrawable( icon ); + image->setPixelsSize( drawable->getPixelsSize() ); + image->setDrawable( drawable ); if ( !mExpandersAsIcons ) { cell->setIndentation( cell->getIndentation() - image->getPixelsSize().getWidth() - @@ -286,6 +292,9 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, if ( icon.is( Variant::Type::Drawable ) && icon.asDrawable() ) { isVisible = true; cell->setIcon( icon.asDrawable() ); + } else if ( icon.is( Variant::Type::Icon ) && icon.asIcon() ) { + isVisible = true; + cell->setIcon( icon.asIcon()->getSize( mIconSize ) ); } cell->getIcon()->setVisible( isVisible ); } @@ -410,11 +419,11 @@ void UITreeView::contractAll( const ModelIndex& index ) { createOrUpdateColumns(); } -Drawable* UITreeView::getExpandIcon() const { +UIIcon* UITreeView::getExpandIcon() const { return mExpandIcon; } -void UITreeView::setExpandedIcon( Drawable* expandIcon ) { +void UITreeView::setExpandedIcon( UIIcon* expandIcon ) { if ( mExpandIcon != expandIcon ) { mExpandIcon = expandIcon; createOrUpdateColumns(); @@ -425,11 +434,11 @@ void UITreeView::setExpandedIcon( const std::string& expandIcon ) { setExpandedIcon( mUISceneNode->findIcon( expandIcon ) ); } -Drawable* UITreeView::getContractIcon() const { +UIIcon* UITreeView::getContractIcon() const { return mContractIcon; } -void UITreeView::setContractedIcon( Drawable* contractIcon ) { +void UITreeView::setContractedIcon( UIIcon* contractIcon ) { if ( mContractIcon != contractIcon ) { mContractIcon = contractIcon; createOrUpdateColumns(); @@ -466,6 +475,14 @@ Float UITreeView::getMaxColumnContentWidth( const size_t& colIndex ) { return lWidth; } +const size_t& UITreeView::getExpanderIconSize() const { + return mExpanderIconSize; +} + +void UITreeView::setExpanderIconSize( const size_t& expanderSize ) { + mExpanderIconSize = expanderSize; +} + Uint32 UITreeView::onKeyDown( const KeyEvent& event ) { if ( event.getMod() != 0 ) return UIAbstractTableView::onKeyDown( event ); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index 391697af2..635a3bd46 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -391,7 +391,7 @@ void EETest::createBaseUI() { UIPushButton* Button = UIPushButton::New(); Button->setParent( C )->setPosition( 225, 215 )->setSize( 90, 0 ); - Button->setIcon( mSceneNode->findIcon( "ok" ) ); + Button->setIcon( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); Button->setText( "Click Me" ); Button->addEventListener( Event::MouseClick, cb::Make1( this, &EETest::onButtonClick ) ); Button->setTooltipText( "Click and see what happens..." ); @@ -490,7 +490,7 @@ void EETest::createBaseUI() { Cell->setParent( genGrid->getContainer() ); TxtGfx->setVerticalAlign( UI_VALIGN_CENTER ); - TxtGfx->setDrawable( mSceneNode->findIcon( "ok" ) ); + TxtGfx->setDrawable( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); TxtBox->setText( "Test " + String::toString( i + 1 ) ); Cell->setColumn( 0, TxtBox ); @@ -514,9 +514,10 @@ void EETest::createBaseUI() { C = C->getParent()->asType(); Menu = UIPopUpMenu::New(); - Menu->add( "New", mSceneNode->findIcon( "document-new" ) ); + Menu->add( "New", mSceneNode->findIconDrawable( "document-new", PixelDensity::dpToPxI( 16 ) ) ); - Menu->add( "Open...", mSceneNode->findIcon( "document-open" ) ); + Menu->add( "Open...", + mSceneNode->findIconDrawable( "document-open", PixelDensity::dpToPxI( 16 ) ) ); Menu->addSeparator(); Menu->add( "Map Editor" ); Menu->add( "Texture Atlas Editor" ); @@ -699,7 +700,7 @@ void EETest::createNewUI() { UIImage* gfx = UIImage::New(); gfx->setPosition( 50, 140 )->setSize( 16, 16 )->setParent( container ); gfx->setBackgroundColor( 0x33333333 ); - gfx->setDrawable( mSceneNode->findIcon( "ok" ) ); + gfx->setDrawable( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); UISlider* slider = UISlider::New(); slider->setOrientation( UIOrientation::Horizontal ) @@ -733,7 +734,7 @@ void EETest::createNewUI() { UIPushButton* pushButton = UIPushButton::New(); pushButton->setPosition( 50, 560 )->setSize( 200, 0 )->setParent( container ); pushButton->setText( "PushButton" ); - pushButton->setIcon( mSceneNode->findIcon( "ok" ) ); + pushButton->setIcon( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); pushButton->addEventListener( Event::MouseClick, [&, pushButton]( const Event* event ) { if ( static_cast( event )->getFlags() & EE_BUTTON_LMASK ) createColorPicker( pushButton ); @@ -798,7 +799,7 @@ void EETest::createNewUI() { Cell->setColumn( 1, TxtGfx ); Cell->setColumn( 2, TxtInput ); - TxtGfx->setDrawable( mSceneNode->findIcon( "ok" ) ); + TxtGfx->setDrawable( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); TxtBox->setText( "Test " + String::toString( i + 1 ) ); genGrid->add( Cell ); @@ -808,11 +809,11 @@ void EETest::createNewUI() { TabWidget->setPosition( 350, 530 )->setSize( 200, 64 )->setParent( container ); TabWidget->add( "Tab 1", UIWidget::New()->setThemeSkin( "winback" ), - mSceneNode->findIcon( "ok" ) ); + mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); TabWidget->add( "Tab 2", UIWidget::New()->setThemeSkin( "winback" ), - mSceneNode->findIcon( "go-up" ) ); + mSceneNode->findIconDrawable( "go-up", PixelDensity::dpToPxI( 16 ) ) ); TabWidget->add( "Tab 3", UIWidget::New()->setThemeSkin( "winback" ), - mSceneNode->findIcon( "add" ) ); + mSceneNode->findIconDrawable( "add", PixelDensity::dpToPxI( 16 ) ) ); UIWindow* MenuCont = UIWindow::New(); MenuCont->setPosition( 350, 390 )->setSize( 200, 115 ); @@ -1289,7 +1290,7 @@ using namespace EE::Scene::Actions; void EETest::addFlyingIcon() { UIImage* Gfx = UIImage::New(); - Gfx->setDrawable( mSceneNode->findIcon( "ok" ) ); + Gfx->setDrawable( mSceneNode->findIconDrawable( "ok", PixelDensity::dpToPxI( 16 ) ) ); Gfx->setEnabled( false ); Gfx->runAction( Spawn::New( diff --git a/src/tests/ui_perf_test/ui_perf_test.cpp b/src/tests/ui_perf_test/ui_perf_test.cpp index dd82d415d..ea3f41a45 100644 --- a/src/tests/ui_perf_test/ui_perf_test.cpp +++ b/src/tests/ui_perf_test/ui_perf_test.cpp @@ -153,17 +153,17 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" ); FontTrueType* iconFont = FontTrueType::New( "icon", "assets/fonts/remixicon.ttf" ); UIIconTheme* iconTheme = UIIconTheme::New( "remixicon" ); - auto addIcon = [iconTheme, iconFont]( const std::string& name, const Uint32& codePoint, - const Uint32& size ) -> Drawable* { - Drawable* ic = iconFont->getGlyphDrawable( codePoint, size ); - iconTheme->add( name, ic ); - return ic; + auto addIcon = [iconTheme, iconFont]( const std::string& name, + const Uint32& codePoint ) -> UIIcon* { + auto* icon = UIGlyphIcon::New( name, iconFont, codePoint ); + iconTheme->add( icon ); + return icon; }; - addIcon( "folder", 0xed6a, 16 ); - addIcon( "folder-open", 0xed70, 16 ); - addIcon( "tree-expanded", 0xea50, 24 ); - addIcon( "tree-contracted", 0xea54, 24 ); - addIcon( "file", 0xecc3, 16 ); + addIcon( "folder", 0xed6a ); + addIcon( "folder-open", 0xed70 ); + addIcon( "tree-expanded", 0xea50 ); + addIcon( "tree-contracted", 0xea54 ); + addIcon( "file", 0xecc3 ); UISceneNode* uiSceneNode = UISceneNode::New(); SceneManager::instance()->add( uiSceneNode ); uiSceneNode->getUIThemeManager()->setDefaultFont( font ); @@ -194,6 +194,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { auto model = FileSystemModel::New( "." ); // std::make_shared(); UITreeView* view = UITreeView::New(); // UITableView* view = UITableView::New(); + view->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); view->setId( "treeview" ); /*view->setExpandedIcon( open ); view->setContractedIcon( closed );*/ @@ -210,6 +211,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { widgetTree->setParent( uiWin ); widgetTree->setHeadersVisible( false ); widgetTree->setAutoExpandOnSingleColumn( true ); + widgetTree->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); widgetTree->setModel( WidgetTreeModel::New( uiSceneNode ) ); /* ListBox test */ /* diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index 7e2dde217..57ac9e357 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -719,6 +719,7 @@ void App::initGlobalSearchBar() { mGlobalSearchTree = UITreeView::New(); mGlobalSearchTree->setId( "search_tree" ); mGlobalSearchTree->setParent( mUISceneNode->getRoot() ); + mGlobalSearchTree->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); mGlobalSearchTree->setHeadersVisible( false ); mGlobalSearchTree->setVisible( false ); mGlobalSearchTree->setColumnsHidden( @@ -1173,7 +1174,10 @@ void App::setFocusEditorOnClose( UIMessageBox* msgBox ) { } Drawable* App::findIcon( const std::string& name ) { - return mUISceneNode->findIcon( name ); + UIIcon* icon = mUISceneNode->findIcon( name ); + if ( icon ) + return icon->getSize( mMenuIconSize ); + return nullptr; } UIMenu* App::createEditMenu() { @@ -1798,6 +1802,8 @@ void App::initProjectTreeView( const std::string& path ) { FileSystemModel::Inode, FileSystemModel::Owner, FileSystemModel::SymlinkTarget, FileSystemModel::Permissions, FileSystemModel::ModificationTime, FileSystemModel::Path}, true ); + mProjectTreeView->setIconSize( mMenuIconSize ); + mProjectTreeView->setExpanderIconSize( mMenuIconSize ); mProjectTreeView->setExpandedIcon( "folder-open" ); mProjectTreeView->setContractedIcon( "folder" ); mProjectTreeView->setHeadersVisible( false ); @@ -2077,49 +2083,53 @@ void App::init( const std::string& file, const Float& pidelDensity ) { )xml"; UIIconTheme* iconTheme = UIIconTheme::New( "remixicon" ); - Float menuIconSize = mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ); - Float buttonIconSize = - StyleSheetLength::fromString( "16dp" ).asPixels( 0, Sizef(), mDisplayDPI ); - auto addIcon = [iconTheme, iconFont]( const std::string& name, const Uint32& codePoint, - const Uint32& size ) { - iconTheme->add( name, iconFont->getGlyphDrawable( codePoint, size ) ); + mMenuIconSize = mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI ); + /*Float buttonIconSize = + StyleSheetLength::fromString( "16dp" ).asPixels( 0, Sizef(), mDisplayDPI );*/ + auto addIcon = [iconTheme, iconFont]( const std::string& name, + const Uint32& codePoint ) -> UIIcon* { + auto* icon = UIGlyphIcon::New( name, iconFont, codePoint ); + iconTheme->add( icon ); + return icon; }; - addIcon( "document-new", 0xecc3, menuIconSize ); - addIcon( "document-open", 0xed70, menuIconSize ); - addIcon( "document-save", 0xf0b3, menuIconSize ); - addIcon( "document-save-as", 0xf0b3, menuIconSize ); - addIcon( "document-close", 0xeb99, menuIconSize ); - addIcon( "quit", 0xeb97, menuIconSize ); - addIcon( "undo", 0xea58, menuIconSize ); - addIcon( "redo", 0xea5a, menuIconSize ); - addIcon( "redo", 0xea5a, menuIconSize ); - addIcon( "cut", 0xf0c1, menuIconSize ); - addIcon( "copy", 0xecd5, menuIconSize ); - addIcon( "paste", 0xeb91, menuIconSize ); - addIcon( "split-horizontal", 0xf17a, menuIconSize ); - addIcon( "split-vertical", 0xf17b, menuIconSize ); - addIcon( "find-replace", 0xed2b, menuIconSize ); - addIcon( "folder", 0xed54, menuIconSize ); - addIcon( "folder-open", 0xed70, menuIconSize ); - addIcon( "folder-add", 0xed5a, menuIconSize ); - addIcon( "file", 0xecc3, menuIconSize ); - addIcon( "file-code", 0xecd1, menuIconSize ); - addIcon( "file-edit", 0xecdb, menuIconSize ); - addIcon( "font-size", 0xed8d, menuIconSize ); - addIcon( "zoom-in", 0xf2db, menuIconSize ); - addIcon( "zoom-out", 0xf2dd, menuIconSize ); - addIcon( "zoom-reset", 0xeb47, menuIconSize ); - addIcon( "fullscreen", 0xed9c, menuIconSize ); - addIcon( "keybindings", 0xee75, menuIconSize ); - addIcon( "go-up", 0xea78, buttonIconSize ); - addIcon( "ok", 0xeb7a, buttonIconSize ); - addIcon( "cancel", 0xeb98, buttonIconSize ); - addIcon( "color-picker", 0xf13d, buttonIconSize ); - addIcon( "pixel-density", 0xed8c, buttonIconSize ); - addIcon( "go-to-line", 0xf1f8, buttonIconSize ); - addIcon( "tree-expanded", 0xea50, PixelDensity::dpToPx( 24 ) ); - addIcon( "tree-contracted", 0xea54, PixelDensity::dpToPx( 24 ) ); - addIcon( "search", 0xf0d1, menuIconSize ); + addIcon( "document-new", 0xecc3 ); + addIcon( "document-open", 0xed70 ); + addIcon( "document-save", 0xf0b3 ); + addIcon( "document-save-as", 0xf0b3 ); + addIcon( "document-close", 0xeb99 ); + addIcon( "quit", 0xeb97 ); + addIcon( "undo", 0xea58 ); + addIcon( "redo", 0xea5a ); + addIcon( "redo", 0xea5a ); + addIcon( "cut", 0xf0c1 ); + addIcon( "copy", 0xecd5 ); + addIcon( "paste", 0xeb91 ); + addIcon( "split-horizontal", 0xf17a ); + addIcon( "split-vertical", 0xf17b ); + addIcon( "find-replace", 0xed2b ); + addIcon( "folder", 0xed54 ); + addIcon( "folder-open", 0xed70 ); + addIcon( "folder-add", 0xed5a ); + addIcon( "file", 0xecc3 ); + addIcon( "file-code", 0xecd1 ); + addIcon( "file-edit", 0xecdb ); + addIcon( "font-size", 0xed8d ); + addIcon( "zoom-in", 0xf2db ); + addIcon( "zoom-out", 0xf2dd ); + addIcon( "zoom-reset", 0xeb47 ); + addIcon( "fullscreen", 0xed9c ); + addIcon( "keybindings", 0xee75 ); + addIcon( "tree-expanded", 0xea50 ); + addIcon( "tree-contracted", 0xea54 ); + addIcon( "search", 0xf0d1 ); + + addIcon( "go-up", 0xea78 ); + addIcon( "ok", 0xeb7a ); + addIcon( "cancel", 0xeb98 ); + addIcon( "color-picker", 0xf13d ); + addIcon( "pixel-density", 0xed8c ); + addIcon( "go-to-line", 0xf1f8 ); + mUISceneNode->getUIIconThemeManager()->setCurrentTheme( iconTheme ); UIWidgetCreator::registerWidget( "searchbar", [] { return UISearchBar::New(); } ); diff --git a/src/tools/codeeditor/codeeditor.hpp b/src/tools/codeeditor/codeeditor.hpp index a89f9a7b5..34f4b9004 100644 --- a/src/tools/codeeditor/codeeditor.hpp +++ b/src/tools/codeeditor/codeeditor.hpp @@ -252,6 +252,7 @@ class App : public UICodeEditorSplitter::Client { UITextInput* mLocateInput{nullptr}; UITreeView* mGlobalSearchTree{nullptr}; UITextInput* mGlobalSearchInput; + size_t mMenuIconSize; bool mDirTreeReady{false}; void initLocateBar(); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index f52fc23e2..a0dc75ddd 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -891,27 +891,32 @@ void createAppMenu() { uiMenuBar = UIMenuBar::New(); + size_t iconSize = PixelDensity::dpToPxI( 16 ); UIPopUpMenu* uiPopMenu = UIPopUpMenu::New(); - uiPopMenu->add( "Open project...", appUiSceneNode->findIcon( "document-open" ) ); + uiPopMenu->add( "Open project...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Open layout...", appUiSceneNode->findIcon( "document-open" ) ); + uiPopMenu->add( "Open layout...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); uiPopMenu->addSeparator(); uiPopMenu->addSubMenu( "Recent files", NULL, UIPopUpMenu::New() ); uiPopMenu->addSubMenu( "Recent projects", NULL, UIPopUpMenu::New() ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Close", appUiSceneNode->findIcon( "document-close" ) ); + uiPopMenu->add( "Close", appUiSceneNode->findIconDrawable( "document-close", iconSize ) ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Quit", appUiSceneNode->findIcon( "quit" ) ); + uiPopMenu->add( "Quit", appUiSceneNode->findIconDrawable( "quit", iconSize ) ); uiMenuBar->addMenuButton( "File", uiPopMenu ); uiPopMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) ); UIPopUpMenu* uiResourceMenu = UIPopUpMenu::New(); - uiResourceMenu->add( "Load images from path...", appUiSceneNode->findIcon( "document-open" ) ); + uiResourceMenu->add( "Load images from path...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); uiResourceMenu->addSeparator(); - uiResourceMenu->add( "Load fonts from path...", appUiSceneNode->findIcon( "document-open" ) ); + uiResourceMenu->add( "Load fonts from path...", + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); uiResourceMenu->addSeparator(); uiResourceMenu->add( "Load style sheet from path...", - appUiSceneNode->findIcon( "document-open" ) ); + appUiSceneNode->findIconDrawable( "document-open", iconSize ) ); uiMenuBar->addMenuButton( "Resources", uiResourceMenu ); uiResourceMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) );