src/TrackArtist.cpp
// Draws the sync-lock bitmap, tiled; always draws stationary relative to the DC
//
// AWD: now that the tiles don't link together, we're drawing a tilted grid, at
// two steps down for every one across. This creates a pattern that repeats in
// 5-step by 5-step boxes. Because we're only drawing in 5/25 possible positions
// we have a grid spacing somewhat smaller than the image dimensions. Thus we
// achieve lower density than with a square grid and eliminate edge cases where
// no tiles are displayed.
//
// The pattern draws in tiles at (0,0), (2,1), (4,2), (1,3), and (3,4) in each
// 5x5 box.
//
// There may be a better way to do this, or a more appealing pattern.
Draws the sync-lock bitmap, tiled; always draws stationary relative to the DC
AWD: now that the tiles don't link together, we're drawing a tilted grid, at
two steps down for every one across. This creates a pattern that repeats in
5-step by 5-step boxes. Because we're only drawing in 5/25 possible positions
we have a grid spacing somewhat smaller than the image dimensions. Thus we
achieve lower density than with a square grid and eliminate edge cases where
no tiles are displayed.



There may be a better way to do this, or a more appealing pattern.
Draws the sync - lock bitmap tiled ; always draws stationary relative to the DC AWD : now that the tiles don ' t link together we ' re drawing a tilted grid at two steps down for every one across . This creates a pattern that repeats in 5 - step by 5 - step boxes . Because we ' re only drawing in 5 / 25 possible positions we have a grid spacing somewhat smaller than the image dimensions . Thus we achieve lower density than with a square grid and eliminate edge cases where no tiles are displayed . There may be a better way to do this or a more appealing pattern .
void TrackArt::DrawSyncLockTiles(
   TrackPanelDrawingContext &context, const wxRect &rect )
{
   const auto dc = &context.dc;
   wxBitmap syncLockBitmap(theTheme.Image(bmpSyncLockSelTile));
   int gridW = syncLockBitmap.GetWidth() - 6;
   int gridH = syncLockBitmap.GetHeight() - 8;
   int blockX = (rect.x / gridW) % 5;
   int xOffset = rect.x % gridW;
   if (xOffset < 0) xOffset += gridW;
   bool extraCol = false;
   if (syncLockBitmap.GetWidth() - gridW > xOffset) {
      extraCol = true;
      xOffset += gridW;
      blockX = (blockX - 1) % 5;
   }
   if (blockX < 0) blockX += 5;
   int xx = 0;
   while (xx < rect.width) {
      int width = syncLockBitmap.GetWidth() - xOffset;
      if (xx + width > rect.width)
         width = rect.width - xx;
       Draw each row in this column
       Vertical position in the grid, modulo its period
      int blockY = (rect.y / gridH) % 5;
       Amount to offset drawing of first row
      int yOffset = rect.y % gridH;
      if (yOffset < 0) yOffset += gridH;
       Check if we're missing an extra row on top (this can happen because
       the tiles are bigger than the grid spacing)
      bool extraRow = false;
      if (syncLockBitmap.GetHeight() - gridH > yOffset) {
         extraRow = true;
         yOffset += gridH;
         blockY = (blockY - 1) % 5;
      }
       Make sure blockY is non-negative
      if (blockY < 0) blockY += 5;
      int yy = 0;
      while (yy < rect.height)
      {
         int height = syncLockBitmap.GetHeight() - yOffset;
         if (yy + height > rect.height)
            height = rect.height - yy;
          AWD: draw blocks according to our pattern
         if ((blockX == 0 && blockY == 0) || (blockX == 2 && blockY == 1) ||
             (blockX == 4 && blockY == 2) || (blockX == 1 && blockY == 3) ||
             (blockX == 3 && blockY == 4))
         {
             Do we need to get a sub-bitmap?
            if (width != syncLockBitmap.GetWidth() || height != syncLockBitmap.GetHeight()) {
               wxBitmap subSyncLockBitmap =
                  syncLockBitmap.GetSubBitmap(wxRect(xOffset, yOffset, width, height));
               dc->DrawBitmap(subSyncLockBitmap, rect.x + xx, rect.y + yy, true);
            }
            else {
               dc->DrawBitmap(syncLockBitmap, rect.x + xx, rect.y + yy, true);
            }
         }
          Updates for next row
         if (extraRow) {
             Second offset row, still at y = 0; no more extra rows
            yOffset -= gridH;
            extraRow = false;
         }
         else {
             Move on in y, no more offset rows
            yy += gridH - yOffset;
            yOffset = 0;
         }
         blockY = (blockY + 1) % 5;
      }
       Updates for next column
      if (extraCol) {
          Second offset column, still at x = 0; no more extra columns
         xOffset -= gridW;
         extraCol = false;
      }
      else {
          Move on in x, no more offset rows
         xx += gridW - xOffset;
         xOffset = 0;
      }
      blockX = (blockX + 1) % 5;
   }
}
void TrackArt :: DrawSyncLockTiles ( TrackPanelDrawingContext & context , const wxRect & rect ) { const auto dc = & context . dc ; wxBitmap syncLockBitmap ( theTheme . Image ( bmpSyncLockSelTile ) ) ; int gridW = syncLockBitmap . GetWidth ( ) - 6 ; int gridH = syncLockBitmap . GetHeight ( ) - 8 ; int blockX = ( rect . x / gridW ) % 5 ; int xOffset = rect . x % gridW ; if ( xOffset < 0 ) xOffset += gridW ; bool extraCol = false ; if ( syncLockBitmap . GetWidth ( ) - gridW > xOffset ) { extraCol = true ; xOffset += gridW ; blockX = ( blockX - 1 ) % 5 ; } if ( blockX < 0 ) blockX += 5 ; int xx = 0 ; while ( xx < rect . width ) { int width = syncLockBitmap . GetWidth ( ) - xOffset ; if ( xx + width > rect . width ) width = rect . width - xx ; int blockY = ( rect . y / gridH ) % 5 ; int yOffset = rect . y % gridH ; if ( yOffset < 0 ) yOffset += gridH ; bool extraRow = false ; if ( syncLockBitmap . GetHeight ( ) - gridH > yOffset ) { extraRow = true ; yOffset += gridH ; blockY = ( blockY - 1 ) % 5 ; } if ( blockY < 0 ) blockY += 5 ; int yy = 0 ; while ( yy < rect . height ) { int height = syncLockBitmap . GetHeight ( ) - yOffset ; if ( yy + height > rect . height ) height = rect . height - yy ; if ( ( blockX == 0 && blockY == 0 ) || ( blockX == 2 && blockY == 1 ) || ( blockX == 4 && blockY == 2 ) || ( blockX == 1 && blockY == 3 ) || ( blockX == 3 && blockY == 4 ) ) { if ( width != syncLockBitmap . GetWidth ( ) || height != syncLockBitmap . GetHeight ( ) ) { wxBitmap subSyncLockBitmap = syncLockBitmap . GetSubBitmap ( wxRect ( xOffset , yOffset , width , height ) ) ; dc -> DrawBitmap ( subSyncLockBitmap , rect . x + xx , rect . y + yy , true ) ; } else { dc -> DrawBitmap ( syncLockBitmap , rect . x + xx , rect . y + yy , true ) ; } } if ( extraRow ) { yOffset -= gridH ; extraRow = false ; } else { yy += gridH - yOffset ; yOffset = 0 ; } blockY = ( blockY + 1 ) % 5 ; } if ( extraCol ) { xOffset -= gridW ; extraCol = false ; } else { xx += gridW - xOffset ; xOffset = 0 ; } blockX = ( blockX + 1 ) % 5 ; } }
Draws the sync-lock bitmap, tiled; always draws stationary relative to the DC
AWD: now that the tiles don't link together, we're drawing a tilted grid, at
two steps down for every one across.
Draws the sync - lock bitmap tiled ; always draws stationary relative to the DC AWD : now that the tiles don ' t link together we ' re drawing a tilted grid at two steps down for every one across .
// Grid spacing is a bit smaller than actual image size // Horizontal position within the grid, modulo its period // Amount to offset drawing of first column // Check if we're missing an extra column to the left (this can happen // because the tiles are bigger than the grid spacing) // Make sure blockX is non-negative // // Draw each row in this column // // Vertical position in the grid, modulo its period // Amount to offset drawing of first row // Check if we're missing an extra row on top (this can happen because // the tiles are bigger than the grid spacing) // Make sure blockY is non-negative // AWD: draw blocks according to our pattern // Do we need to get a sub-bitmap? // Updates for next row // Second offset row, still at y = 0; no more extra rows // Move on in y, no more offset rows // Updates for next column // Second offset column, still at x = 0; no more extra columns // Move on in x, no more offset rows