summaryrefslogtreecommitdiff
path: root/src/game/Brush.h
blob: 617f7df6943ec13079ad2740baede82134cc9de9 (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
/*
 * Brush.h
 *
 *  Created on: Jan 22, 2012
 *      Author: Simon
 */

#ifndef BRUSH_H_
#define BRUSH_H_

#include "interface/Point.h"

class Brush
{
protected:
	bool * bitmap;
	ui::Point size;
public:
	Brush(ui::Point size_):
		bitmap(NULL),
		size(size_)
	{

	};
	ui::Point GetRadius()
	{
		return size;
	}
	void SetRadius(ui::Point size)
	{
		this->size = size;
		GenerateBitmap();
	}
	virtual ~Brush() {
		if(bitmap)
			delete bitmap;
	}
	virtual void RenderRect(Graphics * g, ui::Point position1, ui::Point position2)
	{
		int width, height, t;
		width = position2.X-position1.X;
		height = position2.Y-position1.Y;
		if(height<0)
		{
			position1.Y += height;
			height *= -1;
		}
		if(width<0)
		{
			position1.X += width;
			width *= -1;
		}
		g->fillrect(position1.X-1, position1.Y-1, width+2, height+2, 255, 0, 255, 70);
	}
	virtual void RenderLine(Graphics * g, ui::Point position1, ui::Point position2)
	{
		g->blend_line(position1.X, position1.Y, position2.X, position2.Y, 255, 0, 255, 70);
	}
	//Draw the brush outline onto the screen
	virtual void RenderPoint(Graphics * g, ui::Point position)
	{
		g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
	}
	virtual void GenerateBitmap()
	{
		if(bitmap)
			free(bitmap);
		bitmap = (bool *)malloc(sizeof(bool)*(((size.X*2)+1)*((size.Y*2)+1)));
		for(int x = 0; x <= size.X*2; x++)
		{
			for(int y = 0; y <= size.Y*2; y++)
			{
				bitmap[y*(size.X*2)+x] = true;
			}
		}
	}
	//Get a bitmap for drawing particles
	bool * GetBitmap()
	{
		if(!bitmap)
			GenerateBitmap();
		return bitmap;
	}
};


#endif /* BRUSH_H_ */