diff --git a/include/eepp/ui/uipushbutton.hpp b/include/eepp/ui/uipushbutton.hpp index d8161448a..87ddfe653 100644 --- a/include/eepp/ui/uipushbutton.hpp +++ b/include/eepp/ui/uipushbutton.hpp @@ -15,28 +15,23 @@ class EE_API UIPushButton : public UIComplexControl { public: inline CreateParams() : UITextBox::CreateParams(), - Icon( NULL ), - IconHorizontalMargin( 0 ), - IconAutoMargin( true ), - IconMinSize( 0, 0 ) + Icon( NULL ) { - FontStyleConfig = UIThemeManager::instance()->getDefaultFontStyleConfig(); + UITheme * theme = UIThemeManager::instance()->getDefaultTheme(); + + if ( NULL != theme ) { + StyleConfig = theme->getPushButtonStyleConfig(); + } } inline ~CreateParams() {} inline void setIcon( SubTexture * icon ) { Icon = icon; - - if ( !IconHorizontalMargin ) - IconHorizontalMargin = 4; } - UI::FontStyleConfig FontStyleConfig; + PushButtonStyleConfig StyleConfig; SubTexture * Icon; - Int32 IconHorizontalMargin; - bool IconAutoMargin; - Sizei IconMinSize; }; UIPushButton( const UIPushButton::CreateParams& Params ); @@ -51,7 +46,7 @@ class EE_API UIPushButton : public UIComplexControl { virtual void setTheme( UITheme * Theme ); - virtual void setIcon( SubTexture * icon ); + virtual UIPushButton * setIcon( SubTexture * icon ); virtual UIGfx * getIcon() const; @@ -85,14 +80,13 @@ class EE_API UIPushButton : public UIComplexControl { void setFontShadowColor( const ColorA& color ); - FontStyleConfig getFontStyleConfig() const; + FontStyleConfig getStyleConfig() const; - void setFontStyleConfig(const FontStyleConfig & fontStyleConfig); + void setStyleConfig(const PushButtonStyleConfig & styleConfig); protected: - FontStyleConfig mFontStyleConfig; + PushButtonStyleConfig mStyleConfig; UIGfx * mIcon; UITextBox * mTextBox; - Int32 mIconSpace; virtual void onSizeChange(); diff --git a/include/eepp/ui/uiselectbutton.hpp b/include/eepp/ui/uiselectbutton.hpp index 21e6caf74..456ab5718 100644 --- a/include/eepp/ui/uiselectbutton.hpp +++ b/include/eepp/ui/uiselectbutton.hpp @@ -9,8 +9,6 @@ class EE_API UISelectButton : public UIPushButton { public: static UISelectButton * New(); - UISelectButton( const UIPushButton::CreateParams& Params ); - UISelectButton(); virtual ~UISelectButton(); diff --git a/include/eepp/ui/uitab.hpp b/include/eepp/ui/uitab.hpp index f317d3ecb..b414bebf1 100644 --- a/include/eepp/ui/uitab.hpp +++ b/include/eepp/ui/uitab.hpp @@ -9,7 +9,7 @@ class UITabWidget; class EE_API UITab : public UISelectButton { public: - UITab( UISelectButton::CreateParams& Params, UIControl * controlOwned ); + static UITab * New(); UITab(); diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index d47e94c0b..a46aaa0de 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -95,10 +95,6 @@ class EE_API UITheme : protected ResourceManager { virtual UIListBox * createListBox( UIControl * Parent = NULL, const Sizei& Size = Sizei(), const Vector2i& Pos = Vector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING, bool SmoothScroll = true, Uint32 RowHeight = 0, UI_SCROLLBAR_MODE VScrollMode = UI_SCROLLBAR_AUTO, UI_SCROLLBAR_MODE HScrollMode = UI_SCROLLBAR_AUTO, Recti PaddingContainer = Recti() ); - virtual UIPushButton * createPushButton( UIControl * Parent = NULL, const Sizei& Size = Sizei(), const Vector2i& Pos = Vector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, SubTexture * Icon = NULL, Int32 IconHorizontalMargin = 0, bool IconAutoMargin = true ); - - virtual UISelectButton * createSelectButton( UIControl * Parent = NULL, const Sizei& Size = Sizei(), const Vector2i& Pos = Vector2i(), const Uint32& Flags = UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, SubTexture * Icon = NULL, Int32 IconHorizontalMargin = 0, bool IconAutoMargin = true ); - ColorA getTooltipFontColor() const; void setTooltipFontColor(const ColorA & tooltipFontColor); @@ -122,6 +118,8 @@ class EE_API UITheme : protected ResourceManager { virtual WindowStyleConfig getWindowStyleConfig(); virtual MenuStyleConfig getMenuStyleConfig(); + + virtual PushButtonStyleConfig getPushButtonStyleConfig(); protected: std::string mName; Uint32 mNameHash; diff --git a/include/eepp/ui/uithemeconfig.hpp b/include/eepp/ui/uithemeconfig.hpp index 90516f2bc..121db1bbd 100644 --- a/include/eepp/ui/uithemeconfig.hpp +++ b/include/eepp/ui/uithemeconfig.hpp @@ -185,6 +185,19 @@ class MenuStyleConfig : public FontStyleConfig { }; +class PushButtonStyleConfig : public FontStyleConfig { + public: + PushButtonStyleConfig() {} + + PushButtonStyleConfig( FontStyleConfig fontStyleConfig ) : + FontStyleConfig( fontStyleConfig ) + {} + + Int32 IconHorizontalMargin = 4; + bool IconAutoMargin = true; + Sizei IconMinSize; +}; + }} #endif diff --git a/src/eepp/gaming/mapeditor/mapeditor.cpp b/src/eepp/gaming/mapeditor/mapeditor.cpp index a217ce8eb..7a0e8c1a7 100644 --- a/src/eepp/gaming/mapeditor/mapeditor.cpp +++ b/src/eepp/gaming/mapeditor/mapeditor.cpp @@ -262,7 +262,10 @@ void MapEditor::CreateSubTextureContainer( Int32 Width ) { mGOTypeList->addEventListener( UIEvent::EventOnItemSelected, cb::Make1( this, &MapEditor::OnTypeChange ) ); FillGotyList(); - mBtnGOTypeAdd = mTheme->createPushButton( mSubTextureCont, Sizei( 24, 21 ), Vector2i( mGOTypeList->getPosition().x + mGOTypeList->getSize().getWidth() + 2, mGOTypeList->getPosition().y ), UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mTheme->getIconByName( "add" ) ); + mBtnGOTypeAdd = UIPushButton::New(); + mBtnGOTypeAdd->setParent( mSubTextureCont )->setSize( 24, mGOTypeList->getSize().getHeight() ) + ->setPosition( mGOTypeList->getPosition().x + mGOTypeList->getSize().getWidth() + 2, mGOTypeList->getPosition().y ); + mBtnGOTypeAdd->setIcon( mTheme->getIconByName( "add" ) )->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); mBtnGOTypeAdd->setTooltipText( "Adds a new game object type\nunknown by the map editor." ); mBtnGOTypeAdd->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapEditor::AddNewGOType ) ); @@ -364,7 +367,8 @@ void MapEditor::CreateSubTextureContainer( Int32 Width ) { } void MapEditor::CreateLighContainer() { - UIPushButton * NewLightBut = mTheme->createPushButton( mLightCont, Sizei( mLightCont->getSize().getWidth() - TAB_CONT_X_DIST * 2, 22 ), Vector2i( TAB_CONT_X_DIST, 0 ) ); + UIPushButton * NewLightBut = UIPushButton::New(); + NewLightBut->setParent( mLightCont )->setSize( mLightCont->getSize().getWidth() - TAB_CONT_X_DIST * 2, 0 )->setPosition( TAB_CONT_X_DIST, 0 ); NewLightBut->setText( "New Light" ); NewLightBut->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapEditor::OnNewLight ) ); diff --git a/src/eepp/gaming/mapeditor/maplayerproperties.cpp b/src/eepp/gaming/mapeditor/maplayerproperties.cpp index 8e089dcfe..43e7f372e 100644 --- a/src/eepp/gaming/mapeditor/maplayerproperties.cpp +++ b/src/eepp/gaming/mapeditor/maplayerproperties.cpp @@ -38,13 +38,17 @@ MapLayerProperties::MapLayerProperties( MapLayer * Map, RefreshLayerListCb Cb ) mUITheme->createTextBox( "Property Name", mUIWindow->getContainer(), Sizei(192, 24), Vector2i( 50, mUIInput->getPosition().y + mUIInput->getSize().getHeight() + 12 ), TxtBoxFlags ); UITextBox * TxtBox = mUITheme->createTextBox( "Property Value", mUIWindow->getContainer(), Sizei(192, 24), Vector2i( 50+192, mUIInput->getPosition().y + mUIInput->getSize().getHeight() + 12 ), TxtBoxFlags ); - UIPushButton * OKButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "ok" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mUITheme->getIconByName( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapLayerProperties::onOKClick ) ); OKButton->setText( "OK" ); - UIPushButton * CancelButton = mUITheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( OKButton->getSize() )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapLayerProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -66,7 +70,10 @@ MapLayerProperties::MapLayerProperties( MapLayer * Map, RefreshLayerListCb Cb ) Vector2i Pos( mGenGrid->getPosition().x + mGenGrid->getSize().getWidth() + 10, mGenGrid->getPosition().y ); - UIPushButton * AddButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei(24,21), Pos, UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mUITheme->getIconByName( "add" ) ); + UIPushButton * AddButton = UIPushButton::New(); + AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); + AddButton->setIcon( mUITheme->getIconByName( "add" ) ); + AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapLayerProperties::onAddCellClick ) ); if ( NULL == AddButton->getIcon()->getSubTexture() ) @@ -74,7 +81,10 @@ MapLayerProperties::MapLayerProperties( MapLayer * Map, RefreshLayerListCb Cb ) Pos.y += AddButton->getSize().getHeight() + 5; - UIPushButton * RemoveButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei(24,21), Pos, UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mUITheme->getIconByName( "remove" ) ); + UIPushButton * RemoveButton = UIPushButton::New(); + RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); + RemoveButton->setIcon( mUITheme->getIconByName( "remove" ) ); + RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapLayerProperties::onRemoveCellClick ) ); if ( NULL == RemoveButton->getIcon()->getSubTexture() ) diff --git a/src/eepp/gaming/mapeditor/mapobjectproperties.cpp b/src/eepp/gaming/mapeditor/mapobjectproperties.cpp index 14cbfa4fe..154d3e560 100644 --- a/src/eepp/gaming/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/gaming/mapeditor/mapobjectproperties.cpp @@ -42,13 +42,17 @@ MapObjectProperties::MapObjectProperties( GameObjectObject * Obj ) : mUITheme->createTextBox( "Property Name", mUIWindow->getContainer(), Sizei(192, 24), Vector2i( 50, mUIInput->getPosition().y + mUIInput->getSize().getHeight() + 12 ), TxtBoxFlags ); UITextBox * TxtBox = mUITheme->createTextBox( "Property Value", mUIWindow->getContainer(), Sizei(192, 24), Vector2i( 50+192, mUIInput->getPosition().y + mUIInput->getSize().getHeight() + 12 ), TxtBoxFlags ); - UIPushButton * OKButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "ok" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mUITheme->getIconByName( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapObjectProperties::onOKClick ) ); OKButton->setText( "OK" ); - UIPushButton * CancelButton = mUITheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( OKButton->getSize() )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapObjectProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -70,7 +74,10 @@ MapObjectProperties::MapObjectProperties( GameObjectObject * Obj ) : Vector2i Pos( mGenGrid->getPosition().x + mGenGrid->getSize().getWidth() + 10, mGenGrid->getPosition().y ); - UIPushButton * AddButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei(24,21), Pos, UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mUITheme->getIconByName( "add" ) ); + UIPushButton * AddButton = UIPushButton::New(); + AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); + AddButton->setIcon( mUITheme->getIconByName( "add" ) ); + AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapObjectProperties::onAddCellClick ) ); if ( NULL == AddButton->getIcon()->getSubTexture() ) @@ -78,7 +85,10 @@ MapObjectProperties::MapObjectProperties( GameObjectObject * Obj ) : Pos.y += AddButton->getSize().getHeight() + 5; - UIPushButton * RemoveButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei(24,21), Pos, UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mUITheme->getIconByName( "remove" ) ); + UIPushButton * RemoveButton = UIPushButton::New(); + RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); + RemoveButton->setIcon( mUITheme->getIconByName( "remove" ) ); + RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &MapObjectProperties::onRemoveCellClick ) ); if ( NULL == RemoveButton->getIcon()->getSubTexture() ) diff --git a/src/eepp/gaming/mapeditor/tilemapproperties.cpp b/src/eepp/gaming/mapeditor/tilemapproperties.cpp index 496384f7c..dcaaa6f5c 100644 --- a/src/eepp/gaming/mapeditor/tilemapproperties.cpp +++ b/src/eepp/gaming/mapeditor/tilemapproperties.cpp @@ -72,13 +72,17 @@ TileMapProperties::TileMapProperties( TileMap * Map ) : UITextBox * TxtBox = mUITheme->createTextBox( "Property Name", mUIWindow->getContainer(), Sizei(192, 24), Vector2i( 50, 10 + DiffIfLights ), TxtBoxFlags ); mUITheme->createTextBox( "Property Value", mUIWindow->getContainer(), Sizei(192, 24), Vector2i(50+192, TxtBox->getPosition().y ), TxtBoxFlags ); - UIPushButton * OKButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "ok" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mUITheme->getIconByName( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TileMapProperties::onOKClick ) ); OKButton->setText( "OK" ); - UIPushButton * CancelButton = mUITheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( OKButton->getSize() )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TileMapProperties::onCancelClick ) ); CancelButton->setText( "Cancel" ); @@ -100,7 +104,10 @@ TileMapProperties::TileMapProperties( TileMap * Map ) : Vector2i Pos( mGenGrid->getPosition().x + mGenGrid->getSize().getWidth() + 10, mGenGrid->getPosition().y ); - UIPushButton * AddButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei(24,21), Pos, UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mUITheme->getIconByName( "add" ) ); + UIPushButton * AddButton = UIPushButton::New(); + AddButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); + AddButton->setIcon( mUITheme->getIconByName( "add" ) ); + AddButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); AddButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TileMapProperties::onAddCellClick ) ); if ( NULL == AddButton->getIcon()->getSubTexture() ) @@ -108,7 +115,10 @@ TileMapProperties::TileMapProperties( TileMap * Map ) : Pos.y += AddButton->getSize().getHeight() + 5; - UIPushButton * RemoveButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei(24,21), Pos, UI_CONTROL_ALIGN_CENTER | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP, mUITheme->getIconByName( "remove" ) ); + UIPushButton * RemoveButton = UIPushButton::New(); + RemoveButton->setParent( mUIWindow->getContainer() )->setSize( 24, 0 )->setPosition( Pos ); + RemoveButton->setIcon( mUITheme->getIconByName( "remove" ) ); + RemoveButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_TOP ); RemoveButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TileMapProperties::onRemoveCellClick ) ); if ( NULL == RemoveButton->getIcon()->getSubTexture() ) diff --git a/src/eepp/gaming/mapeditor/uigotypenew.cpp b/src/eepp/gaming/mapeditor/uigotypenew.cpp index 1693f4f76..4877bca41 100644 --- a/src/eepp/gaming/mapeditor/uigotypenew.cpp +++ b/src/eepp/gaming/mapeditor/uigotypenew.cpp @@ -27,14 +27,18 @@ UIGOTypeNew::UIGOTypeNew( cb::Callback2 Cb ) : mUIInput = mUITheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); - UIPushButton * OKButton = mUITheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "add" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mUITheme->getIconByName( "add" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &UIGOTypeNew::onOKClick ) ); mUIInput->addEventListener( UIEvent::EventOnPressEnter, cb::Make1( this, &UIGOTypeNew::onOKClick ) ); OKButton->setText( "Add" ); - UIPushButton * CancelButton = mUITheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( OKButton->getSize() )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mUITheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &UIGOTypeNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/gaming/mapeditor/uimap.cpp b/src/eepp/gaming/mapeditor/uimap.cpp index 710778872..8c7e4f460 100644 --- a/src/eepp/gaming/mapeditor/uimap.cpp +++ b/src/eepp/gaming/mapeditor/uimap.cpp @@ -577,6 +577,7 @@ void UIMap::createObjPopUpMenu() { if ( Menu->show() ) { Vector2i Pos = UIManager::instance()->getInput()->getMousePos(); UIMenu::fixMenuPos( Pos , Menu ); + Pos = PixelDensity::pxToDpI( Pos ); Menu->setPosition( Pos ); } } diff --git a/src/eepp/gaming/mapeditor/uimaplayernew.cpp b/src/eepp/gaming/mapeditor/uimaplayernew.cpp index 39d7f0b56..d30953864 100644 --- a/src/eepp/gaming/mapeditor/uimaplayernew.cpp +++ b/src/eepp/gaming/mapeditor/uimaplayernew.cpp @@ -34,14 +34,18 @@ UIMapLayerNew::UIMapLayerNew( UIMap * Map, EE_LAYER_TYPE Type, NewLayerCb newLay mUILayerName = mTheme->createTextInput( mUIWindow->getContainer(), Sizei( 120, 22 ), Vector2i( Txt->getPosition().x + DistFromTitle, Txt->getPosition().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE, true, 64 ); mUILayerName->setText( "Layer " + String::toStr( mUIMap->Map()->getLayerCount() + 1 ) ); - UIPushButton * OKButton = mTheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->getIconByName( "add" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mTheme->getIconByName( "add" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &UIMapLayerNew::onOKClick ) ); mUILayerName->addEventListener( UIEvent::EventOnPressEnter, cb::Make1( this, &UIMapLayerNew::onOKClick ) ); OKButton->setText( "Add" ); - UIPushButton * CancelButton = mTheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( OKButton->getSize() )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mTheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &UIMapLayerNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/gaming/mapeditor/uimapnew.cpp b/src/eepp/gaming/mapeditor/uimapnew.cpp index a36f176b8..7fbb3509f 100644 --- a/src/eepp/gaming/mapeditor/uimapnew.cpp +++ b/src/eepp/gaming/mapeditor/uimapnew.cpp @@ -182,12 +182,16 @@ UIMapNew::UIMapNew( UIMap * Map, cb::Callback0 NewMapCb, bool ResizeMap ) mUIBlueSlider->setValue( mUIMap->Map()->getBaseColor().b() ); } - UIPushButton * OKButton = mTheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->getIconByName( "ok" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mTheme->getIconByName( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &UIMapNew::onOKClick ) ); OKButton->setText( "OK" ); - UIPushButton * CancelButton = mTheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( OKButton->getSize() )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mTheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &UIMapNew::onCancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index 131ea194e..acc8dee52 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -93,21 +93,27 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow * AttatchTo, const TGEditorClos TxtBox = createTextBox( Vector2i(), "Dest. Height:" ); TxtBox->setPosition( mSpinDestH->getPosition().x - 10 - TxtBox->getSize().getWidth(), InitY ); - Uint32 ButFlags = UI_CONTROL_ALIGN_CENTER | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_AUTO_SIZE; - - UIPushButton * ResetButton = mTheme->createPushButton( mUIContainer, Sizei( 120, 22 ), Vector2i( mUIContainer->getSize().getWidth() - 120 - 5 , mSpinDestH->getPosition().y + mSpinDestH->getSize().getHeight() + 8 ), ButFlags ); + UIPushButton * ResetButton = UIPushButton::New(); + ResetButton->setParent( mUIContainer )->setSize( 200, 0 )->setPosition( mUIContainer->getSize().getWidth() - 200 - 5 , mSpinDestH->getPosition().y + mSpinDestH->getSize().getHeight() + 8 ); + ResetButton->setAnchors( UI_ANCHOR_TOP | UI_ANCHOR_RIGHT ); ResetButton->setText( "Reset Dest. Size" ); ResetButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasEditor::onResetDestSize ) ); - UIPushButton * ResetOffsetButton = mTheme->createPushButton( mUIContainer, Sizei( 120, 22 ), Vector2i( ResetButton->getPosition().x, ResetButton->getPosition().y + ResetButton->getSize().getHeight() + 8 ), ButFlags ); + UIPushButton * ResetOffsetButton = UIPushButton::New(); + ResetOffsetButton->setParent( mUIContainer )->setSize( 200, 0 )->setPosition( ResetButton->getPosition().x, ResetButton->getPosition().y + ResetButton->getSize().getHeight() + 8 ); + ResetOffsetButton->setAnchors( UI_ANCHOR_TOP | UI_ANCHOR_RIGHT ); ResetOffsetButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasEditor::onResetOffset ) ); ResetOffsetButton->setText( "Reset Offset" ); - UIPushButton * CenterOffsetButton = mTheme->createPushButton( mUIContainer, Sizei( 120, 22 ), Vector2i( ResetOffsetButton->getPosition().x, ResetOffsetButton->getPosition().y + ResetOffsetButton->getSize().getHeight() + 8 ), ButFlags ); + UIPushButton * CenterOffsetButton = UIPushButton::New(); + CenterOffsetButton->setParent( mUIContainer )->setSize( 200, 0 )->setPosition( ResetOffsetButton->getPosition().x, ResetOffsetButton->getPosition().y + ResetOffsetButton->getSize().getHeight() + 8 ); + CenterOffsetButton->setAnchors( UI_ANCHOR_TOP | UI_ANCHOR_RIGHT ); CenterOffsetButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasEditor::onCenterOffset ) ); CenterOffsetButton->setText( "Centered Offset" ); - UIPushButton * HBOffsetButton = mTheme->createPushButton( mUIContainer, Sizei( 120, 22 ), Vector2i( CenterOffsetButton->getPosition().x, CenterOffsetButton->getPosition().y + CenterOffsetButton->getSize().getHeight() + 8 ), ButFlags ); + UIPushButton * HBOffsetButton = UIPushButton::New(); + HBOffsetButton->setParent( mUIContainer )->setSize( 200, 0 )->setPosition( CenterOffsetButton->getPosition().x, CenterOffsetButton->getPosition().y + CenterOffsetButton->getSize().getHeight() + 8 ); + HBOffsetButton->setAnchors( UI_ANCHOR_TOP | UI_ANCHOR_RIGHT ); HBOffsetButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasEditor::onHBOffset ) ); HBOffsetButton->setText( "Half-Bottom Offset" ); diff --git a/src/eepp/ui/tools/textureatlasnew.cpp b/src/eepp/ui/tools/textureatlasnew.cpp index 1889b611d..339ed2ed6 100644 --- a/src/eepp/ui/tools/textureatlasnew.cpp +++ b/src/eepp/ui/tools/textureatlasnew.cpp @@ -76,16 +76,21 @@ TextureAtlasNew::TextureAtlasNew( TGCreateCb NewTGCb ) : mTGPath = mTheme->createTextInput( mUIWindow->getContainer(), Sizei( mUIWindow->getContainer()->getSize().getWidth() - 60, 22 ), Vector2i( 10, 160 ), UI_CONTROL_DEFAULT_FLAGS | UI_CLIP_ENABLE | UI_AUTO_PADDING | UI_AUTO_SIZE , false, 512 ); mTGPath->setAllowEditing( false ); - mSetPathButton = mTheme->createPushButton( mUIWindow->getContainer(), Sizei( 32, 32 ), Vector2i( mUIWindow->getContainer()->getSize().getWidth() - 10 - 32, 160 ) ); + mSetPathButton = UIPushButton::New(); + mSetPathButton->setParent( mUIWindow->getContainer() )->setSize( 32, 22 )->setPosition( mUIWindow->getContainer()->getSize().getWidth() - 10 - 32, 160 ); mSetPathButton->setText( "..." ); mSetPathButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasNew::onDialogFolderSelect ) ); - UIPushButton * OKButton = mTheme->createPushButton( mUIWindow->getContainer(), Sizei( 80, 22 ), Vector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->getIconByName( "ok" ) ); + UIPushButton * OKButton = UIPushButton::New(); + OKButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 ); + OKButton->setIcon( mTheme->getIconByName( "ok" ) ); OKButton->setPosition( mUIWindow->getContainer()->getSize().getWidth() - OKButton->getSize().getWidth() - 4, mUIWindow->getContainer()->getSize().getHeight() - OKButton->getSize().getHeight() - 4 ); OKButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasNew::okClick ) ); OKButton->setText( "OK" ); - UIPushButton * CancelButton = mTheme->createPushButton( mUIWindow->getContainer(), OKButton->getSize(), Vector2i( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->getIconByName( "cancel" ) ); + UIPushButton * CancelButton = UIPushButton::New(); + CancelButton->setParent( mUIWindow->getContainer() )->setSize( 80, 0 )->setPosition( OKButton->getPosition().x - OKButton->getSize().getWidth() - 4, OKButton->getPosition().y ); + CancelButton->setIcon( mTheme->getIconByName( "cancel" ) ); CancelButton->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &TextureAtlasNew::cancelClick ) ); CancelButton->setText( "Cancel" ); diff --git a/src/eepp/ui/uicomplexcontrol.cpp b/src/eepp/ui/uicomplexcontrol.cpp index 0c6f1eb42..2761ce597 100644 --- a/src/eepp/ui/uicomplexcontrol.cpp +++ b/src/eepp/ui/uicomplexcontrol.cpp @@ -50,20 +50,23 @@ void UIComplexControl::updateAnchorsDistances() { void UIComplexControl::update() { if ( mVisible && NULL != mTooltip && mTooltip->getText().size() ) { if ( isMouseOverMeOrChilds() ) { - Vector2i Pos = UIManager::instance()->getMousePos(); - Pos.x += UIThemeManager::instance()->getCursorSize().x; - Pos.y += UIThemeManager::instance()->getCursorSize().y; + UIManager * uiManager = UIManager::instance(); + UIThemeManager * themeManager = UIThemeManager::instance(); - if ( Pos.x + mTooltip->getRealSize().getWidth() > UIManager::instance()->getMainControl()->getRealSize().getWidth() ) { - Pos.x = UIManager::instance()->getMousePos().x - mTooltip->getRealSize().getWidth(); + Vector2i Pos = uiManager->getMousePos(); + Pos.x += themeManager->getCursorSize().x; + Pos.y += themeManager->getCursorSize().y; + + if ( Pos.x + mTooltip->getRealSize().getWidth() > uiManager->getMainControl()->getRealSize().getWidth() ) { + Pos.x = uiManager->getMousePos().x - mTooltip->getRealSize().getWidth(); } - if ( Pos.y + mTooltip->getRealSize().getHeight() > UIManager::instance()->getMainControl()->getRealSize().getHeight() ) { - Pos.y = UIManager::instance()->getMousePos().y - mTooltip->getRealSize().getHeight(); + if ( Pos.y + mTooltip->getRealSize().getHeight() > uiManager->getMainControl()->getRealSize().getHeight() ) { + Pos.y = uiManager->getMousePos().y - mTooltip->getRealSize().getHeight(); } - if ( Time::Zero == UIThemeManager::instance()->getTooltipTimeToShow() ) { - if ( !mTooltip->isVisible() || UIThemeManager::instance()->getTooltipFollowMouse() ) + if ( Time::Zero == themeManager->getTooltipTimeToShow() ) { + if ( !mTooltip->isVisible() || themeManager->getTooltipFollowMouse() ) mTooltip->setPosition( PixelDensity::pxToDpI( Pos ) ); mTooltip->show(); @@ -72,7 +75,7 @@ void UIComplexControl::update() { mTooltip->addTooltipTime( getElapsed() ); } - if ( mTooltip->getTooltipTime() >= UIThemeManager::instance()->getTooltipTimeToShow() ) { + if ( mTooltip->getTooltipTime() >= themeManager->getTooltipTimeToShow() ) { if ( mTooltip->getTooltipTime().asMilliseconds() != -1.f ) { mTooltip->setPosition( PixelDensity::pxToDpI( Pos ) ); @@ -83,7 +86,7 @@ void UIComplexControl::update() { } } - if ( UIThemeManager::instance()->getTooltipFollowMouse() ) { + if ( themeManager->getTooltipFollowMouse() ) { mTooltip->setPosition( PixelDensity::pxToDpI( Pos ) ); } } else { diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 290a216bc..b8bdfe5f3 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -393,13 +393,22 @@ void UIControl::drawOverControl() { } void UIControl::drawDebugData() { - Graphics::Font * font = UIThemeManager::instance()->getDefaultFont(); + if ( UIManager::instance()->getDrawDebugData() ) { + if ( isComplex() ) { + UIComplexControl * me = static_cast( this ); - if ( UIManager::instance()->getDrawDebugData() && font != NULL ) { - String text( String::strFormated( "X: %d Y: %d\nW: %d H: %d", mRealPos.x, mRealPos.y, mRealSize.x, mRealSize.y ) ); + if ( UIManager::instance()->getOverControl() == this ) { + String text( String::strFormated( "X: %d Y: %d\nW: %d H: %d", mPos.x, mPos.y, mSize.x, mSize.y ) ); - font->setColor( ColorA( 255, 0, 255, 255 ) ); - font->draw( text, mScreenPos.x, mScreenPos.y ); + if ( !mId.empty() ) { + text = "ID: " + mId + "\n" + text; + } + + me->setTooltipText( text ); + } else { + me->setTooltipText( "" ); + } + } } } diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 20d90ce49..c521f1768 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -61,7 +61,7 @@ UIMenuItem * UIMenu::createMenuItem( const String& Text, SubTexture * Icon ) { Params.setParent( this ); Params.FontStyleConfig = mStyleConfig; Params.Icon = Icon; - Params.IconMinSize = Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ); + Params.StyleConfig.IconMinSize = Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ); if ( mFlags & UI_AUTO_SIZE ) { Params.Flags = UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; @@ -86,7 +86,7 @@ UIMenuCheckBox * UIMenu::createMenuCheckBox( const String& Text, const bool &Act UIMenuCheckBox::CreateParams Params; Params.setParent( this ); Params.FontStyleConfig = mStyleConfig; - Params.IconMinSize = Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ); + Params.StyleConfig.IconMinSize = Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ); if ( mFlags & UI_AUTO_SIZE ) { Params.Flags = UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; @@ -116,7 +116,7 @@ UIMenuSubMenu * UIMenu::createSubMenu( const String& Text, SubTexture * Icon, UI Params.FontStyleConfig = mStyleConfig; Params.SubMenu = SubMenu; Params.Icon = Icon; - Params.IconMinSize = Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ); + Params.StyleConfig.IconMinSize = Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ); if ( mFlags & UI_AUTO_SIZE ) { Params.Flags = UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_LEFT; diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 1b41735dc..3785beaff 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -9,16 +9,15 @@ UIPushButton * UIPushButton::New() { UIPushButton::UIPushButton( const UIPushButton::CreateParams& Params ) : UIComplexControl( Params ), - mFontStyleConfig( Params.FontStyleConfig ), + mStyleConfig( Params.StyleConfig ), mIcon( NULL ), - mTextBox( NULL ), - mIconSpace( Params.IconHorizontalMargin ) + mTextBox( NULL ) { UIGfx::CreateParams GfxParams; GfxParams.setParent( this ); GfxParams.SubTexture = Params.Icon; - if ( Params.IconMinSize.x != 0 && Params.IconMinSize.y != 0 ) { + if ( mStyleConfig.IconMinSize.x != 0 && mStyleConfig.IconMinSize.y != 0 ) { GfxParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; } else { GfxParams.Flags = UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER; @@ -26,8 +25,8 @@ UIPushButton::UIPushButton( const UIPushButton::CreateParams& Params ) : mIcon = eeNew( UIGfx, ( GfxParams ) ); - if ( Params.IconMinSize.x != 0 && Params.IconMinSize.y != 0 ) { - mIcon->setSize( Params.IconMinSize ); + if ( mStyleConfig.IconMinSize.x != 0 && mStyleConfig.IconMinSize.y != 0 ) { + mIcon->setSize( mStyleConfig.IconMinSize ); } mIcon->setVisible( true ); @@ -38,7 +37,7 @@ UIPushButton::UIPushButton( const UIPushButton::CreateParams& Params ) : UITextBox::CreateParams TxtParams = Params; TxtParams.setParent( this ); TxtParams.Flags = HAlignGet( Params.Flags ) | VAlignGet( Params.Flags ); - TxtParams.FontStyleConfig = Params.FontStyleConfig; + TxtParams.FontStyleConfig = Params.StyleConfig; if ( TxtParams.Flags & UI_CLIP_ENABLE ) TxtParams.Flags &= ~UI_CLIP_ENABLE; @@ -47,7 +46,7 @@ UIPushButton::UIPushButton( const UIPushButton::CreateParams& Params ) : mTextBox->setVisible( true ); mTextBox->setEnabled( false ); - if ( Params.IconAutoMargin ) + if ( mStyleConfig.IconAutoMargin ) mControlFlags |= UI_CTRL_FLAG_FREE_USE; onSizeChange(); @@ -58,26 +57,43 @@ UIPushButton::UIPushButton( const UIPushButton::CreateParams& Params ) : UIPushButton::UIPushButton() : UIComplexControl(), mIcon( NULL ), - mTextBox( NULL ), - mIconSpace( 0 ) + mTextBox( NULL ) { - mFontStyleConfig = UIThemeManager::instance()->getDefaultFontStyleConfig(); + UITheme * theme = UIThemeManager::instance()->getDefaultTheme(); - setFlags( UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER ); + if ( NULL != theme ) { + mStyleConfig = theme->getPushButtonStyleConfig(); + } - mIcon = eeNew( UIGfx, () ); + mFlags |= ( UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER ); + + Uint32 GfxFlags; + + if ( mStyleConfig.IconMinSize.x != 0 && mStyleConfig.IconMinSize.y != 0 ) { + GfxFlags = UI_VALIGN_CENTER | UI_HALIGN_CENTER; + } else { + GfxFlags = UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER; + } + + mIcon = UIGfx::New(); mIcon->setParent( this ); - mIcon->setFlags( UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER ); + mIcon->setFlags( GfxFlags ); + + if ( mStyleConfig.IconMinSize.x != 0 && mStyleConfig.IconMinSize.y != 0 ) { + mIcon->setSize( mStyleConfig.IconMinSize ); + } + mIcon->setVisible( true ); mIcon->setEnabled( false ); - mTextBox = eeNew( UITextBox, () ); + mTextBox = UITextBox::New(); mTextBox->setParent( this ); mTextBox->setVisible( true ); mTextBox->setEnabled( false ); mTextBox->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ); - mControlFlags |= UI_CTRL_FLAG_FREE_USE; // IconAutoMargin + if ( mStyleConfig.IconAutoMargin ) + mControlFlags |= UI_CTRL_FLAG_FREE_USE; onSizeChange(); @@ -114,7 +130,7 @@ void UIPushButton::onSizeChange() { mTextBox->setPosition( 0, 0 ); } - mIcon->setPosition( mIconSpace, 0 ); + mIcon->setPosition( mStyleConfig.IconHorizontalMargin, 0 ); mIcon->centerVertical(); if ( NULL != mTextBox ) { @@ -158,7 +174,7 @@ void UIPushButton::doAfterSetTheme() { if ( mControlFlags & UI_CTRL_FLAG_FREE_USE ) { Recti RMargin = makePadding( true, false, false, false, true ); - mIconSpace = RMargin.Left; + mStyleConfig.IconHorizontalMargin = RMargin.Left; } if ( ( mFlags & UI_AUTO_SIZE ) && NULL != getSkin() ) { @@ -176,9 +192,10 @@ void UIPushButton::autoPadding() { } } -void UIPushButton::setIcon( SubTexture * Icon ) { +UIPushButton * UIPushButton::setIcon( SubTexture * Icon ) { mIcon->setSubTexture( Icon ); onSizeChange(); + return this; } UIGfx * UIPushButton::getIcon() const { @@ -203,12 +220,12 @@ const Recti& UIPushButton::getPadding() const { } void UIPushButton::setIconHorizontalMargin( Int32 margin ) { - mIconSpace = margin; + mStyleConfig.IconHorizontalMargin = margin; onSizeChange(); } const Int32& UIPushButton::getIconHorizontalMargin() const { - return mIconSpace; + return mStyleConfig.IconHorizontalMargin; } UITextBox * UIPushButton::getTextBox() const { @@ -232,9 +249,9 @@ void UIPushButton::onAlphaChange() { void UIPushButton::onStateChange() { if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - mTextBox->setFontColor( mFontStyleConfig.FontOverColor ); + mTextBox->setFontColor( mStyleConfig.FontOverColor ); } else { - mTextBox->setFontColor( mFontStyleConfig.FontColor ); + mTextBox->setFontColor( mStyleConfig.FontColor ); } mTextBox->setAlpha( mAlpha ); @@ -260,20 +277,20 @@ Uint32 UIPushButton::onKeyUp( const UIEventKey& Event ) { return UIComplexControl::onKeyUp( Event ); } const ColorA& UIPushButton::getFontColor() const { - return mFontStyleConfig.FontColor; + return mStyleConfig.FontColor; } void UIPushButton::setFontColor( const ColorA& color ) { - mFontStyleConfig.FontColor = color; + mStyleConfig.FontColor = color; onStateChange(); } const ColorA& UIPushButton::getFontOverColor() const { - return mFontStyleConfig.FontOverColor; + return mStyleConfig.FontOverColor; } void UIPushButton::setFontOverColor( const ColorA& color ) { - mFontStyleConfig.FontOverColor = color; + mStyleConfig.FontOverColor = color; onStateChange(); } @@ -285,12 +302,12 @@ void UIPushButton::setFontShadowColor( const ColorA& color ) { mTextBox->setFontShadowColor( color ); } -FontStyleConfig UIPushButton::getFontStyleConfig() const { - return mFontStyleConfig; +FontStyleConfig UIPushButton::getStyleConfig() const { + return mStyleConfig; } -void UIPushButton::setFontStyleConfig(const FontStyleConfig & fontStyleConfig) { - mFontStyleConfig = fontStyleConfig; +void UIPushButton::setStyleConfig(const PushButtonStyleConfig & fontStyleConfig) { + mStyleConfig = fontStyleConfig; mTextBox->setFontStyleConfig( fontStyleConfig ); onStateChange(); } diff --git a/src/eepp/ui/uiselectbutton.cpp b/src/eepp/ui/uiselectbutton.cpp index 03285f9ed..746a9752b 100644 --- a/src/eepp/ui/uiselectbutton.cpp +++ b/src/eepp/ui/uiselectbutton.cpp @@ -7,11 +7,6 @@ UISelectButton *UISelectButton::New() { return eeNew( UISelectButton, () ); } -UISelectButton::UISelectButton( const UIPushButton::CreateParams& Params ) : - UIPushButton( Params ) -{ -} - UISelectButton::UISelectButton() : UIPushButton() { @@ -71,21 +66,21 @@ void UISelectButton::onStateChange() { } } else { if ( mSkinState->getState() == UISkinState::StateSelected ) { - getTextBox()->setFontColor( mFontStyleConfig.FontSelectedColor ); + getTextBox()->setFontColor( mStyleConfig.FontSelectedColor ); } else if ( mSkinState->getState() == UISkinState::StateMouseEnter ) { - getTextBox()->setFontColor( mFontStyleConfig.FontOverColor ); + getTextBox()->setFontColor( mStyleConfig.FontOverColor ); } else { - getTextBox()->setFontColor( mFontStyleConfig.FontColor ); + getTextBox()->setFontColor( mStyleConfig.FontColor ); } } } void UISelectButton::setFontSelectedColor(const ColorA & color) { - mFontStyleConfig.FontSelectedColor = color; + mStyleConfig.FontSelectedColor = color; } const ColorA &UISelectButton::getFontSelectedColor() const { - return mFontStyleConfig.FontSelectedColor; + return mStyleConfig.FontSelectedColor; } }} diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 2adb9e115..cab23df27 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -4,11 +4,8 @@ namespace EE { namespace UI { -UITab::UITab( UISelectButton::CreateParams& Params, UIControl * controlOwned ) : - UISelectButton( Params ), - mControlOwned( controlOwned ) -{ - applyDefaultTheme(); +UITab *UITab::New() { + return eeNew( UITab, () ); } UITab::UITab() : @@ -123,7 +120,7 @@ void UITab::setText( const String &text ) { void UITab::onAutoSize() { if ( mFlags & UI_AUTO_SIZE ) { - Uint32 w = PixelDensity::pxToDpI( mTextBox->getTextWidth() ) + mIconSpace + ( NULL != mIcon ? mIcon->getSize().getWidth() : 0 ) + getSkinSize().getWidth(); + Uint32 w = PixelDensity::pxToDpI( mTextBox->getTextWidth() ) + mStyleConfig.IconHorizontalMargin + ( NULL != mIcon ? mIcon->getSize().getWidth() : 0 ) + getSkinSize().getWidth(); UITabWidget * tTabW = getTabWidget(); diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 24060b7c0..2e818f836 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -346,16 +346,15 @@ void UITabWidget::orderTabs() { } UITab * UITabWidget::createTab( const String& Text, UIControl * CtrlOwned, SubTexture * Icon ) { - UITab * tCtrl = eeNew( UITab, ( ) ); + UITab * tCtrl = UITab::New(); tCtrl->setParent( mTabContainer ); tCtrl->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER | UI_AUTO_SIZE ); - tCtrl->setFontStyleConfig( mStyleConfig ); + tCtrl->setStyleConfig( mStyleConfig ); tCtrl->setIcon( Icon ); tCtrl->setText( Text ); tCtrl->setVisible( true ); tCtrl->setEnabled( true ); tCtrl->setControlOwned( CtrlOwned ); - CtrlOwned->setParent( mCtrlContainer ); CtrlOwned->setVisible( false ); CtrlOwned->setEnabled( true ); diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index f31775fee..b0d39aea1 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -474,44 +474,6 @@ UIListBox * UITheme::createListBox( UIControl * Parent, const Sizei& Size, const return Ctrl; } -UIPushButton * UITheme::createPushButton( UIControl * Parent, const Sizei& Size, const Vector2i& Pos, const Uint32& Flags, SubTexture * Icon, Int32 IconHorizontalMargin, bool IconAutoMargin ) { - UIPushButton::CreateParams ButtonParams; - ButtonParams.setParent( Parent ); - ButtonParams.setPosition( Pos ); - ButtonParams.setSize( Size ); - ButtonParams.Flags = Flags; - ButtonParams.Icon = Icon; - ButtonParams.IconHorizontalMargin = IconHorizontalMargin; - ButtonParams.IconAutoMargin = IconAutoMargin; - - if ( NULL != Icon ) - ButtonParams.setIcon( Icon ); - - UIPushButton * Ctrl = eeNew( UIPushButton, ( ButtonParams ) ); - Ctrl->setVisible( true ); - Ctrl->setEnabled( true ); - return Ctrl; -} - -UISelectButton * UITheme::createSelectButton( UIControl * Parent, const Sizei& Size, const Vector2i& Pos, const Uint32& Flags, SubTexture * Icon, Int32 IconHorizontalMargin, bool IconAutoMargin ) { - UIPushButton::CreateParams ButtonParams; - ButtonParams.setParent( Parent ); - ButtonParams.setPosition( Pos ); - ButtonParams.setSize( Size ); - ButtonParams.Flags = Flags; - ButtonParams.Icon = Icon; - ButtonParams.IconHorizontalMargin = IconHorizontalMargin; - ButtonParams.IconAutoMargin = IconAutoMargin; - - if ( NULL != Icon ) - ButtonParams.setIcon( Icon ); - - UISelectButton * Ctrl = eeNew( UISelectButton, ( ButtonParams ) ); - Ctrl->setVisible( true ); - Ctrl->setEnabled( true ); - return Ctrl; -} - ColorA UITheme::getTooltipFontColor() const { return mTooltipFontColor; } @@ -556,6 +518,10 @@ MenuStyleConfig UITheme::getMenuStyleConfig() { return MenuStyleConfig( getFontStyleConfig() ); } +PushButtonStyleConfig UITheme::getPushButtonStyleConfig() { + return PushButtonStyleConfig( getFontStyleConfig() ); +} + FontStyleConfig UITheme::getFontStyleConfig() const { return mFontStyleConfig; } diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index cda7cc111..c6da52033 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -32,8 +32,8 @@ UITooltip::UITooltip() : if ( NULL == getFont() ) { if ( NULL != UIThemeManager::instance()->getDefaultFont() ) setFont( UIThemeManager::instance()->getDefaultFont() ); - } else { - eePRINTL( "UITooltip::UITooltip : Created a UI TextBox without a defined font." ); + else + eePRINTL( "UITooltip::UITooltip : Created a UI TextBox without a defined font." ); } autoPadding(); @@ -94,7 +94,7 @@ void UITooltip::hide() { } void UITooltip::draw() { - if ( mVisible && 0.f != mAlpha ) { + if ( mVisible && 0.f != mAlpha && mTextCache->getText().size() > 0 ) { UIControlAnim::draw(); if ( mTextCache->getTextWidth() ) { diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index 316900e42..31dde3592 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -45,7 +45,7 @@ void UIWinMenu::addMenuButton( const String& ButtonText, UIPopUpMenu * Menu ) { if ( mFlags & UI_DRAW_SHADOW ) Button->setFlags( UI_DRAW_SHADOW ); - Button->setFontStyleConfig( mStyleConfig ); + Button->setStyleConfig( mStyleConfig ); Button->setParent( this ); Button->setText( ButtonText ); Button->setVisible( true ); @@ -175,7 +175,7 @@ void UIWinMenu::refreshButtons() { UISelectButton * pbut = it->first; UITextBox * tbox = pbut->getTextBox(); - pbut->setFontStyleConfig( mStyleConfig ); + pbut->setStyleConfig( mStyleConfig ); pbut->setSize( PixelDensity::pxToDpI( tbox->getTextWidth() ) + mStyleConfig.ButtonMargin, getSize().getHeight() ); pbut->setPosition( xpos, ycenter ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 73229a083..c2cd347e5 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -277,7 +277,7 @@ void EETest::createUI() { eePRINTL( "Texture Atlas Loading Time: %4.3f ms.", TE.getElapsed().asMilliseconds() ); - UIManager::instance()->init(UI_MANAGER_DRAW_BOXES); // UI_MANAGER_DRAW_BOXES | UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER + UIManager::instance()->init(UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER | UI_MANAGER_DRAW_DEBUG_DATA); // UI_MANAGER_DRAW_BOXES | UI_MANAGER_HIGHLIGHT_FOCUS | UI_MANAGER_HIGHLIGHT_OVER //mTheme = UITheme::loadFromPath( eeNew( UIdefaultTheme, ( mThemeName, mThemeName ) ), MyPath + mThemeName + "/" ); @@ -579,9 +579,11 @@ void EETest::createUI() { UISkinSimple nSkin( "button-te" ); - mShowMenu = mTheme->createPushButton( NULL, butTex->getSize(), Vector2i( mWindow->getWidth() - butTex->getWidth() - 20, mWindow->getHeight() - butTex->getHeight() - 10 ), UI_CONTROL_ALIGN_CENTER | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); + mShowMenu = UIPushButton::New(); + mShowMenu->setSize( butText->getSize() )->setPosition( mWindow->getWidth() - butTex->getWidth() - 20, mWindow->getHeight() - butTex->getHeight() - 10 ); mShowMenu->setSkin( nSkin ); mShowMenu->setText( "Show Menu" ); + mShowMenu->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); mShowMenu->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &EETest::OnShowMenu ) ); #endif @@ -806,7 +808,9 @@ void EETest::createDecoratedWindow() { mUIWindow->setTitle( "Test Window" ); mUIWindow->toBack(); - UIPushButton * Button = mTheme->createPushButton( mUIWindow->getContainer(), Sizei( 510, 22 ), Vector2i( 10, 28 ), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_ANCHOR_RIGHT ); + UIPushButton * Button = UIPushButton::New(); + Button->setParent( mUIWindow->getContainer() )->setSize( 510, 22 )->setPosition( 10, 28 ); + Button->setAnchors( UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT ); Button->setText( "Click Me" ); Button->addEventListener( UIEvent::EventMouseClick, cb::Make1( this, &EETest::onButtonClick ) );