Kiwano Engine v1.2.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
30KGE_DECLARE_SMART_PTR(Window);
31
36enum class CursorType
37{
38 Arrow,
39 TextInput,
40 Hand,
41 SizeAll,
42 SizeWE,
43 SizeNS,
44 SizeNESW,
45 SizeNWSE,
46};
47
53{
54 uint32_t width = 0;
55 uint32_t height = 0;
56 uint32_t refresh_rate = 0;
57
58 Resolution() = default;
59
60 Resolution(uint32_t width, uint32_t height, uint32_t refresh_rate)
61 : width(width)
62 , height(height)
64 {
65 }
66};
67
72struct Icon
73{
74 Icon() = default;
75
76 Icon(const String& file_path)
78 {
79 }
80
81 String file_path;
82
83#if defined(KGE_PLATFORM_WINDOWS)
84 uint32_t resource_id = 0;
85
86 Icon(uint32_t resource_id)
87 : resource_id(resource_id)
88 {
89 }
90#endif
91};
92
93
99{
100 uint32_t width = 640;
101 uint32_t height = 480;
102 String title = "Kiwano Game";
104 bool resizable = false;
105 bool fullscreen = false;
106};
107
108
109#if defined(KGE_PLATFORM_WINDOWS)
110typedef HWND WindowHandle;
111#endif
112
113
118class KGE_API Window : public ObjectBase
119{
120public:
127 static WindowPtr Create(const WindowConfig& config);
128
134 String GetTitle() const;
135
141 int GetPosX() const;
142
148 int GetPosY() const;
149
155 Size GetSize() const;
156
162 uint32_t GetWidth() const;
163
169 uint32_t GetHeight() const;
170
175 Resolution GetCurrentResolution() const;
176
181 WindowHandle GetHandle() const;
182
187 virtual Vector<Resolution> GetResolutions() = 0;
188
194 virtual void SetTitle(const String& title) = 0;
195
201 virtual void SetIcon(Icon icon) = 0;
202
210 virtual void SetResolution(uint32_t width, uint32_t height, bool fullscreen) = 0;
211
218 virtual void SetMinimumSize(uint32_t width, uint32_t height) = 0;
219
226 virtual void SetMaximumSize(uint32_t width, uint32_t height) = 0;
227
233 virtual void SetCursor(CursorType cursor) = 0;
234
240 EventPtr PollEvent();
241
247 void PushEvent(EventPtr evt);
248
253 virtual void PumpEvents() = 0;
254
259 bool ShouldClose();
260
265 void SetShouldClose(bool should);
266
267protected:
268 Window();
269
270 virtual ~Window();
271
272protected:
273 bool should_close_;
274 bool is_fullscreen_;
275 int pos_x_;
276 int pos_y_;
277 uint32_t width_;
278 uint32_t height_;
279 uint32_t min_width_;
280 uint32_t min_height_;
281 uint32_t max_width_;
282 uint32_t max_height_;
283 Resolution resolution_;
284 WindowHandle handle_;
285 String title_;
286 std::queue<EventPtr> event_queue_;
287};
288
289} // namespace kiwano
基础对象
Definition: ObjectBase.h:137
窗口类,控制窗口标题、大小、图标等
Definition: Window.h:119
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 WindowPtr 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 SetTitle(const String &title)=0
设置标题
图标
Definition: Window.h:73
String file_path
文件路径
Definition: Window.h:81
分辨率
Definition: Window.h:53
uint32_t refresh_rate
刷新率
Definition: Window.h:56
uint32_t width
分辨率宽度
Definition: Window.h:54
uint32_t height
分辨率高度
Definition: Window.h:55
窗口设置
Definition: Window.h:99
bool resizable
窗口大小可调整
Definition: Window.h:104
uint32_t width
窗口宽度
Definition: Window.h:100
uint32_t height
窗口高度
Definition: Window.h:101
String title
窗口标题
Definition: Window.h:102
bool fullscreen
窗口全屏
Definition: Window.h:105
Icon icon
窗口图标
Definition: Window.h:103