Added triangle brush, fixes #47

This commit is contained in:
Savely Skresanov 2012-08-05 20:37:18 +07:00 committed by Simon Robertshaw
parent 3030d67516
commit 6e324c82e2
2 changed files with 49 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include "interface/Point.h"
#include "Brush.h"
#include "EllipseBrush.h"
#include "TriangleBrush.h"
#include "client/Client.h"
#include "game/DecorationTool.h"
#include "GameModelException.h"
@ -222,6 +223,7 @@ void GameModel::BuildMenus()
//Set default brush palette
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
brushList.push_back(new Brush(ui::Point(4, 4)));
brushList.push_back(new TriangleBrush(ui::Point(4, 4)));
//Set default tools
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
@ -801,4 +803,4 @@ void GameModel::notifyQuickOptionsChanged()
{
observers[i]->NotifyQuickOptionsChanged(this);
}
}
}

46
src/game/TriangleBrush.h Normal file
View File

@ -0,0 +1,46 @@
/*
* TriangleBrush.h
*
* Created on: Jan 26, 2012
* Author: Savely Skresanov
*/
#ifndef TRIANGLEBRUSH_H_
#define TRIANGLEBRUSH_H_
#include <cmath>
#include "Brush.h"
class TriangleBrush: public Brush
{
public:
TriangleBrush(ui::Point size_):
Brush(size_)
{
SetRadius(size_);
};
virtual void GenerateBitmap()
{
if(bitmap)
delete[] bitmap;
bitmap = new unsigned char[size.X*size.Y];
int rx = radius.X;
int ry = radius.Y;
for(int x = -rx; x <= rx; x++)
{
for(int y = -ry; y <= ry; y++)
{
if ((abs((rx+2*x)*ry+rx*y) + abs(2*rx*(y-ry)) + abs((rx-2*x)*ry+rx*y))<=(4*rx*ry))
{
bitmap[(y+ry)*(size.X)+x+rx] = 255;
}
else
{
bitmap[(y+ry)*(size.X)+x+rx] = 0;
}
}
}
}
};
#endif /* TRIANGLEBRUSH_H_ */