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)