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
150 Size GetLogicalSize() const;
151
156 uint32_t GetRealWidth() const;
157
162 uint32_t GetRealHeight() const;
163
168 float GetDPI() const;
169
174 float GetDPIScale() const;
175
180 Resolution GetCurrentResolution() const;
181
186 WindowHandle GetHandle() const;
187
192 virtual Vector<Resolution> GetResolutions() = 0;
193
199 virtual void SetTitle(StringView title) = 0;
200
206 virtual void SetIcon(Icon icon) = 0;
207
215 virtual void SetResolution(uint32_t width, uint32_t height, bool fullscreen) = 0;
216
223 virtual void SetMinimumSize(uint32_t width, uint32_t height) = 0;
224
231 virtual void SetMaximumSize(uint32_t width, uint32_t height) = 0;
232
238 virtual void SetCursor(CursorType cursor) = 0;
239
245 RefPtr<Event> PollEvent();
246
252 void PushEvent(RefPtr<Event> evt);
253
258 virtual void PumpEvents() = 0;
259
264 bool ShouldClose() const;
265
270 void SetShouldClose(bool should);
271
276 virtual void SetImmEnabled(bool enable) = 0;
277
282 void SetKeyEventsIgnored(bool ignored);
283
284protected:
285 Window();
286
287 virtual ~Window();
288
289protected:
290 bool should_close_;
291 bool is_fullscreen_;
292 bool ignore_key_events_;
293 int pos_x_;
294 int pos_y_;
295 uint32_t real_width_;
296 uint32_t real_height_;
297 uint32_t min_width_;
298 uint32_t min_height_;
299 uint32_t max_width_;
300 uint32_t max_height_;
301 float dpi_;
302 Size logical_size_;
303 Resolution resolution_;
304 WindowHandle handle_;
305 String title_;
306 std::queue<RefPtr<Event>> event_queue_;
307};
308
309} // 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