Integer values for prefs, Default decoration colour, clear decoration
This commit is contained in:
parent
64ebd1117b
commit
e65e222f2c
@ -1438,6 +1438,34 @@ double Client::GetPrefNumber(std::string property, double defaultValue)
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
int Client::GetPrefInteger(std::string property, int defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::stringstream defHexInt;
|
||||
defHexInt << std::hex << defaultValue;
|
||||
|
||||
std::string hexString = GetPrefString(property, defHexInt.str());
|
||||
int finalValue = defaultValue;
|
||||
|
||||
std::stringstream hexInt;
|
||||
hexInt << hexString;
|
||||
|
||||
hexInt >> std::hex >> finalValue;
|
||||
|
||||
return finalValue;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
catch(exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
vector<string> Client::GetPrefStringArray(std::string property)
|
||||
{
|
||||
try
|
||||
@ -1445,10 +1473,17 @@ vector<string> Client::GetPrefStringArray(std::string property)
|
||||
json::Array value = GetPref(property);
|
||||
vector<string> strArray;
|
||||
for(json::Array::iterator iter = value.Begin(); iter != value.End(); ++iter)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::String cValue = *iter;
|
||||
strArray.push_back(cValue.Value());
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return strArray;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
@ -1465,10 +1500,17 @@ vector<double> Client::GetPrefNumberArray(std::string property)
|
||||
json::Array value = GetPref(property);
|
||||
vector<double> strArray;
|
||||
for(json::Array::iterator iter = value.Begin(); iter != value.End(); ++iter)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::Number cValue = *iter;
|
||||
strArray.push_back(cValue.Value());
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return strArray;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
@ -1478,6 +1520,40 @@ vector<double> Client::GetPrefNumberArray(std::string property)
|
||||
return vector<double>();
|
||||
}
|
||||
|
||||
vector<int> Client::GetPrefIntegerArray(std::string property)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::Array value = GetPref(property);
|
||||
vector<int> intArray;
|
||||
for(json::Array::iterator iter = value.Begin(); iter != value.End(); ++iter)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::String cValue = *iter;
|
||||
int finalValue = 0;
|
||||
|
||||
std::string hexString = cValue.Value();
|
||||
std::stringstream hexInt;
|
||||
hexInt << std::hex << hexString;
|
||||
hexInt >> finalValue;
|
||||
|
||||
intArray.push_back(finalValue);
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return intArray;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
return vector<int>();
|
||||
}
|
||||
|
||||
vector<bool> Client::GetPrefBoolArray(std::string property)
|
||||
{
|
||||
try
|
||||
@ -1485,10 +1561,17 @@ vector<bool> Client::GetPrefBoolArray(std::string property)
|
||||
json::Array value = GetPref(property);
|
||||
vector<bool> strArray;
|
||||
for(json::Array::iterator iter = value.Begin(); iter != value.End(); ++iter)
|
||||
{
|
||||
try
|
||||
{
|
||||
json::Boolean cValue = *iter;
|
||||
strArray.push_back(cValue.Value());
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return strArray;
|
||||
}
|
||||
catch (json::Exception & e)
|
||||
@ -1524,6 +1607,14 @@ void Client::SetPref(std::string property, double value)
|
||||
SetPref(property, numberValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, int value)
|
||||
{
|
||||
std::stringstream hexInt;
|
||||
hexInt << std::hex << value;
|
||||
json::UnknownElement intValue = json::String(hexInt.str());
|
||||
SetPref(property, intValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, vector<string> value)
|
||||
{
|
||||
json::Array newArray;
|
||||
@ -1557,6 +1648,20 @@ void Client::SetPref(std::string property, vector<bool> value)
|
||||
SetPref(property, newArrayValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, vector<int> value)
|
||||
{
|
||||
json::Array newArray;
|
||||
for(vector<int>::iterator iter = value.begin(); iter != value.end(); ++iter)
|
||||
{
|
||||
std::stringstream hexInt;
|
||||
hexInt << std::hex << *iter;
|
||||
|
||||
newArray.Insert(json::String(hexInt.str()));
|
||||
}
|
||||
json::UnknownElement newArrayValue = newArray;
|
||||
SetPref(property, newArrayValue);
|
||||
}
|
||||
|
||||
void Client::SetPref(std::string property, bool value)
|
||||
{
|
||||
json::UnknownElement boolValue = json::Boolean(value);
|
||||
@ -1570,7 +1675,7 @@ json::UnknownElement Client::GetPref(std::string property)
|
||||
json::UnknownElement currentRef = configDocumentCopy;
|
||||
for(vector<string>::iterator iter = pTokens.begin(); iter != pTokens.end(); ++iter)
|
||||
{
|
||||
currentRef = currentRef[*iter];
|
||||
currentRef = ((const json::UnknownElement &)currentRef)[*iter];
|
||||
}
|
||||
return currentRef;
|
||||
}
|
||||
|
@ -120,15 +120,19 @@ public:
|
||||
|
||||
std::string GetPrefString(std::string property, std::string defaultValue);
|
||||
double GetPrefNumber(std::string property, double defaultValue);
|
||||
int GetPrefInteger(std::string property, int defaultValue);
|
||||
vector<string> GetPrefStringArray(std::string property);
|
||||
vector<double> GetPrefNumberArray(std::string property);
|
||||
vector<int> GetPrefIntegerArray(std::string property);
|
||||
vector<bool> GetPrefBoolArray(std::string property);
|
||||
bool GetPrefBool(std::string property, bool defaultValue);
|
||||
|
||||
void SetPref(std::string property, std::string value);
|
||||
void SetPref(std::string property, double value);
|
||||
void SetPref(std::string property, int value);
|
||||
void SetPref(std::string property, vector<string> value);
|
||||
void SetPref(std::string property, vector<double> value);
|
||||
void SetPref(std::string property, vector<int> value);
|
||||
void SetPref(std::string property, vector<bool> value);
|
||||
void SetPref(std::string property, bool value);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
class DecorationTool: public Tool
|
||||
{
|
||||
public:
|
||||
enum ToolType { BlendAdd = DECO_ADD, BlendRemove = DECO_SUBTRACT, BlendMultiply = DECO_MULTIPLY, BlendDivide = DECO_DIVIDE, BlendSet = DECO_DRAW, BlendSmudge = DECO_SMUDGE };
|
||||
enum ToolType { BlendAdd = DECO_ADD, BlendRemove = DECO_SUBTRACT, BlendMultiply = DECO_MULTIPLY, BlendDivide = DECO_DIVIDE, BlendSet = DECO_DRAW, BlendSmudge = DECO_SMUDGE, Remove = DECO_CLEAR };
|
||||
|
||||
ToolType decoMode;
|
||||
|
||||
@ -27,10 +27,10 @@ public:
|
||||
}
|
||||
virtual ~DecorationTool() {}
|
||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){
|
||||
sim->ApplyDecorationPoint(position.X, position.Y, 1, 1, Red, Green, Blue, Alpha, decoMode, brush);
|
||||
sim->ApplyDecorationPoint(position.X, position.Y, Red, Green, Blue, Alpha, 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, Red, Green, Blue, Alpha, decoMode, brush);
|
||||
sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, Red, Green, Blue, Alpha, 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, Red, Green, Blue, Alpha, decoMode);
|
||||
|
@ -20,7 +20,8 @@ GameModel::GameModel():
|
||||
colourSelector(false),
|
||||
clipboard(NULL),
|
||||
stamp(NULL),
|
||||
placeSave(NULL)
|
||||
placeSave(NULL),
|
||||
colour(255, 0, 0, 255)
|
||||
{
|
||||
sim = new Simulation();
|
||||
ren = new Renderer(ui::Engine::Ref().g, sim);
|
||||
@ -108,6 +109,7 @@ GameModel::GameModel():
|
||||
menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendDivide, "DIV", "Colour blending: Divide" , 0, 0, 0));
|
||||
menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSmudge, "SMDG", "Smudge colour", 0, 0, 0));
|
||||
menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSet, "SET", "Set colour (No blending)", 0, 0, 0));
|
||||
menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::Remove, "CLR", "Clear any set decoration", 0, 0, 0));
|
||||
|
||||
//Set default brush palette
|
||||
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
|
||||
@ -135,6 +137,15 @@ GameModel::GameModel():
|
||||
if(stampFile && stampFile->GetGameSave())
|
||||
stamp = stampFile->GetGameSave();
|
||||
}
|
||||
|
||||
|
||||
//Set default decoration colour
|
||||
unsigned char colourR = min(Client::Ref().GetPrefInteger("Decoration.Red", 200), 255);
|
||||
unsigned char colourG = min(Client::Ref().GetPrefInteger("Decoration.Green", 100), 255);
|
||||
unsigned char colourB = min(Client::Ref().GetPrefInteger("Decoration.Blue", 50), 255);
|
||||
unsigned char colourA = min(Client::Ref().GetPrefInteger("Decoration.Alpha", 255), 255);
|
||||
|
||||
SetColourSelectorColour(ui::Colour(colourR, colourG, colourB, colourA));
|
||||
}
|
||||
|
||||
GameModel::~GameModel()
|
||||
@ -148,6 +159,11 @@ GameModel::~GameModel()
|
||||
std::vector<unsigned int> renderModes = ren->GetRenderMode();
|
||||
Client::Ref().SetPref("Renderer.RenderModes", std::vector<double>(renderModes.begin(), renderModes.end()));
|
||||
|
||||
Client::Ref().SetPref("Decoration.Red", (int)colour.Red);
|
||||
Client::Ref().SetPref("Decoration.Green", (int)colour.Green);
|
||||
Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue);
|
||||
Client::Ref().SetPref("Decoration.Alpha", (int)colour.Alpha);
|
||||
|
||||
for(int i = 0; i < menuList.size(); i++)
|
||||
{
|
||||
delete menuList[i];
|
||||
|
@ -700,6 +700,10 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_,
|
||||
tg = colG;
|
||||
tb = colB;
|
||||
}
|
||||
else if (mode == DECO_CLEAR)
|
||||
{
|
||||
ta = tr = tg = tb = 0.0f;
|
||||
}
|
||||
else if (mode == DECO_ADD)
|
||||
{
|
||||
ta += (colA*0.1f)*colA;
|
||||
@ -773,27 +777,32 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_,
|
||||
parts[rp>>8].dcolour = ((colA_<<24)|(colR_<<16)|(colG_<<8)|colB_);
|
||||
}
|
||||
|
||||
void Simulation::ApplyDecorationPoint(int x, int y, int rx, int ry, int colR, int colG, int colB, int colA, int mode, Brush * cBrush)
|
||||
void Simulation::ApplyDecorationPoint(int positionX, int positionY, int colR, int colG, int colB, int colA, int mode, Brush * cBrush)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if(cBrush)
|
||||
{
|
||||
rx = cBrush->GetRadius().X;
|
||||
ry = cBrush->GetRadius().Y;
|
||||
}
|
||||
int radiusX, radiusY, sizeX, sizeY;
|
||||
|
||||
if (rx == 0 && ry == 0)
|
||||
{
|
||||
ApplyDecoration(x, y, colR, colG, colB, colA, mode);
|
||||
return;
|
||||
}
|
||||
radiusX = cBrush->GetRadius().X;
|
||||
radiusY = cBrush->GetRadius().Y;
|
||||
|
||||
sizeX = cBrush->GetSize().X;
|
||||
sizeY = cBrush->GetSize().Y;
|
||||
|
||||
unsigned char *bitmap = cBrush->GetBitmap();
|
||||
for (j=-ry; j<=ry; j++)
|
||||
for (i=-rx; i<=rx; i++)
|
||||
if(bitmap[(j+ry)*(rx*2)+(i+rx)])
|
||||
ApplyDecoration(x+i, y+j, colR, colG, colB, colA, mode);
|
||||
for(int y = 0; y < sizeY; y++)
|
||||
{
|
||||
for(int x = 0; x < sizeX; x++)
|
||||
{
|
||||
if(bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES))
|
||||
{
|
||||
ApplyDecoration(positionX+(x-radiusX), positionY+(y-radiusY), colR, colG, colB, colA, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode)
|
||||
@ -814,13 +823,20 @@ void Simulation::ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, in
|
||||
}
|
||||
for (j=y1; j<=y2; j++)
|
||||
for (i=x1; i<=x2; i++)
|
||||
ApplyDecorationPoint(i, j, 0, 0, colR, colG, colB, colA, mode);
|
||||
ApplyDecoration(i, j, colR, colG, colB, colA, mode);
|
||||
}
|
||||
|
||||
void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int rx, int ry, int colR, int colG, int colB, int colA, int mode, Brush * cBrush)
|
||||
void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush)
|
||||
{
|
||||
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
|
||||
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy, rx, ry;
|
||||
float e, de;
|
||||
|
||||
if(cBrush)
|
||||
{
|
||||
rx = cBrush->GetRadius().X;
|
||||
ry = cBrush->GetRadius().Y;
|
||||
}
|
||||
|
||||
if (cp)
|
||||
{
|
||||
y = x1;
|
||||
@ -851,9 +867,9 @@ void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int rx, int
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (cp)
|
||||
ApplyDecorationPoint(y, x, rx, ry, colR, colG, colB, colA, mode, cBrush);
|
||||
ApplyDecorationPoint(y, x, colR, colG, colB, colA, mode, cBrush);
|
||||
else
|
||||
ApplyDecorationPoint(x, y, rx, ry, colR, colG, colB, colA, mode, cBrush);
|
||||
ApplyDecorationPoint(x, y, colR, colG, colB, colA, mode, cBrush);
|
||||
e += de;
|
||||
if (e >= 0.5f)
|
||||
{
|
||||
@ -861,9 +877,9 @@ void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int rx, int
|
||||
if (!(rx+ry))
|
||||
{
|
||||
if (cp)
|
||||
ApplyDecorationPoint(y, x, rx, ry, colR, colG, colB, colA, mode, cBrush);
|
||||
ApplyDecorationPoint(y, x, colR, colG, colB, colA, mode, cBrush);
|
||||
else
|
||||
ApplyDecorationPoint(x, y, rx, ry, colR, colG, colB, colA, mode, cBrush);
|
||||
ApplyDecorationPoint(x, y, colR, colG, colB, colA, mode, cBrush);
|
||||
}
|
||||
e -= 1.0f;
|
||||
}
|
||||
|
@ -173,8 +173,8 @@ public:
|
||||
void CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags, Brush * cBrush = NULL);
|
||||
|
||||
void ApplyDecoration(int x, int y, int colR, int colG, int colB, int colA, int mode);
|
||||
void ApplyDecorationPoint(int x, int y, int rx, int ry, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
|
||||
void ApplyDecorationLine(int x1, int y1, int x2, int y2, int rx, int ry, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
|
||||
void ApplyDecorationPoint(int x, int y, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
|
||||
void ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
|
||||
void ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode);
|
||||
|
||||
void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate);
|
||||
|
@ -81,6 +81,7 @@
|
||||
#define DECO_MULTIPLY 3
|
||||
#define DECO_DIVIDE 4
|
||||
#define DECO_SMUDGE 5
|
||||
#define DECO_CLEAR 6
|
||||
|
||||
//Old IDs for GOL types
|
||||
#define GT_GOL 78
|
||||
|
Loading…
Reference in New Issue
Block a user