From dce7cd429b0721be92d84d09aab2065d47b4bc37 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Tue, 21 Dec 2021 20:01:37 +0000 Subject: [PATCH] #5836: light option flags are set individually 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. --- radiant/ui/lightinspector/LightInspector.cpp | 37 ++++++++++---------- radiant/ui/lightinspector/LightInspector.h | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/radiant/ui/lightinspector/LightInspector.cpp b/radiant/ui/lightinspector/LightInspector.cpp index 0769408b71..5e679541c1 100644 --- a/radiant/ui/lightinspector/LightInspector.cpp +++ b/radiant/ui/lightinspector/LightInspector.cpp @@ -135,14 +135,20 @@ void LightInspector::setupLightShapeOptions() // Start/end checkbox wxControl* startEnd = findNamedObject(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(this, checkbox)->Bind(wxEVT_CHECKBOX, [=](wxCommandEvent&) { + if (_updateActive) return; // avoid callback loops + writeToAllEntities({{spawnarg, checkboxValue(checkbox)}}); + }); +} + void LightInspector::setupOptionsPanel() { // Colour and brightness @@ -171,15 +177,18 @@ void LightInspector::setupOptionsPanel() } ); - findNamedObject(this, "LightInspectorParallel")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this); - findNamedObject(this, "LightInspectorNoShadows")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this); - findNamedObject(this, "LightInspectorSkipSpecular")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this); - findNamedObject(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(this, "LightInspectorAiSee")->Show(); - findNamedObject(this, "LightInspectorAiSee")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this); + findNamedObject(this, "LightInspectorAiSee")->Bind( + wxEVT_CHECKBOX, [=](wxCommandEvent&) { writeToAllEntities(); } + ); } else { @@ -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 diff --git a/radiant/ui/lightinspector/LightInspector.h b/radiant/ui/lightinspector/LightInspector.h index a0e4e4afe2..28e16c7c8a 100644 --- a/radiant/ui/lightinspector/LightInspector.h +++ b/radiant/ui/lightinspector/LightInspector.h @@ -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)