From fccb832e2de09c6c6aa7e823c6dc6032933795c6 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 4 Nov 2018 09:21:51 -0500 Subject: [PATCH] Move drawing code for track borders and shadows --- src/TrackArtist.h | 1 + src/TrackPanel.cpp | 104 +++++++++++++++++++++++---------------------- src/TrackPanel.h | 2 - 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/TrackArtist.h b/src/TrackArtist.h index 78f11c39a..55c0b307c 100644 --- a/src/TrackArtist.h +++ b/src/TrackArtist.h @@ -71,6 +71,7 @@ public: enum : unsigned { PassTracks, PassMargins, + PassBorders, NPasses }; diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 66f92ede8..088571d90 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1032,23 +1032,17 @@ void TrackPanel::DrawOutside // Start with whole track rect wxRect rect = rec; - { - // Now exclude the resizer below - rect.height -= kSeparatorThickness; + // Now exclude the resizer below + rect.height -= kSeparatorThickness; - // Vaughan, 2010-08-24: No longer doing this. - // Draw sync-lock tiles in ruler area. - //if (t->IsSyncLockSelected()) { - // wxRect tileFill = rect; - // tileFill.x = mViewInfo->GetVRulerOffset(); - // tileFill.width = mViewInfo->GetVRulerWidth(); - // TrackArt::DrawSyncLockTiles(dc, tileFill); - //} - - DrawBordersAroundTrack( dc, rect ); - - DrawShadow( dc, rect ); - } + // Vaughan, 2010-08-24: No longer doing this. + // Draw sync-lock tiles in ruler area. + //if (t->IsSyncLockSelected()) { + // wxRect tileFill = rect; + // tileFill.x = mViewInfo->GetVRulerOffset(); + // tileFill.width = mViewInfo->GetVRulerWidth(); + // TrackArt::DrawSyncLockTiles(dc, tileFill); + //} // Draw things within the track control panel rect.width = kTrackInfoWidth; @@ -1244,41 +1238,6 @@ void TrackPanel::VerticalScroll( float fracPosition){ } -// Draw a rectangular border -void TrackPanel::DrawBordersAroundTrack( wxDC * dc, const wxRect & rect ) -{ - // Border around track and label area - // leaving room for the shadow - dc->SetBrush(*wxTRANSPARENT_BRUSH); - dc->SetPen(*wxBLACK_PEN); - dc->DrawRectangle( rect.Inflate( kBorderThickness, kBorderThickness ) ); -} - -// Given rectangle is the track rectangle excluding the border -// Stroke lines along bottom and right, which are slightly short at -// bottom-left and top-right -void TrackPanel::DrawShadow( wxDC * dc, const wxRect & rect ) -{ - int right = rect.GetRight() + kBorderThickness + kShadowThickness; - int bottom = rect.GetBottom() + kBorderThickness + kShadowThickness; - - // shadow color for lines - dc->SetPen(*wxBLACK_PEN); - - // bottom - AColor::Line(*dc, rect.x, bottom, right, bottom); - // right - AColor::Line(*dc, right, rect.y, right, bottom); - - // background color erases small parts of those lines - AColor::TrackPanelBackground(dc, false); - - // bottom-left - AColor::Line(*dc, rect.x, bottom, rect.x + 1, bottom); - // top-right - AColor::Line(*dc, right, rect.y, right, rect.y + 1); -} - namespace { /* @@ -1402,6 +1361,49 @@ struct LabeledChannelGroup final : TrackPanelGroup { { rect.GetLeft() + kTrackInfoWidth, std::make_shared< ChannelGroup >( mpTrack, mLeftOffset ) } } }; } + + // TrackPanelDrawable impementation + void Draw( TrackPanelDrawingContext &context, + const wxRect &rect, unsigned iPass ) override + { + if ( iPass == TrackArtist::PassBorders ) { + auto &dc = context.dc; + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.SetPen(*wxBLACK_PEN); + + // border + dc.DrawRectangle( + rect.x, rect.y, + rect.width - kShadowThickness, rect.height - kShadowThickness + ); + + // shadow + // Stroke lines along bottom and right, which are slightly short at + // bottom-left and top-right + const auto right = rect.GetRight(); + const auto bottom = rect.GetBottom(); + + // bottom + AColor::Line(dc, rect.x + 2, bottom, right, bottom); + // right + AColor::Line(dc, right, rect.y + 2, right, bottom); + } + } + + wxRect DrawingArea( + const wxRect &rect, const wxRect &, unsigned iPass ) override + { + if ( iPass == TrackArtist::PassBorders ) + return { + rect.x - kBorderThickness, + rect.y - kBorderThickness, + rect.width + 2 * kBorderThickness + kShadowThickness, + rect.height + 2 * kBorderThickness + kShadowThickness + }; + else + return rect; + } + std::shared_ptr< Track > mpTrack; wxCoord mLeftOffset; }; diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 9dc41cbbb..3c524c2e4 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -181,8 +181,6 @@ protected: const Track *leaderTrack, const wxRect & teamRect); void HighlightFocusedTrack (wxDC* dc, const wxRect &rect); - void DrawShadow ( wxDC* dc, const wxRect & rect ); - void DrawBordersAroundTrack(wxDC* dc, const wxRect & rect ); public: // Set the object that performs catch-all event handling when the pointer