Make launcher look closer to C# one

also offset text shadows slightly more for system fonts
This commit is contained in:
UnknownShadow200 2019-01-08 19:10:27 +11:00
parent 1ebd553f36
commit f889ae6223
6 changed files with 36 additions and 24 deletions

View File

@ -213,7 +213,7 @@ namespace ClassicalSharp.Entities {
return true; return true;
} else if (!warnedRespawn) { } else if (!warnedRespawn) {
warnedRespawn = true; warnedRespawn = true;
if (!hackPermMsgs) game.Chat.Add("&cRespawning is currently disabled"); if (hackPermMsgs) game.Chat.Add("&cRespawning is currently disabled");
} }
return false; return false;
} }
@ -245,7 +245,7 @@ namespace ClassicalSharp.Entities {
return true; return true;
} else if (!warnedFly) { } else if (!warnedFly) {
warnedFly = true; warnedFly = true;
if (!hackPermMsgs) game.Chat.Add("&cFlying is currently disabled"); if (hackPermMsgs) game.Chat.Add("&cFlying is currently disabled");
} }
return false; return false;
} }
@ -259,7 +259,7 @@ namespace ClassicalSharp.Entities {
return true; return true;
} else if (!warnedNoclip) { } else if (!warnedNoclip) {
warnedNoclip = true; warnedNoclip = true;
if (!hackPermMsgs) game.Chat.Add("&cNoclip is currently disabled"); if (hackPermMsgs) game.Chat.Add("&cNoclip is currently disabled");
} }
return false; return false;
} }

View File

@ -15,7 +15,6 @@ BitmapCol Drawer2D_Cols[DRAWER2D_MAX_COLS];
static char fontNameBuffer[STRING_SIZE]; static char fontNameBuffer[STRING_SIZE];
String Drawer2D_FontName = String_FromArray(fontNameBuffer); String Drawer2D_FontName = String_FromArray(fontNameBuffer);
#define DRAWER2D_OFFSET 1
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, const FontDesc* font, bool useShadow) { void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, const FontDesc* font, bool useShadow) {
args->Text = *text; args->Text = *text;
@ -558,10 +557,10 @@ void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
col = Drawer2D_GetCol(colCode); col = Drawer2D_GetCol(colCode);
if (args->UseShadow) { if (args->UseShadow) {
backCol = Drawer2D_BlackTextShadows ? black : BitmapCol_Scale(col, 0.25f); backCol = Drawer2D_BlackTextShadows ? black : BitmapCol_Scale(col, 0.25f);
Platform_TextDraw(args, bmp, x + DRAWER2D_OFFSET, y + DRAWER2D_OFFSET, backCol); Platform_TextDraw(args, bmp, x, y, backCol, true);
} }
partWidth = Platform_TextDraw(args, bmp, x, y, col); partWidth = Platform_TextDraw(args, bmp, x, y, col, false);
x += partWidth; x += partWidth;
} }
args->Text = value; args->Text = value;
@ -583,9 +582,7 @@ int Drawer2D_TextWidth(struct DrawTextArgs* args) {
width += Platform_TextWidth(args); width += Platform_TextWidth(args);
} }
/* TODO: Is this font shadow offset right? */ if (args->UseShadow) width += 2;
if (args->UseShadow) { width += DRAWER2D_OFFSET; }
args->Text = value; args->Text = value;
return width; return width;
} }
@ -600,8 +597,7 @@ int Drawer2D_FontHeight(const FontDesc* font, bool useShadow) {
if (useShadow) { height += Drawer2D_ShadowOffset(point); } if (useShadow) { height += Drawer2D_ShadowOffset(point); }
} else { } else {
height = Platform_FontHeight(font); height = Platform_FontHeight(font);
/* TODO: Is this font shadow offset right? */ if (useShadow) height += 2;
if (useShadow) { height += DRAWER2D_OFFSET; }
} }
return height; return height;
} }

View File

@ -675,9 +675,9 @@ static int SoftwareColumn_Sort(const struct ServerInfo* a, const struct ServerIn
static struct LTableColumn tableColumns[5] = { static struct LTableColumn tableColumns[5] = {
{ "", 15, FlagColumn_Draw, NULL, false, false }, { "", 15, FlagColumn_Draw, NULL, false, false },
{ "Name", 320, NameColumn_Draw, NameColumn_Sort, true, true }, { "Name", 325, NameColumn_Draw, NameColumn_Sort, true, true },
{ "Players", 65, PlayersColumn_Draw, PlayersColumn_Sort, true, true }, { "Players", 70, PlayersColumn_Draw, PlayersColumn_Sort, true, true },
{ "Uptime", 65, UptimeColumn_Draw, UptimeColumn_Sort, true, true }, { "Uptime", 70, UptimeColumn_Draw, UptimeColumn_Sort, true, true },
{ "Software", 140, SoftwareColumn_Draw, SoftwareColumn_Sort, false, true } { "Software", 140, SoftwareColumn_Draw, SoftwareColumn_Sort, false, true }
}; };

View File

@ -220,7 +220,8 @@ void Launcher_Run(void) {
Drawer2D_Component.Init(); Drawer2D_Component.Init();
Game_UpdateClientSize(); Game_UpdateClientSize();
Drawer2D_BitmappedText = false; Drawer2D_BitmappedText = false;
Drawer2D_BlackTextShadows = true;
Launcher_LoadSkin(); Launcher_LoadSkin();
Launcher_Init(); Launcher_Init();

View File

@ -832,7 +832,8 @@ struct FontData {
FT_StreamRec stream; FT_StreamRec stream;
uint8_t buffer[8192]; /* small buffer to minimise disk I/O */ uint8_t buffer[8192]; /* small buffer to minimise disk I/O */
uint16_t widths[256]; /* cached width of each character glyph */ uint16_t widths[256]; /* cached width of each character glyph */
FT_Glyph glyphs[256]; /* cached glyph */ FT_Glyph glyphs[256]; /* cached glyphs */
FT_Glyph shadow_glyphs[256]; /* cached glyphs (for back layer shadow) */
#ifdef CC_BUILD_OSX #ifdef CC_BUILD_OSX
char filename[FILENAME_SIZE + 1]; char filename[FILENAME_SIZE + 1];
#endif #endif
@ -883,8 +884,9 @@ static bool FontData_Init(const String* path, struct FontData* data, FT_Open_Arg
data->filename[filename.length] = '\0'; data->filename[filename.length] = '\0';
args->pathname = data->filename; args->pathname = data->filename;
#endif #endif
Mem_Set(data->widths, 0xFF, sizeof(data->widths)); Mem_Set(data->widths, 0xFF, sizeof(data->widths));
Mem_Set(data->glyphs, 0x00, sizeof(data->glyphs)); Mem_Set(data->glyphs, 0x00, sizeof(data->glyphs));
Mem_Set(data->shadow_glyphs, 0x00, sizeof(data->shadow_glyphs));
return true; return true;
} }
@ -898,6 +900,10 @@ static void FontData_Free(struct FontData* font) {
if (!font->glyphs[i]) continue; if (!font->glyphs[i]) continue;
FT_Done_Glyph(font->glyphs[i]); FT_Done_Glyph(font->glyphs[i]);
} }
for (i = 0; i < 256; i++) {
if (!font->shadow_glyphs[i]) continue;
FT_Done_Glyph(font->shadow_glyphs[i]);
}
} }
void Font_GetNames(StringsBuffer* buffer) { void Font_GetNames(StringsBuffer* buffer) {
@ -1141,12 +1147,14 @@ static void Platform_BlackWhiteGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y,
} }
} }
int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col) { int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col, bool shadow) {
struct FontData* data = args->Font.Handle; struct FontData* data = args->Font.Handle;
FT_Face face = data->face; FT_Face face = data->face;
String text = args->Text; String text = args->Text;
FT_Glyph* glyphs = data->glyphs;
int descender, height, begX = x; int descender, height, begX = x;
/* glyph state */ /* glyph state */
FT_BitmapGlyph glyph; FT_BitmapGlyph glyph;
FT_Bitmap* img; FT_Bitmap* img;
@ -1154,11 +1162,17 @@ int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, Bitm
FT_Error res; FT_Error res;
Codepoint cp; Codepoint cp;
if (shadow) {
glyphs = data->shadow_glyphs;
FT_Vector delta = { 83, -83 };
FT_Set_Transform(face, NULL, &delta);
}
height = TEXT_CEIL(face->size->metrics.height); height = TEXT_CEIL(face->size->metrics.height);
descender = TEXT_CEIL(face->size->metrics.descender); descender = TEXT_CEIL(face->size->metrics.descender);
for (i = 0; i < text.length; i++) { for (i = 0; i < text.length; i++) {
glyph = data->glyphs[(uint8_t)text.buffer[i]]; glyph = glyphs[(uint8_t)text.buffer[i]];
if (!glyph) { if (!glyph) {
cp = Convert_CP437ToUnicode(text.buffer[i]); cp = Convert_CP437ToUnicode(text.buffer[i]);
res = FT_Load_Char(face, cp, FT_LOAD_RENDER); res = FT_Load_Char(face, cp, FT_LOAD_RENDER);
@ -1169,7 +1183,7 @@ int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, Bitm
} }
FT_Get_Glyph(face->glyph, &glyph); /* TODO: Check error */ FT_Get_Glyph(face->glyph, &glyph); /* TODO: Check error */
data->glyphs[(uint8_t)text.buffer[i]] = glyph; glyphs[(uint8_t)text.buffer[i]] = glyph;
} }
offset = (height + descender) - glyph->top; offset = (height + descender) - glyph->top;
@ -1195,6 +1209,7 @@ int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, Bitm
Drawer2D_Underline(bmp, begX, ulY + y, x - begX, ulHeight, col); Drawer2D_Underline(bmp, begX, ulY + y, x - begX, ulHeight, col);
} }
if (shadow) FT_Set_Transform(face, NULL, NULL);
return x - begX; return x - begX;
} }

View File

@ -200,7 +200,7 @@ int Platform_TextWidth(struct DrawTextArgs* args);
/* Measures height of any text when drawn with the given font. */ /* Measures height of any text when drawn with the given font. */
int Platform_FontHeight(const FontDesc* font); int Platform_FontHeight(const FontDesc* font);
/* Draws the given text with the given font onto the given bitmap. */ /* Draws the given text with the given font onto the given bitmap. */
int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col); int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, BitmapCol col, bool shadow);
/* Allocates a new socket. */ /* Allocates a new socket. */
void Socket_Create(SocketHandle* socket); void Socket_Create(SocketHandle* socket);