summaryrefslogtreecommitdiff
path: root/Editor/EditorMain.cpp
blob: 1606e94510291a379e8e13f7859424e34e32b159 (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
#include <windows.h>
#include <vector>
#include "GUI/EditorWindows.h"
#include "Runtime/LuaBind/LuaBind.h"
#include "EditorManager.h"
#include "Runtime/Graphics/OpenGL.h"
#include "Editor/Scripting/EditorScripting.h"

using namespace LuaBind;

static int MainLoop()
{
	BOOL returnValue;
	MSG  msg, lastMsg;
	msg.message = WM_NULL;
	std::vector<MSG> messages;
	PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
	bool isQuitSignaled = msg.message == WM_QUIT;

	while (!isQuitSignaled)
	{
		MSG msg;
		while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0)
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			if (msg.message == WM_QUIT)
				isQuitSignaled = true;

		}

	}

	return (INT)msg.wParam;
}

void InitLuaState() 
{
	LuaBind::VM vm;
	vm.Setup();
	vm.OpenLibs();
	if (!SetupGameLabEditorScripting(vm.GetMainThread()))
	{
		log_error("Can't setup scripting.");
	}
	LuaBind::State state = vm.GetMainState();
	state.DoFile("./Scripts/EditorApplication.lua");
}

#ifdef GAMELAB_DEBUG
int main()
#else 
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
#endif
{
	InitLuaState();

	WindowUtil::Init();

	ContainnerWindow* wnd = new ContainnerWindow();
	Vector2f min = Vector2f(100, 100);
	Vector2f max = Vector2f(700, 700);
	wnd->Init(Rectf(400, 400, 800, 500), ContainnerWindow::kShowMainWindow, min, max);
	wnd->SetTitle("GameLab");
	wnd->SetIcon("./Icon/GameLab.ico");

	EditorManager::Instance()->SetMainWindow(wnd);
	MenuManager::Instance()->Init();

	GUIWindow* guiWnd = new GUIWindow();
	guiWnd->Init();
	guiWnd->SetContainnerWindow(wnd);
	Rectf position;
	position.x = 0;
	position.y = 0;
	position.width = 200;
	position.height = 200;
	guiWnd->SetPosition(position);

	GUIWindow* guiWnd2 = new GUIWindow();
	guiWnd2->Init();
	guiWnd2->SetContainnerWindow(wnd);
	position.x = 200;
	position.y = 0;
	position.width = 200;
	position.height = 200;
	guiWnd2->SetPosition(position);

	// init gl
	wglMakeCurrent(guiWnd2->GetDC(), guiWnd2->GetRC());
	if (!gladLoadGL()) {
		log_error("³õʼ»¯GL´íÎó");
	}

	// force repaint
	wnd->DoPaint();
	guiWnd->DoPaint();
	guiWnd2->DoPaint();

	MainLoop();

	return 0;
}