Slider and decoration colour changer
This commit is contained in:
parent
3bbaa1a111
commit
644e6770e4
@ -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) {
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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++)
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
107
src/interface/Slider.cpp
Normal file
107
src/interface/Slider.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Slider.cpp
|
||||
*
|
||||
* Created on: Mar 3, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#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 */
|
41
src/interface/Slider.h
Normal file
41
src/interface/Slider.h
Normal file
@ -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_ */
|
Reference in New Issue
Block a user