Launcher: Start work on nicer text input widgets.

This commit is contained in:
UnknownShadow200 2016-09-13 18:35:27 +10:00
parent ed8a4d3d1f
commit ffacf8e8e2
11 changed files with 57 additions and 28 deletions

View File

@ -43,7 +43,7 @@ namespace Launcher.Gui.Screens {
void SetStatus( string text ) {
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[5];
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
game.ResetArea( widget.X, widget.Y, widget.Width, widget.Height );
widget.SetDrawData( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 100 );
RedrawWidget( widget );
}

View File

@ -114,7 +114,7 @@ namespace Launcher.Gui.Screens {
protected virtual void RedrawLastInput() {
if( curInput.Width > curInput.ButtonWidth )
game.ClearArea( curInput.X, curInput.Y, curInput.Width, curInput.Height );
game.ResetArea( curInput.X, curInput.Y, curInput.Width, curInput.Height );
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );

View File

@ -43,7 +43,7 @@ namespace Launcher.Gui.Screens {
lastStatus = text;
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[3];
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
game.ResetArea( widget.X, widget.Y, widget.Width, widget.Height );
widget.SetDrawData( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 20 );
RedrawWidget( widget );
game.Dirty = true;

View File

@ -75,9 +75,9 @@ namespace Launcher.Gui.Screens {
task.Exception = null;
LauncherWidget w = widgets[view.devIndex - 1];
game.ClearArea( w.X, w.Y, w.Width, w.Height );
game.ResetArea( w.X, w.Y, w.Width, w.Height );
w = widgets[view.relIndex - 1];
game.ClearArea( w.X, w.Y, w.Width, w.Height );
game.ResetArea( w.X, w.Y, w.Width, w.Height );
game.RedrawBackground();
Resize();
}
@ -107,7 +107,7 @@ namespace Launcher.Gui.Screens {
view.gameOpen = CheckClientInstances();
view.SetWarning();
LauncherWidget widget = widgets[view.statusIndex];
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
game.ResetArea( widget.X, widget.Y, widget.Width, widget.Height );
RedrawWidget( widgets[view.statusIndex] );
if( view.gameOpen ) return;

View File

@ -41,12 +41,12 @@ namespace Launcher.Gui.Views {
}
if( buttons == 0 ) return;
using( FastBitmap dst = new FastBitmap( game.Framebuffer, true, false ) ) {
using( FastBitmap bmp = game.LockBits() ) {
for( int i = 0; i < widgets.Length; i++ ) {
if( widgets[i] == null ) continue;
LauncherButtonWidget button = widgets[i] as LauncherButtonWidget;
if( button != null )
button.RedrawBackground( dst );
button.RedrawBackground( bmp );
}
}
}

View File

@ -20,7 +20,7 @@ namespace Launcher.Gui.Views {
const int boxWidth = 190 * 2, boxHeight = 70 * 2;
public override void DrawAll() {
using( FastBitmap bmp = new FastBitmap( game.Framebuffer, true, false ) ) {
using( FastBitmap bmp = game.LockBits() ) {
drawer.SetBitmap( game.Framebuffer );
Rectangle r = new Rectangle( 0, 0, bmp.Width, bmp.Height );
Drawer2DExt.Clear( bmp, r, clearCol );

View File

@ -59,9 +59,9 @@ namespace Launcher.Gui.Views {
}
void DrawBackground() {
using( FastBitmap dst = new FastBitmap( game.Framebuffer, true, false ) ) {
game.ClearArea( 0, 0, game.Width, tableY, dst );
DrawTableBackground( dst );
using( FastBitmap bmp = game.LockBits() ) {
game.ResetArea( 0, 0, game.Width, tableY, bmp );
DrawTableBackground( bmp );
}
}
@ -73,7 +73,7 @@ namespace Launcher.Gui.Views {
FastColour col = LauncherTableView.backGridCol;
Drawer2DExt.Clear( dst, rec, col );
} else {
game.ClearArea( rec.X, rec.Y, rec.Width, rec.Height, dst );
game.ResetArea( rec.X, rec.Y, rec.Width, rec.Height, dst );
}
}
@ -101,7 +101,7 @@ namespace Launcher.Gui.Views {
}
internal void RedrawTable() {
using( FastBitmap dst = new FastBitmap( game.Framebuffer, true, false ) )
using( FastBitmap dst = game.LockBits() )
DrawTableBackground( dst );
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
table.ClampIndex();

View File

@ -78,6 +78,7 @@ namespace Launcher.Gui.Widgets {
FastColour foreCol = Active ? LauncherSkin.ButtonForeActiveCol : LauncherSkin.ButtonForeCol;
FastColour top = Expand( foreCol, 8 ), bottom = Expand( foreCol, -8 );
Gradient.Vertical( dst, rect, top, bottom );
}
}

View File

@ -59,21 +59,43 @@ namespace Launcher.Gui.Widgets {
public override void Redraw( IDrawer2D drawer ) {
string text = Text;
if( Password ) text = new String( '*', text.Length );
DrawTextArgs args = new DrawTextArgs( text, font, true );
DrawTextArgs args = new DrawTextArgs( "&0" + text, font, false );
Size size = drawer.MeasureSize( ref args );
Width = Math.Max( ButtonWidth, size.Width + 15 );
textHeight = size.Height;
args.SkipPartsCheck = true;
textHeight = size.Height;
args.SkipPartsCheck = true;
if( Window.Minimised ) return;
FastColour col = Active ? new FastColour( 240, 240, 240 ) : new FastColour( 180, 180, 180 );
drawer.Clear( col, X + 1, Y, Width - 2, 2 );
drawer.Clear( col, X + 1, Y + Height - 2, Width - 2, 2 );
drawer.Clear( col, X, Y + 1, 2, Height - 2 );
drawer.Clear( col, X + Width - 2, Y + 1, 2, Height - 2 );
drawer.Clear( FastColour.Black, X + 2, Y + 2, Width - 4, Height - 4 );
DrawBorders( drawer );
DrawText( drawer, args );
}
static FastColour borderIn = new FastColour( 165, 142, 168 );
static FastColour borderOut = new FastColour( 97, 81, 110 );
const int border = 1;
void DrawBorders( IDrawer2D drawer ) {
FastColour col = borderOut;
if( Active ) {
drawer.Clear( col, X, Y, Width, border );
drawer.Clear( col, X, Y + Height - border, Width, border );
drawer.Clear( col, X, Y, border, Height );
drawer.Clear( col, X + Width - border, Y, border, Height );
} else {
//Window.ResetArea( X, Y, Width,
}
col = borderIn;
drawer.Clear( col, X + border, Y + border, Width - border * 2, border );
drawer.Clear( col, X + border, Y + Height - border * 2, Width - border * 2, border );
drawer.Clear( col, X + border, Y + border, border, Height - border * 2 );
drawer.Clear( col, X + Width - border * 2, Y + border, border, Height - border * 2 );
drawer.Clear( FastColour.White, X + 2, Y + 2, Width - 4, Height - 4 );
}
void DrawText( IDrawer2D drawer, DrawTextArgs args ) {
if( Text.Length != 0 || HintText == null ) {
int y = Y + 2 + (Height - textHeight) / 2;
drawer.DrawText( ref args, X + 5, y );

View File

@ -97,7 +97,7 @@ namespace Launcher {
ClearTile( 0, 48, Width, Height - 48, 0, dst );
}
} else {
ClearArea( 0, 0, Width, Height );
ResetArea( 0, 0, Width, Height );
}
DrawTitle();
@ -121,12 +121,14 @@ namespace Launcher {
}
}
public void ClearArea( int x, int y, int width, int height ) {
using( FastBitmap dst = new FastBitmap( Framebuffer, true, false ) )
ClearArea( x, y, width, height, dst );
/// <summary> Redraws the specified region with the background pixels. </summary>
public void ResetArea( int x, int y, int width, int height ) {
using( FastBitmap dst = LockBits() )
ResetArea( x, y, width, height, dst );
}
public void ClearArea( int x, int y, int width, int height, FastBitmap dst ) {
/// <summary> Redraws the specified region with the background pixels. </summary>
public void ResetArea( int x, int y, int width, int height, FastBitmap dst ) {
if( ClassicBackground && terrainPixels != null ) {
ClearTile( x, y, width, height, 0, dst );
} else {

View File

@ -234,5 +234,9 @@ namespace Launcher {
if( !OpenTK.Configuration.RunningOnMacOS ) return false;
return key == Key.Q && (lastKey == Key.WinLeft || lastKey == Key.WinRight);
}
public FastBitmap LockBits() {
return new FastBitmap( Framebuffer, true, false );
}
}
}