summaryrefslogtreecommitdiff
path: root/src/PowderToy.cpp
blob: d634ccef21f15526dd5e24e3dc9138161cec525d (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

#include <time.h>
#include <SDL/SDL.h>
#include "Config.h"
#include "Simulation.h"
#include "Renderer.h"
#include "Graphics.h"
#include "Air.h"

#include "interface/Window.h"
#include "interface/Button.h"
#include "interface/Sandbox.h"

SDL_Surface * SDLOpen()
{
	if (SDL_Init(SDL_INIT_VIDEO)<0)
	{
		fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
		return 0;
	}
	atexit(SDL_Quit);
	return SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_SWSURFACE);
}

int SDLPoll(SDL_Event * event)
{
	while (SDL_PollEvent(event))
	{
		switch (event->type)
		{
			case SDL_QUIT:
				return 1;
		}
	}
	return 0;
}

int main(int argc, char * argv[])
{
	int mouseX, mouseY, mouseButton, lastMouseButton;

	//Renderer * ren;
	Graphics * g = new Graphics();
	g->AttachSDLSurface(SDLOpen());
	//Simulation * sim = new Simulation();
	//ren = new Renderer(g, sim);

	ui::Window * window = new ui::Window();
	ui::Sandbox * sandbox = new ui::Sandbox();
	ui::Button * button = new ui::Button(100, 100, 100, 100, "poP");
	window->Add(sandbox);
	window->Add(button);

	SDL_Event event;
	while(!SDLPoll(&event))
	{
		mouseButton = SDL_GetMouseState(&mouseX, &mouseY);
		switch(event.type)
		{
		case SDL_KEYDOWN:
			break;
		case SDL_KEYUP:
			break;
		case SDL_MOUSEMOTION:
			window->OnMouseMove(event.motion.x, event.motion.y);
			break;
		case SDL_MOUSEBUTTONDOWN:
			window->OnMouseDown(event.motion.x, event.motion.y, event.button.button);
			break;
		case SDL_MOUSEBUTTONUP:
			window->OnMouseUp(event.motion.x, event.motion.y, event.button.button);
			break;
		}
		window->Tick(1.0f);
		window->Draw(g);
		/*sim->update_particles();
		sim->air->update_air();
		mouseButton = SDL_GetMouseState(&mouseX, &mouseY);
		if(mouseButton)
		{
			sim->create_parts(mouseX, mouseY, 4, 4, (rand()%4)+1, 0);
		}
		if(mouseButton==4 && !lastMouseButton)
		{
			sim->sys_pause = !sim->sys_pause;
		}
		//ren->render_parts();
		//ren->render_fire();


		ren->g->clearrect(0, 0, XRES+BARSIZE, YRES+MENUSIZE);*/
		g->Blit();
		g->Clear();
	}
}