Colour picker and presets for decorations
This commit is contained in:
parent
0a67e560f4
commit
618e29d5d4
287
src/colourpicker/ColourPickerActivity.cpp
Normal file
287
src/colourpicker/ColourPickerActivity.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
/*
|
||||
* ElementSearchActivity.cpp
|
||||
*
|
||||
* Created on: Jun 24, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "ColourPickerActivity.h"
|
||||
#include "interface/Textbox.h"
|
||||
#include "interface/Label.h"
|
||||
#include "interface/Keys.h"
|
||||
#include "game/Tool.h"
|
||||
#include "Style.h"
|
||||
#include "Format.h"
|
||||
#include "game/GameModel.h"
|
||||
|
||||
ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback) :
|
||||
WindowActivity(ui::Point(-1, -1), ui::Point(266, 175)),
|
||||
currentHue(0),
|
||||
currentSaturation(0),
|
||||
currentValue(0),
|
||||
mouseDown(false),
|
||||
valueMouseDown(false),
|
||||
callback(callback)
|
||||
{
|
||||
|
||||
class ColourChange : public ui::TextboxAction
|
||||
{
|
||||
ColourPickerActivity * a;
|
||||
public:
|
||||
ColourChange(ColourPickerActivity * a) : a(a) {}
|
||||
|
||||
void TextChangedCallback(ui::Textbox * sender)
|
||||
{
|
||||
int r, g, b;
|
||||
r = format::StringToNumber<int>(a->rValue->GetText());
|
||||
g = format::StringToNumber<int>(a->gValue->GetText());
|
||||
b = format::StringToNumber<int>(a->bValue->GetText());
|
||||
RGB_to_HSV(r, g, b, &a->currentHue, &a->currentSaturation, &a->currentValue);
|
||||
}
|
||||
};
|
||||
|
||||
rValue = new ui::Textbox(ui::Point(5, Size.Y-23), ui::Point(30, 17), "255");
|
||||
rValue->SetActionCallback(new ColourChange(this));
|
||||
rValue->SetLimit(3);
|
||||
rValue->SetInputType(ui::Textbox::Number);
|
||||
AddComponent(rValue);
|
||||
|
||||
gValue = new ui::Textbox(ui::Point(40, Size.Y-23), ui::Point(30, 17), "255");
|
||||
gValue->SetActionCallback(new ColourChange(this));
|
||||
gValue->SetLimit(3);
|
||||
gValue->SetInputType(ui::Textbox::Number);
|
||||
AddComponent(gValue);
|
||||
|
||||
bValue = new ui::Textbox(ui::Point(75, Size.Y-23), ui::Point(30, 17), "255");
|
||||
bValue->SetActionCallback(new ColourChange(this));
|
||||
bValue->SetLimit(3);
|
||||
bValue->SetInputType(ui::Textbox::Number);
|
||||
AddComponent(bValue);
|
||||
|
||||
class CancelAction: public ui::ButtonAction
|
||||
{
|
||||
ColourPickerActivity * a;
|
||||
public:
|
||||
CancelAction(ColourPickerActivity * a) : a(a) { }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
a->Exit();
|
||||
}
|
||||
};
|
||||
|
||||
class OkayAction: public ui::ButtonAction
|
||||
{
|
||||
ColourPickerActivity * a;
|
||||
public:
|
||||
OkayAction(ColourPickerActivity * a) : a(a) { }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
int Red, Green, Blue;
|
||||
HSV_to_RGB(a->currentHue, a->currentSaturation, a->currentValue, &Red, &Green, &Blue);
|
||||
ui::Colour col(Red, Green, Blue);
|
||||
if(a->callback)
|
||||
a->callback->ColourPicked(col);
|
||||
a->Exit();
|
||||
}
|
||||
};
|
||||
|
||||
ui::Button * doneButton = new ui::Button(ui::Point(Size.X-45, Size.Y-23), ui::Point(40, 17), "Done");
|
||||
doneButton->SetActionCallback(new OkayAction(this));
|
||||
AddComponent(doneButton);
|
||||
SetOkayButton(doneButton);
|
||||
|
||||
ui::Button * cancelButton = new ui::Button(ui::Point(Size.X-90, Size.Y-23), ui::Point(40, 17), "Cancel");
|
||||
cancelButton->SetActionCallback(new CancelAction(this));
|
||||
AddComponent(cancelButton);
|
||||
SetCancelButton(cancelButton);
|
||||
|
||||
rValue->SetText(format::NumberToString<int>(initialColour.Red));
|
||||
gValue->SetText(format::NumberToString<int>(initialColour.Green));
|
||||
bValue->SetText(format::NumberToString<int>(initialColour.Blue));
|
||||
RGB_to_HSV(initialColour.Red, initialColour.Green, initialColour.Blue, ¤tHue, ¤tSaturation, ¤tValue);
|
||||
}
|
||||
|
||||
void ColourPickerActivity::OnMouseMove(int x, int y, int dx, int dy)
|
||||
{
|
||||
if(mouseDown)
|
||||
{
|
||||
x -= Position.X+5;
|
||||
y -= Position.Y+5;
|
||||
|
||||
currentHue = (float(x)/float(255))*359.0f;
|
||||
currentSaturation = 255-(y*2);
|
||||
|
||||
if(currentSaturation > 255)
|
||||
currentSaturation = 255;
|
||||
if(currentSaturation < 0)
|
||||
currentSaturation = 0;
|
||||
if(currentHue > 359)
|
||||
currentHue = 359;
|
||||
if(currentHue < 0)
|
||||
currentHue = 0;
|
||||
}
|
||||
|
||||
if(valueMouseDown)
|
||||
{
|
||||
x -= Position.X+5;
|
||||
y -= Position.Y+5;
|
||||
|
||||
currentValue = x;
|
||||
|
||||
if(currentValue > 255)
|
||||
currentValue = 255;
|
||||
if(currentValue < 0)
|
||||
currentValue = 0;
|
||||
}
|
||||
|
||||
if(mouseDown || valueMouseDown)
|
||||
{
|
||||
int cr, cg, cb;
|
||||
HSV_to_RGB(currentHue, currentSaturation, currentValue, &cr, &cg, &cb);
|
||||
rValue->SetText(format::NumberToString<int>(cr));
|
||||
gValue->SetText(format::NumberToString<int>(cg));
|
||||
bValue->SetText(format::NumberToString<int>(cb));
|
||||
}
|
||||
}
|
||||
|
||||
void ColourPickerActivity::OnMouseDown(int x, int y, unsigned button)
|
||||
{
|
||||
x -= Position.X+5;
|
||||
y -= Position.Y+5;
|
||||
if(x >= 0 && x <= 256 && y >= 0 && y < 127)
|
||||
{
|
||||
mouseDown = true;
|
||||
currentHue = (float(x)/float(255))*359.0f;
|
||||
currentSaturation = 255-(y*2);
|
||||
|
||||
if(currentSaturation > 255)
|
||||
currentSaturation = 255;
|
||||
if(currentSaturation < 0)
|
||||
currentSaturation = 0;
|
||||
if(currentHue > 359)
|
||||
currentHue = 359;
|
||||
if(currentHue < 0)
|
||||
currentHue = 0;
|
||||
}
|
||||
|
||||
if(x >= 0 && x <= 256 && y >= 131 && y < 142)
|
||||
{
|
||||
valueMouseDown = true;
|
||||
currentValue = x;
|
||||
|
||||
if(currentValue > 255)
|
||||
currentValue = 255;
|
||||
if(currentValue < 0)
|
||||
currentValue = 0;
|
||||
}
|
||||
|
||||
if(mouseDown || valueMouseDown)
|
||||
{
|
||||
int cr, cg, cb;
|
||||
HSV_to_RGB(currentHue, currentSaturation, currentValue, &cr, &cg, &cb);
|
||||
rValue->SetText(format::NumberToString<int>(cr));
|
||||
gValue->SetText(format::NumberToString<int>(cg));
|
||||
bValue->SetText(format::NumberToString<int>(cb));
|
||||
}
|
||||
}
|
||||
|
||||
void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
|
||||
{
|
||||
if(mouseDown || valueMouseDown)
|
||||
{
|
||||
int cr, cg, cb;
|
||||
HSV_to_RGB(currentHue, currentSaturation, currentValue, &cr, &cg, &cb);
|
||||
rValue->SetText(format::NumberToString<int>(cr));
|
||||
gValue->SetText(format::NumberToString<int>(cg));
|
||||
bValue->SetText(format::NumberToString<int>(cb));
|
||||
}
|
||||
|
||||
if(mouseDown)
|
||||
{
|
||||
mouseDown = false;
|
||||
x -= Position.X+5;
|
||||
y -= Position.Y+5;
|
||||
|
||||
currentHue = (float(x)/float(255))*359.0f;
|
||||
currentSaturation = 255-(y*2);
|
||||
|
||||
if(currentSaturation > 255)
|
||||
currentSaturation = 255;
|
||||
if(currentSaturation < 0)
|
||||
currentSaturation = 0;
|
||||
if(currentHue > 359)
|
||||
currentHue = 359;
|
||||
if(currentHue < 0)
|
||||
currentHue = 0;
|
||||
}
|
||||
|
||||
if(valueMouseDown)
|
||||
{
|
||||
valueMouseDown = false;
|
||||
|
||||
x -= Position.X+5;
|
||||
y -= Position.Y+5;
|
||||
|
||||
currentValue = x;
|
||||
|
||||
if(currentValue > 255)
|
||||
currentValue = 255;
|
||||
if(currentValue < 0)
|
||||
currentValue = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ColourPickerActivity::OnDraw()
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||
|
||||
g->drawrect(Position.X+4, Position.Y+4, 258, 130, 180, 180, 180, 255);
|
||||
|
||||
g->drawrect(Position.X+4, Position.Y+4+4+128, 258, 12, 180, 180, 180, 255);
|
||||
|
||||
|
||||
int offsetX = Position.X+5;
|
||||
int offsetY = Position.Y+5;
|
||||
|
||||
|
||||
for(int saturation = 0; saturation <= 255; saturation+=2)
|
||||
for(int hue = 0; hue <= 359; hue++)
|
||||
{
|
||||
int cr = 0;
|
||||
int cg = 0;
|
||||
int cb = 0;
|
||||
HSV_to_RGB(hue, 255-saturation, 255-saturation, &cr, &cg, &cb);
|
||||
|
||||
g->blendpixel(clamp_flt(hue, 0, 359)+offsetX, (saturation/2)+offsetY, cr, cg, cb, 255);
|
||||
}
|
||||
|
||||
//draw brightness bar
|
||||
for(int value = 0; value <= 255; value++)
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
int cr = 0;
|
||||
int cg = 0;
|
||||
int cb = 0;
|
||||
HSV_to_RGB(currentHue, currentSaturation, value, &cr, &cg, &cb);
|
||||
|
||||
g->blendpixel(value+offsetX, i+offsetY+127+5, cr, cg, cb, 255);
|
||||
}
|
||||
|
||||
int currentHueX = clamp_flt(currentHue, 0, 359);
|
||||
int currentSaturationY = ((255-currentSaturation)/2);
|
||||
g->xor_line(offsetX+currentHueX, offsetY+currentSaturationY-5, offsetX+currentHueX, offsetY+currentSaturationY+5);
|
||||
g->xor_line(offsetX+currentHueX-5, offsetY+currentSaturationY, offsetX+currentHueX+5, offsetY+currentSaturationY);
|
||||
|
||||
g->xor_line(offsetX+currentValue, offsetY+4+128, offsetX+currentValue, offsetY+13+128);
|
||||
g->xor_line(offsetX+currentValue+1, offsetY+4+128, offsetX+currentValue+1, offsetY+13+128);
|
||||
}
|
||||
|
||||
ColourPickerActivity::~ColourPickerActivity() {
|
||||
if(callback)
|
||||
delete callback;
|
||||
}
|
||||
|
37
src/colourpicker/ColourPickerActivity.h
Normal file
37
src/colourpicker/ColourPickerActivity.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Activity.h"
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Textbox.h"
|
||||
|
||||
class ColourPickedCallback
|
||||
{
|
||||
public:
|
||||
ColourPickedCallback() {}
|
||||
virtual ~ColourPickedCallback() {}
|
||||
virtual void ColourPicked(ui::Colour colour) {}
|
||||
};
|
||||
|
||||
class ColourPickerActivity: public WindowActivity {
|
||||
int currentHue;
|
||||
int currentSaturation;
|
||||
int currentValue;
|
||||
|
||||
bool mouseDown;
|
||||
bool valueMouseDown;
|
||||
|
||||
ui::Textbox * rValue;
|
||||
ui::Textbox * gValue;
|
||||
ui::Textbox * bValue;
|
||||
|
||||
ColourPickedCallback * callback;
|
||||
public:
|
||||
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);
|
||||
ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback = NULL);
|
||||
virtual ~ColourPickerActivity();
|
||||
virtual void OnDraw();
|
||||
};
|
@ -17,6 +17,7 @@
|
||||
#include "GameModelException.h"
|
||||
#include "simulation/Air.h"
|
||||
#include "elementsearch/ElementSearchActivity.h"
|
||||
#include "colourpicker/ColourPickerActivity.h"
|
||||
#include "update/UpdateActivity.h"
|
||||
#include "Notification.h"
|
||||
#include "filebrowser/FileBrowserActivity.h"
|
||||
@ -845,6 +846,11 @@ void GameController::SetDecoration()
|
||||
gameModel->SetDecoration(!gameModel->GetDecoration());
|
||||
}
|
||||
|
||||
void GameController::SetActiveColourPreset(int preset)
|
||||
{
|
||||
gameModel->SetActiveColourPreset(preset);
|
||||
}
|
||||
|
||||
void GameController::SetColour(ui::Colour colour)
|
||||
{
|
||||
gameModel->SetColourSelectorColour(colour);
|
||||
@ -965,6 +971,22 @@ void GameController::OpenElementSearch()
|
||||
new ElementSearchActivity(gameModel, toolList);
|
||||
}
|
||||
|
||||
void GameController::OpenColourPicker()
|
||||
{
|
||||
class ColourPickerCallback: public ColourPickedCallback
|
||||
{
|
||||
GameController * c;
|
||||
public:
|
||||
ColourPickerCallback(GameController * _c): c(_c) {}
|
||||
virtual ~ColourPickerCallback() {};
|
||||
virtual void ColourPicked(ui::Colour colour)
|
||||
{
|
||||
c->SetColour(colour);
|
||||
}
|
||||
};
|
||||
new ColourPickerActivity(gameModel->GetColourSelectorColour(), new ColourPickerCallback(this));
|
||||
}
|
||||
|
||||
void GameController::OpenTags()
|
||||
{
|
||||
if(gameModel->GetUser().ID)
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
void SetDecoration();
|
||||
void SetActiveMenu(Menu * menu);
|
||||
void SetActiveTool(int toolSelection, Tool * tool);
|
||||
void SetActiveColourPreset(int preset);
|
||||
void SetColour(ui::Colour colour);
|
||||
void SetToolStrength(float value);
|
||||
void LoadSaveFile(SaveFile * file);
|
||||
@ -112,6 +113,7 @@ public:
|
||||
void SaveAsCurrent();
|
||||
void OpenStamps();
|
||||
void OpenElementSearch();
|
||||
void OpenColourPicker();
|
||||
void PlaceSave(ui::Point position);
|
||||
void ClearSim();
|
||||
void ReloadSim();
|
||||
|
@ -26,7 +26,8 @@ GameModel::GameModel():
|
||||
stamp(NULL),
|
||||
placeSave(NULL),
|
||||
colour(255, 0, 0, 255),
|
||||
toolStrength(1.0f)
|
||||
toolStrength(1.0f),
|
||||
activeColourPreset(-1)
|
||||
{
|
||||
sim = new Simulation();
|
||||
ren = new Renderer(ui::Engine::Ref().g, sim);
|
||||
@ -88,6 +89,14 @@ GameModel::GameModel():
|
||||
unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);
|
||||
|
||||
SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));
|
||||
|
||||
colourPresets.push_back(ui::Colour(255, 255, 255));
|
||||
colourPresets.push_back(ui::Colour(0, 255, 255));
|
||||
colourPresets.push_back(ui::Colour(255, 0, 255));
|
||||
colourPresets.push_back(ui::Colour(255, 255, 0));
|
||||
colourPresets.push_back(ui::Colour(255, 0, 0));
|
||||
colourPresets.push_back(ui::Colour(0, 255, 0));
|
||||
colourPresets.push_back(ui::Colour(0, 0, 255));
|
||||
}
|
||||
|
||||
GameModel::~GameModel()
|
||||
@ -338,6 +347,8 @@ void GameModel::AddObserver(GameView * observer){
|
||||
observer->NotifyZoomChanged(this);
|
||||
observer->NotifyColourSelectorVisibilityChanged(this);
|
||||
observer->NotifyColourSelectorColourChanged(this);
|
||||
observer->NotifyColourPresetsChanged(this);
|
||||
observer->NotifyColourActivePresetChanged(this);
|
||||
observer->NotifyQuickOptionsChanged(this);
|
||||
observer->NotifyLastToolChanged(this);
|
||||
UpdateQuickOptions();
|
||||
@ -560,6 +571,31 @@ int GameModel::GetZoomFactor()
|
||||
return ren->ZFACTOR;
|
||||
}
|
||||
|
||||
void GameModel::SetActiveColourPreset(int preset)
|
||||
{
|
||||
activeColourPreset = preset;
|
||||
notifyColourActivePresetChanged();
|
||||
}
|
||||
|
||||
int GameModel::GetActiveColourPreset()
|
||||
{
|
||||
return activeColourPreset;
|
||||
}
|
||||
|
||||
void GameModel::SetPresetColour(ui::Colour colour)
|
||||
{
|
||||
if(activeColourPreset >= 0 && activeColourPreset < colourPresets.size())
|
||||
{
|
||||
colourPresets[activeColourPreset] = colour;
|
||||
notifyColourPresetsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<ui::Colour> GameModel::GetColourPresets()
|
||||
{
|
||||
return colourPresets;
|
||||
}
|
||||
|
||||
void GameModel::SetColourSelectorVisibility(bool visibility)
|
||||
{
|
||||
if(colourSelector != visibility)
|
||||
@ -757,6 +793,22 @@ void GameModel::notifyNotificationsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::notifyColourPresetsChanged()
|
||||
{
|
||||
for(std::vector<GameView*>::iterator iter = observers.begin(); iter != observers.end(); ++iter)
|
||||
{
|
||||
(*iter)->NotifyColourPresetsChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::notifyColourActivePresetChanged()
|
||||
{
|
||||
for(std::vector<GameView*>::iterator iter = observers.begin(); iter != observers.end(); ++iter)
|
||||
{
|
||||
(*iter)->NotifyColourActivePresetChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::notifyColourSelectorColourChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
|
@ -60,11 +60,14 @@ private:
|
||||
Tool * lastTool;
|
||||
Tool * activeTools[3];
|
||||
User currentUser;
|
||||
bool colourSelector;
|
||||
ui::Colour colour;
|
||||
float toolStrength;
|
||||
std::deque<Snapshot*> history;
|
||||
|
||||
int activeColourPreset;
|
||||
std::vector<ui::Colour> colourPresets;
|
||||
bool colourSelector;
|
||||
ui::Colour colour;
|
||||
|
||||
std::string infoTip;
|
||||
std::string toolTip;
|
||||
//bool zoomEnabled;
|
||||
@ -83,6 +86,8 @@ private:
|
||||
void notifyPlaceSaveChanged();
|
||||
void notifyColourSelectorColourChanged();
|
||||
void notifyColourSelectorVisibilityChanged();
|
||||
void notifyColourPresetsChanged();
|
||||
void notifyColourActivePresetChanged();
|
||||
void notifyNotificationsChanged();
|
||||
void notifyLogChanged(string entry);
|
||||
void notifyInfoTipChanged();
|
||||
@ -93,6 +98,13 @@ public:
|
||||
GameModel();
|
||||
~GameModel();
|
||||
|
||||
void SetActiveColourPreset(int preset);
|
||||
int GetActiveColourPreset();
|
||||
|
||||
void SetPresetColour(ui::Colour colour);
|
||||
|
||||
std::vector<ui::Colour> GetColourPresets();
|
||||
|
||||
void SetColourSelectorVisibility(bool visibility);
|
||||
bool GetColourSelectorVisibility();
|
||||
|
||||
|
@ -390,49 +390,6 @@ GameView::GameView():
|
||||
pauseButton->SetActionCallback(new PauseAction(this));
|
||||
AddComponent(pauseButton);
|
||||
|
||||
class ColourChange : public ui::SliderAction, public ui::TextboxAction
|
||||
{
|
||||
GameView * v;
|
||||
public:
|
||||
ColourChange(GameView * _v) { v = _v; }
|
||||
void ValueChangedCallback(ui::Slider * sender)
|
||||
{
|
||||
v->changeColourSlider();
|
||||
}
|
||||
|
||||
void TextChangedCallback(ui::Textbox * sender)
|
||||
{
|
||||
v->changeColourText();
|
||||
}
|
||||
};
|
||||
colourRSlider = new ui::Slider(ui::Point(5, Size.Y-39), ui::Point(50, 14), 255);
|
||||
colourRSlider->SetActionCallback(new ColourChange(this));
|
||||
colourRValue = new ui::Textbox(ui::Point(60, Size.Y-41), ui::Point(25, 17), "255");
|
||||
colourRValue->SetActionCallback(new ColourChange(this));
|
||||
colourRValue->SetLimit(3);
|
||||
colourRValue->SetInputType(ui::Textbox::Number);
|
||||
|
||||
colourGSlider = new ui::Slider(ui::Point(95, Size.Y-39), ui::Point(50, 14), 255);
|
||||
colourGSlider->SetActionCallback(new ColourChange(this));
|
||||
colourGValue = new ui::Textbox(ui::Point(150, Size.Y-41), ui::Point(25, 17), "255");
|
||||
colourGValue->SetActionCallback(new ColourChange(this));
|
||||
colourGValue->SetLimit(3);
|
||||
colourGValue->SetInputType(ui::Textbox::Number);
|
||||
|
||||
colourBSlider = new ui::Slider(ui::Point(185, Size.Y-39), ui::Point(50, 14), 255);
|
||||
colourBSlider->SetActionCallback(new ColourChange(this));
|
||||
colourBValue = new ui::Textbox(ui::Point(240, Size.Y-41), ui::Point(25, 17), "255");
|
||||
colourBValue->SetActionCallback(new ColourChange(this));
|
||||
colourBValue->SetLimit(3);
|
||||
colourBValue->SetInputType(ui::Textbox::Number);
|
||||
|
||||
colourASlider = new ui::Slider(ui::Point(275, Size.Y-39), ui::Point(50, 14), 255);
|
||||
colourASlider->SetActionCallback(new ColourChange(this));
|
||||
colourAValue = new ui::Textbox(ui::Point(330, Size.Y-41), ui::Point(25, 17), "255");
|
||||
colourAValue->SetActionCallback(new ColourChange(this));
|
||||
colourAValue->SetLimit(3);
|
||||
colourAValue->SetInputType(ui::Textbox::Number);
|
||||
|
||||
class ElementSearchAction : public ui::ButtonAction
|
||||
{
|
||||
GameView * v;
|
||||
@ -448,6 +405,19 @@ GameView::GameView():
|
||||
tempButton->SetActionCallback(new ElementSearchAction(this));
|
||||
AddComponent(tempButton);
|
||||
|
||||
class ColourPickerAction : public ui::ButtonAction
|
||||
{
|
||||
GameView * v;
|
||||
public:
|
||||
ColourPickerAction(GameView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->OpenColourPicker();
|
||||
}
|
||||
};
|
||||
colourPicker = new ui::Button(ui::Point((XRES/2)-8, YRES+1), ui::Point(16, 16), "", "Pick Colour");
|
||||
colourPicker->SetActionCallback(new ColourPickerAction(this));
|
||||
|
||||
//Render mode presets. Possibly load from config in future?
|
||||
renderModePresets = new RenderPreset[10];
|
||||
|
||||
@ -506,29 +476,18 @@ GameView::~GameView()
|
||||
{
|
||||
delete[] renderModePresets;
|
||||
|
||||
if(!colourRSlider->GetParentWindow())
|
||||
delete colourRSlider;
|
||||
if(!colourPicker->GetParentWindow())
|
||||
delete colourPicker;
|
||||
|
||||
if(!colourGSlider->GetParentWindow())
|
||||
delete colourGSlider;
|
||||
for(std::vector<ToolButton*>::iterator iter = colourPresets.begin(), end = colourPresets.end(); iter != end; ++iter)
|
||||
{
|
||||
ToolButton * button = *iter;
|
||||
if(!button->GetParentWindow())
|
||||
{
|
||||
delete button;
|
||||
}
|
||||
|
||||
if(!colourBSlider->GetParentWindow())
|
||||
delete colourBSlider;
|
||||
|
||||
if(!colourASlider->GetParentWindow())
|
||||
delete colourASlider;
|
||||
|
||||
if(!colourRValue->GetParentWindow())
|
||||
delete colourRValue;
|
||||
|
||||
if(!colourGValue->GetParentWindow())
|
||||
delete colourGValue;
|
||||
|
||||
if(!colourBValue->GetParentWindow())
|
||||
delete colourBValue;
|
||||
|
||||
if(!colourAValue->GetParentWindow())
|
||||
delete colourAValue;
|
||||
}
|
||||
|
||||
if(placeSaveThumb)
|
||||
delete placeSaveThumb;
|
||||
@ -761,71 +720,96 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
||||
|
||||
void GameView::NotifyColourSelectorVisibilityChanged(GameModel * sender)
|
||||
{
|
||||
RemoveComponent(colourRSlider);
|
||||
colourRSlider->SetParentWindow(NULL);
|
||||
RemoveComponent(colourRValue);
|
||||
colourRValue->SetParentWindow(NULL);
|
||||
for(std::vector<ToolButton*>::iterator iter = colourPresets.begin(), end = colourPresets.end(); iter != end; ++iter)
|
||||
{
|
||||
ToolButton * button = *iter;
|
||||
RemoveComponent(button);
|
||||
button->SetParentWindow(NULL);
|
||||
}
|
||||
|
||||
RemoveComponent(colourGSlider);
|
||||
colourGSlider->SetParentWindow(NULL);
|
||||
RemoveComponent(colourGValue);
|
||||
colourGValue->SetParentWindow(NULL);
|
||||
|
||||
RemoveComponent(colourBSlider);
|
||||
colourBSlider->SetParentWindow(NULL);
|
||||
RemoveComponent(colourBValue);
|
||||
colourBValue->SetParentWindow(NULL);
|
||||
|
||||
RemoveComponent(colourASlider);
|
||||
colourASlider->SetParentWindow(NULL);
|
||||
RemoveComponent(colourAValue);
|
||||
colourAValue->SetParentWindow(NULL);
|
||||
RemoveComponent(colourPicker);
|
||||
colourPicker->SetParentWindow(NULL);
|
||||
|
||||
if(sender->GetColourSelectorVisibility())
|
||||
{
|
||||
AddComponent(colourRSlider);
|
||||
AddComponent(colourRValue);
|
||||
|
||||
AddComponent(colourGSlider);
|
||||
AddComponent(colourGValue);
|
||||
|
||||
AddComponent(colourBSlider);
|
||||
AddComponent(colourBValue);
|
||||
|
||||
AddComponent(colourASlider);
|
||||
AddComponent(colourAValue);
|
||||
for(std::vector<ToolButton*>::iterator iter = colourPresets.begin(), end = colourPresets.end(); iter != end; ++iter)
|
||||
{
|
||||
ToolButton * button = *iter;
|
||||
AddComponent(button);
|
||||
}
|
||||
AddComponent(colourPicker);
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::NotifyColourPresetsChanged(GameModel * sender)
|
||||
{
|
||||
class ColourPresetAction: public ui::ButtonAction
|
||||
{
|
||||
GameView * v;
|
||||
public:
|
||||
int preset;
|
||||
ColourPresetAction(GameView * _v, int preset) : preset(preset) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender_)
|
||||
{
|
||||
ToolButton *sender = (ToolButton*)sender_;
|
||||
if(sender->GetSelectionState() == 0)
|
||||
{
|
||||
v->c->SetActiveColourPreset(preset);
|
||||
v->c->SetColour(sender->Appearance.BackgroundInactive);
|
||||
}
|
||||
else
|
||||
sender->SetSelectionState(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
for(std::vector<ToolButton*>::iterator iter = colourPresets.begin(), end = colourPresets.end(); iter != end; ++iter)
|
||||
{
|
||||
ToolButton * button = *iter;
|
||||
RemoveComponent(button);
|
||||
delete button;
|
||||
}
|
||||
colourPresets.clear();
|
||||
|
||||
int currentX = 5;
|
||||
std::vector<ui::Colour> colours = sender->GetColourPresets();
|
||||
int i = 0;
|
||||
for(std::vector<ui::Colour>::iterator iter = colours.begin(), end = colours.end(); iter != end; ++iter)
|
||||
{
|
||||
ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "");
|
||||
tempButton->Appearance.BackgroundInactive = *iter;
|
||||
tempButton->SetActionCallback(new ColourPresetAction(this, i));
|
||||
|
||||
currentX += 31;
|
||||
|
||||
if(sender->GetColourSelectorVisibility())
|
||||
AddComponent(tempButton);
|
||||
colourPresets.push_back(tempButton);
|
||||
|
||||
i++;
|
||||
}
|
||||
NotifyColourActivePresetChanged(sender);
|
||||
}
|
||||
|
||||
void GameView::NotifyColourActivePresetChanged(GameModel * sender)
|
||||
{
|
||||
for(int i = 0; i < colourPresets.size(); i++)
|
||||
{
|
||||
if(sender->GetActiveColourPreset() == i)
|
||||
{
|
||||
colourPresets[i]->SetSelectionState(0); //Primary
|
||||
}
|
||||
else
|
||||
{
|
||||
colourPresets[i]->SetSelectionState(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::NotifyColourSelectorColourChanged(GameModel * sender)
|
||||
{
|
||||
std::string intR, intG, intB, intA;
|
||||
|
||||
intR = format::NumberToString<int>(sender->GetColourSelectorColour().Red);
|
||||
intG = format::NumberToString<int>(sender->GetColourSelectorColour().Green);
|
||||
intB = format::NumberToString<int>(sender->GetColourSelectorColour().Blue);
|
||||
intA = format::NumberToString<int>(sender->GetColourSelectorColour().Alpha);
|
||||
|
||||
colourRSlider->SetValue(sender->GetColourSelectorColour().Red);
|
||||
colourRSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(255, 0, 0));
|
||||
if(!colourRValue->IsFocused())
|
||||
colourRValue->SetText(intR);
|
||||
|
||||
colourGSlider->SetValue(sender->GetColourSelectorColour().Green);
|
||||
colourGSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(0, 255, 0));
|
||||
if(!colourGValue->IsFocused())
|
||||
colourGValue->SetText(intG);
|
||||
|
||||
colourBSlider->SetValue(sender->GetColourSelectorColour().Blue);
|
||||
colourBSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(0, 0, 255));
|
||||
if(!colourBValue->IsFocused())
|
||||
colourBValue->SetText(intB);
|
||||
|
||||
colourASlider->SetValue(sender->GetColourSelectorColour().Alpha);
|
||||
colourASlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(sender->GetColourSelectorColour().Red, sender->GetColourSelectorColour().Green, sender->GetColourSelectorColour().Blue));
|
||||
if(!colourAValue->IsFocused())
|
||||
colourAValue->SetText(intA);
|
||||
colourPicker->Appearance.BackgroundInactive = sender->GetColourSelectorColour();
|
||||
colourPicker->Appearance.BackgroundHover = sender->GetColourSelectorColour();
|
||||
}
|
||||
|
||||
void GameView::NotifyRendererChanged(GameModel * sender)
|
||||
@ -1210,9 +1194,6 @@ void GameView::BeginStampSelection()
|
||||
|
||||
void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||
{
|
||||
if(colourRValue->IsFocused() || colourGValue->IsFocused() || colourBValue->IsFocused() || colourAValue->IsFocused())
|
||||
return;
|
||||
|
||||
if(introText > 50)
|
||||
{
|
||||
introText = 50;
|
||||
@ -1432,9 +1413,6 @@ 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)
|
||||
{
|
||||
if(colourRValue->IsFocused() || colourGValue->IsFocused() || colourBValue->IsFocused() || colourAValue->IsFocused())
|
||||
return;
|
||||
|
||||
if(!isMouseDown)
|
||||
drawMode = DrawPoints;
|
||||
else
|
||||
@ -1691,21 +1669,6 @@ void GameView::NotifyPlaceSaveChanged(GameModel * sender)
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::changeColourSlider()
|
||||
{
|
||||
c->SetColour(ui::Colour(colourRSlider->GetValue(), colourGSlider->GetValue(), colourBSlider->GetValue(), colourASlider->GetValue()));
|
||||
}
|
||||
|
||||
void GameView::changeColourText()
|
||||
{
|
||||
c->SetColour(ui::Colour(
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourRValue->GetText())),
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourGValue->GetText())),
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourBValue->GetText())),
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourAValue->GetText())))
|
||||
);
|
||||
}
|
||||
|
||||
void GameView::enableShiftBehaviour()
|
||||
{
|
||||
if(!shiftBehaviour)
|
||||
|
@ -88,15 +88,8 @@ private:
|
||||
ui::Button * pauseButton;
|
||||
ui::Point currentMouse;
|
||||
|
||||
ui::Slider * colourRSlider;
|
||||
ui::Slider * colourGSlider;
|
||||
ui::Slider * colourBSlider;
|
||||
ui::Slider * colourASlider;
|
||||
|
||||
ui::Textbox * colourRValue;
|
||||
ui::Textbox * colourGValue;
|
||||
ui::Textbox * colourBValue;
|
||||
ui::Textbox * colourAValue;
|
||||
ui::Button * colourPicker;
|
||||
vector<ToolButton*> colourPresets;
|
||||
|
||||
bool drawModeReset;
|
||||
ui::Point drawPoint1;
|
||||
@ -116,8 +109,6 @@ private:
|
||||
|
||||
int lastOffset;
|
||||
void setToolButtonOffset(int offset);
|
||||
void changeColourSlider();
|
||||
void changeColourText();
|
||||
virtual ui::Point lineSnapCoords(ui::Point point1, ui::Point point2);
|
||||
virtual ui::Point rectSnapCoords(ui::Point point1, ui::Point point2);
|
||||
|
||||
@ -157,6 +148,8 @@ public:
|
||||
void NotifyZoomChanged(GameModel * sender);
|
||||
void NotifyColourSelectorVisibilityChanged(GameModel * sender);
|
||||
void NotifyColourSelectorColourChanged(GameModel * sender);
|
||||
void NotifyColourPresetsChanged(GameModel * sender);
|
||||
void NotifyColourActivePresetChanged(GameModel * sender);
|
||||
void NotifyPlaceSaveChanged(GameModel * sender);
|
||||
void NotifyNotificationsChanged(GameModel * sender);
|
||||
void NotifyLogChanged(GameModel * sender, string entry);
|
||||
|
Loading…
Reference in New Issue
Block a user