1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 00:29:41 +02:00

Move drawing code for snap guidelines

This commit is contained in:
Paul Licameli 2019-06-21 15:10:11 -04:00
parent e6dae33038
commit dc216d669b
9 changed files with 55 additions and 108 deletions

View File

@ -72,6 +72,7 @@ public:
PassZooming,
PassBackground,
PassFocus,
PassSnapping,
NPasses
};

View File

@ -911,72 +911,9 @@ void TrackPanel::DrawTracks(wxDC * dc)
mTrackArtist->hasSolo = hasSolo;
this->CellularPanel::Draw( context, TrackArtist::NPasses );
// Draw the rest, including the click-to-deselect blank area below all
// tracks
DrawEverythingElse(context, region, clip);
TrackArt::DrawTrackNames( context, GetTracks(), region, clip );
}
/// Draws 'Everything else'. In particular it draws:
/// - Drop shadow for tracks and vertical rulers.
/// - Zooming Indicators.
/// - Fills in space below the tracks.
void TrackPanel::DrawEverythingElse(TrackPanelDrawingContext &context,
const wxRegion &region,
const wxRect & clip)
{
// We draw everything else
auto dc = &context.dc;
// Fix the horizontal extent, will vary the vertical:
wxRect trackRect{
kLeftMargin, 0, clip.width - (kLeftMargin + kRightMargin), 0
};
wxRect focusRect{};
// The loop below now groups each track with the margin BELOW it, to
// correspond better with the subdivision of panel area used in hit testing.
for ( auto leaderTrack : GetTracks()->Leaders< const Track >()
// Predicate is true iff any channel in the group is wholly or partly
// visible:
+ IsVisibleTrack{ GetProject() } ) {
const auto channels = TrackList::Channels(leaderTrack);
bool focused = false;
trackRect.height = 0;
bool first = true;
for (auto channel : channels) {
focused = focused || mAx->IsFocused(channel);
auto &view = TrackView::Get( *channel );
if (first)
first = false,
trackRect.y = view.GetY() - mViewInfo->vpos + kTopMargin;
trackRect.height += view.GetHeight();
}
if (focused) {
focusRect = trackRect;
focusRect.height -= kSeparatorThickness;
}
// Believe it or not, we can speed up redrawing if we don't
// redraw the vertical ruler when only the waveform data has
// changed. An example is during recording.
#if DEBUG_DRAW_TIMING
// wxRect rbox = region.GetBox();
// wxPrintf(wxT("Update Region: %d %d %d %d\n"),
// rbox.x, rbox.y, rbox.width, rbox.height);
#endif
}
auto target = Target();
if (target)
target->DrawExtras(UIHandle::Panel, dc, region, clip);
}
void TrackPanel::SetBackgroundCell
(const std::shared_ptr< TrackPanelCell > &pCell)
{

View File

@ -173,10 +173,6 @@ public:
protected:
void DrawTracks(wxDC * dc);
void DrawEverythingElse(TrackPanelDrawingContext &context,
const wxRegion & region,
const wxRect & clip);
public:
// Set the object that performs catch-all event handling when the pointer
// is not in any track or ruler or control panel.

View File

@ -41,11 +41,6 @@ bool UIHandle::Escape()
return false;
}
void UIHandle::DrawExtras
(DrawingPass, wxDC *, const wxRegion &, const wxRect &)
{
}
bool UIHandle::StopsOnKeystroke()
{
return false;

View File

@ -41,11 +41,6 @@ public:
// Future: may generalize away from current Track class
using Cell = TrackPanelCell;
// Argument for the drawing function
enum DrawingPass {
Panel,
};
virtual ~UIHandle() = 0;
// Before clicking, the handle is notified that it has been "hit"
@ -105,17 +100,6 @@ public:
// Cancelled in return flags has no effect.
virtual Result Cancel(AudacityProject *pProject) = 0;
// Draw extras over cells. Default does nothing.
// Supplies only the whole panel rectangle for now.
// If pass is Cells, then any drawing that extends outside the cells
// is later overlaid with the cell bevels and the empty background color.
// Otherwise (Panel), it is a later drawing pass that will not be overlaid.
// This is invoked on the hit test target even before it is clicked,
// and also during drag.
virtual void DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &updateRegion, const wxRect &panelRect);
// Whether to force Release (not Cancel!) of the drag when a
// keystroke command is about to be dispatched. Default is always false.
// When default is false, any remembered pointers to tracks should be

View File

@ -27,7 +27,9 @@ Paul Licameli split from TrackPanel.cpp
#include "../../RefreshCode.h"
#include "../../SelectUtilities.h"
#include "../../SelectionState.h"
#include "../../TrackArtist.h"
#include "../../TrackPanel.h"
#include "../../TrackPanelDrawingContext.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../ViewInfo.h"
#include "../../WaveClip.h"
@ -1009,19 +1011,30 @@ UIHandle::Result SelectHandle::Cancel(AudacityProject *pProject)
return RefreshCode::RefreshAll;
}
void SelectHandle::DrawExtras
(DrawingPass pass, wxDC * dc, const wxRegion &, const wxRect &)
void SelectHandle::Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass )
{
if (pass == Panel) {
if ( iPass == TrackArtist::PassSnapping ) {
auto &dc = context.dc;
// Draw snap guidelines if we have any
if ( mSnapManager ) {
auto coord1 = (mUseSnap || IsClicked()) ? mSnapStart.outCoord : -1;
auto coord2 = (!mUseSnap || !IsClicked()) ? -1 : mSnapEnd.outCoord;
mSnapManager->Draw( dc, coord1, coord2 );
mSnapManager->Draw( &dc, coord1, coord2 );
}
}
}
wxRect SelectHandle::DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass )
{
if ( iPass == TrackArtist::PassSnapping )
return MaximizeHeight( rect, panelRect );
else
return rect;
}
void SelectHandle::Connect(AudacityProject *pProject)
{
mTimerHandler = std::make_shared<TimerHandler>( this, pProject );

View File

@ -73,11 +73,6 @@ public:
Result Cancel(AudacityProject*) override;
void DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &updateRegion, const wxRect &panelRect)
override;
static UIHandle::Result NeedChangeHighlight
(const SelectHandle &oldState,
const SelectHandle &newState);
@ -116,6 +111,15 @@ public:
(SpectrumAnalyst &analyst,
ViewInfo &viewInfo, const WaveTrack *pTrack, bool up);
private:
// TrackPanelDrawable implementation
void Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass ) override;
wxRect DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass ) override;
//void ResetFreqSelectionPin
// (const ViewInfo &viewInfo, double hintFrequency, bool logF);

View File

@ -21,6 +21,8 @@ Paul Licameli split from TrackPanel.cpp
#include "../../ProjectHistory.h"
#include "../../ProjectSettings.h"
#include "../../RefreshCode.h"
#include "../../TrackArtist.h"
#include "../../TrackPanelDrawingContext.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../UndoManager.h"
#include "../../WaveClip.h"
@ -848,14 +850,25 @@ UIHandle::Result TimeShiftHandle::Cancel(AudacityProject *pProject)
return RefreshCode::RefreshAll;
}
void TimeShiftHandle::DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &, const wxRect &)
void TimeShiftHandle::Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass )
{
if (pass == Panel) {
if ( iPass == TrackArtist::PassSnapping ) {
auto &dc = context.dc;
// Draw snap guidelines if we have any
if ( mSnapManager )
mSnapManager->Draw
( dc, mClipMoveState.snapLeft, mClipMoveState.snapRight );
if ( mSnapManager ) {
mSnapManager->Draw(
&dc, mClipMoveState.snapLeft, mClipMoveState.snapRight );
}
}
}
wxRect TimeShiftHandle::DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass )
{
if ( iPass == TrackArtist::PassSnapping )
return MaximizeHeight( rect, panelRect );
else
return rect;
}

View File

@ -102,13 +102,17 @@ public:
Result Cancel(AudacityProject *pProject) override;
void DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &, const wxRect &panelRect) override;
bool StopsOnKeystroke() override { return true; }
private:
// TrackPanelDrawable implementation
void Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass ) override;
wxRect DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass ) override;
std::shared_ptr<Track> mCapturedTrack;
wxRect mRect{};