mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Fix urls also being italicised
Also make 'underline' a flag instead of a separate style
This commit is contained in:
parent
19ee03a901
commit
84578127fa
@ -48,7 +48,7 @@ enum FACE_CONSTS {
|
||||
};
|
||||
|
||||
enum SKIN_TYPE { SKIN_64x32, SKIN_64x64, SKIN_64x64_SLIM, SKIN_INVALID = 0xF0 };
|
||||
enum FONT_STYLE { FONT_STYLE_NORMAL, FONT_STYLE_BOLD, FONT_STYLE_ITALIC, FONT_STYLE_UNDERLINE };
|
||||
enum FONT_STYLE { FONT_STYLE_NORMAL, FONT_STYLE_BOLD, FONT_STYLE_ITALIC, FONT_FLAG_UNDERLINE = 0x80 };
|
||||
#define DRAWER2D_MAX_COLS 256
|
||||
|
||||
#define UInt8_MaxValue ((uint8_t)255)
|
||||
|
@ -488,7 +488,7 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int
|
||||
x = begX;
|
||||
}
|
||||
|
||||
if (args->Font.Style != FONT_STYLE_UNDERLINE) return;
|
||||
if (!(args->Font.Style & FONT_FLAG_UNDERLINE)) return;
|
||||
/* scale up bottom row of a cell to drawn text font */
|
||||
cellY = (8 - 1) * dstHeight / 8;
|
||||
underlineY = y + (cellY + yPadding);
|
||||
|
@ -1919,7 +1919,7 @@ static void MenuOptionsScreen_SelectExtHelp(struct MenuOptionsScreen* s, int idx
|
||||
descRaw = String_FromReadonly(desc);
|
||||
count = String_UNSAFE_Split(&descRaw, '|', descLines, Array_Elems(descLines));
|
||||
|
||||
TextGroupWidget_Create(&s->ExtHelp, count, &s->TextFont, &s->TextFont, s->ExtHelp_Textures, s->ExtHelp_Buffer);
|
||||
TextGroupWidget_Create(&s->ExtHelp, count, &s->TextFont, s->ExtHelp_Textures, s->ExtHelp_Buffer);
|
||||
Widget_SetLocation((struct Widget*)(&s->ExtHelp), ANCHOR_MIN, ANCHOR_MIN, 0, 0);
|
||||
Elem_Init(&s->ExtHelp);
|
||||
|
||||
|
@ -1152,7 +1152,7 @@ int Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, Bitm
|
||||
x -= face->glyph->bitmap_left; y -= offset;
|
||||
}
|
||||
|
||||
if (args->Font.Style == FONT_STYLE_UNDERLINE) {
|
||||
if (args->Font.Style & FONT_FLAG_UNDERLINE) {
|
||||
int ul_pos = FT_MulFix(face->underline_position, face->size->metrics.y_scale);
|
||||
int ul_thick = FT_MulFix(face->underline_thickness, face->size->metrics.y_scale);
|
||||
|
||||
|
@ -69,7 +69,7 @@ struct ChatScreen {
|
||||
bool SuppressNextPress;
|
||||
int ChatIndex;
|
||||
int LastDownloadStatus;
|
||||
FontDesc ChatFont, ChatUrlFont, AnnouncementFont;
|
||||
FontDesc ChatFont, AnnouncementFont;
|
||||
struct TextWidget Announcement;
|
||||
struct ChatInputWidget Input;
|
||||
struct TextGroupWidget Status, BottomRight, Chat, ClientStatus;
|
||||
@ -754,7 +754,7 @@ static void ChatScreen_ResetChat(struct ChatScreen* s) {
|
||||
}
|
||||
|
||||
static void ChatScreen_ConstructWidgets(struct ChatScreen* s) {
|
||||
#define ChatScreen_MakeGroup(widget, lines, textures, buffer) TextGroupWidget_Create(widget, lines, &s->ChatFont, &s->ChatUrlFont, textures, buffer);
|
||||
#define ChatScreen_MakeGroup(widget, lines, textures, buffer) TextGroupWidget_Create(widget, lines, &s->ChatFont, textures, buffer);
|
||||
int yOffset = ChatScreen_BottomOffset() + 15;
|
||||
|
||||
ChatInputWidget_Create(&s->Input, &s->ChatFont);
|
||||
@ -1108,7 +1108,6 @@ static void ChatScreen_Init(void* screen) {
|
||||
Math_Clamp(largeSize, 8, 60);
|
||||
|
||||
Drawer2D_MakeFont(&s->ChatFont, fontSize, FONT_STYLE_NORMAL);
|
||||
Drawer2D_MakeFont(&s->ChatUrlFont, fontSize, FONT_STYLE_UNDERLINE);
|
||||
Drawer2D_MakeFont(&s->AnnouncementFont, largeSize, FONT_STYLE_NORMAL);
|
||||
Screen_CommonInit(s);
|
||||
|
||||
@ -1167,7 +1166,6 @@ static void ChatScreen_Render(void* screen, double delta) {
|
||||
static void ChatScreen_Free(void* screen) {
|
||||
struct ChatScreen* s = screen;
|
||||
Font_Free(&s->ChatFont);
|
||||
Font_Free(&s->ChatUrlFont);
|
||||
Font_Free(&s->AnnouncementFont);
|
||||
Screen_CommonFree(s);
|
||||
|
||||
|
@ -2483,7 +2483,7 @@ static bool TextGroupWidget_GetUrl(struct TextGroupWidget* w, String* text, int
|
||||
for (i = 0, x = 0; i < portionsCount; i++) {
|
||||
bit = portions[i];
|
||||
args.Text = String_UNSAFE_Substring(&line, bit.LineBeg, bit.LineLen);
|
||||
args.Font = (bit.Len & TEXTGROUPWIDGET_URL) ? w->UnderlineFont : w->Font;
|
||||
args.Font = w->Font;
|
||||
|
||||
width = Drawer2D_TextWidth(&args);
|
||||
if ((bit.Len & TEXTGROUPWIDGET_URL) && mouseX >= x && mouseX < x + width) {
|
||||
@ -2538,14 +2538,12 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
|
||||
Size2D partSizes[Array_Elems(portions)];
|
||||
Bitmap bmp;
|
||||
int portionsCount;
|
||||
int i, x;
|
||||
int i, x, ul;
|
||||
|
||||
portionsCount = TextGroupWidget_Reduce(w, chars, index, portions);
|
||||
for (i = 0; i < portionsCount; i++) {
|
||||
bit = portions[i];
|
||||
|
||||
args->Text = String_UNSAFE_Substring(text, bit.LineBeg, bit.LineLen);
|
||||
args->Font = (bit.Len & TEXTGROUPWIDGET_URL) ? w->UnderlineFont : w->Font;
|
||||
|
||||
partSizes[i] = Drawer2D_MeasureText(args);
|
||||
size.Height = max(partSizes[i].Height, size.Height);
|
||||
@ -2557,11 +2555,13 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
|
||||
x = 0;
|
||||
for (i = 0; i < portionsCount; i++) {
|
||||
bit = portions[i];
|
||||
|
||||
ul = (bit.Len & TEXTGROUPWIDGET_URL);
|
||||
args->Text = String_UNSAFE_Substring(text, bit.LineBeg, bit.LineLen);
|
||||
args->Font = (bit.Len & TEXTGROUPWIDGET_URL) ? w->UnderlineFont : w->Font;
|
||||
|
||||
if (ul) args->Font.Style |= FONT_FLAG_UNDERLINE;
|
||||
Drawer2D_DrawText(&bmp, args, x, 0);
|
||||
if (ul) args->Font.Style &= ~FONT_FLAG_UNDERLINE;
|
||||
|
||||
x += partSizes[i].Width;
|
||||
}
|
||||
Drawer2D_Make2DTexture(tex, &bmp, size, 0, 0);
|
||||
@ -2641,13 +2641,12 @@ static struct WidgetVTABLE TextGroupWidget_VTABLE = {
|
||||
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
|
||||
TextGroupWidget_Reposition,
|
||||
};
|
||||
void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, const FontDesc* font, const FontDesc* ulFont, STRING_REF struct Texture* textures, STRING_REF char* buffer) {
|
||||
void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, const FontDesc* font, STRING_REF struct Texture* textures, STRING_REF char* buffer) {
|
||||
Widget_Reset(w);
|
||||
w->VTABLE = &TextGroupWidget_VTABLE;
|
||||
|
||||
w->LinesCount = lines;
|
||||
w->Font = *font;
|
||||
w->UnderlineFont = *ulFont;
|
||||
w->Textures = textures;
|
||||
w->Buffer = buffer;
|
||||
}
|
||||
|
@ -161,14 +161,14 @@ CC_NOINLINE void ChatInputWidget_Create(struct ChatInputWidget* w, const FontDes
|
||||
struct TextGroupWidget {
|
||||
Widget_Layout
|
||||
int LinesCount, DefaultHeight;
|
||||
FontDesc Font, UnderlineFont;
|
||||
FontDesc Font;
|
||||
bool PlaceholderHeight[TEXTGROUPWIDGET_MAX_LINES];
|
||||
uint8_t LineLengths[TEXTGROUPWIDGET_MAX_LINES];
|
||||
struct Texture* Textures;
|
||||
char* Buffer;
|
||||
};
|
||||
|
||||
CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, const FontDesc* font, const FontDesc* ulFont, STRING_REF struct Texture* textures, STRING_REF char* buffer);
|
||||
CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, const FontDesc* font, STRING_REF struct Texture* textures, STRING_REF char* buffer);
|
||||
CC_NOINLINE void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, bool placeHolder);
|
||||
CC_NOINLINE void TextGroupWidget_PushUpAndReplaceLast(struct TextGroupWidget* w, const String* text);
|
||||
CC_NOINLINE int TextGroupWidget_UsedHeight(struct TextGroupWidget* w);
|
||||
|
Loading…
x
Reference in New Issue
Block a user