1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-06 23:02:42 +02:00

Move drawing code for zoom guidelines

This commit is contained in:
Paul Licameli 2018-11-04 15:24:17 -05:00
parent 488cb466c3
commit f84d92f0a8
11 changed files with 124 additions and 65 deletions

View File

@ -69,6 +69,7 @@ public:
PassMargins, PassMargins,
PassBorders, PassBorders,
PassControls, PassControls,
PassZooming,
NPasses NPasses
}; };

View File

@ -972,8 +972,6 @@ void TrackPanel::DrawEverythingElse(TrackPanelDrawingContext &context,
} }
auto target = Target(); auto target = Target();
if (target)
target->DrawExtras(UIHandle::Cells, dc, region, clip);
// Paint over the part below the tracks // Paint over the part below the tracks
trackRect.y += trackRect.height; trackRect.y += trackRect.height;

View File

@ -43,7 +43,6 @@ public:
// Argument for the drawing function // Argument for the drawing function
enum DrawingPass { enum DrawingPass {
Cells,
Panel, Panel,
}; };

View File

@ -21,6 +21,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../Project.h" #include "../../../../Project.h"
#include "../../../../ProjectHistory.h" #include "../../../../ProjectHistory.h"
#include "../../../../RefreshCode.h" #include "../../../../RefreshCode.h"
#include "../../../../TrackArtist.h"
#include "../../../../TrackPanelMouseEvent.h" #include "../../../../TrackPanelMouseEvent.h"
#include "../../../../widgets/PopupMenuTable.h" #include "../../../../widgets/PopupMenuTable.h"
#include "../../../../../images/Cursors.h" #include "../../../../../images/Cursors.h"
@ -356,16 +357,27 @@ UIHandle::Result NoteTrackVZoomHandle::Cancel(AudacityProject *WXUNUSED(pProject
return RefreshCode::RefreshAll; return RefreshCode::RefreshAll;
} }
void NoteTrackVZoomHandle::DrawExtras void NoteTrackVZoomHandle::Draw(
(DrawingPass pass, wxDC * dc, const wxRegion &, const wxRect &panelRect) TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass )
{ {
if ( iPass == TrackArtist::PassZooming ) {
if (!mpTrack.lock()) //? TrackList::Lock() if (!mpTrack.lock()) //? TrackList::Lock()
return; return;
if ( pass == UIHandle::Cells && if ( IsDragZooming( mZoomStart, mZoomEnd ) )
IsDragZooming( mZoomStart, mZoomEnd ) )
TrackVRulerControls::DrawZooming TrackVRulerControls::DrawZooming
( dc, mRect, panelRect, mZoomStart, mZoomEnd ); ( context, rect, mZoomStart, mZoomEnd );
}
}
wxRect NoteTrackVZoomHandle::DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass )
{
if ( iPass == TrackArtist::PassZooming )
return TrackVRulerControls::ZoomingArea( rect, panelRect );
else
return rect;
} }
#endif #endif

View File

@ -54,12 +54,15 @@ public:
Result Cancel(AudacityProject *pProject) override; Result Cancel(AudacityProject *pProject) override;
void DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &updateRegion, const wxRect &panelRect)
override;
private: 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::weak_ptr<NoteTrack> mpTrack; std::weak_ptr<NoteTrack> mpTrack;
int mZoomStart, mZoomEnd; int mZoomStart, mZoomEnd;

View File

@ -22,6 +22,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../Project.h" #include "../../../../Project.h"
#include "../../../../ProjectHistory.h" #include "../../../../ProjectHistory.h"
#include "../../../../RefreshCode.h" #include "../../../../RefreshCode.h"
#include "../../../../TrackArtist.h"
#include "../../../../TrackPanelMouseEvent.h" #include "../../../../TrackPanelMouseEvent.h"
#include "../../../../WaveTrack.h" #include "../../../../WaveTrack.h"
#include "../../../../widgets/PopupMenuTable.h" #include "../../../../widgets/PopupMenuTable.h"
@ -706,15 +707,25 @@ UIHandle::Result WaveTrackVZoomHandle::Cancel(AudacityProject*)
return RefreshCode::RefreshAll; return RefreshCode::RefreshAll;
} }
void WaveTrackVZoomHandle::DrawExtras void WaveTrackVZoomHandle::Draw(
(DrawingPass pass, wxDC * dc, const wxRegion &, const wxRect &panelRect) TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass )
{ {
if (!mpTrack.lock()) // TrackList::Lock()? if ( iPass == TrackArtist::PassZooming ) {
if (!mpTrack.lock()) //? TrackList::Lock()
return; return;
if ( pass == UIHandle::Cells && if ( IsDragZooming( mZoomStart, mZoomEnd ) )
IsDragZooming( mZoomStart, mZoomEnd ) )
TrackVRulerControls::DrawZooming TrackVRulerControls::DrawZooming
( dc, mRect, panelRect, mZoomStart, mZoomEnd ); ( context, rect, mZoomStart, mZoomEnd );
}
} }
wxRect WaveTrackVZoomHandle::DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass )
{
if ( iPass == TrackArtist::PassZooming )
return TrackVRulerControls::ZoomingArea( rect, panelRect );
else
return rect;
}

View File

@ -57,12 +57,16 @@ public:
Result Cancel(AudacityProject *pProject) override; Result Cancel(AudacityProject *pProject) override;
void DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &updateRegion, const wxRect &panelRect)
override;
private: 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::weak_ptr<WaveTrack> mpTrack; std::weak_ptr<WaveTrack> mpTrack;
int mZoomStart{}, mZoomEnd{}; int mZoomStart{}, mZoomEnd{};

View File

@ -68,25 +68,40 @@ std::vector<UIHandlePtr> TrackVRulerControls::HitTest
} }
void TrackVRulerControls::DrawZooming void TrackVRulerControls::DrawZooming
( wxDC *dc, const wxRect &cellRect, const wxRect &panelRect, ( TrackPanelDrawingContext &context, const wxRect &rect_,
int zoomStart, int zoomEnd ) int zoomStart, int zoomEnd )
{ {
// Draw a dashed rectangle, its right side disappearing in the black right // Draw a dashed rectangle, its right side disappearing in the black right
// border of the track area, which is not part of this cell but right of it. // border of the track area, which is not part of this cell but right of it.
wxRect rect; auto &dc = context.dc;
dc->SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc->SetPen(*wxBLACK_DASHED_PEN); dc.SetPen(*wxBLACK_DASHED_PEN);
rect.y = std::min( zoomStart, zoomEnd); wxRect rect {
rect.height = 1 + abs( zoomEnd - zoomStart); rect_.x,
std::min( zoomStart, zoomEnd),
rect_.width,
1 + abs( zoomEnd - zoomStart)
};
rect.x = cellRect.x; dc.DrawRectangle(rect);
}
wxRect TrackVRulerControls::ZoomingArea(
const wxRect &rect, const wxRect &panelRect )
{
// TODO: Don't use the constant kRightMargin, but somehow discover the // TODO: Don't use the constant kRightMargin, but somehow discover the
// neighboring track rectangle // neighboring track rectangle
rect.SetRight(panelRect.GetWidth() - kRightMargin); return {
// Left edge of the rectangle disappears in the vertical line at
dc->DrawRectangle(rect); // left edge of the ruler
rect.x,
rect.y,
// Extend the dashed rectangle right up to the track border
(panelRect.width - kRightMargin + kBorderThickness) - rect.x,
rect.height
};
} }
void TrackVRulerControls::Draw( void TrackVRulerControls::Draw(

View File

@ -39,9 +39,11 @@ public:
(const TrackPanelMouseState &state, (const TrackPanelMouseState &state,
const AudacityProject *pProject) override; const AudacityProject *pProject) override;
// Helpers for handle classes' TrackPanelDrawable implementations
static void DrawZooming static void DrawZooming
( wxDC *dc, const wxRect &cellRect, const wxRect &panelRect, ( TrackPanelDrawingContext &context, const wxRect &rect,
int zoomStart, int zoomEnd); int zoomStart, int zoomEnd);
static wxRect ZoomingArea( const wxRect &rect, const wxRect &panelRect );
// Modify the ruler rectangle, and related display parameters, // Modify the ruler rectangle, and related display parameters,
// cached in the associated track // cached in the associated track

View File

@ -19,6 +19,8 @@ Paul Licameli split from TrackPanel.cpp
#include "../../HitTestResult.h" #include "../../HitTestResult.h"
#include "../../RefreshCode.h" #include "../../RefreshCode.h"
#include "../../TrackArtist.h"
#include "../../TrackPanelDrawingContext.h"
#include "../../TrackPanelMouseEvent.h" #include "../../TrackPanelMouseEvent.h"
#include "../../ViewInfo.h" #include "../../ViewInfo.h"
#include "../../../images/Cursors.h" #include "../../../images/Cursors.h"
@ -183,29 +185,37 @@ UIHandle::Result ZoomHandle::Cancel(AudacityProject*)
return RefreshCode::RefreshAll; return RefreshCode::RefreshAll;
} }
void ZoomHandle::DrawExtras void ZoomHandle::Draw(
(DrawingPass pass, wxDC * dc, const wxRegion &, const wxRect &panelRect) TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass )
{ {
if (pass == Cells) { if ( iPass == TrackArtist::PassZooming &&
// PRL: Draw dashed lines only if we would zoom in // PRL: Draw dashed lines only if we would zoom in
// for button up. // for button up.
if (!IsDragZooming()) IsDragZooming() ) {
return; auto &dc = context.dc;
dc.SetBrush(*wxTRANSPARENT_BRUSH);
wxRect rect; dc.SetPen(*wxBLACK_DASHED_PEN);
// Make the top and bottom of the dashed rectangle disappear out of
dc->SetBrush(*wxTRANSPARENT_BRUSH); // bounds, so that you only see vertical dashed lines.
dc->SetPen(*wxBLACK_DASHED_PEN); dc.DrawRectangle( {
std::min(mZoomStart, mZoomEnd),
rect.x = std::min(mZoomStart, mZoomEnd); rect.y - 1,
rect.width = 1 + abs(mZoomEnd - mZoomStart); 1 + abs(mZoomEnd - mZoomStart),
rect.y = -1; rect.height + 2
rect.height = panelRect.height + 2; } );
dc->DrawRectangle(rect);
} }
} }
wxRect ZoomHandle::DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass )
{
if ( iPass == TrackArtist::PassZooming )
return MaximizeHeight( rect, panelRect );
else
return rect;
}
bool ZoomHandle::IsDragZooming() const bool ZoomHandle::IsDragZooming() const
{ {
const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click. const int DragThreshold = 3;// Anything over 3 pixels is a drag, else a click.

View File

@ -50,12 +50,16 @@ public:
Result Cancel(AudacityProject *pProject) override; Result Cancel(AudacityProject *pProject) override;
void DrawExtras
(DrawingPass pass,
wxDC * dc, const wxRegion &updateRegion, const wxRect &panelRect)
override;
private: private:
// TrackPanelDrawable implementation
void Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass ) override;
wxRect DrawingArea(
const wxRect &rect, const wxRect &panelRect, unsigned iPass ) override;
bool IsDragZooming() const; bool IsDragZooming() const;
int mZoomStart{}, mZoomEnd{}; int mZoomStart{}, mZoomEnd{};