1 #include "Tool.h"
2 
3 #include "graphics/Graphics.h"
4 #include "graphics/Renderer.h"
5 
6 #include "gui/game/GameModel.h"
7 #include "gui/interface/Colour.h"
8 
9 #include "simulation/Simulation.h"
10 #include "simulation/ElementClasses.h"
11 
12 #include "Menu.h"
13 
GetIcon(int toolID,int width,int height)14 VideoBuffer * SampleTool::GetIcon(int toolID, int width, int height)
15 {
16 	VideoBuffer * newTexture = new VideoBuffer(width, height);
17 	for (int y=0; y<height; y++)
18 	{
19 		for (int x=0; x<width; x++)
20 		{
21 			pixel pc =  x==0||x==width-1||y==0||y==height-1 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
22 			newTexture->SetPixel(x, y, PIXR(pc), PIXG(pc), PIXB(pc), 255);
23 		}
24 	}
25 	newTexture->AddCharacter((width/2)-5, (height/2)-5, 0xE066, 255, 255, 255, 255);
26 	newTexture->BlendPixel(10, 9, 100, 180, 255, 255);
27 	newTexture->BlendPixel(11, 8, 100, 180, 255, 255);
28 	newTexture->BlendPixel(12, 7, 100, 180, 255, 255);
29 	return newTexture;
30 }
31 
Draw(Simulation * sim,Brush * brush,ui::Point position)32 void SampleTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
33 {
34 	if(gameModel->GetColourSelectorVisibility())
35 	{
36 		pixel colour = gameModel->GetRenderer()->sampleColor;
37 		gameModel->SetColourSelectorColour(ui::Colour(PIXR(colour), PIXG(colour), PIXB(colour), 255));
38 	}
39 	else
40 	{
41 		int particleType = 0;
42 		int particleCtype = 0;
43 		if (sim->photons[position.Y][position.X])
44 		{
45 			particleType = sim->parts[ID(sim->photons[position.Y][position.X])].type;
46 			particleCtype = sim->parts[ID(sim->pmap[position.Y][position.X])].ctype;
47 		}
48 		else if (sim->pmap[position.Y][position.X])
49 		{
50 			particleType = sim->parts[ID(sim->pmap[position.Y][position.X])].type;
51 			particleCtype = sim->parts[ID(sim->pmap[position.Y][position.X])].ctype;
52 		}
53 
54 		if(particleType)
55 		{
56 			if(particleType == PT_LIFE)
57 			{
58 				Menu * lifeMenu = gameModel->GetMenuList()[SC_LIFE];
59 				std::vector<Tool*> elementTools = lifeMenu->GetToolList();
60 
61 				for(std::vector<Tool*>::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter)
62 				{
63 					Tool * elementTool = *iter;
64 					if(elementTool && ID(elementTool->GetToolID()) == particleCtype)
65 						gameModel->SetActiveTool(0, elementTool);
66 				}
67 			}
68 			else
69 			{
70 				Tool * elementTool = gameModel->GetElementTool(particleType);
71 				if(elementTool)
72 					gameModel->SetActiveTool(0, elementTool);
73 			}
74 		}
75 	}
76 }
77