diff --git a/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs index 5c4b6f138..bbf77025a 100644 --- a/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs +++ b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs @@ -30,7 +30,7 @@ namespace ClassicalSharp { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); - Brush shadowBrush = GetOrCreateBrush( Color.Black ); + Brush shadowBrush = GetOrCreateBrush( FastColour.Black ); float textX = x; for( int i = 0; i < parts.Count; i++ ) { TextPart part = parts[i]; @@ -47,7 +47,7 @@ namespace ClassicalSharp { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); - Brush shadowBrush = GetOrCreateBrush( Color.Black ); + Brush shadowBrush = GetOrCreateBrush( FastColour.Black ); StringFormatFlags flags = format.FormatFlags; format.FormatFlags |= StringFormatFlags.NoWrap; format.Trimming = StringTrimming.EllipsisCharacter; diff --git a/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs index 8fbc761b0..af1d74152 100644 --- a/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs +++ b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs @@ -92,13 +92,13 @@ namespace ClassicalSharp { DisposeBitmappedText(); } - SolidBrush GetOrCreateBrush( Color color ) { - int key = color.ToArgb(); + SolidBrush GetOrCreateBrush( FastColour col ) { + int key = col.ToArgb(); SolidBrush brush; if( brushCache.TryGetValue( key, out brush ) ) return brush; - brush = new SolidBrush( color ); + brush = new SolidBrush( col ); brushCache[key] = brush; return brush; } diff --git a/Launcher2/Gui/Drawer2DExt.cs b/Launcher2/Gui/Drawer2DExt.cs index c0b7581a5..0e8b387f4 100644 --- a/Launcher2/Gui/Drawer2DExt.cs +++ b/Launcher2/Gui/Drawer2DExt.cs @@ -38,6 +38,30 @@ namespace Launcher { } } + public unsafe static void DrawScaledPixels( FastBitmap src, FastBitmap dst, Size scale, + Rectangle srcRect, Rectangle dstRect ) { + int srcWidth = srcRect.Width, dstWidth = dstRect.Width; + int srcHeight = srcRect.Height, dstHeight = dstRect.Height; + int srcX = srcRect.X, dstX = dstRect.X; + int srcY = srcRect.Y, dstY = dstRect.Y; + int scaleWidth = scale.Width, scaleHeight = scale.Height; + + if( dstX >= dst.Width || dstY >= dst.Height ) return; + dstWidth = Math.Min( dstX + dstWidth, dst.Width ) - dstX; + dstHeight = Math.Min( dstY + dstHeight, dst.Height ) - dstY; + + for( int yy = 0; yy < dstHeight; yy++ ) { + int scaledY = (yy + dstRect.Y) * srcHeight / scaleHeight; + int* srcRow = src.GetRowPtr( srcY + (scaledY % srcHeight) ); + int* dstRow = dst.GetRowPtr( dstY + yy ); + + for( int xx = 0; xx < dstWidth; xx++ ) { + int scaledX = (xx + dstRect.X) * srcWidth / scaleWidth; + dstRow[dstX + xx] = srcRow[srcX + (scaledX % srcWidth)]; + } + } + } + public unsafe static void DrawNoise( FastBitmap dst, Rectangle dstRect, FastColour col, int variation ) { int dstX, dstY, dstWidth, dstHeight; if( !CheckCoords( dst, dstRect, out dstX, out dstY, out dstWidth, out dstHeight ) ) diff --git a/Launcher2/LauncherWindow.Background.cs b/Launcher2/LauncherWindow.Background.cs index e194c5b13..a658ca212 100644 --- a/Launcher2/LauncherWindow.Background.cs +++ b/Launcher2/LauncherWindow.Background.cs @@ -56,6 +56,10 @@ namespace Launcher { terrainPixels = new FastBitmap( terrainBmp, true ); FastBitmap.MovePortion( elemSize * 1, 0, elemSize * 0, 0, src, terrainPixels, elemSize ); FastBitmap.MovePortion( elemSize * 2, 0, elemSize * 1, 0, src, terrainPixels, elemSize ); + + // Precompute the darkened stone background + Rectangle rect = new Rectangle( 0, 0, elemSize, elemSize ); + Drawer2DExt.DrawScaledPixels( terrainPixels, terrainPixels, rect.Size, rect, rect, 96, 96 ); } } @@ -68,8 +72,8 @@ namespace Launcher { if( ClassicBackground ) { using( FastBitmap dst = new FastBitmap( Framebuffer, true ) ) { - ClearTile( 0, 0, Width, 48, elemSize, 128, 64, dst ); - ClearTile( 0, 48, Width, Height - 48, 0, 96, 96, dst ); + ClearTile( 0, 0, Width, 48, elemSize, 128, 64, dst, true ); + ClearTile( 0, 48, Width, Height - 48, 0, 96, 96, dst, false ); } } else { ClearArea( 0, 0, Width, Height ); @@ -99,7 +103,7 @@ namespace Launcher { public void ClearArea( int x, int y, int width, int height, FastBitmap dst ) { if( ClassicBackground ) { - ClearTile( x, y, width, height, 0, 96, 96, dst ); + ClearTile( x, y, width, height, 0, 96, 96, dst, false ); } else { FastColour col = LauncherSkin.BackgroundCol; Drawer2DExt.DrawNoise( dst, new Rectangle( x, y, width, height ), col, 6 ); @@ -107,7 +111,7 @@ namespace Launcher { } void ClearTile( int x, int y, int width, int height, int srcX, - byte scaleA, byte scaleB, FastBitmap dst ) { + byte scaleA, byte scaleB, FastBitmap dst, bool scale ) { if( x >= Width || y >= Height ) return; Rectangle srcRect = new Rectangle( srcX, 0, elemSize, elemSize ); const int tileSize = 48; @@ -121,7 +125,10 @@ namespace Launcher { int y2 = Math.Min( y + tileSize, Math.Min( yMax, Height ) ); Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y ); - Drawer2DExt.DrawScaledPixels( terrainPixels, dst, size, srcRect, dstRect, scaleA, scaleB ); + if( scale ) + Drawer2DExt.DrawScaledPixels( terrainPixels, dst, size, srcRect, dstRect, scaleA, scaleB ); + else + Drawer2DExt.DrawScaledPixels( terrainPixels, dst, size, srcRect, dstRect ); } } }