Remove some redundant font creations in launcher, fix few more C compile errors

This commit is contained in:
UnknownShadow200 2017-11-07 16:18:51 +11:00
parent 2f3fa76c6e
commit 813ea75a4b
8 changed files with 37 additions and 39 deletions

View File

@ -10,10 +10,8 @@ using Launcher.Gui.Widgets;
namespace Launcher.Gui.Screens { namespace Launcher.Gui.Screens {
public sealed class DirectConnectScreen : InputScreen { public sealed class DirectConnectScreen : InputScreen {
Font booleanFont;
DirectConnectView view; DirectConnectView view;
public DirectConnectScreen(LauncherWindow game) : base(game) { public DirectConnectScreen(LauncherWindow game) : base(game) {
booleanFont = new Font(game.FontName, 22, FontStyle.Regular);
enterIndex = 3; enterIndex = 3;
view = new DirectConnectView(game); view = new DirectConnectView(game);
widgets = view.widgets; widgets = view.widgets;
@ -57,7 +55,6 @@ namespace Launcher.Gui.Screens {
public override void Dispose() { public override void Dispose() {
StoreFields(); StoreFields();
base.Dispose(); base.Dispose();
booleanFont.Dispose();
} }
static string cachedUser, cachedAddress, cachedMppass; static string cachedUser, cachedAddress, cachedMppass;

View File

@ -14,7 +14,7 @@ namespace Launcher.Gui.Views {
internal int defIndex, sliderIndex; internal int defIndex, sliderIndex;
public override void Init() { public override void Init() {
titleFont = new Font(game.FontName, 15, FontStyle.Bold); titleFont = new Font(game.FontName, 16, FontStyle.Bold);
textFont = new Font(game.FontName, 14, FontStyle.Regular); textFont = new Font(game.FontName, 14, FontStyle.Regular);
inputHintFont = new Font(game.FontName, 12, FontStyle.Italic); inputHintFont = new Font(game.FontName, 12, FontStyle.Italic);
MakeWidgets(); MakeWidgets();

View File

@ -7,7 +7,6 @@ using Launcher.Gui.Widgets;
namespace Launcher.Gui.Views { namespace Launcher.Gui.Views {
public sealed class MainView : IView { public sealed class MainView : IView {
Font buttonFont, updateFont;
internal int loginIndex, resIndex, dcIndex, spIndex, statusIndex; internal int loginIndex, resIndex, dcIndex, spIndex, statusIndex;
internal int sslIndex, settingsIndex; internal int sslIndex, settingsIndex;
const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150; const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150;
@ -17,12 +16,9 @@ namespace Launcher.Gui.Views {
} }
public override void Init() { public override void Init() {
titleFont = new Font(game.FontName, 15, FontStyle.Bold); titleFont = new Font(game.FontName, 16, FontStyle.Bold);
textFont = new Font(game.FontName, 14, FontStyle.Regular); textFont = new Font(game.FontName, 14, FontStyle.Regular);
inputHintFont = new Font(game.FontName, 12, FontStyle.Italic); inputHintFont = new Font(game.FontName, 12, FontStyle.Italic);
buttonFont = new Font(game.FontName, 16, FontStyle.Bold);
updateFont = new Font(game.FontName, 12, FontStyle.Italic);
MakeWidgets(); MakeWidgets();
} }
@ -31,12 +27,6 @@ namespace Launcher.Gui.Views {
return widget == null ? "" : widget.Text; return widget == null ? "" : widget.Text;
} }
public override void Dispose() {
buttonFont.Dispose();
updateFont.Dispose();
base.Dispose();
}
internal string updateText = "&eChecking.."; internal string updateText = "&eChecking..";
protected override void MakeWidgets() { protected override void MakeWidgets() {
@ -47,7 +37,7 @@ namespace Launcher.Gui.Views {
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -75); .SetLocation(Anchor.Centre, Anchor.Centre, 0, -75);
loginIndex = widgetIndex; loginIndex = widgetIndex;
Makers.Button(this, "Sign in", 100, buttonHeight, buttonFont) Makers.Button(this, "Sign in", 100, buttonHeight, titleFont)
.SetLocation(Anchor.Centre, Anchor.Centre, -90, -25); .SetLocation(Anchor.Centre, Anchor.Centre, -90, -25);
statusIndex = widgetIndex; statusIndex = widgetIndex;
Makers.Label(this, Get(statusIndex), textFont) Makers.Label(this, Get(statusIndex), textFont)
@ -55,13 +45,13 @@ namespace Launcher.Gui.Views {
resIndex = widgetIndex; resIndex = widgetIndex;
Makers.Button(this, "Resume", 100, buttonHeight, buttonFont) Makers.Button(this, "Resume", 100, buttonHeight, titleFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 90, -25); .SetLocation(Anchor.Centre, Anchor.Centre, 90, -25);
dcIndex = widgetIndex; dcIndex = widgetIndex;
Makers.Button(this, "Direct connect", 200, buttonHeight, buttonFont) Makers.Button(this, "Direct connect", 200, buttonHeight, titleFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 60); .SetLocation(Anchor.Centre, Anchor.Centre, 0, 60);
spIndex = widgetIndex; spIndex = widgetIndex;
Makers.Button(this, "Singleplayer", 200, buttonHeight, buttonFont) Makers.Button(this, "Singleplayer", 200, buttonHeight, titleFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110);
sslIndex = widgetIndex; sslIndex = widgetIndex;
@ -73,11 +63,11 @@ namespace Launcher.Gui.Views {
widgets[sslIndex].Visible = sslVisible; widgets[sslIndex].Visible = sslVisible;
widgets[sslIndex + 1].Visible = sslVisible; widgets[sslIndex + 1].Visible = sslVisible;
Makers.Label(this, updateText, updateFont) Makers.Label(this, updateText, inputHintFont)
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -45); .SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -45);
settingsIndex = widgetIndex; settingsIndex = widgetIndex;
Makers.Button(this, "Options", 100, buttonHeight, buttonFont) Makers.Button(this, "Options", 100, buttonHeight, titleFont)
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -6, -6); .SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -6, -6);
} }
} }

View File

@ -4,7 +4,6 @@ using System.Drawing;
using ClassicalSharp; using ClassicalSharp;
using Launcher.Drawing; using Launcher.Drawing;
using Launcher.Gui.Widgets; using Launcher.Gui.Widgets;
using OpenTK.Input;
namespace Launcher.Gui.Views { namespace Launcher.Gui.Views {
public sealed class ServersView : IView { public sealed class ServersView : IView {
@ -20,7 +19,7 @@ namespace Launcher.Gui.Views {
} }
public override void Init() { public override void Init() {
titleFont = new Font(game.FontName, 15, FontStyle.Bold); titleFont = new Font(game.FontName, 16, FontStyle.Bold);
textFont = new Font(game.FontName, 14, FontStyle.Regular); textFont = new Font(game.FontName, 14, FontStyle.Regular);
inputHintFont = new Font(game.FontName, 12, FontStyle.Italic); inputHintFont = new Font(game.FontName, 12, FontStyle.Italic);
tableFont = new Font(game.FontName, 11, FontStyle.Regular); tableFont = new Font(game.FontName, 11, FontStyle.Regular);

View File

@ -10,6 +10,8 @@
/* Newline for text */ /* Newline for text */
extern UInt8* Platform_NewLine; extern UInt8* Platform_NewLine;
extern UInt8 Platform_DirectorySeparator;
extern ReturnCode ReturnCode_FileShareViolation;
/* Initalises required state for this platform. */ /* Initalises required state for this platform. */
void Platform_Init(void); void Platform_Init(void);

View File

@ -15,29 +15,20 @@ String String_FromRawBuffer(UInt8* buffer, UInt16 capacity) {
Int32 i; Int32 i;
/* Need to set region occupied by string to NULL for interop with native APIs */ /* Need to set region occupied by string to NULL for interop with native APIs */
for (i = 0; i < capacity + 1; i++) { for (i = 0; i < capacity + 1; i++) { buffer[i] = NULL; }
buffer[i] = 0;
}
return str; return str;
} }
String String_FromReadonly(const UInt8* buffer) { String String_FromReadonly(const UInt8* buffer) {
UInt16 length = 0; UInt16 length = 0;
UInt8 cur = 0; UInt8* cur = buffer;
UInt8* ptr = buffer; while ((*cur) != NULL) { cur++; length++; }
while ((cur = *buffer) != 0) { String str = String_FromEmptyBuffer(buffer, length);
length++; buffer++;
}
String str = String_FromEmptyBuffer(ptr, length);
str.length = length; str.length = length;
return str; return str;
} }
String String_MakeNull(void) { return String_FromEmptyBuffer(NULL, 0); }
String String_MakeNull(void) {
return String_FromEmptyBuffer(NULL, 0);
}
void String_MakeLowercase(STRING_TRANSIENT String* str) { void String_MakeLowercase(STRING_TRANSIENT String* str) {
@ -50,7 +41,7 @@ void String_MakeLowercase(STRING_TRANSIENT String* str) {
void String_Clear(STRING_TRANSIENT String* str) { void String_Clear(STRING_TRANSIENT String* str) {
Int32 i; Int32 i;
for (i = 0; i < str->length; i++) { for (i = 0; i < str->length; i++) {
str->buffer[i] = 0; str->buffer[i] = NULL;
} }
str->length = 0; str->length = 0;
} }
@ -390,3 +381,18 @@ bool Convert_TryParseBool(STRING_PURE String* str, bool* value) {
*value = false; return false; *value = false; return false;
} }
#define STRINGSBUFFER_LEN_SHIFT 10
#define STRINGSBUFFER_LEN_MASK 0x3FFUL
void StringsBuffer_Get(StringsBuffer* buffer, UInt32 index, STRING_TRANSIENT String* text) {
if (index >= buffer->Count) ErrorHandler_Fail("Tried to get String past StringsBuffer end");
String_Clear(text);
UInt32 flags = buffer->FlagsBuffer[index];
UInt32 offset = flags >> STRINGSBUFFER_LEN_SHIFT;
UInt32 len = flags & STRINGSBUFFER_LEN_MASK;
UInt8* src = &buffer->FlagsBuffer[offset];
UInt32 i;
for (i = 0; i < len; i++) { String_Append(text, src[i]); }
}

View File

@ -108,6 +108,8 @@ typedef struct StringsBuffer_ {
UInt32 FlagsBufferSize; UInt32 FlagsBufferSize;
UInt32 Count; UInt32 Count;
} StringsBuffer; } StringsBuffer;
void StringsBuffer_Get(StringsBuffer* buffer, UInt32 index, STRING_TRANSIENT String* text); void StringsBuffer_Get(StringsBuffer* buffer, UInt32 index, STRING_TRANSIENT String* text);
void StringsBuffer_Add(StringsBuffer* buffer, STRING_PURE String* text); void StringsBuffer_Add(StringsBuffer* buffer, STRING_PURE String* text);
void StringsBuffer_Free(StringsBuffer* buffer);
#endif #endif

View File

@ -12,6 +12,8 @@ HBITMAP hbmp;
HANDLE heap; HANDLE heap;
UInt8* Platform_NewLine = "\r\n"; UInt8* Platform_NewLine = "\r\n";
UInt8 Platform_DirectorySeparator = '\\';
ReturnCode ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION;
void Platform_Init(void) { void Platform_Init(void) {
heap = GetProcessHeap(); /* TODO: HeapCreate instead? probably not */ heap = GetProcessHeap(); /* TODO: HeapCreate instead? probably not */