forked from floft/sprouts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgui.cpp
68 lines (62 loc) · 1.92 KB
/
gui.cpp
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
#include "gui.h"
/**************
*Description:
*Input:
*Output:
**************/
unordered_map<shared_ptr<GUIContainer>, weak_ptr<GUIRunner>> * GUIRunner::runners = nullptr;
void GUIRunner::makeRunners()
{
if(runners == nullptr)
runners = new unordered_map<shared_ptr<GUIContainer>, weak_ptr<GUIRunner>>;
}
namespace
{
Image getBackground()
{
static Image * pbackground = nullptr;
if(pbackground == nullptr)
pbackground = new Image();
Image & background = *pbackground;
if(!background)
background = Image(L"background.png");
return background;
}
}
bool GUIRunner::run()
{
Renderer renderer;
Image background = getBackground();
needQuit = false;
runRetval = false;
bool first = true;
while(!needQuit)
{
Display::initFrame();
if(first)
{
first = false;
gui->reset();
}
Display::handleEvents(gui);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
TextureDescriptor td = TextureDescriptor(background, 0, (float)Display::width() / background.width(), 0,
(float)Display::height() / background.height());
Mesh backgroundmesh = Generate::quadrilateral(td, VectorF(-Display::scaleX(), -Display::scaleY(),
-1), Color(1), VectorF(Display::scaleX(), -Display::scaleY(), -1), Color(1),
VectorF(Display::scaleX(), Display::scaleY(), -1), Color(1), VectorF(-Display::scaleX(),
Display::scaleY(), -1), Color(1));
renderer << backgroundmesh;
Display::initOverlay();
renderer << gui->render();
Display::flip(60);
vector<function<void()>> fns = std::move(functionList);
functionList.clear();
for(function<void()> fn : fns)
{
fn();
}
}
return runRetval;
}