diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-03-04 16:26:03 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-03-04 16:26:03 (GMT) |
| commit | 644e6770e43e5ed568b0cdc14d63f20869d7fccc (patch) | |
| tree | 19e0b8b60df245d0972a3d7afb106f6954b931ee /src/game | |
| parent | 3bbaa1a111e3770d2ce9b04f4b0f9688948d3e85 (diff) | |
| download | powder-644e6770e43e5ed568b0cdc14d63f20869d7fccc.zip powder-644e6770e43e5ed568b0cdc14d63f20869d7fccc.tar.gz | |
Slider and decoration colour changer
Diffstat (limited to 'src/game')
| -rw-r--r-- | src/game/DecorationTool.h | 6 | ||||
| -rw-r--r-- | src/game/GameController.cpp | 17 | ||||
| -rw-r--r-- | src/game/GameController.h | 1 | ||||
| -rw-r--r-- | src/game/GameModel.cpp | 49 | ||||
| -rw-r--r-- | src/game/GameModel.h | 11 | ||||
| -rw-r--r-- | src/game/GameView.cpp | 57 | ||||
| -rw-r--r-- | src/game/GameView.h | 8 |
7 files changed, 145 insertions, 4 deletions
diff --git a/src/game/DecorationTool.h b/src/game/DecorationTool.h index b6ab7e3..f6f08d4 100644 --- a/src/game/DecorationTool.h +++ b/src/game/DecorationTool.h @@ -18,13 +18,13 @@ public: } virtual ~DecorationTool() {} virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){ - sim->ApplyDecorationPoint(position.X, position.Y, 1, 1, 24, 24, 24, 255, decoMode, brush); + sim->ApplyDecorationPoint(position.X, position.Y, 1, 1, colRed, colGreen, colBlue, 255, decoMode, brush); } virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, 24, 24, 24, 255, decoMode, brush); + sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, colRed, colGreen, colBlue, 255, decoMode, brush); } virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { - sim->ApplyDecorationBox(position1.X, position1.Y, position2.X, position2.Y, 24, 24, 24, 255, decoMode); + sim->ApplyDecorationBox(position1.X, position1.Y, position2.X, position2.Y, colRed, colGreen, colBlue, 255, decoMode); } virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index e6baa5e..1164de5 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -292,9 +292,26 @@ void GameController::SetDecoration() gameModel->SetDecoration(!gameModel->GetDecoration()); } +void GameController::SetColour(ui::Colour colour) +{ + gameModel->SetColourSelectorColour(colour); +} + void GameController::SetActiveMenu(Menu * menu) { gameModel->SetActiveMenu(menu); + vector<Menu*> menuList = gameModel->GetMenuList(); + bool set = false; + for(int i = 0; i < menuList.size(); i++) + { + if(menuList[i]==menu && i == SC_DECO) + { + gameModel->SetColourSelectorVisibility(true); + set = true; + } + } + if(!set) + gameModel->SetColourSelectorVisibility(false); } void GameController::SetActiveTool(int toolSelection, Tool * tool) diff --git a/src/game/GameController.h b/src/game/GameController.h index 16bf47c..8480aeb 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -56,6 +56,7 @@ public: void SetDecoration(); void SetActiveMenu(Menu * menu); void SetActiveTool(int toolSelection, Tool * tool); + void SetColour(ui::Colour colour); void OpenSearch(); void OpenLogin(); void OpenTags(); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 099a501..7b71633 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -15,7 +15,8 @@ GameModel::GameModel(): ren(NULL), currentBrush(0), currentUser(0, ""), - currentSave(NULL) + currentSave(NULL), + colourSelector(false) { sim = new Simulation(); ren = new Renderer(ui::Engine::Ref().g, sim); @@ -200,6 +201,8 @@ void GameModel::AddObserver(GameView * observer){ observer->NotifyToolListChanged(this); observer->NotifyUserChanged(this); observer->NotifyZoomChanged(this); + observer->NotifyColourSelectorVisibilityChanged(this); + observer->NotifyColourSelectorColourChanged(this); } void GameModel::SetActiveMenu(Menu * menu) @@ -329,6 +332,34 @@ int GameModel::GetZoomFactor() return ren->ZFACTOR; } +void GameModel::SetColourSelectorVisibility(bool visibility) +{ + if(colourSelector != visibility) + { + colourSelector = visibility; + notifyColourSelectorVisibilityChanged(); + } +} + +bool GameModel::GetColourSelectorVisibility() +{ + return colourSelector; +} + +void GameModel::SetColourSelectorColour(ui::Colour colour_) +{ + //if(this->colour!=colour) + { + colour = colour_; + notifyColourSelectorColourChanged(); + } +} + +ui::Colour GameModel::GetColourSelectorColour() +{ + return colour; +} + void GameModel::SetUser(User user) { currentUser = user; @@ -368,6 +399,22 @@ void GameModel::ClearSimulation() sim->clear_sim(); } +void GameModel::notifyColourSelectorColourChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyColourSelectorColourChanged(this); + } +} + +void GameModel::notifyColourSelectorVisibilityChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyColourSelectorVisibilityChanged(this); + } +} + void GameModel::notifyRendererChanged() { for(int i = 0; i < observers.size(); i++) diff --git a/src/game/GameModel.h b/src/game/GameModel.h index e77b62e..0f170df 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -4,6 +4,7 @@ #include <vector> #include "search/Save.h" #include "simulation/Simulation.h" +#include "interface/Colour.h" #include "Renderer.h" #include "GameView.h" #include "Brush.h" @@ -41,6 +42,8 @@ private: Renderer * ren; Tool * activeTools[3]; User currentUser; + bool colourSelector; + ui::Colour colour; //bool zoomEnabled; void notifyRendererChanged(); void notifySimulationChanged(); @@ -53,10 +56,18 @@ private: void notifyActiveToolsChanged(); void notifyUserChanged(); void notifyZoomChanged(); + void notifyColourSelectorColourChanged(); + void notifyColourSelectorVisibilityChanged(); public: GameModel(); ~GameModel(); + void SetColourSelectorVisibility(bool visibility); + bool GetColourSelectorVisibility(); + + void SetColourSelectorColour(ui::Colour colour); + ui::Colour GetColourSelectorColour(); + void SetVote(int direction); Save * GetSave(); Brush * GetBrush(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index faf973e..7969ed0 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -4,6 +4,7 @@ #include "interface/Button.h" #include "interface/Colour.h" #include "interface/Keys.h" +#include "interface/Slider.h" GameView::GameView(): ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)), @@ -194,6 +195,24 @@ GameView::GameView(): pauseButton->SetTogglable(true); pauseButton->SetActionCallback(new PauseAction(this)); AddComponent(pauseButton); + + class ColourChange : public ui::SliderAction + { + GameView * v; + public: + ColourChange(GameView * _v) { v = _v; } + void ValueChangedCallback(ui::Slider * sender) + { + v->changeColour(); + } + }; + ColourChange * colC = new ColourChange(this); + colourRSlider = new ui::Slider(ui::Point(5, Size.Y-40), ui::Point(100, 16), 255); + colourRSlider->SetActionCallback(colC); + colourGSlider = new ui::Slider(ui::Point(115, Size.Y-40), ui::Point(100, 16), 255); + colourGSlider->SetActionCallback(colC); + colourBSlider = new ui::Slider(ui::Point(225, Size.Y-40), ui::Point(100, 16), 255); + colourBSlider->SetActionCallback(colC); } class GameView::MenuAction: public ui::ButtonAction @@ -328,6 +347,39 @@ void GameView::NotifyToolListChanged(GameModel * sender) } +void GameView::NotifyColourSelectorVisibilityChanged(GameModel * sender) +{ + RemoveComponent(colourRSlider); + colourRSlider->SetParentWindow(NULL); + RemoveComponent(colourGSlider); + colourGSlider->SetParentWindow(NULL); + RemoveComponent(colourBSlider); + colourBSlider->SetParentWindow(NULL); + if(sender->GetColourSelectorVisibility()) + { + AddComponent(colourRSlider); + AddComponent(colourGSlider); + AddComponent(colourBSlider); + } + +} + +void GameView::NotifyColourSelectorColourChanged(GameModel * sender) +{ + colourRSlider->SetValue(sender->GetColourSelectorColour().Red); + colourGSlider->SetValue(sender->GetColourSelectorColour().Green); + colourBSlider->SetValue(sender->GetColourSelectorColour().Blue); + + vector<Tool*> tools = sender->GetMenuList()[SC_DECO]->GetToolList(); + for(int i = 0; i < tools.size(); i++) + { + tools[i]->colRed = sender->GetColourSelectorColour().Red; + tools[i]->colGreen = sender->GetColourSelectorColour().Green; + tools[i]->colBlue = sender->GetColourSelectorColour().Blue; + } + NotifyToolListChanged(sender); +} + void GameView::NotifyRendererChanged(GameModel * sender) { ren = sender->GetRenderer(); @@ -565,6 +617,11 @@ void GameView::NotifyZoomChanged(GameModel * sender) zoomEnabled = sender->GetZoomEnabled(); } +void GameView::changeColour() +{ + c->SetColour(ui::Colour(colourRSlider->GetValue(), colourGSlider->GetValue(), colourBSlider->GetValue())); +} + void GameView::OnDraw() { if(ren) diff --git a/src/game/GameView.h b/src/game/GameView.h index 716147c..a27ecf4 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -8,6 +8,7 @@ #include "interface/Window.h" #include "interface/Point.h" #include "interface/Button.h" +#include "interface/Slider.h" #include "ToolButton.h" #include "Brush.h" @@ -48,9 +49,14 @@ private: ui::Button * pauseButton; ui::Point currentMouse; + ui::Slider * colourRSlider; + ui::Slider * colourGSlider; + ui::Slider * colourBSlider; + bool drawModeReset; ui::Point drawPoint1; ui::Point drawPoint2; + void changeColour(); public: GameView(); void AttachController(GameController * _c){ c = _c; } @@ -64,6 +70,8 @@ public: void NotifyActiveToolsChanged(GameModel * sender); void NotifyUserChanged(GameModel * sender); void NotifyZoomChanged(GameModel * sender); + void NotifyColourSelectorVisibilityChanged(GameModel * sender); + void NotifyColourSelectorColourChanged(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); |
