diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index 4ec7a3d1..ffe0546b 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -11,7 +11,6 @@
-
@@ -64,6 +63,7 @@
+
@@ -123,11 +123,11 @@
-
+
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index 2f48b1a4..87053e5a 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -117,9 +117,6 @@
2d
-
- core
-
2d
@@ -303,6 +300,9 @@
platform
+
+ platform
+
@@ -356,9 +356,6 @@
2d
-
- core
-
2d
@@ -485,5 +482,8 @@
platform
+
+ platform
+
\ No newline at end of file
diff --git a/src/kiwano-physics/ContactEvent.cpp b/src/kiwano-physics/ContactEvent.cpp
index 108134a7..ae7f13ac 100644
--- a/src/kiwano-physics/ContactEvent.cpp
+++ b/src/kiwano-physics/ContactEvent.cpp
@@ -24,7 +24,7 @@ namespace kiwano
{
namespace event
{
- EventType event::ContactBegin = EventType(L"ContactBegin");
+ EventType event::ContactBegin = EventType(L"ContactBegin");
EventType event::ContactEnd = EventType(L"ContactEnd");
}
diff --git a/src/kiwano-physics/World.cpp b/src/kiwano-physics/World.cpp
index 9a808a16..71f61377 100644
--- a/src/kiwano-physics/World.cpp
+++ b/src/kiwano-physics/World.cpp
@@ -68,13 +68,13 @@ namespace kiwano
void BeginContact(b2Contact* contact) override
{
ContactBeginEvent evt(contact);
- world_->Dispatch(&evt);
+ world_->Dispatch(evt);
}
void EndContact(b2Contact* contact) override
{
ContactEndEvent evt(contact);
- world_->Dispatch(&evt);
+ world_->Dispatch(evt);
}
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override { KGE_NOT_USED(contact); KGE_NOT_USED(oldManifold); }
@@ -227,33 +227,37 @@ namespace kiwano
void World::Update(Duration dt)
{
- Stage::Update(dt);
-
- b2Body* b2body = world_.GetBodyList();
- while (b2body)
{
- Body* body = static_cast
(b2body->GetUserData());
- if (body && body->GetType() != Body::Type::Static)
+ b2Body* b2body = world_.GetBodyList();
+ while (b2body)
{
- body->UpdateFromActor();
- }
+ Body* body = static_cast(b2body->GetUserData());
+ if (body && body->GetType() != Body::Type::Static)
+ {
+ body->UpdateFromActor();
+ }
- b2body = b2body->GetNext();
+ b2body = b2body->GetNext();
+ }
}
world_.Step(dt.Seconds(), vel_iter_, pos_iter_);
- b2body = world_.GetBodyList();
- while (b2body)
{
- Body* body = static_cast(b2body->GetUserData());
- if (body && body->GetType() != Body::Type::Static)
+ b2Body* b2body = world_.GetBodyList();
+ while (b2body)
{
- body->UpdateActor();
- }
+ Body* body = static_cast(b2body->GetUserData());
+ if (body && body->GetType() != Body::Type::Static)
+ {
+ body->UpdateActor();
+ }
- b2body = b2body->GetNext();
+ b2body = b2body->GetNext();
+ }
}
+
+ Stage::Update(dt);
}
}
diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp
index 3570d728..ec4f0eff 100644
--- a/src/kiwano/2d/Actor.cpp
+++ b/src/kiwano/2d/Actor.cpp
@@ -62,11 +62,11 @@ namespace kiwano
void Actor::Update(Duration dt)
{
+ UpdateActions(this, dt);
+ UpdateTimers(dt);
+
if (!update_pausing_)
{
- UpdateActions(this, dt);
- UpdateTimers(dt);
-
if (cb_update_)
cb_update_(dt);
@@ -155,7 +155,7 @@ namespace kiwano
return visible_in_rt_;
}
- void Actor::Dispatch(Event* evt)
+ void Actor::Dispatch(Event& evt)
{
if (!visible_)
return;
@@ -169,9 +169,9 @@ namespace kiwano
if (responsible_)
{
- if (evt->type == event::MouseMove)
+ if (evt.type == event::MouseMove)
{
- auto mouse_evt = evt->SafeCast();
+ auto mouse_evt = evt.SafeCast();
if (!mouse_evt->target && ContainsPoint(mouse_evt->pos))
{
mouse_evt->target = this;
@@ -185,7 +185,7 @@ namespace kiwano
hover.left_btn_down = mouse_evt->left_btn_down;
hover.right_btn_down = mouse_evt->right_btn_down;
hover.target = this;
- EventDispatcher::Dispatch(&hover);
+ EventDispatcher::Dispatch(hover);
}
}
else if (hover_)
@@ -198,29 +198,30 @@ namespace kiwano
out.left_btn_down = mouse_evt->left_btn_down;
out.right_btn_down = mouse_evt->right_btn_down;
out.target = this;
- EventDispatcher::Dispatch(&out);
+ EventDispatcher::Dispatch(out);
}
}
- if (evt->type == event::MouseDown && hover_)
+ if (evt.type == event::MouseDown && hover_)
{
pressed_ = true;
- evt->SafeCast()->target = this;
+ evt.SafeCast()->target = this;
}
- if (evt->type == event::MouseUp && pressed_)
+ if (evt.type == event::MouseUp && pressed_)
{
pressed_ = false;
- auto mouse_up_evt = evt->SafeCast();
+ auto mouse_up_evt = evt.SafeCast();
mouse_up_evt->target = this;
- MouseOutEvent click;
+ MouseClickEvent click;
click.pos = mouse_up_evt->pos;
click.left_btn_down = mouse_up_evt->left_btn_down;
click.right_btn_down = mouse_up_evt->right_btn_down;
click.target = this;
- EventDispatcher::Dispatch(&click);
+ click.button = mouse_up_evt->button;
+ EventDispatcher::Dispatch(click);
}
}
diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h
index 8b0e97fd..975c5338 100644
--- a/src/kiwano/2d/Actor.h
+++ b/src/kiwano/2d/Actor.h
@@ -365,7 +365,7 @@ namespace kiwano
void ShowBorder(bool show);
// 事件分发
- void Dispatch(Event* evt) override;
+ void Dispatch(Event& evt) override;
// 设置默认锚点
static void SetDefaultAnchor(
diff --git a/src/kiwano/2d/DebugActor.cpp b/src/kiwano/2d/DebugActor.cpp
index 5d53e1fa..f220de25 100644
--- a/src/kiwano/2d/DebugActor.cpp
+++ b/src/kiwano/2d/DebugActor.cpp
@@ -66,8 +66,8 @@ namespace kiwano
style.line_spacing = 20.f;
debug_text_->SetStyle(style);
- AddListener(event::MouseHover, [=](Event*) { SetOpacity(0.4f); });
- AddListener(event::MouseOut, [=](Event*) { SetOpacity(1.f); });
+ AddListener(event::MouseHover, [=](Event&) { SetOpacity(0.4f); });
+ AddListener(event::MouseOut, [=](Event&) { SetOpacity(1.f); });
}
DebugActor::~DebugActor()
diff --git a/src/kiwano/2d/Layer.cpp b/src/kiwano/2d/Layer.cpp
index 270c50a7..7e46fceb 100644
--- a/src/kiwano/2d/Layer.cpp
+++ b/src/kiwano/2d/Layer.cpp
@@ -64,7 +64,7 @@ namespace kiwano
area_.SetMaskTransform(transform);
}
- void Layer::Dispatch(Event* evt)
+ void Layer::Dispatch(Event& evt)
{
if (!IsVisible())
return;
@@ -91,41 +91,41 @@ namespace kiwano
rt->PopLayer();
}
- void Layer::HandleMessages(Event* evt)
+ void Layer::HandleMessages(Event& evt)
{
- if (evt->type == event::MouseDown)
+ if (evt.type == event::MouseDown)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnMouseButtonDown(real_evt->button, real_evt->pos);
}
- else if (evt->type == event::MouseUp)
+ else if (evt.type == event::MouseUp)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnMouseButtonUp(real_evt->button, real_evt->pos);
}
- else if (evt->type == event::MouseMove)
+ else if (evt.type == event::MouseMove)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnMouseMoved(real_evt->pos);
}
- else if (evt->type == event::MouseWheel)
+ else if (evt.type == event::MouseWheel)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnMouseWheel(real_evt->wheel);
}
- else if (evt->type == event::KeyDown)
+ else if (evt.type == event::KeyDown)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnKeyDown(real_evt->code);
}
- else if (evt->type == event::KeyUp)
+ else if (evt.type == event::KeyUp)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnKeyUp(real_evt->code);
}
- else if (evt->type == event::KeyChar)
+ else if (evt.type == event::KeyChar)
{
- auto real_evt = evt->SafeCast();
+ auto real_evt = evt.SafeCast();
OnChar(real_evt->value);
}
}
diff --git a/src/kiwano/2d/Layer.h b/src/kiwano/2d/Layer.h
index fa06e350..6bab3dd7 100644
--- a/src/kiwano/2d/Layer.h
+++ b/src/kiwano/2d/Layer.h
@@ -67,12 +67,12 @@ namespace kiwano
inline LayerArea const& GetArea() const { return area_; }
public:
- void Dispatch(Event* evt) override;
+ void Dispatch(Event& evt) override;
protected:
void Render(RenderTarget* rt) override;
- void HandleMessages(Event* evt);
+ void HandleMessages(Event& evt);
protected:
bool swallow_;
diff --git a/src/kiwano/core/Component.h b/src/kiwano/core/Component.h
index 8c556108..9dde2529 100644
--- a/src/kiwano/core/Component.h
+++ b/src/kiwano/core/Component.h
@@ -85,7 +85,7 @@ namespace kiwano
: public virtual ComponentBase
{
public:
- virtual void HandleEvent(Event*) {}
+ virtual void HandleEvent(Event&) {}
virtual void HandleMessage(HWND, UINT32, WPARAM, LPARAM) {}
diff --git a/src/kiwano/core/Event.cpp b/src/kiwano/core/Event.cpp
index 681d92ee..41a0221c 100644
--- a/src/kiwano/core/Event.cpp
+++ b/src/kiwano/core/Event.cpp
@@ -3,8 +3,8 @@
namespace kiwano
{
EventType event::MouseMove = EventType(L"MouseMove");
- EventType event::MouseDown = EventType(L"MouseBtnDown");
- EventType event::MouseUp = EventType(L"MouseBtnUp");
+ EventType event::MouseDown = EventType(L"MouseDown");
+ EventType event::MouseUp = EventType(L"MouseUp");
EventType event::MouseWheel = EventType(L"MouseWheel");
EventType event::MouseHover = EventType(L"MouseHover");
EventType event::MouseOut = EventType(L"MouseOut");
@@ -82,21 +82,18 @@ namespace kiwano
KeyDownEvent::KeyDownEvent()
: Event(event::KeyDown)
, code(0)
- , count(0)
{
}
KeyUpEvent::KeyUpEvent()
: Event(event::KeyUp)
, code(0)
- , count(0)
{
}
KeyCharEvent::KeyCharEvent()
: Event(event::KeyChar)
, value()
- , count(0)
{
}
diff --git a/src/kiwano/core/Event.h b/src/kiwano/core/Event.h
index c5e64394..420b35e9 100644
--- a/src/kiwano/core/Event.h
+++ b/src/kiwano/core/Event.h
@@ -192,7 +192,6 @@ namespace kiwano
{
public:
KeyCode::Value code;
- int count;
KeyDownEvent();
};
@@ -203,7 +202,6 @@ namespace kiwano
{
public:
KeyCode::Value code;
- int count;
KeyUpEvent();
};
@@ -214,7 +212,6 @@ namespace kiwano
{
public:
char value;
- int count;
KeyCharEvent();
};
diff --git a/src/kiwano/core/EventDispatcher.cpp b/src/kiwano/core/EventDispatcher.cpp
index 222bd4b7..5cef85db 100644
--- a/src/kiwano/core/EventDispatcher.cpp
+++ b/src/kiwano/core/EventDispatcher.cpp
@@ -23,7 +23,7 @@
namespace kiwano
{
- void EventDispatcher::Dispatch(Event* evt)
+ void EventDispatcher::Dispatch(Event& evt)
{
if (listeners_.empty())
return;
@@ -33,7 +33,7 @@ namespace kiwano
{
next = listener->next_item();
- if (listener->IsRunning() && listener->type_ == evt->type)
+ if (listener->IsRunning() && listener->type_ == evt.type)
{
listener->callback_(evt);
}
diff --git a/src/kiwano/core/EventDispatcher.h b/src/kiwano/core/EventDispatcher.h
index 49147faf..f91f70eb 100644
--- a/src/kiwano/core/EventDispatcher.h
+++ b/src/kiwano/core/EventDispatcher.h
@@ -81,7 +81,7 @@ namespace kiwano
const EventType& type
);
- virtual void Dispatch(Event* evt);
+ virtual void Dispatch(Event& evt);
protected:
Listeners listeners_;
diff --git a/src/kiwano/core/EventListener.h b/src/kiwano/core/EventListener.h
index 5c8f51c2..a7a082a0 100644
--- a/src/kiwano/core/EventListener.h
+++ b/src/kiwano/core/EventListener.h
@@ -39,7 +39,7 @@ namespace kiwano
friend IntrusiveList;
public:
- using Callback = Function;
+ using Callback = Function;
EventListener();
diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h
index f8b51499..6c8af7a6 100644
--- a/src/kiwano/kiwano.h
+++ b/src/kiwano/kiwano.h
@@ -76,7 +76,6 @@
//
#include
-#include
#include
#include
#include
@@ -130,6 +129,7 @@
#include
#include
#include
+#include
#include
diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp
index 57f56e4b..e55436e4 100644
--- a/src/kiwano/platform/Application.cpp
+++ b/src/kiwano/platform/Application.cpp
@@ -24,7 +24,7 @@
#include
#include
#include
-#include
+#include
#include
#include
@@ -261,7 +261,7 @@ namespace kiwano
}
}
- void Application::DispatchEvent(Event* evt)
+ void Application::DispatchEvent(Event& evt)
{
for (auto c : event_comps_)
{
@@ -311,15 +311,15 @@ namespace kiwano
{
KeyDownEvent evt;
evt.code = static_cast(wparam);
- evt.count = static_cast(lparam & 0xFF);
- app->DispatchEvent(&evt);
+ // evt.count = static_cast(lparam & 0xFF);
+ app->DispatchEvent(evt);
}
else
{
KeyUpEvent evt;
evt.code = static_cast(wparam);
- evt.count = static_cast(lparam & 0xFF);
- app->DispatchEvent(&evt);
+ // evt.count = static_cast(lparam & 0xFF);
+ app->DispatchEvent(evt);
}
}
break;
@@ -328,8 +328,8 @@ namespace kiwano
{
KeyCharEvent evt;
evt.value = static_cast(wparam);
- evt.count = static_cast(lparam & 0xFF);
- app->DispatchEvent(&evt);
+ // evt.count = static_cast(lparam & 0xFF);
+ app->DispatchEvent(evt);
}
break;
@@ -345,43 +345,43 @@ namespace kiwano
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
{
- auto UpdateMouseData = [&](MouseEvent* evt)
+ auto UpdateMouseData = [&](MouseEvent& evt)
{
- evt->pos = Point(static_cast(GET_X_LPARAM(lparam)), static_cast(GET_Y_LPARAM(lparam)));
- evt->left_btn_down = !!(wparam & MK_LBUTTON);
- evt->left_btn_down = !!(wparam & MK_RBUTTON);
+ evt.pos = Point(static_cast(GET_X_LPARAM(lparam)), static_cast(GET_Y_LPARAM(lparam)));
+ evt.left_btn_down = !!(wparam & MK_LBUTTON);
+ evt.left_btn_down = !!(wparam & MK_RBUTTON);
};
if (msg == WM_MOUSEMOVE)
{
MouseMoveEvent evt;
- UpdateMouseData(&evt);
- app->DispatchEvent(&evt);
+ UpdateMouseData(evt);
+ app->DispatchEvent(evt);
}
else if (msg == WM_LBUTTONDOWN || msg == WM_RBUTTONDOWN || msg == WM_MBUTTONDOWN)
{
MouseDownEvent evt;
- UpdateMouseData(&evt);
+ UpdateMouseData(evt);
if (msg == WM_LBUTTONDOWN) { evt.button = MouseButton::Left; }
else if (msg == WM_RBUTTONDOWN) { evt.button = MouseButton::Right; }
else if (msg == WM_MBUTTONDOWN) { evt.button = MouseButton::Middle; }
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
else if (msg == WM_LBUTTONUP || msg == WM_RBUTTONUP || msg == WM_MBUTTONUP)
{
- MouseDownEvent evt;
- UpdateMouseData(&evt);
+ MouseUpEvent evt;
+ UpdateMouseData(evt);
if (msg == WM_LBUTTONUP) { evt.button = MouseButton::Left; }
else if (msg == WM_RBUTTONUP) { evt.button = MouseButton::Right; }
else if (msg == WM_MBUTTONUP) { evt.button = MouseButton::Middle; }
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
else if (msg == WM_MOUSEWHEEL)
{
MouseWheelEvent evt;
- UpdateMouseData(&evt);
+ UpdateMouseData(evt);
evt.wheel = GET_WHEEL_DELTA_WPARAM(wparam) / (float)WHEEL_DELTA;
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
}
break;
@@ -401,7 +401,7 @@ namespace kiwano
WindowResizedEvent evt;
evt.width = LOWORD(lparam);
evt.height = HIWORD(lparam);
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
}
break;
@@ -414,7 +414,7 @@ namespace kiwano
WindowMovedEvent evt;
evt.x = x;
evt.y = y;
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
break;
@@ -426,7 +426,7 @@ namespace kiwano
WindowFocusChangedEvent evt;
evt.focus = active;
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
break;
@@ -436,7 +436,7 @@ namespace kiwano
WindowTitleChangedEvent evt;
evt.title = reinterpret_cast(lparam);
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
}
break;
@@ -467,7 +467,7 @@ namespace kiwano
if (!app->OnClosing())
{
WindowClosedEvent evt;
- app->DispatchEvent(&evt);
+ app->DispatchEvent(evt);
return 0;
}
}
diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h
index 7f5280fa..1d443de9 100644
--- a/src/kiwano/platform/Application.h
+++ b/src/kiwano/platform/Application.h
@@ -91,7 +91,7 @@ namespace kiwano
);
// 分发事件
- void DispatchEvent(Event* evt);
+ void DispatchEvent(Event& evt);
// 在 Kiwano 主线程中执行函数
// 当在其他线程调用 Kiwano 函数时使用
diff --git a/src/kiwano/core/Director.cpp b/src/kiwano/platform/Director.cpp
similarity index 98%
rename from src/kiwano/core/Director.cpp
rename to src/kiwano/platform/Director.cpp
index 7d41966f..007320dd 100644
--- a/src/kiwano/core/Director.cpp
+++ b/src/kiwano/platform/Director.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
#include
#include
@@ -180,7 +180,7 @@ namespace kiwano
}
}
- void Director::HandleEvent(Event* evt)
+ void Director::HandleEvent(Event& evt)
{
if (debug_actor_)
debug_actor_->Dispatch(evt);
diff --git a/src/kiwano/core/Director.h b/src/kiwano/platform/Director.h
similarity index 98%
rename from src/kiwano/core/Director.h
rename to src/kiwano/platform/Director.h
index f96ca9b6..613bc981 100644
--- a/src/kiwano/core/Director.h
+++ b/src/kiwano/platform/Director.h
@@ -72,7 +72,7 @@ namespace kiwano
void OnRender(RenderTarget* rt) override;
- void HandleEvent(Event* evt) override;
+ void HandleEvent(Event& evt) override;
protected:
Director();
diff --git a/src/kiwano/ui/Button.cpp b/src/kiwano/ui/Button.cpp
index 13c15f1c..f8390b5a 100644
--- a/src/kiwano/ui/Button.cpp
+++ b/src/kiwano/ui/Button.cpp
@@ -103,14 +103,14 @@ namespace kiwano
}
}
- void Button::UpdateStatus(Event* evt)
+ void Button::UpdateStatus(Event& evt)
{
- auto mouse_evt = evt->SafeCast();
+ auto mouse_evt = evt.SafeCast();
KGE_ASSERT(mouse_evt);
if (enabled_ && (mouse_evt->target == this))
{
- if (evt->type == event::MouseHover)
+ if (evt.type == event::MouseHover)
{
SetStatus(Status::Hover);
Window::GetInstance()->SetCursor(CursorType::Hand);
@@ -118,7 +118,7 @@ namespace kiwano
if (mouse_over_callback_)
mouse_over_callback_();
}
- else if (evt->type == event::MouseOut)
+ else if (evt.type == event::MouseOut)
{
SetStatus(Status::Normal);
Window::GetInstance()->SetCursor(CursorType::Arrow);
@@ -126,14 +126,14 @@ namespace kiwano
if (mouse_out_callback_)
mouse_out_callback_();
}
- else if (evt->type == event::MouseDown && status_ == Status::Hover)
+ else if (evt.type == event::MouseDown && status_ == Status::Hover)
{
SetStatus(Status::Pressed);
if (pressed_callback_)
pressed_callback_();
}
- else if (evt->type == event::MouseUp && status_ == Status::Pressed)
+ else if (evt.type == event::MouseUp && status_ == Status::Pressed)
{
SetStatus(Status::Hover);
diff --git a/src/kiwano/ui/Button.h b/src/kiwano/ui/Button.h
index 28e16537..ff5df4a9 100644
--- a/src/kiwano/ui/Button.h
+++ b/src/kiwano/ui/Button.h
@@ -84,7 +84,7 @@ namespace kiwano
Status status
);
- void UpdateStatus(Event* evt);
+ void UpdateStatus(Event& evt);
private:
bool enabled_;