summaryrefslogtreecommitdiff
path: root/Editor/GUI/EditorWindows.h
blob: e1ad89a89fa8e518a479f484b2c6fa40eb300b20 (plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#ifndef EDITOR_WINDOW_H
#define EDITOR_WINDOW_H

#include <windows.h>
#include <vector>
#include "Runtime/Math/Rect.h"
#include "Runtime/Lua/LuaBind/LuaBind.h"
#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Utilities/Singleton.h"
#include "Runtime/Debug/Log.h"
#include "Runtime/Graphics/OpenGL.h"
#include "Runtime/Utilities/UtilMacros.h"
#include "Editor/Utils/HelperFuncs.h"

using namespace LuaBind;

class GUIWindow;

class WindowUtil
{
public :
	static void RegisterClasses();

	static const wchar_t* kContainerWindowClassName;
	static const wchar_t* kPopupWindowClassName;
	static const wchar_t* kGUIWindowClassName;
};

class WindowManager : Singleton<WindowManager>
{
public:
	static Internal::Vector2 GetMousePosition();
	static GUIWindow* GetMouseOverWindow();

private:
	static std::vector<GUIWindow*> s_GUIWindows;

};

// 一个containner window中有多个viewport
class ContainerWindow 
	: public LuaBind::NativeClass<ContainerWindow>
{
public:
	static LRESULT CALLBACK ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

    enum ShowMode {
        kShowNormalWindow = 0,	// normal window with max/min/close buttons
        kShowPopupMenu = 1,		// popup menu - no title bar
        kShowUtility = 2,			// tool window - floats in the app, and hides when the app deactivates
        kShowNoShadow = 3,		// no shadow/decorations
        kShowMainWindow = 4,		// main Unity window. On Mac does not have close button; on Windows has menu bar etc.
        kShowAuxWindow = 5,		// Popup windows like the color picker, gradient editor, etc. Drawn with black background on Mac
    };

    ContainerWindow(LuaBind::VM* vm);
    ~ContainerWindow();

    void Init(Internal::Rect size, int showMode, const Internal::Vector2& minSize, const Internal::Vector2& maxSize, std::string name = "");
	void SetTitle(const char* title);
	void SetIcon(LPCSTR iconName);
	void SetAsRenderContext();
	void DoPaint();
	void Close();

	GET_SET(std::string, Name, m_Name);

	GET(HWND, WindowHandle, m_Window);
	GET(HDC, DC, m_DC);

	void OnRectChanged();
	void OnActivateApplication(bool active);

private:
	bool SetRenderContext();

	std::string m_Name;

	HWND m_Window;
	HDC m_DC;
	POINT m_Size;
    ShowMode m_ShowMode; // 窗口类型
    bool  m_IsClosing;
    bool  m_InMenuLoop;
    bool  m_CloseFromScriptDontShutdown;
    Internal::Rect  m_InternalRect;
    POINT m_MinSize;
    POINT m_MaxSize;

	LUA_BIND_DECL_CLASS(ContainerWindow);

    LUA_BIND_DECL_METHOD(_New);
    LUA_BIND_DECL_METHOD(_SetTitle);
    LUA_BIND_DECL_METHOD(_SetIcon);
    LUA_BIND_DECL_METHOD(_DoPaint);

};

// 窗口基类
class WindowBase 
{
};

// 抽象窗口,用来做布局
class SplitWindow : public WindowBase
{
public: 
	enum SplitMode 
	{
		Horizontal,
		Vertical,
	};

	SplitMode GetSplitMode() { return m_SplitMode; }

	GET(SplitMode, SplitMode, m_SplitMode);

private:
	SplitMode m_SplitMode;

	GUIWindow* m_GUIWindow;
	std::vector<GUIWindow*>* m_GUIWindows;

};

// GUI窗口,事件相应、绘制、布局的单元
class GUIWindow 
    : public WindowBase
    , public LuaBind::NativeClass<GUIWindow>
{
public:
    static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	static void RepaintAll();

    GUIWindow(LuaBind::VM* vm);

	void Init(std::string name = "");
    void DoPaint();
	void SetContainerWindow(ContainerWindow* wnd);
	void Focus();
	void SetPosition(Internal::Rect position);
	void SetAsRenderContext();

	void OnFocus();
	void OnLostFocus();
    void OnPaint();

	GET_SET(std::string, Name, m_Name);
	GET(HDC, DC, m_DC);

private:
	void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam);
	bool SetRenderContext();

	std::string m_Name; 

	ContainerWindow* m_ContainerWindow;
	HWND m_Handle;
	HDC m_DC;

	std::vector<LuaBind::MemberRef> m_EditorWindows;

	LuaBind::MemberRef m_Script; // EditorWindow脚本

    LUA_BIND_DECL_CLASS(GUIWindow);

	LUA_BIND_DECL_METHOD(_New);
    LUA_BIND_DECL_METHOD(_DoPaint);
    LUA_BIND_DECL_METHOD(_Focus);
    LUA_BIND_DECL_METHOD(_SetContainerWindow);
    LUA_BIND_DECL_METHOD(_SetPosition);

	LUA_BIND_DECL_METHOD(_SetInstance);

};

#endif