summaryrefslogtreecommitdiff
path: root/src/interface/Sandbox.cpp
blob: 5e29bae042e7e9c3f303da9583ae636721f6d1ec (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
/*
 * Sandbox.cpp
 *
 *  Created on: Jan 8, 2012
 *      Author: Simon
 */

#include <iostream>

#include "Config.h"

#include "interface/Sandbox.h"
#include "interface/Component.h"
#include "Renderer.h"
#include "Simulation.h"

namespace ui {

Sandbox::Sandbox():
	Component(0, 0, XRES, YRES),
	ren(NULL),
	isMouseDown(false),
	activeElement(1)
{
	sim = new Simulation();
}

Simulation * Sandbox::GetSimulation()
{
	return sim;
}

void Sandbox::OnMouseMovedInside(int localx, int localy, int dx, int dy)
{
	if(isMouseDown)
	{
		sim->create_line(lastCoordX, lastCoordY, localx, localy, 2, 2, activeElement, 0);
		lastCoordX = localx;
		lastCoordY = localy;
	}
}

void Sandbox::OnMouseDown(int localx, int localy, unsigned int button)
{
	sim->create_line(localx, localy, localx, localy, 2, 2, activeElement, 0);
	lastCoordX = localx;
	lastCoordY = localy;
	isMouseDown = true;
}

void Sandbox::OnMouseUp(int localx, int localy, unsigned int button)
{
	sim->create_line(lastCoordX, lastCoordY, localx, localy, 2, 2, activeElement, 0);
	lastCoordX = localx;
	lastCoordY = localy;
	isMouseDown = false;
}

void Sandbox::Draw(void* userdata)
{
	Graphics * g = reinterpret_cast<Graphics*>(userdata);
	if(!ren)
		ren = new Renderer(g, sim);
	ren->render_parts();
}

void Sandbox::Tick(float delta)
{
	sim->update_particles();
}

Sandbox::~Sandbox() {
	// TODO Auto-generated destructor stub
}

} /* namespace ui */