diff --git a/Launcher2/Gui/Screens/Screen.cs b/Launcher2/Gui/Screens/Screen.cs
index 814557959..870ada2fc 100644
--- a/Launcher2/Gui/Screens/Screen.cs
+++ b/Launcher2/Gui/Screens/Screen.cs
@@ -61,6 +61,9 @@ namespace Launcher.Gui.Screens {
game.ResetArea( label.X, label.Y, label.Width, label.Height );
RedrawWidget( label );
}
+
+ BitmapWidget bitmap = widget as BitmapWidget;
+ if( bitmap != null ) RedrawWidget( bitmap );
}
/// Redraws the given widget and marks the window as needing to be redrawn.
diff --git a/Launcher2/Gui/Views/DirectConnectView.cs b/Launcher2/Gui/Views/DirectConnectView.cs
index c389523bc..5c2933c92 100644
--- a/Launcher2/Gui/Views/DirectConnectView.cs
+++ b/Launcher2/Gui/Views/DirectConnectView.cs
@@ -4,7 +4,7 @@ using System.Drawing;
using ClassicalSharp;
using Launcher.Gui.Widgets;
-namespace Launcher.Gui.Views {
+namespace Launcher.Gui.Views {
public sealed class DirectConnectView : IView {
internal int connectIndex, backIndex, ccSkinsIndex, statusIndex;
@@ -45,7 +45,7 @@ namespace Launcher.Gui.Views {
connectIndex = widgetIndex;
Makers.Button( this, "Connect", 110, 35, titleFont )
- .SetLocation( Anchor.Centre, Anchor.Centre, -110, 50 );
+ .SetLocation( Anchor.Centre, Anchor.Centre, -110, 50 );
backIndex = widgetIndex;
Makers.Button( this, "Back", 80, 35, titleFont )
.SetLocation( Anchor.Centre, Anchor.Centre, 125, 50 );
diff --git a/Launcher2/Gui/Widgets/BitmapWidget.cs b/Launcher2/Gui/Widgets/BitmapWidget.cs
new file mode 100644
index 000000000..6360d0d03
--- /dev/null
+++ b/Launcher2/Gui/Widgets/BitmapWidget.cs
@@ -0,0 +1,58 @@
+// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
+using System;
+using ClassicalSharp;
+
+namespace Launcher.Gui.Widgets {
+ /// Represents an image that cannot be modified by the user.
+ /// Uses 4 bit (16 colour) palette.
+ public sealed class BitmapWidget : Widget {
+
+ /// The raw indices within the palette that make up this image.
+ public byte[] Indices;
+
+ /// The ARGB palette for this image.
+ public FastColour[] Palette;
+
+ public BitmapWidget( LauncherWindow window, int size,
+ byte[] indices, FastColour[] palette ) : base( window ) {
+ Indices = indices;
+ Palette = palette;
+ Width = size; Height = size;
+ }
+
+ public unsafe override void Redraw( IDrawer2D drawer ) {
+ if( Window.Minimised || !Visible ) return;
+ int* palette = stackalloc int[Palette.Length];
+ CalculatePalette( palette );
+
+ using( FastBitmap bmp = Window.LockBits() ) {
+ int i = 0;
+ for( int yy = 0; yy < Height; yy++ ) {
+ if( (Y + yy) < 0 ) continue;
+ if( (Y + yy) >= bmp.Height ) break;
+ int* row = bmp.GetRowPtr( Y + yy );
+
+ for( int xx = 0; xx < Width; xx++ ) {
+ int index = Indices[i >> 1]; // each byte has even and odd 4bits
+ int selector = 4 * ((i + 1) & 1);
+ index = (index >> selector) & 0xF;
+ i++;
+
+ int col = palette[index];
+ if( col == 0 ) continue; // transparent pixel
+ if( (X + xx) < 0 || (X + xx) >= bmp.Width ) continue;
+ row[X + xx] = col;
+ }
+ }
+ }
+ }
+
+ unsafe void CalculatePalette( int* palette ) {
+ for( int i = 0; i < Palette.Length; i++ ) {
+ FastColour col = Palette[i];
+ if( !Active ) col = FastColour.Scale( col, 0.7f );
+ palette[i] = col.ToArgb();
+ }
+ }
+ }
+}
diff --git a/Launcher2/Gui/Widgets/Makers.cs b/Launcher2/Gui/Widgets/Makers.cs
index 5b0966e2b..69387fede 100644
--- a/Launcher2/Gui/Widgets/Makers.cs
+++ b/Launcher2/Gui/Widgets/Makers.cs
@@ -3,7 +3,7 @@ using System.Drawing;
using ClassicalSharp;
using Launcher.Gui.Views;
-namespace Launcher.Gui.Widgets {
+namespace Launcher.Gui.Widgets {
/// Helper methods to construct widgets.
public static class Makers {
@@ -85,5 +85,19 @@ namespace Launcher.Gui.Widgets {
view.widgetIndex++;
return widget;
}
+
+ public static Widget Bitmap( IView view, byte[] indices,
+ FastColour[] palette, int size ) {
+ BitmapWidget widget;
+ if( view.widgets[view.widgetIndex] != null ) {
+ widget = (BitmapWidget)view.widgets[view.widgetIndex];
+ } else {
+ widget = new BitmapWidget( view.game, size, indices, palette );
+ view.widgets[view.widgetIndex] = widget;
+ }
+
+ view.widgetIndex++;
+ return widget;
+ }
}
}
diff --git a/Launcher2/Launcher2.csproj b/Launcher2/Launcher2.csproj
index 100e687ad..c134118fd 100644
--- a/Launcher2/Launcher2.csproj
+++ b/Launcher2/Launcher2.csproj
@@ -85,6 +85,7 @@
+