add Window::SetMinimumSize()
This commit is contained in:
		
							parent
							
								
									01ce68accb
								
							
						
					
					
						commit
						1de59e3a15
					
				|  | @ -29,6 +29,8 @@ Window::Window() | ||||||
|     , is_fullscreen_(false) |     , is_fullscreen_(false) | ||||||
|     , width_(0) |     , width_(0) | ||||||
|     , height_(0) |     , height_(0) | ||||||
|  |     , min_width_(100) | ||||||
|  |     , min_height_(50) | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -128,6 +128,14 @@ public: | ||||||
|      */ |      */ | ||||||
|     virtual void Resize(uint32_t width, uint32_t height) = 0; |     virtual void Resize(uint32_t width, uint32_t height) = 0; | ||||||
| 
 | 
 | ||||||
|  |     /**
 | ||||||
|  |      * \~chinese | ||||||
|  |      * @brief 设置窗口最小大小 | ||||||
|  |      * @param width 最小窗口宽度 | ||||||
|  |      * @param height 最小窗口高度 | ||||||
|  |      */ | ||||||
|  |     virtual void SetMinimumSize(uint32_t width, uint32_t height) = 0; | ||||||
|  | 
 | ||||||
|     /**
 |     /**
 | ||||||
|      * \~chinese |      * \~chinese | ||||||
|      * @brief 譜崔報炎峺寞窃侏 |      * @brief 譜崔報炎峺寞窃侏 | ||||||
|  | @ -183,6 +191,8 @@ protected: | ||||||
|     bool                 is_fullscreen_; |     bool                 is_fullscreen_; | ||||||
|     uint32_t             width_; |     uint32_t             width_; | ||||||
|     uint32_t             height_; |     uint32_t             height_; | ||||||
|  |     uint32_t             min_width_; | ||||||
|  |     uint32_t             min_height_; | ||||||
|     WindowHandle         handle_; |     WindowHandle         handle_; | ||||||
|     String               title_; |     String               title_; | ||||||
|     std::queue<EventPtr> event_queue_; |     std::queue<EventPtr> event_queue_; | ||||||
|  |  | ||||||
|  | @ -56,6 +56,8 @@ public: | ||||||
| 
 | 
 | ||||||
|     void Resize(uint32_t width, uint32_t height) override; |     void Resize(uint32_t width, uint32_t height) override; | ||||||
| 
 | 
 | ||||||
|  |     void SetMinimumSize(uint32_t width, uint32_t height) override; | ||||||
|  | 
 | ||||||
|     void SetCursor(CursorType cursor) override; |     void SetCursor(CursorType cursor) override; | ||||||
| 
 | 
 | ||||||
|     void PumpEvents() override; |     void PumpEvents() override; | ||||||
|  | @ -70,6 +72,8 @@ public: | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     bool       resizable_; |     bool       resizable_; | ||||||
|  |     bool       is_resizing_; | ||||||
|  |     bool       is_minimized_; | ||||||
|     CursorType mouse_cursor_; |     CursorType mouse_cursor_; | ||||||
|     String     device_name_; |     String     device_name_; | ||||||
| 
 | 
 | ||||||
|  | @ -133,6 +137,8 @@ void AdjustWindow(uint32_t width, uint32_t height, DWORD style, uint32_t* win_wi | ||||||
| 
 | 
 | ||||||
| WindowWin32Impl::WindowWin32Impl() | WindowWin32Impl::WindowWin32Impl() | ||||||
|     : resizable_(false) |     : resizable_(false) | ||||||
|  |     , is_resizing_(false) | ||||||
|  |     , is_minimized_(false) | ||||||
|     , mouse_cursor_(CursorType::Arrow) |     , mouse_cursor_(CursorType::Arrow) | ||||||
|     , key_map_{} |     , key_map_{} | ||||||
| { | { | ||||||
|  | @ -321,6 +327,12 @@ void WindowWin32Impl::Resize(uint32_t width, uint32_t height) | ||||||
|     ::SetWindowPos(handle_, 0, left, top, width, height, SWP_NOZORDER | SWP_NOACTIVATE); |     ::SetWindowPos(handle_, 0, left, top, width, height, SWP_NOZORDER | SWP_NOACTIVATE); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height) | ||||||
|  | { | ||||||
|  |     min_width_  = width; | ||||||
|  |     min_height_ = height; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void WindowWin32Impl::SetCursor(CursorType cursor) | void WindowWin32Impl::SetCursor(CursorType cursor) | ||||||
| { | { | ||||||
|     mouse_cursor_ = cursor; |     mouse_cursor_ = cursor; | ||||||
|  | @ -475,6 +487,44 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|         if (SIZE_MAXHIDE == wparam || SIZE_MINIMIZED == wparam) |         if (SIZE_MAXHIDE == wparam || SIZE_MINIMIZED == wparam) | ||||||
|         { |         { | ||||||
|             KGE_SYS_LOG("Window minimized"); |             KGE_SYS_LOG("Window minimized"); | ||||||
|  | 
 | ||||||
|  |             is_minimized_ = true; | ||||||
|  |             // Pause game when window is minimized
 | ||||||
|  |             if (Application::GetInstance().IsRunning()) | ||||||
|  |             { | ||||||
|  |                 TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|  |                 timer->Pause(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         else if (SIZE_MAXIMIZED == wparam) | ||||||
|  |         { | ||||||
|  |             if (is_minimized_) | ||||||
|  |             { | ||||||
|  |                 is_minimized_ = false; | ||||||
|  |                 if (Application::GetInstance().IsRunning()) | ||||||
|  |                 { | ||||||
|  |                     TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|  |                     timer->Pause(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         else if (wparam == SIZE_RESTORED) | ||||||
|  |         { | ||||||
|  |             if (is_minimized_) | ||||||
|  |             { | ||||||
|  |                 KGE_SYS_LOG("Window restored"); | ||||||
|  | 
 | ||||||
|  |                 // the window was restored and was previously minimized
 | ||||||
|  |                 is_minimized_ = false; | ||||||
|  |                 if (Application::GetInstance().IsRunning()) | ||||||
|  |                 { | ||||||
|  |                     TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|  |                     timer->Pause(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             else if (is_resizing_) | ||||||
|  |             { | ||||||
|  |                 // DO NOTHING until the dragging / resizing has stopped.
 | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -489,8 +539,41 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|                 this->PushEvent(evt); |                 this->PushEvent(evt); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|     break; |     break; | ||||||
| 
 | 
 | ||||||
|  |     case WM_ENTERSIZEMOVE: | ||||||
|  |     { | ||||||
|  |         is_resizing_ = true; | ||||||
|  |         if (Application::GetInstance().IsRunning()) | ||||||
|  |         { | ||||||
|  |             TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|  |             timer->Pause(); | ||||||
|  |         } | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  |     break; | ||||||
|  | 
 | ||||||
|  |     case WM_EXITSIZEMOVE: | ||||||
|  |     { | ||||||
|  |         is_resizing_ = false; | ||||||
|  |         if (Application::GetInstance().IsRunning()) | ||||||
|  |         { | ||||||
|  |             TimerPtr timer = Application::GetInstance().GetTimer(); | ||||||
|  |             timer->Resume(); | ||||||
|  |         } | ||||||
|  |         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_); | ||||||
|  |     } | ||||||
|  |     return 0; | ||||||
|  | 
 | ||||||
|     case WM_MOVE: |     case WM_MOVE: | ||||||
|     { |     { | ||||||
|         WindowMovedEventPtr evt = new WindowMovedEvent; |         WindowMovedEventPtr evt = new WindowMovedEvent; | ||||||
|  | @ -500,6 +583,13 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|     } |     } | ||||||
|     break; |     break; | ||||||
| 
 | 
 | ||||||
|  |     case WM_MENUCHAR: | ||||||
|  |     { | ||||||
|  |         // Disables the crazy beeping sound when pressing a mnemonic key.
 | ||||||
|  |         // Simply tell Windows that we want the menu closed.
 | ||||||
|  |         return MAKELRESULT(0, MNC_CLOSE); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     case WM_ACTIVATE: |     case WM_ACTIVATE: | ||||||
|     { |     { | ||||||
|         bool active = (LOWORD(wparam) != WA_INACTIVE); |         bool active = (LOWORD(wparam) != WA_INACTIVE); | ||||||
|  | @ -507,16 +597,6 @@ LRESULT WindowWin32Impl::MessageProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA | ||||||
|         WindowFocusChangedEventPtr evt = new WindowFocusChangedEvent; |         WindowFocusChangedEventPtr evt = new WindowFocusChangedEvent; | ||||||
|         evt->focus                     = active; |         evt->focus                     = active; | ||||||
|         this->PushEvent(evt); |         this->PushEvent(evt); | ||||||
| 
 |  | ||||||
|         // Pause game when window is inactive
 |  | ||||||
|         TimerPtr timer = Application::GetInstance().GetTimer(); |  | ||||||
|         if (timer) |  | ||||||
|         { |  | ||||||
|             if (active) |  | ||||||
|                 timer->Resume(); |  | ||||||
|             else |  | ||||||
|                 timer->Pause(); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|     break; |     break; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue