Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The stack tool can delete stacks now. #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/gui/game/GameController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c
case SDL_SCANCODE_S:
if (shift)
{
SetActiveTool(0, "DEFAULT_UI_STACK");
ToggleStackTool();
break;
}
gameView->BeginStampSelection();
Expand Down Expand Up @@ -1231,6 +1231,14 @@ void GameController::ToggleConfigTool()
SetActiveTool(0, "DEFAULT_UI_CONFIG");
}

void GameController::ToggleStackTool()
{
if (GetActiveTool(0)->GetIdentifier() == "DEFAULT_UI_STACK")
SetActiveMenu(gameModel->GetActiveMenu());
else
SetActiveTool(0, "DEFAULT_UI_STACK");
}

int GameController::GetStackEditDepth()
{
return gameModel->GetSimulation()->stackEditDepth;
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameController.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class GameController: public ClientListener
int GetParticleDebugPosition();
ConfigTool * GetActiveConfigTool();
void ToggleConfigTool();
void ToggleStackTool();
int GetStackEditDepth();
void SetStackEditDepth(int depth);
void AdjustStackEditDepth(int ddepth);
Expand Down
11 changes: 10 additions & 1 deletion src/gui/game/GameModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ void GameModel::BuildMenus()
configToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE");
configToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE");

StackTool *stackTool = (StackTool*)GetToolFromIdentifier("DEFAULT_UI_STACK");
stackTool->SetClearTool(GetToolFromIdentifier("DEFAULT_PT_NONE"));
stackToolToolset[0] = stackTool;
stackToolToolset[1] = &stackTool->deleteStackTool;
stackToolToolset[2] = GetToolFromIdentifier("DEFAULT_UI_SAMPLE");
stackToolToolset[3] = GetToolFromIdentifier("DEFAULT_PT_NONE");

regularToolset[0] = GetToolFromIdentifier(activeToolIdentifiers[0]);
regularToolset[1] = GetToolFromIdentifier(activeToolIdentifiers[1]);
regularToolset[2] = GetToolFromIdentifier(activeToolIdentifiers[2]);
Expand Down Expand Up @@ -943,7 +950,9 @@ void GameModel::SetActiveTool(int selection, Tool * tool)
sim->configToolSampleActive = false;
if (tool->GetIdentifier() == "DEFAULT_UI_CONFIG")
activeTools = configToolset;
else if (activeTools == configToolset)
else if (tool->GetIdentifier() == "DEFAULT_UI_STACK")
activeTools = stackToolToolset;
else if (activeTools != decoToolset)
activeTools = regularToolset;
activeTools[selection] = tool;
notifyActiveToolsChanged();
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/GameModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class GameModel
Tool * decoToolset[4];
Tool * regularToolset[4];
Tool * configToolset[4];
Tool * stackToolToolset[4];
User currentUser;
float toolStrength;
std::deque<HistoryEntry> history;
Expand Down
111 changes: 111 additions & 0 deletions src/gui/game/StackTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,114 @@ void StackTool::DrawRect(Simulation *sim, Brush *cBrush, ui::Point position, ui:
}
ProcessParts(sim, parts, position, position2);
}

void StackTool::DeleteStackTool::Draw(Simulation *sim, Brush *cBrush, ui::Point position)
{
if (cBrush)
{
int radiusX = cBrush->GetRadius().X, radiusY = cBrush->GetRadius().Y, sizeX = cBrush->GetSize().X, sizeY = cBrush->GetSize().Y;
unsigned char *bitmap = cBrush->GetBitmap();
for (int i=0; i<=sim->parts_lastActiveIndex; i++)
{
if (sim->parts[i].type)
{
int partx = (int)(sim->parts[i].x+0.5f);
int party = (int)(sim->parts[i].y+0.5f);
int partbmpx = partx - position.X + radiusX;
int partbmpy = party - position.Y + radiusY;
if (partbmpx >= 0 && partbmpx < sizeX && partbmpy >= 0 && partbmpy < sizeY && bitmap[partbmpy * sizeX + partbmpx])
sim->kill_part(i);
}
}
}
}

void StackTool::DeleteStackTool::DrawLine(Simulation *sim, Brush *cBrush, ui::Point position, ui::Point position2, bool dragging)
{
int x1 = position.X, y1 = position.Y, x2 = position2.X, y2 = position2.Y;
bool reverseXY = abs(y2-y1) > abs(x2-x1);
int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y;
float e = 0.0f, de;
if (reverseXY)
{
y = x1;
x1 = y1;
y1 = y;
y = x2;
x2 = y2;
y2 = y;
}
if (x1 > x2)
{
y = x1;
x1 = x2;
x2 = y;
y = y1;
y1 = y2;
y2 = y;
}
dx = x2 - x1;
dy = abs(y2 - y1);
if (dx)
de = dy/(float)dx;
else
de = 0.0f;
y = y1;
sy = (y1<y2) ? 1 : -1;
for (x=x1; x<=x2; x++)
{
if (reverseXY)
Draw(sim, cBrush, ui::Point(y, x));
else
Draw(sim, cBrush, ui::Point(x, y));
e += de;
if (e >= 0.5f)
{
y += sy;
if (!(rx+ry) && ((y1<y2) ? (y<=y2) : (y>=y2)))
{
if (reverseXY)
Draw(sim, cBrush, ui::Point(y, x));
else
Draw(sim, cBrush, ui::Point(x, y));
}
e -= 1.0f;
}
}
}

void StackTool::DeleteStackTool::DrawRect(Simulation *sim, Brush *cBrush, ui::Point position, ui::Point position2)
{
int x1 = position.X, y1 = position.Y, x2 = position2.X, y2 = position2.Y;
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (int i=0; i<=sim->parts_lastActiveIndex; i++)
{
if (sim->parts[i].type)
{
int partx = (int)(sim->parts[i].x+0.5f);
int party = (int)(sim->parts[i].y+0.5f);
if (partx >= x1 && partx <= x2 && party >= y1 && party <= y2)
sim->kill_part(i);
}
}
}

void StackTool::DeleteStackTool::DrawFill(Simulation * sim, Brush * cbrush, ui::Point position)
{
// create a heatmap of particles. Index is: Y*XRES + X
clearTool->DrawFill(sim, cbrush, position);
// re-implement flood fill and kill stacks that it encounters.

}
25 changes: 24 additions & 1 deletion src/gui/game/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,36 @@ class SampleTool: public Tool

class StackTool: public Tool
{
class DeleteStackTool : public Tool
{
StackTool * stackTool;
Tool * clearTool;
public:
DeleteStackTool(StackTool *stackTool_):
Tool(0, "", "", 0, 0, 0, "DEFAULT_UI_STACK_DELETE", NULL),
stackTool(stackTool_),
clearTool(NULL)
{
}
virtual ~DeleteStackTool() {}
void SetClearTool(Tool *clearTool_) { clearTool = clearTool_; }
virtual void Click(Simulation * sim, Brush * brush, ui::Point position){ }
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2);
virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position);
};

GameModel * gameModel;
public:
DeleteStackTool deleteStackTool;
StackTool(GameModel *model):
Tool(0, "STCK", "Stack or unstack particles.", 0xff, 0xff, 0, "DEFAULT_UI_STACK", NULL),
gameModel(model)
gameModel(model),
deleteStackTool(DeleteStackTool(this))
{
}
void SetClearTool(Tool *clearTool) { deleteStackTool.SetClearTool(clearTool); }
virtual ~StackTool() {}
void ProcessParts(Simulation * sim, std::vector<int> &parts, ui::Point position, ui::Point position2);
virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { }
Expand Down