Define BackgoundCell, move some things into it

This commit is contained in:
Paul Licameli 2017-06-10 15:02:10 -04:00
parent 674ccc5e15
commit 8ef5f696d8
9 changed files with 173 additions and 19 deletions

View File

@ -1232,6 +1232,7 @@
5E7396501DAFD98400BA0A4D /* SliderHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E73964E1DAFD98400BA0A4D /* SliderHandle.cpp */; };
5E7396561DAFDA0000BA0A4D /* WaveTrackSliderHandles.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E7396541DAFDA0000BA0A4D /* WaveTrackSliderHandles.cpp */; };
5E7396591DAFDA3600BA0A4D /* TrackButtonHandles.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E7396571DAFDA3600BA0A4D /* TrackButtonHandles.cpp */; };
5E73965C1DAFDAA400BA0A4D /* BackgroundCell.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E73965A1DAFDAA400BA0A4D /* BackgroundCell.cpp */; };
5E74D2E31CC4429700D88B0B /* EditCursorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2DD1CC4429700D88B0B /* EditCursorOverlay.cpp */; };
5E74D2E41CC4429700D88B0B /* PlayIndicatorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2DF1CC4429700D88B0B /* PlayIndicatorOverlay.cpp */; };
5E74D2E51CC4429700D88B0B /* Scrubbing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2E11CC4429700D88B0B /* Scrubbing.cpp */; };
@ -3067,6 +3068,8 @@
5E7396551DAFDA0000BA0A4D /* WaveTrackSliderHandles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WaveTrackSliderHandles.h; sourceTree = "<group>"; };
5E7396571DAFDA3600BA0A4D /* TrackButtonHandles.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackButtonHandles.cpp; sourceTree = "<group>"; };
5E7396581DAFDA3600BA0A4D /* TrackButtonHandles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackButtonHandles.h; sourceTree = "<group>"; };
5E73965A1DAFDAA400BA0A4D /* BackgroundCell.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BackgroundCell.cpp; sourceTree = "<group>"; };
5E73965B1DAFDAA400BA0A4D /* BackgroundCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackgroundCell.h; sourceTree = "<group>"; };
5E74D2D91CC4427B00D88B0B /* TrackPanelCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackPanelCell.h; sourceTree = "<group>"; };
5E74D2DA1CC4427B00D88B0B /* TrackPanelCellIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackPanelCellIterator.h; sourceTree = "<group>"; };
5E74D2DD1CC4429700D88B0B /* EditCursorOverlay.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditCursorOverlay.cpp; sourceTree = "<group>"; };
@ -5764,6 +5767,7 @@
5E74D2DC1CC4429700D88B0B /* ui */ = {
isa = PBXGroup;
children = (
5E73965A1DAFDAA400BA0A4D /* BackgroundCell.cpp */,
5E73964B1DAFD95B00BA0A4D /* ButtonHandle.cpp */,
5E1512661DB0010C00702E29 /* CommonTrackPanelCell.cpp */,
5E74D2DD1CC4429700D88B0B /* EditCursorOverlay.cpp */,
@ -5777,6 +5781,7 @@
5E15126A1DB0010C00702E29 /* TrackUI.cpp */,
5E15126B1DB0010C00702E29 /* TrackVRulerControls.cpp */,
5E73963C1DAFD86000BA0A4D /* ZoomHandle.cpp */,
5E73965B1DAFDAA400BA0A4D /* BackgroundCell.h */,
5E73964C1DAFD95B00BA0A4D /* ButtonHandle.h */,
5E1512671DB0010C00702E29 /* CommonTrackPanelCell.h */,
5E74D2DE1CC4429700D88B0B /* EditCursorOverlay.h */,
@ -7937,6 +7942,7 @@
28001B4B1A0F0EB6007DD161 /* SpectralSelectionBar.cpp in Sources */,
28BB98051A15BE6800D1CC80 /* NoiseReduction.cpp in Sources */,
5E74D2E41CC4429700D88B0B /* PlayIndicatorOverlay.cpp in Sources */,
5E73965C1DAFDAA400BA0A4D /* BackgroundCell.cpp in Sources */,
28D000A51A32920C00367B21 /* DeviceChange.cpp in Sources */,
28D8425C1AD8D69D00551353 /* SelectedRegion.cpp in Sources */,
2888A1631AE25F9A00E06FDC /* Diags.cpp in Sources */,

View File

@ -579,6 +579,8 @@ audacity_SOURCES = \
tracks/timetrack/ui/TimeTrackUI.cpp \
tracks/timetrack/ui/TimeTrackVRulerControls.cpp \
tracks/timetrack/ui/TimeTrackVRulerControls.h \
tracks/ui/BackgroundCell.cpp \
tracks/ui/BackgroundCell.h \
tracks/ui/ButtonHandle.h \
tracks/ui/ButtonHandle.cpp \
tracks/ui/CommonTrackPanelCell.cpp \

View File

@ -158,6 +158,7 @@ scroll information. It also has some status flags.
#include "toolbars/ToolsToolBar.h"
#include "toolbars/TranscriptionToolBar.h"
#include "tracks/ui/BackgroundCell.h"
#include "tracks/ui/EditCursorOverlay.h"
#include "tracks/ui/PlayIndicatorOverlay.h"
#include "tracks/ui/Scrubbing.h"
@ -1078,6 +1079,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mCursorOverlay = std::make_unique<EditCursorOverlay>(this);
mBackgroundCell = std::make_shared<BackgroundCell>(this);
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
mScrubOverlay = std::make_unique<ScrubbingOverlay>(this);
mScrubber = std::make_unique<Scrubber>(this);
@ -1107,6 +1110,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
CreateMenusAndCommands();
mTrackPanel->SetBackgroundCell(mBackgroundCell);
// LLL: When Audacity starts or becomes active after returning from
// another application, the first window that can accept focus
// will be given the focus even if we try to SetFocus(). By

View File

@ -102,6 +102,7 @@ enum class UndoPush : unsigned char;
class Track;
class WaveClip;
class BackgroundCell;
AudacityProject *CreateNewAudacityProject();
AUDACITY_DLL_API AudacityProject *GetActiveProject();
@ -764,6 +765,8 @@ private:
std::unique_ptr<Overlay>
mIndicatorOverlay, mCursorOverlay;
std::shared_ptr<BackgroundCell> mBackgroundCell;
#ifdef EXPERIMENTAL_SCRUBBING_BASIC
std::unique_ptr<Overlay> mScrubOverlay;
std::unique_ptr<Scrubber> mScrubber;

View File

@ -1458,22 +1458,13 @@ void TrackPanel::HandleCursor(wxMouseEvent & event)
if( SetCursorByActivity() )
return;
// (2) If we are not over a track at all, set the cursor to Arrow and
// clear the StatusBar,
const auto foundCell = FindCell( event.m_x, event.m_y );
auto &track = foundCell.pTrack;
auto &rect = foundCell.rect;
auto &pCell = foundCell.pCell;
wxCursor *pCursor = NULL;
if (!track) {
SetCursor(*mArrowCursor);
mListener->TP_DisplayStatusMessage(wxT(""));
return;
}
// (3) The easy cases are done.
// (2) The easy cases are done.
// Now we've got to hit-test against a number of different possibilities.
// We could be over the label or a vertical ruler etc...
@ -4174,14 +4165,6 @@ void TrackPanel::HandleTrackSpecificMouseEvent(wxMouseEvent & event)
return;
}
// AS: If the user clicked outside all tracks, make nothing
// selected.
if ((event.ButtonDown() || event.ButtonDClick()) && !pTrack) {
GetSelectionState().SelectNone( *mTracks, GetMixerBoard() );
Refresh(false);
return;
}
//Determine if user clicked on the track's left-hand label or ruler
if ( !( foundCell.type == CellType::Track ||
foundCell.type == CellType::Background ) ) {

View File

@ -0,0 +1,109 @@
/**********************************************************************
Audacity: A Digital Audio Editor
BackgroundCell.cpp
Paul Licameli split from TrackPanel.cpp
**********************************************************************/
#include "../../Audacity.h"
#include "BackgroundCell.h"
#include "../../HitTestResult.h"
#include "../../Project.h"
#include "../../RefreshCode.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../UIHandle.h"
#include <wx/cursor.h>
#include <wx/event.h>
namespace
{
// Define this, just so the click to deselect can dispatch here
class BackgroundHandle : public UIHandle
{
BackgroundHandle() {}
BackgroundHandle(const BackgroundHandle&) = delete;
BackgroundHandle &operator=(const BackgroundHandle&) = delete;
public:
static BackgroundHandle& Instance()
{
static BackgroundHandle instance;
return instance;
}
static HitTestPreview HitPreview()
{
static wxCursor arrowCursor{ wxCURSOR_ARROW };
return { {}, &arrowCursor };
}
static HitTestResult HitAnywhere()
{
return {
HitPreview(),
&BackgroundHandle::Instance()
};
}
virtual ~BackgroundHandle()
{}
Result Click
(const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
{
using namespace RefreshCode;
const wxMouseEvent &event = evt.event;
// Do not start a drag
Result result = Cancelled;
// AS: If the user clicked outside all tracks, make nothing
// selected.
if ((event.ButtonDown() || event.ButtonDClick())) {
pProject->GetSelectionState().SelectNone
( *pProject->GetTracks(), pProject->GetMixerBoard() );
result |= RefreshAll;
}
return result;
}
Result Drag
(const TrackPanelMouseEvent &, AudacityProject *) override
{ return RefreshCode::RefreshNone; }
HitTestPreview Preview
(const TrackPanelMouseEvent &, const AudacityProject *) override
{ return HitPreview(); }
Result Release
(const TrackPanelMouseEvent &, AudacityProject *,
wxWindow *) override
{ return RefreshCode::RefreshNone; }
Result Cancel(AudacityProject *) override
{ return RefreshCode::RefreshNone; }
};
}
BackgroundCell::~BackgroundCell()
{
}
HitTestResult BackgroundCell::HitTest
(const TrackPanelMouseEvent &,
const AudacityProject *)
{
return BackgroundHandle::HitAnywhere();
}
Track *BackgroundCell::FindTrack()
{
return nullptr;
}

View File

@ -0,0 +1,38 @@
/**********************************************************************
Audacity: A Digital Audio Editor
BackgroundCell.h
Paul Licameli split from TrackPanel.cpp
**********************************************************************/
#ifndef __AUDACITY_BACKGROUND_CELL__
#define __AUDACITY_BACKGROUND_CELL__
#include "CommonTrackPanelCell.h"
class AudacityProject;
class BackgroundCell final : public CommonTrackPanelCell
{
public:
BackgroundCell(AudacityProject *pProject)
: mpProject(pProject)
{}
virtual ~BackgroundCell();
protected:
HitTestResult HitTest
(const TrackPanelMouseEvent &event,
const AudacityProject *) override;
Track *FindTrack() override;
private:
AudacityProject *mpProject;
};
#endif

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -240,6 +240,7 @@
<ClCompile Include="..\..\..\src\tracks\timetrack\ui\TimeTrackControls.cpp" />
<ClCompile Include="..\..\..\src\tracks\timetrack\ui\TimeTrackUI.cpp" />
<ClCompile Include="..\..\..\src\tracks\timetrack\ui\TimeTrackVRulerControls.cpp" />
<ClCompile Include="..\..\..\src\tracks\ui\BackgroundCell.cpp" />
<ClCompile Include="..\..\..\src\tracks\ui\ButtonHandle.cpp" />
<ClCompile Include="..\..\..\src\tracks\ui\CommonTrackPanelCell.cpp" />
<ClCompile Include="..\..\..\src\tracks\ui\EditCursorOverlay.cpp" />
@ -505,6 +506,7 @@
<ClInclude Include="..\..\..\src\tracks\playabletrack\wavetrack\ui\WaveTrackControls.h" />
<ClInclude Include="..\..\..\src\tracks\playabletrack\wavetrack\ui\WaveTrackSliderHandles.h" />
<ClInclude Include="..\..\..\src\tracks\playabletrack\wavetrack\ui\WaveTrackVRulerControls.h" />
<ClInclude Include="..\..\..\src\tracks\ui\BackgroundCell.h" />
<ClInclude Include="..\..\..\src\tracks\ui\CommonTrackPanelCell.h" />
<ClInclude Include="..\..\..\src\tracks\labeltrack\ui\LabelTrackControls.h" />
<ClInclude Include="..\..\..\src\tracks\labeltrack\ui\LabelTrackVRulerControls.h" />

View File

@ -1022,6 +1022,9 @@
<ClCompile Include="..\..\..\src\tracks\ui\TrackButtonHandles.cpp">
<Filter>src\tracks\ui</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\tracks\ui\BackgroundCell.cpp">
<Filter>src\tracks\ui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\src\AboutDialog.h">
@ -2035,6 +2038,9 @@
<ClInclude Include="..\..\..\src\tracks\ui\TrackButtonHandles.h">
<Filter>src\tracks\ui</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\tracks\ui\BackgroundCell.h">
<Filter>src\tracks\ui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\audacity.ico">