1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-04 06:29:07 +02:00

Move drawing code for margins and separators

This commit is contained in:
Paul Licameli 2018-11-03 00:34:49 -04:00
parent b881a6e918
commit 1ca079b503
5 changed files with 86 additions and 135 deletions

View File

@ -70,6 +70,7 @@ public:
enum : unsigned {
PassTracks,
PassMargins,
NPasses
};

View File

@ -886,12 +886,6 @@ void TrackPanel::DrawTracks(wxDC * dc)
*dc, Target(), mLastMouseState, mTrackArtist.get()
};
// Draw margins on two or three sides.
ClearLeftAndRightMargins(context, clip);
if ( GetTracks()->Any() )
// This margin may may scrolled up out of view
ClearTopMargin( context, clip );
// Don't draw a bottom margin here.
const auto &settings = ProjectSettings::Get( *GetProject() );
@ -1039,12 +1033,9 @@ void TrackPanel::DrawOutside
wxRect rect = rec;
{
ClearSeparator(context, rect);
// Now exclude the resizer below
rect.height -= kSeparatorThickness;
int labelw = mViewInfo->GetLabelWidth();
int vrul = mViewInfo->GetVRulerOffset();
TrackInfo::DrawBackground( dc, rect, t->GetSelected(), vrul );
@ -1059,22 +1050,6 @@ void TrackPanel::DrawOutside
//}
DrawBordersAroundTrack( dc, rect );
{
auto channels = TrackList::Channels(t);
// omit last (perhaps, only) channel
--channels.second;
for (auto channel : channels) {
auto &view = TrackView::Get( *channel );
// draw the sash below this channel
auto yy =
view.GetY() - mViewInfo->vpos + view.GetHeight()
- kBottomMargin;
wxRect sashRect{
vrul, yy, rect.GetRight() - vrul, kSeparatorThickness
};
DrawSash( dc, sashRect, labelw, t->GetSelected() );
}
}
DrawShadow( dc, rect );
}
@ -1086,108 +1061,6 @@ void TrackPanel::DrawOutside
//mTrackInfo.DrawBordersWithin( dc, rect, *t );
}
void TrackPanel::ClearTopMargin
(TrackPanelDrawingContext &context, const wxRect &clip)
{
auto dc = &context.dc;
// Area above the first track if there is one
AColor::TrackPanelBackground(dc, false);
wxRect side{
clip.x + kLeftMargin,
-mViewInfo->vpos,
clip.width - ( kLeftMargin + kRightMargin ),
kTopMargin
};
if (side.Intersects(clip))
dc->DrawRectangle(side);
}
// Paint the inset areas of the whole panel, left and right, in a background
// color
void TrackPanel::ClearLeftAndRightMargins
(TrackPanelDrawingContext &context, const wxRect & clip)
{
auto dc = &context.dc;
// Fill in area outside of tracks
AColor::TrackPanelBackground(dc, false);
wxRect side;
// Area between panel border and left track border
side = clip;
side.width = kLeftMargin;
dc->DrawRectangle(side);
// Area between panel border and right track border
side = clip;
side.x += side.width - kRightMargin;
side.width = kRightMargin;
dc->DrawRectangle(side);
}
// Given rectangle should be the whole track rectangle
// Paint the separator area below in a background color
void TrackPanel::ClearSeparator
(TrackPanelDrawingContext &context, const wxRect & rect)
{
auto dc = &context.dc;
// Fill in area outside of the track
AColor::TrackPanelBackground(dc, false);
// Area below the track, where the resizer will be
auto height = kSeparatorThickness;
wxRect side{
rect.x,
rect.y + rect.height - height,
rect.width,
height
};
dc->DrawRectangle(side);
}
void TrackPanel::DrawSash(
wxDC * dc, const wxRect & rect, int labelw, bool bSelected )
{
// Area between channels of a group
// Paint the channel separator over (what would be) the lower border of this
// channel, down to and including the upper border of the next channel
ADCChanger cleanup{ dc };
// Paint the left part of the background
AColor::MediumTrackInfo(dc, bSelected);
dc->DrawRectangle( rect.GetX(), rect.GetY(), labelw, rect.GetHeight() );
// Stroke the left border
dc->SetPen(*wxBLACK_PEN);
{
const auto left = rect.GetLeft();
AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
}
AColor::TrackPanelBackground(dc, false);
wxRect rec{ rect };
rec.width -= labelw - rec.x;
rec.x = labelw;
dc->DrawRectangle( wxRect( rec ).Inflate( 0, -kBorderThickness ) );
// These lines stroke over what is otherwise "border" of each channel
dc->SetBrush(*wxTRANSPARENT_BRUSH);
dc->SetPen(*wxBLACK_PEN);
const auto left = rec.GetLeft();
const auto right = rec.GetRight();
const auto top = rec.GetTop();
const auto bottom = rec.GetBottom();
AColor::Line( *dc, left, top, right, top );
AColor::Line( *dc, left, bottom, right, bottom );
}
void TrackPanel::SetBackgroundCell
(const std::shared_ptr< TrackPanelCell > &pCell)
{
@ -1456,6 +1329,20 @@ struct EmptyCell final : CommonTrackPanelCell {
static auto instance = std::make_shared< EmptyCell >();
return instance;
}
// TrackPanelDrawable implementation
void Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass ) override
{
if ( iPass == TrackArtist::PassMargins ) {
// Draw a margin area of TrackPanel
auto dc = &context.dc;
AColor::TrackPanelBackground( dc, false );
dc->DrawRectangle( rect );
}
}
};
// A vertical ruler left of a channel

View File

@ -183,14 +183,6 @@ protected:
void HighlightFocusedTrack (wxDC* dc, const wxRect &rect);
void DrawShadow ( wxDC* dc, const wxRect & rect );
void DrawBordersAroundTrack(wxDC* dc, const wxRect & rect );
void ClearTopMargin (
TrackPanelDrawingContext &context, const wxRect &clip);
void ClearLeftAndRightMargins (
TrackPanelDrawingContext &context, const wxRect & clip);
void ClearSeparator (
TrackPanelDrawingContext &context, const wxRect & rect);
void DrawSash (
wxDC* dc, const wxRect & rect, int labelw, bool bSelected );
public:
// Set the object that performs catch-all event handling when the pointer

View File

@ -11,12 +11,18 @@ Paul Licameli split from TrackPanel.cpp
#include "Audacity.h"
#include "TrackPanelResizerCell.h"
#include "AColor.h"
#include "Track.h"
#include "TrackArtist.h"
#include "TrackPanelDrawingContext.h"
#include "TrackPanelResizeHandle.h"
#include "TrackPanelMouseEvent.h"
#include "HitTestResult.h"
#include "ViewInfo.h"
#include "tracks/ui/TrackView.h"
#include <wx/dc.h>
#include <wx/mousestate.h>
TrackPanelResizerCell::TrackPanelResizerCell(
@ -46,3 +52,63 @@ std::shared_ptr<Track> TrackPanelResizerCell::DoFindTrack()
return pView->FindTrack();
return {};
}
void TrackPanelResizerCell::Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass )
{
if ( iPass == TrackArtist::PassMargins ) {
auto pTrack = FindTrack();
if ( pTrack ) {
auto dc = &context.dc;
const bool last =
pTrack.get() == *TrackList::Channels( pTrack.get() ).rbegin();
if ( last ) {
// Fill in separator area below a track
AColor::TrackPanelBackground( dc, false );
dc->DrawRectangle( rect );
}
else {
// Area between channels of a group
// Paint the channel separator over (what would be) the lower border
// of this channel, down to and including the upper border of the
// next channel
ADCChanger cleanup{ dc };
// Paint the left part of the background
const auto artist = TrackArtist::Get( context );
auto labelw = artist->pZoomInfo->GetLabelWidth();
AColor::MediumTrackInfo( dc, pTrack->GetSelected() );
dc->DrawRectangle(
rect.GetX(), rect.GetY(), labelw, rect.GetHeight() );
// Stroke the left border
dc->SetPen(*wxBLACK_PEN);
{
const auto left = rect.GetLeft();
AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
}
AColor::TrackPanelBackground(dc, false);
wxRect rec{ rect };
rec.width -= labelw - rec.x;
rec.x = labelw;
dc->DrawRectangle( wxRect( rec ).Inflate( 0, -kBorderThickness ) );
// These lines stroke over what is otherwise "border" of each
// channel
dc->SetBrush(*wxTRANSPARENT_BRUSH);
dc->SetPen(*wxBLACK_PEN);
const auto left = rec.GetLeft();
const auto right = rec.GetRight();
const auto top = rec.GetTop();
const auto bottom = rec.GetBottom();
AColor::Line( *dc, left, top, right, top );
AColor::Line( *dc, left, bottom, right, bottom );
}
}
}
}

View File

@ -35,6 +35,11 @@ private:
// back-pointer is weak to break a cycle
std::weak_ptr<TrackView> mwView;
// TrackPanelDrawable implementation
void Draw(
TrackPanelDrawingContext &context,
const wxRect &rect, unsigned iPass ) override;
std::weak_ptr<TrackPanelResizeHandle> mResizeHandle;
};