From 2a500e56b9a16bef0ec74db3101a0e64324506f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 19 Jun 2020 04:58:00 -0300 Subject: [PATCH] Implemented UIIconTeme and UIIconThemeManager, now the icon searches are using these new classes. --- TODO.md | 4 - bin/assets/ui/breeze.css | 3 +- include/eepp/graphics/font.hpp | 3 +- include/eepp/graphics/fontbmfont.hpp | 4 +- include/eepp/graphics/fontsprite.hpp | 4 +- include/eepp/graphics/fonttruetype.hpp | 4 +- include/eepp/ui.hpp | 1 + include/eepp/ui/uiicontheme.hpp | 32 +++++++ include/eepp/ui/uiiconthememanager.hpp | 48 ++++++++++ include/eepp/ui/uimessagebox.hpp | 10 +- include/eepp/ui/uiscenenode.hpp | 6 ++ projects/linux/ee.files | 4 + projects/linux/ee.includes | 2 + src/eepp/maps/mapeditor/mapeditor.cpp | 21 ++-- .../maps/mapeditor/maplayerproperties.cpp | 12 ++- .../maps/mapeditor/mapobjectproperties.cpp | 11 ++- src/eepp/maps/mapeditor/tilemapproperties.cpp | 11 ++- src/eepp/maps/mapeditor/uigotypenew.cpp | 7 +- src/eepp/maps/mapeditor/uimaplayernew.cpp | 7 +- src/eepp/maps/mapeditor/uimapnew.cpp | 7 +- src/eepp/ui/uifiledialog.cpp | 7 +- src/eepp/ui/uiicontheme.cpp | 31 ++++++ src/eepp/ui/uiiconthememanager.cpp | 96 +++++++++++++++++++ src/eepp/ui/uiimage.cpp | 4 +- src/eepp/ui/uimenu.cpp | 13 ++- src/eepp/ui/uimessagebox.cpp | 31 +++--- src/eepp/ui/uipushbutton.cpp | 2 +- src/eepp/ui/uiscenenode.cpp | 13 ++- src/tests/test_all/test.cpp | 48 +++++----- src/tests/test_all/test.hpp | 1 + src/tools/codeeditor/codeeditor.cpp | 33 +++++-- src/tools/uieditor/uieditor.cpp | 15 +-- 32 files changed, 377 insertions(+), 118 deletions(-) create mode 100644 include/eepp/ui/uiicontheme.hpp create mode 100644 include/eepp/ui/uiiconthememanager.hpp create mode 100644 src/eepp/ui/uiicontheme.cpp create mode 100644 src/eepp/ui/uiiconthememanager.cpp diff --git a/TODO.md b/TODO.md index 7ac6a0724..3216e1843 100644 --- a/TODO.md +++ b/TODO.md @@ -1,10 +1,6 @@ # TODO - Short and mid term plans. -## UIIconTheme and UIIconThemeManager - -Implement icon themes separated from the `UITheme` and customizable from a CSS file. - ## UICodeEditor * Add show white spaces. diff --git a/bin/assets/ui/breeze.css b/bin/assets/ui/breeze.css index e4eed3fce..870cffb65 100644 --- a/bin/assets/ui/breeze.css +++ b/bin/assets/ui/breeze.css @@ -58,7 +58,8 @@ TextInput, TextInputPassword, TextView, Tooltip, -MenuBar::button { +MenuBar::button, +Window::title { color: var(--font); font-size: 11dp; } diff --git a/include/eepp/graphics/font.hpp b/include/eepp/graphics/font.hpp index 912c4cd42..bef666ee0 100644 --- a/include/eepp/graphics/font.hpp +++ b/include/eepp/graphics/font.hpp @@ -77,7 +77,8 @@ class EE_API Font { /** @return The glyph drawable that represents the glyph in a texture. The glyph drawable * allocation is managed by the font. */ virtual GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, - bool bold, Float outlineThickness = 0 ) const = 0; + bool bold = false, + Float outlineThickness = 0 ) const = 0; virtual Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const = 0; diff --git a/include/eepp/graphics/fontbmfont.hpp b/include/eepp/graphics/fontbmfont.hpp index a2b6b056b..09c9cdca6 100644 --- a/include/eepp/graphics/fontbmfont.hpp +++ b/include/eepp/graphics/fontbmfont.hpp @@ -35,8 +35,8 @@ class EE_API FontBMFont : public Font { const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const; - GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness = 0 ) const; + GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold = false, Float outlineThickness = 0 ) const; Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const; diff --git a/include/eepp/graphics/fontsprite.hpp b/include/eepp/graphics/fontsprite.hpp index 3cea08627..50f3042d8 100644 --- a/include/eepp/graphics/fontsprite.hpp +++ b/include/eepp/graphics/fontsprite.hpp @@ -39,8 +39,8 @@ class EE_API FontSprite : public Font { const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const; - GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness = 0 ) const; + GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold = false, Float outlineThickness = 0 ) const; Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const; diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 19036134f..0b9503102 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -33,8 +33,8 @@ class EE_API FontTrueType : public Font { const Glyph& getGlyph( Uint32 codePoint, unsigned int characterSize, bool bold, Float outlineThickness = 0 ) const; - GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, bool bold, - Float outlineThickness = 0 ) const; + GlyphDrawable* getGlyphDrawable( Uint32 codePoint, unsigned int characterSize, + bool bold = false, Float outlineThickness = 0 ) const; Float getKerning( Uint32 first, Uint32 second, unsigned int characterSize ) const; diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index 9314bf741..002b108fd 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/include/eepp/ui/uiicontheme.hpp b/include/eepp/ui/uiicontheme.hpp new file mode 100644 index 000000000..d589ce8b9 --- /dev/null +++ b/include/eepp/ui/uiicontheme.hpp @@ -0,0 +1,32 @@ +#ifndef EE_UI_UIICONTHEME_HPP +#define EE_UI_UIICONTHEME_HPP + +#include +#include + +using namespace EE::Graphics; + +namespace EE { namespace UI { + +class EE_API UIIconTheme { + public: + static UIIconTheme* New( const std::string& name ); + + UIIconTheme* add( const std::string& name, Drawable* drawable ); + + UIIconTheme* add( const std::unordered_map& icons ); + + const std::string& getName() const; + + Drawable* getIcon( const std::string& name ) const; + + protected: + std::string mName; + std::unordered_map mIcons; + + UIIconTheme( const std::string& name ); +}; + +}} // namespace EE::UI + +#endif // EE_UI_UIICONTHEME_HPP diff --git a/include/eepp/ui/uiiconthememanager.hpp b/include/eepp/ui/uiiconthememanager.hpp new file mode 100644 index 000000000..f328ebb7f --- /dev/null +++ b/include/eepp/ui/uiiconthememanager.hpp @@ -0,0 +1,48 @@ +#ifndef EE_UI_UIICONTHEMEMANAGER_HPP +#define EE_UI_UIICONTHEMEMANAGER_HPP + +#include +#include + +namespace EE { namespace UI { + +class UIThemeManager; + +class EE_API UIIconThemeManager { + public: + static UIIconThemeManager* New(); + + ~UIIconThemeManager(); + + UIIconThemeManager* add( UIIconTheme* iconTheme ); + + UIIconTheme* getCurrentTheme() const; + + UIIconThemeManager* setCurrentTheme( UIIconTheme* currentTheme ); + + UIIconTheme* getFallbackTheme() const; + + UIIconThemeManager* setFallbackTheme( UIIconTheme* fallbackTheme ); + + Drawable* findIcon( const std::string& name ); + + UIThemeManager* getFallbackThemeManager() const; + + UIIconThemeManager* setFallbackThemeManager( UIThemeManager* fallbackThemeManager ); + + void remove( UIIconTheme* iconTheme ); + + protected: + std::vector mIconThemes; + UIIconTheme* mCurrentTheme{nullptr}; + UIIconTheme* mFallbackTheme{nullptr}; + UIThemeManager* mFallbackThemeManager{nullptr}; + + UIIconThemeManager(); + + bool isPresent( UIIconTheme* iconTheme ); +}; + +}} // namespace EE::UI + +#endif // EE_UI_UIICONTHEMEMANAGER_HPP diff --git a/include/eepp/ui/uimessagebox.hpp b/include/eepp/ui/uimessagebox.hpp index 8a8e59d18..e165614b8 100644 --- a/include/eepp/ui/uimessagebox.hpp +++ b/include/eepp/ui/uimessagebox.hpp @@ -26,7 +26,7 @@ class EE_API UIMessageBox : public UIWindow { virtual Uint32 onMessage( const NodeMessage* Msg ); - virtual void setTheme( UITheme* Theme ); + virtual void setTheme( UITheme* theme ); UITextView* getTextBox() const; @@ -36,9 +36,9 @@ class EE_API UIMessageBox : public UIWindow { virtual bool show(); - const Uint32& getCloseWithKey() const; + const KeyBindings::Shortcut& getCloseWithKey() const; - void setCloseWithKey( const Uint32& closeWithKey ); + void setCloseWithKey( const KeyBindings::Shortcut& closeWithKey ); UITextInput* getTextInput() const; @@ -48,12 +48,12 @@ class EE_API UIMessageBox : public UIWindow { UIPushButton* mButtonOK; UIPushButton* mButtonCancel; UITextInput* mTextInput; - Uint32 mCloseWithKey; + KeyBindings::Shortcut mCloseWithKey; UIWidget* mLayoutCont; virtual void onWindowReady(); - virtual Uint32 onKeyUp( const KeyEvent& Event ); + virtual Uint32 onKeyUp( const KeyEvent& event ); }; }} // namespace EE::UI diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index bb20a4248..b0f8079d3 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -14,6 +14,7 @@ class Font; namespace EE { namespace UI { class UIThemeManager; +class UIIconThemeManager; class UIWidget; class UIWindow; class UIWidget; @@ -104,6 +105,10 @@ class EE_API UISceneNode : public SceneNode { const bool& isUpdatingLayouts() const; + UIIconThemeManager* getUIIconThemeManager() const; + + Drawable* findIcon( const std::string& iconName ); + protected: friend class EE::UI::UIWindow; friend class EE::UI::UIWidget; @@ -117,6 +122,7 @@ class EE_API UISceneNode : public SceneNode { bool mVerbose; bool mUpdatingLayouts; UIThemeManager* mUIThemeManager; + UIIconThemeManager* mUIIconThemeManager; std::vector mFontFaces; UIKeyboardShortcuts mKbShortcuts; std::unordered_set mDirtyStyle; diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 3f833599c..44c7812dd 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -342,6 +342,8 @@ ../../include/eepp/ui/uifontstyleconfig.hpp ../../include/eepp/ui/uigridlayout.hpp ../../include/eepp/ui/uihelper.hpp +../../include/eepp/ui/uiicontheme.hpp +../../include/eepp/ui/uiiconthememanager.hpp ../../include/eepp/ui/uiimage.hpp ../../include/eepp/ui/uiitemcontainer.hpp ../../include/eepp/ui/uilayout.hpp @@ -794,6 +796,8 @@ ../../src/eepp/ui/uieventdispatcher.cpp ../../src/eepp/ui/uifiledialog.cpp ../../src/eepp/ui/uigridlayout.cpp +../../src/eepp/ui/uiicontheme.cpp +../../src/eepp/ui/uiiconthememanager.cpp ../../src/eepp/ui/uiimage.cpp ../../src/eepp/ui/uilayout.cpp ../../src/eepp/ui/uilinearlayout.cpp diff --git a/projects/linux/ee.includes b/projects/linux/ee.includes index 20628943b..bbcd0ea96 100644 --- a/projects/linux/ee.includes +++ b/projects/linux/ee.includes @@ -9,3 +9,5 @@ ../../docs/articles ../../include/eepp/ui/doc ../../src/eepp/ui/doc +../../include/eepp/ui +../../src/eepp/ui diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 0ef4924be..119242d5d 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -117,16 +117,17 @@ void MapEditor::createMenuBar() { mTileBox->updateAnchorsDistances(); UIPopUpMenu* PU1 = UIPopUpMenu::New(); + PU1->setParent( mUIContainer ); - PU1->add( "New...", mTheme->getIconByName( "document-new" ) ); - PU1->add( "Open...", mTheme->getIconByName( "document-open" ) ); + PU1->add( "New...", PU1->getUISceneNode()->findIcon( "document-new" ) ); + PU1->add( "Open...", PU1->getUISceneNode()->findIcon( "document-open" ) ); PU1->addSeparator(); - PU1->add( "Save", mTheme->getIconByName( "document-save" ) ); - PU1->add( "Save As...", mTheme->getIconByName( "document-save-as" ) ); + PU1->add( "Save", PU1->getUISceneNode()->findIcon( "document-save" ) ); + PU1->add( "Save As...", PU1->getUISceneNode()->findIcon( "document-save-as" ) ); PU1->addSeparator(); - PU1->add( "Close", mTheme->getIconByName( "document-close" ) ); + PU1->add( "Close", PU1->getUISceneNode()->findIcon( "document-close" ) ); PU1->addSeparator(); - PU1->add( "Quit", mTheme->getIconByName( "quit" ) ); + PU1->add( "Quit", PU1->getUISceneNode()->findIcon( "quit" ) ); PU1->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::fileMenuClick ) ); MenuBar->addMenuButton( "File", PU1 ); @@ -142,11 +143,11 @@ void MapEditor::createMenuBar() { PU3->addSeparator(); addShortcut( KEY_KP_PLUS, KEYMOD_CTRL, - PU3->add( "Zoom In", mTheme->getIconByName( "zoom-in" ) ) ); + PU3->add( "Zoom In", PU3->getUISceneNode()->findIcon( "zoom-in" ) ) ); addShortcut( KEY_KP_MINUS, KEYMOD_CTRL, - PU3->add( "Zoom Out", mTheme->getIconByName( "zoom-out" ) ) ); + PU3->add( "Zoom Out", PU3->getUISceneNode()->findIcon( "zoom-out" ) ) ); addShortcut( KEY_0, KEYMOD_CTRL, - PU3->add( "Normal Size", mTheme->getIconByName( "zoom-original" ) ) ); + PU3->add( "Normal Size", PU3->getUISceneNode()->findIcon( "zoom-original" ) ) ); PU3->addSeparator(); PU3->addEventListener( Event::OnItemClicked, cb::Make1( this, &MapEditor::viewMenuClick ) ); @@ -304,7 +305,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { ->setSize( 24, mGOTypeList->getSize().getHeight() ) ->setPosition( mGOTypeList->getPosition().x + mGOTypeList->getSize().getWidth() + 2, mGOTypeList->getPosition().y ); - mBtnGOTypeAdd->setIcon( mTheme->getIconByName( "add" ) ) + mBtnGOTypeAdd->setIcon( mBtnGOTypeAdd->getUISceneNode()->findIcon( "add" ) ) ->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 db8e978e5..6aab2b2ed 100644 --- a/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -15,7 +15,9 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : if ( SceneManager::instance()->getUISceneNode() == NULL ) return; - mUITheme = SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultTheme(); + UISceneNode* sceneNode = SceneManager::instance()->getUISceneNode(); + + mUITheme = sceneNode->getUIThemeManager()->getDefaultTheme(); if ( NULL == mUITheme ) return; @@ -65,7 +67,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( mUITheme->getIconByName( "ok" ) ); + OKButton->setIcon( sceneNode->findIcon( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -79,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( mUITheme->getIconByName( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapLayerProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -102,7 +104,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : UIPushButton* AddButton = UIPushButton::New(); AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - AddButton->setIcon( mUITheme->getIconByName( "add" ) ); + AddButton->setIcon( sceneNode->findIcon( "add" ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapLayerProperties::onAddCellClick ) ); @@ -114,7 +116,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : UIPushButton* RemoveButton = UIPushButton::New(); RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - RemoveButton->setIcon( mUITheme->getIconByName( "remove" ) ); + RemoveButton->setIcon( sceneNode->findIcon( "remove" ) ); 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 328c3a569..1e2628bdb 100644 --- a/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -31,7 +31,8 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : if ( SceneManager::instance()->getUISceneNode() == NULL ) return; - mUITheme = SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultTheme(); + UISceneNode* sceneNode = SceneManager::instance()->getUISceneNode(); + mUITheme = sceneNode->getUIThemeManager()->getDefaultTheme(); if ( NULL == mUITheme ) return; @@ -84,7 +85,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); - OKButton->setIcon( mUITheme->getIconByName( "ok" ) ); + OKButton->setIcon( sceneNode->findIcon( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -98,7 +99,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapObjectProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -121,7 +122,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : UIPushButton* AddButton = UIPushButton::New(); AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - AddButton->setIcon( mUITheme->getIconByName( "add" ) ); + AddButton->setIcon( sceneNode->findIcon( "add" ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, cb::Make1( this, &MapObjectProperties::onAddCellClick ) ); @@ -133,7 +134,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : UIPushButton* RemoveButton = UIPushButton::New(); RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); - RemoveButton->setIcon( mUITheme->getIconByName( "remove" ) ); + RemoveButton->setIcon( sceneNode->findIcon( "remove" ) ); 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 2aa2b03b6..f29bd10cc 100644 --- a/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -31,7 +31,8 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : if ( SceneManager::instance()->getUISceneNode() == NULL ) return; - mUITheme = SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultTheme(); + UISceneNode* sceneNode = SceneManager::instance()->getUISceneNode(); + mUITheme = sceneNode->getUIThemeManager()->getDefaultTheme(); if ( NULL == mUITheme ) return; @@ -135,7 +136,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( mUITheme->getIconByName( "ok" ) ); + OKButton->setIcon( sceneNode->findIcon( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -149,7 +150,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &TileMapProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -172,7 +173,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : UIPushButton* AddButton = UIPushButton::New(); AddButton->setSize( 24, 0 )->setParent( mUIWindow->getContainer() )->setPosition( Pos ); - AddButton->setIcon( mUITheme->getIconByName( "add" ) ); + AddButton->setIcon( sceneNode->findIcon( "add" ) ); AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( Event::MouseClick, cb::Make1( this, &TileMapProperties::onAddCellClick ) ); @@ -184,7 +185,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : UIPushButton* RemoveButton = UIPushButton::New(); RemoveButton->setSize( 24, 0 )->setParent( mUIWindow->getContainer() )->setPosition( Pos ); - RemoveButton->setIcon( mUITheme->getIconByName( "remove" ) ); + RemoveButton->setIcon( sceneNode->findIcon( "remove" ) ); 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 7aa0e44b8..600cd310c 100644 --- a/src/eepp/maps/mapeditor/uigotypenew.cpp +++ b/src/eepp/maps/mapeditor/uigotypenew.cpp @@ -10,7 +10,8 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : if ( SceneManager::instance()->getUISceneNode() == NULL ) return; - mUITheme = SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultTheme(); + UISceneNode* sceneNode = SceneManager::instance()->getUISceneNode(); + mUITheme = sceneNode->getUIThemeManager()->getDefaultTheme(); if ( NULL == mUITheme ) return; @@ -41,7 +42,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : UIPushButton* OKButton = UIPushButton::New(); OKButton->setSize( 80, 0 )->setParent( mUIWindow->getContainer() ); - OKButton->setIcon( mUITheme->getIconByName( "add" ) ); + OKButton->setIcon( sceneNode->findIcon( "add" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -55,7 +56,7 @@ UIGOTypeNew::UIGOTypeNew( std::function Cb ) : ->setSize( OKButton->getSize() ) ->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); - CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); 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 e6d2f7419..26fa9194f 100644 --- a/src/eepp/maps/mapeditor/uimaplayernew.cpp +++ b/src/eepp/maps/mapeditor/uimaplayernew.cpp @@ -15,7 +15,8 @@ UIMapLayerNew::UIMapLayerNew( UIMap* Map, EE_LAYER_TYPE Type, NewLayerCb newLaye if ( SceneManager::instance()->getUISceneNode() == NULL ) return; - mTheme = SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultTheme(); + UISceneNode* sceneNode = SceneManager::instance()->getUISceneNode(); + mTheme = sceneNode->getUIThemeManager()->getDefaultTheme(); if ( NULL == mTheme ) return; @@ -51,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( mTheme->getIconByName( "add" ) ); + OKButton->setIcon( sceneNode->findIcon( "add" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -66,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( mTheme->getIconByName( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); 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 56b049f47..23a5ef5ce 100644 --- a/src/eepp/maps/mapeditor/uimapnew.cpp +++ b/src/eepp/maps/mapeditor/uimapnew.cpp @@ -30,7 +30,8 @@ UIMapNew::UIMapNew( UIMap* Map, std::function NewMapCb, bool ResizeMap ) if ( SceneManager::instance()->getUISceneNode() == NULL ) return; - mTheme = SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultTheme(); + UISceneNode* sceneNode = SceneManager::instance()->getUISceneNode(); + mTheme = sceneNode->getUIThemeManager()->getDefaultTheme(); if ( NULL == mTheme ) return; @@ -280,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( mTheme->getIconByName( "ok" ) ); + OKButton->setIcon( sceneNode->findIcon( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); @@ -292,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( mTheme->getIconByName( "cancel" ) ); + CancelButton->setIcon( sceneNode->findIcon( "cancel" ) ); CancelButton->addEventListener( Event::MouseClick, cb::Make1( this, &UIMapNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index 3288e435c..0b5a46f57 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -77,6 +77,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, std::string defaultFilePattern, mButtonUp = UIPushButton::New(); mButtonUp->setText( "Up" ) + ->setLayoutMarginLeft( 4 ) ->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::MatchParent ) ->setParent( hLayout ); @@ -182,11 +183,11 @@ void UIFileDialog::setTheme( UITheme* Theme ) { mFile->setTheme( Theme ); mFiletype->setTheme( Theme ); - Drawable* Icon = Theme->getIconByName( "go-up" ); + Drawable* icon = getUISceneNode()->findIcon( "go-up" ); - if ( NULL != Icon ) { + if ( NULL != icon ) { mButtonUp->setText( "" ); - mButtonUp->setIcon( Icon ); + mButtonUp->setIcon( icon ); } onThemeLoaded(); diff --git a/src/eepp/ui/uiicontheme.cpp b/src/eepp/ui/uiicontheme.cpp new file mode 100644 index 000000000..d5d3eee1e --- /dev/null +++ b/src/eepp/ui/uiicontheme.cpp @@ -0,0 +1,31 @@ +#include +#include + +namespace EE { namespace UI { + +UIIconTheme* UIIconTheme::New( const std::string& name ) { + return eeNew( UIIconTheme, ( name ) ); +} + +UIIconTheme::UIIconTheme( const std::string& name ) : mName( name ) {} + +UIIconTheme* UIIconTheme::add( const std::string& name, Drawable* drawable ) { + mIcons[name] = drawable; + return this; +} + +UIIconTheme* UIIconTheme::add( const std::unordered_map& icons ) { + mIcons.insert( icons.begin(), icons.end() ); + return this; +} + +const std::string& UIIconTheme::getName() const { + return mName; +} + +Drawable* UIIconTheme::getIcon( const std::string& name ) const { + auto it = mIcons.find( name ); + return it != mIcons.end() ? it->second : nullptr; +} + +}} // namespace EE::UI diff --git a/src/eepp/ui/uiiconthememanager.cpp b/src/eepp/ui/uiiconthememanager.cpp new file mode 100644 index 000000000..8c43d2266 --- /dev/null +++ b/src/eepp/ui/uiiconthememanager.cpp @@ -0,0 +1,96 @@ +#include +#include +#include + +namespace EE { namespace UI { + +UIIconThemeManager* UIIconThemeManager::New() { + return eeNew( UIIconThemeManager, () ); +} + +UIIconThemeManager::~UIIconThemeManager() { + for ( UIIconTheme* theme : mIconThemes ) + eeDelete( theme ); +} + +UIIconThemeManager::UIIconThemeManager() {} + +UIIconThemeManager* UIIconThemeManager::add( UIIconTheme* iconTheme ) { + if ( !isPresent( iconTheme ) ) { + mIconThemes.push_back( iconTheme ); + } + return this; +} + +UIIconTheme* UIIconThemeManager::getCurrentTheme() const { + return mCurrentTheme; +} + +UIIconThemeManager* UIIconThemeManager::setCurrentTheme( UIIconTheme* currentTheme ) { + if ( currentTheme != mCurrentTheme && currentTheme != mFallbackTheme ) { + if ( !isPresent( currentTheme ) ) + add( currentTheme ); + mCurrentTheme = currentTheme; + } + return this; +} + +UIIconTheme* UIIconThemeManager::getFallbackTheme() const { + return mFallbackTheme; +} + +UIIconThemeManager* UIIconThemeManager::setFallbackTheme( UIIconTheme* fallbackTheme ) { + if ( fallbackTheme != mFallbackTheme && fallbackTheme != mCurrentTheme ) { + if ( !isPresent( fallbackTheme ) ) + add( fallbackTheme ); + mFallbackTheme = fallbackTheme; + } + return this; +} + +Drawable* UIIconThemeManager::findIcon( const std::string& name ) { + Drawable* icon = nullptr; + if ( mCurrentTheme ) { + icon = mCurrentTheme->getIcon( name ); + if ( icon ) + return icon; + } + if ( mFallbackTheme ) { + icon = mFallbackTheme->getIcon( name ); + if ( icon ) + return icon; + } + if ( mFallbackThemeManager && mFallbackThemeManager->getDefaultTheme() ) { + return mFallbackThemeManager->getDefaultTheme()->getIconByName( name ); + } + return nullptr; +} + +UIThemeManager* UIIconThemeManager::getFallbackThemeManager() const { + return mFallbackThemeManager; +} + +UIIconThemeManager* +UIIconThemeManager::setFallbackThemeManager( UIThemeManager* fallbackThemeManager ) { + mFallbackThemeManager = fallbackThemeManager; + return this; +} + +void UIIconThemeManager::remove( UIIconTheme* iconTheme ) { + auto pos = std::find( mIconThemes.begin(), mIconThemes.end(), iconTheme ); + if ( pos != mIconThemes.end() ) { + if ( *pos == mCurrentTheme ) { + mCurrentTheme = mFallbackTheme; + mFallbackTheme = nullptr; + } else if ( *pos == mFallbackTheme ) { + mFallbackTheme = nullptr; + } + mIconThemes.erase( pos ); + } +} + +bool UIIconThemeManager::isPresent( UIIconTheme* iconTheme ) { + return std::find( mIconThemes.begin(), mIconThemes.end(), iconTheme ) != mIconThemes.end(); +} + +}} // namespace EE::UI diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index 48755b199..b1d5356f7 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace EE { namespace UI { @@ -260,7 +260,7 @@ bool UIImage::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::Icon: { std::string val = attribute.asString(); Drawable* icon = NULL; - if ( NULL != mTheme && NULL != ( icon = mTheme->getIconByName( val ) ) ) { + if ( NULL != ( icon = getUISceneNode()->findIcon( val ) ) ) { setDrawable( icon ); } else if ( NULL != ( icon = DrawableSearcher::searchByName( val ) ) ) { setDrawable( icon ); diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index a8462b97d..299df138e 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -542,11 +543,11 @@ Uint32 UIMenu::onKeyDown( const KeyEvent& Event ) { return UIWidget::onKeyDown( Event ); } -static Drawable* getIconDrawable( const std::string& name, UITheme* theme ) { +static Drawable* getIconDrawable( const std::string& name, UIIconThemeManager* iconThemeManager ) { Drawable* iconDrawable = NULL; - if ( NULL != theme ) - iconDrawable = theme->getIconByName( name ); + if ( NULL != iconThemeManager ) + iconDrawable = iconThemeManager->findIcon( name ); if ( NULL == iconDrawable ) iconDrawable = DrawableSearcher::searchByName( name ); @@ -569,8 +570,7 @@ void UIMenu::loadFromXmlNode( const pugi::xml_node& node ) { if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) add( static_cast( mSceneNode )->getTranslatorString( text ), - getIconDrawable( icon, - getUISceneNode()->getUIThemeManager()->getDefaultTheme() ) ); + getIconDrawable( icon, getUISceneNode()->getUIIconThemeManager() ) ); } else if ( name == "menuseparator" || name == "separator" ) { addSeparator(); } else if ( name == "menucheckbox" || name == "checkbox" ) { @@ -593,8 +593,7 @@ void UIMenu::loadFromXmlNode( const pugi::xml_node& node ) { if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) addSubMenu( static_cast( mSceneNode )->getTranslatorString( text ), - getIconDrawable( - icon, getUISceneNode()->getUIThemeManager()->getDefaultTheme() ), + getIconDrawable( icon, getUISceneNode()->getUIIconThemeManager() ), subMenu ); } } diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index e2d4150ac..1c5a5d1cd 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -94,23 +94,23 @@ UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint3 UIMessageBox::~UIMessageBox() {} -void UIMessageBox::setTheme( UITheme* Theme ) { - UIWindow::setTheme( Theme ); +void UIMessageBox::setTheme( UITheme* theme ) { + UIWindow::setTheme( theme ); - mTextBox->setTheme( Theme ); - mButtonOK->setTheme( Theme ); - mButtonCancel->setTheme( Theme ); + mTextBox->setTheme( theme ); + mButtonOK->setTheme( theme ); + mButtonCancel->setTheme( theme ); if ( "Retry" != mButtonOK->getText() ) { - Drawable* OKIcon = Theme->getIconByName( "ok" ); - Drawable* CancelIcon = Theme->getIconByName( "cancel" ); + Drawable* okIcon = getUISceneNode()->findIcon( "ok" ); + Drawable* cancelIcon = getUISceneNode()->findIcon( "cancel" ); - if ( NULL != OKIcon ) { - mButtonOK->setIcon( OKIcon ); + if ( NULL != okIcon ) { + mButtonOK->setIcon( okIcon ); } - if ( NULL != CancelIcon ) { - mButtonCancel->setIcon( CancelIcon ); + if ( NULL != cancelIcon ) { + mButtonCancel->setIcon( cancelIcon ); } } @@ -149,8 +149,9 @@ UIPushButton* UIMessageBox::getButtonCancel() const { return mButtonCancel; } -Uint32 UIMessageBox::onKeyUp( const KeyEvent& Event ) { - if ( mCloseWithKey && Event.getKeyCode() == mCloseWithKey ) { +Uint32 UIMessageBox::onKeyUp( const KeyEvent& event ) { + if ( mCloseWithKey && event.getKeyCode() == mCloseWithKey && + ( event.getMod() & mCloseWithKey.mod ) ) { sendCommonEvent( Event::MsgBoxCancelClick ); closeWindow(); } @@ -168,11 +169,11 @@ bool UIMessageBox::show() { return b; } -const Uint32& UIMessageBox::getCloseWithKey() const { +const KeyBindings::Shortcut& UIMessageBox::getCloseWithKey() const { return mCloseWithKey; } -void UIMessageBox::setCloseWithKey( const Uint32& closeWithKey ) { +void UIMessageBox::setCloseWithKey( const KeyBindings::Shortcut& closeWithKey ) { mCloseWithKey = closeWithKey; } diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 163a1337f..d38c72da9 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -366,7 +366,7 @@ bool UIPushButton::applyProperty( const StyleSheetProperty& attribute ) { std::string val = attribute.asString(); Drawable* icon = NULL; - if ( NULL != mTheme && NULL != ( icon = mTheme->getIconByName( val ) ) ) { + if ( NULL != mTheme && NULL != ( icon = getUISceneNode()->findIcon( val ) ) ) { setIcon( icon ); } else if ( NULL != ( icon = DrawableSearcher::searchByName( val ) ) ) { setIcon( icon ); diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index b5aeeed38..e1428ae18 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,8 @@ UISceneNode::UISceneNode( EE::Window::Window* window ) : mIsLoading( false ), mVerbose( false ), mUpdatingLayouts( false ), - mUIThemeManager( UIThemeManager::New() ) { + mUIThemeManager( UIThemeManager::New() ), + mUIIconThemeManager( UIIconThemeManager::New()->setFallbackThemeManager( mUIThemeManager ) ) { // Reset size since the SceneNode already set it but needs to set the size from zero to emmit // the required events to its childs. mSize = Sizef(); @@ -57,6 +59,7 @@ UISceneNode::UISceneNode( EE::Window::Window* window ) : UISceneNode::~UISceneNode() { eeSAFE_DELETE( mUIThemeManager ); + eeSAFE_DELETE( mUIIconThemeManager ); for ( auto& font : mFontFaces ) { FontManager::instance()->remove( font ); @@ -669,6 +672,14 @@ const bool& UISceneNode::isUpdatingLayouts() const { return mUpdatingLayouts; } +UIIconThemeManager* UISceneNode::getUIIconThemeManager() const { + return mUIIconThemeManager; +} + +Drawable* UISceneNode::findIcon( const std::string& iconName ) { + return getUIIconThemeManager()->findIcon( iconName ); +} + bool UISceneNode::onMediaChanged() { if ( !mStyleSheet.isMediaQueryListEmpty() ) { MediaFeatures media; diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index f0e90b713..26bfe1fad 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( mTheme->getIconByName( "ok" ) ); + Button->setIcon( mSceneNode->findIcon( "ok" ) ); 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( mTheme->getIconByName( "ok" ) ); + TxtGfx->setDrawable( mSceneNode->findIcon( "ok" ) ); TxtBox->setText( "Test " + String::toString( i + 1 ) ); Cell->setCell( 0, TxtBox ); @@ -514,9 +514,9 @@ void EETest::createBaseUI() { C = C->getParent()->asType(); Menu = UIPopUpMenu::New(); - Menu->add( "New", mTheme->getIconByName( "document-new" ) ); + Menu->add( "New", mSceneNode->findIcon( "document-new" ) ); - Menu->add( "Open...", mTheme->getIconByName( "document-open" ) ); + Menu->add( "Open...", mSceneNode->findIcon( "document-open" ) ); Menu->addSeparator(); Menu->add( "Map Editor" ); Menu->add( "Texture Atlas Editor" ); @@ -600,23 +600,23 @@ void EETest::createUI() { eePRINTL( "Texture Atlas Loading Time: %4.3f ms.", TE.getElapsed().asMilliseconds() ); - UISceneNode* sceneNode = UISceneNode::New(); + mSceneNode = UISceneNode::New(); - sceneNode->enableDrawInvalidation(); - sceneNode->enableFrameBuffer(); - sceneNode->setVerbose( true ); + mSceneNode->enableDrawInvalidation(); + mSceneNode->enableFrameBuffer(); + mSceneNode->setVerbose( true ); if ( mDebugUI ) { - sceneNode->setDrawBoxes( true ); - sceneNode->setDrawDebugData( true ); - sceneNode->setHighlightFocus( true ); - sceneNode->setHighlightOver( true ); - sceneNode->setHighlightInvalidation( true ); + mSceneNode->setDrawBoxes( true ); + mSceneNode->setDrawDebugData( true ); + mSceneNode->setHighlightFocus( true ); + mSceneNode->setHighlightOver( true ); + mSceneNode->setHighlightInvalidation( true ); } - sceneNode->setTranslator( mTranslator ); + mSceneNode->setTranslator( mTranslator ); - SceneManager::instance()->add( sceneNode ); + SceneManager::instance()->add( mSceneNode ); eePRINTL( "Node size: %d", sizeof( Node ) ); eePRINTL( "UINode size: %d", sizeof( UINode ) ); @@ -628,9 +628,9 @@ void EETest::createUI() { /*mTheme = UITheme::load( mThemeName, mThemeName, "", TTF, MyPath + "ui/breeze.css" );*/ - sceneNode->combineStyleSheet( mTheme->getStyleSheet() ); + mSceneNode->combineStyleSheet( mTheme->getStyleSheet() ); - UIThemeManager* uiThemeManager = sceneNode->getUIThemeManager(); + UIThemeManager* uiThemeManager = mSceneNode->getUIThemeManager(); uiThemeManager->add( mTheme ); uiThemeManager->setDefaultEffectsEnabled( true )->setDefaultFont( TTF )->setDefaultTheme( mThemeName ); @@ -699,7 +699,7 @@ void EETest::createNewUI() { UIImage* gfx = UIImage::New(); gfx->setPosition( 50, 140 )->setSize( 16, 16 )->setParent( container ); gfx->setBackgroundColor( 0x33333333 ); - gfx->setDrawable( mTheme->getIconByName( "ok" ) ); + gfx->setDrawable( mSceneNode->findIcon( "ok" ) ); UISlider* slider = UISlider::New(); slider->setOrientation( UIOrientation::Horizontal ) @@ -733,7 +733,7 @@ void EETest::createNewUI() { UIPushButton* pushButton = UIPushButton::New(); pushButton->setPosition( 50, 560 )->setSize( 200, 0 )->setParent( container ); pushButton->setText( "PushButton" ); - pushButton->setIcon( mTheme->getIconByName( "ok" ) ); + pushButton->setIcon( mSceneNode->findIcon( "ok" ) ); pushButton->addEventListener( Event::MouseClick, [&, pushButton]( const Event* event ) { if ( static_cast( event )->getFlags() & EE_BUTTON_LMASK ) createColorPicker( pushButton ); @@ -798,7 +798,7 @@ void EETest::createNewUI() { Cell->setCell( 1, TxtGfx ); Cell->setCell( 2, TxtInput ); - TxtGfx->setDrawable( mTheme->getIconByName( "ok" ) ); + TxtGfx->setDrawable( mSceneNode->findIcon( "ok" ) ); TxtBox->setText( "Test " + String::toString( i + 1 ) ); genGrid->add( Cell ); @@ -808,11 +808,11 @@ void EETest::createNewUI() { TabWidget->setPosition( 350, 530 )->setSize( 200, 64 )->setParent( container ); TabWidget->add( "Tab 1", UIWidget::New()->setThemeSkin( "winback" ), - mTheme->getIconByName( "ok" ) ); + mSceneNode->findIcon( "ok" ) ); TabWidget->add( "Tab 2", UIWidget::New()->setThemeSkin( "winback" ), - mTheme->getIconByName( "go-up" ) ); + mSceneNode->findIcon( "go-up" ) ); TabWidget->add( "Tab 3", UIWidget::New()->setThemeSkin( "winback" ), - mTheme->getIconByName( "add" ) ); + mSceneNode->findIcon( "add" ) ); UIWindow* MenuCont = UIWindow::New(); MenuCont->setPosition( 350, 390 )->setSize( 200, 115 ); @@ -1291,7 +1291,7 @@ void EETest::onButtonClick( const Event* event ) { if ( mouseEvent->getFlags() & EE_BUTTONS_LRM ) { UIImage* Gfx = UIImage::New(); - Gfx->setDrawable( mTheme->getIconByName( "ok" ) ); + Gfx->setDrawable( mSceneNode->findIcon( "ok" ) ); Gfx->setEnabled( false ); Gfx->runAction( Spawn::New( diff --git a/src/tests/test_all/test.hpp b/src/tests/test_all/test.hpp index 9bfe66fca..22af363bc 100644 --- a/src/tests/test_all/test.hpp +++ b/src/tests/test_all/test.hpp @@ -224,6 +224,7 @@ class EETest : private Thread { Sprite* mCircleSprite; UITheme* mTheme; + UISceneNode* mSceneNode; bool mTerrainUp; UIPushButton* mShowMenu; diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index 641845c2a..c03a8231e 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -732,6 +732,8 @@ void App::showFindView() { if ( !text.empty() ) { findInput->setText( text ); findInput->getDocument().selectAll(); + } else if ( !findInput->getText().empty() ) { + findInput->getDocument().selectAll(); } } @@ -806,18 +808,18 @@ App::~App() { void App::createSettingsMenu() { mSettingsMenu = UIPopUpMenu::New(); - mSettingsMenu->add( "New", NULL, "Ctrl+T" ); - mSettingsMenu->add( "Open...", NULL, "Ctrl+O" ); + mSettingsMenu->add( "New", mUISceneNode->findIcon( "document-new" ), "Ctrl+T" ); + mSettingsMenu->add( "Open...", mUISceneNode->findIcon( "document-open" ), "Ctrl+O" ); mSettingsMenu->addSeparator(); - mSettingsMenu->add( "Save", NULL, "Ctrl+S" ); - mSettingsMenu->add( "Save as..." ); + mSettingsMenu->add( "Save", mUISceneNode->findIcon( "document-save" ), "Ctrl+S" ); + mSettingsMenu->add( "Save as...", mUISceneNode->findIcon( "document-save-as" ) ); mSettingsMenu->addSeparator(); mSettingsMenu->addSubMenu( "Filetype", NULL, createFiletypeMenu() ); mSettingsMenu->addSubMenu( "Color Scheme", NULL, createColorSchemeMenu() ); mSettingsMenu->addSeparator(); - mSettingsMenu->add( "Close", NULL, "Ctrl+W" ); + mSettingsMenu->add( "Close", mUISceneNode->findIcon( "document-close" ), "Ctrl+W" ); mSettingsMenu->addSeparator(); - mSettingsMenu->add( "Quit", NULL, "Ctrl+Q" ); + mSettingsMenu->add( "Quit", mUISceneNode->findIcon( "quit" ), "Ctrl+Q" ); mSettingsButton = mUISceneNode->find( "settings" ); mSettingsButton->addEventListener( Event::MouseClick, [&]( const Event* ) { Vector2f pos( mSettingsButton->getPixelsPosition() ); @@ -945,7 +947,7 @@ void App::init( const std::string& file, const Float& pidelDensity ) { Font* fontMono = FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" ); - FontTrueType::New( "icon", resPath + "assets/fonts/remixicon.ttf" ); + Font* iconFont = FontTrueType::New( "icon", resPath + "assets/fonts/remixicon.ttf" ); SceneManager::instance()->add( mUISceneNode ); @@ -1046,6 +1048,23 @@ void App::init( const std::string& file, const Float& pidelDensity ) { mUISceneNode->bind( "code_container", mBaseLayout ); mUISceneNode->bind( "search_bar", mSearchBarLayout ); mSearchBarLayout->setVisible( false )->setEnabled( false ); + UIIconTheme* iconTheme = UIIconTheme::New( "remixicon" ); + auto addIcon = [iconTheme, iconFont]( const std::string& name, const Uint32& codePoint, + const Uint32& size ) { + iconTheme->add( name, + iconFont->getGlyphDrawable( codePoint, PixelDensity::dpToPx( size ) ) ); + }; + addIcon( "go-up", 0xea78, 16 ); + addIcon( "ok", 0xeb7a, 16 ); + addIcon( "cancel", 0xeb98, 16 ); + addIcon( "document-new", 0xecc3, 12 ); + addIcon( "document-open", 0xed70, 12 ); + addIcon( "document-save", 0xf0b3, 12 ); + addIcon( "document-save-as", 0xf0b3, 12 ); + addIcon( "document-close", 0xeb99, 12 ); + addIcon( "quit", 0xeb97, 12 ); + + mUISceneNode->getUIIconThemeManager()->setCurrentTheme( iconTheme ); initSearchBar(); createSettingsMenu(); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 9a84d7024..675775ac0 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -894,25 +894,26 @@ void createAppMenu() { uiMenuBar = UIMenuBar::New(); UIPopUpMenu* uiPopMenu = UIPopUpMenu::New(); - uiPopMenu->add( "Open project...", theme->getIconByName( "document-open" ) ); + uiPopMenu->add( "Open project...", appUiSceneNode->findIcon( "document-open" ) ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Open layout...", theme->getIconByName( "document-open" ) ); + uiPopMenu->add( "Open layout...", appUiSceneNode->findIcon( "document-open" ) ); uiPopMenu->addSeparator(); uiPopMenu->addSubMenu( "Recent files", NULL, UIPopUpMenu::New() ); uiPopMenu->addSubMenu( "Recent projects", NULL, UIPopUpMenu::New() ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Close", theme->getIconByName( "document-close" ) ); + uiPopMenu->add( "Close", appUiSceneNode->findIcon( "document-close" ) ); uiPopMenu->addSeparator(); - uiPopMenu->add( "Quit", theme->getIconByName( "quit" ) ); + uiPopMenu->add( "Quit", appUiSceneNode->findIcon( "quit" ) ); uiMenuBar->addMenuButton( "File", uiPopMenu ); uiPopMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) ); UIPopUpMenu* uiResourceMenu = UIPopUpMenu::New(); - uiResourceMenu->add( "Load images from path...", theme->getIconByName( "document-open" ) ); + uiResourceMenu->add( "Load images from path...", appUiSceneNode->findIcon( "document-open" ) ); uiResourceMenu->addSeparator(); - uiResourceMenu->add( "Load fonts from path...", theme->getIconByName( "document-open" ) ); + uiResourceMenu->add( "Load fonts from path...", appUiSceneNode->findIcon( "document-open" ) ); uiResourceMenu->addSeparator(); - uiResourceMenu->add( "Load style sheet from path...", theme->getIconByName( "document-open" ) ); + uiResourceMenu->add( "Load style sheet from path...", + appUiSceneNode->findIcon( "document-open" ) ); uiMenuBar->addMenuButton( "Resources", uiResourceMenu ); uiResourceMenu->addEventListener( Event::OnItemClicked, cb::Make1( fileMenuClick ) );