mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-10 18:34:21 +02:00
Line and rect drawing
This commit is contained in:
@@ -1761,7 +1761,8 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
|
|||||||
zoomWindowPosition(0, 0),
|
zoomWindowPosition(0, 0),
|
||||||
zoomScopePosition(0, 0),
|
zoomScopePosition(0, 0),
|
||||||
zoomScopeSize(10),
|
zoomScopeSize(10),
|
||||||
ZFACTOR(8)
|
ZFACTOR(8),
|
||||||
|
zoomEnabled(false)
|
||||||
{
|
{
|
||||||
this->g = g;
|
this->g = g;
|
||||||
this->sim = sim;
|
this->sim = sim;
|
||||||
|
@@ -35,8 +35,29 @@ public:
|
|||||||
if(bitmap)
|
if(bitmap)
|
||||||
delete bitmap;
|
delete bitmap;
|
||||||
}
|
}
|
||||||
|
virtual void RenderRect(Graphics * g, ui::Point position1, ui::Point position2)
|
||||||
|
{
|
||||||
|
int width, height, t;
|
||||||
|
width = position2.X-position1.X;
|
||||||
|
height = position2.Y-position1.Y;
|
||||||
|
if(height<0)
|
||||||
|
{
|
||||||
|
position1.Y += height;
|
||||||
|
height *= -1;
|
||||||
|
}
|
||||||
|
if(width<0)
|
||||||
|
{
|
||||||
|
position1.X += width;
|
||||||
|
width *= -1;
|
||||||
|
}
|
||||||
|
g->fillrect(position1.X-1, position1.Y-1, width+2, height+2, 255, 0, 255, 70);
|
||||||
|
}
|
||||||
|
virtual void RenderLine(Graphics * g, ui::Point position1, ui::Point position2)
|
||||||
|
{
|
||||||
|
g->blend_line(position1.X, position1.Y, position2.X, position2.Y, 255, 0, 255, 70);
|
||||||
|
}
|
||||||
//Draw the brush outline onto the screen
|
//Draw the brush outline onto the screen
|
||||||
virtual void Render(Graphics * g, ui::Point position)
|
virtual void RenderPoint(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);
|
g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
//Draw the brush outline onto the screen
|
//Draw the brush outline onto the screen
|
||||||
virtual void Render(Graphics * g, ui::Point position)
|
virtual void RenderPoint(Graphics * g, ui::Point position)
|
||||||
{
|
{
|
||||||
if(!bitmap)
|
if(!bitmap)
|
||||||
GenerateBitmap();
|
GenerateBitmap();
|
||||||
|
@@ -147,10 +147,35 @@ ui::Point GameController::PointTranslate(ui::Point point)
|
|||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
|
void GameController::DrawRect(int toolSelection, ui::Point point1, ui::Point point2)
|
||||||
{
|
{
|
||||||
Simulation * sim = gameModel->GetSimulation();
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
Tool * activeTool = gameModel->GetActiveTool();
|
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
|
||||||
|
Brush * cBrush = gameModel->GetBrush();
|
||||||
|
if(!activeTool || !cBrush)
|
||||||
|
return;
|
||||||
|
activeTool->DrawRect(sim, cBrush, point1, point2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameController::DrawLine(int toolSelection, ui::Point point1, ui::Point point2)
|
||||||
|
{
|
||||||
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
|
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
|
||||||
|
Brush * cBrush = gameModel->GetBrush();
|
||||||
|
if(!activeTool || !cBrush)
|
||||||
|
return;
|
||||||
|
activeTool->DrawLine(sim, cBrush, point1, point2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameController::DrawFill(int toolSelection, ui::Point point)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameController::DrawPoints(int toolSelection, queue<ui::Point*> & pointQueue)
|
||||||
|
{
|
||||||
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
|
Tool * activeTool = gameModel->GetActiveTool(toolSelection);
|
||||||
Brush * cBrush = gameModel->GetBrush();
|
Brush * cBrush = gameModel->GetBrush();
|
||||||
if(!activeTool || !cBrush)
|
if(!activeTool || !cBrush)
|
||||||
{
|
{
|
||||||
@@ -249,9 +274,9 @@ void GameController::SetActiveMenu(Menu * menu)
|
|||||||
gameModel->SetActiveMenu(menu);
|
gameModel->SetActiveMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::SetActiveTool(Tool * tool)
|
void GameController::SetActiveTool(int toolSelection, Tool * tool)
|
||||||
{
|
{
|
||||||
gameModel->SetActiveTool(tool);
|
gameModel->SetActiveTool(toolSelection, tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameController::OpenSearch()
|
void GameController::OpenSearch()
|
||||||
|
@@ -38,12 +38,15 @@ public:
|
|||||||
void SetZoomPosition(ui::Point position);
|
void SetZoomPosition(ui::Point position);
|
||||||
void AdjustBrushSize(int direction);
|
void AdjustBrushSize(int direction);
|
||||||
void AdjustZoomSize(int direction);
|
void AdjustZoomSize(int direction);
|
||||||
void DrawPoints(queue<ui::Point*> & pointQueue);
|
void DrawPoints(int toolSelection, queue<ui::Point*> & pointQueue);
|
||||||
|
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
|
||||||
|
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);
|
||||||
|
void DrawFill(int toolSelection, ui::Point point);
|
||||||
void Update();
|
void Update();
|
||||||
void SetPaused(bool pauseState);
|
void SetPaused(bool pauseState);
|
||||||
void SetPaused();
|
void SetPaused();
|
||||||
void SetActiveMenu(Menu * menu);
|
void SetActiveMenu(Menu * menu);
|
||||||
void SetActiveTool(Tool * tool);
|
void SetActiveTool(int toolSelection, Tool * tool);
|
||||||
void OpenSearch();
|
void OpenSearch();
|
||||||
void OpenLogin();
|
void OpenLogin();
|
||||||
void OpenTags();
|
void OpenTags();
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
|
|
||||||
GameModel::GameModel():
|
GameModel::GameModel():
|
||||||
activeTool(NULL),
|
activeTools({NULL, NULL, NULL}),
|
||||||
sim(NULL),
|
sim(NULL),
|
||||||
ren(NULL),
|
ren(NULL),
|
||||||
currentBrush(0),
|
currentBrush(0),
|
||||||
@@ -44,7 +44,9 @@ GameModel::GameModel():
|
|||||||
brushList.push_back(new Brush(ui::Point(4, 4)));
|
brushList.push_back(new Brush(ui::Point(4, 4)));
|
||||||
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
|
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
|
||||||
|
|
||||||
activeTool = new ElementTool(1, "TURD", 0, 0, 0);
|
activeTools[0] = new ElementTool(1, "TURD", 0, 0, 0);
|
||||||
|
activeTools[1] = new ElementTool(0, "TURD", 0, 0, 0);
|
||||||
|
//activeTool[1] = new ElementTool(0, "TURD", 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameModel::~GameModel()
|
GameModel::~GameModel()
|
||||||
@@ -63,8 +65,8 @@ GameModel::~GameModel()
|
|||||||
}
|
}
|
||||||
delete sim;
|
delete sim;
|
||||||
delete ren;
|
delete ren;
|
||||||
if(activeTool)
|
if(activeTools)
|
||||||
delete activeTool;
|
delete activeTools;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameModel::SetVote(int direction)
|
void GameModel::SetVote(int direction)
|
||||||
@@ -131,15 +133,15 @@ Menu * GameModel::GetActiveMenu()
|
|||||||
return activeMenu;
|
return activeMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tool * GameModel::GetActiveTool()
|
Tool * GameModel::GetActiveTool(int selection)
|
||||||
{
|
{
|
||||||
return activeTool;
|
return activeTools[selection];
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameModel::SetActiveTool(Tool * tool)
|
void GameModel::SetActiveTool(int selection, Tool * tool)
|
||||||
{
|
{
|
||||||
activeTool = tool;
|
activeTools[selection] = tool;
|
||||||
notifyActiveToolChanged();
|
notifyActiveToolsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Menu*> GameModel::GetMenuList()
|
vector<Menu*> GameModel::GetMenuList()
|
||||||
@@ -162,6 +164,7 @@ void GameModel::SetSave(Save * newSave)
|
|||||||
sim->Load(currentSave->GetData(), currentSave->GetDataLength());
|
sim->Load(currentSave->GetData(), currentSave->GetDataLength());
|
||||||
}
|
}
|
||||||
notifySaveChanged();
|
notifySaveChanged();
|
||||||
|
notifyPausedChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Simulation * GameModel::GetSimulation()
|
Simulation * GameModel::GetSimulation()
|
||||||
@@ -313,11 +316,11 @@ void GameModel::notifyToolListChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameModel::notifyActiveToolChanged()
|
void GameModel::notifyActiveToolsChanged()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < observers.size(); i++)
|
for(int i = 0; i < observers.size(); i++)
|
||||||
{
|
{
|
||||||
observers[i]->NotifyActiveToolChanged(this);
|
observers[i]->NotifyActiveToolsChanged(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,15 @@ class GameView;
|
|||||||
class Simulation;
|
class Simulation;
|
||||||
class Renderer;
|
class Renderer;
|
||||||
|
|
||||||
|
class ToolSelection
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ToolPrimary, ToolSecondary, ToolTertiary
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
class GameModel
|
class GameModel
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -30,7 +39,7 @@ private:
|
|||||||
Save * currentSave;
|
Save * currentSave;
|
||||||
Simulation * sim;
|
Simulation * sim;
|
||||||
Renderer * ren;
|
Renderer * ren;
|
||||||
Tool * activeTool;
|
Tool * activeTools[3];
|
||||||
User currentUser;
|
User currentUser;
|
||||||
//bool zoomEnabled;
|
//bool zoomEnabled;
|
||||||
void notifyRendererChanged();
|
void notifyRendererChanged();
|
||||||
@@ -40,7 +49,7 @@ private:
|
|||||||
void notifyBrushChanged();
|
void notifyBrushChanged();
|
||||||
void notifyMenuListChanged();
|
void notifyMenuListChanged();
|
||||||
void notifyToolListChanged();
|
void notifyToolListChanged();
|
||||||
void notifyActiveToolChanged();
|
void notifyActiveToolsChanged();
|
||||||
void notifyUserChanged();
|
void notifyUserChanged();
|
||||||
void notifyZoomChanged();
|
void notifyZoomChanged();
|
||||||
public:
|
public:
|
||||||
@@ -52,8 +61,8 @@ public:
|
|||||||
Brush * GetBrush();
|
Brush * GetBrush();
|
||||||
void SetSave(Save * newSave);
|
void SetSave(Save * newSave);
|
||||||
void AddObserver(GameView * observer);
|
void AddObserver(GameView * observer);
|
||||||
Tool * GetActiveTool();
|
Tool * GetActiveTool(int selection);
|
||||||
void SetActiveTool(Tool * tool);
|
void SetActiveTool(int selection, Tool * tool);
|
||||||
bool GetPaused();
|
bool GetPaused();
|
||||||
void SetPaused(bool pauseState);
|
void SetPaused(bool pauseState);
|
||||||
void ClearSimulation();
|
void ClearSimulation();
|
||||||
|
@@ -11,7 +11,14 @@ GameView::GameView():
|
|||||||
isMouseDown(false),
|
isMouseDown(false),
|
||||||
ren(NULL),
|
ren(NULL),
|
||||||
activeBrush(NULL),
|
activeBrush(NULL),
|
||||||
currentMouse(0, 0)
|
currentMouse(0, 0),
|
||||||
|
toolIndex(0),
|
||||||
|
zoomEnabled(false),
|
||||||
|
zoomCursorFixed(false),
|
||||||
|
drawPoint1(0, 0),
|
||||||
|
drawPoint2(0, 0),
|
||||||
|
drawMode(DrawPoints),
|
||||||
|
drawModeReset(false)
|
||||||
{
|
{
|
||||||
int currentX = 1;
|
int currentX = 1;
|
||||||
//Set up UI
|
//Set up UI
|
||||||
@@ -207,9 +214,11 @@ class GameView::ToolAction: public ui::ButtonAction
|
|||||||
public:
|
public:
|
||||||
Tool * tool;
|
Tool * tool;
|
||||||
ToolAction(GameView * _v, Tool * tool_) { v = _v; tool = tool_; }
|
ToolAction(GameView * _v, Tool * tool_) { v = _v; tool = tool_; }
|
||||||
void ActionCallback(ui::Button * sender)
|
void ActionCallback(ui::Button * sender_)
|
||||||
{
|
{
|
||||||
v->c->SetActiveTool(tool);
|
ToolButton *sender = (ToolButton*)sender_;
|
||||||
|
if(sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 2)
|
||||||
|
v->c->SetActiveTool(sender->GetSelectionState(), tool);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -242,17 +251,26 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::NotifyActiveToolChanged(GameModel * sender)
|
void GameView::NotifyActiveToolsChanged(GameModel * sender)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < toolButtons.size(); i++)
|
for(int i = 0; i < toolButtons.size(); i++)
|
||||||
{
|
{
|
||||||
if(((ToolAction*)toolButtons[i]->GetActionCallback())->tool==sender->GetActiveTool())
|
Tool * tool = ((ToolAction*)toolButtons[i]->GetActionCallback())->tool;
|
||||||
|
if(sender->GetActiveTool(0) == tool)
|
||||||
{
|
{
|
||||||
toolButtons[i]->SetToggleState(true);
|
toolButtons[i]->SetSelectionState(0); //Primary
|
||||||
|
}
|
||||||
|
else if(sender->GetActiveTool(1) == tool)
|
||||||
|
{
|
||||||
|
toolButtons[i]->SetSelectionState(1); //Secondary
|
||||||
|
}
|
||||||
|
else if(sender->GetActiveTool(2) == tool)
|
||||||
|
{
|
||||||
|
toolButtons[i]->SetSelectionState(2); //Tertiary
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
toolButtons[i]->SetToggleState(false);
|
toolButtons[i]->SetSelectionState(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,25 +299,24 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
|||||||
vector<Tool*> toolList = sender->GetToolList();
|
vector<Tool*> toolList = sender->GetToolList();
|
||||||
for(int i = 0; i < toolList.size(); i++)
|
for(int i = 0; i < toolList.size(); i++)
|
||||||
{
|
{
|
||||||
ui::Button * tempButton = new ui::Button(ui::Point(currentX, YRES), ui::Point(32, 16), toolList[i]->GetName());
|
ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES), ui::Point(32, 16), toolList[i]->GetName());
|
||||||
currentX -= 36;
|
currentX -= 36;
|
||||||
tempButton->SetTogglable(true);
|
|
||||||
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
|
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
|
||||||
|
|
||||||
totalColour = toolList[i]->colRed + 3*toolList[i]->colGreen + 2*toolList[i]->colBlue;
|
|
||||||
|
|
||||||
tempButton->SetBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
|
tempButton->SetBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
|
||||||
if (totalColour<544)
|
|
||||||
|
if(sender->GetActiveTool(0) == toolList[i])
|
||||||
{
|
{
|
||||||
tempButton->SetTextColour(ui::Colour(255, 255, 255));
|
tempButton->SetSelectionState(0); //Primary
|
||||||
}
|
}
|
||||||
else
|
else if(sender->GetActiveTool(1) == toolList[i])
|
||||||
{
|
{
|
||||||
tempButton->SetTextColour(ui::Colour(0, 0, 0));
|
tempButton->SetSelectionState(1); //Secondary
|
||||||
|
}
|
||||||
|
else if(sender->GetActiveTool(2) == toolList[i])
|
||||||
|
{
|
||||||
|
tempButton->SetSelectionState(2); //Tertiary
|
||||||
}
|
}
|
||||||
tempButton->SetBorderColour(ui::Colour(0, 0, 0));
|
|
||||||
tempButton->SetActiveBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
|
|
||||||
tempButton->SetActiveBorderColour(ui::Colour(0, 0, 255));
|
|
||||||
|
|
||||||
tempButton->SetAlignment(AlignCentre, AlignBottom);
|
tempButton->SetAlignment(AlignCentre, AlignBottom);
|
||||||
AddComponent(tempButton);
|
AddComponent(tempButton);
|
||||||
@@ -374,7 +391,7 @@ void GameView::NotifyBrushChanged(GameModel * sender)
|
|||||||
void GameView::OnMouseMove(int x, int y, int dx, int dy)
|
void GameView::OnMouseMove(int x, int y, int dx, int dy)
|
||||||
{
|
{
|
||||||
currentMouse = ui::Point(x, y);
|
currentMouse = ui::Point(x, y);
|
||||||
if(isMouseDown)
|
if(isMouseDown && drawMode == DrawPoints)
|
||||||
{
|
{
|
||||||
pointQueue.push(new ui::Point(x-dx, y-dy));
|
pointQueue.push(new ui::Point(x-dx, y-dy));
|
||||||
pointQueue.push(new ui::Point(x, y));
|
pointQueue.push(new ui::Point(x, y));
|
||||||
@@ -385,8 +402,21 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
|
|||||||
{
|
{
|
||||||
if(currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES && !(zoomEnabled && !zoomCursorFixed))
|
if(currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES && !(zoomEnabled && !zoomCursorFixed))
|
||||||
{
|
{
|
||||||
|
if(button == BUTTON_LEFT)
|
||||||
|
toolIndex = 0;
|
||||||
|
if(button == BUTTON_RIGHT)
|
||||||
|
toolIndex = 1;
|
||||||
|
if(button == BUTTON_MIDDLE)
|
||||||
|
toolIndex = 2;
|
||||||
isMouseDown = true;
|
isMouseDown = true;
|
||||||
pointQueue.push(new ui::Point(x, y));
|
if(drawMode == DrawRect || drawMode == DrawLine)
|
||||||
|
{
|
||||||
|
drawPoint1 = ui::Point(x, y);
|
||||||
|
}
|
||||||
|
if(drawMode == DrawPoints)
|
||||||
|
{
|
||||||
|
pointQueue.push(new ui::Point(x, y));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +429,27 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
|
|||||||
if(isMouseDown)
|
if(isMouseDown)
|
||||||
{
|
{
|
||||||
isMouseDown = false;
|
isMouseDown = false;
|
||||||
pointQueue.push(new ui::Point(x, y));
|
if(drawMode == DrawRect || drawMode == DrawLine)
|
||||||
|
{
|
||||||
|
drawPoint2 = ui::Point(x, y);
|
||||||
|
if(drawMode == DrawRect)
|
||||||
|
{
|
||||||
|
c->DrawRect(toolIndex, drawPoint1, drawPoint2);
|
||||||
|
}
|
||||||
|
if(drawMode == DrawLine)
|
||||||
|
{
|
||||||
|
c->DrawLine(toolIndex, drawPoint1, drawPoint2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(drawMode == DrawPoints)
|
||||||
|
{
|
||||||
|
pointQueue.push(new ui::Point(x, y));
|
||||||
|
}
|
||||||
|
if(drawModeReset)
|
||||||
|
{
|
||||||
|
drawModeReset = false;
|
||||||
|
drawMode = DrawPoints;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,6 +476,26 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
{
|
{
|
||||||
switch(key)
|
switch(key)
|
||||||
{
|
{
|
||||||
|
case KEY_CTRL:
|
||||||
|
if(drawModeReset)
|
||||||
|
drawModeReset = false;
|
||||||
|
else
|
||||||
|
drawPoint1 = currentMouse;
|
||||||
|
if(shift)
|
||||||
|
drawMode = DrawFill;
|
||||||
|
else
|
||||||
|
drawMode = DrawRect;
|
||||||
|
break;
|
||||||
|
case KEY_SHIFT:
|
||||||
|
if(drawModeReset)
|
||||||
|
drawModeReset = false;
|
||||||
|
else
|
||||||
|
drawPoint1 = currentMouse;
|
||||||
|
if(ctrl)
|
||||||
|
drawMode = DrawFill;
|
||||||
|
else
|
||||||
|
drawMode = DrawLine;
|
||||||
|
break;
|
||||||
case ' ': //Space
|
case ' ': //Space
|
||||||
c->SetPaused();
|
c->SetPaused();
|
||||||
break;
|
break;
|
||||||
@@ -442,26 +512,37 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
|
|
||||||
void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
//switch(key)
|
if(!isMouseDown)
|
||||||
//{
|
drawMode = DrawPoints;
|
||||||
//case 'z':
|
else
|
||||||
|
drawModeReset = true;
|
||||||
|
switch(character)
|
||||||
|
{
|
||||||
|
case 'z':
|
||||||
if(!zoomCursorFixed)
|
if(!zoomCursorFixed)
|
||||||
c->SetZoomEnabled(false);
|
c->SetZoomEnabled(false);
|
||||||
// break;
|
break;
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::OnTick(float dt)
|
void GameView::OnTick(float dt)
|
||||||
{
|
{
|
||||||
if(zoomEnabled && !zoomCursorFixed)
|
if(zoomEnabled && !zoomCursorFixed)
|
||||||
c->SetZoomPosition(currentMouse);
|
c->SetZoomPosition(currentMouse);
|
||||||
if(isMouseDown)
|
if(drawMode == DrawPoints)
|
||||||
{
|
{
|
||||||
pointQueue.push(new ui::Point(currentMouse));
|
if(isMouseDown)
|
||||||
|
{
|
||||||
|
pointQueue.push(new ui::Point(currentMouse));
|
||||||
|
}
|
||||||
|
if(!pointQueue.empty())
|
||||||
|
{
|
||||||
|
c->DrawPoints(toolIndex, pointQueue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!pointQueue.empty())
|
if(drawMode == DrawFill)
|
||||||
{
|
{
|
||||||
c->DrawPoints(pointQueue);
|
c->DrawFill(toolIndex, currentMouse);
|
||||||
}
|
}
|
||||||
c->Update();
|
c->Update();
|
||||||
}
|
}
|
||||||
@@ -480,7 +561,18 @@ void GameView::OnDraw()
|
|||||||
ren->DrawWalls();
|
ren->DrawWalls();
|
||||||
if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
|
if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES)
|
||||||
{
|
{
|
||||||
activeBrush->Render(ui::Engine::Ref().g, c->PointTranslate(currentMouse));
|
if(drawMode==DrawRect && isMouseDown)
|
||||||
|
{
|
||||||
|
activeBrush->RenderRect(ui::Engine::Ref().g, c->PointTranslate(drawPoint1), c->PointTranslate(currentMouse));
|
||||||
|
}
|
||||||
|
else if(drawMode==DrawLine && isMouseDown)
|
||||||
|
{
|
||||||
|
activeBrush->RenderLine(ui::Engine::Ref().g, c->PointTranslate(drawPoint1), c->PointTranslate(currentMouse));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activeBrush->RenderPoint(ui::Engine::Ref().g, c->PointTranslate(currentMouse));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ren->RenderZoom();
|
ren->RenderZoom();
|
||||||
ren->DrawSigns();
|
ren->DrawSigns();
|
||||||
|
@@ -8,25 +8,33 @@
|
|||||||
#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 "ToolButton.h"
|
||||||
#include "Brush.h"
|
#include "Brush.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
enum DrawMode
|
||||||
|
{
|
||||||
|
DrawPoints, DrawLine, DrawRect, DrawFill
|
||||||
|
};
|
||||||
|
|
||||||
class GameController;
|
class GameController;
|
||||||
class GameModel;
|
class GameModel;
|
||||||
class GameView: public ui::Window
|
class GameView: public ui::Window
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
DrawMode drawMode;
|
||||||
bool isMouseDown;
|
bool isMouseDown;
|
||||||
bool zoomEnabled;
|
bool zoomEnabled;
|
||||||
bool zoomCursorFixed;
|
bool zoomCursorFixed;
|
||||||
|
int toolIndex;
|
||||||
queue<ui::Point*> pointQueue;
|
queue<ui::Point*> pointQueue;
|
||||||
GameController * c;
|
GameController * c;
|
||||||
Renderer * ren;
|
Renderer * ren;
|
||||||
Brush * activeBrush;
|
Brush * activeBrush;
|
||||||
//UI Elements
|
//UI Elements
|
||||||
vector<ui::Button*> menuButtons;
|
vector<ui::Button*> menuButtons;
|
||||||
vector<ui::Button*> toolButtons;
|
vector<ToolButton*> toolButtons;
|
||||||
ui::Button * searchButton;
|
ui::Button * searchButton;
|
||||||
ui::Button * reloadButton;
|
ui::Button * reloadButton;
|
||||||
ui::Button * saveSimulationButton;
|
ui::Button * saveSimulationButton;
|
||||||
@@ -39,6 +47,10 @@ private:
|
|||||||
ui::Button * displayModeButton;
|
ui::Button * displayModeButton;
|
||||||
ui::Button * pauseButton;
|
ui::Button * pauseButton;
|
||||||
ui::Point currentMouse;
|
ui::Point currentMouse;
|
||||||
|
|
||||||
|
bool drawModeReset;
|
||||||
|
ui::Point drawPoint1;
|
||||||
|
ui::Point drawPoint2;
|
||||||
public:
|
public:
|
||||||
GameView();
|
GameView();
|
||||||
void AttachController(GameController * _c){ c = _c; }
|
void AttachController(GameController * _c){ c = _c; }
|
||||||
@@ -49,7 +61,7 @@ public:
|
|||||||
void NotifyBrushChanged(GameModel * sender);
|
void NotifyBrushChanged(GameModel * sender);
|
||||||
void NotifyMenuListChanged(GameModel * sender);
|
void NotifyMenuListChanged(GameModel * sender);
|
||||||
void NotifyToolListChanged(GameModel * sender);
|
void NotifyToolListChanged(GameModel * sender);
|
||||||
void NotifyActiveToolChanged(GameModel * sender);
|
void NotifyActiveToolsChanged(GameModel * sender);
|
||||||
void NotifyUserChanged(GameModel * sender);
|
void NotifyUserChanged(GameModel * sender);
|
||||||
void NotifyZoomChanged(GameModel * sender);
|
void NotifyZoomChanged(GameModel * sender);
|
||||||
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
||||||
|
@@ -48,7 +48,9 @@ public:
|
|||||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
sim->create_line(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush);
|
sim->create_line(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush);
|
||||||
}
|
}
|
||||||
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
|
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
|
||||||
|
sim->create_box(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TOOL_H_ */
|
#endif /* TOOL_H_ */
|
||||||
|
88
src/game/ToolButton.cpp
Normal file
88
src/game/ToolButton.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* ToolButton.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jan 30, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ToolButton.h"
|
||||||
|
#include "interface/Keys.h"
|
||||||
|
|
||||||
|
ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_):
|
||||||
|
ui::Button(position, size, text_)
|
||||||
|
{
|
||||||
|
SetSelectionState(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolButton::OnMouseClick(int x, int y, unsigned int button)
|
||||||
|
{
|
||||||
|
isButtonDown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolButton::OnMouseUp(int x, int y, unsigned int button)
|
||||||
|
{
|
||||||
|
if(isButtonDown)
|
||||||
|
{
|
||||||
|
if(button == BUTTON_LEFT)
|
||||||
|
SetSelectionState(0);
|
||||||
|
if(button == BUTTON_RIGHT)
|
||||||
|
SetSelectionState(1);
|
||||||
|
if(button == BUTTON_MIDDLE)
|
||||||
|
SetSelectionState(2);
|
||||||
|
DoAction();
|
||||||
|
}
|
||||||
|
isButtonDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolButton::Draw(const ui::Point& screenPos)
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
int totalColour = background.Red + 3*background.Green + 2*background.Blue;
|
||||||
|
|
||||||
|
g->fillrect(screenPos.X, screenPos.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);
|
||||||
|
|
||||||
|
if (totalColour<544)
|
||||||
|
{
|
||||||
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, ButtonText.c_str(), 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, ButtonText.c_str(), 0, 0, 0, 255);
|
||||||
|
}
|
||||||
|
if(currentSelection!=-1)
|
||||||
|
{
|
||||||
|
//g->fillrect(screenPos.X+1, screenPos.Y+1, Size.X-2, Size.Y-2, 255, 255, 255, 170);
|
||||||
|
g->fillrect(screenPos.X+2, screenPos.Y+2, Size.Y-4, Size.Y-4, 0, 0, 0, 170);
|
||||||
|
g->drawtext(screenPos.X+5, screenPos.Y+4, selectionText, 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolButton::SetSelectionState(int state)
|
||||||
|
{
|
||||||
|
currentSelection = state;
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
selectionText = "L";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
selectionText = "R";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
selectionText = "M";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
selectionText = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ToolButton::GetSelectionState()
|
||||||
|
{
|
||||||
|
return currentSelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolButton::~ToolButton() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
26
src/game/ToolButton.h
Normal file
26
src/game/ToolButton.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* ToolButton.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 30, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOOLBUTTON_H_
|
||||||
|
#define TOOLBUTTON_H_
|
||||||
|
|
||||||
|
#include "interface/Button.h"
|
||||||
|
|
||||||
|
class ToolButton: public ui::Button {
|
||||||
|
int currentSelection;
|
||||||
|
std::string selectionText;
|
||||||
|
public:
|
||||||
|
ToolButton(ui::Point position, ui::Point size, std::string text_);
|
||||||
|
virtual void OnMouseUp(int x, int y, unsigned int button);
|
||||||
|
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||||
|
virtual void Draw(const ui::Point& screenPos);
|
||||||
|
void SetSelectionState(int state);
|
||||||
|
int GetSelectionState();
|
||||||
|
virtual ~ToolButton();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* TOOLBUTTON_H_ */
|
@@ -8,7 +8,14 @@
|
|||||||
#define KEY_DELETE SDLK_DELETE
|
#define KEY_DELETE SDLK_DELETE
|
||||||
#define KEY_TAB SDLK_TAB
|
#define KEY_TAB SDLK_TAB
|
||||||
|
|
||||||
|
#define KEY_CTRL SDLK_LCTRL
|
||||||
|
#define KEY_ALT SDLK_LALT
|
||||||
|
#define KEY_SHIFT SDLK_LSHIFT
|
||||||
|
|
||||||
#define KEY_MOD_CONTROL KMOD_CTRL
|
#define KEY_MOD_CONTROL KMOD_CTRL
|
||||||
#define KEY_MOD_ALT KMOD_ALT
|
#define KEY_MOD_ALT KMOD_ALT
|
||||||
#define KEY_MOD_SHIFT KMOD_SHIFT
|
#define KEY_MOD_SHIFT KMOD_SHIFT
|
||||||
|
|
||||||
|
#define BUTTON_LEFT SDL_BUTTON_LEFT
|
||||||
|
#define BUTTON_MIDDLE SDL_BUTTON_MIDDLE
|
||||||
|
#define BUTTON_RIGHT SDL_BUTTON_RIGHT
|
||||||
|
Reference in New Issue
Block a user