[deploy] Merge pull request #45 from KiwanoEngine/dev

some fixes
This commit is contained in:
Haibo 2019-11-14 13:28:26 +08:00 committed by GitHub
commit c9f4fd87f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 112 additions and 113 deletions

View File

@ -11,7 +11,6 @@
<ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" />
<ClInclude Include="..\..\src\kiwano\2d\Frame.h" />
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
<ClInclude Include="..\..\src\kiwano\core\Director.h" />
<ClInclude Include="..\..\src\kiwano\core\Event.h" />
<ClInclude Include="..\..\src\kiwano\core\Library.h" />
<ClInclude Include="..\..\src\kiwano\core\win32\ComPtr.hpp" />
@ -64,6 +63,7 @@
<ClInclude Include="..\..\src\kiwano\math\scalar.h" />
<ClInclude Include="..\..\src\kiwano\math\Vec2.hpp" />
<ClInclude Include="..\..\src\kiwano\platform\Application.h" />
<ClInclude Include="..\..\src\kiwano\platform\Director.h" />
<ClInclude Include="..\..\src\kiwano\platform\FileSystem.h" />
<ClInclude Include="..\..\src\kiwano\platform\Input.h" />
<ClInclude Include="..\..\src\kiwano\platform\modules.h" />
@ -123,11 +123,11 @@
<ClCompile Include="..\..\src\kiwano\core\Logger.cpp" />
<ClCompile Include="..\..\src\kiwano\core\ObjectBase.cpp" />
<ClCompile Include="..\..\src\kiwano\core\Resource.cpp" />
<ClCompile Include="..\..\src\kiwano\core\Director.cpp" />
<ClCompile Include="..\..\src\kiwano\core\Timer.cpp" />
<ClCompile Include="..\..\src\kiwano\core\TimerManager.cpp" />
<ClCompile Include="..\..\src\kiwano\core\time.cpp" />
<ClCompile Include="..\..\src\kiwano\platform\Application.cpp" />
<ClCompile Include="..\..\src\kiwano\platform\Director.cpp" />
<ClCompile Include="..\..\src\kiwano\platform\FileSystem.cpp" />
<ClCompile Include="..\..\src\kiwano\platform\Input.cpp" />
<ClCompile Include="..\..\src\kiwano\platform\modules.cpp" />

View File

@ -117,9 +117,6 @@
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\core\Director.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\Actor.h">
<Filter>2d</Filter>
</ClInclude>
@ -303,6 +300,9 @@
<ClInclude Include="..\..\src\kiwano\platform\Window.h">
<Filter>platform</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\platform\Director.h">
<Filter>platform</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\kiwano\ui\Button.cpp">
@ -356,9 +356,6 @@
<ClCompile Include="..\..\src\kiwano\2d\GifSprite.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\core\Director.cpp">
<Filter>core</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\Actor.cpp">
<Filter>2d</Filter>
</ClCompile>
@ -485,5 +482,8 @@
<ClCompile Include="..\..\src\kiwano\platform\Window.cpp">
<Filter>platform</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\platform\Director.cpp">
<Filter>platform</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -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");
}

View File

@ -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<Body*>(b2body->GetUserData());
if (body && body->GetType() != Body::Type::Static)
b2Body* b2body = world_.GetBodyList();
while (b2body)
{
body->UpdateFromActor();
}
Body* body = static_cast<Body*>(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<Body*>(b2body->GetUserData());
if (body && body->GetType() != Body::Type::Static)
b2Body* b2body = world_.GetBodyList();
while (b2body)
{
body->UpdateActor();
}
Body* body = static_cast<Body*>(b2body->GetUserData());
if (body && body->GetType() != Body::Type::Static)
{
body->UpdateActor();
}
b2body = b2body->GetNext();
b2body = b2body->GetNext();
}
}
Stage::Update(dt);
}
}

View File

@ -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<MouseMoveEvent>();
auto mouse_evt = evt.SafeCast<MouseMoveEvent>();
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<MouseDownEvent>()->target = this;
evt.SafeCast<MouseDownEvent>()->target = this;
}
if (evt->type == event::MouseUp && pressed_)
if (evt.type == event::MouseUp && pressed_)
{
pressed_ = false;
auto mouse_up_evt = evt->SafeCast<MouseUpEvent>();
auto mouse_up_evt = evt.SafeCast<MouseUpEvent>();
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);
}
}

View File

@ -365,7 +365,7 @@ namespace kiwano
void ShowBorder(bool show);
// 事件分发
void Dispatch(Event* evt) override;
void Dispatch(Event& evt) override;
// 设置默认锚点
static void SetDefaultAnchor(

View File

@ -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()

View File

@ -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<MouseDownEvent>();
auto real_evt = evt.SafeCast<MouseDownEvent>();
OnMouseButtonDown(real_evt->button, real_evt->pos);
}
else if (evt->type == event::MouseUp)
else if (evt.type == event::MouseUp)
{
auto real_evt = evt->SafeCast<MouseUpEvent>();
auto real_evt = evt.SafeCast<MouseUpEvent>();
OnMouseButtonUp(real_evt->button, real_evt->pos);
}
else if (evt->type == event::MouseMove)
else if (evt.type == event::MouseMove)
{
auto real_evt = evt->SafeCast<MouseMoveEvent>();
auto real_evt = evt.SafeCast<MouseMoveEvent>();
OnMouseMoved(real_evt->pos);
}
else if (evt->type == event::MouseWheel)
else if (evt.type == event::MouseWheel)
{
auto real_evt = evt->SafeCast<MouseWheelEvent>();
auto real_evt = evt.SafeCast<MouseWheelEvent>();
OnMouseWheel(real_evt->wheel);
}
else if (evt->type == event::KeyDown)
else if (evt.type == event::KeyDown)
{
auto real_evt = evt->SafeCast<KeyDownEvent>();
auto real_evt = evt.SafeCast<KeyDownEvent>();
OnKeyDown(real_evt->code);
}
else if (evt->type == event::KeyUp)
else if (evt.type == event::KeyUp)
{
auto real_evt = evt->SafeCast<KeyUpEvent>();
auto real_evt = evt.SafeCast<KeyUpEvent>();
OnKeyUp(real_evt->code);
}
else if (evt->type == event::KeyChar)
else if (evt.type == event::KeyChar)
{
auto real_evt = evt->SafeCast<KeyCharEvent>();
auto real_evt = evt.SafeCast<KeyCharEvent>();
OnChar(real_evt->value);
}
}

View File

@ -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_;

View File

@ -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) {}

View File

@ -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)
{
}

View File

@ -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();
};

View File

@ -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);
}

View File

@ -81,7 +81,7 @@ namespace kiwano
const EventType& type
);
virtual void Dispatch(Event* evt);
virtual void Dispatch(Event& evt);
protected:
Listeners listeners_;

View File

@ -39,7 +39,7 @@ namespace kiwano
friend IntrusiveList<EventListenerPtr>;
public:
using Callback = Function<void(Event*)>;
using Callback = Function<void(Event&)>;
EventListener();

View File

@ -76,7 +76,6 @@
//
#include <kiwano/core/time.h>
#include <kiwano/core/Director.h>
#include <kiwano/core/Logger.h>
#include <kiwano/core/SmartPtr.hpp>
#include <kiwano/core/ObjectBase.h>
@ -130,6 +129,7 @@
#include <kiwano/platform/FileSystem.h>
#include <kiwano/platform/Input.h>
#include <kiwano/platform/Window.h>
#include <kiwano/platform/Director.h>
#include <kiwano/platform/Application.h>

View File

@ -24,7 +24,7 @@
#include <kiwano/platform/modules.h>
#include <kiwano/core/win32/helper.h>
#include <kiwano/platform/Input.h>
#include <kiwano/core/Director.h>
#include <kiwano/platform/Director.h>
#include <kiwano/renderer/TextureCache.h>
#include <kiwano/utils/ResourceCache.h>
@ -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<int>(wparam);
evt.count = static_cast<int>(lparam & 0xFF);
app->DispatchEvent(&evt);
// evt.count = static_cast<int>(lparam & 0xFF);
app->DispatchEvent(evt);
}
else
{
KeyUpEvent evt;
evt.code = static_cast<int>(wparam);
evt.count = static_cast<int>(lparam & 0xFF);
app->DispatchEvent(&evt);
// evt.count = static_cast<int>(lparam & 0xFF);
app->DispatchEvent(evt);
}
}
break;
@ -328,8 +328,8 @@ namespace kiwano
{
KeyCharEvent evt;
evt.value = static_cast<char>(wparam);
evt.count = static_cast<int>(lparam & 0xFF);
app->DispatchEvent(&evt);
// evt.count = static_cast<int>(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<float>(GET_X_LPARAM(lparam)), static_cast<float>(GET_Y_LPARAM(lparam)));
evt->left_btn_down = !!(wparam & MK_LBUTTON);
evt->left_btn_down = !!(wparam & MK_RBUTTON);
evt.pos = Point(static_cast<float>(GET_X_LPARAM(lparam)), static_cast<float>(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<const wchar_t*>(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;
}
}

View File

@ -91,7 +91,7 @@ namespace kiwano
);
// 分发事件
void DispatchEvent(Event* evt);
void DispatchEvent(Event& evt);
// 在 Kiwano 主线程中执行函数
// 当在其他线程调用 Kiwano 函数时使用

View File

@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/core/Director.h>
#include <kiwano/platform/Director.h>
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/2d/Transition.h>
@ -180,7 +180,7 @@ namespace kiwano
}
}
void Director::HandleEvent(Event* evt)
void Director::HandleEvent(Event& evt)
{
if (debug_actor_)
debug_actor_->Dispatch(evt);

View File

@ -72,7 +72,7 @@ namespace kiwano
void OnRender(RenderTarget* rt) override;
void HandleEvent(Event* evt) override;
void HandleEvent(Event& evt) override;
protected:
Director();

View File

@ -103,14 +103,14 @@ namespace kiwano
}
}
void Button::UpdateStatus(Event* evt)
void Button::UpdateStatus(Event& evt)
{
auto mouse_evt = evt->SafeCast<MouseEvent>();
auto mouse_evt = evt.SafeCast<MouseEvent>();
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);

View File

@ -84,7 +84,7 @@ namespace kiwano
Status status
);
void UpdateStatus(Event* evt);
void UpdateStatus(Event& evt);
private:
bool enabled_;