Launcher: Use button for options, use much nicer checkbox.

This commit is contained in:
UnknownShadow200 2016-10-07 18:12:31 +11:00
parent 8098ebdc1d
commit 9944e4b8bc
9 changed files with 142 additions and 133 deletions

View file

@ -0,0 +1,73 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Drawing;
using ClassicalSharp;
namespace Launcher.Drawing {
public unsafe static class BitmapDrawer {
public static void DrawIndexed( byte[] indices, FastColour[] palette,
int size, int x, int y, FastBitmap dst ) {
int* argb = stackalloc int[palette.Length];
for( int i = 0; i < palette.Length; i++ )
argb[i] = palette[i].ToArgb();
for( int i = 0, yy = 0; yy < size; yy++ ) {
if( (y + yy) < 0 ) { i += size; continue; }
if( (y + yy) >= dst.Height ) break;
int* row = dst.GetRowPtr( y + yy );
for( int xx = 0; xx < size; xx++ ) {
int col = argb[indices[i]]; i++;
if( col == 0 ) continue; // transparent pixel
if( (x + xx) < 0 || (x + xx) >= dst.Width ) continue;
row[x + xx] = col;
}
}
}
public static void DrawScaled( 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;
for( int yy = 0; yy < dstHeight; yy++ ) {
int scaledY = (yy + dstY) * srcHeight / scaleHeight;
int* srcRow = src.GetRowPtr( srcY + (scaledY % 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 + dstX) * srcWidth / scaleWidth;
int pixel = srcRow[srcX + (scaledX % srcWidth)];
int col = pixel & ~0xFFFFFF; // keep a, but clear rgb
col |= ((pixel & 0xFF) * rgbScale / 255);
col |= (((pixel >> 8) & 0xFF) * rgbScale / 255) << 8;
col |= (((pixel >> 16) & 0xFF) * rgbScale / 255) << 16;
dstRow[dstX + xx] = col;
}
}
}
public static void DrawTiled( FastBitmap src, FastBitmap dst,
Rectangle srcRect, Rectangle dstRect ) {
int srcX = srcRect.X, srcWidth = srcRect.Width, srcHeight = srcRect.Height;
int x, y, width, height;
if( !Drawer2DExt.ClampCoords( dst, dstRect, out x, out y, out width, out height ) )
return;
for( int yy = 0; yy < height; yy++ ) {
// srcY is always 0 so we don't need to add
int* srcRow = src.GetRowPtr( ((yy + y) % srcHeight) );
int* dstRow = dst.GetRowPtr( y + yy );
for( int xx = 0; xx < width; xx++ )
dstRow[x + xx] = srcRow[srcX + ((xx + x) % srcWidth)];
}
}
}
}

View file

@ -6,50 +6,6 @@ using ClassicalSharp;
namespace Launcher.Drawing {
public unsafe static class Drawer2DExt {
public 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;
for( int yy = 0; yy < dstHeight; yy++ ) {
int scaledY = (yy + dstY) * srcHeight / scaleHeight;
int* srcRow = src.GetRowPtr( srcY + (scaledY % 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 + dstX) * srcWidth / scaleWidth;
int pixel = srcRow[srcX + (scaledX % srcWidth)];
int col = pixel & ~0xFFFFFF; // keep a, but clear rgb
col |= ((pixel & 0xFF) * rgbScale / 255);
col |= (((pixel >> 8) & 0xFF) * rgbScale / 255) << 8;
col |= (((pixel >> 16) & 0xFF) * rgbScale / 255) << 16;
dstRow[dstX + xx] = col;
}
}
}
public static void DrawTiledPixels( FastBitmap src, FastBitmap dst,
Rectangle srcRect, Rectangle dstRect ) {
int srcX = srcRect.X, srcWidth = srcRect.Width, srcHeight = srcRect.Height;
int x, y, width, height;
if( !ClampCoords( dst, dstRect, out x, out y, out width, out height ) )
return;
for( int yy = 0; yy < height; yy++ ) {
// srcY is always 0 so we don't need to add
int* srcRow = src.GetRowPtr( ((yy + y) % srcHeight) );
int* dstRow = dst.GetRowPtr( y + yy );
for( int xx = 0; xx < width; xx++ )
dstRow[x + xx] = srcRow[srcX + ((xx + x) % srcWidth)];
}
}
public static void Clear( FastBitmap bmp, Rectangle rect, FastColour col ) {
int x, y, width, height;
if( !ClampCoords( bmp, rect, out x, out y, out width, out height ) )
@ -62,8 +18,7 @@ namespace Launcher.Drawing {
row[x + xx] = pixel;
}
}
public static bool ClampCoords( FastBitmap bmp, Rectangle rect, out int x,
out int y, out int width, out int height ) {
width = rect.Width; height = rect.Height;

View file

@ -8,14 +8,12 @@ namespace Launcher.Gui.Views {
public sealed class DirectConnectView : IView {
internal int connectIndex, backIndex, ccSkinsIndex, statusIndex;
Font booleanFont;
public DirectConnectView( LauncherWindow game ) : base( game ) {
widgets = new Widget[8];
}
public override void Init() {
booleanFont = new Font( game.FontName, 22, FontStyle.Regular );
titleFont = new Font( game.FontName, 15, FontStyle.Bold );
textFont = new Font( game.FontName, 14, FontStyle.Regular );
inputHintFont = new Font( game.FontName, 12, FontStyle.Italic );
@ -26,11 +24,6 @@ namespace Launcher.Gui.Views {
Widget widget = widgets[index];
return widget == null ? "" : widget.Text;
}
public override void Dispose() {
base.Dispose();
booleanFont.Dispose();
}
protected override void MakeWidgets() {
@ -57,7 +50,7 @@ namespace Launcher.Gui.Views {
.SetLocation( Anchor.Centre, Anchor.Centre, 30, 100 );
ccSkinsIndex = widgetIndex;
Makers.Checkbox( this, booleanFont, true, 30 )
Makers.Checkbox( this, true, 24 )
.SetLocation( Anchor.Centre, Anchor.Centre, -110, 100 );
}
}

View file

@ -66,7 +66,7 @@ namespace Launcher.Gui.Views {
sslIndex = widgetIndex;
bool sslVisible = widgets[sslIndex] != null && widgets[sslIndex].Visible;
Makers.Checkbox( this, textFont, true, 30 )
Makers.Checkbox( this, true, 30 )
.SetLocation( Anchor.Centre, Anchor.Centre, 160, -20 );
Makers.Label( this, "Skip SSL check", textFont )
.SetLocation( Anchor.Centre, Anchor.Centre, 250, -20 );
@ -77,9 +77,8 @@ namespace Launcher.Gui.Views {
.SetLocation( Anchor.BottomOrRight, Anchor.LeftOrTop, -5, 50 );
settingsIndex = widgetIndex;
Makers.Bitmap( this, Bitmaps.OptionsIndices,
Bitmaps.OptionsPalette, Bitmaps.OptionsSize )
.SetLocation( Anchor.BottomOrRight, Anchor.LeftOrTop, -5, 5 );
Makers.Button( this, "Options", 100, buttonHeight, buttonFont )
.SetLocation( Anchor.BottomOrRight, Anchor.LeftOrTop, -6, 6 );
}
}
}

View file

@ -2,32 +2,72 @@
using System;
using System.Drawing;
using ClassicalSharp;
using Launcher.Drawing;
namespace Launcher.Gui.Widgets {
/// <summary> Represents a state that can be toggled by the user. </summary>
public sealed class CheckboxWidget : Widget {
public int BoxWidth, BoxHeight;
public bool Value;
Font font;
public CheckboxWidget( LauncherWindow window, Font font, int width, int height ) : base( window ) {
BoxWidth = width; BoxHeight = height;
public CheckboxWidget( LauncherWindow window, int width, int height ) : base( window ) {
Width = width; Height = height;
this.font = font;
}
public override void Redraw( IDrawer2D drawer ) {
if( Window.Minimised || !Visible ) return;
drawer.DrawRect( FastColour.Black, X, Y, Width, Height );
if( Value ) {
DrawTextArgs args = new DrawTextArgs( "X", font, false );
Size size = drawer.MeasureSize( ref args );
args.SkipPartsCheck = true;
drawer.DrawText( ref args, X + (Width + 2 - size.Width) / 2, // account for border
Y + (Height - size.Height) / 2 );
Rectangle rect = new Rectangle( X, Y, Width, Height / 2 );
using( FastBitmap bmp = Window.LockBits() ) {
Gradient.Vertical( bmp, rect, boxTop, boxBottom );
rect.Y += rect.Height;
Gradient.Vertical( bmp, rect, boxBottom, boxTop );
if( Value ) {
const int size = 12;
int x = X + Width / 2 - size / 2;
int y = Y + Height / 2 - size / 2;
BitmapDrawer.DrawIndexed( indices, palette, size, x, y, bmp );
}
}
drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height );
drawer.DrawRectBounds( FastColour.Black, 1, X, Y, Width - 1, Height - 1 );
}
static FastColour boxTop = new FastColour( 255, 255, 255 );
static FastColour boxBottom = new FastColour( 240, 240, 240 );
// Based off checkbox from original ClassiCube Launcher
static byte[] indices = new byte[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x06, 0x09, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x06, 0x0B, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0D, 0x0E, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0F, 0x06, 0x10, 0x00, 0x11, 0x06, 0x12, 0x00, 0x00, 0x00,
0x00, 0x00, 0x13, 0x14, 0x15, 0x00, 0x16, 0x17, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x06, 0x19, 0x06, 0x1A, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1B, 0x06, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1D, 0x06, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static FastColour[] palette = new FastColour[] {
new FastColour( 0, 0, 0, 0 ), new FastColour( 144, 144, 144 ),
new FastColour( 61, 61, 61 ), new FastColour( 94, 94, 94 ),
new FastColour( 197, 196, 197 ), new FastColour( 57, 57, 57 ),
new FastColour( 33, 33, 33 ), new FastColour( 177, 177, 177 ),
new FastColour( 189, 189, 189 ), new FastColour( 67, 67, 67 ),
new FastColour( 108, 108, 108 ), new FastColour( 171, 171, 171 ),
new FastColour( 220, 220, 220 ), new FastColour( 43, 43, 43 ),
new FastColour( 63, 63, 63 ), new FastColour( 100, 100, 100 ),
new FastColour( 192, 192, 192 ), new FastColour( 132, 132, 132 ),
new FastColour( 175, 175, 175 ), new FastColour( 217, 217, 217 ),
new FastColour( 42, 42, 42 ), new FastColour( 86, 86, 86 ),
new FastColour( 56, 56, 56 ), new FastColour( 76, 76, 76 ),
new FastColour( 139, 139, 139 ), new FastColour( 130, 130, 130 ),
new FastColour( 181, 181, 181 ), new FastColour( 62, 62, 62 ),
new FastColour( 75, 75, 75 ), new FastColour( 184, 184, 184 ),
};
}
}

View file

@ -37,12 +37,12 @@ namespace Launcher.Gui.Widgets {
return widget;
}
public static Widget Checkbox( IView view, Font font, bool initValue, int size ) {
public static Widget Checkbox( IView view, bool initValue, int size ) {
CheckboxWidget widget;
if( view.widgets[view.widgetIndex] != null ) {
widget = (CheckboxWidget)view.widgets[view.widgetIndex];
} else {
widget = new CheckboxWidget( view.game, font, size, size );
widget = new CheckboxWidget( view.game, size, size );
widget.Value = initValue;
view.widgets[view.widgetIndex] = widget;
}

View file

@ -57,6 +57,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Drawing\BitmapDrawer.cs" />
<Compile Include="Drawing\Drawer2DExt.cs" />
<Compile Include="Drawing\Gradient.cs" />
<Compile Include="Drawing\Platform\OSXDrawer.cs" />
@ -110,7 +111,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Updater\Scripts.cs" />
<Compile Include="Updater\Applier.cs" />
<Compile Include="Utils\Bitmaps.cs" />
<Compile Include="Utils\Client.cs" />
<Compile Include="Utils\ErrorHandler.cs" />
<Compile Include="Utils\JSON.cs" />

View file

@ -85,12 +85,12 @@ namespace Launcher {
// Precompute the scaled background
using( FastBitmap src = new FastBitmap( bmp, true, true ) ) {
Drawer2DExt.DrawScaledPixels( src, terrainPixels, size,
new Rectangle( 2 * elemSize, 0, elemSize, elemSize ),
new Rectangle( tileSize, 0, tileSize, tileSize ), 128, 64 );
Drawer2DExt.DrawScaledPixels( src, terrainPixels, size,
new Rectangle( 1 * elemSize, 0, elemSize, elemSize ),
new Rectangle( 0, 0, tileSize, tileSize ), 96, 96 );
BitmapDrawer.DrawScaled( src, terrainPixels, size,
new Rectangle( 2 * elemSize, 0, elemSize, elemSize ),
new Rectangle( tileSize, 0, tileSize, tileSize ), 128, 64 );
BitmapDrawer.DrawScaled( src, terrainPixels, size,
new Rectangle( 1 * elemSize, 0, elemSize, elemSize ),
new Rectangle( 0, 0, tileSize, tileSize ), 96, 96 );
}
}
@ -149,8 +149,8 @@ namespace Launcher {
void ClearTile( int x, int y, int width, int height, int srcX, FastBitmap dst ) {
Rectangle srcRect = new Rectangle( srcX, 0, tileSize, tileSize );
Drawer2DExt.DrawTiledPixels( terrainPixels, dst, srcRect,
new Rectangle( x, y, width, height ) );
Rectangle dstRect = new Rectangle( x, y, width, height );
BitmapDrawer.DrawTiled( terrainPixels, dst, srcRect, dstRect );
}
}
}

View file

@ -1,51 +0,0 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using ClassicalSharp;
namespace Launcher {
internal static class Bitmaps {
public static int OptionsSize = 32;
public static byte[] OptionsIndices = new byte[] {
0x00, 0x00, 0x00, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x10, 0x02, 0x20, 0x01, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x11, 0x11, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x11, 0x11, 0x10, 0x00, 0x00,
0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
0x00, 0x01, 0x11, 0x10, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x01, 0x11, 0x10, 0x00,
0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00,
0x01, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11, 0x10,
0x01, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x10,
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11,
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11,
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x11, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11,
0x11, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11,
0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11,
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11,
0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,
0x01, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x10,
0x01, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11, 0x10,
0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x00,
0x00, 0x01, 0x11, 0x10, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x01, 0x11, 0x10, 0x00,
0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x11, 0x11, 0x10, 0x00,
0x00, 0x00, 0x01, 0x11, 0x11, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x11, 0x11, 0x11, 0x00, 0x00,
0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x00, 0x02, 0x20, 0x00, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00,
};
public static FastColour[] OptionsPalette = new FastColour[] {
new FastColour( 0, 0, 0, 0 ), new FastColour( 255, 255, 255 ),
new FastColour( 225, 225, 225 ),
};
}
}