src/tracks/labeltrack/ui/LabelTrackView.cpp
/// Draw calls other functions to draw the LabelTrack.
///   @param  dc the device context
///   @param  r  the LabelTrack rectangle.
Draw calls other functions to draw the LabelTrack.
Draw calls other functions to draw the LabelTrack .
void LabelTrackView::Draw
( TrackPanelDrawingContext &context, const wxRect & r ) const
{
   auto &dc = context.dc;
   const auto artist = TrackArtist::Get( context );
   const auto &zoomInfo = *artist->pZoomInfo;
   auto pHit = findHit( artist->parent );
   if(msFont.Ok())
      dc.SetFont(msFont);
   if (mFontHeight == -1)
      calculateFontHeight(dc);
   const auto pTrack = std::static_pointer_cast< const LabelTrack >(
      FindTrack()->SubstitutePendingChangedTrack());
   const auto &mLabels = pTrack->GetLabels();
   TrackArt::DrawBackgroundWithSelection( context, r, pTrack.get(),
      AColor::labelSelectedBrush, AColor::labelUnselectedBrush,
      ( pTrack->GetSelected() || pTrack->IsSyncLockSelected() ) );
   wxCoord textWidth, textHeight;
   for (const auto &labelStruct : mLabels) {
      dc.GetTextExtent(labelStruct.title, &textWidth, &textHeight);
      labelStruct.width = textWidth;
   }
   mTextHeight = dc.GetFontMetrics().ascent + dc.GetFontMetrics().descent;
   const int yFrameHeight = mTextHeight + TextFramePadding * 2;
   ComputeLayout( r, zoomInfo );
   dc.SetTextForeground(theTheme.Colour( clrLabelTrackText));
   dc.SetBackgroundMode(wxTRANSPARENT);
   dc.SetBrush(AColor::labelTextNormalBrush);
   dc.SetPen(AColor::labelSurroundPen);
   int GlyphLeft;
   int GlyphRight;
   for (const auto &labelStruct : mLabels)
      DrawLines( dc, labelStruct, r );
   { int i = -1; for (const auto &labelStruct : mLabels) { ++i;
      GlyphLeft=0;
      GlyphRight=1;
      if( pHit && i == pHit->mMouseOverLabelLeft )
         GlyphLeft = (pHit->mEdge & 4) ? 6:9;
      if( pHit && i == pHit->mMouseOverLabelRight )
         GlyphRight = (pHit->mEdge & 4) ? 7:4;
      DrawGlyphs( dc, labelStruct, r, GlyphLeft, GlyphRight );
   }}
   auto &project = *artist->parent->GetProject();
   {
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
      bool highlightTrack = false;
      auto target = dynamic_cast<LabelTextHandle*>(context.target.get());
      highlightTrack = target && target->GetTrack().get() == this;
#endif
      int i = -1; for (const auto &labelStruct : mLabels) { ++i;
         bool highlight = false;
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
         highlight = highlightTrack && target->GetLabelNum() == i;
#endif
         dc.SetBrush(mNavigationIndex == i || (pHit && pHit->mMouseOverLabel == i) 
            ? AColor::labelTextEditBrush : AColor::labelTextNormalBrush);
         DrawBar(dc, labelStruct, r);
         bool selected = mTextEditIndex == i;
         if (selected)
            dc.SetBrush(AColor::labelTextEditBrush);
         else if (highlight)
            dc.SetBrush(AColor::uglyBrush);
         else
            dc.SetBrush(AColor::labelTextNormalBrush);
         DrawTextBox(dc, labelStruct, r);
         dc.SetBrush(AColor::labelTextNormalBrush);
      }
   }
   if ( (mInitialCursorPos != mCurrentCursorPos) && IsValidIndex(mTextEditIndex, project))
   {
      int xpos1, xpos2;
      CalcHighlightXs(&xpos1, &xpos2);
      DrawHighlight(dc, mLabels[mTextEditIndex],
         xpos1, xpos2, dc.GetFontMetrics().ascent + dc.GetFontMetrics().descent);
   }
   { int i = -1; for (const auto &labelStruct : mLabels) { ++i;
      if(mTextEditIndex == i )
         dc.SetBrush(AColor::labelTextEditBrush);
      DrawText( dc, labelStruct, r );
      if(mTextEditIndex == i )
         dc.SetBrush(AColor::labelTextNormalBrush);
   }}
   if(mInitialCursorPos == mCurrentCursorPos && IsValidIndex(mTextEditIndex, project))
   {
      const auto &labelStruct = mLabels[mTextEditIndex];
      int xPos = labelStruct.xText;
      if( mCurrentCursorPos > 0)
      {
         int partWidth;
         dc.GetTextExtent(labelStruct.title.Left(mCurrentCursorPos), &partWidth, NULL);
         xPos += partWidth;
      }
      wxPen currentPen = dc.GetPen();
      const int CursorWidth=2;
      currentPen.SetWidth(CursorWidth);
      const auto top = labelStruct.y - (LabelBarHeight + yFrameHeight) / 2 + (yFrameHeight - mFontHeight) / 2 + TextFrameYOffset;
      AColor::Line(dc,
                   xPos-1, top,
                   xPos-1, top + mFontHeight);
      currentPen.SetWidth(1);
   }
}
void LabelTrackView :: Draw ( TrackPanelDrawingContext & context , const wxRect & r ) const { auto & dc = context . dc ; const auto artist = TrackArtist :: Get ( context ) ; const auto & zoomInfo = * artist -> pZoomInfo ; auto pHit = findHit ( artist -> parent ) ; if ( msFont . Ok ( ) ) dc . SetFont ( msFont ) ; if ( mFontHeight == -1 ) calculateFontHeight ( dc ) ; const auto pTrack = std :: static_pointer_cast < const LabelTrack > ( FindTrack ( ) -> SubstitutePendingChangedTrack ( ) ) ; const auto & mLabels = pTrack -> GetLabels ( ) ; TrackArt :: DrawBackgroundWithSelection ( context , r , pTrack . get ( ) , AColor :: labelSelectedBrush , AColor :: labelUnselectedBrush , ( pTrack -> GetSelected ( ) || pTrack -> IsSyncLockSelected ( ) ) ) ; wxCoord textWidth , textHeight ; for ( const auto & labelStruct : mLabels ) { dc . GetTextExtent ( labelStruct . title , & textWidth , & textHeight ) ; labelStruct . width = textWidth ; } mTextHeight = dc . GetFontMetrics ( ) . ascent + dc . GetFontMetrics ( ) . descent ; const int yFrameHeight = mTextHeight + TextFramePadding * 2 ; ComputeLayout ( r , zoomInfo ) ; dc . SetTextForeground ( theTheme . Colour ( clrLabelTrackText ) ) ; dc . SetBackgroundMode ( wxTRANSPARENT ) ; dc . SetBrush ( AColor :: labelTextNormalBrush ) ; dc . SetPen ( AColor :: labelSurroundPen ) ; int GlyphLeft ; int GlyphRight ; for ( const auto & labelStruct : mLabels ) DrawLines ( dc , labelStruct , r ) ; { int i = -1 ; for ( const auto & labelStruct : mLabels ) { ++ i ; GlyphLeft = 0 ; GlyphRight = 1 ; if ( pHit && i == pHit -> mMouseOverLabelLeft ) GlyphLeft = ( pHit -> mEdge & 4 ) ? 6 : 9 ; if ( pHit && i == pHit -> mMouseOverLabelRight ) GlyphRight = ( pHit -> mEdge & 4 ) ? 7 : 4 ; DrawGlyphs ( dc , labelStruct , r , GlyphLeft , GlyphRight ) ; } } auto & project = * artist -> parent -> GetProject ( ) ; { #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING bool highlightTrack = false ; auto target = dynamic_cast < LabelTextHandle * > ( context . target . get ( ) ) ; highlightTrack = target && target -> GetTrack ( ) . get ( ) == this ; #endif int i = -1 ; for ( const auto & labelStruct : mLabels ) { ++ i ; bool highlight = false ; #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING highlight = highlightTrack && target -> GetLabelNum ( ) == i ; #endif dc . SetBrush ( mNavigationIndex == i || ( pHit && pHit -> mMouseOverLabel == i ) ? AColor :: labelTextEditBrush : AColor :: labelTextNormalBrush ) ; DrawBar ( dc , labelStruct , r ) ; bool selected = mTextEditIndex == i ; if ( selected ) dc . SetBrush ( AColor :: labelTextEditBrush ) ; else if ( highlight ) dc . SetBrush ( AColor :: uglyBrush ) ; else dc . SetBrush ( AColor :: labelTextNormalBrush ) ; DrawTextBox ( dc , labelStruct , r ) ; dc . SetBrush ( AColor :: labelTextNormalBrush ) ; } } if ( ( mInitialCursorPos != mCurrentCursorPos ) && IsValidIndex ( mTextEditIndex , project ) ) { int xpos1 , xpos2 ; CalcHighlightXs ( & xpos1 , & xpos2 ) ; DrawHighlight ( dc , mLabels [ mTextEditIndex ] , xpos1 , xpos2 , dc . GetFontMetrics ( ) . ascent + dc . GetFontMetrics ( ) . descent ) ; } { int i = -1 ; for ( const auto & labelStruct : mLabels ) { ++ i ; if ( mTextEditIndex == i ) dc . SetBrush ( AColor :: labelTextEditBrush ) ; DrawText ( dc , labelStruct , r ) ; if ( mTextEditIndex == i ) dc . SetBrush ( AColor :: labelTextNormalBrush ) ; } } if ( mInitialCursorPos == mCurrentCursorPos && IsValidIndex ( mTextEditIndex , project ) ) { const auto & labelStruct = mLabels [ mTextEditIndex ] ; int xPos = labelStruct . xText ; if ( mCurrentCursorPos > 0 ) { int partWidth ; dc . GetTextExtent ( labelStruct . title . Left ( mCurrentCursorPos ) , & partWidth , NULL ) ; xPos += partWidth ; } wxPen currentPen = dc . GetPen ( ) ; const int CursorWidth = 2 ; currentPen . SetWidth ( CursorWidth ) ; const auto top = labelStruct . y - ( LabelBarHeight + yFrameHeight ) / 2 + ( yFrameHeight - mFontHeight ) / 2 + TextFrameYOffset ; AColor :: Line ( dc , xPos - 1 , top , xPos - 1 , top + mFontHeight ) ; currentPen . SetWidth ( 1 ) ; } }
Draw calls other functions to draw the LabelTrack.
Draw calls other functions to draw the LabelTrack .
// Get the text widths. // TODO: Make more efficient by only re-computing when a // text label title changes. // TODO: And this only needs to be done once, but we // do need the dc to do it. // We need to set mTextHeight to something sensible, // guarding against the case where there are no // labels or all are empty strings, which for example // happens with a NEW label track. // Now we draw the various items in this order, // so that the correct things overpaint each other. // Draw vertical lines that show where the end positions are. // Draw the end glyphs. // Draw the label boxes. // Draw highlights // Draw the text and the label boxes. // Draw the cursor, if there is one. // Calculate the width of the substring and add it to Xpos