summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2012-12-06 16:01:46 (GMT)
committer jacob1 <jfu614@gmail.com>2012-12-06 16:01:46 (GMT)
commit122599763ef9827d7aadc0fe0295c2fbc96e82ab (patch)
treedcf0a21b20cd38a12dee93d9db6115da6c0fdb35 /src/game
parent2d7ac84c1dca8521f41cf023774b7a90e300b3bf (diff)
parent9bf5eeeef919260458637e84f3388b4d7d8204c5 (diff)
downloadpowder-122599763ef9827d7aadc0fe0295c2fbc96e82ab.zip
powder-122599763ef9827d7aadc0fe0295c2fbc96e82ab.tar.gz
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/game')
-rw-r--r--src/game/BitmapBrush.h96
-rw-r--r--src/game/Brush.h2
-rw-r--r--src/game/GameController.cpp9
-rw-r--r--src/game/GameController.h1
-rw-r--r--src/game/GameModel.cpp21
-rw-r--r--src/game/GameView.cpp4
6 files changed, 132 insertions, 1 deletions
diff --git a/src/game/BitmapBrush.h b/src/game/BitmapBrush.h
new file mode 100644
index 0000000..e1c0445
--- /dev/null
+++ b/src/game/BitmapBrush.h
@@ -0,0 +1,96 @@
+/*
+ * BitmapBrush.h
+ *
+ * Created on: Nov 18, 2012
+ * Author: Simon Robertshaw
+ */
+
+#ifndef BTIMAPBRUSH_H_
+#define BTIMAPBRUSH_H_
+
+#include <vector>
+#include <cmath>
+#include "Brush.h"
+
+class BitmapBrush: public Brush
+{
+protected:
+ ui::Point origSize;
+ unsigned char * origBitmap;
+public:
+ BitmapBrush(std::vector<unsigned char> newBitmap, ui::Point rectSize_):
+ Brush(ui::Point(0, 0)),
+ origSize(0, 0)
+ {
+ ui::Point newSize = rectSize_;
+
+ //Ensure the rect has odd dimentions so we can pull an integer radius with a 1x1 centre
+ if(!(newSize.X % 2))
+ newSize.X += 1;
+ if(!(newSize.Y % 2))
+ newSize.Y += 1;
+
+ radius = (newSize-ui::Point(1, 1))/2;
+ size = newSize;
+ origSize = size;
+
+ origBitmap = new unsigned char[size.X*size.Y];
+ std::fill(origBitmap, origBitmap+(size.X*size.Y), 0);
+ for(int y = 0; y < rectSize_.Y; y++)
+ {
+ for(int x = 0; x < rectSize_.X; x++)
+ {
+ if(newBitmap[(y*rectSize_.X)+x] >= 128)
+ origBitmap[(y*size.X)+x] = newBitmap[(y*rectSize_.X)+x];
+ }
+ }
+
+ SetRadius(radius);
+ };
+ virtual void GenerateBitmap()
+ {
+ if(origBitmap)
+ {
+ if(bitmap)
+ delete[] bitmap;
+ bitmap = new unsigned char[size.X*size.Y];
+ if(size == origSize)
+ std::copy(origBitmap, origBitmap+(origSize.X*origSize.Y), bitmap);
+ else
+ {
+ //Bilinear interpolation
+ float factorX = ((float)origSize.X)/((float)size.X);
+ float factorY = ((float)origSize.Y)/((float)size.Y);
+ for(int y = 0; y < size.Y; y++)
+ {
+ for(int x = 0; x < size.X; x++)
+ {
+ float originalY = ((float)y)*factorY;
+ float originalX = ((float)x)*factorX;
+
+ int lowerX = std::floor(originalX);
+ int upperX = std::min((float)(origSize.X-1), std::floor(originalX+1.0f));
+ int lowerY = std::floor(originalY);
+ int upperY = std::min((float)(origSize.Y-1), std::floor(originalY+1.0f));
+
+ unsigned char topRight = origBitmap[(lowerY*origSize.X)+upperX];
+ unsigned char topLeft = origBitmap[(lowerY*origSize.X)+lowerX];
+ unsigned char bottomRight = origBitmap[(upperY*origSize.X)+upperX];
+ unsigned char bottomLeft = origBitmap[(upperY*origSize.X)+lowerX];
+ float top = LinearInterpolate<float>(topLeft, topRight, lowerX, upperX, originalX);
+ float bottom = LinearInterpolate<float>(bottomLeft, bottomRight, lowerX, upperX, originalX);
+ float mid = LinearInterpolate<float>(top, bottom, lowerY, upperY, originalY);
+ bitmap[(y*size.X)+x] = mid > 128 ? 255 : 0;
+ }
+ }
+ }
+ }
+ }
+ virtual ~BitmapBrush()
+ {
+ if(origBitmap)
+ delete[] origBitmap;
+ }
+};
+
+#endif /* BTIMAPBRUSH_H_ */
diff --git a/src/game/Brush.h b/src/game/Brush.h
index 068ecf5..b59d017 100644
--- a/src/game/Brush.h
+++ b/src/game/Brush.h
@@ -61,7 +61,7 @@ public:
{
return size;
}
- void SetRadius(ui::Point radius)
+ virtual void SetRadius(ui::Point radius)
{
this->radius = radius;
this->size = radius+radius+ui::Point(1, 1);
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 18b93d6..c929f3a 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -987,6 +987,15 @@ void GameController::OpenSavePreview(int saveID, int saveDate)
ui::Engine::Ref().ShowWindow(activePreview->GetView());
}
+void GameController::OpenSavePreview()
+{
+ if(gameModel->GetSave())
+ {
+ activePreview = new PreviewController(gameModel->GetSave()->GetID(), new SaveOpenCallback(this));
+ ui::Engine::Ref().ShowWindow(activePreview->GetView());
+ }
+}
+
void GameController::OpenLocalBrowse()
{
class LocalSaveOpenCallback: public FileSelectedCallback
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 4c7a8c9..a5c4416 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -106,6 +106,7 @@ public:
void OpenLogin();
void OpenTags();
void OpenSavePreview(int saveID, int saveDate);
+ void OpenSavePreview();
void OpenLocalSaveWindow(bool asCurrent);
void OpenLocalBrowse();
void OpenOptions();
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 5c4ee97..71d9263 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -9,6 +9,7 @@
#include "Brush.h"
#include "EllipseBrush.h"
#include "TriangleBrush.h"
+#include "BitmapBrush.h"
#include "client/Client.h"
#include "client/GameSave.h"
#include "game/DecorationTool.h"
@@ -310,6 +311,26 @@ void GameModel::BuildMenus()
brushList.push_back(new Brush(ui::Point(4, 4)));
brushList.push_back(new TriangleBrush(ui::Point(4, 4)));
+ //Load more from brushes folder
+ std::vector<string> brushFiles = Client::Ref().DirectorySearch(BRUSH_DIR, "", ".ptb");
+ for(int i = 0; i < brushFiles.size(); i++)
+ {
+ std::vector<unsigned char> brushData = Client::Ref().ReadFile(brushFiles[i]);
+ if(!brushData.size())
+ {
+ std::cout << "Brushes: Skipping " << brushFiles[i] << ". Could not open" << std::endl;
+ continue;
+ }
+ int dimension = std::sqrt(brushData.size());
+ if(dimension * dimension != brushData.size())
+ {
+ std::cout << "Brushes: Skipping " << brushFiles[i] << ". Invalid bitmap size" << std::endl;
+ continue;
+ }
+ brushList.push_back(new BitmapBrush(brushData, ui::Point(dimension, dimension)));
+ }
+
+
//Set default tools
regularToolset[0] = GetToolFromIdentifier("DEFAULT_PT_DUST");
regularToolset[1] = GetToolFromIdentifier("DEFAULT_PT_NONE");
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 0e3f580..9d900ba 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -223,6 +223,10 @@ GameView::GameView():
{
v->c->ReloadSim();
}
+ void AltActionCallback(ui::Button * sender)
+ {
+ v->c->OpenSavePreview();
+ }
};
reloadButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(17, 15), "", "Reload the simulation");
reloadButton->SetIcon(IconReload);