summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-26 18:06:23 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-26 18:06:23 (GMT)
commite84f0fc6e5301265708a99b13ab898ce45422611 (patch)
tree2bbcf8aeb7e0b4177ccaa22a0bde2add3c696765 /src
parent824d3c069bc409d268a2a15352e96868a7731a56 (diff)
downloadpowder-e84f0fc6e5301265708a99b13ab898ce45422611.zip
powder-e84f0fc6e5301265708a99b13ab898ce45422611.tar.gz
Ellipse cursor
Diffstat (limited to 'src')
-rw-r--r--src/game/Brush.h1
-rw-r--r--src/game/EllipseBrush.h60
-rw-r--r--src/game/GameController.cpp4
-rw-r--r--src/game/GameController.h1
-rw-r--r--src/game/GameModel.cpp21
-rw-r--r--src/game/GameModel.h6
-rw-r--r--src/game/GameView.cpp6
-rw-r--r--src/interface/Keys.h1
8 files changed, 97 insertions, 3 deletions
diff --git a/src/game/Brush.h b/src/game/Brush.h
index cc5e819..9daf721 100644
--- a/src/game/Brush.h
+++ b/src/game/Brush.h
@@ -12,6 +12,7 @@
class Brush
{
+protected:
bool * bitmap;
ui::Point size;
public:
diff --git a/src/game/EllipseBrush.h b/src/game/EllipseBrush.h
new file mode 100644
index 0000000..7e5825b
--- /dev/null
+++ b/src/game/EllipseBrush.h
@@ -0,0 +1,60 @@
+/*
+ * ElipseBrush.h
+ *
+ * Created on: Jan 26, 2012
+ * Author: Simon
+ */
+
+#ifndef ELIPSEBRUSH_H_
+#define ELIPSEBRUSH_H_
+
+#include "Brush.h"
+
+class EllipseBrush: public Brush
+{
+public:
+ EllipseBrush(ui::Point size_):
+ Brush(size_)
+ {
+
+ };
+ //Draw the brush outline onto the screen
+ virtual void Render(Graphics * g, ui::Point position)
+ {
+ if(!bitmap)
+ GenerateBitmap();
+ //g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
+ for(int x = 0; x <= size.X*2; x++)
+ {
+ for(int y = 0; y <= size.Y*2; y++)
+ {
+ if(bitmap[y*(size.X*2)+x])
+ g->blendpixel(position.X-size.X+x, position.Y-size.Y+y, 255, 0, 255, 70);
+ }
+ }
+ }
+ virtual void GenerateBitmap()
+ {
+ if(bitmap)
+ free(bitmap);
+ bitmap = (bool *)malloc(sizeof(bool)*(((size.X*2)+1)*((size.Y*2)+1)));
+ int rx = size.X;
+ int ry = size.Y;
+ for(int x = 0; x <= size.X*2; x++)
+ {
+ for(int y = 0; y <= size.Y*2; y++)
+ {
+ if((pow(x-size.X,2)*pow(ry,2)+pow(y-size.Y,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2)))
+ {
+ bitmap[y*(size.X*2)+x] = true;
+ }
+ else
+ {
+ bitmap[y*(size.X*2)+x] = false;
+ }
+ }
+ }
+ }
+};
+
+#endif /* ELIPSEBRUSH_H_ */
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 90ef70c..277c32c 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -226,6 +226,10 @@ void GameController::Vote(int direction)
//TODO: Implement
}
+void GameController::ChangeBrush()
+{
+ gameModel->SetBrush(gameModel->GetBrushID()+1);
+}
void GameController::ClearSim()
{
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 28edd86..2ec4523 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -47,6 +47,7 @@ public:
void ClearSim();
void ReloadSim();
void Vote(int direction);
+ void ChangeBrush();
};
#endif // GAMECONTROLLER_H
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 3085b09..5dfc521 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -5,13 +5,14 @@
#include "Renderer.h"
#include "interface/Point.h"
#include "Brush.h"
+#include "EllipseBrush.h"
GameModel::GameModel():
activeTool(NULL),
sim(NULL),
ren(NULL),
currentSave(NULL),
- currentBrush(new Brush(ui::Point(4, 4))),
+ currentBrush(0),
currentUser(0, "")
{
sim = new Simulation();
@@ -39,6 +40,9 @@ GameModel::GameModel():
//sim->wtypes[i]
}
+ brushList.push_back(new Brush(ui::Point(4, 4)));
+ brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
+
activeTool = new ElementTool(1, "TURD", 0, 0, 0);
}
@@ -52,6 +56,10 @@ GameModel::~GameModel()
}
delete menuList[i];
}
+ for(int i = 0; i < brushList.size(); i++)
+ {
+ delete brushList[i];
+ }
delete sim;
delete ren;
if(activeTool)
@@ -60,9 +68,20 @@ GameModel::~GameModel()
Brush * GameModel::GetBrush()
{
+ return brushList[currentBrush];
+}
+
+int GameModel::GetBrushID()
+{
return currentBrush;
}
+void GameModel::SetBrush(int i)
+{
+ currentBrush = i%brushList.size();
+ notifyBrushChanged();
+}
+
void GameModel::AddObserver(GameView * observer){
observers.push_back(observer);
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index b8f5217..72e2875 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -25,7 +25,8 @@ private:
vector<Tool*> toolList;
vector<Menu*> menuList;
Menu * activeMenu;
- Brush * currentBrush;
+ int currentBrush;
+ vector<Brush *> brushList;
Save * currentSave;
Simulation * sim;
Renderer * ren;
@@ -43,6 +44,7 @@ private:
public:
GameModel();
~GameModel();
+
Save * GetSave();
Brush * GetBrush();
void SetSave(Save * newSave);
@@ -58,6 +60,8 @@ public:
Menu * GetActiveMenu();
User GetUser();
void SetUser(User user);
+ void SetBrush(int i);
+ int GetBrushID();
Simulation * GetSimulation();
Renderer * GetRenderer();
};
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 163c2f7..ec87f64 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -3,6 +3,7 @@
#include "interface/Window.h"
#include "interface/Button.h"
#include "interface/Colour.h"
+#include "interface/Keys.h"
GameView::GameView():
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
@@ -399,9 +400,12 @@ void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
{
switch(key)
{
- case ' ':
+ case ' ': //Space
c->SetPaused();
break;
+ case KEY_TAB: //Tab
+ c->ChangeBrush();
+ break;
}
}
diff --git a/src/interface/Keys.h b/src/interface/Keys.h
index e923703..22fffa2 100644
--- a/src/interface/Keys.h
+++ b/src/interface/Keys.h
@@ -6,3 +6,4 @@
#define KEY_END SDLK_END
#define KEY_BACKSPACE SDLK_BACKSPACE
#define KEY_DELETE SDLK_DELETE
+#define KEY_TAB SDLK_TAB