From 0742b0c02d9fcb542c9af76f660b50c719b313b1 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Fri, 3 May 2019 15:27:18 +0800 Subject: [PATCH] some optimization minor minor minor minor minor minor minor minor minor minor fixes --- Kiwano/2d/Action.cpp | 15 +++- Kiwano/2d/Action.h | 14 ++-- Kiwano/2d/ActionGroup.cpp | 7 +- Kiwano/2d/ActionGroup.h | 6 +- Kiwano/2d/ActionHelper.h | 19 +++-- Kiwano/2d/ActionManager.cpp | 5 +- Kiwano/2d/ActionManager.h | 4 +- Kiwano/2d/ActionTween.cpp | 45 +++++++----- Kiwano/2d/ActionTween.h | 47 +++++------- Kiwano/2d/Animation.cpp | 12 +-- Kiwano/2d/Animation.h | 8 +- Kiwano/2d/Canvas.cpp | 6 +- Kiwano/2d/Canvas.h | 6 +- Kiwano/2d/DebugNode.cpp | 5 +- Kiwano/2d/Frames.cpp | 2 +- Kiwano/2d/Frames.h | 2 +- Kiwano/2d/GeometryNode.cpp | 4 +- Kiwano/2d/GeometryNode.h | 6 +- Kiwano/2d/Node.cpp | 20 ++--- Kiwano/2d/Node.h | 4 +- Kiwano/2d/Scene.cpp | 1 + Kiwano/2d/Sprite.cpp | 6 +- Kiwano/2d/Sprite.h | 6 +- Kiwano/2d/Transform.hpp | 2 +- Kiwano/2d/Transition.cpp | 12 +-- Kiwano/2d/Transition.h | 24 +++--- Kiwano/2d/include-forwards.h | 2 +- Kiwano/base/EventDispatcher.cpp | 2 +- Kiwano/base/EventDispatcher.h | 2 +- Kiwano/base/SmartPtr.hpp | 2 +- Kiwano/base/TimerManager.cpp | 2 +- Kiwano/base/TimerManager.h | 2 +- Kiwano/base/time.cpp | 2 +- Kiwano/base/time.h | 2 +- Kiwano/common/Array.h | 19 ++--- Kiwano/common/ComPtr.hpp | 6 +- Kiwano/common/IntrusivePtr.hpp | 68 ++++++++--------- Kiwano/common/Json.h | 4 +- Kiwano/common/String.h | 10 +-- Kiwano/common/closure.hpp | 59 +++++++++++++-- Kiwano/macros.h | 14 +--- Kiwano/math/Matrix.hpp | 126 ++++++++++++++++++-------------- Kiwano/math/Rect.hpp | 50 ++++++++----- Kiwano/math/Vec2.hpp | 50 +++++++------ Kiwano/math/helper.h | 6 +- Kiwano/network/HttpClient.cpp | 4 +- Kiwano/network/HttpClient.h | 6 +- Kiwano/network/HttpResponse.h | 4 +- Kiwano/platform/Application.cpp | 6 +- Kiwano/platform/Application.h | 8 +- Kiwano/renderer/helper.hpp | 8 +- Kiwano/renderer/render.cpp | 2 +- Kiwano/renderer/render.h | 2 +- Kiwano/ui/Button.cpp | 8 ++ Kiwano/ui/Button.h | 10 ++- Kiwano/ui/Menu.cpp | 6 +- Kiwano/ui/Menu.h | 6 +- Kiwano/utils/ResLoader.cpp | 14 ++-- Kiwano/utils/ResLoader.h | 14 ++-- 59 files changed, 450 insertions(+), 364 deletions(-) diff --git a/Kiwano/2d/Action.cpp b/Kiwano/2d/Action.cpp index 528dc21e..759b2989 100644 --- a/Kiwano/2d/Action.cpp +++ b/Kiwano/2d/Action.cpp @@ -36,7 +36,16 @@ namespace kiwano { } - void Action::UpdateStep(NodePtr const& target, Duration dt) + void Action::Init(NodePtr target) + { + } + + void Action::Update(NodePtr target, Duration dt) + { + Complete(target); + } + + void Action::UpdateStep(NodePtr target, Duration dt) { elapsed_ += dt; @@ -72,7 +81,7 @@ namespace kiwano } } - void Action::Complete(NodePtr const& target) + void Action::Complete(NodePtr target) { if (cb_loop_done_) cb_loop_done_(); @@ -90,7 +99,7 @@ namespace kiwano ++loops_done_; } - void Action::Restart(NodePtr const & target) + void Action::Restart(NodePtr target) { status_ = Status::NotStarted; elapsed_ = 0; diff --git a/Kiwano/2d/Action.h b/Kiwano/2d/Action.h index c73cc1a8..beecd92a 100644 --- a/Kiwano/2d/Action.h +++ b/Kiwano/2d/Action.h @@ -95,20 +95,20 @@ namespace kiwano inline Duration GetElapsed() const { return elapsed_; } - inline ActionCallback const& GetDoneCallback() const { return cb_done_; } + inline ActionCallback GetDoneCallback() const { return cb_done_; } - inline ActionCallback const& GetLoopDoneCallback() const { return cb_loop_done_; } + inline ActionCallback GetLoopDoneCallback() const { return cb_loop_done_; } protected: - virtual void Init(NodePtr const& target) {} + virtual void Init(NodePtr target); - virtual void Update(NodePtr const& target, Duration dt) { Complete(target); } + virtual void Update(NodePtr target, Duration dt); - void UpdateStep(NodePtr const& target, Duration dt); + void UpdateStep(NodePtr target, Duration dt); - void Complete(NodePtr const& target); + void Complete(NodePtr target); - void Restart(NodePtr const& target); + void Restart(NodePtr target); protected: Status status_; diff --git a/Kiwano/2d/ActionGroup.cpp b/Kiwano/2d/ActionGroup.cpp index 1ea5fc11..4976cb32 100644 --- a/Kiwano/2d/ActionGroup.cpp +++ b/Kiwano/2d/ActionGroup.cpp @@ -19,6 +19,7 @@ // THE SOFTWARE. #include "ActionGroup.h" +#include "Node.h" #include "../base/logs.h" namespace kiwano @@ -42,7 +43,7 @@ namespace kiwano { } - void ActionGroup::Init(NodePtr const& target) + void ActionGroup::Init(NodePtr target) { if (actions_.IsEmpty()) { @@ -63,7 +64,7 @@ namespace kiwano } } - void ActionGroup::Update(NodePtr const& target, Duration dt) + void ActionGroup::Update(NodePtr target, Duration dt) { if (sequence_) { @@ -101,7 +102,7 @@ namespace kiwano } } - void ActionGroup::Add(ActionPtr const& action) + void ActionGroup::Add(ActionPtr action) { if (action) { diff --git a/Kiwano/2d/ActionGroup.h b/Kiwano/2d/ActionGroup.h index 449c2fa7..d3286225 100644 --- a/Kiwano/2d/ActionGroup.h +++ b/Kiwano/2d/ActionGroup.h @@ -41,7 +41,7 @@ namespace kiwano // 添加动作 void Add( - ActionPtr const& action + ActionPtr action ); // 添加多个动作 @@ -60,10 +60,10 @@ namespace kiwano protected: // 初始化动作 - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; // 更新动作 - void Update(NodePtr const& target, Duration dt) override; + void Update(NodePtr target, Duration dt) override; protected: bool sequence_; diff --git a/Kiwano/2d/ActionHelper.h b/Kiwano/2d/ActionHelper.h index 37dd81a4..7bfcd099 100644 --- a/Kiwano/2d/ActionHelper.h +++ b/Kiwano/2d/ActionHelper.h @@ -46,9 +46,9 @@ namespace kiwano inline ActionHelper& SetName(String const& name) { base->SetName(name); return (*this); } // 获取指针 - inline ActionPtr const& Get() const { return base; } + inline ActionPtr Get() const { return base; } - inline ActionHelper(ActionPtr const& base) : base(base) {} + inline ActionHelper(ActionPtr base) : base(base) {} inline operator ActionPtr() const { return base; } @@ -83,12 +83,14 @@ namespace kiwano inline TweenHelper& SetName(String const& name) { base->SetName(name); return (*this); } // 获取指针 - inline ActionTweenPtr const& Get() const { return base; } + inline ActionTweenPtr Get() const { return base; } - inline TweenHelper(ActionTweenPtr const& base) : base(base) {} + inline TweenHelper(ActionTweenPtr base) : base(base) {} inline operator ActionPtr() const { return base; } + inline operator ActionTweenPtr() const { return base; } + protected: ActionTweenPtr base; }; @@ -189,7 +191,7 @@ namespace kiwano static inline TweenHelper Path( - GeometryPtr const& geo, /* 几何图形 */ + GeometryPtr geo, /* 几何图形 */ bool rotating = false, /* 沿路径切线方向旋转 */ float start = 0.f, /* 起点 */ float end = 1.f) /* 终点 */ @@ -198,7 +200,7 @@ namespace kiwano } static inline TweenHelper - Animation(FramesPtr const& frames) + Animation(FramesPtr frames) { return TweenHelper(new kiwano::Animation(0, frames)); } @@ -221,6 +223,9 @@ namespace kiwano return ActionHelper(new kiwano::ActionGroup(actions, false)); } +#pragma warning(push) +#pragma warning(disable : 4996) + KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead") static inline ActionHelper Sequence(Array const& actions) @@ -234,5 +239,7 @@ namespace kiwano { return ActionHelper(new kiwano::ActionGroup(actions, false)); } + +#pragma warning(pop) }; } diff --git a/Kiwano/2d/ActionManager.cpp b/Kiwano/2d/ActionManager.cpp index 151049db..13c3ed76 100644 --- a/Kiwano/2d/ActionManager.cpp +++ b/Kiwano/2d/ActionManager.cpp @@ -19,11 +19,12 @@ // THE SOFTWARE. #include "ActionManager.h" +#include "Node.h" #include "../base/logs.h" namespace kiwano { - void ActionManager::UpdateActions(NodePtr const& target, Duration dt) + void ActionManager::UpdateActions(NodePtr target, Duration dt) { if (actions_.IsEmpty() || !target) return; @@ -41,7 +42,7 @@ namespace kiwano } } - ActionPtr ActionManager::AddAction(ActionPtr const& action) + ActionPtr ActionManager::AddAction(ActionPtr action) { KGE_ASSERT(action && "AddAction failed, NULL pointer exception"); diff --git a/Kiwano/2d/ActionManager.h b/Kiwano/2d/ActionManager.h index ae287c24..1e6b0978 100644 --- a/Kiwano/2d/ActionManager.h +++ b/Kiwano/2d/ActionManager.h @@ -30,7 +30,7 @@ namespace kiwano public: // 添加动作 ActionPtr AddAction( - ActionPtr const& action + ActionPtr action ); // 获取动作 @@ -51,7 +51,7 @@ namespace kiwano Actions const& GetAllActions() const; protected: - void UpdateActions(NodePtr const& target, Duration dt); + void UpdateActions(NodePtr target, Duration dt); protected: Actions actions_; diff --git a/Kiwano/2d/ActionTween.cpp b/Kiwano/2d/ActionTween.cpp index f0da9825..aff69266 100644 --- a/Kiwano/2d/ActionTween.cpp +++ b/Kiwano/2d/ActionTween.cpp @@ -28,6 +28,13 @@ namespace kiwano // Ease Functions //------------------------------------------------------- + inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); } + inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); } + inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); } + inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); } + inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); } + inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); } + EaseFunc Ease::Linear = math::Linear; EaseFunc Ease::EaseIn = MakeEaseIn(2.f); EaseFunc Ease::EaseOut = MakeEaseOut(2.f); @@ -91,7 +98,7 @@ namespace kiwano return dur_; } - void ActionTween::Update(NodePtr const& target, Duration dt) + void ActionTween::Update(NodePtr target, Duration dt) { float percent; @@ -135,7 +142,7 @@ namespace kiwano delta_pos_ = vector; } - void ActionMoveBy::Init(NodePtr const& target) + void ActionMoveBy::Init(NodePtr target) { if (target) { @@ -143,7 +150,7 @@ namespace kiwano } } - void ActionMoveBy::UpdateTween(NodePtr const& target, float percent) + void ActionMoveBy::UpdateTween(NodePtr target, float percent) { Point diff = target->GetPosition() - prev_pos_; start_pos_ = start_pos_ + diff; @@ -175,7 +182,7 @@ namespace kiwano return new (std::nothrow) ActionMoveTo(dur_, end_pos_, ease_func_); } - void ActionMoveTo::Init(NodePtr const& target) + void ActionMoveTo::Init(NodePtr target) { ActionMoveBy::Init(target); delta_pos_ = end_pos_ - start_pos_; @@ -204,7 +211,7 @@ namespace kiwano return new (std::nothrow) ActionJumpBy(dur_, -delta_pos_, height_, jumps_, ease_func_); } - void ActionJumpBy::Init(NodePtr const& target) + void ActionJumpBy::Init(NodePtr target) { if (target) { @@ -212,7 +219,7 @@ namespace kiwano } } - void ActionJumpBy::UpdateTween(NodePtr const& target, float percent) + void ActionJumpBy::UpdateTween(NodePtr target, float percent) { float frac = fmod(percent * jumps_, 1.f); float x = delta_pos_.x * percent; @@ -239,7 +246,7 @@ namespace kiwano return new (std::nothrow) ActionJumpTo(dur_, end_pos_, height_, jumps_, ease_func_); } - void ActionJumpTo::Init(NodePtr const& target) + void ActionJumpTo::Init(NodePtr target) { ActionJumpBy::Init(target); delta_pos_ = end_pos_ - start_pos_; @@ -264,7 +271,7 @@ namespace kiwano delta_y_ = scale_y; } - void ActionScaleBy::Init(NodePtr const& target) + void ActionScaleBy::Init(NodePtr target) { if (target) { @@ -273,7 +280,7 @@ namespace kiwano } } - void ActionScaleBy::UpdateTween(NodePtr const& target, float percent) + void ActionScaleBy::UpdateTween(NodePtr target, float percent) { target->SetScale(start_scale_x_ + delta_x_ * percent, start_scale_y_ + delta_y_ * percent); } @@ -307,7 +314,7 @@ namespace kiwano return new (std::nothrow) ActionScaleTo(dur_, end_scale_x_, end_scale_y_, ease_func_); } - void ActionScaleTo::Init(NodePtr const& target) + void ActionScaleTo::Init(NodePtr target) { ActionScaleBy::Init(target); delta_x_ = end_scale_x_ - start_scale_x_; @@ -325,7 +332,7 @@ namespace kiwano delta_val_ = opacity; } - void ActionOpacityBy::Init(NodePtr const& target) + void ActionOpacityBy::Init(NodePtr target) { if (target) { @@ -333,7 +340,7 @@ namespace kiwano } } - void ActionOpacityBy::UpdateTween(NodePtr const& target, float percent) + void ActionOpacityBy::UpdateTween(NodePtr target, float percent) { target->SetOpacity(start_val_ + delta_val_ * percent); } @@ -359,7 +366,7 @@ namespace kiwano return new (std::nothrow) ActionOpacityTo(dur_, end_val_, ease_func_); } - void ActionOpacityTo::Init(NodePtr const& target) + void ActionOpacityTo::Init(NodePtr target) { ActionOpacityBy::Init(target); delta_val_ = end_val_ - start_val_; @@ -386,7 +393,7 @@ namespace kiwano { } - void ActionRotateBy::Init(NodePtr const& target) + void ActionRotateBy::Init(NodePtr target) { if (target) { @@ -394,7 +401,7 @@ namespace kiwano } } - void ActionRotateBy::UpdateTween(NodePtr const& target, float percent) + void ActionRotateBy::UpdateTween(NodePtr target, float percent) { float rotation = start_val_ + delta_val_ * percent; if (rotation > 360.f) @@ -424,7 +431,7 @@ namespace kiwano return new (std::nothrow) ActionRotateTo(dur_, end_val_, ease_func_); } - void ActionRotateTo::Init(NodePtr const& target) + void ActionRotateTo::Init(NodePtr target) { ActionRotateBy::Init(target); delta_val_ = end_val_ - start_val_; @@ -435,7 +442,7 @@ namespace kiwano // ActionPath //------------------------------------------------------- - ActionPath::ActionPath(Duration duration, GeometryPtr const& geo, bool rotating, float start, float end, EaseFunc func) + ActionPath::ActionPath(Duration duration, GeometryPtr geo, bool rotating, float start, float end, EaseFunc func) : ActionTween(duration, func) , start_(start) , end_(end) @@ -454,12 +461,12 @@ namespace kiwano return new ActionPath(dur_, geo_, rotating_, end_, start_, ease_func_); } - void ActionPath::Init(NodePtr const& target) + void ActionPath::Init(NodePtr target) { start_pos_ = target->GetPosition(); } - void ActionPath::UpdateTween(NodePtr const& target, float percent) + void ActionPath::UpdateTween(NodePtr target, float percent) { float length = geo_->GetLength() * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f); diff --git a/Kiwano/2d/ActionTween.h b/Kiwano/2d/ActionTween.h index 77af20f0..69d1ca09 100644 --- a/Kiwano/2d/ActionTween.h +++ b/Kiwano/2d/ActionTween.h @@ -65,13 +65,6 @@ namespace kiwano static KGE_API EaseFunc SineInOut; }; - inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); } - inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); } - inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); } - inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); } - inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); } - inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); } - // 补间动画 class KGE_API ActionTween @@ -97,9 +90,9 @@ namespace kiwano void SetDuration(Duration duration); protected: - void Update(NodePtr const& target, Duration dt) override; + void Update(NodePtr target, Duration dt) override; - virtual void UpdateTween(NodePtr const& target, float percent) = 0; + virtual void UpdateTween(NodePtr target, float percent) = 0; protected: Duration dur_; @@ -125,9 +118,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: Point start_pos_; @@ -158,7 +151,7 @@ namespace kiwano } protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; protected: Point end_pos_; @@ -185,9 +178,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: Point start_pos_; @@ -222,7 +215,7 @@ namespace kiwano } protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; protected: Point end_pos_; @@ -254,9 +247,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: float start_scale_x_; @@ -295,7 +288,7 @@ namespace kiwano } protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; protected: float end_scale_x_; @@ -321,9 +314,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: float start_val_; @@ -353,7 +346,7 @@ namespace kiwano } protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; protected: float end_val_; @@ -404,9 +397,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: float start_val_; @@ -436,7 +429,7 @@ namespace kiwano } protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; protected: float end_val_; @@ -450,7 +443,7 @@ namespace kiwano public: ActionPath( Duration duration, /* 持续时长 */ - GeometryPtr const& geo, /* 几何图形 */ + GeometryPtr geo, /* 几何图形 */ bool rotating = false, /* 沿路径切线方向旋转 */ float start = 0.f, /* 起点 */ float end = 1.f, /* 终点 */ @@ -464,9 +457,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: bool rotating_; diff --git a/Kiwano/2d/Animation.cpp b/Kiwano/2d/Animation.cpp index 2cf12a1f..b8c9bbfc 100644 --- a/Kiwano/2d/Animation.cpp +++ b/Kiwano/2d/Animation.cpp @@ -30,7 +30,7 @@ namespace kiwano { } - Animation::Animation(Duration duration, FramesPtr const& animation, EaseFunc func) + Animation::Animation(Duration duration, FramesPtr animation, EaseFunc func) : ActionTween(duration, func) , frames_(nullptr) { @@ -46,12 +46,12 @@ namespace kiwano return frames_; } - void Animation::SetFrames(FramesPtr const& frames) + void Animation::SetFrames(FramesPtr frames) { frames_ = frames; } - void Animation::Init(NodePtr const& target) + void Animation::Init(NodePtr target) { if (!frames_ || frames_->GetFrames().empty()) { @@ -66,15 +66,15 @@ namespace kiwano } } - void Animation::UpdateTween(NodePtr const& target, float percent) + void Animation::UpdateTween(NodePtr target, float percent) { auto sprite_target = dynamic_cast(target.Get()); KGE_ASSERT(sprite_target && "Animation only supports Sprites"); const auto& frames = frames_->GetFrames(); - int size = frames.size(); - int index = std::min(static_cast(math::Floor(size * percent)), size - 1); + auto size = frames.size(); + auto index = std::min(static_cast(math::Floor(size * percent)), size - 1); sprite_target->Load(frames[index]); } diff --git a/Kiwano/2d/Animation.h b/Kiwano/2d/Animation.h index 143417d1..5440c05e 100644 --- a/Kiwano/2d/Animation.h +++ b/Kiwano/2d/Animation.h @@ -32,7 +32,7 @@ namespace kiwano Animation( Duration duration, /* 动画时长 */ - FramesPtr const& frames, /* 序列帧 */ + FramesPtr frames, /* 序列帧 */ EaseFunc func = nullptr /* 速度变化 */ ); @@ -43,7 +43,7 @@ namespace kiwano // 设置动画 void SetFrames( - FramesPtr const& frames + FramesPtr frames ); // 获取该动作的拷贝对象 @@ -53,9 +53,9 @@ namespace kiwano ActionPtr Reverse() const override; protected: - void Init(NodePtr const& target) override; + void Init(NodePtr target) override; - void UpdateTween(NodePtr const& target, float percent) override; + void UpdateTween(NodePtr target, float percent) override; protected: FramesPtr frames_; diff --git a/Kiwano/2d/Canvas.cpp b/Kiwano/2d/Canvas.cpp index c2ab0deb..4fd8c808 100644 --- a/Kiwano/2d/Canvas.cpp +++ b/Kiwano/2d/Canvas.cpp @@ -249,7 +249,7 @@ namespace kiwano cache_expired_ = true; } - void Canvas::DrawImage(ImagePtr const & image, float opacity) + void Canvas::DrawImage(ImagePtr image, float opacity) { if (image && image->GetBitmap()) { @@ -297,7 +297,7 @@ namespace kiwano ); } - void Canvas::DrawGeometry(GeometryPtr const & geo) + void Canvas::DrawGeometry(GeometryPtr geo) { if (geo && geo->geo_) { @@ -375,7 +375,7 @@ namespace kiwano cache_expired_ = true; } - void Canvas::FillGeometry(GeometryPtr const & geo) + void Canvas::FillGeometry(GeometryPtr geo) { if (geo && geo->geo_) { diff --git a/Kiwano/2d/Canvas.h b/Kiwano/2d/Canvas.h index 248f4386..436284aa 100644 --- a/Kiwano/2d/Canvas.h +++ b/Kiwano/2d/Canvas.h @@ -85,7 +85,7 @@ namespace kiwano // 画图片 void DrawImage( - ImagePtr const& image, + ImagePtr image, float opacity = 1.f ); @@ -97,7 +97,7 @@ namespace kiwano // 画几何图形边框 void DrawGeometry( - GeometryPtr const& geo + GeometryPtr geo ); // 填充圆形 @@ -127,7 +127,7 @@ namespace kiwano // 填充几何图形 void FillGeometry( - GeometryPtr const& geo + GeometryPtr geo ); // 开始绘制路径 diff --git a/Kiwano/2d/DebugNode.cpp b/Kiwano/2d/DebugNode.cpp index c71da403..7d7a9dc6 100644 --- a/Kiwano/2d/DebugNode.cpp +++ b/Kiwano/2d/DebugNode.cpp @@ -51,10 +51,11 @@ namespace kiwano void DebugNode::OnRender() { + Renderer::Instance().SetTransform(Matrix{}); Renderer::Instance().GetSolidColorBrush()->SetColor(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.5f)); Renderer::Instance().GetDeviceResources()->GetD2DDeviceContext()->FillRectangle( - D2D1_RECT_F{ 10, 10, 30 + debug_text_->GetWidth(), 30 + debug_text_->GetHeight() }, + D2D1_RECT_F{ 10, 10, 30 + debug_text_->GetLayoutSize().x, 30 + debug_text_->GetLayoutSize().y }, Renderer::Instance().GetSolidColorBrush() ); } @@ -85,8 +86,6 @@ namespace kiwano ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb"; debug_text_->SetText(ss.str()); - - debug_text_->SetSize(debug_text_->GetLayoutSize()); } } diff --git a/Kiwano/2d/Frames.cpp b/Kiwano/2d/Frames.cpp index 8937cebb..549946dc 100644 --- a/Kiwano/2d/Frames.cpp +++ b/Kiwano/2d/Frames.cpp @@ -37,7 +37,7 @@ namespace kiwano { } - void Frames::Add(ImagePtr const& frame) + void Frames::Add(ImagePtr frame) { KGE_ASSERT(frame && "Frames::Add failed, NULL pointer exception"); diff --git a/Kiwano/2d/Frames.h b/Kiwano/2d/Frames.h index 06b7c6df..0f13324f 100644 --- a/Kiwano/2d/Frames.h +++ b/Kiwano/2d/Frames.h @@ -38,7 +38,7 @@ namespace kiwano // 添加关键帧 void Add( - ImagePtr const& frame + ImagePtr frame ); // 添加多个关键帧 diff --git a/Kiwano/2d/GeometryNode.cpp b/Kiwano/2d/GeometryNode.cpp index 3084efa1..b964efa8 100644 --- a/Kiwano/2d/GeometryNode.cpp +++ b/Kiwano/2d/GeometryNode.cpp @@ -31,7 +31,7 @@ namespace kiwano { } - GeometryNode::GeometryNode(GeometryPtr const& geometry) + GeometryNode::GeometryNode(GeometryPtr geometry) : GeometryNode() { SetGeometry(geometry); @@ -41,7 +41,7 @@ namespace kiwano { } - void GeometryNode::SetGeometry(GeometryPtr const& geometry) + void GeometryNode::SetGeometry(GeometryPtr geometry) { geometry_ = geometry; } diff --git a/Kiwano/2d/GeometryNode.h b/Kiwano/2d/GeometryNode.h index ec020055..7228933b 100644 --- a/Kiwano/2d/GeometryNode.h +++ b/Kiwano/2d/GeometryNode.h @@ -32,14 +32,14 @@ namespace kiwano GeometryNode(); GeometryNode( - GeometryPtr const& geometry + GeometryPtr geometry ); virtual ~GeometryNode(); // 设置形状 void SetGeometry( - GeometryPtr const& geometry + GeometryPtr geometry ); // 设置填充颜色 @@ -63,7 +63,7 @@ namespace kiwano ); // 获取形状 - GeometryPtr const& GetGeometry() const { return geometry_; } + GeometryPtr GetGeometry() const { return geometry_; } // 获取填充颜色 Color GetFillColor() const { return fill_color_; } diff --git a/Kiwano/2d/Node.cpp b/Kiwano/2d/Node.cpp index dc87aedf..90b23e7b 100644 --- a/Kiwano/2d/Node.cpp +++ b/Kiwano/2d/Node.cpp @@ -58,16 +58,16 @@ namespace kiwano void Node::Update(Duration dt) { - if (update_pausing_) - return; + if (!update_pausing_) + { + UpdateActions(this, dt); + UpdateTimers(dt); - UpdateActions(this, dt); - UpdateTimers(dt); + if (cb_update_) + cb_update_(dt); - if (cb_update_) - cb_update_(dt); - - OnUpdate(dt); + OnUpdate(dt); + } if (!children_.IsEmpty()) { @@ -451,7 +451,7 @@ namespace kiwano dirty_transform_ = true; } - void Node::AddChild(NodePtr const& child) + void Node::AddChild(NodePtr child) { KGE_ASSERT(child && "Node::AddChild failed, NULL pointer exception"); @@ -537,7 +537,7 @@ namespace kiwano } } - void Node::RemoveChild(NodePtr const& child) + void Node::RemoveChild(NodePtr child) { RemoveChild(child.Get()); } diff --git a/Kiwano/2d/Node.h b/Kiwano/2d/Node.h index 91f71adc..5008fcef 100644 --- a/Kiwano/2d/Node.h +++ b/Kiwano/2d/Node.h @@ -325,7 +325,7 @@ namespace kiwano // 添加子节点 void AddChild( - NodePtr const& child + NodePtr child ); // 添加多个子节点 @@ -348,7 +348,7 @@ namespace kiwano // 移除子节点 void RemoveChild( - NodePtr const& child + NodePtr child ); // 移除子节点 diff --git a/Kiwano/2d/Scene.cpp b/Kiwano/2d/Scene.cpp index 11d70784..c01e16cf 100644 --- a/Kiwano/2d/Scene.cpp +++ b/Kiwano/2d/Scene.cpp @@ -30,6 +30,7 @@ namespace kiwano { scene_ = this; + SetAnchor(0, 0); SetSize(Renderer::Instance().GetOutputSize()); } diff --git a/Kiwano/2d/Sprite.cpp b/Kiwano/2d/Sprite.cpp index 21c74cc5..5cd71e0d 100644 --- a/Kiwano/2d/Sprite.cpp +++ b/Kiwano/2d/Sprite.cpp @@ -28,7 +28,7 @@ namespace kiwano { } - Sprite::Sprite(ImagePtr const& image) + Sprite::Sprite(ImagePtr image) : image_(nullptr) { Load(image); @@ -51,7 +51,7 @@ namespace kiwano { } - bool Sprite::Load(ImagePtr const& image) + bool Sprite::Load(ImagePtr image) { if (image) { @@ -90,7 +90,7 @@ namespace kiwano ); } - ImagePtr const& Sprite::GetImage() const + ImagePtr Sprite::GetImage() const { return image_; } diff --git a/Kiwano/2d/Sprite.h b/Kiwano/2d/Sprite.h index 6648ad34..9712750d 100644 --- a/Kiwano/2d/Sprite.h +++ b/Kiwano/2d/Sprite.h @@ -32,7 +32,7 @@ namespace kiwano Sprite(); explicit Sprite( - ImagePtr const& image + ImagePtr image ); explicit Sprite( @@ -53,7 +53,7 @@ namespace kiwano // 加载图片 bool Load( - ImagePtr const& image + ImagePtr image ); // 将图片裁剪为矩形 @@ -62,7 +62,7 @@ namespace kiwano ); // 获取 Image 对象 - ImagePtr const& GetImage() const; + ImagePtr GetImage() const; // 渲染精灵 void OnRender() override; diff --git a/Kiwano/2d/Transform.hpp b/Kiwano/2d/Transform.hpp index ee7615d1..69e1605c 100644 --- a/Kiwano/2d/Transform.hpp +++ b/Kiwano/2d/Transform.hpp @@ -47,7 +47,7 @@ namespace kiwano rotation == other.rotation; } - inline math::Matrix ToMatrix() const + inline Matrix ToMatrix() const { // matrix multiplication is optimized by expression template return Matrix::Scaling(scale) diff --git a/Kiwano/2d/Transition.cpp b/Kiwano/2d/Transition.cpp index 2f3d2e81..5329cdcb 100644 --- a/Kiwano/2d/Transition.cpp +++ b/Kiwano/2d/Transition.cpp @@ -55,7 +55,7 @@ namespace kiwano return done_; } - void Transition::Init(ScenePtr const& prev, ScenePtr const& next) + void Transition::Init(ScenePtr prev, ScenePtr next) { process_ = 0; delta_ = Duration{}; @@ -147,7 +147,7 @@ namespace kiwano { } - void BoxTransition::Init(ScenePtr const& prev, ScenePtr const& next) + void BoxTransition::Init(ScenePtr prev, ScenePtr next) { Transition::Init(prev, next); @@ -189,7 +189,7 @@ namespace kiwano { } - void EmergeTransition::Init(ScenePtr const& prev, ScenePtr const& next) + void EmergeTransition::Init(ScenePtr prev, ScenePtr next) { Transition::Init(prev, next); @@ -214,7 +214,7 @@ namespace kiwano { } - void FadeTransition::Init(ScenePtr const& prev, ScenePtr const& next) + void FadeTransition::Init(ScenePtr prev, ScenePtr next) { Transition::Init(prev, next); @@ -248,7 +248,7 @@ namespace kiwano { } - void MoveTransition::Init(ScenePtr const& prev, ScenePtr const& next) + void MoveTransition::Init(ScenePtr prev, ScenePtr next) { Transition::Init(prev, next); @@ -327,7 +327,7 @@ namespace kiwano { } - void RotationTransition::Init(ScenePtr const& prev, ScenePtr const& next) + void RotationTransition::Init(ScenePtr prev, ScenePtr next) { Transition::Init(prev, next); diff --git a/Kiwano/2d/Transition.h b/Kiwano/2d/Transition.h index 9a3a907d..0d605cb7 100644 --- a/Kiwano/2d/Transition.h +++ b/Kiwano/2d/Transition.h @@ -43,8 +43,8 @@ namespace kiwano protected: virtual void Init( - ScenePtr const& prev, - ScenePtr const& next + ScenePtr prev, + ScenePtr next ); virtual void Update(Duration dt); @@ -84,8 +84,8 @@ namespace kiwano void Update(Duration dt) override; virtual void Init( - ScenePtr const& prev, - ScenePtr const& next + ScenePtr prev, + ScenePtr next ) override; }; @@ -103,8 +103,8 @@ namespace kiwano void Update(Duration dt) override; virtual void Init( - ScenePtr const& prev, - ScenePtr const& next + ScenePtr prev, + ScenePtr next ) override; }; @@ -122,8 +122,8 @@ namespace kiwano void Update(Duration dt) override; virtual void Init( - ScenePtr const& prev, - ScenePtr const& next + ScenePtr prev, + ScenePtr next ) override; }; @@ -142,8 +142,8 @@ namespace kiwano void Update(Duration dt) override; virtual void Init( - ScenePtr const& prev, - ScenePtr const& next + ScenePtr prev, + ScenePtr next ) override; void Reset() override; @@ -169,8 +169,8 @@ namespace kiwano void Update(Duration dt) override; virtual void Init( - ScenePtr const& prev, - ScenePtr const& next + ScenePtr prev, + ScenePtr next ) override; void Reset() override; diff --git a/Kiwano/2d/include-forwards.h b/Kiwano/2d/include-forwards.h index 2fb8401a..043ff7f3 100644 --- a/Kiwano/2d/include-forwards.h +++ b/Kiwano/2d/include-forwards.h @@ -126,7 +126,7 @@ namespace kiwano // 图层属性 struct LayerProperties { - math::Rect area; + Rect area; float opacity; }; } diff --git a/Kiwano/base/EventDispatcher.cpp b/Kiwano/base/EventDispatcher.cpp index c5369d8e..ae94459c 100644 --- a/Kiwano/base/EventDispatcher.cpp +++ b/Kiwano/base/EventDispatcher.cpp @@ -40,7 +40,7 @@ namespace kiwano } } - EventListenerPtr EventDispatcher::AddListener(EventListenerPtr const & listener) + EventListenerPtr EventDispatcher::AddListener(EventListenerPtr listener) { KGE_ASSERT(listener && "AddListener failed, NULL pointer exception"); diff --git a/Kiwano/base/EventDispatcher.h b/Kiwano/base/EventDispatcher.h index 42d97e03..97fc1fce 100644 --- a/Kiwano/base/EventDispatcher.h +++ b/Kiwano/base/EventDispatcher.h @@ -30,7 +30,7 @@ namespace kiwano public: // 添加监听器 EventListenerPtr AddListener( - EventListenerPtr const& listener + EventListenerPtr listener ); // 添加监听器 diff --git a/Kiwano/base/SmartPtr.hpp b/Kiwano/base/SmartPtr.hpp index 40552a07..ff780561 100644 --- a/Kiwano/base/SmartPtr.hpp +++ b/Kiwano/base/SmartPtr.hpp @@ -38,7 +38,7 @@ namespace kiwano }; template - using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager, true>; + using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager>; } diff --git a/Kiwano/base/TimerManager.cpp b/Kiwano/base/TimerManager.cpp index e7af45db..023b4df0 100644 --- a/Kiwano/base/TimerManager.cpp +++ b/Kiwano/base/TimerManager.cpp @@ -41,7 +41,7 @@ namespace kiwano } } - void TimerManager::AddTimer(TimerPtr const& timer) + void TimerManager::AddTimer(TimerPtr timer) { KGE_ASSERT(timer && "AddTimer failed, NULL pointer exception"); diff --git a/Kiwano/base/TimerManager.h b/Kiwano/base/TimerManager.h index 5bea8245..a96e6e71 100644 --- a/Kiwano/base/TimerManager.h +++ b/Kiwano/base/TimerManager.h @@ -30,7 +30,7 @@ namespace kiwano public: // 添加任务 void AddTimer( - TimerPtr const& timer + TimerPtr timer ); // 启动任务 diff --git a/Kiwano/base/time.cpp b/Kiwano/base/time.cpp index 7dfb061c..9945189e 100644 --- a/Kiwano/base/time.cpp +++ b/Kiwano/base/time.cpp @@ -67,7 +67,7 @@ namespace kiwano return Duration(dur_ - other.dur_); } - Time Time::Now() KGE_NOEXCEPT + Time Time::Now() noexcept { static LARGE_INTEGER freq = {}; if (freq.QuadPart == 0LL) diff --git a/Kiwano/base/time.h b/Kiwano/base/time.h index fe11424c..3b6c9c49 100644 --- a/Kiwano/base/time.h +++ b/Kiwano/base/time.h @@ -177,7 +177,7 @@ namespace kiwano // 获取当前时间 // 由于该时间点基于系统启动时间开始计算, 所以无法格式化该时间, // 也无法获得该时间的 Unix 时间戳 - static Time Now() KGE_NOEXCEPT; + static Time Now() noexcept; private: long dur_; diff --git a/Kiwano/common/Array.h b/Kiwano/common/Array.h index e05d1bbb..6478a556 100644 --- a/Kiwano/common/Array.h +++ b/Kiwano/common/Array.h @@ -25,14 +25,6 @@ namespace kiwano { - // - // Array - // Lightweight std::vector<>-like class - // - template - class Array; - - // // ArrayManager<> with memory operations // @@ -42,6 +34,7 @@ namespace kiwano // // Array<> + // Lightweight std::vector<>-like class // template< typename _Ty, @@ -68,14 +61,14 @@ namespace kiwano inline Array(size_type count, const _Ty& val) : Array() { assign(count, val); } inline Array(initializer_list list) : Array() { assign(list); } inline Array(const Array& src) : Array() { assign(src); } - inline Array(Array&& src) : Array() { swap(src); } + inline Array(Array&& src) noexcept : Array() { swap(src); } inline ~Array() { destroy(); } template inline Array(_Iter first, _Iter last) : Array() { assign(first, last); } inline Array& operator=(const Array& src) { if (&src != this) { resize(src.size_); manager::copy_data(begin(), src.cbegin(), size_); } return (*this); } - inline Array& operator=(Array&& src) { swap(src); return *this; } + inline Array& operator=(Array&& src) noexcept { swap(src); return *this; } inline Array& operator=(initializer_list list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); } inline Array& assign(size_type count, const _Ty& val) { if (count > 0) { resize(count); manager::copy_data(begin(), count, val); } else clear(); return (*this); } @@ -86,7 +79,7 @@ namespace kiwano inline void assign(_Iter first, _Iter last) { auto diff = std::distance(first, last); resize((size_type)diff); auto data = begin(); while (first != last) (*data++) = (*first++); } inline void clear() { destroy(); size_ = capacity_ = 0; data_ = nullptr; } - inline void swap(Array& rhs) { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); } + inline void swap(Array& rhs) noexcept { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); } inline void resize(size_type new_size) { resize(new_size, _Ty()); } inline void resize(size_type new_size, const _Ty& v); @@ -215,7 +208,7 @@ namespace kiwano struct __ArrayManager<_Ty, _Alloc, false> { using value_type = _Ty; - using size_type = int; + using size_type = size_t; using allocator_type = typename _Alloc; static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); } @@ -244,7 +237,7 @@ namespace kiwano struct __ArrayManager<_Ty, _Alloc, true> { using value_type = _Ty; - using size_type = int; + using size_type = size_t; using allocator_type = typename _Alloc; static inline void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); } diff --git a/Kiwano/common/ComPtr.hpp b/Kiwano/common/ComPtr.hpp index dda69d9b..9e2d660f 100644 --- a/Kiwano/common/ComPtr.hpp +++ b/Kiwano/common/ComPtr.hpp @@ -39,7 +39,9 @@ namespace kiwano }; // ComPtr<> is a smart pointer for COM - template - using ComPtr = IntrusivePtr<_Ty, ComPtrManager, ::std::is_base_of::value>; + template< + typename _Ty, + typename = typename std::enable_if::value, int>::type> + using ComPtr = IntrusivePtr<_Ty, ComPtrManager>; } diff --git a/Kiwano/common/IntrusivePtr.hpp b/Kiwano/common/IntrusivePtr.hpp index 955de57d..15e51d51 100644 --- a/Kiwano/common/IntrusivePtr.hpp +++ b/Kiwano/common/IntrusivePtr.hpp @@ -25,65 +25,55 @@ namespace kiwano { - template - class IntrusivePtr; - template - class IntrusivePtr<_Ty, _Manager, false>; - - - template - using RealIntrusivePtr = IntrusivePtr<_Ty, _Manager, true>; - - template - class IntrusivePtr<_Ty, _Manager, true> + class IntrusivePtr { _Ty* ptr_{ nullptr }; public: using Type = _Ty; - IntrusivePtr() KGE_NOEXCEPT {} + IntrusivePtr() noexcept {} - IntrusivePtr(nullptr_t) KGE_NOEXCEPT {} + IntrusivePtr(nullptr_t) noexcept {} - IntrusivePtr(Type* p) KGE_NOEXCEPT : ptr_(p) + IntrusivePtr(Type* p) noexcept : ptr_(p) { typename _Manager::AddRef(ptr_); } - IntrusivePtr(const IntrusivePtr& other) KGE_NOEXCEPT + IntrusivePtr(const IntrusivePtr& other) noexcept : ptr_(other.ptr_) { typename _Manager::AddRef(ptr_); } template - IntrusivePtr(const RealIntrusivePtr<_UTy, _Manager>& other) KGE_NOEXCEPT + IntrusivePtr(const IntrusivePtr<_UTy, _Manager>& other) noexcept : ptr_(other.Get()) { typename _Manager::AddRef(ptr_); } - IntrusivePtr(IntrusivePtr&& other) KGE_NOEXCEPT + IntrusivePtr(IntrusivePtr&& other) noexcept { ptr_ = other.ptr_; other.ptr_ = nullptr; } - ~IntrusivePtr() KGE_NOEXCEPT + ~IntrusivePtr() noexcept { typename _Manager::Release(ptr_); } - inline Type* Get() const KGE_NOEXCEPT { return ptr_; } + inline Type* Get() const noexcept { return ptr_; } - inline void Reset() KGE_NOEXCEPT + inline void Reset() noexcept { IntrusivePtr{}.Swap(*this); } - inline void Swap(IntrusivePtr& other) KGE_NOEXCEPT + inline void Swap(IntrusivePtr& other) noexcept { std::swap(ptr_, other.ptr_); } @@ -106,18 +96,18 @@ namespace kiwano return &ptr_; } - inline operator bool() const KGE_NOEXCEPT { return ptr_ != nullptr; } + inline operator bool() const noexcept { return ptr_ != nullptr; } - inline bool operator !() const KGE_NOEXCEPT { return ptr_ == 0; } + inline bool operator !() const noexcept { return ptr_ == 0; } - inline IntrusivePtr& operator =(const IntrusivePtr& other) KGE_NOEXCEPT + inline IntrusivePtr& operator =(const IntrusivePtr& other) noexcept { if (other.ptr_ != ptr_) IntrusivePtr(other).Swap(*this); return *this; } - inline IntrusivePtr& operator =(IntrusivePtr&& other) KGE_NOEXCEPT + inline IntrusivePtr& operator =(IntrusivePtr&& other) noexcept { typename _Manager::Release(ptr_); ptr_ = other.ptr_; @@ -125,14 +115,14 @@ namespace kiwano return *this; } - inline IntrusivePtr& operator =(Type* p) KGE_NOEXCEPT + inline IntrusivePtr& operator =(Type* p) noexcept { if (p != ptr_) IntrusivePtr(p).Swap(*this); return *this; } - inline IntrusivePtr& operator =(nullptr_t) KGE_NOEXCEPT + inline IntrusivePtr& operator =(nullptr_t) noexcept { if (nullptr != ptr_) IntrusivePtr{}.Swap(*this); @@ -141,67 +131,67 @@ namespace kiwano }; template - inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept { return lhs.Get() == rhs.Get(); } template - inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept { return lhs.Get() != rhs.Get(); } template - inline bool operator<(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator<(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept { return lhs.Get() < rhs.Get(); } template - inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) KGE_NOEXCEPT + inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) noexcept { return lhs.Get() == rhs; } template - inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) KGE_NOEXCEPT + inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) noexcept { return lhs.Get() != rhs; } template - inline bool operator==(_Ty* lhs, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator==(_Ty* lhs, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept { return lhs == rhs.Get(); } template - inline bool operator!=(_Ty* lhs, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator!=(_Ty* lhs, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept { return lhs != rhs.Get(); } template - inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) KGE_NOEXCEPT + inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) noexcept { return !static_cast(lhs); } template - inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) KGE_NOEXCEPT + inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) noexcept { return static_cast(lhs); } template - inline bool operator==(nullptr_t, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator==(nullptr_t, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept { return !static_cast(rhs); } template - inline bool operator!=(nullptr_t, RealIntrusivePtr<_Ty, _Manager> const& rhs) KGE_NOEXCEPT + inline bool operator!=(nullptr_t, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept { return static_cast(rhs); } @@ -209,7 +199,7 @@ namespace kiwano // template class cannot specialize std::swap, // so implement a swap function in kiwano namespace template - inline void swap(RealIntrusivePtr<_Ty, _Manager>& lhs, RealIntrusivePtr<_Ty, _Manager>& rhs) KGE_NOEXCEPT + inline void swap(IntrusivePtr<_Ty, _Manager>& lhs, IntrusivePtr<_Ty, _Manager>& rhs) noexcept { lhs.Swap(rhs); } diff --git a/Kiwano/common/Json.h b/Kiwano/common/Json.h index 4e1df47c..46e98490 100644 --- a/Kiwano/common/Json.h +++ b/Kiwano/common/Json.h @@ -363,7 +363,7 @@ namespace kiwano { using difference_type = std::ptrdiff_t; - inline primitive_iterator(int it = 0) : it_(it) {} + inline primitive_iterator(difference_type it = 0) : it_(it) {} inline void set_begin() { it_ = 0; } inline void set_end() { it_ = 1; } @@ -392,7 +392,7 @@ namespace kiwano inline bool operator>=(primitive_iterator const& other) const { return it_ >= other.it_; } private: - int it_; + difference_type it_; }; template diff --git a/Kiwano/common/String.h b/Kiwano/common/String.h index 06c1c5de..ded533a7 100644 --- a/Kiwano/common/String.h +++ b/Kiwano/common/String.h @@ -106,7 +106,7 @@ namespace kiwano String(std::wstring const& str); String(String const& rhs); String(String const& rhs, size_type pos, size_type count = npos); - String(String && rhs); + String(String && rhs) noexcept; ~String(); template @@ -191,7 +191,7 @@ namespace kiwano std::string to_string() const; std::wstring to_wstring() const; - void swap(String& rhs); + void swap(String& rhs) noexcept; size_t hash() const; public: @@ -245,7 +245,7 @@ namespace kiwano inline String& operator=(const wchar_t* cstr) { if (const_str_ != cstr) String{ cstr }.swap(*this); return *this; } inline String& operator=(std::wstring const& str) { String{ str }.swap(*this); return *this; } inline String& operator=(String const& rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; } - inline String& operator=(String && rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; } + inline String& operator=(String && rhs) noexcept { if (this != &rhs) String{ rhs }.swap(*this); return *this; } public: static const String::size_type npos = static_cast(-1); @@ -537,7 +537,7 @@ namespace kiwano assign(rhs, pos, count); } - inline String::String(String && rhs) + inline String::String(String && rhs) noexcept : str_(rhs.str_) , size_(rhs.size_) , capacity_(rhs.capacity_) @@ -1074,7 +1074,7 @@ namespace kiwano size_ = capacity_ = 0; } - inline void String::swap(String & rhs) + inline void String::swap(String & rhs) noexcept { std::swap(const_str_, rhs.const_str_); std::swap(size_, rhs.size_); diff --git a/Kiwano/common/closure.hpp b/Kiwano/common/closure.hpp index 60b45573..9763ecab 100644 --- a/Kiwano/common/closure.hpp +++ b/Kiwano/common/closure.hpp @@ -29,6 +29,43 @@ namespace kiwano namespace __closure_detail { + // + // is_callable + // + + namespace __callable_detail + { + template + struct helper + { + template static int test(...); + + template struct class_mem; + template static char test(class_mem<_Uty, &_Uty::operator()>*); + + template struct class_const_mem; + template static char test(class_const_mem<_Uty, &_Uty::operator()>*); + + template< + typename _Uty, + typename _Uret = typename std::decay().operator()(std::declval<_Args>()...))>::type, + typename = typename std::enable_if::value>::type> + static char test(int); + + static constexpr bool value = sizeof(test<_Ty>(0)) == sizeof(char); + }; + } + + template + struct is_callable + : public std::bool_constant<__callable_detail::helper<_Ty, _Ret, _Args...>::value> + { + }; + + // + // Callable + // + template class Callable { @@ -195,7 +232,15 @@ namespace kiwano rhs.callable_ = nullptr; } - template + Closure(_Ret(*func)(_Args...)) + { + callable_ = __closure_detail::ProxyCallable<_Ret(*)(_Args...), _Ret, _Args...>::Make(std::move(func)); + if (callable_) callable_->AddRef(); + } + + template< + typename _Ty, + typename = typename std::enable_if<__closure_detail::is_callable<_Ty, _Ret, _Args...>::value, int>::type> Closure(_Ty val) { callable_ = __closure_detail::ProxyCallable<_Ty, _Ret, _Args...>::Make(std::move(val)); @@ -204,7 +249,7 @@ namespace kiwano template::value || std::is_base_of<_Ty, _Uty>::value, int>::type = 0> + typename = typename std::enable_if::value || std::is_base_of<_Ty, _Uty>::value, int>::type> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) { callable_ = __closure_detail::ProxyMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func); @@ -213,7 +258,7 @@ namespace kiwano template::value || std::is_base_of<_Ty, _Uty>::value, int>::type = 0> + typename = typename std::enable_if::value || std::is_base_of<_Ty, _Uty>::value, int>::type> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) { callable_ = __closure_detail::ProxyConstMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func); @@ -274,9 +319,9 @@ namespace kiwano template::value || std::is_base_of<_Ty, _Uty>::value, int - >::type = 0, + >::type, typename _Ret, typename... _Args> inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) @@ -286,9 +331,9 @@ namespace kiwano template::value || std::is_base_of<_Ty, _Uty>::value, int - >::type = 0, + >::type, typename _Ret, typename... _Args> inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) diff --git a/Kiwano/macros.h b/Kiwano/macros.h index 2425b17e..ac13650e 100644 --- a/Kiwano/macros.h +++ b/Kiwano/macros.h @@ -33,10 +33,11 @@ # define VS_2013 1800 # define VS_2015 1900 # define VS_2017 1900 +# define VS_2019 1920 #endif -#if VS_VER < VS_2013 -# error Kiwano only supports Visual Studio 2013 and above +#if VS_VER < VS_2015 +# error Kiwano only supports Visual Studio 2015 and above #endif #ifndef WINVER @@ -84,15 +85,6 @@ #endif -#if VS_VER >= VS_2015 -# define KGE_NOEXCEPT noexcept -# define KGE_CONSTEXPR constexpr -#else -# define KGE_NOEXCEPT throw() -# define KGE_CONSTEXPR const -#endif - - #ifndef KGE_ASSERT # ifdef KGE_DEBUG # define KGE_ASSERT(EXPR) assert(EXPR) diff --git a/Kiwano/math/Matrix.hpp b/Kiwano/math/Matrix.hpp index db16cb59..6fd0358f 100644 --- a/Kiwano/math/Matrix.hpp +++ b/Kiwano/math/Matrix.hpp @@ -27,43 +27,49 @@ namespace kiwano { namespace math { - struct Matrix + template + struct MatrixMultiply; + + template + struct MatrixT { + using value_type = _Ty; + union { struct { - float m[6]; // m[3][2] + _Ty m[6]; // m[3][2] }; struct { - float + _Ty _11, _12, _21, _22, _31, _32; }; }; - Matrix() + MatrixT() : _11(1.f), _12(0.f) , _21(0.f), _22(1.f) , _31(0.f), _32(0.f) { } - Matrix(float _11, float _12, float _21, float _22, float _31, float _32) + MatrixT(value_type _11, value_type _12, value_type _21, value_type _22, value_type _31, value_type _32) : _11(_11), _12(_12), _21(_21), _22(_22), _31(_31), _32(_32) { } - explicit Matrix(const float* p) + explicit MatrixT(const value_type* p) { for (int i = 0; i < 6; i++) m[i] = p[i]; } - Matrix(Matrix const& other) + MatrixT(MatrixT const& other) : _11(other._11), _12(other._12) , _21(other._21), _22(other._22) , _31(other._31), _32(other._32) @@ -71,7 +77,7 @@ namespace kiwano } template - Matrix(T const& other) + MatrixT(T const& other) { for (int i = 0; i < 6; i++) m[i] = other[i]; @@ -92,17 +98,17 @@ namespace kiwano ); } - Rect Transform(const Rect & rect) const + RectT Transform(const Rect & rect) const { - Vec2 top_left = Transform(rect.GetLeftTop()); - Vec2 top_right = Transform(rect.GetRightTop()); - Vec2 bottom_left = Transform(rect.GetLeftBottom()); - Vec2 bottom_right = Transform(rect.GetRightBottom()); + Vec2T top_left = Transform(rect.GetLeftTop()); + Vec2T top_right = Transform(rect.GetRightTop()); + Vec2T bottom_left = Transform(rect.GetLeftBottom()); + Vec2T bottom_right = Transform(rect.GetRightBottom()); - float left = std::min(std::min(top_left.x, top_right.x), std::min(bottom_left.x, bottom_right.x)); - float right = std::max(std::max(top_left.x, top_right.x), std::max(bottom_left.x, bottom_right.x)); - float top = std::min(std::min(top_left.y, top_right.y), std::min(bottom_left.y, bottom_right.y)); - float bottom = std::max(std::max(top_left.y, top_right.y), std::max(bottom_left.y, bottom_right.y)); + value_type left = std::min(std::min(top_left.x, top_right.x), std::min(bottom_left.x, bottom_right.x)); + value_type right = std::max(std::max(top_left.x, top_right.x), std::max(bottom_left.x, bottom_right.x)); + value_type top = std::min(std::min(top_left.y, top_right.y), std::min(bottom_left.y, bottom_right.y)); + value_type bottom = std::max(std::max(top_left.y, top_right.y), std::max(bottom_left.y, bottom_right.y)); return Rect{ left, top, (right - left), (bottom - top) }; } @@ -113,20 +119,20 @@ namespace kiwano _32 += _12 * v.x + _22 * v.y; } - inline float operator [](unsigned int index) const + inline value_type operator [](unsigned int index) const { return m[index]; } - template - inline Matrix& operator =(T const& other) + template + inline MatrixT& operator= (MatrixMultiply const& other) { for (int i = 0; i < 6; i++) m[i] = other[i]; return *this; } - inline float Determinant() const + inline value_type Determinant() const { return (_11 * _22) - (_12 * _21); } @@ -143,27 +149,27 @@ namespace kiwano return 0 != Determinant(); } - static inline Matrix Translation(const Vec2& v) + static inline MatrixT Translation(const Vec2& v) { - return Matrix( + return MatrixT( 1.f, 0.f, 0.f, 1.f, v.x, v.y ); } - static inline Matrix Translation( - float x, - float y) + static inline MatrixT Translation( + value_type x, + value_type y) { return Translation(Vec2(x, y)); } - static inline Matrix Scaling( + static inline MatrixT Scaling( const Vec2& v, const Vec2& center = Vec2()) { - return Matrix( + return MatrixT( v.x, 0.f, 0.f, v.y, center.x - v.x * center.x, @@ -171,21 +177,21 @@ namespace kiwano ); } - static inline Matrix Scaling( - float x, - float y, + static inline MatrixT Scaling( + value_type x, + value_type y, const Vec2& center = Vec2()) { return Scaling(Vec2(x, y), center); } - static inline Matrix Rotation( - float angle, + static inline MatrixT Rotation( + value_type angle, const Vec2& center = Vec2()) { - float s = math::Sin(angle); - float c = math::Cos(angle); - return Matrix( + value_type s = math::Sin(angle); + value_type c = math::Cos(angle); + return MatrixT( c, s, -s, c, center.x * (1 - c) + center.y * s, @@ -193,25 +199,25 @@ namespace kiwano ); } - static inline Matrix Skewing( - float angle_x, - float angle_y, + static inline MatrixT Skewing( + value_type angle_x, + value_type angle_y, const Vec2& center = Vec2()) { - float tx = math::Tan(angle_x); - float ty = math::Tan(angle_y); - return Matrix( + value_type tx = math::Tan(angle_x); + value_type ty = math::Tan(angle_y); + return MatrixT( 1.f, -ty, -tx, 1.f, center.y * tx, center.x * ty ); } - static inline Matrix Invert(Matrix const& matrix) + static inline MatrixT Invert(MatrixT const& matrix) { - float det = 1.f / matrix.Determinant(); + value_type det = 1.f / matrix.Determinant(); - return Matrix( + return MatrixT( det * matrix._22, -det * matrix._12, -det * matrix._21, @@ -224,18 +230,18 @@ namespace kiwano // Use template expression to optimize matrix multiply - template + template struct MatrixMultiply { - L const& lhs; - R const& rhs; + _Lty const& lhs; + _Rty const& rhs; - MatrixMultiply(L const& lhs, R const& rhs) + MatrixMultiply(_Lty const& lhs, _Rty const& rhs) : lhs(lhs) , rhs(rhs) {} - inline float operator [](unsigned int index) const + inline _Ty operator [](unsigned int index) const { switch (index) { @@ -257,15 +263,25 @@ namespace kiwano } }; - inline MatrixMultiply operator *(Matrix const& lhs, Matrix const& rhs) + template + inline + MatrixMultiply<_Ty, MatrixT<_Ty>, MatrixT<_Ty>> + operator *(MatrixT<_Ty> const& lhs, MatrixT<_Ty> const& rhs) { - return MatrixMultiply(lhs, rhs); + return MatrixMultiply<_Ty, MatrixT<_Ty>, MatrixT<_Ty>>(lhs, rhs); } - template - inline MatrixMultiply, Matrix> operator *(MatrixMultiply const& lhs, Matrix const& rhs) + template + inline + MatrixMultiply<_Ty, MatrixMultiply<_Ty, _Lty, _Rty>, MatrixT<_Ty>> + operator *(MatrixMultiply<_Ty, _Lty, _Rty> const& lhs, MatrixT<_Ty> const& rhs) { - return MatrixMultiply, Matrix>(lhs, rhs); + return MatrixMultiply<_Ty, MatrixMultiply<_Ty, _Lty, _Rty>, MatrixT<_Ty>>(lhs, rhs); } } } + +namespace kiwano +{ + using Matrix = kiwano::math::MatrixT; +} diff --git a/Kiwano/math/Rect.hpp b/Kiwano/math/Rect.hpp index 4e840a67..9d502e95 100644 --- a/Kiwano/math/Rect.hpp +++ b/Kiwano/math/Rect.hpp @@ -26,24 +26,29 @@ namespace kiwano namespace math { // 矩形 - struct Rect + template + struct RectT { - Vec2 origin; // 左上角坐标 - Vec2 size; // 宽度和高度 + public: + using value_type = _Ty; - Rect() {} + Vec2T origin; // 左上角坐标 + Vec2T size; // 宽度和高度 - Rect( - float x, - float y, - float width, - float height + public: + RectT() {} + + RectT( + value_type x, + value_type y, + value_type width, + value_type height ) : origin(x, y) , size(width, height) {} - Rect( + RectT( const Vec2& pos, const Vec2& size ) @@ -51,26 +56,26 @@ namespace kiwano , size(size.x, size.y) {} - Rect( - const Rect& other + RectT( + const RectT& other ) : origin(other.origin.x, other.origin.y) , size(other.size.x, other.size.y) {} - Rect& operator= (const Rect& other) + RectT& operator= (const RectT& other) { origin = other.origin; size = other.size; return *this; } - inline bool operator== (const Rect& rect) const + inline bool operator== (const RectT& rect) const { return (origin == rect.origin) && (size == rect.size); } - inline void Set(float x, float y, float width, float height) { origin = Vec2{ x, y }; size = Vec2{ width, height }; } + inline void Set(value_type x, value_type y, value_type width, value_type height) { origin = Vec2{ x, y }; size = Vec2{ width, height }; } inline Vec2 GetCenter() const { return Vec2{ origin.x + size.x / 2, origin.y + size.y / 2 }; } @@ -82,13 +87,13 @@ namespace kiwano inline Vec2 GetLeftBottom() const { return Vec2{ GetLeft(), GetBottom() }; } - inline float GetLeft() const { return origin.x; } + inline value_type GetLeft() const { return origin.x; } - inline float GetTop() const { return origin.y; } + inline value_type GetTop() const { return origin.y; } - inline float GetRight() const { return origin.x + size.x; } + inline value_type GetRight() const { return origin.x + size.x; } - inline float GetBottom() const { return origin.y + size.y; } + inline value_type GetBottom() const { return origin.y + size.y; } inline bool IsEmpty() const { return origin.IsOrigin() && size.IsOrigin(); } @@ -100,7 +105,7 @@ namespace kiwano } // 判断两矩形是否相交 - inline bool Intersects(const Rect& rect) const + inline bool Intersects(const RectT& rect) const { return !((origin.x + size.x) < rect.origin.x || (rect.origin.x + rect.size.x) < origin.x || @@ -110,3 +115,8 @@ namespace kiwano }; } } + +namespace kiwano +{ + using Rect = kiwano::math::RectT; +} diff --git a/Kiwano/math/Vec2.hpp b/Kiwano/math/Vec2.hpp index dd44942e..ac2bf2ca 100644 --- a/Kiwano/math/Vec2.hpp +++ b/Kiwano/math/Vec2.hpp @@ -25,18 +25,21 @@ namespace kiwano { namespace math { - struct Vec2 + template + struct Vec2T { - float x; - float y; + using value_type = _Ty; - Vec2() : x(0.f), y(0.f) {} + value_type x; + value_type y; - Vec2(float x, float y) : x(x), y(y) {} + Vec2T() : x(0.f), y(0.f) {} - Vec2(const Vec2& other) : x(other.x), y(other.y) {} + Vec2T(value_type x, value_type y) : x(x), y(y) {} - inline float Length() const + Vec2T(const Vec2T& other) : x(other.x), y(other.y) {} + + inline value_type Length() const { return math::Sqrt(x * x + y * y); } @@ -46,46 +49,51 @@ namespace kiwano return (x == 0) && (y == 0); } - inline void Set(float x, float y) + inline void Set(value_type x, value_type y) { this->x = x; this->y = y; } - inline const Vec2 operator + (const Vec2 & other) const + inline const Vec2T operator + (const Vec2T & other) const { - return Vec2(x + other.x, y + other.y); + return Vec2T(x + other.x, y + other.y); } - inline const Vec2 operator - (const Vec2 & other) const + inline const Vec2T operator - (const Vec2T & other) const { - return Vec2(x - other.x, y - other.y); + return Vec2T(x - other.x, y - other.y); } - inline const Vec2 operator * (float val) const + inline const Vec2T operator * (value_type val) const { - return Vec2(x * val, y * val); + return Vec2T(x * val, y * val); } - inline const Vec2 operator / (float val) const + inline const Vec2T operator / (value_type val) const { - return Vec2(x / val, y / val); + return Vec2T(x / val, y / val); } - inline const Vec2 operator - () const + inline const Vec2T operator - () const { - return Vec2(-x, -y); + return Vec2T(-x, -y); } - inline bool operator== (const Vec2& other) const + inline bool operator== (const Vec2T& other) const { return (x == other.x) && (y == other.y); } - inline bool operator!= (const Vec2& other) const + inline bool operator!= (const Vec2T& other) const { return (x != other.x) || (y != other.y); } }; } -} \ No newline at end of file +} + +namespace kiwano +{ + using Vec2 = kiwano::math::Vec2T; +} diff --git a/Kiwano/math/helper.h b/Kiwano/math/helper.h index f0db880a..46af02dd 100644 --- a/Kiwano/math/helper.h +++ b/Kiwano/math/helper.h @@ -28,8 +28,6 @@ namespace kiwano { - using namespace kiwano::math; - - typedef Vec2 Point; - typedef Vec2 Size; + using Point = Vec2; + using Size = Vec2; } diff --git a/Kiwano/network/HttpClient.cpp b/Kiwano/network/HttpClient.cpp index 364457b0..908d8e06 100644 --- a/Kiwano/network/HttpClient.cpp +++ b/Kiwano/network/HttpClient.cpp @@ -262,7 +262,7 @@ namespace kiwano ::curl_global_cleanup(); } - void HttpClient::Send(HttpRequestPtr const & request) + void HttpClient::Send(HttpRequestPtr request) { if (!request) return; @@ -300,7 +300,7 @@ namespace kiwano } } - void HttpClient::Perform(HttpRequestPtr const & request, HttpResponsePtr const & response) + void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response) { bool ok = false; long response_code = 0; diff --git a/Kiwano/network/HttpClient.h b/Kiwano/network/HttpClient.h index 0cb6ab10..ba0c3c59 100644 --- a/Kiwano/network/HttpClient.h +++ b/Kiwano/network/HttpClient.h @@ -34,7 +34,7 @@ namespace kiwano public: void Send( - HttpRequestPtr const& request + HttpRequestPtr request ); inline void SetTimeoutForConnect(Duration timeout) @@ -78,8 +78,8 @@ namespace kiwano void NetworkThread(); void Perform( - HttpRequestPtr const& request, - HttpResponsePtr const& response + HttpRequestPtr request, + HttpResponsePtr response ); void DispatchResponseCallback(); diff --git a/Kiwano/network/HttpResponse.h b/Kiwano/network/HttpResponse.h index 844f6d3c..635fed71 100644 --- a/Kiwano/network/HttpResponse.h +++ b/Kiwano/network/HttpResponse.h @@ -28,14 +28,14 @@ namespace kiwano : public Object { public: - inline HttpResponse(HttpRequestPtr const& request) + inline HttpResponse(HttpRequestPtr request) : request_(request) , succeed_(false) , response_code_(0) { } - inline HttpRequestPtr const& GetRequest() const + inline HttpRequestPtr GetRequest() const { return request_; } diff --git a/Kiwano/platform/Application.cpp b/Kiwano/platform/Application.cpp index 5cd1e20b..28f08590 100644 --- a/Kiwano/platform/Application.cpp +++ b/Kiwano/platform/Application.cpp @@ -187,7 +187,7 @@ namespace kiwano } } - void Application::EnterScene(ScenePtr const & scene) + void Application::EnterScene(ScenePtr scene) { KGE_ASSERT(scene && "Application::EnterScene failed, NULL pointer exception"); @@ -197,7 +197,7 @@ namespace kiwano next_scene_ = scene; } - void Application::EnterScene(ScenePtr const& scene, TransitionPtr const& transition) + void Application::EnterScene(ScenePtr scene, TransitionPtr transition) { EnterScene(scene); @@ -212,7 +212,7 @@ namespace kiwano } } - ScenePtr const& Application::GetCurrentScene() + ScenePtr Application::GetCurrentScene() { return curr_scene_; } diff --git a/Kiwano/platform/Application.h b/Kiwano/platform/Application.h index aa3dcdfa..439caf3a 100644 --- a/Kiwano/platform/Application.h +++ b/Kiwano/platform/Application.h @@ -105,17 +105,17 @@ namespace kiwano // 切换场景 void EnterScene( - ScenePtr const& scene /* 场景 */ + ScenePtr scene /* 场景 */ ); // 切换场景 void EnterScene( - ScenePtr const& scene, /* 场景 */ - TransitionPtr const& transition /* 场景动画 */ + ScenePtr scene, /* 场景 */ + TransitionPtr transition /* 场景动画 */ ); // 获取当前场景 - ScenePtr const& GetCurrentScene(); + ScenePtr GetCurrentScene(); // 获取主窗口 inline Window* GetWindow() const { return main_window_; } diff --git a/Kiwano/renderer/helper.hpp b/Kiwano/renderer/helper.hpp index e0ef844a..47097db3 100644 --- a/Kiwano/renderer/helper.hpp +++ b/Kiwano/renderer/helper.hpp @@ -38,17 +38,17 @@ namespace kiwano } } - inline D2D1_POINT_2F const& ConvertToPoint2F(math::Vec2 const& point) + inline D2D1_POINT_2F const& ConvertToPoint2F(Vec2 const& point) { return reinterpret_cast(point); } - inline D2D1_SIZE_F const& ConvertToSizeF(math::Vec2 const& size) + inline D2D1_SIZE_F const& ConvertToSizeF(Vec2 const& size) { return reinterpret_cast(size); } - inline D2D1_RECT_F ConvertToRectF(math::Rect const& rect) + inline D2D1_RECT_F ConvertToRectF(Rect const& rect) { return D2D1_RECT_F{ rect.origin.x, rect.origin.y, rect.origin.x + rect.size.x, rect.origin.y + rect.size.y }; } @@ -58,7 +58,7 @@ namespace kiwano return reinterpret_cast(color); } - inline D2D1_MATRIX_3X2_F const& ConvertToMatrix3x2F(math::Matrix const& matrix) + inline D2D1_MATRIX_3X2_F const& ConvertToMatrix3x2F(Matrix const& matrix) { return reinterpret_cast(matrix); } diff --git a/Kiwano/renderer/render.cpp b/Kiwano/renderer/render.cpp index 9ec17eca..56b7485c 100644 --- a/Kiwano/renderer/render.cpp +++ b/Kiwano/renderer/render.cpp @@ -227,7 +227,7 @@ namespace kiwano return S_OK; } - HRESULT Renderer::DrawImage(ImagePtr const & image, Rect const& dest_rect) + HRESULT Renderer::DrawImage(ImagePtr image, Rect const& dest_rect) { if (!device_context_) return E_UNEXPECTED; diff --git a/Kiwano/renderer/render.h b/Kiwano/renderer/render.h index 179c3225..1b3f5f71 100644 --- a/Kiwano/renderer/render.h +++ b/Kiwano/renderer/render.h @@ -66,7 +66,7 @@ namespace kiwano ); HRESULT DrawImage( - ImagePtr const& image, + ImagePtr image, Rect const& dest_rect ); diff --git a/Kiwano/ui/Button.cpp b/Kiwano/ui/Button.cpp index 85830070..29923e48 100644 --- a/Kiwano/ui/Button.cpp +++ b/Kiwano/ui/Button.cpp @@ -79,6 +79,11 @@ namespace kiwano pressed_callback_ = func; } + void Button::SetReleasedCallback(const Callback& func) + { + released_callback_ = func; + } + void Button::SetMouseOverCallback(const Callback & func) { mouse_over_callback_ = func; @@ -130,6 +135,9 @@ namespace kiwano { SetStatus(Status::Hover); + if (released_callback_) + released_callback_(); + if (click_callback_) click_callback_(); } diff --git a/Kiwano/ui/Button.h b/Kiwano/ui/Button.h index fc066f41..7529a5e7 100644 --- a/Kiwano/ui/Button.h +++ b/Kiwano/ui/Button.h @@ -27,16 +27,16 @@ namespace kiwano class KGE_API Button : public Sprite { + public: using Callback = Closure; - public: Button(); explicit Button( Callback const& click /* 按钮点击回调函数 */ ); - explicit Button( + Button( Callback const& click, /* 按钮点击回调函数 */ Callback const& pressed, /* 按钮按下回调函数 */ Callback const& mouse_over, /* 按钮移入回调函数 */ @@ -63,6 +63,11 @@ namespace kiwano const Callback& func ); + // 设置按钮被抬起时的回调函数 + void SetReleasedCallback( + const Callback& func + ); + // 设置鼠标移入按钮时的回调函数 void SetMouseOverCallback( const Callback& func @@ -88,6 +93,7 @@ namespace kiwano Status status_; Callback click_callback_; Callback pressed_callback_; + Callback released_callback_; Callback mouse_over_callback_; Callback mouse_out_callback_; }; diff --git a/Kiwano/ui/Menu.cpp b/Kiwano/ui/Menu.cpp index e093e344..56a591b9 100644 --- a/Kiwano/ui/Menu.cpp +++ b/Kiwano/ui/Menu.cpp @@ -41,7 +41,7 @@ namespace kiwano return enabled_; } - int Menu::GetButtonCount() const + size_t Menu::GetButtonCount() const { return buttons_.size(); } @@ -59,7 +59,7 @@ namespace kiwano } } - void Menu::AddButton(ButtonPtr const& button) + void Menu::AddButton(ButtonPtr button) { if (button) { @@ -69,7 +69,7 @@ namespace kiwano } } - bool Menu::RemoveButton(ButtonPtr const& button) + bool Menu::RemoveButton(ButtonPtr button) { if (buttons_.empty()) { diff --git a/Kiwano/ui/Menu.h b/Kiwano/ui/Menu.h index 5c3e4e2a..a06424fc 100644 --- a/Kiwano/ui/Menu.h +++ b/Kiwano/ui/Menu.h @@ -38,7 +38,7 @@ namespace kiwano bool IsEnable() const; // 获取菜单中的按钮数量 - int GetButtonCount() const; + size_t GetButtonCount() const; // 设置菜单启用或禁用 void SetEnabled( @@ -47,12 +47,12 @@ namespace kiwano // 添加按钮 void AddButton( - ButtonPtr const& button + ButtonPtr button ); // 移除按钮 bool RemoveButton( - ButtonPtr const& button + ButtonPtr button ); // 获取所有按钮 diff --git a/Kiwano/utils/ResLoader.cpp b/Kiwano/utils/ResLoader.cpp index d48b990e..e0b62ae3 100644 --- a/Kiwano/utils/ResLoader.cpp +++ b/Kiwano/utils/ResLoader.cpp @@ -58,7 +58,7 @@ namespace kiwano return false; } - bool ResLoader::AddImage(String const & id, ImagePtr const & image) + bool ResLoader::AddImage(String const & id, ImagePtr image) { if (image) { @@ -68,7 +68,7 @@ namespace kiwano return false; } - int ResLoader::AddFrames(String const& id, Array const& images) + size_t ResLoader::AddFrames(String const& id, Array const& images) { if (images.empty()) return 0; @@ -100,7 +100,7 @@ namespace kiwano return 0; } - int ResLoader::AddFrames(String const& id, Array const& images) + size_t ResLoader::AddFrames(String const& id, Array const& images) { if (images.empty()) return 0; @@ -114,7 +114,7 @@ namespace kiwano return 0; } - int ResLoader::AddFrames(String const & id, Resource const & image, int cols, int rows) + size_t ResLoader::AddFrames(String const & id, Resource const & image, int cols, int rows) { if (cols <= 0 || rows <= 0) return 0; @@ -153,7 +153,7 @@ namespace kiwano return 0; } - int ResLoader::AddFrames(String const & id, Resource const & image, Array const & crop_rects) + size_t ResLoader::AddFrames(String const & id, Resource const & image, Array const & crop_rects) { ImagePtr raw = new (std::nothrow) Image; if (!raw || !raw->Load(LocateRes(image, search_paths_))) @@ -181,7 +181,7 @@ namespace kiwano return 0; } - bool ResLoader::AddFrames(String const & id, FramesPtr const & frames) + bool ResLoader::AddFrames(String const & id, FramesPtr frames) { if (frames) { @@ -191,7 +191,7 @@ namespace kiwano return false; } - bool ResLoader::AddObj(String const& id, ObjectPtr const& obj) + bool ResLoader::AddObj(String const& id, ObjectPtr obj) { if (obj) { diff --git a/Kiwano/utils/ResLoader.h b/Kiwano/utils/ResLoader.h index ba42515c..7b1e69ec 100644 --- a/Kiwano/utils/ResLoader.h +++ b/Kiwano/utils/ResLoader.h @@ -33,27 +33,27 @@ namespace kiwano bool AddImage(String const& id, Resource const& image); // 添加图片 - bool AddImage(String const& id, ImagePtr const& image); + bool AddImage(String const& id, ImagePtr image); // 添加帧集合 - int AddFrames(String const& id, Array const& images); + size_t AddFrames(String const& id, Array const& images); // 添加帧集合 - int AddFrames(String const& id, Array const& images); + size_t AddFrames(String const& id, Array const& images); // 添加帧集合 // 按行列数裁剪图片 - int AddFrames(String const& id, Resource const& image, int cols, int rows = 1); + size_t AddFrames(String const& id, Resource const& image, int cols, int rows = 1); // 添加帧集合 // 按指定裁剪矩形裁剪图片 - int AddFrames(String const& id, Resource const& image, Array const& crop_rects); + size_t AddFrames(String const& id, Resource const& image, Array const& crop_rects); // 添加帧集合 - bool AddFrames(String const& id, FramesPtr const& frames); + bool AddFrames(String const& id, FramesPtr frames); // 添加对象 - bool AddObj(String const& id, ObjectPtr const& obj); + bool AddObj(String const& id, ObjectPtr obj); ImagePtr GetImage(String const& id) const;