1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-07 15:22:34 +02:00

Note track affordances

This commit is contained in:
Vitaly Sverchinsky 2021-07-15 14:41:57 +03:00 committed by Paul Licameli
parent 70a7238ee6
commit ff57fd53bc
5 changed files with 153 additions and 9 deletions

View File

@ -796,6 +796,8 @@ list( APPEND SOURCES
tracks/labeltrack/ui/LabelTrackVRulerControls.h
tracks/labeltrack/ui/LabelTrackView.cpp
tracks/labeltrack/ui/LabelTrackView.h
tracks/playabletrack/notetrack/ui/NoteTrackAffordanceControls.h
tracks/playabletrack/notetrack/ui/NoteTrackAffordanceControls.cpp
tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.cpp
tracks/playabletrack/notetrack/ui/NoteTrackButtonHandle.h
tracks/playabletrack/notetrack/ui/NoteTrackControls.cpp

View File

@ -0,0 +1,93 @@
/*!********************************************************************
*
Audacity: A Digital Audio Editor
NoteTrackAffordanceControls.cpp
Vitaly Sverchinsky
**********************************************************************/
#include "NoteTrackAffordanceControls.h"
#include <wx/dc.h>
#include "../../../ui/AffordanceHandle.h"
#include "../../../../AllThemeResources.h"
#include "../../../../AColor.h"
#include "../../../../NoteTrack.h"
#include "../../../../ViewInfo.h"
#include "../../../../TrackArtist.h"
#include "../../../../TrackPanelMouseEvent.h"
#include "../../../../TrackPanelDrawingContext.h"
#include "../lib-src/header-substitutes/allegro.h"
NoteTrackAffordanceControls::NoteTrackAffordanceControls(const std::shared_ptr<Track>& pTrack)
: CommonTrackCell(pTrack)
{
}
std::vector<UIHandlePtr> NoteTrackAffordanceControls::HitTest(const TrackPanelMouseState& state, const AudacityProject* pProject)
{
std::vector<UIHandlePtr> results;
auto track = FindTrack();
const auto nt = std::static_pointer_cast<const NoteTrack>(track->SubstitutePendingChangedTrack());
const auto rect = state.rect;
auto& zoomInfo = ViewInfo::Get(*pProject);
auto left = zoomInfo.TimeToPosition(nt->GetOffset(), rect.x);
auto right = zoomInfo.TimeToPosition(nt->GetOffset() + nt->GetSeq().get_real_dur(), rect.x);
auto headerRect = wxRect(left, rect.y, right - left, rect.height);
auto px = state.state.m_x;
auto py = state.state.m_y;
if (px >= headerRect.GetLeft() && px <= headerRect.GetRight() &&
py >= headerRect.GetTop() && py <= headerRect.GetBottom())
{
results.push_back(AffordanceHandle::HitAnywhere(mAffordanceHandle, track));
}
return results;
}
void NoteTrackAffordanceControls::Draw(TrackPanelDrawingContext& context, const wxRect& rect, unsigned iPass)
{
if (iPass == TrackArtist::PassBackground) {
const auto nt = std::static_pointer_cast<const NoteTrack>(FindTrack()->SubstitutePendingChangedTrack());
const auto artist = TrackArtist::Get(context);
TrackArt::DrawBackgroundWithSelection(context, rect, nt.get(), AColor::labelSelectedBrush, AColor::labelUnselectedBrush);
const auto& zoomInfo = *artist->pZoomInfo;
auto left = zoomInfo.TimeToPosition(nt->GetOffset(), rect.x);
auto right = zoomInfo.TimeToPosition(nt->GetOffset() + nt->GetSeq().get_real_dur(), rect.x);
auto clipRect = wxRect(left, rect.y, right - left + 1, rect.height);
auto px = context.lastState.m_x;
auto py = context.lastState.m_y;
auto selected = IsSelected();
auto highlight = selected ||
(px >= clipRect.GetLeft() && px <= clipRect.GetRight() &&
py >= clipRect.GetTop() && py <= clipRect.GetBottom());
context.dc.SetClippingRegion(rect);
TrackArt::DrawClipAffordance(context.dc, clipRect, highlight, selected);
context.dc.DestroyClippingRegion();
}
}
bool NoteTrackAffordanceControls::IsSelected() const
{
if (auto handle = mAffordanceHandle.lock())
{
return handle->Clicked();
}
return false;
}

View File

@ -0,0 +1,28 @@
/*!********************************************************************
*
Audacity: A Digital Audio Editor
NoteTrackAffordanceControls.h
Vitaly Sverchinsky
**********************************************************************/
#pragma once
#include "../../../ui/CommonTrackPanelCell.h"
class AffordanceHandle;
class AUDACITY_DLL_API NoteTrackAffordanceControls : public CommonTrackCell
{
std::weak_ptr<AffordanceHandle> mAffordanceHandle;
public:
NoteTrackAffordanceControls(const std::shared_ptr<Track>& pTrack);
std::vector<UIHandlePtr> HitTest(const TrackPanelMouseState& state, const AudacityProject* pProject) override;
void Draw(TrackPanelDrawingContext& context, const wxRect& rect, unsigned iPass) override;
bool IsSelected() const;
};

View File

@ -27,6 +27,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../ViewInfo.h"
#include "../../../ui/SelectHandle.h"
#include "StretchHandle.h"
#include "NoteTrackAffordanceControls.h"
#include <wx/dc.h>
@ -75,6 +76,11 @@ std::shared_ptr<TrackVRulerControls> NoteTrackView::DoGetVRulerControls()
#define TIME_TO_X(t) (zoomInfo.TimeToPosition((t), rect.x))
#define X_TO_TIME(xx) (zoomInfo.PositionToTime((xx), rect.x))
std::shared_ptr<CommonTrackCell> NoteTrackView::DoGetAffordanceControls()
{
return std::make_shared<NoteTrackAffordanceControls>(DoFindTrack());
}
namespace {
/*
@ -352,7 +358,8 @@ window and draw out-of-bounds notes here instead.
void DrawNoteTrack(TrackPanelDrawingContext &context,
const NoteTrack *track,
const wxRect & rect,
bool muted)
bool muted,
bool selected)
{
auto &dc = context.dc;
const auto artist = TrackArtist::Get( context );
@ -378,11 +385,6 @@ void DrawNoteTrack(TrackPanelDrawingContext &context,
int numPitches = (rect.height) / data.GetPitchHeight(1);
if (numPitches < 0) numPitches = 0; // cannot be negative
#ifdef EXPERIMENTAL_NOTETRACK_OVERLAY
TrackArt::DrawBackgroundWithSelection(context, rect, track,
AColor::labelSelectedBrush, AColor::labelUnselectedBrush);
#endif
// Background comes in 4 colors, that are now themed.
// 214, 214,214 -- unselected white keys
// 192,192,192 -- black keys
@ -704,6 +706,14 @@ void DrawNoteTrack(TrackPanelDrawingContext &context,
TrackArt::DrawNegativeOffsetTrackArrows( context, rect );
}
//draw clip edges
{
int left = TIME_TO_X(track->GetOffset());
int right = TIME_TO_X(track->GetOffset() + track->GetSeq().get_real_dur());
TrackArt::DrawClipEdges(dc, wxRect(left, rect.GetTop(), right - left + 1, rect.GetHeight()), selected);
}
dc.DestroyClippingRegion();
SonifyEndNoteForeground();
}
@ -723,7 +733,17 @@ void NoteTrackView::Draw(
const auto hasSolo = artist->hasSolo;
muted = (hasSolo || nt->GetMute()) && !nt->GetSolo();
#endif
DrawNoteTrack( context, nt.get(), rect, muted );
#ifdef EXPERIMENTAL_NOTETRACK_OVERLAY
TrackArt::DrawBackgroundWithSelection(context, rect, nt.get(), AColor::labelSelectedBrush, AColor::labelUnselectedBrush);
#endif
bool selected{ false };
if (auto affordance = std::dynamic_pointer_cast<NoteTrackAffordanceControls>(GetAffordanceControls()))
{
selected = affordance->IsSelected();
}
DrawNoteTrack(context, nt.get(), rect, muted, selected);
}
CommonTrackView::Draw( context, rect, iPass );
}

View File

@ -23,9 +23,10 @@ public:
NoteTrackView( const std::shared_ptr<Track> &pTrack );
~NoteTrackView() override;
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
private:
std::shared_ptr<TrackVRulerControls> DoGetVRulerControls() override;
std::shared_ptr<CommonTrackCell> DoGetAffordanceControls() override;
std::vector<UIHandlePtr> DetailedHitTest
(const TrackPanelMouseState &state,
const AudacityProject *pProject, int currentTool, bool bMultiTool)