Skip to content

Commit

Permalink
#5836: light option flags are set individually
Browse files Browse the repository at this point in the history
Instead of setting all four option flags in one go (on all selected lights,
regardless of current per-light option values), each checkbox is connected to
its own lambda resulting in only the toggled option being applied to the
selected lights.

This means that you can now safely toggle "No shadows" with several lights
selected, without unexpectedly overwriting the lights' individual settings for
"Parallel", "No specular" etc.
  • Loading branch information
Matthew Mott committed Dec 21, 2021
1 parent 9305c55 commit dce7cd4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
37 changes: 18 additions & 19 deletions radiant/ui/lightinspector/LightInspector.cpp
Expand Up @@ -135,14 +135,20 @@ void LightInspector::setupLightShapeOptions()

// Start/end checkbox
wxControl* startEnd = findNamedObject<wxCheckBox>(this, "LightInspectorStartEnd");
startEnd->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(LightInspector::_onOptionsToggle),
NULL, this
startEnd->Bind(
wxEVT_CHECKBOX, [=](wxCommandEvent&) { writeToAllEntities(); }
);
startEnd->Enable(false);
}

// Connect the options checkboxes
void LightInspector::bindSpawnargToCheckbox(std::string spawnarg, std::string checkbox)
{
findNamedObject<wxCheckBox>(this, checkbox)->Bind(wxEVT_CHECKBOX, [=](wxCommandEvent&) {
if (_updateActive) return; // avoid callback loops
writeToAllEntities({{spawnarg, checkboxValue(checkbox)}});
});
}

void LightInspector::setupOptionsPanel()
{
// Colour and brightness
Expand Down Expand Up @@ -171,15 +177,18 @@ void LightInspector::setupOptionsPanel()
}
);

findNamedObject<wxCheckBox>(this, "LightInspectorParallel")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorNoShadows")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorSkipSpecular")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorSkipDiffuse")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
// Connect light option checkboxes
bindSpawnargToCheckbox("parallel", "LightInspectorParallel");
bindSpawnargToCheckbox("noshadows", "LightInspectorNoShadows");
bindSpawnargToCheckbox("nospecular", "LightInspectorSkipSpecular");
bindSpawnargToCheckbox("nodiffuse", "LightInspectorSkipDiffuse");

if (_supportsAiSee)
{
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->Show();
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->Bind(
wxEVT_CHECKBOX, [=](wxCommandEvent&) { writeToAllEntities(); }
);
}
else
{
Expand Down Expand Up @@ -645,16 +654,6 @@ void LightInspector::setValuesOnEntity(Entity* entity)
}
}

void LightInspector::_onOptionsToggle(wxCommandEvent& ev)
{
if (_updateActive) return; // avoid callback loops

writeToAllEntities({{"parallel", checkboxValue("LightInspectorParallel")},
{"nospecular", checkboxValue("LightInspectorSkipSpecular")},
{"nodiffuse", checkboxValue("LightInspectorSkipDiffuse")},
{"noshadows", checkboxValue("LightInspectorNoShadows")}});
}

void LightInspector::_onColourChange(wxColourPickerEvent& ev)
{
if (_updateActive) return; // avoid callback loops
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/lightinspector/LightInspector.h
Expand Up @@ -71,13 +71,13 @@ class LightInspector :

// Widget construction functions
void setupLightShapeOptions();
void bindSpawnargToCheckbox(std::string spawnarg, std::string checkbox);
void setupOptionsPanel();
void setupTextureWidgets();

// Callbacks
void _onProjToggle(wxCommandEvent& ev);
void _onColourChange(wxColourPickerEvent& ev);
void _onOptionsToggle(wxCommandEvent& ev);
void adjustBrightness() const;

// Get value of a checkbox as a spawnarg string (1 or 0)
Expand Down

0 comments on commit dce7cd4

Please sign in to comment.