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

View File

@ -14,7 +14,7 @@ namespace Launcher.Gui.Views {
internal int defIndex, sliderIndex;
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);
inputHintFont = new Font(game.FontName, 12, FontStyle.Italic);
MakeWidgets();

View File

@ -7,7 +7,6 @@ using Launcher.Gui.Widgets;
namespace Launcher.Gui.Views {
public sealed class MainView : IView {
Font buttonFont, updateFont;
internal int loginIndex, resIndex, dcIndex, spIndex, statusIndex;
internal int sslIndex, settingsIndex;
const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150;
@ -17,12 +16,9 @@ namespace Launcher.Gui.Views {
}
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);
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();
}
@ -30,12 +26,6 @@ namespace Launcher.Gui.Views {
Widget widget = widgets[index];
return widget == null ? "" : widget.Text;
}
public override void Dispose() {
buttonFont.Dispose();
updateFont.Dispose();
base.Dispose();
}
internal string updateText = "&eChecking..";
@ -47,7 +37,7 @@ namespace Launcher.Gui.Views {
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -75);
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);
statusIndex = widgetIndex;
Makers.Label(this, Get(statusIndex), textFont)
@ -55,13 +45,13 @@ namespace Launcher.Gui.Views {
resIndex = widgetIndex;
Makers.Button(this, "Resume", 100, buttonHeight, buttonFont)
Makers.Button(this, "Resume", 100, buttonHeight, titleFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 90, -25);
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);
spIndex = widgetIndex;
Makers.Button(this, "Singleplayer", 200, buttonHeight, buttonFont)
Makers.Button(this, "Singleplayer", 200, buttonHeight, titleFont)
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 110);
sslIndex = widgetIndex;
@ -73,11 +63,11 @@ namespace Launcher.Gui.Views {
widgets[sslIndex].Visible = sslVisible;
widgets[sslIndex + 1].Visible = sslVisible;
Makers.Label(this, updateText, updateFont)
Makers.Label(this, updateText, inputHintFont)
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -45);
settingsIndex = widgetIndex;
Makers.Button(this, "Options", 100, buttonHeight, buttonFont)
Makers.Button(this, "Options", 100, buttonHeight, titleFont)
.SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, -6, -6);
}
}

View File

@ -4,7 +4,6 @@ using System.Drawing;
using ClassicalSharp;
using Launcher.Drawing;
using Launcher.Gui.Widgets;
using OpenTK.Input;
namespace Launcher.Gui.Views {
public sealed class ServersView : IView {
@ -20,7 +19,7 @@ namespace Launcher.Gui.Views {
}
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);
inputHintFont = new Font(game.FontName, 12, FontStyle.Italic);
tableFont = new Font(game.FontName, 11, FontStyle.Regular);

View File

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

View File

@ -15,29 +15,20 @@ String String_FromRawBuffer(UInt8* buffer, UInt16 capacity) {
Int32 i;
/* Need to set region occupied by string to NULL for interop with native APIs */
for (i = 0; i < capacity + 1; i++) {
buffer[i] = 0;
}
for (i = 0; i < capacity + 1; i++) { buffer[i] = NULL; }
return str;
}
String String_FromReadonly(const UInt8* buffer) {
UInt16 length = 0;
UInt8 cur = 0;
UInt8* ptr = buffer;
UInt8* cur = buffer;
while ((*cur) != NULL) { cur++; length++; }
while ((cur = *buffer) != 0) {
length++; buffer++;
}
String str = String_FromEmptyBuffer(ptr, length);
String str = String_FromEmptyBuffer(buffer, length);
str.length = length;
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) {
@ -49,8 +40,8 @@ void String_MakeLowercase(STRING_TRANSIENT String* str) {
void String_Clear(STRING_TRANSIENT String* str) {
Int32 i;
for (i = 0; i < str->length; i++) {
str->buffer[i] = 0;
for (i = 0; i < str->length; i++) {
str->buffer[i] = NULL;
}
str->length = 0;
}
@ -389,4 +380,19 @@ bool Convert_TryParseBool(STRING_PURE String* str, bool* value) {
}
*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 Count;
} StringsBuffer;
void StringsBuffer_Get(StringsBuffer* buffer, UInt32 index, STRING_TRANSIENT String* text);
void StringsBuffer_Add(StringsBuffer* buffer, STRING_PURE String* text);
void StringsBuffer_Free(StringsBuffer* buffer);
#endif

View File

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