summaryrefslogtreecommitdiff
path: root/src/game/SampleTool.cpp
blob: 296167b3bdf1f107354bae47f096311c814bcfc3 (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
#include <iostream>
#include "graphics/Graphics.h"
#include "Tool.h"
#include "GameModel.h"
#include "interface/Colour.h"

VideoBuffer * SampleTool::GetIcon(int toolID, int width, int height)
{
	VideoBuffer * newTexture = new VideoBuffer(width, height);
	for (int y=0; y<height; y++)
	{
		for (int x=0; x<width; x++)
		{
			pixel pc =  x==0||x==width-1||y==0||y==height-1 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
			newTexture->SetPixel(x, y, PIXR(pc), PIXG(pc), PIXB(pc), 255);
		}
	}
	newTexture->SetCharacter((width/2)-5, (height/2)-5, 0xE6, 255, 255, 255, 255);
	newTexture->BlendCharacter((width/2)-5, (height/2)-5, 0xE7, 100, 180, 255, 255);
	return newTexture;
}

void SampleTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
{
	if(gameModel->GetColourSelectorVisibility())
	{
		pixel colour = gameModel->GetRenderer()->GetPixel(position.X, position.Y);
		gameModel->SetColourSelectorColour(ui::Colour(PIXR(colour), PIXG(colour), PIXB(colour), 255));
	}
	else
	{
		int particleType = 0;
		int particleCtype = 0;
		if(sim->pmap[position.Y][position.X])
		{
			particleType = sim->parts[sim->pmap[position.Y][position.X]>>8].type;
			particleCtype = sim->parts[sim->pmap[position.Y][position.X]>>8].ctype;
		}
		else if(sim->photons[position.Y][position.X])
		{
			particleType = sim->parts[sim->photons[position.Y][position.X]>>8].type;
			particleCtype = sim->parts[sim->pmap[position.Y][position.X]>>8].ctype;
		}

		if(particleType)
		{
			if(particleType == PT_LIFE)
			{
				Menu * lifeMenu = gameModel->GetMenuList()[SC_LIFE];
				std::vector<Tool*> elementTools = lifeMenu->GetToolList();

				for(std::vector<Tool*>::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter)
				{
					Tool * elementTool = *iter;
					if(elementTool && elementTool->GetToolID() == particleCtype)
						gameModel->SetActiveTool(0, elementTool);
				}
			}
			else
			{
				Tool * elementTool = gameModel->GetElementTool(particleType);
				if(elementTool)
					gameModel->SetActiveTool(0, elementTool);
			}
		}
	}
}