Brush class for drawing on simulation, more interface for game

This commit is contained in:
Simon Robertshaw 2012-01-22 14:45:37 +00:00
parent 91bb5a8b78
commit 19c1fa5dcb
11 changed files with 335 additions and 141 deletions

65
src/game/Brush.h Normal file
View File

@ -0,0 +1,65 @@
/*
* Brush.h
*
* Created on: Jan 22, 2012
* Author: Simon
*/
#ifndef BRUSH_H_
#define BRUSH_H_
#include "interface/Point.h"
class Brush
{
bool * bitmap;
ui::Point size;
public:
Brush(ui::Point size_):
bitmap(NULL),
size(size_)
{
};
ui::Point GetRadius()
{
return size;
}
void SetRadius(ui::Point size)
{
this->size = size;
GenerateBitmap();
}
virtual ~Brush() {
if(bitmap)
delete bitmap;
}
//Draw the brush outline onto the screen
virtual void Render(Graphics * g, ui::Point position)
{
g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
}
virtual void GenerateBitmap()
{
if(bitmap)
free(bitmap);
bitmap = (bool *)malloc(sizeof(bool)*(((size.X*2)+1)*((size.Y*2)+1)));
for(int x = 0; x <= size.X*2; x++)
{
for(int y = 0; y <= size.Y*2; y++)
{
bitmap[y*(size.X*2)+x] = true;
}
}
}
//Get a bitmap for drawing particles
bool * GetBitmap()
{
if(!bitmap)
GenerateBitmap();
return bitmap;
}
};
#endif /* BRUSH_H_ */

View File

@ -37,10 +37,21 @@ GameView * GameController::GetView()
return gameView; return gameView;
} }
void GameController::AdjustBrushSize(int direction)
{
ui::Point newSize = gameModel->GetBrush()->GetRadius() + ui::Point(direction, direction);
if(newSize.X<0)
newSize.X = 0;
if(newSize.Y<0)
newSize.Y = 0;
gameModel->GetBrush()->SetRadius(newSize);
}
void GameController::DrawPoints(queue<ui::Point*> & pointQueue) void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
{ {
Simulation * sim = gameModel->GetSimulation(); Simulation * sim = gameModel->GetSimulation();
int activeElement = gameModel->GetActiveElement(); int activeElement = gameModel->GetActiveElement();
Brush * cBrush = gameModel->GetBrush();
if(!pointQueue.empty()) if(!pointQueue.empty())
{ {
ui::Point * sPoint = NULL; ui::Point * sPoint = NULL;
@ -50,12 +61,12 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
pointQueue.pop(); pointQueue.pop();
if(sPoint) if(sPoint)
{ {
sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0); sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0, cBrush);
delete sPoint; delete sPoint;
} }
else else
{ {
sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0); sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0, cBrush);
} }
sPoint = fPoint; sPoint = fPoint;
} }
@ -79,3 +90,46 @@ void GameController::OpenSearch()
search = new SearchController(); search = new SearchController();
ui::Engine::Ref().ShowWindow(search->GetView()); ui::Engine::Ref().ShowWindow(search->GetView());
} }
void GameController::OpenLogin()
{
//TODO: Implement
}
void GameController::OpenTags()
{
//TODO: Implement
}
void GameController::OpenDisplayOptions()
{
//TODO: Implement
}
void GameController::OpenRenderOptions()
{
//TODO: Implement
}
void GameController::OpenSaveWindow()
{
//TODO: Implement
}
void GameController::Vote(int direction)
{
//TODO: Implement
}
void GameController::ClearSim()
{
gameModel->ClearSimulation();
}
void GameController::ReloadSim()
{
//TODO: Implement
}

View File

@ -23,10 +23,19 @@ public:
GameController(); GameController();
~GameController(); ~GameController();
GameView * GetView(); GameView * GetView();
void AdjustBrushSize(int direction);
void DrawPoints(queue<ui::Point*> & pointQueue); void DrawPoints(queue<ui::Point*> & pointQueue);
void Tick(); void Tick();
void SetPaused(bool pauseState); void SetPaused(bool pauseState);
void OpenSearch(); void OpenSearch();
void OpenLogin();
void OpenTags();
void OpenDisplayOptions();
void OpenRenderOptions();
void OpenSaveWindow();
void ClearSim();
void ReloadSim();
void Vote(int direction);
}; };
#endif // GAMECONTROLLER_H #endif // GAMECONTROLLER_H

View File

@ -3,11 +3,15 @@
#include "GameView.h" #include "GameView.h"
#include "simulation/Simulation.h" #include "simulation/Simulation.h"
#include "Renderer.h" #include "Renderer.h"
#include "interface/Point.h"
#include "Brush.h"
GameModel::GameModel(): GameModel::GameModel():
activeElement(1), activeElement(1),
sim(NULL), sim(NULL),
ren(NULL) ren(NULL),
currentSave(NULL),
currentBrush(new Brush(ui::Point(4, 4)))
{ {
sim = new Simulation(); sim = new Simulation();
ren = new Renderer(ui::Engine::Ref().g, sim); ren = new Renderer(ui::Engine::Ref().g, sim);
@ -19,12 +23,19 @@ GameModel::~GameModel()
delete ren; delete ren;
} }
Brush * GameModel::GetBrush()
{
return currentBrush;
}
void GameModel::AddObserver(GameView * observer){ void GameModel::AddObserver(GameView * observer){
observers.push_back(observer); observers.push_back(observer);
observer->NotifySimulationChanged(this); observer->NotifySimulationChanged(this);
observer->NotifyRendererChanged(this); observer->NotifyRendererChanged(this);
observer->NotifyPausedChanged(this); observer->NotifyPausedChanged(this);
observer->NotifySaveChanged(this);
observer->NotifyBrushChanged(this);
} }
int GameModel::GetActiveElement() int GameModel::GetActiveElement()
@ -37,6 +48,16 @@ void GameModel::SetActiveElement(int element)
activeElement = element; activeElement = element;
} }
Save * GameModel::GetSave()
{
return currentSave;
}
void GameModel::SetSave(Save * newSave)
{
currentSave = newSave;
notifySaveChanged();
}
Simulation * GameModel::GetSimulation() Simulation * GameModel::GetSimulation()
{ {
return sim; return sim;
@ -58,6 +79,11 @@ bool GameModel::GetPaused()
return sim->sys_pause?true:false; return sim->sys_pause?true:false;
} }
void GameModel::ClearSimulation()
{
sim->clear_sim();
}
void GameModel::notifyRendererChanged() void GameModel::notifyRendererChanged()
{ {
for(int i = 0; i < observers.size(); i++) for(int i = 0; i < observers.size(); i++)
@ -66,6 +92,14 @@ void GameModel::notifyRendererChanged()
} }
} }
void GameModel::notifySaveChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifySaveChanged(this);
}
}
void GameModel::notifySimulationChanged() void GameModel::notifySimulationChanged()
{ {
for(int i = 0; i < observers.size(); i++) for(int i = 0; i < observers.size(); i++)
@ -81,3 +115,11 @@ void GameModel::notifyPausedChanged()
observers[i]->NotifyPausedChanged(this); observers[i]->NotifyPausedChanged(this);
} }
} }
void GameModel::notifyBrushChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyBrushChanged(this);
}
}

View File

@ -2,9 +2,11 @@
#define GAMEMODEL_H #define GAMEMODEL_H
#include <vector> #include <vector>
#include "search/Save.h"
#include "simulation/Simulation.h" #include "simulation/Simulation.h"
#include "Renderer.h" #include "Renderer.h"
#include "GameView.h" #include "GameView.h"
#include "Brush.h"
using namespace std; using namespace std;
@ -16,20 +18,28 @@ class GameModel
{ {
private: private:
vector<GameView*> observers; vector<GameView*> observers;
Brush * currentBrush;
Save * currentSave;
Simulation * sim; Simulation * sim;
Renderer * ren; Renderer * ren;
int activeElement; int activeElement;
void notifyRendererChanged(); void notifyRendererChanged();
void notifySimulationChanged(); void notifySimulationChanged();
void notifyPausedChanged(); void notifyPausedChanged();
void notifySaveChanged();
void notifyBrushChanged();
public: public:
GameModel(); GameModel();
~GameModel(); ~GameModel();
Save * GetSave();
Brush * GetBrush();
void SetSave(Save * newSave);
void AddObserver(GameView * observer); void AddObserver(GameView * observer);
int GetActiveElement(); int GetActiveElement();
void SetActiveElement(int element); void SetActiveElement(int element);
bool GetPaused(); bool GetPaused();
void SetPaused(bool pauseState); void SetPaused(bool pauseState);
void ClearSimulation();
Simulation * GetSimulation(); Simulation * GetSimulation();
Renderer * GetRenderer(); Renderer * GetRenderer();

View File

@ -7,7 +7,8 @@ GameView::GameView():
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)), ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
pointQueue(queue<ui::Point*>()), pointQueue(queue<ui::Point*>()),
isMouseDown(false), isMouseDown(false),
ren(NULL) ren(NULL),
activeBrush(NULL)
{ {
int currentX = 1; int currentX = 1;
//Set up UI //Set up UI
@ -34,10 +35,10 @@ GameView::GameView():
ReloadAction(GameView * _v) { v = _v; } ReloadAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->OpenSearch(); // TODO call proper function v->c->ReloadSim();
} }
}; };
reloadButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\x91"); // TODO Position? reloadButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\x91");
currentX+=18; currentX+=18;
reloadButton->SetActionCallback(new ReloadAction(this)); reloadButton->SetActionCallback(new ReloadAction(this));
AddComponent(reloadButton); AddComponent(reloadButton);
@ -49,10 +50,10 @@ GameView::GameView():
SaveSimulationAction(GameView * _v) { v = _v; } SaveSimulationAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->OpenSearch(); // TODO call proper function v->c->OpenSaveWindow();
} }
}; };
saveSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X/5, 16), "\x82"); // TODO All arguments saveSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X/5, 16), "\x82");
currentX+=(Size.X/5)+2; currentX+=(Size.X/5)+2;
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this)); saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
AddComponent(saveSimulationButton); AddComponent(saveSimulationButton);
@ -64,10 +65,10 @@ GameView::GameView():
UpVoteAction(GameView * _v) { v = _v; } UpVoteAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->OpenSearch(); // TODO call proper function v->c->Vote(1);
} }
}; };
upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\xCB"); // TODO All arguments upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\xCB");
currentX+=16; currentX+=16;
upVoteButton->SetActionCallback(new UpVoteAction(this)); upVoteButton->SetActionCallback(new UpVoteAction(this));
AddComponent(upVoteButton); AddComponent(upVoteButton);
@ -79,10 +80,10 @@ GameView::GameView():
DownVoteAction(GameView * _v) { v = _v; } DownVoteAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->OpenSearch(); // TODO call proper function v->c->Vote(-1);
} }
}; };
downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\xCA"); // TODO All arguments downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(16, 16), "\xCA");
currentX+=18; currentX+=18;
downVoteButton->SetActionCallback(new DownVoteAction(this)); downVoteButton->SetActionCallback(new DownVoteAction(this));
AddComponent(downVoteButton); AddComponent(downVoteButton);
@ -94,10 +95,10 @@ GameView::GameView():
TagSimulationAction(GameView * _v) { v = _v; } TagSimulationAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->OpenSearch(); // TODO call proper function v->c->OpenTags();
} }
}; };
tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X-(currentX+176), 16), "\x83"); // TODO All arguments tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-18), ui::Point(Size.X-(currentX+176), 16), "\x83");
currentX+=Size.X-(currentX+176); currentX+=Size.X-(currentX+176);
tagSimulationButton->SetActionCallback(new TagSimulationAction(this)); tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
AddComponent(tagSimulationButton); AddComponent(tagSimulationButton);
@ -109,10 +110,10 @@ GameView::GameView():
ClearSimAction(GameView * _v) { v = _v; } ClearSimAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->SetPaused(sender->GetToggleState()); // TODO call proper function v->c->ClearSim();
} }
}; };
clearSimButton = new ui::Button(ui::Point(Size.X-174, Size.Y-18), ui::Point(16, 16), "C"); // TODO All arguments clearSimButton = new ui::Button(ui::Point(Size.X-174, Size.Y-18), ui::Point(16, 16), "C");
clearSimButton->SetActionCallback(new ClearSimAction(this)); clearSimButton->SetActionCallback(new ClearSimAction(this));
AddComponent(clearSimButton); AddComponent(clearSimButton);
@ -123,10 +124,10 @@ GameView::GameView():
LoginAction(GameView * _v) { v = _v; } LoginAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->SetPaused(sender->GetToggleState()); // TODO call proper function v->c->OpenLogin();
} }
}; };
loginButton = new ui::Button(ui::Point(Size.X-156, Size.Y-18), ui::Point(100, 16), "\xDA Login"); // TODO All arguments loginButton = new ui::Button(ui::Point(Size.X-156, Size.Y-18), ui::Point(100, 16), "\xDA Login");
loginButton->SetActionCallback(new LoginAction(this)); loginButton->SetActionCallback(new LoginAction(this));
AddComponent(loginButton); AddComponent(loginButton);
@ -137,10 +138,10 @@ GameView::GameView():
SimulationOptionAction(GameView * _v) { v = _v; } SimulationOptionAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->SetPaused(sender->GetToggleState()); // TODO call proper function v->c->OpenDisplayOptions();
} }
}; };
simulationOptionButton = new ui::Button(ui::Point(Size.X-54, Size.Y-18), ui::Point(16, 16), "\xDA"); // TODO All arguments simulationOptionButton = new ui::Button(ui::Point(Size.X-54, Size.Y-18), ui::Point(16, 16), "\xDA");
simulationOptionButton->SetActionCallback(new SimulationOptionAction(this)); simulationOptionButton->SetActionCallback(new SimulationOptionAction(this));
AddComponent(simulationOptionButton); AddComponent(simulationOptionButton);
@ -151,10 +152,10 @@ GameView::GameView():
DisplayModeAction(GameView * _v) { v = _v; } DisplayModeAction(GameView * _v) { v = _v; }
void ActionCallback(ui::Button * sender) void ActionCallback(ui::Button * sender)
{ {
v->c->SetPaused(sender->GetToggleState()); // TODO call proper function v->c->OpenRenderOptions();
} }
}; };
displayModeButton = new ui::Button(ui::Point(Size.X-36, Size.Y-18), ui::Point(16, 16), "\xDA"); // TODO All arguments displayModeButton = new ui::Button(ui::Point(Size.X-36, Size.Y-18), ui::Point(16, 16), "\xDA");
displayModeButton->SetActionCallback(new DisplayModeAction(this)); displayModeButton->SetActionCallback(new DisplayModeAction(this));
AddComponent(displayModeButton); AddComponent(displayModeButton);
@ -189,6 +190,38 @@ void GameView::NotifyPausedChanged(GameModel * sender)
pauseButton->SetToggleState(sender->GetPaused()); pauseButton->SetToggleState(sender->GetPaused());
} }
void GameView::NotifySaveChanged(GameModel * sender)
{
if(sender->GetSave())
{
reloadButton->Enabled = true;
if(sender->GetSave()->GetID()) //Online saves have an ID, local saves have an ID of 0 and a filename
{
upVoteButton->Enabled = true;
downVoteButton->Enabled = true;
tagSimulationButton->Enabled = true;
}
else
{
upVoteButton->Enabled = false;
downVoteButton->Enabled = false;
tagSimulationButton->Enabled = false;
}
}
else
{
reloadButton->Enabled = false;
upVoteButton->Enabled = false;
downVoteButton->Enabled = false;
tagSimulationButton->Enabled = false;
}
}
void GameView::NotifyBrushChanged(GameModel * sender)
{
activeBrush = sender->GetBrush();
}
void GameView::OnMouseMove(int x, int y, int dx, int dy) void GameView::OnMouseMove(int x, int y, int dx, int dy)
{ {
if(isMouseDown) if(isMouseDown)
@ -213,6 +246,17 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
} }
} }
void GameView::OnMouseWheel(int x, int y, int d)
{
if(!d)
return;
c->AdjustBrushSize(d);
if(isMouseDown)
{
pointQueue.push(new ui::Point(x, y));
}
}
void GameView::OnTick(float dt) void GameView::OnTick(float dt)
{ {
if(!pointQueue.empty()) if(!pointQueue.empty())
@ -228,4 +272,8 @@ void GameView::OnDraw()
{ {
ren->render_parts(); ren->render_parts();
} }
if(activeBrush)
{
activeBrush->Render(ui::Engine::Ref().g, ui::Point(ui::Engine::Ref().GetMouseX(),ui::Engine::Ref().GetMouseY()));
}
} }

View File

@ -7,6 +7,7 @@
#include "interface/Window.h" #include "interface/Window.h"
#include "interface/Point.h" #include "interface/Point.h"
#include "interface/Button.h" #include "interface/Button.h"
#include "Brush.h"
using namespace std; using namespace std;
@ -19,6 +20,7 @@ private:
queue<ui::Point*> pointQueue; queue<ui::Point*> pointQueue;
GameController * c; GameController * c;
Renderer * ren; Renderer * ren;
Brush * activeBrush;
//UI Elements //UI Elements
ui::Button * searchButton; ui::Button * searchButton;
ui::Button * reloadButton; ui::Button * reloadButton;
@ -37,10 +39,12 @@ public:
void NotifyRendererChanged(GameModel * sender); void NotifyRendererChanged(GameModel * sender);
void NotifySimulationChanged(GameModel * sender); void NotifySimulationChanged(GameModel * sender);
void NotifyPausedChanged(GameModel * sender); void NotifyPausedChanged(GameModel * sender);
void NotifySaveChanged(GameModel * sender);
void NotifyBrushChanged(GameModel * sender);
virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseMove(int x, int y, int dx, int dy);
virtual void OnMouseDown(int x, int y, unsigned button); virtual void OnMouseDown(int x, int y, unsigned button);
virtual void OnMouseUp(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button);
//virtual void OnMouseWheel(int x, int y, int d) {} virtual void OnMouseWheel(int x, int y, int d);
//virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {} //virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {}
//virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {} //virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {}
virtual void OnTick(float dt); virtual void OnTick(float dt);

View File

@ -25,7 +25,8 @@ Button::Button(Window* parent_state, std::string buttonText):
actionCallback(NULL), actionCallback(NULL),
textPosition(ui::Point(0, 0)), textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle), textVAlign(AlignMiddle),
textHAlign(AlignCentre) textHAlign(AlignCentre),
Enabled(true)
{ {
TextPosition(); TextPosition();
} }
@ -40,7 +41,8 @@ Button::Button(Point position, Point size, std::string buttonText):
actionCallback(NULL), actionCallback(NULL),
textPosition(ui::Point(0, 0)), textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle), textVAlign(AlignMiddle),
textHAlign(AlignCentre) textHAlign(AlignCentre),
Enabled(true)
{ {
TextPosition(); TextPosition();
} }
@ -55,7 +57,8 @@ Button::Button(std::string buttonText):
actionCallback(NULL), actionCallback(NULL),
textPosition(ui::Point(0, 0)), textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle), textVAlign(AlignMiddle),
textHAlign(AlignCentre) textHAlign(AlignCentre),
Enabled(true)
{ {
TextPosition(); TextPosition();
} }
@ -121,6 +124,8 @@ void Button::Draw(const Point& screenPos)
{ {
Graphics * g = ui::Engine::Ref().g; Graphics * g = ui::Engine::Ref().g;
Point Position = screenPos; Point Position = screenPos;
if(Enabled)
{
if(isButtonDown || (isTogglable && toggle)) if(isButtonDown || (isTogglable && toggle))
{ {
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255); g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255);
@ -134,6 +139,12 @@ void Button::Draw(const Point& screenPos)
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255); g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
} }
} }
else
{
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 180, 180, 180, 255);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 180, 180, 180, 255);
}
}
void Button::OnMouseUnclick(int x, int y, unsigned int button) void Button::OnMouseUnclick(int x, int y, unsigned int button)
{ {
@ -179,9 +190,8 @@ void Button::OnMouseLeave(int x, int y)
void Button::DoAction() void Button::DoAction()
{ {
std::cout << "Do action!"<<std::endl; if(!Enabled)
//if(actionCallback) return;
// (*(actionCallback))();
if(actionCallback) if(actionCallback)
actionCallback->ActionCallback(this); actionCallback->ActionCallback(this);
} }

View File

@ -33,6 +33,7 @@ public:
virtual ~Button(); virtual ~Button();
bool Toggleable; bool Toggleable;
bool Enabled;
std::string ButtonText; std::string ButtonText;

View File

@ -290,10 +290,16 @@ int Simulation::create_part_add_props(int p, int x, int y, int tv, int rx, int r
} }
//this creates particles from a brush, don't use if you want to create one particle //this creates particles from a brush, don't use if you want to create one particle
int Simulation::create_parts(int x, int y, int rx, int ry, int c, int flags) int Simulation::create_parts(int x, int y, int rx, int ry, int c, int flags, Brush * cBrush)
{ {
int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p;//n; int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p;//n;
if(cBrush)
{
rx = cBrush->GetRadius().X;
ry = cBrush->GetRadius().Y;
}
int wall = c - 100; int wall = c - 100;
if (c==SPC_WIND || c==PT_FIGH) if (c==SPC_WIND || c==PT_FIGH)
return 0; return 0;
@ -357,16 +363,6 @@ int Simulation::create_parts(int x, int y, int rx, int ry, int c, int flags)
{ {
i = ox; i = ox;
j = oy; j = oy;
/*if ((flags&BRUSH_SPECIFIC_DELETE) && b!=WL_FANHELPER)
{
if (bmap[j][i]==SLALT-100)
{
b = 0;
if (SLALT==WL_GRAV) gravwl_timeout = 60;
}
else
continue;
}*/
if (b==WL_FAN) if (b==WL_FAN)
{ {
fvx[j][i] = 0.0f; fvx[j][i] = 0.0f;
@ -394,132 +390,86 @@ int Simulation::create_parts(int x, int y, int rx, int ry, int c, int flags)
} }
//eraser //eraser
if (c == 0/* && !(flags&BRUSH_REPLACEMODE)*/) if (c == 0)
{ {
if (rx==0&&ry==0) if (rx==0&&ry==0)
{ {
delete_part(x, y, 0); delete_part(x, y, 0);
} }
else else if(cBrush)
{
bool *bitmap = cBrush->GetBitmap();
for (j=-ry; j<=ry; j++) for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
//if (InCurrentBrush(i ,j ,rx ,ry)) if(bitmap[(j+ry)*(rx*2)+(i+rx)])
delete_part(x+i, y+j, 0); delete_part(x+i, y+j, 0);
return 1;
}
//specific deletion
/*if ((flags&BRUSH_SPECIFIC_DELETE)&& !(flags&BRUSH_REPLACEMODE))
{
if (rx==0&&ry==0)
{
delete_part(x, y, flags);
} }
else else
{
for (j=-ry; j<=ry; j++) for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
if (InCurrentBrush(i ,j ,rx ,ry)) delete_part(x+i, y+j, 0);
delete_part(x+i, y+j, flags); }
return 1; return 1;
}*/ }
//why do these need a special if
if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV) if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV)
{ {
if (rx==0&&ry==0) if (rx==0&&ry==0)
{ {
create_part(-2, x, y, c); create_part(-2, x, y, c);
} }
else else if(cBrush)
{
bool *bitmap = cBrush->GetBitmap();
for (j=-ry; j<=ry; j++) for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
//if (InCurrentBrush(i ,j ,rx ,ry)) if(bitmap[(j+ry)*(rx*2)+(i+rx)])
{ {
if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
continue; continue;
//if (!REPLACE_MODE)
create_part(-2, x+i, y+j, c); create_part(-2, x+i, y+j, c);
/*else if ((pmap[y+j][x+i]&0xFF)==SLALT&&SLALT!=0)
create_part(-2, x+i, y+j, c);*/
}
return 1;
}
/*if (flags&BRUSH_REPLACEMODE)
{
if (rx==0&&ry==0)
{
if ((pmap[y][x]&0xFF)==SLALT || SLALT==0)
{
if ((pmap[y][x]))
{
delete_part(x, y, 0);
if (c!=0)
create_part_add_props(-2, x, y, c, rx, ry);
}
} }
} }
else else
{
for (j=-ry; j<=ry; j++) for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
if (InCurrentBrush(i ,j ,rx ,ry))
{ {
if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
continue; continue;
if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0) create_part(-2, x+i, y+j, c);
continue;
if ((pmap[y+j][x+i]))
{
delete_part(x+i, y+j, 0);
if (c!=0)
create_part_add_props(-2, x+i, y+j, c, rx, ry);
} }
} }
return 1; return 1;
}
}*/
//else, no special modes, draw element like normal. //else, no special modes, draw element like normal.
if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later. if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later.
{ {
if (create_part_add_props(-2, x, y, c, rx, ry)==-1) if (create_part_add_props(-2, x, y, c, rx, ry)==-1)
f = 1; f = 1;
} }
else else if(cBrush)
{
bool *bitmap = cBrush->GetBitmap();
for (j=-ry; j<=ry; j++) for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
//if (InCurrentBrush(i ,j ,rx ,ry)) if(bitmap[(j+ry)*(rx*2)+(i+rx)])
if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1) if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1)
f = 1; f = 1;
}
else
{
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++)
if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1)
f = 1;
}
return !f; return !f;
} }
/*int Simulation::InCurrentBrush(int i, int j, int rx, int ry)
{ void Simulation::create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags, Brush * cBrush)
switch(CURRENT_BRUSH)
{
case CIRCLE_BRUSH:
return (pow(i,2)*pow(ry,2)+pow(j,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2));
break;
case SQUARE_BRUSH:
return (i*j<=ry*rx);
break;
case TRI_BRUSH:
return (j <= ry ) && ( j >= (((-2.0*ry)/rx)*i) -ry) && ( j >= (((-2.0*ry)/(-rx))*i)-ry ) ;
break;
}
return 0;
}
int Simulation::get_brush_flags()
{
int flags = 0;
if (REPLACE_MODE)
flags |= BRUSH_REPLACEMODE;
if (sdl_mod & KMOD_CAPS)
flags |= BRUSH_SPECIFIC_DELETE;
if ((sdl_mod & KMOD_LALT) && (sdl_mod & (KMOD_CTRL)))
flags |= BRUSH_SPECIFIC_DELETE;
return flags;
}*/
void Simulation::create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags)
{ {
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
float e, de; float e, de;
@ -555,9 +505,9 @@ void Simulation::create_line(int x1, int y1, int x2, int y2, int rx, int ry, int
for (x=x1; x<=x2; x++) for (x=x1; x<=x2; x++)
{ {
if (cp) if (cp)
create_parts(y, x, rx, ry, c, flags); create_parts(y, x, rx, ry, c, flags, cBrush);
else else
create_parts(x, y, rx, ry, c, flags); create_parts(x, y, rx, ry, c, flags, cBrush);
e += de; e += de;
if (e >= 0.5f) if (e >= 0.5f)
{ {
@ -566,9 +516,9 @@ void Simulation::create_line(int x1, int y1, int x2, int y2, int rx, int ry, int
&& ((y1<y2) ? (y<=y2) : (y>=y2))) && ((y1<y2) ? (y<=y2) : (y>=y2)))
{ {
if (cp) if (cp)
create_parts(y, x, rx, ry, c, flags); create_parts(y, x, rx, ry, c, flags, cBrush);
else else
create_parts(x, y, rx, ry, c, flags); create_parts(x, y, rx, ry, c, flags, cBrush);
} }
e -= 1.0f; e -= 1.0f;
} }

View File

@ -13,6 +13,7 @@
#include "Graphics.h" #include "Graphics.h"
#include "Elements.h" #include "Elements.h"
#include "Misc.h" #include "Misc.h"
#include "game/Brush.h"
#define CHANNELS ((int)(MAX_TEMP-73)/100+2) #define CHANNELS ((int)(MAX_TEMP-73)/100+2)
@ -224,8 +225,8 @@ public:
void clear_area(int area_x, int area_y, int area_w, int area_h); void clear_area(int area_x, int area_y, int area_w, int area_h);
void create_box(int x1, int y1, int x2, int y2, int c, int flags); void create_box(int x1, int y1, int x2, int y2, int c, int flags);
int flood_parts(int x, int y, int c, int cm, int bm, int flags); int flood_parts(int x, int y, int c, int cm, int bm, int flags);
int create_parts(int x, int y, int rx, int ry, int c, int flags); int create_parts(int x, int y, int rx, int ry, int c, int flags, Brush * cBrush = NULL);
void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags); void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags, Brush * cBrush = NULL);
void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate);
void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]); void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]);
void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]); void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]);