1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#ifndef __ASURA_ENGINE_WINDOW_H__
#define __ASURA_ENGINE_WINDOW_H__
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/math/vector2.hpp>
#include <asura-utils/singleton.hpp>
#include "../graphics/image.h"
#include "../graphics/render_state.h"
#include "../graphics/render_target.h"
namespace AsuraEngine
{
namespace Window
{
class WindowImpl;
///
/// SDLģһЩõġ
///
enum WindowFlag
{
WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window
WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context
WINDOW_SHOWN = 1 << 3, ///< window is visible
WINDOW_HIDDEN = 1 << 4, ///< window is not visible
WINDOW_BORDERLESS = 1 << 5, ///< no window decoration
WINDOW_RESIZABLE = 1 << 6, ///< window can be resized
WINDOW_MINIMIZED = 1 << 7, ///< window is minimized
WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized
WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus
WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus
WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus
WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported.
///< On macOS NSHighResolutionCapable must be set true in the
///< application's Info.plist for this to have any effect.
WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED)
WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others
};
/// Windowʼ
struct WindowConfig
{
uint width, height; ///< ߴ
int x, y; ///< ڳʼ
std::string title; ///<
bool vsync; ///< ֱͬ
AEImage::ImageData* icon; ///< ͼ
bool show; ///< Ƿʾ
int flag; ///< ڱ
};
///
/// ϷĵڣrunnerֻҪһڡͬĿͻʵִ˽ӿڲֶעᵽlua༭
/// ᵼ࣬ӵ༭ⴰϡ
///
class Window ASURA_FINAL
: public AEScripting::Portable<Window, AEGraphics::RenderTarget>
, public Singleton<Window>
{
public:
/// ϷʱĴΨһģ༭õࡣ
LUAX_DECL_SINGLETON(Window);
Window();
~Window();
/// ڡ
bool Init(const WindowConfig& config);
void Exit();
void SetSize(uint width, uint height);
void SetPosition(int x, int y);
void SetTitle(const std::string& title);
void SetIcon(AEImage::ImageData* imgData);
void Show();
void Hide();
/// ǿ˫ĴڣҪչʾǰ̨
void SwapRenderBuffer();
void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override;
void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override;
void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override;
void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override;
private:
WindowImpl* m_Impl;
luaxport:
LUAX_DECL_ENUM(WindowFlag, 0);
LUAX_DECL_METHOD(_Init);
LUAX_DECL_METHOD(_Exit);
LUAX_DECL_METHOD(_Show);
LUAX_DECL_METHOD(_Hide);
LUAX_DECL_METHOD(_SetSize);
LUAX_DECL_METHOD(_SetPosition);
LUAX_DECL_METHOD(_SetTitle);
LUAX_DECL_METHOD(_SetIcon);
LUAX_DECL_METHOD(_SwapRenderBuffer);
LUAX_DECL_METHOD(_Clear);
LUAX_DECL_METHOD(_Draw);
};
using RenderWindow = Window;
ASURA_ABSTRACT class WindowImpl
{
public:
WindowImpl() {};
virtual ~WindowImpl() {};
virtual bool Init(const WindowConfig& config);
virtual void SetSize(uint width, uint height) = 0;
virtual void SetPosition(int x, int y) = 0;
virtual void SetTitils(const std::string& title) = 0;
virtual void Show() = 0;
virtual void Hide() = 0;
virtual void SwapRenderBuffer() = 0;
};
}
}
namespace AEWindow = AsuraEngine::Window;
#endif
|