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 buttons
This commit is contained in:
committed by
Paul Licameli
parent
f89cbefc7b
commit
d28b8f072b
111
src/tracks/ui/ButtonHandle.cpp
Normal file
111
src/tracks/ui/ButtonHandle.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
ButtonHandle.cpp
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "ButtonHandle.h"
|
||||
#include "../../HitTestResult.h"
|
||||
#include "../../Project.h"
|
||||
#include "../../RefreshCode.h"
|
||||
#include "../../Track.h"
|
||||
#include "../../TrackPanelMouseEvent.h"
|
||||
#include "../ui/TrackControls.h"
|
||||
|
||||
ButtonHandle::ButtonHandle(int dragCode)
|
||||
: mDragCode(dragCode)
|
||||
{
|
||||
}
|
||||
|
||||
ButtonHandle::~ButtonHandle()
|
||||
{
|
||||
}
|
||||
|
||||
HitTestPreview ButtonHandle::HitPreview()
|
||||
{
|
||||
// No special message or cursor
|
||||
return {};
|
||||
}
|
||||
|
||||
UIHandle::Result ButtonHandle::Click
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *)
|
||||
{
|
||||
const wxMouseEvent &event = evt.event;
|
||||
using namespace RefreshCode;
|
||||
if (!event.Button(wxMOUSE_BTN_LEFT))
|
||||
return Cancelled;
|
||||
|
||||
// Come here for left click or double click
|
||||
if (mRect.Contains(event.m_x, event.m_y)) {
|
||||
mpTrack = static_cast<TrackControls*>(evt.pCell)->GetTrack();
|
||||
TrackControls::gCaptureState = mDragCode;
|
||||
// Toggle visible button state
|
||||
return RefreshCell;
|
||||
}
|
||||
else
|
||||
return Cancelled;
|
||||
}
|
||||
|
||||
UIHandle::Result ButtonHandle::Drag
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *)
|
||||
{
|
||||
const wxMouseEvent &event = evt.event;
|
||||
using namespace RefreshCode;
|
||||
const int newState =
|
||||
mRect.Contains(event.m_x, event.m_y) ? mDragCode : 0;
|
||||
if (TrackControls::gCaptureState == newState)
|
||||
return RefreshNone;
|
||||
else {
|
||||
TrackControls::gCaptureState = newState;
|
||||
return RefreshCell;
|
||||
}
|
||||
}
|
||||
|
||||
HitTestPreview ButtonHandle::Preview
|
||||
(const TrackPanelMouseEvent &, const AudacityProject *)
|
||||
{
|
||||
// No special message or cursor
|
||||
return {};
|
||||
}
|
||||
|
||||
UIHandle::Result ButtonHandle::Release
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
|
||||
wxWindow *pParent)
|
||||
{
|
||||
using namespace RefreshCode;
|
||||
Result result = RefreshNone;
|
||||
const wxMouseEvent &event = evt.event;
|
||||
if (TrackControls::gCaptureState) {
|
||||
TrackControls::gCaptureState = 0;
|
||||
result = RefreshCell;
|
||||
}
|
||||
if (mpTrack && mRect.Contains(event.m_x, event.m_y))
|
||||
result |= CommitChanges(event, pProject, pParent);
|
||||
return result;
|
||||
}
|
||||
|
||||
UIHandle::Result ButtonHandle::Cancel(AudacityProject *pProject)
|
||||
{
|
||||
using namespace RefreshCode;
|
||||
if (TrackControls::gCaptureState) {
|
||||
TrackControls::gCaptureState = 0;
|
||||
return RefreshCell;
|
||||
}
|
||||
else
|
||||
return RefreshNone;
|
||||
}
|
||||
|
||||
void ButtonHandle::OnProjectChange(AudacityProject *pProject)
|
||||
{
|
||||
if (! pProject->GetTracks()->Contains(mpTrack)) {
|
||||
mpTrack = nullptr;
|
||||
mRect = {};
|
||||
}
|
||||
|
||||
UIHandle::OnProjectChange(pProject);
|
||||
}
|
||||
|
||||
63
src/tracks/ui/ButtonHandle.h
Normal file
63
src/tracks/ui/ButtonHandle.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/**********************************************************************
|
||||
|
||||
Audacity: A Digital Audio Editor
|
||||
|
||||
ButtonHandle.h
|
||||
|
||||
Paul Licameli
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __AUDACITY_BUTTON_HANDLE__
|
||||
#define __AUDACITY_BUTTON_HANDLE__
|
||||
|
||||
#include "../../UIHandle.h"
|
||||
|
||||
class wxMouseEvent;
|
||||
#include <wx/gdicmn.h>
|
||||
|
||||
class Track;
|
||||
|
||||
class ButtonHandle /* not final */ : public UIHandle
|
||||
{
|
||||
ButtonHandle(const ButtonHandle&) = delete;
|
||||
ButtonHandle &operator=(const ButtonHandle&) = delete;
|
||||
|
||||
protected:
|
||||
explicit ButtonHandle(int dragCode);
|
||||
virtual ~ButtonHandle();
|
||||
|
||||
// This new abstract virtual simplifies the duties of further subclasses.
|
||||
// This class will decide whether to refresh the clicked cell for button state
|
||||
// change.
|
||||
// Subclass can decide to refresh other things and the results will be ORed.
|
||||
virtual Result CommitChanges
|
||||
(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) = 0;
|
||||
|
||||
// For derived class 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;
|
||||
|
||||
void OnProjectChange(AudacityProject *pProject) override;
|
||||
|
||||
wxRect mRect {};
|
||||
Track *mpTrack {};
|
||||
const int mDragCode;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user