diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index 01aa81e5..f20b1ee3 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -10,6 +10,7 @@
+
@@ -111,6 +112,7 @@
+
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index fa289faa..cb14a7c6 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -324,6 +324,9 @@
render
+
+ 2d
+
@@ -539,5 +542,8 @@
render
+
+ 2d
+
\ No newline at end of file
diff --git a/src/kiwano-imgui/ImGuiModule.cpp b/src/kiwano-imgui/ImGuiModule.cpp
index 396967e1..4d9763f9 100644
--- a/src/kiwano-imgui/ImGuiModule.cpp
+++ b/src/kiwano-imgui/ImGuiModule.cpp
@@ -189,8 +189,14 @@ void ImGuiModule::UpdateMouseCursor()
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
return;
+ static ImGuiMouseCursor last_cursor = ImGuiMouseCursor_None;
+ if (ImGui::GetMouseCursor() == last_cursor)
+ return;
+
+ last_cursor = ImGui::GetMouseCursor();
+
CursorType cursor = CursorType::Arrow;
- switch (ImGui::GetMouseCursor())
+ switch (last_cursor)
{
case ImGuiMouseCursor_Arrow:
cursor = CursorType::Arrow;
diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp
index 963efbb4..82624667 100644
--- a/src/kiwano/2d/Actor.cpp
+++ b/src/kiwano/2d/Actor.cpp
@@ -199,11 +199,9 @@ bool Actor::DispatchEvent(Event* evt)
child = child->GetPrev();
}
- if (!EventDispatcher::DispatchEvent(evt))
+ if (!HandleEvent(evt))
return false;
- HandleEvent(evt);
-
while (child)
{
if (!child->DispatchEvent(evt))
@@ -214,8 +212,22 @@ bool Actor::DispatchEvent(Event* evt)
return true;
}
-void Actor::HandleEvent(Event* evt)
+bool Actor::HandleEvent(Event* evt)
{
+ if (!components_.IsEmpty())
+ {
+ ComponentPtr next;
+ for (auto component = components_.GetFirst(); component; component = next)
+ {
+ next = component->GetNext();
+
+ component->HandleEvent(evt);
+ }
+ }
+
+ if (!EventDispatcher::DispatchEvent(evt))
+ return false;
+
if (responsible_)
{
if (evt->IsType())
@@ -228,7 +240,7 @@ void Actor::HandleEvent(Event* evt)
MouseHoverEventPtr hover = new MouseHoverEvent;
hover->pos = mouse_evt->pos;
- EventDispatcher::DispatchEvent(hover.Get());
+ HandleEvent(hover.Get());
}
else if (hover_ && !contains)
{
@@ -237,7 +249,7 @@ void Actor::HandleEvent(Event* evt)
MouseOutEventPtr out = new MouseOutEvent;
out->pos = mouse_evt->pos;
- EventDispatcher::DispatchEvent(out.Get());
+ HandleEvent(out.Get());
}
}
@@ -255,9 +267,10 @@ void Actor::HandleEvent(Event* evt)
MouseClickEventPtr click = new MouseClickEvent;
click->pos = mouse_up_evt->pos;
click->button = mouse_up_evt->button;
- EventDispatcher::DispatchEvent(click.Get());
+ HandleEvent(click.Get());
}
}
+ return true;
}
const Matrix3x2& Actor::GetTransformMatrix() const
@@ -405,16 +418,6 @@ void Actor::SetAnchor(Vec2 const& anchor)
dirty_transform_ = true;
}
-void Actor::SetWidth(float width)
-{
- SetSize(Size{ width, size_.y });
-}
-
-void Actor::SetHeight(float height)
-{
- SetSize(Size{ size_.x, height });
-}
-
void Actor::SetSize(Size const& size)
{
if (size_ == size)
@@ -454,21 +457,6 @@ void Actor::SetPosition(const Point& pos)
dirty_transform_ = true;
}
-void Actor::SetPositionX(float x)
-{
- SetPosition(Point{ x, transform_.position.y });
-}
-
-void Actor::SetPositionY(float y)
-{
- SetPosition(Point{ transform_.position.x, y });
-}
-
-void Actor::Move(Vec2 const& v)
-{
- this->SetPosition(Point{ transform_.position.x + v.x, transform_.position.y + v.y });
-}
-
void Actor::SetScale(Vec2 const& scale)
{
if (transform_.scale == scale)
@@ -583,12 +571,12 @@ ActorPtr Actor::GetChild(String const& name) const
return nullptr;
}
-Actor::Children& Actor::GetAllChildren()
+ActorList& Actor::GetAllChildren()
{
return children_;
}
-Actor::Children const& Actor::GetAllChildren() const
+ActorList const& Actor::GetAllChildren() const
{
return children_;
}
@@ -601,6 +589,54 @@ void Actor::RemoveFromParent()
}
}
+Component* Actor::AddComponent(ComponentPtr component)
+{
+ return this->AddComponent(component.Get());
+}
+
+Component* Actor::AddComponent(Component* component)
+{
+ KGE_ASSERT(component && "AddComponent failed, NULL pointer exception");
+
+ if (component)
+ {
+ components_.PushBack(component);
+ }
+ return component;
+}
+
+ComponentList& Actor::GetAllComponents()
+{
+ return components_;
+}
+
+const ComponentList& Actor::GetAllComponents() const
+{
+ return components_;
+}
+
+void Actor::RemoveComponents(String const& name)
+{
+ if (!components_.IsEmpty())
+ {
+ ComponentPtr next;
+ for (auto component = components_.GetFirst(); component; component = next)
+ {
+ next = component->GetNext();
+
+ if (component->IsName(name))
+ {
+ components_.Remove(component);
+ }
+ }
+ }
+}
+
+void Actor::RemoveAllComponents()
+{
+ components_.Clear();
+}
+
void Actor::RemoveChild(ActorPtr child)
{
RemoveChild(child.Get());
diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h
index 9e838f19..045fc1e0 100644
--- a/src/kiwano/2d/Actor.h
+++ b/src/kiwano/2d/Actor.h
@@ -19,13 +19,13 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
#include
#include
#include
-#include
+#include
#include
+#include
+#include
namespace kiwano
{
@@ -35,6 +35,11 @@ class RenderContext;
KGE_DECLARE_SMART_PTR(Actor);
+
+/// \~chinese
+/// @brief 角色列表
+typedef IntrusiveList ActorList;
+
/**
* \~chinese
* \defgroup Actors 基础角色
@@ -63,13 +68,9 @@ class KGE_API Actor
friend IntrusiveList;
public:
- /// \~chinese
- /// @brief 子成员列表
- using Children = IntrusiveList;
-
/// \~chinese
/// @brief 角色更新回调函数
- using UpdateCallback = Function;
+ typedef Function UpdateCallback;
/// \~chinese
/// @brief 创建角色
@@ -343,11 +344,11 @@ public:
/// \~chinese
/// @brief 获取全部子角色
- Children& GetAllChildren();
+ ActorList& GetAllChildren();
/// \~chinese
/// @brief 获取全部子角色
- Children const& GetAllChildren() const;
+ ActorList const& GetAllChildren() const;
/// \~chinese
/// @brief 移除子角色
@@ -369,6 +370,33 @@ public:
/// @brief 从父角色移除
void RemoveFromParent();
+ /// \~chinese
+ /// @brief 添加组件
+ /// @param component 组件
+ Component* AddComponent(ComponentPtr component);
+
+ /// \~chinese
+ /// @brief 添加组件
+ /// @param component 组件
+ Component* AddComponent(Component* component);
+
+ /// \~chinese
+ /// @brief 获取所有组件
+ ComponentList& GetAllComponents();
+
+ /// \~chinese
+ /// @brief 获取所有组件
+ const ComponentList& GetAllComponents() const;
+
+ /// \~chinese
+ /// @brief 移除组件
+ /// @param name 组件名称
+ void RemoveComponents(String const& name);
+
+ /// \~chinese
+ /// @brief 移除所有组件
+ void RemoveAllComponents();
+
/// \~chinese
/// @brief 暂停角色更新
void PauseUpdating();
@@ -446,7 +474,7 @@ protected:
/// \~chinese
/// @brief 处理事件
- void HandleEvent(Event* evt);
+ bool HandleEvent(Event* evt);
private:
bool visible_;
@@ -464,7 +492,8 @@ private:
size_t hash_name_;
Point anchor_;
Size size_;
- Children children_;
+ ActorList children_;
+ ComponentList components_;
UpdateCallback cb_update_;
Transform transform_;
@@ -666,32 +695,57 @@ inline void Actor::ShowBorder(bool show)
inline void Actor::SetPosition(float x, float y)
{
- SetPosition(Point{ x, y });
+ this->SetPosition(Point(x, y));
+}
+
+inline void Actor::SetPositionX(float x)
+{
+ this->SetPosition(Point(x, transform_.position.y));
+}
+
+inline void Actor::SetPositionY(float y)
+{
+ this->SetPosition(Point(transform_.position.x, y));
+}
+
+inline void Actor::Move(Vec2 const& v)
+{
+ this->SetPosition(transform_.position.x + v.x, transform_.position.y + v.y);
}
inline void Actor::Move(float vx, float vy)
{
- Move(Vec2{ vx, vy });
+ this->Move(Vec2(vx, vy));
}
inline void Actor::SetScale(float scalex, float scaley)
{
- SetScale(Vec2{ scalex, scaley });
+ this->SetScale(Vec2(scalex, scaley));
}
inline void Actor::SetAnchor(float anchorx, float anchory)
{
- SetAnchor(Vec2{ anchorx, anchory });
+ this->SetAnchor(Vec2(anchorx, anchory));
}
inline void Actor::SetSize(float width, float height)
{
- SetSize(Size{ width, height });
+ this->SetSize(Size(width, height));
+}
+
+inline void Actor::SetWidth(float width)
+{
+ this->SetSize(Size(width, size_.y));
+}
+
+inline void Actor::SetHeight(float height)
+{
+ this->SetSize(Size(size_.x, height));
}
inline void Actor::SetSkew(float skewx, float skewy)
{
- SetSkew(Vec2{ skewx, skewy });
+ this->SetSkew(Vec2(skewx, skewy));
}
} // namespace kiwano
diff --git a/src/kiwano/2d/Button.cpp b/src/kiwano/2d/Button.cpp
index d112f4a3..bcb10afb 100644
--- a/src/kiwano/2d/Button.cpp
+++ b/src/kiwano/2d/Button.cpp
@@ -24,13 +24,37 @@
namespace kiwano
{
+
+ButtonPtr Button::Create(ActorPtr actor, Callback const& click)
+{
+ return Button::Create(actor, click, nullptr, nullptr, nullptr);
+}
+
+ButtonPtr Button::Create(ActorPtr actor, Callback const& click, Callback const& pressed, Callback const& mouse_over,
+ Callback const& mouse_out)
+{
+ ButtonPtr ptr = new (std::nothrow) Button;
+ if (ptr)
+ {
+ ptr->BindActor(actor);
+ ptr->SetClickCallback(click);
+ ptr->SetPressedCallback(pressed);
+ ptr->SetMouseOverCallback(mouse_over);
+ ptr->SetMouseOutCallback(mouse_out);
+ }
+ return ptr;
+}
+
Button::Button()
: enabled_(true)
, status_(Status::Normal)
{
}
-Button::~Button() {}
+Button::~Button()
+{
+ Unbind();
+}
bool Button::IsEnable() const
{
@@ -65,6 +89,11 @@ void Button::SetMouseOutCallback(const Callback& func)
mouse_out_callback_ = func;
}
+Button::Status Button::GetStatus() const
+{
+ return status_;
+}
+
void Button::SetStatus(Status status)
{
if (status_ != status)
@@ -76,7 +105,7 @@ void Button::SetStatus(Status status)
Application::GetInstance().GetMainWindow()->SetCursor(CursorType::Arrow);
if (mouse_out_callback_)
- mouse_out_callback_(this);
+ mouse_out_callback_(this, actor_);
}
else if (status == Status::Hover)
{
@@ -85,25 +114,20 @@ void Button::SetStatus(Status status)
if (old_status != Status::Pressed)
{
if (mouse_over_callback_)
- mouse_over_callback_(this);
+ mouse_over_callback_(this, actor_);
}
}
else if (status == Status::Pressed)
{
if (pressed_callback_)
- pressed_callback_(this);
+ pressed_callback_(this, actor_);
}
status_ = status;
}
}
-Button::Status Button::GetStatus() const
-{
- return status_;
-}
-
-void Button::UpdateStatus(Event* evt)
+void Button::HandleEvent(Event* evt)
{
if (!enabled_)
return;
@@ -127,78 +151,17 @@ void Button::UpdateStatus(Event* evt)
else if (evt->IsType())
{
if (click_callback_)
- click_callback_(this);
+ click_callback_(this, actor_);
}
}
void Button::BindActor(Actor* actor)
{
- actor->SetResponsible(true);
-
- EventListener::Callback handler = Closure(this, &Button::UpdateStatus);
- actor->AddListener(handler);
- actor->AddListener(handler);
- actor->AddListener(handler);
- actor->AddListener(handler);
- actor->AddListener(handler);
-}
-
-SpriteButton::SpriteButton()
-{
- BindActor(this);
-}
-
-SpriteButtonPtr SpriteButton::Create(Callback const& click)
-{
- SpriteButtonPtr ptr = new (std::nothrow) SpriteButton;
- if (ptr)
+ Component::BindActor(actor);
+ if (actor)
{
- ptr->SetClickCallback(click);
+ actor->SetResponsible(true);
}
- return ptr;
-}
-
-SpriteButtonPtr SpriteButton::Create(Callback const& click, Callback const& pressed, Callback const& mouse_over,
- Callback const& mouse_out)
-{
- SpriteButtonPtr ptr = new (std::nothrow) SpriteButton;
- if (ptr)
- {
- ptr->SetClickCallback(click);
- ptr->SetPressedCallback(pressed);
- ptr->SetMouseOverCallback(mouse_over);
- ptr->SetMouseOutCallback(mouse_out);
- }
- return ptr;
-}
-
-TextButton::TextButton()
-{
- BindActor(this);
-}
-
-TextButtonPtr TextButton::Create(Callback const& click)
-{
- TextButtonPtr ptr = new (std::nothrow) TextButton;
- if (ptr)
- {
- ptr->SetClickCallback(click);
- }
- return ptr;
-}
-
-TextButtonPtr TextButton::Create(Callback const& click, Callback const& pressed, Callback const& mouse_over,
- Callback const& mouse_out)
-{
- TextButtonPtr ptr = new (std::nothrow) TextButton;
- if (ptr)
- {
- ptr->SetClickCallback(click);
- ptr->SetPressedCallback(pressed);
- ptr->SetMouseOverCallback(mouse_over);
- ptr->SetMouseOutCallback(mouse_out);
- }
- return ptr;
}
} // namespace kiwano
diff --git a/src/kiwano/2d/Button.h b/src/kiwano/2d/Button.h
index e1ebc063..de41c305 100644
--- a/src/kiwano/2d/Button.h
+++ b/src/kiwano/2d/Button.h
@@ -19,25 +19,39 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
+#include
namespace kiwano
{
+
KGE_DECLARE_SMART_PTR(Button);
-KGE_DECLARE_SMART_PTR(SpriteButton);
-KGE_DECLARE_SMART_PTR(TextButton);
/**
* \~chinese
* @brief 按钮
*/
-class KGE_API Button : public virtual ObjectBase
+class KGE_API Button : public Component
{
public:
/// \~chinese
/// @brief 按钮回调函数
- using Callback = Function;
+ using Callback = Function;
+
+ /// \~chinese
+ /// @brief 创建按钮
+ /// @param actor 绑定的角色
+ /// @param click 按钮点击回调函数
+ static ButtonPtr Create(ActorPtr actor, Callback const& click);
+
+ /// \~chinese
+ /// @brief 创建按钮
+ /// @param actor 绑定的角色
+ /// @param click 按钮点击回调函数
+ /// @param pressed 按钮按下回调函数
+ /// @param mouse_over 按钮移入回调函数
+ /// @param mouse_out 按钮移出回调函数
+ static ButtonPtr Create(ActorPtr actor, Callback const& click, Callback const& pressed, Callback const& mouse_over,
+ Callback const& mouse_out);
Button();
@@ -67,6 +81,15 @@ public:
/// @brief 设置鼠标移出按钮时的回调函数
void SetMouseOutCallback(const Callback& func);
+ /// \~chinese
+ /// @brief 绑定到角色
+ void BindActor(ActorPtr actor);
+
+ /// \~chinese
+ /// @brief 绑定到角色
+ void BindActor(Actor* actor) override;
+
+protected:
/// \~chinese
/// @brief 按钮状态
enum class Status
@@ -76,22 +99,17 @@ public:
Pressed ///< 被按下
};
+ /// \~chinese
+ /// @brief 获取按钮状态
+ Status GetStatus() const;
+
/// \~chinese
/// @brief 设置按钮状态
void SetStatus(Status status);
/// \~chinese
- /// @brief 获取按钮状态
- Status GetStatus() const;
-
-protected:
- /// \~chinese
- /// @brief 更新按钮状态
- void UpdateStatus(Event* evt);
-
- /// \~chinese
- /// @brief 绑定到角色
- void BindActor(Actor* actor);
+ /// @brief 处理角色事件
+ void HandleEvent(Event* evt) override;
private:
bool enabled_;
@@ -102,51 +120,9 @@ private:
Callback mouse_out_callback_;
};
-/// \~chinese
-/// @brief 精灵按钮
-class SpriteButton
- : public Sprite
- , public Button
+inline void Button::BindActor(ActorPtr actor)
{
-public:
- SpriteButton();
-
- /// \~chinese
- /// @brief 创建精灵按钮
- /// @param click 按钮点击回调函数
- static SpriteButtonPtr Create(Callback const& click);
-
- /// \~chinese
- /// @brief 创建精灵按钮
- /// @param click 按钮点击回调函数
- /// @param pressed 按钮按下回调函数
- /// @param mouse_over 按钮移入回调函数
- /// @param mouse_out 按钮移出回调函数
- static SpriteButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over,
- Callback const& mouse_out);
-};
-
-/// \~chinese
-/// @brief 文字按钮
-class TextButton
- : public TextActor
- , public Button
-{
-public:
- TextButton();
-
- /// \~chinese
- /// @brief 创建文字按钮
- /// @param click 按钮点击回调函数
- static TextButtonPtr Create(Callback const& click);
-
- /// \~chinese
- /// @brief 创建文字按钮
- /// @param click 按钮点击回调函数
- /// @param pressed 按钮按下回调函数
- /// @param mouse_over 按钮移入回调函数
- /// @param mouse_out 按钮移出回调函数
- static TextButtonPtr Create(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
-};
+ this->BindActor(actor.Get());
+}
} // namespace kiwano
diff --git a/src/kiwano/2d/Component.cpp b/src/kiwano/2d/Component.cpp
new file mode 100644
index 00000000..5af4f3f9
--- /dev/null
+++ b/src/kiwano/2d/Component.cpp
@@ -0,0 +1,50 @@
+// Copyright (c) 2016-2018 Kiwano - Nomango
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#include
+
+namespace kiwano
+{
+
+Component::Component()
+ : actor_(nullptr)
+{
+}
+
+Component::~Component()
+{
+ Unbind();
+}
+
+void Component::BindActor(Actor* actor)
+{
+ if (actor_)
+ {
+ Unbind();
+ }
+ actor_ = actor;
+}
+
+void Component::Unbind()
+{
+ actor_ = nullptr;
+}
+
+} // namespace kiwano
diff --git a/src/kiwano/2d/Component.h b/src/kiwano/2d/Component.h
new file mode 100644
index 00000000..6c9045e0
--- /dev/null
+++ b/src/kiwano/2d/Component.h
@@ -0,0 +1,84 @@
+// Copyright (c) 2016-2018 Kiwano - Nomango
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#pragma once
+#include
+#include
+
+namespace kiwano
+{
+
+class Actor;
+class Event;
+
+KGE_DECLARE_SMART_PTR(Component);
+
+/// \~chinese
+/// @brief 组件列表
+typedef IntrusiveList ComponentList;
+
+/**
+ * \~chinese
+ * @brief 组件
+ */
+class KGE_API Component
+ : public virtual ObjectBase
+ , protected IntrusiveListValue
+{
+ friend class Actor;
+ friend IntrusiveList;
+
+public:
+ /// \~chinese
+ /// @brief 绑定到角色
+ virtual void BindActor(Actor* actor);
+
+ /// \~chinese
+ /// @brief 取消绑定到角色
+ virtual void Unbind();
+
+ /// \~chinese
+ /// @brief 获取绑定的角色
+ Actor* GetBoundActor() const;
+
+protected:
+ Component();
+
+ virtual ~Component();
+
+ /// \~chinese
+ /// @brief 处理角色事件
+ virtual void HandleEvent(Event* evt);
+
+protected:
+ Actor* actor_;
+};
+
+inline Actor* Component::GetBoundActor() const
+{
+ return actor_;
+}
+
+inline void Component::HandleEvent(Event* event)
+{
+ KGE_NOT_USED(event);
+}
+
+} // namespace kiwano
diff --git a/src/kiwano/2d/TextActor.cpp b/src/kiwano/2d/TextActor.cpp
index 094b86e2..5a8e2169 100644
--- a/src/kiwano/2d/TextActor.cpp
+++ b/src/kiwano/2d/TextActor.cpp
@@ -67,43 +67,6 @@ Size TextActor::GetSize() const
return Actor::GetSize();
}
-void TextActor::SetFillColor(Color const& color)
-{
- BrushPtr brush = layout_->GetDefaultFillBrush();
- if (brush)
- {
- brush->SetColor(color);
- }
- else
- {
- layout_->SetDefaultFillBrush(Brush::Create(color));
- }
-}
-
-void TextActor::SetOutlineColor(Color const& outline_color)
-{
- BrushPtr brush = layout_->GetDefaultOutlineBrush();
- if (brush)
- {
- brush->SetColor(outline_color);
- }
- else
- {
- layout_->SetDefaultOutlineBrush(Brush::Create(outline_color));
- }
-}
-
-void TextActor::SetTextLayout(TextLayoutPtr layout)
-{
- KGE_ASSERT(layout && "TextLayout must not be nullptr");
-
- if (layout_ != layout)
- {
- layout_ = layout;
- ForceUpdateLayout();
- }
-}
-
void TextActor::SetText(String const& text)
{
layout_->Reset(text, style_);
@@ -232,6 +195,41 @@ void TextActor::SetOutlineStrokeStyle(StrokeStylePtr stroke)
}
}
+void TextActor::SetFillColor(Color const& color)
+{
+ if (style_.fill_brush)
+ {
+ style_.fill_brush->SetColor(color);
+ }
+ else
+ {
+ SetFillBrush(Brush::Create(color));
+ }
+}
+
+void TextActor::SetOutlineColor(Color const& outline_color)
+{
+ if (style_.outline_brush)
+ {
+ style_.outline_brush->SetColor(outline_color);
+ }
+ else
+ {
+ SetFillBrush(Brush::Create(outline_color));
+ }
+}
+
+void TextActor::SetTextLayout(TextLayoutPtr layout)
+{
+ KGE_ASSERT(layout && "TextLayout must not be nullptr");
+
+ if (layout_ != layout)
+ {
+ layout_ = layout;
+ ForceUpdateLayout();
+ }
+}
+
void TextActor::Update(Duration dt)
{
this->UpdateDirtyLayout();
diff --git a/src/kiwano/2d/action/Action.h b/src/kiwano/2d/action/Action.h
index da1a4acf..c430d6e7 100644
--- a/src/kiwano/2d/action/Action.h
+++ b/src/kiwano/2d/action/Action.h
@@ -33,6 +33,10 @@ class ActionManager;
KGE_DECLARE_SMART_PTR(Action);
+/// \~chinese
+/// @brief 动画列表
+typedef IntrusiveList ActionList;
+
/**
* \~chinese
* \defgroup Actions 动画
diff --git a/src/kiwano/2d/action/ActionManager.cpp b/src/kiwano/2d/action/ActionManager.cpp
index 426636e1..52ec1acd 100644
--- a/src/kiwano/2d/action/ActionManager.cpp
+++ b/src/kiwano/2d/action/ActionManager.cpp
@@ -103,7 +103,7 @@ ActionPtr ActionManager::GetAction(String const& name)
return nullptr;
}
-const ActionManager::Actions& ActionManager::GetAllActions() const
+const ActionList& ActionManager::GetAllActions() const
{
return actions_;
}
diff --git a/src/kiwano/2d/action/ActionManager.h b/src/kiwano/2d/action/ActionManager.h
index e46987e7..2334bd2e 100644
--- a/src/kiwano/2d/action/ActionManager.h
+++ b/src/kiwano/2d/action/ActionManager.h
@@ -35,10 +35,6 @@ namespace kiwano
class KGE_API ActionManager
{
public:
- /// \~chinese
- /// @brief 动画列表
- using Actions = IntrusiveList;
-
/// \~chinese
/// @brief 添加动画
Action* AddAction(ActionPtr action);
@@ -66,7 +62,7 @@ public:
/// \~chinese
/// @brief 获取所有动画
- Actions const& GetAllActions() const;
+ const ActionList& GetAllActions() const;
protected:
/// \~chinese
@@ -74,7 +70,7 @@ protected:
void UpdateActions(Actor* target, Duration dt);
private:
- Actions actions_;
+ ActionList actions_;
};
/** @} */
diff --git a/src/kiwano/core/EventDispatcher.cpp b/src/kiwano/core/EventDispatcher.cpp
index 3c349f19..286ca092 100644
--- a/src/kiwano/core/EventDispatcher.cpp
+++ b/src/kiwano/core/EventDispatcher.cpp
@@ -73,33 +73,33 @@ EventListener* EventDispatcher::AddListener(EventType type, EventListener::Callb
return AddListener(listener);
}
-void EventDispatcher::StartListeners(String const& listener_name)
+void EventDispatcher::StartListeners(String const& name)
{
for (auto& listener : listeners_)
{
- if (listener.IsName(listener_name))
+ if (listener.IsName(name))
{
listener.Start();
}
}
}
-void EventDispatcher::StopListeners(String const& listener_name)
+void EventDispatcher::StopListeners(String const& name)
{
for (auto& listener : listeners_)
{
- if (listener.IsName(listener_name))
+ if (listener.IsName(name))
{
listener.Stop();
}
}
}
-void EventDispatcher::RemoveListeners(String const& listener_name)
+void EventDispatcher::RemoveListeners(String const& name)
{
for (auto& listener : listeners_)
{
- if (listener.IsName(listener_name))
+ if (listener.IsName(name))
{
listener.Remove();
}
@@ -163,7 +163,7 @@ void EventDispatcher::RemoveAllListeners()
}
}
-const EventDispatcher::Listeners& EventDispatcher::GetAllListeners() const
+const ListenerList& EventDispatcher::GetAllListeners() const
{
return listeners_;
}
diff --git a/src/kiwano/core/EventDispatcher.h b/src/kiwano/core/EventDispatcher.h
index 42b1b19f..741e8d4d 100644
--- a/src/kiwano/core/EventDispatcher.h
+++ b/src/kiwano/core/EventDispatcher.h
@@ -30,10 +30,6 @@ namespace kiwano
class KGE_API EventDispatcher
{
public:
- /// \~chinese
- /// @brief 监听器列表
- using Listeners = IntrusiveList;
-
/// \~chinese
/// @brief 添加监听器
EventListener* AddListener(EventListenerPtr listener);
@@ -120,7 +116,7 @@ public:
/// \~chinese
/// @brief 获取所有监听器
- const Listeners& GetAllListeners() const;
+ const ListenerList& GetAllListeners() const;
/// \~chinese
/// @brief 分发事件
@@ -129,6 +125,6 @@ public:
bool DispatchEvent(Event* evt);
private:
- Listeners listeners_;
+ ListenerList listeners_;
};
} // namespace kiwano
diff --git a/src/kiwano/core/EventListener.h b/src/kiwano/core/EventListener.h
index c9044427..129b739b 100644
--- a/src/kiwano/core/EventListener.h
+++ b/src/kiwano/core/EventListener.h
@@ -34,6 +34,10 @@ class EventDispatcher;
KGE_DECLARE_SMART_PTR(EventListener);
+/// \~chinese
+/// @brief 监听器列表
+typedef IntrusiveList ListenerList;
+
/**
* \~chinese
* @brief 事件监听器
diff --git a/src/kiwano/core/Timer.h b/src/kiwano/core/Timer.h
index 0847d1f2..9bd36517 100644
--- a/src/kiwano/core/Timer.h
+++ b/src/kiwano/core/Timer.h
@@ -29,6 +29,10 @@ class TimerManager;
KGE_DECLARE_SMART_PTR(Timer);
+/// \~chinese
+/// @brief 定时器列表
+typedef IntrusiveList TimerList;
+
/// \~chinese
/// @brief 定时器
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
diff --git a/src/kiwano/core/TimerManager.cpp b/src/kiwano/core/TimerManager.cpp
index 3e241620..44d747b9 100644
--- a/src/kiwano/core/TimerManager.cpp
+++ b/src/kiwano/core/TimerManager.cpp
@@ -133,7 +133,7 @@ void TimerManager::RemoveAllTimers()
timers_.Clear();
}
-const TimerManager::Timers& TimerManager::GetAllTimers() const
+const TimerList& TimerManager::GetAllTimers() const
{
return timers_;
}
diff --git a/src/kiwano/core/TimerManager.h b/src/kiwano/core/TimerManager.h
index 9a53c9c6..5419c4d7 100644
--- a/src/kiwano/core/TimerManager.h
+++ b/src/kiwano/core/TimerManager.h
@@ -30,10 +30,6 @@ namespace kiwano
class KGE_API TimerManager
{
public:
- /// \~chinese
- /// @brief 定时器列表
- using Timers = IntrusiveList;
-
/// \~chinese
/// @brief 添加定时器
/// @param cb 回调函数
@@ -79,7 +75,7 @@ public:
/// \~chinese
/// @brief 获取所有定时器
- const Timers& GetAllTimers() const;
+ const TimerList& GetAllTimers() const;
protected:
/// \~chinese
@@ -87,6 +83,6 @@ protected:
void UpdateTimers(Duration dt);
private:
- Timers timers_;
+ TimerList timers_;
};
} // namespace kiwano