mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-18 17:10:55 +02:00
NoteTrack VZooming.
This commit is contained in:
parent
94b1175684
commit
80d7f2426f
@ -18,13 +18,24 @@ Paul Licameli split from TrackPanel.cpp
|
||||
#include "../../../../Project.h"
|
||||
#include "../../../../RefreshCode.h"
|
||||
#include "../../../../TrackPanelMouseEvent.h"
|
||||
#include "../../../../widgets/PopupMenuTable.h"
|
||||
#include "../../../../../images/Cursors.h"
|
||||
#include "../../../../Prefs.h"
|
||||
|
||||
#include <wx/event.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct InitMenuData
|
||||
{
|
||||
public:
|
||||
NoteTrack *pTrack;
|
||||
wxRect rect;
|
||||
unsigned result;
|
||||
int yy;
|
||||
};
|
||||
|
||||
bool IsDragZooming(int zoomStart, int zoomEnd)
|
||||
{
|
||||
const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.
|
||||
@ -115,9 +126,111 @@ HitTestPreview NoteTrackVZoomHandle::Preview
|
||||
return HitPreview(st.state);
|
||||
}
|
||||
|
||||
// Note that these can be with or without spectrum view which
|
||||
// adds a constant.
|
||||
//const int kZoom1to1 = 1;
|
||||
//const int kZoomTimes2 = 2;
|
||||
//const int kZoomDiv2 = 3;
|
||||
//const int kZoomHalfWave = 4;
|
||||
//const int kZoomInByDrag = 5;
|
||||
const int kZoomIn = 6;
|
||||
const int kZoomOut = 7;
|
||||
const int kZoomReset = 8;
|
||||
|
||||
enum {
|
||||
OnZoomFitVerticalID = 20000,
|
||||
OnZoomResetID,
|
||||
OnZoomDiv2ID,
|
||||
OnZoomTimes2ID,
|
||||
OnZoomHalfWaveID,
|
||||
OnZoomInVerticalID,
|
||||
OnZoomOutVerticalID,
|
||||
|
||||
// Reserve an ample block of ids for waveform scale types
|
||||
OnFirstWaveformScaleID,
|
||||
OnLastWaveformScaleID = OnFirstWaveformScaleID + 9,
|
||||
|
||||
// Reserve an ample block of ids for spectrum scale types
|
||||
OnFirstSpectrumScaleID,
|
||||
OnLastSpectrumScaleID = OnFirstSpectrumScaleID + 19,
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Table class
|
||||
|
||||
class NoteTrackVRulerMenuTable : public PopupMenuTable
|
||||
{
|
||||
NoteTrackVRulerMenuTable(){};
|
||||
virtual ~NoteTrackVRulerMenuTable() {}
|
||||
DECLARE_POPUP_MENU(NoteTrackVRulerMenuTable);
|
||||
|
||||
public:
|
||||
static NoteTrackVRulerMenuTable &Instance();
|
||||
|
||||
protected:
|
||||
InitMenuData *mpData {};
|
||||
void OnZoom( int iZoomCode );
|
||||
// void OnZoomFitVertical(wxCommandEvent&){ OnZoom( kZoom1to1 );};
|
||||
void OnZoomReset(wxCommandEvent&){ OnZoom( kZoomReset );};
|
||||
// void OnZoomDiv2Vertical(wxCommandEvent&){ OnZoom( kZoomDiv2 );};
|
||||
// void OnZoomTimes2Vertical(wxCommandEvent&){ OnZoom( kZoomTimes2 );};
|
||||
// void OnZoomHalfWave(wxCommandEvent&){ OnZoom( kZoomHalfWave );};
|
||||
void OnZoomInVertical(wxCommandEvent&){ OnZoom( kZoomIn );};
|
||||
void OnZoomOutVertical(wxCommandEvent&){ OnZoom( kZoomOut );};
|
||||
|
||||
private:
|
||||
void DestroyMenu() override
|
||||
{
|
||||
mpData = nullptr;
|
||||
}
|
||||
|
||||
virtual void InitMenu(Menu *pMenu, void *pUserData);
|
||||
|
||||
void OnWaveformScaleType(wxCommandEvent &evt);
|
||||
};
|
||||
|
||||
NoteTrackVRulerMenuTable &NoteTrackVRulerMenuTable::Instance()
|
||||
{
|
||||
static NoteTrackVRulerMenuTable instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void NoteTrackVRulerMenuTable::InitMenu(Menu *pMenu, void *pUserData)
|
||||
{
|
||||
mpData = static_cast<InitMenuData*>(pUserData);
|
||||
}
|
||||
|
||||
void NoteTrackVRulerMenuTable::OnZoom( int iZoomCode ){
|
||||
switch( iZoomCode ){
|
||||
case kZoomReset:
|
||||
mpData->pTrack->SetBottomNote(0);
|
||||
mpData->pTrack->SetPitchHeight(mpData->rect.height, 1);
|
||||
break;
|
||||
case kZoomIn:
|
||||
mpData->pTrack->ZoomIn(mpData->rect, mpData->yy);
|
||||
break;
|
||||
case kZoomOut:
|
||||
mpData->pTrack->ZoomOut(mpData->rect, mpData->yy);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BEGIN_POPUP_MENU(NoteTrackVRulerMenuTable)
|
||||
|
||||
POPUP_MENU_ITEM(OnZoomResetID, _("Zoom Reset\tShift-Right-Click"), OnZoomReset)
|
||||
|
||||
POPUP_MENU_SEPARATOR()
|
||||
POPUP_MENU_ITEM(OnZoomInVerticalID, _("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
|
||||
POPUP_MENU_ITEM(OnZoomOutVerticalID, _("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
|
||||
|
||||
END_POPUP_MENU()
|
||||
|
||||
|
||||
|
||||
UIHandle::Result NoteTrackVZoomHandle::Release
|
||||
(const TrackPanelMouseEvent &evt, AudacityProject *pProject,
|
||||
wxWindow *WXUNUSED(pParent))
|
||||
wxWindow *pParent)
|
||||
{
|
||||
using namespace RefreshCode;
|
||||
auto pTrack = pProject->GetTracks()->Lock(mpTrack);
|
||||
@ -125,6 +238,50 @@ UIHandle::Result NoteTrackVZoomHandle::Release
|
||||
return RefreshNone;
|
||||
|
||||
const wxMouseEvent &event = evt.event;
|
||||
const bool shiftDown = event.ShiftDown();
|
||||
const bool rightUp = event.RightUp();
|
||||
|
||||
|
||||
bool bVZoom;
|
||||
gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, CFG_DA(!) true);
|
||||
|
||||
// Popup menu...
|
||||
if (
|
||||
rightUp &&
|
||||
!(event.ShiftDown() || event.CmdDown()))
|
||||
{
|
||||
InitMenuData data {
|
||||
pTrack.get(), mRect, RefreshCode::RefreshNone, event.m_y
|
||||
};
|
||||
|
||||
PopupMenuTable *const pTable =
|
||||
(PopupMenuTable *) &NoteTrackVRulerMenuTable::Instance();
|
||||
std::unique_ptr<PopupMenuTable::Menu>
|
||||
pMenu(PopupMenuTable::BuildMenu(pParent, pTable, &data));
|
||||
|
||||
// Accelerators only if zooming enabled.
|
||||
if( !bVZoom )
|
||||
{
|
||||
wxMenuItemList & L = pMenu->GetMenuItems();
|
||||
// let's iterate over the list in STL syntax
|
||||
wxMenuItemList::iterator iter;
|
||||
for (iter = L.begin(); iter != L.end(); ++iter)
|
||||
{
|
||||
wxMenuItem *pItem = *iter;
|
||||
// Remove accelerator, if any.
|
||||
pItem->SetItemLabel( (pItem->GetItemLabel() + "\t" ).BeforeFirst('\t') );
|
||||
}
|
||||
}
|
||||
|
||||
pParent->PopupMenu(pMenu.get(), event.m_x, event.m_y);
|
||||
|
||||
return data.result;
|
||||
}
|
||||
|
||||
bVZoom &= event.GetId() != kCaptureLostEventId;
|
||||
if( !bVZoom )
|
||||
return RefreshAll;
|
||||
|
||||
if (IsDragZooming(mZoomStart, mZoomEnd)) {
|
||||
pTrack->ZoomTo(evt.rect, mZoomStart, mZoomEnd);
|
||||
}
|
||||
|
@ -636,6 +636,10 @@ UIHandle::Result WaveTrackVZoomHandle::Release
|
||||
const bool shiftDown = event.ShiftDown();
|
||||
const bool rightUp = event.RightUp();
|
||||
|
||||
|
||||
bool bVZoom;
|
||||
gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, CFG_DA(!) true);
|
||||
|
||||
// Popup menu...
|
||||
if (
|
||||
rightUp &&
|
||||
@ -651,8 +655,6 @@ UIHandle::Result WaveTrackVZoomHandle::Release
|
||||
: (PopupMenuTable *) &WaveformVRulerMenuTable::Instance();
|
||||
std::unique_ptr<PopupMenuTable::Menu>
|
||||
pMenu(PopupMenuTable::BuildMenu(pParent, pTable, &data));
|
||||
bool bVZoom;
|
||||
gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, CFG_DA(!) true);
|
||||
|
||||
// Accelerators only if zooming enabled.
|
||||
if( !bVZoom )
|
||||
@ -674,8 +676,6 @@ UIHandle::Result WaveTrackVZoomHandle::Release
|
||||
return data.result;
|
||||
}
|
||||
else{
|
||||
bool bVZoom;
|
||||
gPrefs->Read(wxT("/GUI/VerticalZooming"), &bVZoom, CFG_DA(!) true);
|
||||
// Ignore Capture Lost event
|
||||
bVZoom &= event.GetId() != kCaptureLostEventId;
|
||||
// shiftDown | rightUp | ZoomKind
|
||||
|
Loading…
x
Reference in New Issue
Block a user