mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Implement the ability to use blocks for background, similar to the old minecraft.net. Currently not toggleable.
This commit is contained in:
parent
a4c548cd14
commit
cfa93e0eef
@ -6,17 +6,15 @@ namespace Launcher2 {
|
||||
|
||||
public static class Drawer2DExt {
|
||||
|
||||
public unsafe static void CopyScaledPixels( FastBitmap src, FastBitmap dst,
|
||||
Rectangle srcRect, Rectangle dstRect ) {
|
||||
CopyScaledPixels( src, dst, new Size( dstRect.Width, dstRect.Height ), srcRect, dstRect, 255 );
|
||||
}
|
||||
public unsafe static void CopyScaledPixels( FastBitmap src, FastBitmap dst, Size scale,
|
||||
Rectangle srcRect, Rectangle dstRect, byte rgbScale ) {
|
||||
public unsafe static void DrawScaledPixels( FastBitmap src, FastBitmap dst, Size scale,
|
||||
Rectangle srcRect, Rectangle dstRect, byte scaleA, byte scaleB ) {
|
||||
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;
|
||||
int offsetX = dstRect.X * srcRect.Width / scaleWidth;
|
||||
int offsetY = dstRect.Y * srcRect.Height / scaleHeight;
|
||||
|
||||
if( dstX >= dst.Width || dstY >= dst.Height ) return;
|
||||
dstWidth = Math.Min( dstX + dstWidth, dst.Width ) - dstX;
|
||||
@ -24,12 +22,13 @@ namespace Launcher2 {
|
||||
|
||||
for( int yy = 0; yy < dstHeight; yy++ ) {
|
||||
int scaledY = yy * srcHeight / scaleHeight;
|
||||
int* srcRow = src.GetRowPtr( srcY + scaledY );
|
||||
int* srcRow = src.GetRowPtr( srcY + (scaledY + offsetY) % srcHeight );
|
||||
int* dstRow = dst.GetRowPtr( dstY + yy );
|
||||
byte rgbScale = (byte)Utils.Lerp( scaleA, scaleB, (float)yy / dstHeight );
|
||||
|
||||
for( int xx = 0; xx < dstWidth; xx++ ) {
|
||||
int scaledX = xx * srcWidth / scaleWidth;
|
||||
int pixel = srcRow[srcX + scaledX];
|
||||
int pixel = srcRow[srcX + (scaledX + offsetX) % srcWidth];
|
||||
|
||||
int col = pixel & ~0xFFFFFF; // keep a, but clear rgb
|
||||
col |= ((pixel & 0xFF) * rgbScale / 255);
|
||||
|
@ -42,7 +42,7 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
void DrawClassicube() {
|
||||
MakeInput( Get(), 280, Anchor.Centre, false, 0, -115, 32, "&7Username.." );
|
||||
MakeInput( Get(), 280, Anchor.Centre, false, 0, -120, 32, "&7Username.." );
|
||||
MakeInput( Get(), 280, Anchor.Centre, true, 0, -70, 32, "&7Password.." );
|
||||
|
||||
MakeButtonAt( "Sign in", 100, buttonHeight, buttonFont,
|
||||
|
@ -73,7 +73,6 @@ namespace Launcher2 {
|
||||
Redraw( drawer, font, titleFont, boldFont );
|
||||
}
|
||||
|
||||
static FastColour scrollBackCol = new FastColour( 120, 85, 151 ), scrollCol = new FastColour( 200, 184, 216 );
|
||||
public void Redraw( IDrawer2D drawer, Font font, Font titleFont, Font boldFont ) {
|
||||
for( int i = 0; i < ColumnWidths.Length; i++ ) {
|
||||
ColumnWidths[i] = DesiredColumnWidths[i];
|
||||
@ -166,12 +165,12 @@ namespace Launcher2 {
|
||||
|
||||
int maxIndex;
|
||||
void DrawScrollbar( IDrawer2D drawer ) {
|
||||
drawer.Clear( scrollBackCol, Window.Width - 10, Y, 10, Height );
|
||||
drawer.Clear( LauncherSkin.ButtonBorderCol, Window.Width - 10, Y, 10, Height );
|
||||
float scale = Height / (float)Count;
|
||||
|
||||
int y1 = (int)(Y + CurrentIndex * scale);
|
||||
int height = (int)((maxIndex - CurrentIndex) * scale);
|
||||
drawer.Clear( scrollCol, Window.Width - 10, y1, 10, height + 1 );
|
||||
drawer.Clear( LauncherSkin.ButtonForeActiveCol, Window.Width - 10, y1, 10, height + 1 );
|
||||
}
|
||||
|
||||
public void SetSelected( int index ) {
|
||||
|
@ -23,40 +23,56 @@ namespace Launcher2 {
|
||||
using( Stream fs = new FileStream( texPack, FileMode.Open, FileAccess.Read, FileShare.Read ) ) {
|
||||
ZipReader reader = new ZipReader();
|
||||
|
||||
reader.ShouldProcessZipEntry = (f) => f == "default.png";
|
||||
reader.ShouldProcessZipEntry = (f) => f == "default.png" || f == "terrain.png";
|
||||
reader.ProcessZipEntry = ProcessZipEntry;
|
||||
reader.Extract( fs );
|
||||
}
|
||||
}
|
||||
|
||||
bool useBitmappedFont;
|
||||
Bitmap terrainBmp;
|
||||
FastBitmap terrainPixels;
|
||||
int elemSize;
|
||||
|
||||
void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
||||
MemoryStream stream = new MemoryStream( data );
|
||||
Bitmap bmp = new Bitmap( stream );
|
||||
Drawer.SetFontBitmap( bmp );
|
||||
useBitmappedFont = !Options.GetBool( OptionsKey.ArialChatFont, false );
|
||||
if( filename == "default.png" ) {
|
||||
Drawer.SetFontBitmap( bmp );
|
||||
useBitmappedFont = !Options.GetBool( OptionsKey.ArialChatFont, false );
|
||||
} else if( filename == "terrain.png" ) {
|
||||
FastBitmap src = new FastBitmap( bmp, true );
|
||||
elemSize = src.Width / 16;
|
||||
|
||||
terrainBmp = new Bitmap( elemSize * 2, elemSize );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
public void MakeBackground() {
|
||||
if( Framebuffer == null || (Framebuffer.Width != Width || Framebuffer.Height != Height) ) {
|
||||
if( Framebuffer != null )
|
||||
if( Framebuffer != null )
|
||||
Framebuffer.Dispose();
|
||||
Framebuffer = new Bitmap( Width, Height );
|
||||
}
|
||||
}
|
||||
using( IDrawer2D drawer = Drawer ) {
|
||||
drawer.SetBitmap( Framebuffer );
|
||||
ClearArea( 0, 0, Width, Height );
|
||||
|
||||
|
||||
drawer.UseBitmappedChat = useBitmappedFont;
|
||||
DrawTextArgs args = new DrawTextArgs( "&eClassical&fSharp", logoFont, false );
|
||||
Size size = drawer.MeasureChatSize( ref args );
|
||||
int xStart = Width / 2 - size.Width / 2;
|
||||
ClearArea( 0, 0, Width, Height );
|
||||
//ClearTile( 0, 0, Width, 48, elemSize, 128, 64 );
|
||||
|
||||
args.Text = "&0Classical&0Sharp";
|
||||
drawer.DrawChatText( ref args, xStart + 5, 10 + 5 );
|
||||
drawer.DrawChatText( ref args, xStart + 4, 10 + 4 );
|
||||
args.Text = "&eClassical&fSharp";
|
||||
drawer.DrawChatText( ref args, xStart, 10 );
|
||||
drawer.UseBitmappedChat = false;
|
||||
//ClearTile( 0, 48, Width, Height - 48, 0, 64, 64 );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
@ -65,6 +81,27 @@ namespace Launcher2 {
|
||||
FastColour col = LauncherSkin.BackgroundCol;
|
||||
using( FastBitmap dst = new FastBitmap( Framebuffer, true ) )
|
||||
Drawer2DExt.DrawNoise( dst, new Rectangle( x, y, width, height ), col );
|
||||
//ClearTile( x, y, width, height, 0, 64, 64 );
|
||||
}
|
||||
|
||||
void ClearTile( int x, int y, int width, int height, int srcX, byte scaleA, byte scaleB ) {
|
||||
if( x >= Width || y >= Height ) return;
|
||||
using( FastBitmap dst = new FastBitmap( Framebuffer, true ) ) {
|
||||
Rectangle srcRect = new Rectangle( srcX, 0, elemSize, elemSize );
|
||||
const int tileSize = 48;
|
||||
Size size = new Size( tileSize, tileSize );
|
||||
int xMax = x + width, xOrig = x, yMax = y + height;
|
||||
|
||||
for( ; y < yMax; y += tileSize )
|
||||
for( x = xOrig; x < xMax; x += tileSize )
|
||||
{
|
||||
int x2 = Math.Min( x + tileSize, Math.Min( x + width, Width ) );
|
||||
int y2 = Math.Min( y + tileSize, Math.Min( y + height, Height ) );
|
||||
|
||||
Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y );
|
||||
Drawer2DExt.DrawScaledPixels( terrainPixels, dst, size, srcRect, dstRect, scaleA, scaleB );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ namespace Launcher2 {
|
||||
Window.Resize += Resize;
|
||||
Window.FocusedChanged += FocusedChanged;
|
||||
Window.WindowStateChanged += Resize;
|
||||
logoFont = new Font( "Arial", 30, FontStyle.Regular );
|
||||
logoFont = new Font( "Arial", 24, FontStyle.Regular );
|
||||
string path = Assembly.GetExecutingAssembly().Location;
|
||||
Window.Icon = Icon.ExtractAssociatedIcon( path );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user