mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 22:38:38 +01:00
Add option to make deco tools use sRGB colour space
Currently only affects the smudge tool. I'd have to look into the others to decide if they need chaging. They probably do though, they're not exactly intuitive. I also fixed a bug with DropDowns where their popup would show up in some random place if the parent window was a ScrollPanel, and changed a few alignments here and there. Notably, DropDowns now align the popup so that the currently selected item is vertically centered and doesn't move when the popup is opened.
This commit is contained in:
parent
51b78be139
commit
51e5f2bffa
@ -47,7 +47,8 @@ GameModel::GameModel():
|
||||
activeColourPreset(0),
|
||||
colourSelector(false),
|
||||
colour(255, 0, 0, 255),
|
||||
edgeMode(0)
|
||||
edgeMode(0),
|
||||
decoSpace(0)
|
||||
{
|
||||
sim = new Simulation();
|
||||
ren = new Renderer(ui::Engine::Ref().g, sim);
|
||||
@ -92,6 +93,8 @@ GameModel::GameModel():
|
||||
//Load config into simulation
|
||||
edgeMode = Client::Ref().GetPrefInteger("Simulation.EdgeMode", 0);
|
||||
sim->SetEdgeMode(edgeMode);
|
||||
decoSpace = Client::Ref().GetPrefInteger("Simulation.DecoSpace", 0);
|
||||
sim->SetDecoSpace(decoSpace);
|
||||
int ngrav_enable = Client::Ref().GetPrefInteger("Simulation.NewtonianGravity", 0);
|
||||
if (ngrav_enable)
|
||||
sim->grav->start_grav_async();
|
||||
@ -177,6 +180,7 @@ GameModel::~GameModel()
|
||||
Client::Ref().SetPref("Simulation.NewtonianGravity", sim->grav->IsEnabled());
|
||||
Client::Ref().SetPref("Simulation.AmbientHeat", sim->aheat_enable);
|
||||
Client::Ref().SetPref("Simulation.PrettyPowder", sim->pretty_powder);
|
||||
Client::Ref().SetPref("Simulation.DecoSpace", sim->deco_space);
|
||||
|
||||
Client::Ref().SetPref("Decoration.Red", (int)colour.Red);
|
||||
Client::Ref().SetPref("Decoration.Green", (int)colour.Green);
|
||||
@ -450,6 +454,17 @@ int GameModel::GetEdgeMode()
|
||||
return this->edgeMode;
|
||||
}
|
||||
|
||||
void GameModel::SetDecoSpace(int decoSpace)
|
||||
{
|
||||
this->decoSpace = decoSpace;
|
||||
sim->SetDecoSpace(decoSpace);
|
||||
}
|
||||
|
||||
int GameModel::GetDecoSpace()
|
||||
{
|
||||
return this->decoSpace;
|
||||
}
|
||||
|
||||
std::deque<Snapshot*> GameModel::GetHistory()
|
||||
{
|
||||
return history;
|
||||
|
@ -76,6 +76,7 @@ private:
|
||||
ui::Colour colour;
|
||||
|
||||
int edgeMode;
|
||||
int decoSpace;
|
||||
|
||||
String infoTip;
|
||||
String toolTip;
|
||||
@ -109,6 +110,8 @@ public:
|
||||
|
||||
void SetEdgeMode(int edgeMode);
|
||||
int GetEdgeMode();
|
||||
void SetDecoSpace(int decoSpace);
|
||||
int GetDecoSpace();
|
||||
|
||||
void SetActiveColourPreset(size_t preset);
|
||||
size_t GetActiveColourPreset();
|
||||
|
@ -79,7 +79,7 @@ sim(sim_)
|
||||
w->FocusComponent(w->textField);
|
||||
}
|
||||
};
|
||||
property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 17));
|
||||
property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 16));
|
||||
property->SetActionCallback(new PropertyChanged(this));
|
||||
AddComponent(property);
|
||||
for (size_t i = 0; i < properties.size(); i++)
|
||||
|
@ -145,7 +145,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
||||
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
justification = new ui::DropDown(ui::Point(52, 48), ui::Point(50, 16));
|
||||
justification = new ui::DropDown(ui::Point(52, 48), ui::Point(55, 16));
|
||||
AddComponent(justification);
|
||||
justification->AddOption(std::pair<String, int>(0xE020 + String(" Left"), (int)sign::Left));
|
||||
justification->AddOption(std::pair<String, int>(0xE01E + String(" Middle"), (int)sign::Middle));
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
}
|
||||
};
|
||||
DropDownWindow(DropDown * dropDown):
|
||||
Window(ui::Point(dropDown->Position.X+dropDown->GetParentWindow()->Position.X-5, dropDown->Position.Y+dropDown->GetParentWindow()->Position.Y-3), ui::Point(dropDown->Size.X+10, 1+dropDown->options.size()*16)),
|
||||
Window(dropDown->GetScreenPos() + ui::Point(-1, -1 - dropDown->optionIndex * 16), ui::Point(dropDown->Size.X+2, 1+dropDown->options.size()*16)),
|
||||
dropDown(dropDown),
|
||||
appearance(dropDown->Appearance)
|
||||
{
|
||||
|
@ -87,6 +87,11 @@ void OptionsController::SetFastQuit(bool fastquit)
|
||||
model->SetFastQuit(fastquit);
|
||||
}
|
||||
|
||||
void OptionsController::SetDecoSpace(int decoSpace)
|
||||
{
|
||||
model->SetDecoSpace(decoSpace);
|
||||
}
|
||||
|
||||
OptionsView * OptionsController::GetView()
|
||||
{
|
||||
return view;
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
void SetScale(int scale);
|
||||
void SetResizable(bool resizable);
|
||||
void SetFastQuit(bool fastquit);
|
||||
void SetDecoSpace(int decoSpace);
|
||||
void SetShowAvatars(bool showAvatars);
|
||||
void SetMouseClickrequired(bool mouseClickRequired);
|
||||
void SetIncludePressure(bool includePressure);
|
||||
|
@ -169,6 +169,16 @@ void OptionsModel::SetFastQuit(bool fastquit)
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
int OptionsModel::GetDecoSpace()
|
||||
{
|
||||
return gModel->GetDecoSpace();
|
||||
}
|
||||
void OptionsModel::SetDecoSpace(int decoSpace)
|
||||
{
|
||||
gModel->SetDecoSpace(decoSpace);
|
||||
notifySettingsChanged();
|
||||
}
|
||||
|
||||
bool OptionsModel::GetShowAvatars()
|
||||
{
|
||||
return Client::Ref().GetPrefBool("ShowAvatars", true);
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
void SetForceIntegerScaling(bool forceIntegerScaling);
|
||||
bool GetFastQuit();
|
||||
void SetFastQuit(bool fastquit);
|
||||
int GetDecoSpace();
|
||||
void SetDecoSpace(int decoSpace);
|
||||
bool GetMouseClickRequired();
|
||||
void SetMouseClickRequired(bool mouseClickRequired);
|
||||
bool GetIncludePressure();
|
||||
|
@ -417,6 +417,27 @@ OptionsView::OptionsView():
|
||||
scrollPanel->AddChild(tempLabel);
|
||||
scrollPanel->AddChild(includePressure);
|
||||
|
||||
class DecoSpaceAction: public ui::DropDownAction
|
||||
{
|
||||
OptionsView * v;
|
||||
public:
|
||||
DecoSpaceAction(OptionsView * v): v(v) { }
|
||||
void OptionChanged(ui::DropDown * sender, std::pair<String, int> option) override {
|
||||
v->c->SetDecoSpace(option.second);
|
||||
}
|
||||
};
|
||||
currentY+=20;
|
||||
decoSpace = new ui::DropDown(ui::Point(8, currentY), ui::Point(60, 16));
|
||||
decoSpace->SetActionCallback(new DecoSpaceAction(this));
|
||||
scrollPanel->AddChild(decoSpace);
|
||||
decoSpace->AddOption(std::pair<String, int>("Linear", 0));
|
||||
decoSpace->AddOption(std::pair<String, int>("sRGB", 1));
|
||||
|
||||
tempLabel = new ui::Label(ui::Point(decoSpace->Position.X+decoSpace->Size.X+3, currentY), ui::Point(Size.X-40, 16), "\bg- Colour space used by decoration tools");
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
scrollPanel->AddChild(tempLabel);
|
||||
|
||||
class DataFolderAction: public ui::ButtonAction
|
||||
{
|
||||
public:
|
||||
@ -477,6 +498,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
|
||||
waterEqualisation->SetChecked(sender->GetWaterEqualisation());
|
||||
airMode->SetOption(sender->GetAirMode());
|
||||
gravityMode->SetOption(sender->GetGravityMode());
|
||||
decoSpace->SetOption(sender->GetDecoSpace());
|
||||
edgeMode->SetOption(sender->GetEdgeMode());
|
||||
scale->SetOption(sender->GetScale());
|
||||
resizable->SetChecked(sender->GetResizable());
|
||||
|
@ -29,6 +29,7 @@ class OptionsView: public ui::Window
|
||||
ui::Checkbox * altFullscreen;
|
||||
ui::Checkbox * forceIntegerScaling;
|
||||
ui::Checkbox * fastquit;
|
||||
ui::DropDown * decoSpace;
|
||||
ui::Checkbox * showAvatars;
|
||||
ui::Checkbox * mouseClickRequired;
|
||||
ui::Checkbox * includePressure;
|
||||
|
@ -913,6 +913,20 @@ bool Simulation::flood_water(int x, int y, int i)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Simulation::SetDecoSpace(int newDecoSpace)
|
||||
{
|
||||
switch (newDecoSpace)
|
||||
{
|
||||
case 1: // sRGB
|
||||
deco_space = 1;
|
||||
break;
|
||||
|
||||
default: // linear (or anything stupid)
|
||||
deco_space = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::SetEdgeMode(int newEdgeMode)
|
||||
{
|
||||
edgeMode = newEdgeMode;
|
||||
@ -1020,18 +1034,39 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_,
|
||||
{
|
||||
Particle part = parts[ID(pmap[y+ry][x+rx])];
|
||||
num += 1.0f;
|
||||
tas += ((float)((part.dcolour>>24)&0xFF));
|
||||
trs += ((float)((part.dcolour>>16)&0xFF));
|
||||
tgs += ((float)((part.dcolour>>8)&0xFF));
|
||||
tbs += ((float)((part.dcolour)&0xFF));
|
||||
float pa = ((float)((part.dcolour>>24)&0xFF)) / 255.f;
|
||||
float pr = ((float)((part.dcolour>>16)&0xFF)) / 255.f;
|
||||
float pg = ((float)((part.dcolour>> 8)&0xFF)) / 255.f;
|
||||
float pb = ((float)((part.dcolour )&0xFF)) / 255.f;
|
||||
switch (deco_space)
|
||||
{
|
||||
case 1: // sRGB
|
||||
pa = (pa <= 0.04045f) ? (pa / 12.92f) : pow((pa + 0.055f) / 1.055f, 2.4f);
|
||||
pr = (pr <= 0.04045f) ? (pr / 12.92f) : pow((pr + 0.055f) / 1.055f, 2.4f);
|
||||
pg = (pg <= 0.04045f) ? (pg / 12.92f) : pow((pg + 0.055f) / 1.055f, 2.4f);
|
||||
pb = (pb <= 0.04045f) ? (pb / 12.92f) : pow((pb + 0.055f) / 1.055f, 2.4f);
|
||||
break;
|
||||
}
|
||||
tas += pa;
|
||||
trs += pr;
|
||||
tgs += pg;
|
||||
tbs += pb;
|
||||
}
|
||||
}
|
||||
if (num == 0)
|
||||
return;
|
||||
ta = (tas/num)/255.0f;
|
||||
tr = (trs/num)/255.0f;
|
||||
tg = (tgs/num)/255.0f;
|
||||
tb = (tbs/num)/255.0f;
|
||||
ta = tas / num;
|
||||
tr = trs / num;
|
||||
tg = tgs / num;
|
||||
tb = tbs / num;
|
||||
switch (deco_space)
|
||||
{
|
||||
case 1: // sRGB
|
||||
ta = (ta <= 0.0031308f) ? (ta * 12.92f) : (1.055f * pow(ta, 1.f / 2.4f) - 0.055f);
|
||||
tr = (tr <= 0.0031308f) ? (tr * 12.92f) : (1.055f * pow(tr, 1.f / 2.4f) - 0.055f);
|
||||
tg = (tg <= 0.0031308f) ? (tg * 12.92f) : (1.055f * pow(tg, 1.f / 2.4f) - 0.055f);
|
||||
tb = (tb <= 0.0031308f) ? (tb * 12.92f) : (1.055f * pow(tb, 1.f / 2.4f) - 0.055f);
|
||||
}
|
||||
if (!parts[ID(rp)].dcolour)
|
||||
ta -= 3/255.0f;
|
||||
}
|
||||
@ -5420,7 +5455,8 @@ Simulation::Simulation():
|
||||
sys_pause(0),
|
||||
framerender(0),
|
||||
pretty_powder(0),
|
||||
sandcolour_frame(0)
|
||||
sandcolour_frame(0),
|
||||
deco_space(0)
|
||||
{
|
||||
int tportal_rx[] = {-1, 0, 1, 1, 1, 0,-1,-1};
|
||||
int tportal_ry[] = {-1,-1,-1, 0, 1, 1, 1, 0};
|
||||
|
@ -113,6 +113,7 @@ public:
|
||||
int pretty_powder;
|
||||
int sandcolour;
|
||||
int sandcolour_frame;
|
||||
int deco_space;
|
||||
|
||||
int Load(GameSave * save, bool includePressure);
|
||||
int Load(GameSave * save, bool includePressure, int x, int y);
|
||||
@ -166,6 +167,7 @@ public:
|
||||
void clear_area(int area_x, int area_y, int area_w, int area_h);
|
||||
|
||||
void SetEdgeMode(int newEdgeMode);
|
||||
void SetDecoSpace(int newDecoSpace);
|
||||
|
||||
//Drawing Deco
|
||||
void ApplyDecoration(int x, int y, int colR, int colG, int colB, int colA, int mode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user