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/Window.cpp b/src/kiwano/platform/Window.cpp index 1fdd40d7..7bff692b 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 a982bfaa..63dbb122 100644 --- a/src/kiwano/platform/Window.h +++ b/src/kiwano/platform/Window.h @@ -136,6 +136,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 设置鼠标指针类型 @@ -193,6 +201,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 ffe85838..5fc92edf 100644 --- a/src/kiwano/platform/win32/WindowImpl.cpp +++ b/src/kiwano/platform/win32/WindowImpl.cpp @@ -58,6 +58,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 PumpEvents() override; @@ -257,8 +259,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) { @@ -266,10 +271,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); @@ -333,6 +334,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; @@ -498,13 +505,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(); } } } @@ -519,7 +528,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_) @@ -528,8 +537,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)); @@ -537,6 +544,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_); } } } @@ -552,7 +561,6 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA } return 0; } - break; case WM_EXITSIZEMOVE: { @@ -562,17 +570,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: {