summaryrefslogtreecommitdiff
path: root/src/gui/game/EllipseBrush.h
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2013-03-24 12:24:17 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2013-03-24 12:24:17 (GMT)
commit9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d (patch)
treeac7d040253b459ce102e476cb19ab59e3cfa90d7 /src/gui/game/EllipseBrush.h
parent6bf98ccdca39936a3c51367862eed7c49f8786ec (diff)
parentbdc69f31c0be94191015838886bdcc2bc67f1acb (diff)
downloadpowder-9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d.zip
powder-9b5b85f9b01cbda7ef9a7ec2a15b2a35630a5b9d.tar.gz
Merge branch 'reorganisation' of github.com:FacialTurd/The-Powder-Toy
Diffstat (limited to 'src/gui/game/EllipseBrush.h')
-rw-r--r--src/gui/game/EllipseBrush.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/gui/game/EllipseBrush.h b/src/gui/game/EllipseBrush.h
new file mode 100644
index 0000000..ad28766
--- /dev/null
+++ b/src/gui/game/EllipseBrush.h
@@ -0,0 +1,56 @@
+#ifndef ELIPSEBRUSH_H_
+#define ELIPSEBRUSH_H_
+
+#include <cmath>
+#include "Brush.h"
+
+class EllipseBrush: public Brush
+{
+public:
+ EllipseBrush(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;
+
+ if (!rx)
+ {
+ for (int j = 0; j <= 2*ry; j++)
+ {
+ bitmap[j*(size.X)+rx] = 255;
+ }
+ }
+ else
+ {
+ int yTop = ry, yBottom, i, j;
+ for (i = 0; i <= rx; i++)
+ {
+ while (pow(i-rx,2.0f)*pow(ry,2.0f) + pow(yTop-ry,2.0f)*pow(rx,2.0f) <= pow(rx,2.0f)*pow(ry,2.0f))
+ yTop++;
+ yBottom = 2*ry - yTop;
+ for (int j = 0; j <= ry*2; j++)
+ {
+ if (j > yBottom && j < yTop)
+ {
+ bitmap[j*(size.X)+i] = 255;
+ bitmap[j*(size.X)+2*rx-i] = 255;
+ }
+ else
+ {
+ bitmap[j*(size.X)+i] = 0;
+ bitmap[j*(size.X)+2*rx-i] = 0;
+ }
+ }
+ }
+ }
+ }
+};
+
+#endif /* ELIPSEBRUSH_H_ */