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
|
/*
* Sandbox.cpp
*
* Created on: Jan 8, 2012
* Author: Simon
*/
#include <iostream>
#include <queue>
#include "Config.h"
#include "Global.h"
#include "interface/Point.h"
#include "interface/Sandbox.h"
#include "interface/Component.h"
#include "Renderer.h"
#include "Simulation.h"
#include "Engine.h"
namespace ui {
Sandbox::Sandbox():
Component(Point(0, 0), Point(XRES, YRES)),
pointQueue(std::queue<Point*>()),
ren(NULL),
isMouseDown(false),
activeElement(1)
{
sim = new Simulation();
}
Simulation * Sandbox::GetSimulation()
{
return sim;
}
void Sandbox::OnMouseMoved(int localx, int localy, int dx, int dy)
{
if(isMouseDown)
{
pointQueue.push(new Point(localx-dx, localy-dy));
pointQueue.push(new Point(localx, localy));
}
}
void Sandbox::OnMouseClick(int localx, int localy, unsigned int button)
{
isMouseDown = true;
pointQueue.push(new Point(localx, localy));
}
void Sandbox::OnMouseUp(int localx, int localy, unsigned int button)
{
if(isMouseDown)
{
isMouseDown = false;
pointQueue.push(new Point(localx, localy));
}
}
void Sandbox::Draw(const Point& screenPos)
{
Graphics * g = Engine::Ref().g;
if(!ren)
ren = new Renderer(g, sim);
ren->render_parts();
}
void Sandbox::Tick(float delta)
{
if(!pointQueue.empty())
{
Point * sPoint = NULL;
while(!pointQueue.empty())
{
Point * fPoint = pointQueue.front();
pointQueue.pop();
if(sPoint)
{
sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0);
delete sPoint;
}
else
{
sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0);
}
sPoint = fPoint;
}
if(sPoint)
delete sPoint;
}
sim->update_particles();
sim->sys_pause = 1;
}
Sandbox::~Sandbox() {
// TODO Auto-generated destructor stub
}
} /* namespace ui */
|