Kiwano Engine v1.3.x
Window.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Common.h>
23#include <kiwano/base/ObjectBase.h>
24#include <kiwano/event/Event.h>
25#include <kiwano/math/Math.h>
26
27namespace kiwano
28{
29
34enum class CursorType
35{
36 Arrow,
37 TextInput,
38 Hand,
39 SizeAll,
40 SizeWE,
41 SizeNS,
42 SizeNESW,
43 SizeNWSE,
44 No,
45};
46
52{
53 uint32_t width = 0;
54 uint32_t height = 0;
55 uint32_t refresh_rate = 0;
56
57 Resolution() = default;
58
59 Resolution(uint32_t width, uint32_t height, uint32_t refresh_rate)
60 : width(width)
61 , height(height)
63 {
64 }
65};
66
71struct Icon
72{
73 Icon() = default;
74
77 {
78 }
79
80 String file_path;
81
82#if defined(KGE_PLATFORM_WINDOWS)
83 uint32_t resource_id = 0;
84
85 Icon(uint32_t resource_id)
86 : resource_id(resource_id)
87 {
88 }
89#endif
90};
91
97{
98 uint32_t width = 640;
99 uint32_t height = 480;
100 String title = "Kiwano Game";
102 bool resizable = false;
103 bool fullscreen = false;
104};
105
106#if defined(KGE_PLATFORM_WINDOWS)
107typedef HWND WindowHandle;
108#endif
109
114class KGE_API Window : public ObjectBase
115{
116public:
123 static RefPtr<Window> Create(const WindowConfig& config);
124
130 String GetTitle() const;
131
137 int GetPosX() const;
138
144 int GetPosY() const;
145
151 Size GetSize() const;
152
158 uint32_t GetWidth() const;
159
165 uint32_t GetHeight() const;
166
171 Resolution GetCurrentResolution() const;
172
177 WindowHandle GetHandle() const;
178
183 virtual Vector<Resolution> GetResolutions() = 0;
184
190 virtual void SetTitle(StringView title) = 0;
191
197 virtual void SetIcon(Icon icon) = 0;
198
206 virtual void SetResolution(uint32_t width, uint32_t height, bool fullscreen) = 0;
207
214 virtual void SetMinimumSize(uint32_t width, uint32_t height) = 0;
215
222 virtual void SetMaximumSize(uint32_t width, uint32_t height) = 0;
223
229 virtual void SetCursor(CursorType cursor) = 0;
230
236 RefPtr<Event> PollEvent();
237
243 void PushEvent(RefPtr<Event> evt);
244
249 virtual void PumpEvents() = 0;
250
255 bool ShouldClose();
256
261 void SetShouldClose(bool should);
262
267 virtual void SetImmEnabled(bool enable) = 0;
268
269protected:
270 Window();
271
272 virtual ~Window();
273
274protected:
275 bool should_close_;
276 bool is_fullscreen_;
277 int pos_x_;
278 int pos_y_;
279 uint32_t width_;
280 uint32_t height_;
281 uint32_t min_width_;
282 uint32_t min_height_;
283 uint32_t max_width_;
284 uint32_t max_height_;
285 Resolution resolution_;
286 WindowHandle handle_;
287 String title_;
288 std::queue<RefPtr<Event>> event_queue_;
289};
290
291} // namespace kiwano
基础对象
Definition: ObjectBase.h:138
引用计数智能指针
Definition: RefBasePtr.hpp:35
窗口类,控制窗口标题、大小、图标等
Definition: Window.h:115
virtual void SetMaximumSize(uint32_t width, uint32_t height)=0
设置窗口最大大小
virtual void SetMinimumSize(uint32_t width, uint32_t height)=0
设置窗口最小大小
virtual Vector< Resolution > GetResolutions()=0
获取支持的屏幕分辨率列表
static RefPtr< Window > Create(const WindowConfig &config)
初始化窗口
virtual void SetCursor(CursorType cursor)=0
设置鼠标指针类型
virtual void SetResolution(uint32_t width, uint32_t height, bool fullscreen)=0
设置窗口分辨率
virtual void SetIcon(Icon icon)=0
设置窗口图标
virtual void PumpEvents()=0
抽取窗口事件
virtual void SetImmEnabled(bool enable)=0
启用或禁用输入法(默认禁用)
virtual void SetTitle(StringView title)=0
设置标题
图标
Definition: Window.h:72
String file_path
文件路径
Definition: Window.h:80
分辨率
Definition: Window.h:52
uint32_t refresh_rate
刷新率
Definition: Window.h:55
uint32_t width
分辨率宽度
Definition: Window.h:53
uint32_t height
分辨率高度
Definition: Window.h:54
窗口设置
Definition: Window.h:97
bool resizable
窗口大小可调整
Definition: Window.h:102
uint32_t width
窗口宽度
Definition: Window.h:98
uint32_t height
窗口高度
Definition: Window.h:99
String title
窗口标题
Definition: Window.h:100
bool fullscreen
窗口全屏
Definition: Window.h:103
Icon icon
窗口图标
Definition: Window.h:101