minor fixes
This commit is contained in:
		
							parent
							
								
									1de59e3a15
								
							
						
					
					
						commit
						e1ec4f76b7
					
				|  | @ -52,6 +52,8 @@ void Application::Run(RunnerPtr runner, bool debug) | ||||||
| { | { | ||||||
|     KGE_ASSERT(runner); |     KGE_ASSERT(runner); | ||||||
|     runner_ = runner; |     runner_ = runner; | ||||||
|  |     timer_   = Timer::Create(); | ||||||
|  |     running_ = true; | ||||||
| 
 | 
 | ||||||
|     // Setup all modules
 |     // Setup all modules
 | ||||||
|     for (auto c : modules_) |     for (auto c : modules_) | ||||||
|  | @ -68,8 +70,6 @@ void Application::Run(RunnerPtr runner, bool debug) | ||||||
|     // Everything is ready
 |     // Everything is ready
 | ||||||
|     runner->OnReady(); |     runner->OnReady(); | ||||||
| 
 | 
 | ||||||
|     running_ = true; |  | ||||||
|     timer_   = Timer::Create(); |  | ||||||
|     while (running_) |     while (running_) | ||||||
|     { |     { | ||||||
|         timer_->Tick(); |         timer_->Tick(); | ||||||
|  |  | ||||||
|  | @ -29,8 +29,10 @@ Window::Window() | ||||||
|     , is_fullscreen_(false) |     , is_fullscreen_(false) | ||||||
|     , width_(0) |     , width_(0) | ||||||
|     , height_(0) |     , height_(0) | ||||||
|     , min_width_(100) |     , min_width_(0) | ||||||
|     , min_height_(50) |     , min_height_(0) | ||||||
|  |     , max_width_(0) | ||||||
|  |     , max_height_(0) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -136,6 +136,14 @@ public: | ||||||
|      */ |      */ | ||||||
|     virtual void SetMinimumSize(uint32_t width, uint32_t height) = 0; |     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 |      * \~chinese | ||||||
|      * @brief 譜崔報炎峺寞窃侏 |      * @brief 譜崔報炎峺寞窃侏 | ||||||
|  | @ -193,6 +201,8 @@ protected: | ||||||
|     uint32_t             height_; |     uint32_t             height_; | ||||||
|     uint32_t             min_width_; |     uint32_t             min_width_; | ||||||
|     uint32_t             min_height_; |     uint32_t             min_height_; | ||||||
|  |     uint32_t             max_width_; | ||||||
|  |     uint32_t             max_height_; | ||||||
|     WindowHandle         handle_; |     WindowHandle         handle_; | ||||||
|     String               title_; |     String               title_; | ||||||
|     std::queue<EventPtr> event_queue_; |     std::queue<EventPtr> event_queue_; | ||||||
|  |  | ||||||
|  | @ -58,6 +58,8 @@ public: | ||||||
| 
 | 
 | ||||||
|     void SetMinimumSize(uint32_t width, uint32_t height) override; |     void SetMinimumSize(uint32_t width, uint32_t height) override; | ||||||
| 
 | 
 | ||||||
|  |     void SetMaximumSize(uint32_t width, uint32_t height) override; | ||||||
|  | 
 | ||||||
|     void SetCursor(CursorType cursor) override; |     void SetCursor(CursorType cursor) override; | ||||||
| 
 | 
 | ||||||
|     void PumpEvents() override; |     void PumpEvents() override; | ||||||
|  | @ -257,8 +259,11 @@ void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, | ||||||
|         height = win_height; |         height = win_height; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     handle_ = ::CreateWindowExA(fullscreen ? WS_EX_TOPMOST : 0, "KiwanoAppWnd", title.c_str(), GetStyle(), |     width_     = width; | ||||||
|                                 left, top, width, height, nullptr, nullptr, hinst, nullptr); |     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) |     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"); |         KGE_THROW_SYSTEM_ERROR(HRESULT_FROM_WIN32(GetLastError()), "Create window failed"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     width_     = width; |  | ||||||
|     height_    = height; |  | ||||||
|     resizable_ = resizable; |  | ||||||
| 
 |  | ||||||
|     // disable imm
 |     // disable imm
 | ||||||
|     ::ImmAssociateContext(handle_, nullptr); |     ::ImmAssociateContext(handle_, nullptr); | ||||||
| 
 | 
 | ||||||
|  | @ -333,6 +334,12 @@ void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height) | ||||||
|     min_height_ = height; |     min_height_ = height; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void WindowWin32Impl::SetMaximumSize(uint32_t width, uint32_t height) | ||||||
|  | { | ||||||
|  |     max_width_  = width; | ||||||
|  |     max_height_ = height; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void WindowWin32Impl::SetCursor(CursorType cursor) | void WindowWin32Impl::SetCursor(CursorType cursor) | ||||||
| { | { | ||||||
|     mouse_cursor_ = cursor; |     mouse_cursor_ = cursor; | ||||||
|  | @ -498,13 +505,15 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|         } |         } | ||||||
|         else if (SIZE_MAXIMIZED == wparam) |         else if (SIZE_MAXIMIZED == wparam) | ||||||
|         { |         { | ||||||
|  |             KGE_SYS_LOG("Window maximized"); | ||||||
|  | 
 | ||||||
|             if (is_minimized_) |             if (is_minimized_) | ||||||
|             { |             { | ||||||
|                 is_minimized_ = false; |                 is_minimized_ = false; | ||||||
|                 if (Application::GetInstance().IsRunning()) |                 if (Application::GetInstance().IsRunning()) | ||||||
|                 { |                 { | ||||||
|                     TimerPtr timer = Application::GetInstance().GetTimer(); |                     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()) |                 if (Application::GetInstance().IsRunning()) | ||||||
|                 { |                 { | ||||||
|                     TimerPtr timer = Application::GetInstance().GetTimer(); |                     TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|                     timer->Pause(); |                     timer->Resume(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             else if (is_resizing_) |             else if (is_resizing_) | ||||||
|  | @ -528,8 +537,6 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 KGE_SYS_LOG("Window resized"); |  | ||||||
| 
 |  | ||||||
|                 this->width_  = ((uint32_t)(short)LOWORD(lparam)); |                 this->width_  = ((uint32_t)(short)LOWORD(lparam)); | ||||||
|                 this->height_ = ((uint32_t)(short)HIWORD(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->width                = this->GetWidth(); | ||||||
|                 evt->height               = this->GetHeight(); |                 evt->height               = this->GetHeight(); | ||||||
|                 this->PushEvent(evt); |                 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; |         return 0; | ||||||
|     } |     } | ||||||
|     break; |  | ||||||
| 
 | 
 | ||||||
|     case WM_EXITSIZEMOVE: |     case WM_EXITSIZEMOVE: | ||||||
|     { |     { | ||||||
|  | @ -562,17 +570,40 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|             TimerPtr timer = Application::GetInstance().GetTimer(); |             TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|             timer->Resume(); |             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; |         return 0; | ||||||
|     } |     } | ||||||
|     break; |  | ||||||
| 
 | 
 | ||||||
|     case WM_GETMINMAXINFO: |     case WM_GETMINMAXINFO: | ||||||
|     { |     { | ||||||
|         // prevent the window from becoming too small
 |         if (min_width_ || min_height_) | ||||||
|         ((MINMAXINFO*)lparam)->ptMinTrackSize.x = LONG(min_width_); |         { | ||||||
|         ((MINMAXINFO*)lparam)->ptMinTrackSize.y = LONG(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: |     case WM_MOVE: | ||||||
|     { |     { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue