[deploy] Merge pull request #57 from KiwanoEngine/dev
Merge develop branch
This commit is contained in:
		
						commit
						0529112529
					
				|  | @ -103,8 +103,11 @@ void Runner::InitSettings() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Create frame ticker
 |     // Create frame ticker
 | ||||||
|  |     if (!settings_.frame_interval.IsZero()) | ||||||
|  |     { | ||||||
|         frame_ticker_ = Ticker::Create(settings_.frame_interval, -1); |         frame_ticker_ = Ticker::Create(settings_.frame_interval, -1); | ||||||
|     } |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| bool Runner::MainLoop(Duration dt) | bool Runner::MainLoop(Duration dt) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ struct Settings | ||||||
|     uint32_t width;           ///< 窗口宽度
 |     uint32_t width;           ///< 窗口宽度
 | ||||||
|     uint32_t height;          ///< 窗口高度
 |     uint32_t height;          ///< 窗口高度
 | ||||||
|     String   title;           ///< 窗口标题
 |     String   title;           ///< 窗口标题
 | ||||||
|     uint32_t icon;            ///< ´°¿Úͼ±ê
 |     Icon     icon;            ///< ´°¿Úͼ±ê
 | ||||||
|     bool     resizable;       ///< 窗口大小可调整
 |     bool     resizable;       ///< 窗口大小可调整
 | ||||||
|     bool     fullscreen;      ///< 窗口全屏
 |     bool     fullscreen;      ///< 窗口全屏
 | ||||||
|     Color    bg_color;        ///< 窗口背景色
 |     Color    bg_color;        ///< 窗口背景色
 | ||||||
|  | @ -59,8 +59,8 @@ struct Settings | ||||||
|         , resizable(false) |         , resizable(false) | ||||||
|         , fullscreen(false) |         , fullscreen(false) | ||||||
|         , bg_color(Color::Black) |         , bg_color(Color::Black) | ||||||
|         , frame_interval(16) |         , frame_interval(0) | ||||||
|         , vsync_enabled(false) |         , vsync_enabled(true) | ||||||
|         , debug_mode(false) |         , debug_mode(false) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -56,6 +56,31 @@ struct Resolution | ||||||
|     uint32_t refresh_rate;  ///< 刷新率
 |     uint32_t refresh_rate;  ///< 刷新率
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * \~chinese | ||||||
|  |  * @brief 图标 | ||||||
|  |  */ | ||||||
|  | struct Icon | ||||||
|  | { | ||||||
|  |     Icon() = default; | ||||||
|  | 
 | ||||||
|  |     Icon(const String& file_path) | ||||||
|  |         : file_path(file_path) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     String file_path;  ///< 文件路径
 | ||||||
|  | 
 | ||||||
|  | #if defined(KGE_PLATFORM_WINDOWS) | ||||||
|  |     uint32_t resource_id = 0;  ///< 资源ID,仅在windows上生效
 | ||||||
|  | 
 | ||||||
|  |     Icon(uint32_t resource_id) | ||||||
|  |         : resource_id(resource_id) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | #endif | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| #if defined(KGE_PLATFORM_WINDOWS) | #if defined(KGE_PLATFORM_WINDOWS) | ||||||
| typedef HWND WindowHandle; | typedef HWND WindowHandle; | ||||||
|  | @ -79,7 +104,7 @@ public: | ||||||
|      * @param resizable 窗口大小可拉伸 |      * @param resizable 窗口大小可拉伸 | ||||||
|      * @throw kiwano::SystemError 窗口创建失败时抛出 |      * @throw kiwano::SystemError 窗口创建失败时抛出 | ||||||
|      */ |      */ | ||||||
|     static WindowPtr Create(const String& title, uint32_t width, uint32_t height, uint32_t icon = 0, |     static WindowPtr Create(const String& title, uint32_t width, uint32_t height, Icon icon = Icon(), | ||||||
|                             bool resizable = false, bool fullscreen = false); |                             bool resizable = false, bool fullscreen = false); | ||||||
| 
 | 
 | ||||||
|     /**
 |     /**
 | ||||||
|  | @ -138,9 +163,9 @@ public: | ||||||
|     /**
 |     /**
 | ||||||
|      * \~chinese |      * \~chinese | ||||||
|      * @brief 设置窗口图标 |      * @brief 设置窗口图标 | ||||||
|      * @param icon_resource ͼ±ê×ÊÔ´ID |      * @param icon 图标 | ||||||
|      */ |      */ | ||||||
|     virtual void SetIcon(uint32_t icon_resource) = 0; |     virtual void SetIcon(Icon icon) = 0; | ||||||
| 
 | 
 | ||||||
|     /**
 |     /**
 | ||||||
|      * \~chinese |      * \~chinese | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ | ||||||
| #include <kiwano/utils/Logger.h> | #include <kiwano/utils/Logger.h> | ||||||
| #include <kiwano/event/Events.h> | #include <kiwano/event/Events.h> | ||||||
| #include <kiwano/platform/Application.h> | #include <kiwano/platform/Application.h> | ||||||
|  | #include <kiwano/platform/FileSystem.h> | ||||||
| #include <kiwano/render/Renderer.h> | #include <kiwano/render/Renderer.h> | ||||||
| #include <Windowsx.h>  // GET_X_LPARAM, GET_Y_LPARAM
 | #include <Windowsx.h>  // GET_X_LPARAM, GET_Y_LPARAM
 | ||||||
| #include <imm.h>       // ImmAssociateContext
 | #include <imm.h>       // ImmAssociateContext
 | ||||||
|  | @ -48,11 +49,11 @@ public: | ||||||
| 
 | 
 | ||||||
|     virtual ~WindowWin32Impl(); |     virtual ~WindowWin32Impl(); | ||||||
| 
 | 
 | ||||||
|     void Init(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable, bool fullscreen); |     void Init(const String& title, uint32_t width, uint32_t height, Icon icon, bool resizable, bool fullscreen); | ||||||
| 
 | 
 | ||||||
|     void SetTitle(const String& title) override; |     void SetTitle(const String& title) override; | ||||||
| 
 | 
 | ||||||
|     void SetIcon(uint32_t icon_resource) override; |     void SetIcon(Icon icon) override; | ||||||
| 
 | 
 | ||||||
|     void SetMinimumSize(uint32_t width, uint32_t height) override; |     void SetMinimumSize(uint32_t width, uint32_t height) override; | ||||||
| 
 | 
 | ||||||
|  | @ -87,7 +88,7 @@ private: | ||||||
|     std::array<KeyCode, 256> key_map_; |     std::array<KeyCode, 256> key_map_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| WindowPtr Window::Create(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable, | WindowPtr Window::Create(const String& title, uint32_t width, uint32_t height, Icon icon, bool resizable, | ||||||
|                          bool fullscreen) |                          bool fullscreen) | ||||||
| { | { | ||||||
|     WindowWin32ImplPtr ptr = memory::New<WindowWin32Impl>(); |     WindowWin32ImplPtr ptr = memory::New<WindowWin32Impl>(); | ||||||
|  | @ -205,7 +206,7 @@ WindowWin32Impl::~WindowWin32Impl() | ||||||
|     ::timeEndPeriod(0); |     ::timeEndPeriod(0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, uint32_t icon, bool resizable, | void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, Icon icon, bool resizable, | ||||||
|                            bool fullscreen) |                            bool fullscreen) | ||||||
| { | { | ||||||
|     HINSTANCE  hinst   = GetModuleHandle(nullptr); |     HINSTANCE  hinst   = GetModuleHandle(nullptr); | ||||||
|  | @ -222,11 +223,20 @@ void WindowWin32Impl::Init(const String& title, uint32_t width, uint32_t height, | ||||||
|     wcex.lpszMenuName  = nullptr; |     wcex.lpszMenuName  = nullptr; | ||||||
|     wcex.hCursor       = ::LoadCursor(hinst, IDC_ARROW); |     wcex.hCursor       = ::LoadCursor(hinst, IDC_ARROW); | ||||||
| 
 | 
 | ||||||
|     if (icon) |     if (icon.resource_id != 0 && IS_INTRESOURCE(icon.resource_id)) | ||||||
|     { |     { | ||||||
|         wcex.hIcon = (HICON)::LoadImage(hinst, MAKEINTRESOURCE(icon), IMAGE_ICON, 0, 0, |         wcex.hIcon = (HICON)::LoadImage(hinst, MAKEINTRESOURCE(icon.resource_id), IMAGE_ICON, 0, 0, | ||||||
|                                         LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); |                                         LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); | ||||||
|     } |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         String full_path = FileSystem::GetInstance().GetFullPathForFile(icon.file_path); | ||||||
|  |         if (!full_path.empty()) | ||||||
|  |         { | ||||||
|  |             wcex.hIcon = (HICON)::LoadImageA(NULL, full_path.c_str(), IMAGE_ICON, 0, 0, | ||||||
|  |                                              LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     ::RegisterClassExA(&wcex); |     ::RegisterClassExA(&wcex); | ||||||
| 
 | 
 | ||||||
|  | @ -307,16 +317,30 @@ void WindowWin32Impl::SetTitle(const String& title) | ||||||
|     ::SetWindowTextA(handle_, title.c_str()); |     ::SetWindowTextA(handle_, title.c_str()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void WindowWin32Impl::SetIcon(uint32_t icon_resource) | void WindowWin32Impl::SetIcon(Icon icon) | ||||||
| { | { | ||||||
|     KGE_ASSERT(handle_); |     KGE_ASSERT(handle_); | ||||||
| 
 | 
 | ||||||
|  |     HICON hicon = NULL; | ||||||
|  |     if (icon.resource_id != 0 && IS_INTRESOURCE(icon.resource_id)) | ||||||
|  |     { | ||||||
|         HINSTANCE hinstance = ::GetModuleHandle(nullptr); |         HINSTANCE hinstance = ::GetModuleHandle(nullptr); | ||||||
|     HICON     icon      = (HICON)::LoadImage(hinstance, MAKEINTRESOURCE(icon_resource), IMAGE_ICON, 0, 0, |  | ||||||
|                                     LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); |  | ||||||
| 
 | 
 | ||||||
|     ::SendMessage(handle_, WM_SETICON, ICON_BIG, (LPARAM)icon); |         hicon = (HICON)::LoadImage(hinstance, MAKEINTRESOURCE(icon.resource_id), IMAGE_ICON, 0, 0, | ||||||
|     ::SendMessage(handle_, WM_SETICON, ICON_SMALL, (LPARAM)icon); |                                    LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         String full_path = FileSystem::GetInstance().GetFullPathForFile(icon.file_path); | ||||||
|  |         if (!full_path.empty()) | ||||||
|  |         { | ||||||
|  |             hicon = (HICON)::LoadImageA(NULL, full_path.c_str(), IMAGE_ICON, 0, 0, | ||||||
|  |                                         LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     ::SendMessage(handle_, WM_SETICON, ICON_BIG, (LPARAM)hicon); | ||||||
|  |     ::SendMessage(handle_, WM_SETICON, ICON_SMALL, (LPARAM)hicon); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height) | void WindowWin32Impl::SetMinimumSize(uint32_t width, uint32_t height) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue