From 5c1878bd469170df5f9c04e4af83d4bc71fd8558 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Thu, 6 Jun 2019 12:56:38 +0800 Subject: [PATCH] some fixes --- Kiwano/2d/Node.cpp | 19 +++++++++++++------ Kiwano/2d/Node.h | 2 ++ Kiwano/common/IntrusiveList.hpp | 9 ++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Kiwano/2d/Node.cpp b/Kiwano/2d/Node.cpp index 90b23e7b..9ae4377e 100644 --- a/Kiwano/2d/Node.cpp +++ b/Kiwano/2d/Node.cpp @@ -239,10 +239,8 @@ namespace kiwano } } - void Node::SetZOrder(int zorder) + void Node::Reorder() { - z_order_ = zorder; - if (parent_) { NodePtr me = this; @@ -251,12 +249,12 @@ namespace kiwano Node* sibling = parent_->children_.Last().Get(); - if (sibling && sibling->GetZOrder() > zorder) + if (sibling && sibling->GetZOrder() > z_order_) { sibling = sibling->PrevItem().Get(); while (sibling) { - if (sibling->GetZOrder() <= zorder) + if (sibling->GetZOrder() <= z_order_) break; sibling = sibling->PrevItem().Get(); } @@ -273,6 +271,15 @@ namespace kiwano } } + void Node::SetZOrder(int zorder) + { + if (z_order_ != zorder) + { + z_order_ = zorder; + Reorder(); + } + } + void Node::SetOpacity(float opacity) { if (opacity_ == opacity) @@ -473,7 +480,7 @@ namespace kiwano child->SetScene(this->scene_); child->dirty_transform_ = true; child->UpdateOpacity(); - child->SetZOrder(child->GetZOrder()); + child->Reorder(); } } diff --git a/Kiwano/2d/Node.h b/Kiwano/2d/Node.h index 5008fcef..0794ec68 100644 --- a/Kiwano/2d/Node.h +++ b/Kiwano/2d/Node.h @@ -405,6 +405,8 @@ namespace kiwano void SetScene(Scene* scene); + void Reorder(); + protected: bool visible_; bool hover_; diff --git a/Kiwano/common/IntrusiveList.hpp b/Kiwano/common/IntrusiveList.hpp index 65359600..a772a9e2 100644 --- a/Kiwano/common/IntrusiveList.hpp +++ b/Kiwano/common/IntrusiveList.hpp @@ -22,7 +22,9 @@ #include "../macros.h" #include -#ifdef KGE_DEBUG +// #define KGE_DEBUG_ENABLE_LIST_CHECK + +#ifdef KGE_DEBUG_ENABLE_LIST_CHECK # define KGE_DEBUG_CHECK_LIST(list_ptr) list_ptr->Check() #else # define KGE_DEBUG_CHECK_LIST __noop @@ -167,7 +169,7 @@ namespace kiwano void Remove(T const& child) { -#ifdef KGE_DEBUG +#ifdef KGE_DEBUG_ENABLE_LIST_CHECK T tmp = first_; while (tmp != child) { @@ -217,7 +219,7 @@ namespace kiwano last_ = nullptr; } -#ifdef KGE_DEBUG +#ifdef KGE_DEBUG_ENABLE_LIST_CHECK private: void Check() @@ -250,3 +252,4 @@ namespace kiwano } #undef KGE_DEBUG_CHECK_LIST +#undef KGE_DEBUG_ENABLE_LIST_CHECK