summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-10 17:59:05 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-10 17:59:05 (GMT)
commit3499cb3035e64ed91adfbabdfa9b979e9f8e0885 (patch)
tree1036f4f2fab5301981457a07a8a39df5021fe727 /src
parentcd051924d9ca6d5c39e02111bc311fda9126435e (diff)
downloadpowder-3499cb3035e64ed91adfbabdfa9b979e9f8e0885.zip
powder-3499cb3035e64ed91adfbabdfa9b979e9f8e0885.tar.gz
Wall brush, fixes #63
Diffstat (limited to 'src')
-rw-r--r--src/game/GameController.cpp5
-rw-r--r--src/game/GameModel.cpp25
-rw-r--r--src/game/GameModel.h5
-rw-r--r--src/game/GameView.cpp44
-rw-r--r--src/game/GameView.h2
-rw-r--r--src/game/Tool.cpp4
-rw-r--r--src/game/Tool.h2
-rw-r--r--src/simulation/Simulation.cpp8
8 files changed, 84 insertions, 11 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 9636c8f..02dd4df 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -276,6 +276,7 @@ void GameController::DrawRect(int toolSelection, ui::Point point1, ui::Point poi
{
Simulation * sim = gameModel->GetSimulation();
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
+ gameModel->SetLastTool(activeTool);
Brush * cBrush = gameModel->GetBrush();
if(!activeTool || !cBrush)
return;
@@ -287,6 +288,7 @@ void GameController::DrawLine(int toolSelection, ui::Point point1, ui::Point poi
{
Simulation * sim = gameModel->GetSimulation();
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
+ gameModel->SetLastTool(activeTool);
Brush * cBrush = gameModel->GetBrush();
if(!activeTool || !cBrush)
return;
@@ -298,6 +300,7 @@ void GameController::DrawFill(int toolSelection, ui::Point point)
{
Simulation * sim = gameModel->GetSimulation();
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
+ gameModel->SetLastTool(activeTool);
Brush * cBrush = gameModel->GetBrush();
if(!activeTool || !cBrush)
return;
@@ -309,6 +312,7 @@ void GameController::DrawPoints(int toolSelection, queue<ui::Point*> & pointQueu
{
Simulation * sim = gameModel->GetSimulation();
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
+ gameModel->SetLastTool(activeTool);
Brush * cBrush = gameModel->GetBrush();
if(!activeTool || !cBrush)
{
@@ -701,6 +705,7 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool)
{
gameModel->SetActiveTool(toolSelection, tool);
gameModel->GetRenderer()->gravityZonesEnabled = false;
+ gameModel->SetLastTool(tool);
for(int i = 0; i < 3; i++)
{
if(gameModel->GetActiveTool(i) == gameModel->GetMenuList().at(SC_WALL)->GetToolList().at(WL_GRAV))
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 3da3074..e88a1aa 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -239,6 +239,7 @@ void GameModel::BuildMenus()
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
activeTools[1] = menuList[SC_SPECIAL]->GetToolList()[0];
activeTools[2] = NULL;
+ lastTool = activeTools[0];
//Set default menu
activeMenu = menuList[SC_POWDERS];
@@ -247,6 +248,7 @@ void GameModel::BuildMenus()
notifyMenuListChanged();
notifyToolListChanged();
notifyActiveToolsChanged();
+ notifyLastToolChanged();
}
void GameModel::SetVote(int direction)
@@ -293,6 +295,7 @@ void GameModel::AddObserver(GameView * observer){
observer->NotifyColourSelectorVisibilityChanged(this);
observer->NotifyColourSelectorColourChanged(this);
observer->NotifyQuickOptionsChanged(this);
+ observer->NotifyLastToolChanged(this);
UpdateQuickOptions();
}
@@ -429,6 +432,20 @@ User GameModel::GetUser()
return currentUser;
}
+Tool * GameModel::GetLastTool()
+{
+ return lastTool;
+}
+
+void GameModel::SetLastTool(Tool * newTool)
+{
+ if(lastTool != newTool)
+ {
+ lastTool = newTool;
+ notifyLastToolChanged();
+ }
+}
+
void GameModel::SetZoomEnabled(bool enabled)
{
ren->zoomEnabled = enabled;
@@ -823,3 +840,11 @@ void GameModel::notifyQuickOptionsChanged()
observers[i]->NotifyQuickOptionsChanged(this);
}
}
+
+void GameModel::notifyLastToolChanged()
+{
+ for(int i = 0; i < observers.size(); i++)
+ {
+ observers[i]->NotifyLastToolChanged(this);
+ }
+}
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index 47a6904..33cf119 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -51,6 +51,7 @@ private:
SaveInfo * currentSave;
Simulation * sim;
Renderer * ren;
+ Tool * lastTool;
Tool * activeTools[3];
User currentUser;
bool colourSelector;
@@ -80,6 +81,7 @@ private:
void notifyInfoTipChanged();
void notifyToolTipChanged();
void notifyQuickOptionsChanged();
+ void notifyLastToolChanged();
public:
GameModel();
~GameModel();
@@ -103,6 +105,9 @@ public:
void SetToolStrength(float value);
float GetToolStrength();
+ Tool * GetLastTool();
+ void SetLastTool(Tool * newTool);
+
void SetVote(int direction);
SaveInfo * GetSave();
Brush * GetBrush();
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 85d0e8d..073d8da 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -174,7 +174,8 @@ GameView::GameView():
showHud(true),
showDebug(false),
introText(2048),
- introTextMessage(introTextData)
+ introTextMessage(introTextData),
+ wallBrush(false)
{
int currentX = 1;
@@ -642,6 +643,18 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender)
}
}
+void GameView::NotifyLastToolChanged(GameModel * sender)
+{
+ if(sender->GetLastTool()->GetResolution() == CELL)
+ {
+ wallBrush = true;
+ }
+ else
+ {
+ wallBrush = false;
+ }
+}
+
void GameView::NotifyToolListChanged(GameModel * sender)
{
//int currentY = YRES+MENUSIZE-36;
@@ -1637,22 +1650,29 @@ void GameView::OnDraw()
if(selectMode == SelectNone && activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
{
ui::Point finalCurrentMouse = c->PointTranslate(currentMouse);
+ ui::Point initialDrawPoint = drawPoint1;
+
+ if(wallBrush)
+ {
+ finalCurrentMouse = c->NormaliseBlockCoord(finalCurrentMouse);
+ initialDrawPoint = c->NormaliseBlockCoord(initialDrawPoint);
+ }
if(drawMode==DrawRect && isMouseDown)
{
if(drawSnap)
{
- finalCurrentMouse = rectSnapCoords(c->PointTranslate(drawPoint1), finalCurrentMouse);
+ finalCurrentMouse = rectSnapCoords(c->PointTranslate(initialDrawPoint), finalCurrentMouse);
}
- activeBrush->RenderRect(ren, c->PointTranslate(drawPoint1), finalCurrentMouse);
+ activeBrush->RenderRect(ren, c->PointTranslate(initialDrawPoint), finalCurrentMouse);
}
else if(drawMode==DrawLine && isMouseDown)
{
if(drawSnap)
{
- finalCurrentMouse = lineSnapCoords(c->PointTranslate(drawPoint1), finalCurrentMouse);
+ finalCurrentMouse = lineSnapCoords(c->PointTranslate(initialDrawPoint), finalCurrentMouse);
}
- activeBrush->RenderLine(ren, c->PointTranslate(drawPoint1), finalCurrentMouse);
+ activeBrush->RenderLine(ren, c->PointTranslate(initialDrawPoint), finalCurrentMouse);
}
else if(drawMode==DrawFill)
{
@@ -1660,7 +1680,19 @@ void GameView::OnDraw()
}
else
{
- activeBrush->RenderPoint(ren, finalCurrentMouse);
+ if(wallBrush)
+ {
+ ui::Point finalBrushRadius = c->NormaliseBlockCoord(activeBrush->GetRadius());
+ ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y-finalBrushRadius.Y, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y-finalBrushRadius.Y);
+ ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-1, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-1);
+
+ ren->xor_line(finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y-finalBrushRadius.Y+1, finalCurrentMouse.X-finalBrushRadius.X, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-2);
+ ren->xor_line(finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y-finalBrushRadius.Y+1, finalCurrentMouse.X+finalBrushRadius.X+CELL-1, finalCurrentMouse.Y+finalBrushRadius.Y+CELL-2);
+ }
+ else
+ {
+ activeBrush->RenderPoint(ren, finalCurrentMouse);
+ }
}
}
ren->RenderEnd();
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 4d1683a..efb4895 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -43,6 +43,7 @@ private:
bool altBehaviour;
bool showHud;
bool showDebug;
+ bool wallBrush;
int introText;
std::string introTextMessage;
int toolIndex;
@@ -144,6 +145,7 @@ public:
void NotifyToolTipChanged(GameModel * sender);
void NotifyInfoTipChanged(GameModel * sender);
void NotifyQuickOptionsChanged(GameModel * sender);
+ void NotifyLastToolChanged(GameModel * sender);
void ExitPrompt();
diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp
index a93afaf..ad98712 100644
--- a/src/game/Tool.cpp
+++ b/src/game/Tool.cpp
@@ -20,7 +20,8 @@ Tool::Tool(int id, string name, string description, int r, int g, int b, VideoBu
colGreen(g),
colBlue(b),
textureGen(textureGen),
- strength(1.0f)
+ strength(1.0f),
+ resolution(1)
{
}
VideoBuffer * Tool::GetTexture(int width, int height)
@@ -72,6 +73,7 @@ void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position)
WallTool::WallTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int)):
Tool(id, name, description, r, g, b, textureGen)
{
+ resolution = CELL;
}
WallTool::~WallTool() {}
void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
diff --git a/src/game/Tool.h b/src/game/Tool.h
index c4f44bb..d4181a7 100644
--- a/src/game/Tool.h
+++ b/src/game/Tool.h
@@ -26,10 +26,12 @@ protected:
string toolName;
string toolDescription;
float strength;
+ int resolution;
public:
Tool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL);
string GetName();
string GetDescription();
+ int GetResolution() { return resolution; }
void SetStrength(float value) { strength = value; }
float GetStrength() { return strength; }
VideoBuffer * GetTexture(int width, int height);
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index c11bde0..f70560a 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -1250,11 +1250,11 @@ int Simulation::CreateWalls(int x, int y, int rx, int ry, int c, int flags, Brus
rx = rx/CELL;
x = x/CELL;
y = y/CELL;
- x -= rx/2;
- y -= ry/2;
- for (ox=x; ox<=x+rx; ox++)
+ x -= rx;///2;
+ y -= ry;///2;
+ for (ox=x; ox<=x+rx+rx; ox++)
{
- for (oy=y; oy<=y+rx; oy++)
+ for (oy=y; oy<=y+ry+ry; oy++)
{
if (ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL)
{