From 9ab0bf9cf51140ead5ed61e0caad9a9158b0cc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 2 Dec 2023 21:19:57 -0300 Subject: [PATCH] Some optimizations on Node::nodeDraw. UIPushButton will not create the icon node if not required (not sure yet if this is OK). --- include/eepp/scene/node.hpp | 11 +- include/eepp/ui/models/modelindex.hpp | 10 +- include/eepp/ui/models/sortingproxymodel.hpp | 4 +- include/eepp/ui/uinode.hpp | 4 + include/eepp/ui/uipushbutton.hpp | 4 +- include/eepp/ui/uitreeview.hpp | 54 +-------- projects/linux/ee.files | 77 ++++++++++++ src/eepp/scene/node.cpp | 38 ++++-- src/eepp/scene/scenenode.cpp | 6 +- src/eepp/ui/abstract/uiabstracttableview.cpp | 4 +- src/eepp/ui/models/sortingproxymodel.cpp | 2 +- src/eepp/ui/uicodeeditor.cpp | 2 +- src/eepp/ui/uiconsole.cpp | 2 +- src/eepp/ui/uimenucheckbox.cpp | 1 - src/eepp/ui/uimenuitem.cpp | 2 +- src/eepp/ui/uimenuradiobutton.cpp | 1 - src/eepp/ui/uinode.cpp | 52 +++++--- src/eepp/ui/uipushbutton.cpp | 84 ++++++++----- src/eepp/ui/uisplitter.cpp | 2 +- src/eepp/ui/uitab.cpp | 6 +- src/eepp/ui/uitabwidget.cpp | 4 +- src/eepp/ui/uitextedit.cpp | 2 +- src/eepp/ui/uitextinput.cpp | 6 +- src/eepp/ui/uitextview.cpp | 4 +- src/eepp/ui/uitooltip.cpp | 2 +- src/eepp/ui/uitreeview.cpp | 58 ++++++++- src/eepp/ui/uiwidget.cpp | 22 ++-- src/eepp/ui/uiwidgettable.cpp | 4 +- src/eepp/ui/uiwindow.cpp | 2 +- .../include/eepp/physics/physicsmanager.hpp | 1 - src/tests/ui_perf_test/ui_perf_test.cpp | 112 ++++++++++-------- 31 files changed, 374 insertions(+), 209 deletions(-) diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp index bbefca5b4..e9580065d 100644 --- a/include/eepp/scene/node.hpp +++ b/include/eepp/scene/node.hpp @@ -533,13 +533,13 @@ class EE_API Node : public Transformable { virtual void onSceneChange(); - void clipStart(); - virtual Uint32 onFocus(); virtual Uint32 onFocusLoss(); - void clipEnd(); + void clipStart( bool needsClipPlanes ); + + void clipEnd(bool needsClipPlanes ); void updateScreenPos(); @@ -577,6 +577,11 @@ class EE_API Node : public Transformable { void setChildsDirty(); + void clipSmartEnable(const Int32& x, const Int32& y, const Uint32& Width, + const Uint32& Height, bool needsClipPlanes ); + + void clipSmartDisable( bool needsClipPlanes ); + void clipSmartEnable( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ); diff --git a/include/eepp/ui/models/modelindex.hpp b/include/eepp/ui/models/modelindex.hpp index 322127e40..0efe6a650 100644 --- a/include/eepp/ui/models/modelindex.hpp +++ b/include/eepp/ui/models/modelindex.hpp @@ -5,7 +5,6 @@ #include #include #include -#include namespace EE { namespace UI { namespace Models { @@ -69,4 +68,13 @@ class EE_API ModelIndex { }}} // namespace EE::UI::Models +template <> struct std::hash { + std::size_t operator()( EE::UI::Models::ModelIndex const& modelIndex ) const noexcept { + return hashCombine( reinterpret_cast( modelIndex.model() ), modelIndex.row(), + modelIndex.column(), + reinterpret_cast( modelIndex.internalData() ), + modelIndex.internalId() ); + } +}; + #endif // EE_UI_MODEL_MODELINDEX_HPP diff --git a/include/eepp/ui/models/sortingproxymodel.hpp b/include/eepp/ui/models/sortingproxymodel.hpp index 6cf63fa0a..4795f8dc5 100644 --- a/include/eepp/ui/models/sortingproxymodel.hpp +++ b/include/eepp/ui/models/sortingproxymodel.hpp @@ -64,7 +64,7 @@ class EE_API SortingProxyModel final : public Model, private Model::Client { ModelIndex sourceParent; }; - using InternalMapIterator = std::map>::iterator; + using InternalMapIterator = UnorderedMap>::iterator; SortingProxyModel( std::shared_ptr ); @@ -85,7 +85,7 @@ class EE_API SortingProxyModel final : public Model, private Model::Client { bool isSortingCaseSensitive(); std::shared_ptr mSource; - std::map> mMappings; + UnorderedMap> mMappings; int mKeyColumn{ -1 }; SortOrder mSortOrder{ SortOrder::Ascending }; ModelRole mSortRole{ ModelRole::Sort }; diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index b235ac9c2..06b54dae9 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -421,6 +421,10 @@ class EE_API UINode : public Node { virtual void updateOriginPoint(); + void smartClipStart( const ClipType& reqClipType, bool needsClipPlanes ); + + void smartClipEnd( const ClipType& reqClipType, bool needsClipPlanes ); + void smartClipStart( const ClipType& reqClipType ); void smartClipEnd( const ClipType& reqClipType ); diff --git a/include/eepp/ui/uipushbutton.hpp b/include/eepp/ui/uipushbutton.hpp index 8b78863f1..5ce41a7c0 100644 --- a/include/eepp/ui/uipushbutton.hpp +++ b/include/eepp/ui/uipushbutton.hpp @@ -40,7 +40,9 @@ class EE_API UIPushButton : public UIWidget { virtual UIPushButton* setIcon( Drawable* icon, bool ownIt = false ); - virtual UIImage* getIcon() const; + virtual UIImage* getIcon(); + + bool hasIcon() const; virtual UIPushButton* setText( const String& text ); diff --git a/include/eepp/ui/uitreeview.hpp b/include/eepp/ui/uitreeview.hpp index 2a3e9e051..ec97f270a 100644 --- a/include/eepp/ui/uitreeview.hpp +++ b/include/eepp/ui/uitreeview.hpp @@ -4,8 +4,6 @@ #include #include #include -#include -#include using namespace EE::UI::Abstract; @@ -19,38 +17,13 @@ class EE_API UITreeViewCell : public UITableCell { Uint32 getType() const { return UI_TYPE_TREEVIEW_CELL; } - bool isType( const Uint32& type ) const { - return UITreeViewCell::getType() == type ? true : UITableCell::isType( type ); - } + bool isType( const Uint32& type ) const; UIImage* getImage() const { return mImage; } - Rectf calculatePadding() const { - Sizef size; - Rectf autoPadding; - if ( mFlags & UI_AUTO_PADDING ) { - autoPadding = makePadding( true, true, true, true ); - if ( autoPadding != Rectf() ) - autoPadding = PixelDensity::dpToPx( autoPadding ); - } - if ( mPaddingPx.Top > autoPadding.Top ) - autoPadding.Top = mPaddingPx.Top; - if ( mPaddingPx.Bottom > autoPadding.Bottom ) - autoPadding.Bottom = mPaddingPx.Bottom; - if ( mPaddingPx.Left > autoPadding.Left ) - autoPadding.Left = mPaddingPx.Left; - if ( mPaddingPx.Right > autoPadding.Right ) - autoPadding.Right = mPaddingPx.Right; - autoPadding.Left += mIndent; - return autoPadding; - } + Rectf calculatePadding() const; - void setIndentation( const Float& indent ) { - if ( mIndent != indent ) { - mIndent = indent; - updateLayout(); - } - } + void setIndentation( const Float& indent ); const Float& getIndentation() const { return mIndent; } @@ -58,26 +31,9 @@ class EE_API UITreeViewCell : public UITableCell { mutable UIImage* mImage{ nullptr }; Float mIndent{ 0 }; - UITreeViewCell( const std::function& newTextViewCb = nullptr ) : - UITableCell( "treeview::cell", newTextViewCb ) { - mTextBox->setElementTag( mTag + "::text" ); - mIcon->setElementTag( mTag + "::icon" ); - mInnerWidgetOrientation = InnerWidgetOrientation::WidgetIconTextBox; - auto cb = [this]( const Event* ) { updateLayout(); }; - mImage = UIImage::NewWithTag( mTag + "::expander" ); - mImage->setScaleType( UIScaleType::FitInside ) - ->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) - ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) - ->setParent( const_cast( this ) ) - ->setVisible( false ) - ->setEnabled( false ); - mImage->addEventListener( Event::OnPaddingChange, cb ); - mImage->addEventListener( Event::OnMarginChange, cb ); - mImage->addEventListener( Event::OnSizeChange, cb ); - mImage->addEventListener( Event::OnVisibleChange, cb ); - } + UITreeViewCell( const std::function& newTextViewCb = nullptr ); - virtual UIWidget* getExtraInnerWidget() const { return mImage; } + virtual UIWidget* getExtraInnerWidget() const; }; class EE_API UITreeView : public UIAbstractTableView { diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 07fc61d2f..509ccf92a 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -1172,6 +1172,83 @@ ../../src/modules/eterm/src/eterm/terminal/wide.hpp ../../src/modules/eterm/src/eterm/terminal/windowserrors.hpp ../../src/modules/eterm/src/eterm/ui/uiterminal.cpp +../../src/modules/physics/include/eepp/physics/arbiter.hpp +../../src/modules/physics/include/eepp/physics/area.hpp +../../src/modules/physics/include/eepp/physics/base.hpp +../../src/modules/physics/include/eepp/physics/body.hpp +../../src/modules/physics/include/eepp/physics/constraints/constraint.hpp +../../src/modules/physics/include/eepp/physics/constraints/dampedrotaryspring.hpp +../../src/modules/physics/include/eepp/physics/constraints/dampedspring.hpp +../../src/modules/physics/include/eepp/physics/constraints/gearjoint.hpp +../../src/modules/physics/include/eepp/physics/constraints/groovejoint.hpp +../../src/modules/physics/include/eepp/physics/constraints/pinjoint.hpp +../../src/modules/physics/include/eepp/physics/constraints/pivotjoint.hpp +../../src/modules/physics/include/eepp/physics/constraints/ratchetjoint.hpp +../../src/modules/physics/include/eepp/physics/constraints/rotarylimitjoint.hpp +../../src/modules/physics/include/eepp/physics/constraints/simplemotor.hpp +../../src/modules/physics/include/eepp/physics/constraints/slidejoint.hpp +../../src/modules/physics/include/eepp/physics/moment.hpp +../../src/modules/physics/include/eepp/physics/physics.hpp +../../src/modules/physics/include/eepp/physics/physicshelper.hpp +../../src/modules/physics/include/eepp/physics/physicsmanager.hpp +../../src/modules/physics/include/eepp/physics/settings.hpp +../../src/modules/physics/include/eepp/physics/shape.hpp +../../src/modules/physics/include/eepp/physics/shapecircle.hpp +../../src/modules/physics/include/eepp/physics/shapecirclesprite.hpp +../../src/modules/physics/include/eepp/physics/shapepoint.hpp +../../src/modules/physics/include/eepp/physics/shapepoly.hpp +../../src/modules/physics/include/eepp/physics/shapepolysprite.hpp +../../src/modules/physics/include/eepp/physics/shapesegment.hpp +../../src/modules/physics/include/eepp/physics/space.hpp +../../src/modules/physics/include/eepp/thirdparty/chipmunk/chipmunk.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/chipmunk_ffi.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/chipmunk_private.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/chipmunk_types.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/chipmunk_unsafe.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpConstraint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpDampedRotarySpring.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpDampedSpring.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpGearJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpGrooveJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpPinJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpPivotJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpRatchetJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpRotaryLimitJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpSimpleMotor.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/cpSlideJoint.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/constraints/util.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpArbiter.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpBB.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpBody.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpPolyShape.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpShape.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpSpace.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpSpatialIndex.h +../../src/modules/physics/include/eepp/thirdparty/chipmunk/cpVect.h +../../src/modules/physics/src/eepp/physics/arbiter.cpp +../../src/modules/physics/src/eepp/physics/area.cpp +../../src/modules/physics/src/eepp/physics/body.cpp +../../src/modules/physics/src/eepp/physics/constraints/constraint.cpp +../../src/modules/physics/src/eepp/physics/constraints/dampedrotaryspring.cpp +../../src/modules/physics/src/eepp/physics/constraints/dampedspring.cpp +../../src/modules/physics/src/eepp/physics/constraints/gearjoint.cpp +../../src/modules/physics/src/eepp/physics/constraints/groovejoint.cpp +../../src/modules/physics/src/eepp/physics/constraints/pinjoint.cpp +../../src/modules/physics/src/eepp/physics/constraints/pivotjoint.cpp +../../src/modules/physics/src/eepp/physics/constraints/ratchetjoint.cpp +../../src/modules/physics/src/eepp/physics/constraints/rotarylimitjoint.cpp +../../src/modules/physics/src/eepp/physics/constraints/simplemotor.cpp +../../src/modules/physics/src/eepp/physics/constraints/slidejoint.cpp +../../src/modules/physics/src/eepp/physics/moment.cpp +../../src/modules/physics/src/eepp/physics/physicsmanager.cpp +../../src/modules/physics/src/eepp/physics/shape.cpp +../../src/modules/physics/src/eepp/physics/shapecircle.cpp +../../src/modules/physics/src/eepp/physics/shapecirclesprite.cpp +../../src/modules/physics/src/eepp/physics/shapepoint.cpp +../../src/modules/physics/src/eepp/physics/shapepoly.cpp +../../src/modules/physics/src/eepp/physics/shapepolysprite.cpp +../../src/modules/physics/src/eepp/physics/shapesegment.cpp +../../src/modules/physics/src/eepp/physics/space.cpp ../../src/test/eetest.cpp ../../src/tests/test_all/test.cpp ../../src/tests/test_all/test.hpp diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 35692bc59..770df8501 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -541,13 +541,15 @@ void Node::nodeDraw() { matrixSet(); - clipStart(); + bool needsClipPlanes = isMeOrParentTreeScaledOrRotatedOrFrameBuffer(); + + clipStart( needsClipPlanes ); draw(); drawChilds(); - clipEnd(); + clipEnd( needsClipPlanes ); matrixUnset(); } @@ -573,15 +575,16 @@ Rectf Node::getScreenRect() const { return Rectf( getScreenPos(), getPixelsSize() ); } -void Node::clipStart() { +void Node::clipStart( bool needsClipPlanes ) { if ( mVisible && isClipped() ) { - clipSmartEnable( mScreenPos.x, mScreenPos.y, mSize.getWidth(), mSize.getHeight() ); + clipSmartEnable( mScreenPos.x, mScreenPos.y, mSize.getWidth(), mSize.getHeight(), + needsClipPlanes ); } } -void Node::clipEnd() { +void Node::clipEnd( bool needsClipPlanes ) { if ( mVisible && isClipped() ) { - clipSmartDisable(); + clipSmartDisable( needsClipPlanes ); } } @@ -1071,7 +1074,7 @@ bool Node::isMeOrParentTreeScaled() const { bool Node::isMeOrParentTreeScaledOrRotated() const { const Node* node = this; while ( NULL != node ) { - if ( node->isScaled() || node->isRotated() ) + if ( node->mNodeFlags & ( NODE_FLAG_SCALED | NODE_FLAG_ROTATED ) ) return true; node = node->getParent(); } @@ -1081,9 +1084,9 @@ bool Node::isMeOrParentTreeScaledOrRotated() const { bool Node::isMeOrParentTreeScaledOrRotatedOrFrameBuffer() const { const Node* node = this; while ( NULL != node ) { - if ( node->isScaled() || node->isRotated() || node->isFrameBuffer() ) + if ( node->mNodeFlags & ( NODE_FLAG_SCALED | NODE_FLAG_ROTATED | NODE_FLAG_FRAME_BUFFER ) ) return true; - node = node->getParent(); + node = node->mParentNode; } return false; } @@ -1718,22 +1721,31 @@ Node* Node::clipDisable() { } void Node::clipSmartEnable( const Int32& x, const Int32& y, const Uint32& Width, - const Uint32& Height ) { - if ( isMeOrParentTreeScaledOrRotatedOrFrameBuffer() ) { + const Uint32& Height, bool needsClipPlanes ) { + if ( needsClipPlanes ) { GLi->getClippingMask()->clipPlaneEnable( x, y, Width, Height ); } else { GLi->getClippingMask()->clipEnable( x, y, Width, Height ); } } -void Node::clipSmartDisable() { - if ( isMeOrParentTreeScaledOrRotatedOrFrameBuffer() ) { +void Node::clipSmartDisable( bool needsClipPlanes ) { + if ( needsClipPlanes ) { GLi->getClippingMask()->clipPlaneDisable(); } else { GLi->getClippingMask()->clipDisable(); } } +void Node::clipSmartEnable( const Int32& x, const Int32& y, const Uint32& Width, + const Uint32& Height ) { + clipSmartEnable( x, y, Width, Height, isMeOrParentTreeScaledOrRotatedOrFrameBuffer() ); +} + +void Node::clipSmartDisable() { + clipSmartDisable( isMeOrParentTreeScaledOrRotatedOrFrameBuffer() ); +} + Node* Node::getDrawInvalidator() { Node* node = mParentNode; while ( node != NULL ) { diff --git a/src/eepp/scene/scenenode.cpp b/src/eepp/scene/scenenode.cpp index d6e66f3f6..ee85034f1 100644 --- a/src/eepp/scene/scenenode.cpp +++ b/src/eepp/scene/scenenode.cpp @@ -106,11 +106,13 @@ void SceneNode::draw() { matrixSet(); if ( NULL == mFrameBuffer || !usesInvalidation() || invalidated() ) { - clipStart(); + bool needsClipPlanes = isMeOrParentTreeScaledOrRotatedOrFrameBuffer(); + + clipStart( needsClipPlanes ); drawChilds(); - clipEnd(); + clipEnd( needsClipPlanes ); } matrixUnset(); diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index 10f1e9a55..5e4933ca4 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -476,7 +476,6 @@ UITableRow* UIAbstractTableView::createRow() { } else { getSelection().set( index ); } - } ); onRowCreated( rowWidget ); return rowWidget; @@ -636,7 +635,8 @@ UIWidget* UIAbstractTableView::updateCell( const int& rowIndex, const ModelIndex isVisible = true; cell->setIcon( icon.asIcon()->getSize( mIconSize ) ); } - cell->getIcon()->setVisible( isVisible ); + if ( cell->hasIcon() ) + cell->getIcon()->setVisible( isVisible ); cell->updateCell( getModel() ); } diff --git a/src/eepp/ui/models/sortingproxymodel.cpp b/src/eepp/ui/models/sortingproxymodel.cpp index 1b2fc8c05..e3414eccf 100644 --- a/src/eepp/ui/models/sortingproxymodel.cpp +++ b/src/eepp/ui/models/sortingproxymodel.cpp @@ -93,7 +93,7 @@ SortingProxyModel::buildMapping( const ModelIndex& sourceParent ) { auto sourceGrandParent = sourceParent.parent(); buildMapping( sourceGrandParent ); } - mMappings.insert( std::make_pair( sourceParent, mapping ) ); + mMappings.insert( { sourceParent, mapping } ); return mMappings.find( sourceParent ); } diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 266381f8a..efaf5b6bb 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -2204,7 +2204,7 @@ bool UICodeEditor::applyProperty( const StyleSheetProperty& attribute ) { setFontSelectionBackColor( attribute.asColor() ); break; case PropertyId::FontFamily: { - Font* font = FontManager::instance()->getByName( attribute.asString() ); + Font* font = FontManager::instance()->getByName( attribute.value() ); if ( NULL != font && font->loaded() ) { setFont( font ); } diff --git a/src/eepp/ui/uiconsole.cpp b/src/eepp/ui/uiconsole.cpp index 652ea5ed4..24628d707 100644 --- a/src/eepp/ui/uiconsole.cpp +++ b/src/eepp/ui/uiconsole.cpp @@ -178,7 +178,7 @@ bool UIConsole::applyProperty( const StyleSheetProperty& attribute ) { setFontSelectionBackColor( attribute.asColor() ); break; case PropertyId::FontFamily: { - Font* font = FontManager::instance()->getByName( attribute.asString() ); + Font* font = FontManager::instance()->getByName( attribute.value() ); if ( NULL != font && font->loaded() ) { setFont( font ); diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index 977df0730..6e7230cfb 100644 --- a/src/eepp/ui/uimenucheckbox.cpp +++ b/src/eepp/ui/uimenucheckbox.cpp @@ -10,7 +10,6 @@ UIMenuCheckBox* UIMenuCheckBox::New() { UIMenuCheckBox::UIMenuCheckBox() : UIMenuItem( "menu::checkbox" ), mActive( false ), mSkinActive( NULL ), mSkinInactive( NULL ) { - mIcon->setElementTag( mTag + "::icon" ); mTextBox->setElementTag( mTag + "::text" ); applyDefaultTheme(); mIcon->setFlags( UI_SKIN_KEEP_SIZE_ON_DRAW ); diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index 24327dc66..a50339a87 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -11,9 +11,9 @@ UIMenuItem* UIMenuItem::New() { } UIMenuItem::UIMenuItem( const std::string& tag ) : UIPushButton( tag ), mShortcutView( NULL ) { + getIcon(); unsetFlags( UI_AUTO_SIZE ); setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::WrapContent ); - mIcon->setElementTag( mTag + "::icon" ); mTextBox->setElementTag( mTag + "::text" ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uimenuradiobutton.cpp b/src/eepp/ui/uimenuradiobutton.cpp index dbf226b3c..3bd71d8e9 100644 --- a/src/eepp/ui/uimenuradiobutton.cpp +++ b/src/eepp/ui/uimenuradiobutton.cpp @@ -13,7 +13,6 @@ UIMenuRadioButton::UIMenuRadioButton() : mActive( false ), mSkinActive( NULL ), mSkinInactive( NULL ) { - mIcon->setElementTag( mTag + "::icon" ); mTextBox->setElementTag( mTag + "::text" ); applyDefaultTheme(); mIcon->setFlags( UI_SKIN_KEEP_SIZE_ON_DRAW ); diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 7ca769205..3c1c61684 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -1006,7 +1006,7 @@ void UINode::drawBorder() { } } -void UINode::smartClipStart( const ClipType& reqClipType ) { +void UINode::smartClipStart( const ClipType& reqClipType, bool needsClipPlanes ) { if ( mClip.getClipType() != reqClipType ) return; switch ( mClip.getClipType() ) { @@ -1014,11 +1014,12 @@ void UINode::smartClipStart( const ClipType& reqClipType ) { const Rectf& pd = getPixelsPadding(); clipSmartEnable( mScreenPos.x + pd.Left, mScreenPos.y + pd.Top, mSize.getWidth() - pd.Left - pd.Right, - mSize.getHeight() - pd.Top - pd.Bottom ); + mSize.getHeight() - pd.Top - pd.Bottom, needsClipPlanes ); break; } case ClipType::ContentBox: { - clipSmartEnable( mScreenPos.x, mScreenPos.y, mSize.getWidth(), mSize.getHeight() ); + clipSmartEnable( mScreenPos.x, mScreenPos.y, mSize.getWidth(), mSize.getHeight(), + needsClipPlanes ); break; } case ClipType::BorderBox: { @@ -1027,7 +1028,7 @@ void UINode::smartClipStart( const ClipType& reqClipType ) { borderDiff = mBorder->getBorderBoxDiff(); clipSmartEnable( mScreenPos.x + borderDiff.Left, mScreenPos.y + borderDiff.Top, mSize.getWidth() + borderDiff.Right, - mSize.getHeight() + borderDiff.Bottom ); + mSize.getHeight() + borderDiff.Bottom, needsClipPlanes ); break; } case ClipType::None: { @@ -1036,12 +1037,20 @@ void UINode::smartClipStart( const ClipType& reqClipType ) { } } -void UINode::smartClipEnd( const ClipType& reqClipType ) { +void UINode::smartClipEnd( const ClipType& reqClipType, bool needsClipPlanes ) { if ( mVisible && isClipped() && mClip.getClipType() == reqClipType ) { - clipEnd(); + clipEnd( needsClipPlanes ); } } +void UINode::smartClipStart( const ClipType& reqClipType ) { + smartClipStart( reqClipType, isMeOrParentTreeScaledOrRotatedOrFrameBuffer() ); +} + +void UINode::smartClipEnd( const ClipType& reqClipType ) { + smartClipEnd( reqClipType, isMeOrParentTreeScaledOrRotatedOrFrameBuffer() ); +} + void UINode::nodeDraw() { if ( mVisible ) { if ( mNodeFlags & NODE_FLAG_POSITION_DIRTY ) @@ -1052,10 +1061,14 @@ void UINode::nodeDraw() { matrixSet(); - smartClipStart( ClipType::BorderBox ); + bool needsClipPlanes = isMeOrParentTreeScaledOrRotatedOrFrameBuffer(); - if ( mWorldBounds.intersect( mSceneNode->getWorldBounds() ) ) { - smartClipStart( ClipType::ContentBox ); + smartClipStart( ClipType::BorderBox, needsClipPlanes ); + + bool intersected = mWorldBounds.intersect( mSceneNode->getWorldBounds() ); + + if ( intersected ) { + smartClipStart( ClipType::ContentBox, needsClipPlanes ); if ( 0.f != mAlpha ) { drawBackground(); @@ -1063,36 +1076,39 @@ void UINode::nodeDraw() { drawSkin(); } - smartClipStart( ClipType::PaddingBox ); + smartClipStart( ClipType::PaddingBox, needsClipPlanes ); draw(); drawChilds(); - smartClipEnd( ClipType::PaddingBox ); + smartClipEnd( ClipType::PaddingBox, needsClipPlanes ); if ( 0.f != mAlpha ) drawForeground(); - smartClipEnd( ClipType::ContentBox ); + smartClipEnd( ClipType::ContentBox, needsClipPlanes ); } else if ( !isClipped() ) { drawChilds(); } - drawBorder(); + if ( intersected ) + drawBorder(); if ( mNodeFlags & NODE_FLAG_DROPPABLE_HOVERING ) drawDroppableHovering(); - drawHighlightFocus(); + if ( intersected ) { + drawHighlightFocus(); - drawOverNode(); + drawOverNode(); - updateDebugData(); + updateDebugData(); - drawBox(); + drawBox(); + } - smartClipEnd( ClipType::BorderBox ); + smartClipEnd( ClipType::BorderBox, needsClipPlanes ); matrixUnset(); } diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 3ca44608e..2885fb5b7 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -65,21 +65,8 @@ UIPushButton::UIPushButton( const std::string& tag, UIWidget( tag ), mIcon( NULL ), mTextBox( NULL ) { mFlags |= ( UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER ); - mIcon = UIImage::NewWithTag( tag + "::icon" ); - mIcon->setScaleType( UIScaleType::FitInside ) - ->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) - ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) - ->setParent( this ) - ->setVisible( true ) - ->setEnabled( false ); - auto cb = [this]( const Event* ) { onSizeChange(); }; - mIcon->addEventListener( Event::OnPaddingChange, cb ); - mIcon->addEventListener( Event::OnMarginChange, cb ); - mIcon->addEventListener( Event::OnSizeChange, cb ); - mIcon->addEventListener( Event::OnVisibleChange, cb ); - mTextBox = newTextViewCb ? newTextViewCb( this ) : UITextView::NewWithTag( tag + "::text" ); mTextBox->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent ) ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) @@ -255,18 +242,16 @@ UIWidget* UIPushButton::getFirstInnerItem() const { case InnerWidgetOrientation::WidgetIconTextBox: return getExtraInnerWidget() && getExtraInnerWidget()->isVisible() ? getExtraInnerWidget() - : mIcon; + : ( mIcon && mIcon->isVisible() ? mIcon->asType() + : mTextBox->asType() ); case InnerWidgetOrientation::IconWidgetTextBox: - return mIcon->isVisible() + return mIcon && mIcon->isVisible() ? mIcon : ( getExtraInnerWidget() && getExtraInnerWidget()->isVisible() ? getExtraInnerWidget() : mTextBox ); case InnerWidgetOrientation::IconTextBoxWidget: - if ( mIcon->isVisible() ) - return mIcon; - else - return mTextBox; + return mIcon && mIcon->isVisible() ? mIcon->asType() : mTextBox; case InnerWidgetOrientation::WidgetTextBoxIcon: return ( getExtraInnerWidget() && getExtraInnerWidget()->isVisible() ) ? getExtraInnerWidget() @@ -274,12 +259,14 @@ UIWidget* UIPushButton::getFirstInnerItem() const { case InnerWidgetOrientation::TextBoxIconWidget: if ( mTextBox->isVisible() ) return mTextBox; - if ( mIcon->isVisible() ) + if ( mIcon && mIcon->isVisible() ) return mIcon; + return getExtraInnerWidget(); break; case InnerWidgetOrientation::TextBoxWidgetIcon: if ( mTextBox->isVisible() ) return mTextBox; + break; } return mChild->isWidget() ? mChild->asType() : nullptr; @@ -360,18 +347,46 @@ void UIPushButton::updateTextBox() { } UIPushButton* UIPushButton::setIcon( Drawable* icon, bool ownIt ) { - if ( mIcon->getDrawable() != icon ) { - mIcon->setPixelsSize( icon->getPixelsSize() ); - mIcon->setDrawable( icon, ownIt ); + if ( nullptr == mIcon || mIcon->getDrawable() != icon ) { + if ( icon ) + getIcon()->setPixelsSize( icon->getPixelsSize() ); + if ( icon == nullptr && mIcon == nullptr ) + return this; + getIcon()->setDrawable( icon, ownIt ); updateTextBox(); } return this; } -UIImage* UIPushButton::getIcon() const { +UIImage* UIPushButton::getIcon() { + if ( nullptr == mIcon ) { + auto cb = [this]( const Event* ) { onSizeChange(); }; + + mIcon = UIImage::NewWithTag( mTag + "::icon" ); + mIcon->setScaleType( UIScaleType::FitInside ) + ->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) + ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) + ->setParent( this ) + ->setVisible( true ) + ->setEnabled( false ); + + mIcon->addEventListener( Event::OnPaddingChange, cb ); + mIcon->addEventListener( Event::OnMarginChange, cb ); + mIcon->addEventListener( Event::OnSizeChange, cb ); + mIcon->addEventListener( Event::OnVisibleChange, cb ); + + if ( mIconMinSize != Sizei::Zero ) { + mIconMinSize = Sizei{ -1, -1 }; // force refresh + setIconMinimumSize( mIconMinSize ); + } + } return mIcon; } +bool UIPushButton::hasIcon() const { + return mIcon != nullptr; +} + UIPushButton* UIPushButton::setText( const String& text ) { if ( text != mTextBox->getText() ) { mTextBox->setVisible( !text.empty() ); @@ -393,7 +408,8 @@ UITextView* UIPushButton::getTextBox() const { void UIPushButton::onAlphaChange() { UIWidget::onAlphaChange(); - mIcon->setAlpha( mAlpha ); + if ( mIcon ) + mIcon->setAlpha( mAlpha ); mTextBox->setAlpha( mAlpha ); if ( NULL != getExtraInnerWidget() ) { @@ -437,7 +453,7 @@ void UIPushButton::setIconMinimumSize( const Sizei& minIconSize ) { if ( minIconSize != mIconMinSize ) { mIconMinSize = minIconSize; - if ( mIconMinSize.x != 0 && mIconMinSize.y != 0 ) { + if ( mIcon && mIconMinSize.x != 0 && mIconMinSize.y != 0 ) { mIcon->setMinSizeEq( String::fromFloat( mIconMinSize.x, "dp" ), String::fromFloat( mIconMinSize.y, "dp" ) ); } @@ -523,8 +539,11 @@ std::string UIPushButton::getPropertyString( const PropertyDefinition* propertyD : "left" ); case PropertyId::TextAsFallback: return mTextAsFallback ? "true" : "false"; - case PropertyId::Tint: - return mIcon->getColor().toHexString(); + case PropertyId::Tint: { + if ( mIcon ) + return mIcon->getColor().toHexString(); + return Color::Transparent.toHexString(); + } case PropertyId::Color: case PropertyId::TextShadowColor: case PropertyId::TextShadowOffset: @@ -580,14 +599,14 @@ bool UIPushButton::applyProperty( const StyleSheetProperty& attribute ) { switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::InnerWidgetOrientation: - setInnerWidgetOrientation( innerWidgetOrientationFromString( attribute.asString() ) ); + setInnerWidgetOrientation( innerWidgetOrientationFromString( attribute.value() ) ); break; case PropertyId::Text: if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) - setText( getUISceneNode()->getTranslatorString( attribute.asString() ) ); + setText( getUISceneNode()->getTranslatorString( attribute.value() ) ); break; case PropertyId::Icon: { - std::string val = attribute.asString(); + const std::string& val = attribute.value(); Drawable* icon = NULL; bool ownIt; UIIcon* iconF = getUISceneNode()->findIcon( val ); @@ -620,7 +639,8 @@ bool UIPushButton::applyProperty( const StyleSheetProperty& attribute ) { setTextAsFallback( attribute.asBool() ); break; case PropertyId::Tint: - mIcon->setColor( attribute.asColor() ); + if ( mIcon ) + mIcon->setColor( attribute.asColor() ); break; case PropertyId::Color: case PropertyId::TextShadowColor: diff --git a/src/eepp/ui/uisplitter.cpp b/src/eepp/ui/uisplitter.cpp index 1a3ba6ea6..dfd09a68f 100644 --- a/src/eepp/ui/uisplitter.cpp +++ b/src/eepp/ui/uisplitter.cpp @@ -120,7 +120,7 @@ bool UISplitter::applyProperty( const StyleSheetProperty& attribute ) { switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::SplitterPartition: - setSplitPartition( StyleSheetLength( attribute.asString() ) ); + setSplitPartition( StyleSheetLength( attribute.value() ) ); case PropertyId::SplitterAlwaysShow: setAlwaysShowSplitter( attribute.asBool() ); case PropertyId::Orientation: { diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 4937e2431..d1e0df9d1 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -13,10 +13,8 @@ UITab* UITab::New() { UITab::UITab() : UISelectButton( "tab" ), mOwnedWidget( NULL ), mDragTotalDiff( 0.f ), mTabWidget( NULL ) { mTextBox->setElementTag( mTag + "::text" ); - mIcon->setElementTag( mTag + "::icon" ); auto cb = [this]( const Event* ) { onSizeChange(); }; mTextBox->addEventListener( Event::OnSizeChange, cb ); - mIcon->addEventListener( Event::OnSizeChange, cb ); mCloseButton = UIWidget::NewWithTag( mTag + "::close" ); mCloseButton->setParent( const_cast( this ) ); mCloseButton->setEnabled( false ); @@ -303,10 +301,10 @@ bool UITab::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::Text: if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) setText( static_cast( mSceneNode ) - ->getTranslatorString( attribute.asString() ) ); + ->getTranslatorString( attribute.value() ) ); break; case PropertyId::Owns: - mOwnedName = attribute.asString(); + mOwnedName = attribute.value(); setOwnedNode(); break; default: diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 34e61048f..56346160f 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -245,10 +245,10 @@ bool UITabWidget::applyProperty( const StyleSheetProperty& attribute ) { setMaxTextLength( attribute.asUint( 1 ) ); break; case PropertyId::MinTabWidth: - setMinTabWidth( attribute.asString() ); + setMinTabWidth( attribute.value() ); break; case PropertyId::MaxTabWidth: - setMaxTabWidth( attribute.asString() ); + setMaxTabWidth( attribute.value() ); break; case PropertyId::TabClosable: setTabsClosable( attribute.asBool() ); diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index 9b345c81f..b27516d93 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -104,7 +104,7 @@ bool UITextEdit::applyProperty( const StyleSheetProperty& attribute ) { switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::Text: - setText( attribute.asString() ); + setText( attribute.value() ); break; default: return UICodeEditor::applyProperty( attribute ); diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index e95338604..feaf6317e 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -511,7 +511,7 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::Text: - setText( getTranslatorString( attribute.asString() ) ); + setText( getTranslatorString( attribute.value() ) ); break; case PropertyId::AllowEditing: setAllowEditing( attribute.asBool() ); @@ -526,7 +526,7 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { setAllowOnlyNumbers( onlyNumbersAllowed(), attribute.asBool() ); break; case PropertyId::Hint: - setHint( getTranslatorString( attribute.asString() ) ); + setHint( getTranslatorString( attribute.value() ) ); break; case PropertyId::HintColor: setHintColor( attribute.asColor() ); @@ -541,7 +541,7 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { setHintFontSize( lengthFromValue( attribute ) ); break; case PropertyId::HintFontFamily: - setHintFont( FontManager::instance()->getByName( attribute.asString() ) ); + setHintFont( FontManager::instance()->getByName( attribute.value() ) ); break; case PropertyId::HintFontStyle: setHintFontStyle( attribute.asFontStyle() ); diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index 1be98a6f1..52922e534 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -679,7 +679,7 @@ bool UITextView::applyProperty( const StyleSheetProperty& attribute ) { switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::Text: - setText( getTranslatorString( attribute.asString() ) ); + setText( getTranslatorString( attribute.value() ) ); break; case PropertyId::TextTransform: setTextTransform( TextTransform::fromString( attribute.asString() ) ); @@ -701,7 +701,7 @@ bool UITextView::applyProperty( const StyleSheetProperty& attribute ) { setSelectionBackColor( attribute.asColor() ); break; case PropertyId::FontFamily: { - Font* font = FontManager::instance()->getByName( attribute.asString() ); + Font* font = FontManager::instance()->getByName( attribute.value() ); if ( NULL != font && font->loaded() ) { setFont( font ); diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 85a8bfdfb..4363d7f28 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -521,7 +521,7 @@ bool UITooltip::applyProperty( const StyleSheetProperty& attribute ) { setFontShadowOffset( attribute.asVector2f() ); break; case PropertyId::FontFamily: { - Font* font = FontManager::instance()->getByName( attribute.asString() ); + Font* font = FontManager::instance()->getByName( attribute.value() ); if ( !mUsingCustomStyling && NULL != font && font->loaded() ) setFont( font ); diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 6824389f0..6b711719b 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -316,7 +316,7 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, } } - if ( hasChilds && mExpandersAsIcons && cell->getIcon() ) { + if ( hasChilds && mExpandersAsIcons && cell->hasIcon() ) { cell->getIcon()->setVisible( false ); return widget; } @@ -330,7 +330,8 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, isVisible = true; cell->setIcon( icon.asIcon()->getSize( mIconSize ) ); } - cell->getIcon()->setVisible( isVisible ); + if ( cell->hasIcon() ) + cell->getIcon()->setVisible( isVisible ); cell->updateCell( getModel() ); } @@ -862,4 +863,57 @@ void UITreeView::onModelSelectionChange() { mFocusSelectionDirty = true; } +bool UITreeViewCell::isType( const Uint32& type ) const { + return UITreeViewCell::getType() == type ? true : UITableCell::isType( type ); +} + +Rectf UITreeViewCell::calculatePadding() const { + Sizef size; + Rectf autoPadding; + if ( mFlags & UI_AUTO_PADDING ) { + autoPadding = makePadding( true, true, true, true ); + if ( autoPadding != Rectf() ) + autoPadding = PixelDensity::dpToPx( autoPadding ); + } + if ( mPaddingPx.Top > autoPadding.Top ) + autoPadding.Top = mPaddingPx.Top; + if ( mPaddingPx.Bottom > autoPadding.Bottom ) + autoPadding.Bottom = mPaddingPx.Bottom; + if ( mPaddingPx.Left > autoPadding.Left ) + autoPadding.Left = mPaddingPx.Left; + if ( mPaddingPx.Right > autoPadding.Right ) + autoPadding.Right = mPaddingPx.Right; + autoPadding.Left += mIndent; + return autoPadding; +} + +void UITreeViewCell::setIndentation( const Float& indent ) { + if ( mIndent != indent ) { + mIndent = indent; + updateLayout(); + } +} + +UITreeViewCell::UITreeViewCell( const std::function& newTextViewCb ) : + UITableCell( "treeview::cell", newTextViewCb ) { + mTextBox->setElementTag( mTag + "::text" ); + mInnerWidgetOrientation = InnerWidgetOrientation::WidgetIconTextBox; + auto cb = [this]( const Event* ) { updateLayout(); }; + mImage = UIImage::NewWithTag( mTag + "::expander" ); + mImage->setScaleType( UIScaleType::FitInside ) + ->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ) + ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) + ->setParent( const_cast( this ) ) + ->setVisible( false ) + ->setEnabled( false ); + mImage->addEventListener( Event::OnPaddingChange, cb ); + mImage->addEventListener( Event::OnMarginChange, cb ); + mImage->addEventListener( Event::OnSizeChange, cb ); + mImage->addEventListener( Event::OnVisibleChange, cb ); +} + +UIWidget* UITreeViewCell::getExtraInnerWidget() const { + return mImage; +} + }} // namespace EE::UI diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index fbc5b407e..f50515647 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -1488,7 +1488,7 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { setEnabled( attribute.asBool() ); break; case PropertyId::Theme: - setThemeByName( attribute.asString() ); + setThemeByName( attribute.value() ); if ( !mSkinName.empty() ) setThemeSkin( mSkinName ); break; @@ -1580,7 +1580,7 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { setLayoutMarginBottom( lengthFromValueAsDp( attribute ) ); break; case PropertyId::Tooltip: { - String text = getTranslatorString( attribute.asString() ); + String text = getTranslatorString( attribute.value() ); setTooltipText( text ); if ( NULL != mTooltip ) mTooltip->setStringBuffer( text ); @@ -1681,7 +1681,7 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { rule = PositionPolicy::TopOf; else if ( layoutId == PropertyId::LayoutToBottomOf ) rule = PositionPolicy::BottomOf; - std::string id = attribute.asString(); + const std::string& id = attribute.value(); Node* node = getParent()->find( id ); if ( NULL != node && node->isWidget() ) { UIWidget* widget = static_cast( node ); @@ -1772,28 +1772,28 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { setBorderEnabled( true )->setColorBottom( attribute.asColor() ); break; case PropertyId::BorderLeftWidth: - setBorderEnabled( true )->setLeftWidth( attribute.asString() ); + setBorderEnabled( true )->setLeftWidth( attribute.value() ); break; case PropertyId::BorderRightWidth: - setBorderEnabled( true )->setRightWidth( attribute.asString() ); + setBorderEnabled( true )->setRightWidth( attribute.value() ); break; case PropertyId::BorderTopWidth: - setBorderEnabled( true )->setTopWidth( attribute.asString() ); + setBorderEnabled( true )->setTopWidth( attribute.value() ); break; case PropertyId::BorderBottomWidth: - setBorderEnabled( true )->setBottomWidth( attribute.asString() ); + setBorderEnabled( true )->setBottomWidth( attribute.value() ); break; case PropertyId::BorderTopLeftRadius: - setTopLeftRadius( attribute.asString() ); + setTopLeftRadius( attribute.value() ); break; case PropertyId::BorderBottomLeftRadius: - setBottomLeftRadius( attribute.asString() ); + setBottomLeftRadius( attribute.value() ); break; case PropertyId::BorderTopRightRadius: - setTopRightRadius( attribute.asString() ); + setTopRightRadius( attribute.value() ); break; case PropertyId::BorderBottomRightRadius: - setBottomRightRadius( attribute.asString() ); + setBottomRightRadius( attribute.value() ); break; case PropertyId::BorderSmooth: setBorderEnabled( true )->setSmooth( attribute.asBool() ); diff --git a/src/eepp/ui/uiwidgettable.cpp b/src/eepp/ui/uiwidgettable.cpp index a75351f16..f715d4e39 100644 --- a/src/eepp/ui/uiwidgettable.cpp +++ b/src/eepp/ui/uiwidgettable.cpp @@ -696,7 +696,7 @@ bool UIWidgetTable::applyProperty( const StyleSheetProperty& attribute ) { setRowHeight( attribute.asDpDimensionI( this ) ); break; case PropertyId::VScrollMode: { - std::string val = attribute.asString(); + const std::string& val = attribute.value(); if ( "auto" == val ) setVerticalScrollMode( ScrollBarMode::Auto ); else if ( "on" == val ) @@ -706,7 +706,7 @@ bool UIWidgetTable::applyProperty( const StyleSheetProperty& attribute ) { break; } case PropertyId::HScrollMode: { - std::string val = attribute.asString(); + const std::string& val = attribute.value(); if ( "auto" == val ) setHorizontalScrollMode( ScrollBarMode::Auto ); else if ( "on" == val ) diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index d39311a8c..8f23d5540 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1643,7 +1643,7 @@ bool UIWindow::applyProperty( const StyleSheetProperty& attribute ) { setSize( getSize().getWidth(), attribute.asDpDimension( this ) ); break; case PropertyId::WindowTitle: - setTitle( getUISceneNode()->getTranslatorString( attribute.asString() ) ); + setTitle( getUISceneNode()->getTranslatorString( attribute.value() ) ); break; case PropertyId::WindowOpacity: setWindowOpacity( (Uint8)eemin( (Uint32)attribute.asFloat() * 255.f, 255u ) ); diff --git a/src/modules/physics/include/eepp/physics/physicsmanager.hpp b/src/modules/physics/include/eepp/physics/physicsmanager.hpp index f9a16040e..b1b8ab3ed 100644 --- a/src/modules/physics/include/eepp/physics/physicsmanager.hpp +++ b/src/modules/physics/include/eepp/physics/physicsmanager.hpp @@ -2,7 +2,6 @@ #define EE_PHYSICS_PHYSICSMANAGER_HPP #include -#include namespace EE { namespace Physics { diff --git a/src/tests/ui_perf_test/ui_perf_test.cpp b/src/tests/ui_perf_test/ui_perf_test.cpp index d60b03f5c..d10296b9c 100644 --- a/src/tests/ui_perf_test/ui_perf_test.cpp +++ b/src/tests/ui_perf_test/ui_perf_test.cpp @@ -125,25 +125,34 @@ void mainLoop() { uiSceneNode->setDrawDebugData( !uiSceneNode->getDrawDebugData() ); } + if ( win->getInput()->isKeyUp( KEY_F11 ) ) { + UIWidgetInspector::create( uiSceneNode ); + } + // Update the UI scene. SceneManager::instance()->update(); // Check if the UI has been invalidated ( needs redraw ). - if ( SceneManager::instance()->getUISceneNode()->invalidated() ) { + if ( true || SceneManager::instance()->getUISceneNode()->invalidated() ) { win->clear(); // Redraw the UI scene. SceneManager::instance()->draw(); + Text::draw( + String( String::format( "FPS: %d", win->getFPS() ) ), { 16, 16 }, + SceneManager::instance()->getUISceneNode()->getUIThemeManager()->getDefaultFont(), 12.f, + Color::White, 0, 1.f, Color::Black ); + win->display(); } else { - Sys::sleep( Milliseconds( 8 ) ); + // win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); } } EE_MAIN_FUNC int main( int, char*[] ) { - win = Engine::instance()->createWindow( WindowSettings( 1024, 768, "eepp - UI Perf Test" ), - ContextSettings( true ) ); + win = Engine::instance()->createWindow( WindowSettings( 1366, 768, "eepp - UI Perf Test" ), + ContextSettings( false ) ); if ( win->isOpen() ) { FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); @@ -198,72 +207,77 @@ EE_MAIN_FUNC int main( int, char*[] ) { UITableView* view = UITableView::New(); // view->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); view->setId( "treeview" ); - /*view->setExpandedIcon( open ); - view->setContractedIcon( closed );*/ view->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); view->setParent( vlay ); view->setModel( SortingProxyModel::New( model ) ); - // view->setModel( model ); Log::notice( "Total time: %.2fms", clock.getElapsedTime().asMilliseconds() ); - UIWindow* uiWin = UIWindow::NewOpt( UIWindow::LINEAR_LAYOUT ); - uiWin->setMinWindowSize( 500, 400 ); - uiWin->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); - UITreeView* widgetTree = UITreeView::New(); - widgetTree->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); - widgetTree->setParent( uiWin ); - widgetTree->setHeadersVisible( false ); - widgetTree->setAutoExpandOnSingleColumn( true ); - widgetTree->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); - widgetTree->setModel( WidgetTreeModel::New( uiSceneNode ) ); - - /* ListBox test *//* - std::vector strings; - for ( size_t i = 0; i < 10000; i++ ) - strings.emplace_back( String::format( - "This is a very long string number %ld. Cover the full width of the listbox.", - i ) ); - auto* lbox = UIListBox::New(); - std::cout << "Time New: " << clock.getElapsed().asMilliseconds() << " ms" << std::endl; - lbox->setParent( vlay ); - std::cout << "Time setParent: " << clock.getElapsed().asMilliseconds() << " ms" - << std::endl; - lbox->setLayoutMargin( Rectf( 4, 4, 4, 4 ) ); - std::cout << "Time setLayoutMargin: " << clock.getElapsed().asMilliseconds() << " ms" - << std::endl; - lbox->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); - std::cout << "Time setLayoutSizePolicy: " << clock.getElapsed().asMilliseconds() << " ms" - << std::endl; - for ( size_t i = 0; i < 10; i++ ) - lbox->addListBoxItem( String::format( + /* ListBox test */ /* + std::vector strings; + for ( size_t i = 0; i < 10000; i++ ) + strings.emplace_back( String::format( "This is a very long string number %ld. Cover the full width of the listbox.", i ) ); - std::cout << "Time addListBoxItem: " << clock.getElapsed().asMilliseconds() << " ms" - << std::endl; - lbox->addListBoxItems( strings ); - std::cout << "Time addListBoxItems: " << clock.getElapsed().asMilliseconds() << " ms" - << std::endl;*/ + auto* lbox = UIListBox::New(); + std::cout << "Time New: " << clock.getElapsed().asMilliseconds() << " ms" << std::endl; + lbox->setParent( vlay ); + std::cout << "Time setParent: " << clock.getElapsed().asMilliseconds() << " ms" + << std::endl; + lbox->setLayoutMargin( Rectf( 4, 4, 4, 4 ) ); + std::cout << "Time setLayoutMargin: " << clock.getElapsed().asMilliseconds() << " ms" + << std::endl; + lbox->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); + std::cout << "Time setLayoutSizePolicy: " << clock.getElapsed().asMilliseconds() << " ms" + << std::endl; + for ( size_t i = 0; i < 10; i++ ) + lbox->addListBoxItem( String::format( + "This is a very long string number %ld. Cover the full width of the listbox.", + i ) ); + std::cout << "Time addListBoxItem: " << clock.getElapsed().asMilliseconds() << " ms" + << std::endl; + lbox->addListBoxItems( strings ); + std::cout << "Time addListBoxItems: " << clock.getElapsed().asMilliseconds() << " ms" + << std::endl;*/ /* Create Widget test */ Clock total; /*for ( size_t i = 0; i < 10000; i++ ) { UINode::New(); } - std::cout << "Time UINode total: " << total.getElapsedTime().asMilliseconds() << " ms" - << std::endl; - + std::cout << "Time UINode total: " << total.getElapsedTime().toString() << std::endl; uiSceneNode->getRoot()->childsCloseAll(); total.restart(); for ( size_t i = 0; i < 10000; i++ ) { UIWidget::New(); } - std::cout << "Time UIWidget total: " << total.getElapsedTime().asMilliseconds() << " ms" - << std::endl; + std::cout << "Time UIWidget total: " << total.getElapsedTime().toString() << std::endl; + uiSceneNode->getRoot()->childsCloseAll();*/ - uiSceneNode->getRoot()->childsCloseAll(); + /*auto* rl = UIRelativeLayout::New(); + rl->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); - SceneManager::instance()->update();*/ + auto* sv = UIScrollView::New(); + sv->setParent( rl ); + sv->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); + auto* parent = UILinearLayout::NewVertical(); + parent->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ); + parent->setParent( sv ); + + total.restart(); + for ( size_t i = 0; i < 10000; i++ ) { + auto* but = UIPushButton::New(); + but->setText( String::format( "Button %zu", i ) ); + but->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ); + but->setParent( parent )->clipEnable(); + } + std::cout << "Time UIPushButton total: " << total.getElapsedTime().toString() << std::endl; + + // uiSceneNode->getRoot()->childsCloseAll(); + total.restart(); + SceneManager::instance()->update(); + std::cout << "SceneManager::instance()->update(): " << total.getElapsedTime().toString() + << std::endl;*/ /*total.restart(); for ( size_t i = 0; i < 100000; i++ ) {