diff --git a/src/game/DecorationTool.h b/src/game/DecorationTool.h index b6ab7e351..f6f08d466 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 e6baa5e34..1164de541 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 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 16bf47c57..8480aeb31 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 099a501e7..7b7163395 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 e77b62e6b..0f170df9f 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -4,6 +4,7 @@ #include #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 faf973ee7..7969ed00c 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 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 716147c34..a27ecf497 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); diff --git a/src/interface/Slider.cpp b/src/interface/Slider.cpp new file mode 100644 index 000000000..1e141d209 --- /dev/null +++ b/src/interface/Slider.cpp @@ -0,0 +1,107 @@ +/* + * Slider.cpp + * + * Created on: Mar 3, 2012 + * Author: Simon + */ + +#include +#include "Slider.h" + +namespace ui { + +Slider::Slider(Point position, Point size, int steps): + Component(position, size), + sliderSteps(steps), + sliderPosition(0), + isMouseDown(false) +{ + // TODO Auto-generated constructor stub + +} + +void Slider::updatePosition(int position) +{ + if(position < 3) + position = 3; + if(position > Size.X-3) + position = Size.X-3; + + float fPosition = position-3; + float fSize = Size.X-6; + float fSteps = sliderSteps; + + float fSliderPosition = (fPosition/fSize)*sliderSteps;//position;//((x-3)/(Size.X-6))*sliderSteps; + + int newSliderPosition = fSliderPosition; + + if(newSliderPosition == sliderPosition) + return; + + sliderPosition = newSliderPosition; + + if(actionCallback) + { + actionCallback->ValueChangedCallback(this); + } +} + +void Slider::OnMouseMoved(int x, int y, int dx, int dy) +{ + if(isMouseDown) + { + updatePosition(x); + } +} + +void Slider::OnMouseClick(int x, int y, unsigned button) +{ + isMouseDown = true; + updatePosition(x); +} + +void Slider::OnMouseUp(int x, int y, unsigned button) +{ + if(isMouseDown) + { + isMouseDown = false; + } +} + +int Slider::GetValue() +{ + return sliderPosition; +} + +void Slider::SetValue(int value) +{ + if(value < 0) + value = 0; + if(value > sliderSteps) + value = sliderSteps; + sliderPosition = value; +} + +void Slider::Draw(const Point& screenPos) +{ + Graphics * g = Engine::Ref().g; + g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255); + g->fillrect(screenPos.X+3, screenPos.Y+3, Size.X-6, Size.Y-6, 255, 255, 255, 255); + + float fPosition = sliderPosition; + float fSize = Size.X-6; + float fSteps = sliderSteps; + + float fSliderX = (fSize/fSteps)*fPosition;//sliderPosition;//((Size.X-6)/sliderSteps)*sliderPosition; + int sliderX = fSliderX; + sliderX += 3; + + g->fillrect(screenPos.X+sliderX-2, screenPos.Y+1, 4, Size.Y-2, 20, 20, 20, 255); + g->drawrect(screenPos.X+sliderX-2, screenPos.Y+1, 4, Size.Y-2, 200, 200, 200, 255); +} + +Slider::~Slider() +{ +} + +} /* namespace ui */ diff --git a/src/interface/Slider.h b/src/interface/Slider.h new file mode 100644 index 000000000..682bc0981 --- /dev/null +++ b/src/interface/Slider.h @@ -0,0 +1,41 @@ +/* + * Slider.h + * + * Created on: Mar 3, 2012 + * Author: Simon + */ + +#ifndef SLIDER_H_ +#define SLIDER_H_ + +#include "Component.h" + +namespace ui { +class Slider; +class SliderAction +{ +public: + virtual void ValueChangedCallback(ui::Slider * sender) {} + virtual ~SliderAction() {} +}; +class Slider: public ui::Component { + friend class SliderAction; + int sliderSteps; + int sliderPosition; + bool isMouseDown; + SliderAction * actionCallback; + void updatePosition(int position); +public: + Slider(Point position, Point size, int steps); + virtual void OnMouseMoved(int x, int y, int dx, int dy); + virtual void OnMouseClick(int x, int y, unsigned button); + virtual void OnMouseUp(int x, int y, unsigned button); + virtual void Draw(const Point& screenPos); + void SetActionCallback(SliderAction * action) { actionCallback = action; } + int GetValue(); + void SetValue(int value); + virtual ~Slider(); +}; + +} /* namespace ui */ +#endif /* SLIDER_H_ */