mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-22 12:03:01 -04:00
Fix crashing of launcher after minimising in classic mode.
This commit is contained in:
parent
819dfc434f
commit
a882312b54
@ -39,9 +39,9 @@ namespace Launcher2 {
|
||||
|
||||
public unsafe static void DrawNoise( FastBitmap dst, Rectangle dstRect, FastColour col, int variation ) {
|
||||
int dstWidth = dstRect.Width, dstHeight = dstRect.Height;
|
||||
int dstX = dstRect.X, dstY = dstRect.Y;
|
||||
|
||||
int dstX = dstRect.X, dstY = dstRect.Y;
|
||||
if( dstX >= dst.Width || dstY >= dst.Height ) return;
|
||||
|
||||
dstWidth = Math.Min( dstX + dstWidth, dst.Width ) - dstX;
|
||||
dstHeight = Math.Min( dstY + dstHeight, dst.Height ) - dstY;
|
||||
const int alpha = 255 << 24;
|
||||
@ -58,6 +58,22 @@ namespace Launcher2 {
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void FastClear( FastBitmap dst, Rectangle dstRect, FastColour col ) {
|
||||
int dstWidth = dstRect.Width, dstHeight = dstRect.Height;
|
||||
int dstX = dstRect.X, dstY = dstRect.Y;
|
||||
if( dstX >= dst.Width || dstY >= dst.Height ) return;
|
||||
|
||||
dstWidth = Math.Min( dstX + dstWidth, dst.Width ) - dstX;
|
||||
dstHeight = Math.Min( dstY + dstHeight, dst.Height ) - dstY;
|
||||
int pixel = col.ToArgb();
|
||||
|
||||
for( int yy = 0; yy < dstHeight; yy++ ) {
|
||||
int* row = dst.GetRowPtr( dstY + yy );
|
||||
for( int xx = 0; xx < dstWidth; xx++ )
|
||||
row[dstX + xx] = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
static float Noise( int x, int y ) {
|
||||
int n = x + y * 57;
|
||||
n = (n << 13) ^ n;
|
||||
|
@ -84,9 +84,9 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
public override void Resize() {
|
||||
DrawBackground();
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
game.ClearArea( 0, 0, game.Width, tableY );
|
||||
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
if( table != null )
|
||||
@ -111,14 +111,23 @@ namespace Launcher2 {
|
||||
MakeTableWidget();
|
||||
}
|
||||
|
||||
void DrawBackground() {
|
||||
using( FastBitmap dst = new FastBitmap( game.Framebuffer, true ) ) {
|
||||
game.ClearArea( 0, 0, game.Width, tableY, dst );
|
||||
int tableHeight = Math.Max( game.Height - tableY - 50, 1 );
|
||||
Rectangle rec = new Rectangle( tableX, tableY, game.Width - tableX, tableHeight );
|
||||
|
||||
if( !game.ClassicMode ) {
|
||||
FastColour col = LauncherTableWidget.backGridCol;
|
||||
Drawer2DExt.FastClear( dst, rec, col );
|
||||
} else {
|
||||
game.ClearArea( rec.X, rec.Y, rec.Width, rec.Height, dst );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MakeTableWidget() {
|
||||
int tableHeight = Math.Max( game.Height - tableY - 50, 1 );
|
||||
FastColour col = LauncherTableWidget.backGridCol;
|
||||
if( !game.ClassicMode )
|
||||
drawer.Clear( col, tableX, tableY, game.Width - tableX, tableHeight );
|
||||
else
|
||||
game.ClearArea( tableX, tableY, game.Width - tableX, tableHeight );
|
||||
|
||||
if( widgets[tableIndex] != null ) {
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
table.Height = tableHeight;
|
||||
|
@ -51,10 +51,11 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
void SetStatus( string text ) {
|
||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[5];
|
||||
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[5];
|
||||
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 100 );
|
||||
Dirty = true;
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ namespace Launcher2 {
|
||||
HandleTab();
|
||||
}
|
||||
if( lastInput == null ) {
|
||||
if( e.Key == Key.Escape )
|
||||
game.SetScreen( new MainScreen( game ) );
|
||||
if( e.Key == Key.Escape )
|
||||
game.SetScreen( new MainScreen( game ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -113,11 +113,11 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
protected virtual void RedrawLastInput() {
|
||||
if( lastInput.Width > lastInput.ButtonWidth )
|
||||
game.ClearArea( lastInput.X, lastInput.Y, lastInput.Width + 1, lastInput.Height + 1 );
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
if( lastInput.Width > lastInput.ButtonWidth )
|
||||
game.ClearArea( lastInput.X, lastInput.Y,
|
||||
lastInput.Width + 1, lastInput.Height + 1 );
|
||||
lastInput.Redraw( drawer, lastInput.Text, inputFont, inputHintFont );
|
||||
Dirty = true;
|
||||
}
|
||||
|
@ -44,22 +44,16 @@ namespace Launcher2 {
|
||||
e.X < widget.X + widget.Width && e.Y < widget.Y + widget.Height ) {
|
||||
if( selectedWidget == widget ) return;
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
if( selectedWidget != null )
|
||||
UnselectWidget( selectedWidget );
|
||||
SelectWidget( widget );
|
||||
}
|
||||
if( selectedWidget != null )
|
||||
UnselectWidget( selectedWidget );
|
||||
SelectWidget( widget );
|
||||
selectedWidget = widget;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( selectedWidget == null ) return;
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
UnselectWidget( selectedWidget );
|
||||
}
|
||||
UnselectWidget( selectedWidget );
|
||||
selectedWidget = null;
|
||||
}
|
||||
|
||||
@ -70,7 +64,10 @@ namespace Launcher2 {
|
||||
LauncherButtonWidget button = widget as LauncherButtonWidget;
|
||||
if( button != null ) {
|
||||
button.Active = false;
|
||||
button.Redraw( drawer, button.Text, buttonFont );
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
button.Redraw( drawer, button.Text, buttonFont );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
}
|
||||
@ -80,7 +77,10 @@ namespace Launcher2 {
|
||||
LauncherButtonWidget button = widget as LauncherButtonWidget;
|
||||
if( button != null ) {
|
||||
button.Active = true;
|
||||
button.Redraw( drawer, button.Text, buttonFont );
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
button.Redraw( drawer, button.Text, buttonFont );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace Launcher2 {
|
||||
if( lastClicked != null && lastClicked != selectedWidget )
|
||||
WidgetUnclicked( lastClicked );
|
||||
if( selectedWidget != null && selectedWidget.OnClick != null )
|
||||
selectedWidget.OnClick( e.X, e.Y );
|
||||
selectedWidget.OnClick( e.X, e.Y );
|
||||
lastClicked = selectedWidget;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ namespace Launcher2 {
|
||||
tabDown = true;
|
||||
int index = lastClicked == null ? -1 :
|
||||
Array.IndexOf<LauncherWidget>( widgets, lastClicked );
|
||||
int dir = (game.Window.Keyboard[Key.ShiftLeft]
|
||||
int dir = (game.Window.Keyboard[Key.ShiftLeft]
|
||||
|| game.Window.Keyboard[Key.ShiftRight]) ? -1 : 1;
|
||||
index += dir;
|
||||
Utils.Clamp( ref index, 0, widgets.Length - 1);
|
||||
|
@ -52,25 +52,19 @@ namespace Launcher2 {
|
||||
|
||||
string lastStatus;
|
||||
void SetStatus( string text ) {
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
SetStatusNoLock( text );
|
||||
}
|
||||
}
|
||||
|
||||
void SetStatusNoLock( string text ) {
|
||||
lastStatus = text;
|
||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[3];
|
||||
|
||||
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
|
||||
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 20 );
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 20 );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
bool HasServers {
|
||||
get {
|
||||
return !(game.Session.Servers == null || game.Session.Servers.Count == 0 );
|
||||
}
|
||||
get { return game.Session.Servers != null && game.Session.Servers.Count != 0; }
|
||||
}
|
||||
|
||||
bool signingIn;
|
||||
@ -83,7 +77,7 @@ namespace Launcher2 {
|
||||
}
|
||||
if( signingIn ) return;
|
||||
UpdateSignInInfo( Get( 0 ), Get( 1 ) );
|
||||
|
||||
|
||||
LauncherBooleanWidget booleanWidget = widgets[skipSSLIndex] as LauncherBooleanWidget;
|
||||
if( booleanWidget != null && booleanWidget.Value ) {
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
@ -123,7 +117,7 @@ namespace Launcher2 {
|
||||
SetStatus( text );
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
widgetIndex = 9;
|
||||
widgetIndex = 9;
|
||||
MakeSSLSkipValidationBoolean();
|
||||
MakeSSLSkipValidationLabel();
|
||||
}
|
||||
|
@ -107,13 +107,13 @@ namespace Launcher2 {
|
||||
base.SelectWidget( widget );
|
||||
if( signingIn || !resumeValid || widget != widgets[4] ) return;
|
||||
const string format = "&eResume to {0}:{1}, as {2}";
|
||||
SetStatusNoLock( String.Format( format, resumeIp, resumePort, resumeUser ) );
|
||||
SetStatus( String.Format( format, resumeIp, resumePort, resumeUser ) );
|
||||
}
|
||||
|
||||
protected override void UnselectWidget( LauncherWidget widget ) {
|
||||
base.UnselectWidget( widget );
|
||||
if( signingIn || !resumeValid || widget != widgets[4] ) return;
|
||||
SetStatusNoLock( "" );
|
||||
SetStatus( "" );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
|
@ -60,6 +60,16 @@ namespace Launcher2 {
|
||||
Framebuffer.Dispose();
|
||||
Framebuffer = new Bitmap( Width, Height );
|
||||
}
|
||||
|
||||
if( ClassicMode ) {
|
||||
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 );
|
||||
}
|
||||
} else {
|
||||
ClearArea( 0, 0, Width, Height );
|
||||
}
|
||||
|
||||
using( IDrawer2D drawer = Drawer ) {
|
||||
drawer.SetBitmap( Framebuffer );
|
||||
|
||||
@ -67,49 +77,46 @@ namespace Launcher2 {
|
||||
DrawTextArgs args = new DrawTextArgs( "&eClassical&fSharp", logoFont, false );
|
||||
Size size = drawer.MeasureChatSize( ref args );
|
||||
int xStart = Width / 2 - size.Width / 2;
|
||||
if( ClassicMode )
|
||||
ClearTile( 0, 0, Width, 48, elemSize, 128, 64 );
|
||||
else
|
||||
ClearArea( 0, 0, Width, Height );
|
||||
|
||||
args.Text = "&0Classical&0Sharp";
|
||||
drawer.DrawChatText( ref args, xStart + 4, 8 + 4 );
|
||||
args.Text = "&eClassical&fSharp";
|
||||
drawer.DrawChatText( ref args, xStart, 8 );
|
||||
drawer.UseBitmappedChat = false;
|
||||
if( ClassicMode )
|
||||
ClearTile( 0, 48, Width, Height - 48, 0, 96, 96 );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
public void ClearArea( int x, int y, int width, int height ) {
|
||||
using( FastBitmap dst = new FastBitmap( Framebuffer, true ) )
|
||||
ClearArea( x, y, width, height, dst );
|
||||
}
|
||||
|
||||
public void ClearArea( int x, int y, int width, int height, FastBitmap dst ) {
|
||||
if( ClassicMode ) {
|
||||
ClearTile( x, y, width, height, 0, 96, 96 );
|
||||
ClearTile( x, y, width, height, 0, 96, 96, dst );
|
||||
} else {
|
||||
FastColour col = LauncherSkin.BackgroundCol;
|
||||
using( FastBitmap dst = new FastBitmap( Framebuffer, true ) )
|
||||
Drawer2DExt.DrawNoise( dst, new Rectangle( x, y, width, height ), col, 6 );
|
||||
Drawer2DExt.DrawNoise( dst, new Rectangle( x, y, width, height ), col, 6 );
|
||||
}
|
||||
}
|
||||
|
||||
void ClearTile( int x, int y, int width, int height, int srcX, byte scaleA, byte scaleB ) {
|
||||
void ClearTile( int x, int y, int width, int height, int srcX,
|
||||
byte scaleA, byte scaleB, FastBitmap dst ) {
|
||||
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 xOrig = x, xMax = x + width, yMax = y + height;
|
||||
Rectangle srcRect = new Rectangle( srcX, 0, elemSize, elemSize );
|
||||
const int tileSize = 48;
|
||||
Size size = new Size( tileSize, tileSize );
|
||||
int xOrig = x, xMax = x + width, yMax = y + height;
|
||||
|
||||
for( ; y < yMax; y += tileSize )
|
||||
for( x = xOrig; x < xMax; x += tileSize )
|
||||
{
|
||||
int x2 = Math.Min( x + tileSize, Math.Min( xMax, Width ) );
|
||||
int y2 = Math.Min( y + tileSize, Math.Min( yMax, Height ) );
|
||||
|
||||
for( ; y < yMax; y += tileSize )
|
||||
for( x = xOrig; x < xMax; x += tileSize )
|
||||
{
|
||||
int x2 = Math.Min( x + tileSize, Math.Min( xMax, Width ) );
|
||||
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 );
|
||||
}
|
||||
Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y );
|
||||
Drawer2DExt.DrawScaledPixels( terrainPixels, dst, size, srcRect, dstRect, scaleA, scaleB );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user