mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-14 17:14:07 +01:00
Define a base class that will be useful for several track control sliders
This commit is contained in:
committed by
Paul Licameli
parent
d28b8f072b
commit
c6e7e5d99b
96
src/tracks/ui/SliderHandle.cpp
Normal file
96
src/tracks/ui/SliderHandle.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
SliderHandle.cpp
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "../../Audacity.h"
|
||||
#include "SliderHandle.h"
|
||||
#include "../../widgets/ASlider.h"
|
||||
#include "../../HitTestResult.h"
|
||||
#include "../../RefreshCode.h"
|
||||
#include "../../TrackPanelMouseEvent.h"
|
||||
|
||||
SliderHandle::SliderHandle()
|
||||
{
|
||||
}
|
||||
|
||||
SliderHandle::~SliderHandle()
|
||||
{
|
||||
}
|
||||
|
||||
HitTestPreview SliderHandle::HitPreview()
|
||||
{
|
||||
// No special message or cursor
|
||||
return {};
|
||||
}
|
||||
|
||||
UIHandle::Result SliderHandle::Click
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *)
|
||||
{
|
||||
wxMouseEvent &event = evt.event;
|
||||
using namespace RefreshCode;
|
||||
if (!event.Button(wxMOUSE_BTN_LEFT))
|
||||
return Cancelled;
|
||||
|
||||
// Come here for left click or double click
|
||||
mStartingValue = GetValue();
|
||||
mpSlider->Set(mStartingValue);
|
||||
mpSlider->OnMouseEvent(event);
|
||||
|
||||
if (event.ButtonDClick())
|
||||
// Just did a modal dialog in OnMouseEvent
|
||||
// Do not start a drag
|
||||
return RefreshCell | Cancelled;
|
||||
else
|
||||
return RefreshCell;
|
||||
}
|
||||
|
||||
UIHandle::Result SliderHandle::Drag
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
|
||||
{
|
||||
wxMouseEvent &event = evt.event;
|
||||
using namespace RefreshCode;
|
||||
mpSlider->OnMouseEvent(event);
|
||||
const float newValue = mpSlider->Get();
|
||||
|
||||
// Make a non-permanent change to the project data:
|
||||
return RefreshCell | SetValue(pProject, newValue);
|
||||
}
|
||||
|
||||
HitTestPreview SliderHandle::Preview
|
||||
(const TrackPanelMouseEvent &, const AudacityProject *)
|
||||
{
|
||||
// No special message or cursor
|
||||
return {};
|
||||
}
|
||||
|
||||
UIHandle::Result SliderHandle::Release
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
|
||||
wxWindow *)
|
||||
{
|
||||
using namespace RefreshCode;
|
||||
wxMouseEvent &event = evt.event;
|
||||
mpSlider->OnMouseEvent(event);
|
||||
const float newValue = mpSlider->Get();
|
||||
|
||||
Result result = RefreshCell;
|
||||
|
||||
// Commit changes to the project data:
|
||||
result |= SetValue(pProject, newValue);
|
||||
result |= CommitChanges(event, pProject);
|
||||
return result;
|
||||
}
|
||||
|
||||
UIHandle::Result SliderHandle::Cancel(AudacityProject *pProject)
|
||||
{
|
||||
wxMouseEvent event(wxEVT_LEFT_UP);
|
||||
mpSlider->OnMouseEvent(event);
|
||||
|
||||
// Undo un-committed changes to project data:
|
||||
return RefreshCode::RefreshCell | SetValue(pProject, mStartingValue);
|
||||
}
|
||||
64
src/tracks/ui/SliderHandle.h
Normal file
64
src/tracks/ui/SliderHandle.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
SliderHandle.h
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __AUDACITY_SLIDER_HANDLE__
|
||||
#define __AUDACITY_SLIDER_HANDLE__
|
||||
|
||||
#include "../../UIHandle.h"
|
||||
|
||||
class wxMouseEvent;
|
||||
class LWSlider;
|
||||
class Track;
|
||||
|
||||
class SliderHandle /* not final */ : public UIHandle
|
||||
{
|
||||
SliderHandle(const SliderHandle&) = delete;
|
||||
SliderHandle &operator=(const SliderHandle&) = delete;
|
||||
|
||||
protected:
|
||||
SliderHandle();
|
||||
virtual ~SliderHandle();
|
||||
|
||||
// These new abstract virtuals simplify the duties of further subclasses.
|
||||
// This class will decide whether to refresh the clicked cell for slider state
|
||||
// change.
|
||||
// Subclass can decide to refresh other things and the results will be ORed.
|
||||
virtual float GetValue() = 0;
|
||||
virtual Result SetValue(AudacityProject *pProject, float newValue) = 0;
|
||||
virtual Result CommitChanges
|
||||
(const wxMouseEvent &event, AudacityProject *pProject) = 0;
|
||||
|
||||
// For derived classes to define hit tests
|
||||
static HitTestPreview HitPreview();
|
||||
|
||||
Result Click
|
||||
(const TrackPanelMouseEvent &event, AudacityProject *pProject) override;
|
||||
|
||||
Result Drag
|
||||
(const TrackPanelMouseEvent &event, AudacityProject *pProject) override;
|
||||
|
||||
HitTestPreview Preview
|
||||
(const TrackPanelMouseEvent &event, const AudacityProject *pProject)
|
||||
override;
|
||||
|
||||
Result Release
|
||||
(const TrackPanelMouseEvent &event, AudacityProject *pProject,
|
||||
wxWindow *pParent) override;
|
||||
|
||||
Result Cancel(AudacityProject *pProject) override;
|
||||
|
||||
// Derived track is expected to set these two before Click():
|
||||
Track *mpTrack {};
|
||||
LWSlider *mpSlider {};
|
||||
|
||||
float mStartingValue {};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user