Brush class for drawing on simulation, more interface for game
This commit is contained in:
parent
91bb5a8b78
commit
19c1fa5dcb
65
src/game/Brush.h
Normal file
65
src/game/Brush.h
Normal 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_ */
|
@ -37,10 +37,21 @@ GameView * GameController::GetView()
|
||||
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)
|
||||
{
|
||||
Simulation * sim = gameModel->GetSimulation();
|
||||
int activeElement = gameModel->GetActiveElement();
|
||||
Brush * cBrush = gameModel->GetBrush();
|
||||
if(!pointQueue.empty())
|
||||
{
|
||||
ui::Point * sPoint = NULL;
|
||||
@ -50,12 +61,12 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
|
||||
pointQueue.pop();
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@ -79,3 +90,46 @@ void GameController::OpenSearch()
|
||||
search = new SearchController();
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,10 +23,19 @@ public:
|
||||
GameController();
|
||||
~GameController();
|
||||
GameView * GetView();
|
||||
void AdjustBrushSize(int direction);
|
||||
void DrawPoints(queue<ui::Point*> & pointQueue);
|
||||
void Tick();
|
||||
void SetPaused(bool pauseState);
|
||||
void OpenSearch();
|
||||
void OpenLogin();
|
||||
void OpenTags();
|
||||
void OpenDisplayOptions();
|
||||
void OpenRenderOptions();
|
||||
void OpenSaveWindow();
|
||||
void ClearSim();
|
||||
void ReloadSim();
|
||||
void Vote(int direction);
|
||||
};
|
||||
|
||||
#endif // GAMECONTROLLER_H
|
||||
|
@ -3,11 +3,15 @@
|
||||
#include "GameView.h"
|
||||
#include "simulation/Simulation.h"
|
||||
#include "Renderer.h"
|
||||
#include "interface/Point.h"
|
||||
#include "Brush.h"
|
||||
|
||||
GameModel::GameModel():
|
||||
activeElement(1),
|
||||
sim(NULL),
|
||||
ren(NULL)
|
||||
ren(NULL),
|
||||
currentSave(NULL),
|
||||
currentBrush(new Brush(ui::Point(4, 4)))
|
||||
{
|
||||
sim = new Simulation();
|
||||
ren = new Renderer(ui::Engine::Ref().g, sim);
|
||||
@ -19,12 +23,19 @@ GameModel::~GameModel()
|
||||
delete ren;
|
||||
}
|
||||
|
||||
Brush * GameModel::GetBrush()
|
||||
{
|
||||
return currentBrush;
|
||||
}
|
||||
|
||||
void GameModel::AddObserver(GameView * observer){
|
||||
observers.push_back(observer);
|
||||
|
||||
observer->NotifySimulationChanged(this);
|
||||
observer->NotifyRendererChanged(this);
|
||||
observer->NotifyPausedChanged(this);
|
||||
observer->NotifySaveChanged(this);
|
||||
observer->NotifyBrushChanged(this);
|
||||
}
|
||||
|
||||
int GameModel::GetActiveElement()
|
||||
@ -37,6 +48,16 @@ void GameModel::SetActiveElement(int element)
|
||||
activeElement = element;
|
||||
}
|
||||
|
||||
Save * GameModel::GetSave()
|
||||
{
|
||||
return currentSave;
|
||||
}
|
||||
void GameModel::SetSave(Save * newSave)
|
||||
{
|
||||
currentSave = newSave;
|
||||
notifySaveChanged();
|
||||
}
|
||||
|
||||
Simulation * GameModel::GetSimulation()
|
||||
{
|
||||
return sim;
|
||||
@ -58,6 +79,11 @@ bool GameModel::GetPaused()
|
||||
return sim->sys_pause?true:false;
|
||||
}
|
||||
|
||||
void GameModel::ClearSimulation()
|
||||
{
|
||||
sim->clear_sim();
|
||||
}
|
||||
|
||||
void GameModel::notifyRendererChanged()
|
||||
{
|
||||
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()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
@ -81,3 +115,11 @@ void GameModel::notifyPausedChanged()
|
||||
observers[i]->NotifyPausedChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::notifyBrushChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
observers[i]->NotifyBrushChanged(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define GAMEMODEL_H
|
||||
|
||||
#include <vector>
|
||||
#include "search/Save.h"
|
||||
#include "simulation/Simulation.h"
|
||||
#include "Renderer.h"
|
||||
#include "GameView.h"
|
||||
#include "Brush.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -16,20 +18,28 @@ class GameModel
|
||||
{
|
||||
private:
|
||||
vector<GameView*> observers;
|
||||
Brush * currentBrush;
|
||||
Save * currentSave;
|
||||
Simulation * sim;
|
||||
Renderer * ren;
|
||||
int activeElement;
|
||||
void notifyRendererChanged();
|
||||
void notifySimulationChanged();
|
||||
void notifyPausedChanged();
|
||||
void notifySaveChanged();
|
||||
void notifyBrushChanged();
|
||||
public:
|
||||
GameModel();
|
||||
~GameModel();
|
||||
Save * GetSave();
|
||||
Brush * GetBrush();
|
||||
void SetSave(Save * newSave);
|
||||
void AddObserver(GameView * observer);
|
||||
int GetActiveElement();
|
||||
void SetActiveElement(int element);
|
||||
bool GetPaused();
|
||||
void SetPaused(bool pauseState);
|
||||
void ClearSimulation();
|
||||
|
||||
Simulation * GetSimulation();
|
||||
Renderer * GetRenderer();
|
||||
|
@ -7,7 +7,8 @@ GameView::GameView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
||||
pointQueue(queue<ui::Point*>()),
|
||||
isMouseDown(false),
|
||||
ren(NULL)
|
||||
ren(NULL),
|
||||
activeBrush(NULL)
|
||||
{
|
||||
int currentX = 1;
|
||||
//Set up UI
|
||||
@ -34,10 +35,10 @@ GameView::GameView():
|
||||
ReloadAction(GameView * _v) { v = _v; }
|
||||
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;
|
||||
reloadButton->SetActionCallback(new ReloadAction(this));
|
||||
AddComponent(reloadButton);
|
||||
@ -49,10 +50,10 @@ GameView::GameView():
|
||||
SaveSimulationAction(GameView * _v) { v = _v; }
|
||||
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;
|
||||
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
|
||||
AddComponent(saveSimulationButton);
|
||||
@ -64,10 +65,10 @@ GameView::GameView():
|
||||
UpVoteAction(GameView * _v) { v = _v; }
|
||||
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;
|
||||
upVoteButton->SetActionCallback(new UpVoteAction(this));
|
||||
AddComponent(upVoteButton);
|
||||
@ -79,10 +80,10 @@ GameView::GameView():
|
||||
DownVoteAction(GameView * _v) { v = _v; }
|
||||
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;
|
||||
downVoteButton->SetActionCallback(new DownVoteAction(this));
|
||||
AddComponent(downVoteButton);
|
||||
@ -94,10 +95,10 @@ GameView::GameView():
|
||||
TagSimulationAction(GameView * _v) { v = _v; }
|
||||
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);
|
||||
tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
|
||||
AddComponent(tagSimulationButton);
|
||||
@ -109,10 +110,10 @@ GameView::GameView():
|
||||
ClearSimAction(GameView * _v) { v = _v; }
|
||||
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));
|
||||
AddComponent(clearSimButton);
|
||||
|
||||
@ -123,10 +124,10 @@ GameView::GameView():
|
||||
LoginAction(GameView * _v) { v = _v; }
|
||||
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));
|
||||
AddComponent(loginButton);
|
||||
|
||||
@ -137,10 +138,10 @@ GameView::GameView():
|
||||
SimulationOptionAction(GameView * _v) { v = _v; }
|
||||
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));
|
||||
AddComponent(simulationOptionButton);
|
||||
|
||||
@ -151,10 +152,10 @@ GameView::GameView():
|
||||
DisplayModeAction(GameView * _v) { v = _v; }
|
||||
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));
|
||||
AddComponent(displayModeButton);
|
||||
|
||||
@ -189,6 +190,38 @@ void GameView::NotifyPausedChanged(GameModel * sender)
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if(!pointQueue.empty())
|
||||
@ -228,4 +272,8 @@ void GameView::OnDraw()
|
||||
{
|
||||
ren->render_parts();
|
||||
}
|
||||
if(activeBrush)
|
||||
{
|
||||
activeBrush->Render(ui::Engine::Ref().g, ui::Point(ui::Engine::Ref().GetMouseX(),ui::Engine::Ref().GetMouseY()));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Point.h"
|
||||
#include "interface/Button.h"
|
||||
#include "Brush.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -19,6 +20,7 @@ private:
|
||||
queue<ui::Point*> pointQueue;
|
||||
GameController * c;
|
||||
Renderer * ren;
|
||||
Brush * activeBrush;
|
||||
//UI Elements
|
||||
ui::Button * searchButton;
|
||||
ui::Button * reloadButton;
|
||||
@ -37,10 +39,12 @@ public:
|
||||
void NotifyRendererChanged(GameModel * sender);
|
||||
void NotifySimulationChanged(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 OnMouseDown(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 OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {}
|
||||
virtual void OnTick(float dt);
|
||||
|
@ -25,7 +25,8 @@ Button::Button(Window* parent_state, std::string buttonText):
|
||||
actionCallback(NULL),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignCentre)
|
||||
textHAlign(AlignCentre),
|
||||
Enabled(true)
|
||||
{
|
||||
TextPosition();
|
||||
}
|
||||
@ -40,7 +41,8 @@ Button::Button(Point position, Point size, std::string buttonText):
|
||||
actionCallback(NULL),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignCentre)
|
||||
textHAlign(AlignCentre),
|
||||
Enabled(true)
|
||||
{
|
||||
TextPosition();
|
||||
}
|
||||
@ -55,7 +57,8 @@ Button::Button(std::string buttonText):
|
||||
actionCallback(NULL),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignCentre)
|
||||
textHAlign(AlignCentre),
|
||||
Enabled(true)
|
||||
{
|
||||
TextPosition();
|
||||
}
|
||||
@ -121,17 +124,25 @@ void Button::Draw(const Point& screenPos)
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
Point Position = screenPos;
|
||||
if(isButtonDown || (isTogglable && toggle))
|
||||
if(Enabled)
|
||||
{
|
||||
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 0, 0, 0, 255);
|
||||
if(isButtonDown || (isTogglable && toggle))
|
||||
{
|
||||
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 0, 0, 0, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isMouseInside)
|
||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isMouseInside)
|
||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 20, 20, 20, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, 255, 255, 255, 255);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,9 +190,8 @@ void Button::OnMouseLeave(int x, int y)
|
||||
|
||||
void Button::DoAction()
|
||||
{
|
||||
std::cout << "Do action!"<<std::endl;
|
||||
//if(actionCallback)
|
||||
// (*(actionCallback))();
|
||||
if(!Enabled)
|
||||
return;
|
||||
if(actionCallback)
|
||||
actionCallback->ActionCallback(this);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
virtual ~Button();
|
||||
|
||||
bool Toggleable;
|
||||
bool Enabled;
|
||||
|
||||
std::string ButtonText;
|
||||
|
||||
|
@ -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
|
||||
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;
|
||||
|
||||
if(cBrush)
|
||||
{
|
||||
rx = cBrush->GetRadius().X;
|
||||
ry = cBrush->GetRadius().Y;
|
||||
}
|
||||
|
||||
int wall = c - 100;
|
||||
if (c==SPC_WIND || c==PT_FIGH)
|
||||
return 0;
|
||||
@ -357,16 +363,6 @@ int Simulation::create_parts(int x, int y, int rx, int ry, int c, int flags)
|
||||
{
|
||||
i = ox;
|
||||
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)
|
||||
{
|
||||
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
|
||||
if (c == 0/* && !(flags&BRUSH_REPLACEMODE)*/)
|
||||
if (c == 0)
|
||||
{
|
||||
if (rx==0&&ry==0)
|
||||
{
|
||||
delete_part(x, y, 0);
|
||||
}
|
||||
else
|
||||
else if(cBrush)
|
||||
{
|
||||
bool *bitmap = cBrush->GetBitmap();
|
||||
for (j=-ry; j<=ry; j++)
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=-ry; j<=ry; j++)
|
||||
for (i=-rx; i<=rx; i++)
|
||||
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
|
||||
for (j=-ry; j<=ry; j++)
|
||||
for (i=-rx; i<=rx; i++)
|
||||
if (InCurrentBrush(i ,j ,rx ,ry))
|
||||
delete_part(x+i, y+j, flags);
|
||||
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 (rx==0&&ry==0)
|
||||
{
|
||||
create_part(-2, x, y, c);
|
||||
}
|
||||
else
|
||||
else if(cBrush)
|
||||
{
|
||||
bool *bitmap = cBrush->GetBitmap();
|
||||
for (j=-ry; j<=ry; j++)
|
||||
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)
|
||||
continue;
|
||||
//if (!REPLACE_MODE)
|
||||
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);*/
|
||||
create_part(-2, x+i, y+j, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=-ry; j<=ry; j++)
|
||||
for (i=-rx; i<=rx; i++)
|
||||
{
|
||||
if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
|
||||
continue;
|
||||
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
|
||||
for (j=-ry; j<=ry; j++)
|
||||
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)
|
||||
continue;
|
||||
if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0)
|
||||
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;
|
||||
|
||||
}*/
|
||||
//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 (create_part_add_props(-2, x, y, c, rx, ry)==-1)
|
||||
f = 1;
|
||||
}
|
||||
else
|
||||
else if(cBrush)
|
||||
{
|
||||
bool *bitmap = cBrush->GetBitmap();
|
||||
for (j=-ry; j<=ry; j++)
|
||||
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)
|
||||
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;
|
||||
}
|
||||
/*int Simulation::InCurrentBrush(int i, int j, int rx, int ry)
|
||||
{
|
||||
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)
|
||||
|
||||
void Simulation::create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags, Brush * cBrush)
|
||||
{
|
||||
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
|
||||
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++)
|
||||
{
|
||||
if (cp)
|
||||
create_parts(y, x, rx, ry, c, flags);
|
||||
create_parts(y, x, rx, ry, c, flags, cBrush);
|
||||
else
|
||||
create_parts(x, y, rx, ry, c, flags);
|
||||
create_parts(x, y, rx, ry, c, flags, cBrush);
|
||||
e += de;
|
||||
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)))
|
||||
{
|
||||
if (cp)
|
||||
create_parts(y, x, rx, ry, c, flags);
|
||||
create_parts(y, x, rx, ry, c, flags, cBrush);
|
||||
else
|
||||
create_parts(x, y, rx, ry, c, flags);
|
||||
create_parts(x, y, rx, ry, c, flags, cBrush);
|
||||
}
|
||||
e -= 1.0f;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "Elements.h"
|
||||
#include "Misc.h"
|
||||
#include "game/Brush.h"
|
||||
|
||||
#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 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 create_parts(int x, int y, 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);
|
||||
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, Brush * cBrush = NULL);
|
||||
void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate);
|
||||
void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]);
|
||||
void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]);
|
||||
|
Loading…
Reference in New Issue
Block a user