From 50d683d691fcd7f758104ea1e09798b66efe4c6d Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Wed, 14 Jul 2021 20:55:10 +0100 Subject: [PATCH] Brightness adjustment now supports undo Start an undo command when the drag begins, and finish it when the mouse is released (i.e. at the same time the colour picker is updated). This avoids flooding the undo queue with lots of useless tiny adjustment commands. The incremental drag event is now wxEVT_SCROLL_THUMBTRACK, since an extra wxEVT_SLIDER is emitted *after* the final wxEVT_SCROLL_CHANGED event, resulting in a spurious new undo command being initiated which in turn prevents the previous command from being undone. --- radiant/ui/lightinspector/LightInspector.cpp | 23 ++++++++++++++++---- radiant/ui/lightinspector/LightInspector.h | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/radiant/ui/lightinspector/LightInspector.cpp b/radiant/ui/lightinspector/LightInspector.cpp index c2ba916b75..0c6094b6a6 100644 --- a/radiant/ui/lightinspector/LightInspector.cpp +++ b/radiant/ui/lightinspector/LightInspector.cpp @@ -150,11 +150,26 @@ void LightInspector::setupOptionsPanel() findNamedObject(this, "LightInspectorColour")->Bind( wxEVT_COLOURPICKER_CHANGED, &LightInspector::_onColourChange, this ); - _brightnessSlider->Bind( - wxEVT_SLIDER, [=](wxCommandEvent&) { adjustBrightness(); } + _brightnessSlider->Bind( // drag in progress + wxEVT_SCROLL_THUMBTRACK, + [=](wxScrollEvent&) { + if (!_adjustingBrightness && !GlobalUndoSystem().operationStarted()) + { + GlobalUndoSystem().start(); + _adjustingBrightness = true; + } + adjustBrightness(); + } ); - _brightnessSlider->Bind( - wxEVT_SCROLL_CHANGED, [=](wxScrollEvent&) { updateColourPicker(); } + _brightnessSlider->Bind( // drag finished + wxEVT_SCROLL_CHANGED, + [=](wxScrollEvent&) { + if (_adjustingBrightness) { + GlobalUndoSystem().finish("Adjust light brightness"); + _adjustingBrightness = false; + } + updateColourPicker(); + } ); findNamedObject(this, "LightInspectorParallel")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this); diff --git a/radiant/ui/lightinspector/LightInspector.h b/radiant/ui/lightinspector/LightInspector.h index 5c096db4e5..a4035fccd6 100644 --- a/radiant/ui/lightinspector/LightInspector.h +++ b/radiant/ui/lightinspector/LightInspector.h @@ -48,6 +48,10 @@ class LightInspector : // Disables callbacks if set to TRUE (during widget updates) bool _updateActive; + // Track if a brightness adjustment is in progress (which needs an undo + // command when finished) + bool _adjustingBrightness = false; + bool _supportsAiSee; sigc::connection _selectionChanged;