forked from gecko0307/electronvolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.d
More file actions
119 lines (102 loc) · 2.65 KB
/
editor.d
File metadata and controls
119 lines (102 loc) · 2.65 KB
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
module main;
import std.stdio;
import std.algorithm;
import dlib;
import dgl;
import gui.window;
import gui.widget;
import gui.scene;
import gui.sceneview;
class Grid: Drawable
{
float cellWidth = 1.0f;
int size = 20;
override void draw(double dt)
{
glColor4f(1, 1, 1, 0.25f);
foreach(x; 0..size+1)
{
glBegin(GL_LINES);
glVertex3f((x - size/2) * cellWidth, 0, -size/2);
glVertex3f((x - size/2) * cellWidth, 0, size/2);
glEnd();
}
foreach(y; 0..size+1)
{
glBegin(GL_LINES);
glVertex3f(-size/2, 0, (y - size/2) * cellWidth);
glVertex3f( size/2, 0, (y - size/2) * cellWidth);
glEnd();
}
glColor4f(1, 1, 1, 1);
}
override void free()
{
Delete(this);
}
}
class EditorApp: Application
{
WindowManager wm;
SceneView sv;
EditorScene scene;
ShapeBox ss;
this()
{
super(800, 600, "DGLEditor");
exitOnEscapePress = false;
clearColor = Color4f(0.5f, 0.5f, 0.5f);
wm = New!WindowManager(eventManager);
wm.addWindow(Vector2f(0, 0), Vector2f(100, 100));
wm.addWindow(Vector2f(50, 50), Vector2f(100, 100));
scene = New!EditorScene(eventManager);
ss = New!ShapeBox(Vector3f(1,1,1));
scene.addEntity(New!Entity(ss, Vector3f(0, 0, 0)));
scene.addEntity(New!Entity(ss, Vector3f(2, 0, 0)));
auto w = wm.addWindow(Vector2f(100, 100), Vector2f(320, 240));
sv = New!SceneView(eventManager, w);
w.addWidget(sv);
sv.scene = scene;
sv.addDrawable(New!Grid());
w = wm.addWindow(Vector2f(50, 50), Vector2f(320, 240));
auto sv2 = New!SceneView(eventManager, w);
w.addWidget(sv2);
sv2.scene = scene;
sv2.addDrawable(New!Grid());
//sv2.addEntity(eSphere);
}
~this()
{
Delete(wm);
Delete(scene);
Delete(ss);
}
override void onKeyDown(int key)
{
if (key == 'a')
scene.addEntity(New!Entity(ss, Vector3f(0, 0, 0)));
}
override void free()
{
Delete(this);
}
override void onUpdate()
{
wm.onUpdate();
}
override void onRedraw()
{
double dt = eventManager.deltaTime;
wm.draw(dt);
}
}
void main(string[] args)
{
loadLibraries();
writefln("Allocated memory at start: %s", allocatedMemory);
auto app = New!EditorApp();
app.run();
Delete(app);
writefln("Allocated memory at end: %s", allocatedMemory);
//printMemoryLog();
}