summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSavely Skresanov <savask@yandex.ru>2012-08-05 13:37:18 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-05 15:19:30 (GMT)
commit6e324c82e2a81d22b4ee09637be64d9b4c24bf1d (patch)
tree5bb33a6b4d074d4cbc87f8558053e40eff03a11d /src
parent3030d675169d240fcc833a93c0c5ca5b3b95ebc8 (diff)
downloadpowder-6e324c82e2a81d22b4ee09637be64d9b4c24bf1d.zip
powder-6e324c82e2a81d22b4ee09637be64d9b4c24bf1d.tar.gz
Added triangle brush, fixes #47
Diffstat (limited to 'src')
-rw-r--r--src/game/GameModel.cpp4
-rw-r--r--src/game/TriangleBrush.h46
2 files changed, 49 insertions, 1 deletions
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 9a9e807..c56c195 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -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);
}
-} \ No newline at end of file
+}
diff --git a/src/game/TriangleBrush.h b/src/game/TriangleBrush.h
new file mode 100644
index 0000000..7d537bd
--- /dev/null
+++ b/src/game/TriangleBrush.h
@@ -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_ */