Skip to content

Commit

Permalink
Brightness adjustment now supports undo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthew Mott committed Jul 14, 2021
1 parent 39efc2e commit 50d683d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 19 additions & 4 deletions radiant/ui/lightinspector/LightInspector.cpp
Expand Up @@ -150,11 +150,26 @@ void LightInspector::setupOptionsPanel()
findNamedObject<wxColourPickerCtrl>(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<wxCheckBox>(this, "LightInspectorParallel")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
Expand Down
4 changes: 4 additions & 0 deletions radiant/ui/lightinspector/LightInspector.h
Expand Up @@ -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;
Expand Down

0 comments on commit 50d683d

Please sign in to comment.