diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index 7fe3b647..2161d336 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -5,7 +5,7 @@ - + @@ -17,7 +17,6 @@ - @@ -26,16 +25,12 @@ - - - - @@ -56,8 +51,6 @@ - - @@ -102,15 +95,22 @@ + + + + + + + - + @@ -127,7 +127,6 @@ - @@ -143,11 +142,7 @@ - - - - @@ -177,8 +172,13 @@ + + + + + diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index bec9acbc..4bbf8004 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -90,9 +90,6 @@ 2d\action - - 2d\action - 2d\action @@ -285,12 +282,6 @@ core - - core - - - core - core @@ -321,20 +312,29 @@ render - - core + + utils - - core + + utils - - core + + utils - - core + + utils - - core + + utils + + + utils + + + utils + + + 2d\action render\DirectX @@ -380,9 +380,6 @@ 2d\action - - 2d\action - 2d\action @@ -545,20 +542,23 @@ render - - core + + utils - - core + + utils - - core + + utils - - core + + utils - - core + + utils + + + 2d\action diff --git a/src/kiwano-network/HttpRequest.h b/src/kiwano-network/HttpRequest.h index fe8bdd6c..626c3b56 100644 --- a/src/kiwano-network/HttpRequest.h +++ b/src/kiwano-network/HttpRequest.h @@ -21,7 +21,7 @@ #pragma once #include #include -#include +#include namespace kiwano { diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index 6e9a0340..85cc83c3 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -77,9 +77,9 @@ Actor::~Actor() void Actor::Update(Duration dt) { - UpdateActions(this, dt); + ActionScheduler::Update(this, dt); + TaskScheduler::Update(dt); UpdateComponents(dt); - UpdateTasks(dt); if (!update_pausing_) { diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h index 0c552b20..8ebc92d2 100644 --- a/src/kiwano/2d/Actor.h +++ b/src/kiwano/2d/Actor.h @@ -19,12 +19,12 @@ // THE SOFTWARE. #pragma once +#include #include #include -#include #include -#include -#include +#include +#include #include namespace kiwano @@ -62,8 +62,8 @@ typedef IntrusiveList ActorList; */ class KGE_API Actor : public ObjectBase - , public TaskManager - , public ActionManager + , public TaskScheduler + , public ActionScheduler , public EventDispatcher , protected IntrusiveListValue { diff --git a/src/kiwano/2d/action/Action.h b/src/kiwano/2d/action/Action.h index f8d79e4a..8bc67bbb 100644 --- a/src/kiwano/2d/action/Action.h +++ b/src/kiwano/2d/action/Action.h @@ -30,7 +30,7 @@ namespace kiwano { class Actor; -class ActionManager; +class ActionScheduler; KGE_DECLARE_SMART_PTR(Action); @@ -55,7 +55,7 @@ class KGE_API Action , public Cloneable , protected IntrusiveListValue { - friend class ActionManager; + friend class ActionScheduler; friend class ActionGroup; friend IntrusiveList; diff --git a/src/kiwano/2d/action/ActionManager.cpp b/src/kiwano/2d/action/ActionScheduler.cpp similarity index 85% rename from src/kiwano/2d/action/ActionManager.cpp rename to src/kiwano/2d/action/ActionScheduler.cpp index 8c79bfe2..4d8b8765 100644 --- a/src/kiwano/2d/action/ActionManager.cpp +++ b/src/kiwano/2d/action/ActionScheduler.cpp @@ -19,12 +19,13 @@ // THE SOFTWARE. #include -#include +#include #include namespace kiwano { -void ActionManager::UpdateActions(Actor* target, Duration dt) + +void ActionScheduler::Update(Actor* target, Duration dt) { if (actions_.IsEmpty() || !target) return; @@ -42,7 +43,7 @@ void ActionManager::UpdateActions(Actor* target, Duration dt) } } -Action* ActionManager::AddAction(ActionPtr action) +Action* ActionScheduler::AddAction(ActionPtr action) { KGE_ASSERT(action && "AddAction failed, NULL pointer exception"); @@ -53,7 +54,7 @@ Action* ActionManager::AddAction(ActionPtr action) return action.Get(); } -void ActionManager::ResumeAllActions() +void ActionScheduler::ResumeAllActions() { if (actions_.IsEmpty()) return; @@ -64,7 +65,7 @@ void ActionManager::ResumeAllActions() } } -void ActionManager::PauseAllActions() +void ActionScheduler::PauseAllActions() { if (actions_.IsEmpty()) return; @@ -75,7 +76,7 @@ void ActionManager::PauseAllActions() } } -void ActionManager::StopAllActions() +void ActionScheduler::StopAllActions() { if (actions_.IsEmpty()) return; @@ -86,7 +87,7 @@ void ActionManager::StopAllActions() } } -ActionPtr ActionManager::GetAction(const String& name) +ActionPtr ActionScheduler::GetAction(const String& name) { if (actions_.IsEmpty()) return nullptr; @@ -97,7 +98,7 @@ ActionPtr ActionManager::GetAction(const String& name) return nullptr; } -const ActionList& ActionManager::GetAllActions() const +const ActionList& ActionScheduler::GetAllActions() const { return actions_; } diff --git a/src/kiwano/2d/action/ActionManager.h b/src/kiwano/2d/action/ActionScheduler.h similarity index 94% rename from src/kiwano/2d/action/ActionManager.h rename to src/kiwano/2d/action/ActionScheduler.h index 841a4611..34d37421 100644 --- a/src/kiwano/2d/action/ActionManager.h +++ b/src/kiwano/2d/action/ActionScheduler.h @@ -30,9 +30,9 @@ namespace kiwano /** * \~chinese - * @brief 动画管理器 + * @brief 动画调度器 */ -class KGE_API ActionManager +class KGE_API ActionScheduler { public: /// \~chinese @@ -60,10 +60,9 @@ public: /// @brief 获取所有动画 const ActionList& GetAllActions() const; -protected: /// \~chinese /// @brief 更新动画 - void UpdateActions(Actor* target, Duration dt); + void Update(Actor* target, Duration dt); private: ActionList actions_; diff --git a/src/kiwano/core/ObjectBase.cpp b/src/kiwano/core/ObjectBase.cpp index 9423407c..7fa059f2 100644 --- a/src/kiwano/core/ObjectBase.cpp +++ b/src/kiwano/core/ObjectBase.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include namespace kiwano diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h index 92aa77fd..86e32e0f 100644 --- a/src/kiwano/kiwano.h +++ b/src/kiwano/kiwano.h @@ -52,11 +52,6 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #include @@ -98,7 +93,7 @@ #include #include #include -#include +#include #include #include #include @@ -120,3 +115,8 @@ #include #include #include +#include +#include +#include +#include +#include diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 5222fe11..b3f0c3c2 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -52,6 +52,8 @@ void Application::Run(RunnerPtr runner, bool debug) { KGE_ASSERT(runner); runner_ = runner; + timer_ = Timer::Create(); + running_ = true; // Setup all modules for (auto c : modules_) @@ -68,8 +70,6 @@ void Application::Run(RunnerPtr runner, bool debug) // Everything is ready runner->OnReady(); - running_ = true; - timer_ = Timer::Create(); while (running_) { timer_->Tick(); diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h index 6fe77c3c..5c2d4e87 100644 --- a/src/kiwano/platform/Application.h +++ b/src/kiwano/platform/Application.h @@ -23,11 +23,11 @@ #include #include #include -#include #include #include #include #include +#include namespace kiwano { diff --git a/src/kiwano/platform/Window.cpp b/src/kiwano/platform/Window.cpp index 0dcdb4fc..e92b7212 100644 --- a/src/kiwano/platform/Window.cpp +++ b/src/kiwano/platform/Window.cpp @@ -29,8 +29,10 @@ Window::Window() , is_fullscreen_(false) , width_(0) , height_(0) - , min_width_(100) - , min_height_(50) + , min_width_(0) + , min_height_(0) + , max_width_(0) + , max_height_(0) { } diff --git a/src/kiwano/platform/Window.h b/src/kiwano/platform/Window.h index 749a5304..284cb1db 100644 --- a/src/kiwano/platform/Window.h +++ b/src/kiwano/platform/Window.h @@ -147,6 +147,14 @@ public: */ virtual void SetMinimumSize(uint32_t width, uint32_t height) = 0; + /** + * \~chinese + * @brief 设置窗口最大大小 + * @param width 最大窗口宽度 + * @param height 最大窗口高度 + */ + virtual void SetMaximumSize(uint32_t width, uint32_t height) = 0; + /** * \~chinese * @brief 设置鼠标指针类型 @@ -213,6 +221,8 @@ protected: uint32_t height_; uint32_t min_width_; uint32_t min_height_; + uint32_t max_width_; + uint32_t max_height_; WindowHandle handle_; String title_; std::queue event_queue_; diff --git a/src/kiwano/platform/win32/WindowImpl.cpp b/src/kiwano/platform/win32/WindowImpl.cpp index 6cd573ea..4bf1f36c 100644 --- a/src/kiwano/platform/win32/WindowImpl.cpp +++ b/src/kiwano/platform/win32/WindowImpl.cpp @@ -59,6 +59,8 @@ public: void SetMinimumSize(uint32_t width, uint32_t height) override; + void SetMaximumSize(uint32_t width, uint32_t height) override; + void SetCursor(CursorType cursor) override; void SetResolution(uint32_t width, uint32_t height, bool fullscreen) override; @@ -263,8 +265,11 @@ void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, height = win_height; } - handle_ = ::CreateWindowExA(fullscreen ? WS_EX_TOPMOST : 0, "KiwanoAppWnd", title.c_str(), GetStyle(), - left, top, width, height, nullptr, nullptr, hinst, nullptr); + width_ = width; + height_ = height; + resizable_ = resizable; + handle_ = ::CreateWindowExA(fullscreen ? WS_EX_TOPMOST : 0, "KiwanoAppWnd", title.c_str(), GetStyle(), left, top, + width, height, nullptr, nullptr, hinst, nullptr); if (handle_ == nullptr) { @@ -272,10 +277,6 @@ void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, KGE_THROW_SYSTEM_ERROR(HRESULT_FROM_WIN32(GetLastError()), "Create window failed"); } - width_ = width; - height_ = height; - resizable_ = resizable; - // disable imm ::ImmAssociateContext(handle_, nullptr); @@ -339,6 +340,12 @@ void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height) min_height_ = height; } +void WindowWin32Impl::SetMaximumSize(uint32_t width, uint32_t height) +{ + max_width_ = width; + max_height_ = height; +} + void WindowWin32Impl::SetCursor(CursorType cursor) { mouse_cursor_ = cursor; @@ -576,13 +583,15 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA } else if (SIZE_MAXIMIZED == wparam) { + KGE_SYS_LOG("Window maximized"); + if (is_minimized_) { is_minimized_ = false; if (Application::GetInstance().IsRunning()) { TimerPtr timer = Application::GetInstance().GetTimer(); - timer->Pause(); + timer->Resume(); } } } @@ -597,7 +606,7 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA if (Application::GetInstance().IsRunning()) { TimerPtr timer = Application::GetInstance().GetTimer(); - timer->Pause(); + timer->Resume(); } } else if (is_resizing_) @@ -606,8 +615,6 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA } else { - KGE_SYS_LOG("Window resized"); - this->width_ = ((uint32_t)(short)LOWORD(lparam)); this->height_ = ((uint32_t)(short)HIWORD(lparam)); @@ -615,6 +622,8 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA evt->width = this->GetWidth(); evt->height = this->GetHeight(); this->PushEvent(evt); + + KGE_SYS_LOG("Window resized to (%d, %d)", this->width_, this->height_); } } } @@ -630,7 +639,6 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA } return 0; } - break; case WM_EXITSIZEMOVE: { @@ -640,17 +648,40 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA TimerPtr timer = Application::GetInstance().GetTimer(); timer->Resume(); } + + // Send window resized event when client size changed + RECT client_rect = { 0 }; + ::GetClientRect(hwnd, &client_rect); + + uint32_t client_width = uint32_t(client_rect.right - client_rect.left); + uint32_t client_height = uint32_t(client_rect.bottom - client_rect.top); + if (client_width != this->GetWidth() || client_height != this->GetHeight()) + { + KGE_SYS_LOG("Window resized to (%d, %d)", client_width, client_height); + + this->width_ = client_width; + this->height_ = client_height; + + WindowResizedEventPtr evt = new WindowResizedEvent; + evt->width = this->GetWidth(); + evt->height = this->GetHeight(); + this->PushEvent(evt); + } return 0; } - break; case WM_GETMINMAXINFO: { - // prevent the window from becoming too small - ((MINMAXINFO*)lparam)->ptMinTrackSize.x = LONG(min_width_); - ((MINMAXINFO*)lparam)->ptMinTrackSize.y = LONG(min_height_); + if (min_width_ || min_height_) + { + ((MINMAXINFO*)lparam)->ptMinTrackSize = POINT{ LONG(min_width_), LONG(min_height_) }; + } + if (max_width_ || max_height_) + { + ((MINMAXINFO*)lparam)->ptMaxTrackSize = POINT{ LONG(max_width_), LONG(max_height_) }; + } + return 0; } - return 0; case WM_MOVE: { diff --git a/src/kiwano/core/EventTicker.cpp b/src/kiwano/utils/EventTicker.cpp similarity index 97% rename from src/kiwano/core/EventTicker.cpp rename to src/kiwano/utils/EventTicker.cpp index b0872b41..f354f081 100644 --- a/src/kiwano/core/EventTicker.cpp +++ b/src/kiwano/utils/EventTicker.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include namespace kiwano { diff --git a/src/kiwano/core/EventTicker.h b/src/kiwano/utils/EventTicker.h similarity index 97% rename from src/kiwano/core/EventTicker.h rename to src/kiwano/utils/EventTicker.h index 1f070edb..3fffff84 100644 --- a/src/kiwano/core/EventTicker.h +++ b/src/kiwano/utils/EventTicker.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include @@ -63,6 +63,8 @@ public: /// @param times 报时次数(设 -1 为永久) static EventTickerPtr Create(Duration interval, int times = -1); + using Ticker::Tick; + bool Tick(Duration dt) override; }; diff --git a/src/kiwano/core/Json.h b/src/kiwano/utils/Json.h similarity index 100% rename from src/kiwano/core/Json.h rename to src/kiwano/utils/Json.h diff --git a/src/kiwano/utils/ResourceCache.h b/src/kiwano/utils/ResourceCache.h index 6c40b938..e6aaa9e8 100644 --- a/src/kiwano/utils/ResourceCache.h +++ b/src/kiwano/utils/ResourceCache.h @@ -19,11 +19,11 @@ // THE SOFTWARE. #pragma once +#include +#include +#include #include #include -#include -#include -#include #include #include diff --git a/src/kiwano/core/Task.cpp b/src/kiwano/utils/Task.cpp similarity index 98% rename from src/kiwano/core/Task.cpp rename to src/kiwano/utils/Task.cpp index 430c6094..a1988735 100644 --- a/src/kiwano/core/Task.cpp +++ b/src/kiwano/utils/Task.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include namespace kiwano { diff --git a/src/kiwano/core/Task.h b/src/kiwano/utils/Task.h similarity index 98% rename from src/kiwano/core/Task.h rename to src/kiwano/utils/Task.h index 9297d707..30e4b652 100644 --- a/src/kiwano/core/Task.h +++ b/src/kiwano/utils/Task.h @@ -19,12 +19,12 @@ // THE SOFTWARE. #pragma once -#include +#include #include namespace kiwano { -class TaskManager; +class TaskScheduler; KGE_DECLARE_SMART_PTR(Task); @@ -39,7 +39,7 @@ class KGE_API Task : public ObjectBase , protected IntrusiveListValue { - friend class TaskManager; + friend class TaskScheduler; friend IntrusiveList; public: diff --git a/src/kiwano/core/TaskManager.cpp b/src/kiwano/utils/TaskScheduler.cpp similarity index 84% rename from src/kiwano/core/TaskManager.cpp rename to src/kiwano/utils/TaskScheduler.cpp index 740ef94a..c06d88da 100644 --- a/src/kiwano/core/TaskManager.cpp +++ b/src/kiwano/utils/TaskScheduler.cpp @@ -19,11 +19,11 @@ // THE SOFTWARE. #include -#include +#include namespace kiwano { -void TaskManager::UpdateTasks(Duration dt) +void TaskScheduler::Update(Duration dt) { if (tasks_.IsEmpty()) return; @@ -40,7 +40,7 @@ void TaskManager::UpdateTasks(Duration dt) } } -Task* TaskManager::AddTask(TaskPtr task) +Task* TaskScheduler::AddTask(TaskPtr task) { KGE_ASSERT(task && "AddTask failed, NULL pointer exception"); @@ -53,7 +53,7 @@ Task* TaskManager::AddTask(TaskPtr task) return task.Get(); } -void TaskManager::StopTasks(const String& name) +void TaskScheduler::StopTasks(const String& name) { if (tasks_.IsEmpty()) return; @@ -67,7 +67,7 @@ void TaskManager::StopTasks(const String& name) } } -void TaskManager::StartTasks(const String& name) +void TaskScheduler::StartTasks(const String& name) { if (tasks_.IsEmpty()) return; @@ -81,7 +81,7 @@ void TaskManager::StartTasks(const String& name) } } -void TaskManager::RemoveTasks(const String& name) +void TaskScheduler::RemoveTasks(const String& name) { if (tasks_.IsEmpty()) return; @@ -95,7 +95,7 @@ void TaskManager::RemoveTasks(const String& name) } } -void TaskManager::StopAllTasks() +void TaskScheduler::StopAllTasks() { if (tasks_.IsEmpty()) return; @@ -106,7 +106,7 @@ void TaskManager::StopAllTasks() } } -void TaskManager::StartAllTasks() +void TaskScheduler::StartAllTasks() { if (tasks_.IsEmpty()) return; @@ -117,12 +117,12 @@ void TaskManager::StartAllTasks() } } -void TaskManager::RemoveAllTasks() +void TaskScheduler::RemoveAllTasks() { tasks_.Clear(); } -const TaskList& TaskManager::GetAllTasks() const +const TaskList& TaskScheduler::GetAllTasks() const { return tasks_; } diff --git a/src/kiwano/core/TaskManager.h b/src/kiwano/utils/TaskScheduler.h similarity index 92% rename from src/kiwano/core/TaskManager.h rename to src/kiwano/utils/TaskScheduler.h index d71d975b..32ae2c33 100644 --- a/src/kiwano/core/TaskManager.h +++ b/src/kiwano/utils/TaskScheduler.h @@ -19,15 +19,15 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano { /** * \~chinese - * @brief 任务管理器 + * @brief 任务调度器 */ -class KGE_API TaskManager +class KGE_API TaskScheduler { public: /// \~chinese @@ -62,12 +62,12 @@ public: /// @brief 获取所有任务 const TaskList& GetAllTasks() const; -protected: /// \~chinese - /// @brief 更新任务 - void UpdateTasks(Duration dt); + /// @brief 更新调度器 + void Update(Duration dt); private: TaskList tasks_; }; + } // namespace kiwano diff --git a/src/kiwano/core/Ticker.cpp b/src/kiwano/utils/Ticker.cpp similarity index 98% rename from src/kiwano/core/Ticker.cpp rename to src/kiwano/utils/Ticker.cpp index b3884cd8..c072f580 100644 --- a/src/kiwano/core/Ticker.cpp +++ b/src/kiwano/utils/Ticker.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include namespace kiwano { diff --git a/src/kiwano/core/Ticker.h b/src/kiwano/utils/Ticker.h similarity index 99% rename from src/kiwano/core/Ticker.h rename to src/kiwano/utils/Ticker.h index a4663769..0fb86ab0 100644 --- a/src/kiwano/core/Ticker.h +++ b/src/kiwano/utils/Ticker.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include namespace kiwano { diff --git a/src/kiwano/core/Timer.cpp b/src/kiwano/utils/Timer.cpp similarity index 98% rename from src/kiwano/core/Timer.cpp rename to src/kiwano/utils/Timer.cpp index aec2bb48..1c9ce5e2 100644 --- a/src/kiwano/core/Timer.cpp +++ b/src/kiwano/utils/Timer.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 namespace kiwano diff --git a/src/kiwano/core/Timer.h b/src/kiwano/utils/Timer.h similarity index 100% rename from src/kiwano/core/Timer.h rename to src/kiwano/utils/Timer.h diff --git a/src/kiwano/core/Xml.h b/src/kiwano/utils/Xml.h similarity index 100% rename from src/kiwano/core/Xml.h rename to src/kiwano/utils/Xml.h