mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
try to use TextHeight instead of MeasureText
This commit is contained in:
parent
b6d9b9b88d
commit
3d7957570b
@ -542,6 +542,10 @@ int Drawer2D_TextWidth(struct DrawTextArgs* args) {
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Drawer2D_TextHeight(struct DrawTextArgs* args) {
|
||||||
|
return Drawer2D_FontHeight(&args->font, args->useShadow);
|
||||||
|
}
|
||||||
|
|
||||||
int Drawer2D_FontHeight(const FontDesc* font, bool useShadow) {
|
int Drawer2D_FontHeight(const FontDesc* font, bool useShadow) {
|
||||||
int height, point;
|
int height, point;
|
||||||
if (Drawer2D_BitmappedText) {
|
if (Drawer2D_BitmappedText) {
|
||||||
@ -560,7 +564,7 @@ int Drawer2D_FontHeight(const FontDesc* font, bool useShadow) {
|
|||||||
Size2D Drawer2D_MeasureText(struct DrawTextArgs* args) {
|
Size2D Drawer2D_MeasureText(struct DrawTextArgs* args) {
|
||||||
Size2D size;
|
Size2D size;
|
||||||
size.Width = Drawer2D_TextWidth(args);
|
size.Width = Drawer2D_TextWidth(args);
|
||||||
size.Height = Drawer2D_FontHeight(&args->font, args->useShadow);
|
size.Height = Drawer2D_TextHeight(args);
|
||||||
|
|
||||||
if (!size.Width) size.Height = 0;
|
if (!size.Width) size.Height = 0;
|
||||||
return size;
|
return size;
|
||||||
|
@ -63,8 +63,11 @@ void Drawer2D_Underline(Bitmap* bmp, int x, int y, int width, int height, Bitmap
|
|||||||
CC_API void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y);
|
CC_API void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y);
|
||||||
/* Returns how wide the given text would be when drawn. */
|
/* Returns how wide the given text would be when drawn. */
|
||||||
int Drawer2D_TextWidth(struct DrawTextArgs* args);
|
int Drawer2D_TextWidth(struct DrawTextArgs* args);
|
||||||
|
/* Returns how tall the given text would be when drawn. */
|
||||||
|
/* NOTE: Height returned only depends on the font. (see Drawer2D_FontHeight). */
|
||||||
|
int Drawer2D_TextHeight(struct DrawTextArgs* args);
|
||||||
/* Returns size the given text would be when drawn. */
|
/* Returns size the given text would be when drawn. */
|
||||||
/* NOTE: Height returned only depends on the font. (see Drawer2D_FontHeight).*/
|
/* NOTE: Height returned only depends on the font. (see Drawer2D_FontHeight). */
|
||||||
CC_API Size2D Drawer2D_MeasureText(struct DrawTextArgs* args);
|
CC_API Size2D Drawer2D_MeasureText(struct DrawTextArgs* args);
|
||||||
/* Similar to Drawer2D_DrawText, but trims the text with trailing ".." if wider than maxWidth. */
|
/* Similar to Drawer2D_DrawText, but trims the text with trailing ".." if wider than maxWidth. */
|
||||||
void Drawer2D_DrawClippedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, int maxWidth);
|
void Drawer2D_DrawClippedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, int maxWidth);
|
||||||
|
@ -235,7 +235,7 @@ static void LInput_BlendBoxTop(struct LInput* w) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
||||||
int hintHeight, y;
|
int y, hintHeight;
|
||||||
|
|
||||||
if (w->Text.length || !w->HintText) {
|
if (w->Text.length || !w->HintText) {
|
||||||
y = w->Y + (w->Height - w->_TextHeight) / 2;
|
y = w->Y + (w->Height - w->_TextHeight) / 2;
|
||||||
@ -244,7 +244,7 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
|||||||
args->text = String_FromReadonly(w->HintText);
|
args->text = String_FromReadonly(w->HintText);
|
||||||
args->font = Launcher_HintFont;
|
args->font = Launcher_HintFont;
|
||||||
|
|
||||||
hintHeight = Drawer2D_MeasureText(args).Height;
|
hintHeight = Drawer2D_TextHeight(args);
|
||||||
y = w->Y + (w->Height - hintHeight) / 2;
|
y = w->Y + (w->Height - hintHeight) / 2;
|
||||||
Drawer2D_DrawText(&Launcher_Framebuffer, args, w->X + 5, y);
|
Drawer2D_DrawText(&Launcher_Framebuffer, args, w->X + 5, y);
|
||||||
}
|
}
|
||||||
|
@ -1728,11 +1728,12 @@ void ChatInputWidget_Create(struct ChatInputWidget* w) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChatInputWidget_SetFont(struct ChatInputWidget* w, FontDesc* font) {
|
void ChatInputWidget_SetFont(struct ChatInputWidget* w, FontDesc* font) {
|
||||||
struct DrawTextArgs args;
|
struct DrawTextArgs args;
|
||||||
w->base.font = font;
|
|
||||||
w->base.lineHeight = Drawer2D_FontHeight(font, true);
|
|
||||||
DrawTextArgs_Make(&args, &chatInputPrefix, font, true);
|
DrawTextArgs_Make(&args, &chatInputPrefix, font, true);
|
||||||
|
|
||||||
|
w->base.font = font;
|
||||||
w->base.prefixWidth = Drawer2D_TextWidth(&args);
|
w->base.prefixWidth = Drawer2D_TextWidth(&args);
|
||||||
|
w->base.lineHeight = Drawer2D_TextHeight(&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2541,16 +2542,15 @@ static void SpecialInputWidget_UpdateColString(struct SpecialInputWidget* w) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool SpecialInputWidget_IntersectsTitle(struct SpecialInputWidget* w, int x, int y) {
|
static bool SpecialInputWidget_IntersectsTitle(struct SpecialInputWidget* w, int x, int y) {
|
||||||
Size2D size;
|
int i, width, titleX = 0;
|
||||||
int i, titleX = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < Array_Elems(w->tabs); i++) {
|
for (i = 0; i < Array_Elems(w->tabs); i++) {
|
||||||
size = w->tabs[i].titleSize;
|
width = w->tabs[i].titleWidth;
|
||||||
if (Gui_Contains(titleX, 0, size.Width, size.Height, x, y)) {
|
if (Gui_Contains(titleX, 0, width, w->titleHeight, x, y)) {
|
||||||
w->selectedIndex = i;
|
w->selectedIndex = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
titleX += size.Width;
|
titleX += width;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2560,7 +2560,7 @@ static void SpecialInputWidget_IntersectsBody(struct SpecialInputWidget* w, int
|
|||||||
String str;
|
String str;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
y -= w->tabs[0].titleSize.Height;
|
y -= w->titleHeight;
|
||||||
x /= w->elementSize.Width; y /= w->elementSize.Height;
|
x /= w->elementSize.Width; y /= w->elementSize.Height;
|
||||||
|
|
||||||
i = (x + y * e.itemsPerRow) * e.charsPerItem;
|
i = (x + y * e.itemsPerRow) * e.charsPerItem;
|
||||||
@ -2575,10 +2575,9 @@ static void SpecialInputWidget_IntersectsBody(struct SpecialInputWidget* w, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void SpecialInputTab_Init(struct SpecialInputTab* tab, STRING_REF String* title, int itemsPerRow, int charsPerItem, STRING_REF String* contents) {
|
static void SpecialInputTab_Init(struct SpecialInputTab* tab, STRING_REF String* title, int itemsPerRow, int charsPerItem, STRING_REF String* contents) {
|
||||||
tab->title = *title;
|
tab->title = *title;
|
||||||
tab->titleSize.Width = 0;
|
tab->titleWidth = 0;
|
||||||
tab->titleSize.Height = 0;
|
tab->contents = *contents;
|
||||||
tab->contents = *contents;
|
|
||||||
tab->itemsPerRow = itemsPerRow;
|
tab->itemsPerRow = itemsPerRow;
|
||||||
tab->charsPerItem = charsPerItem;
|
tab->charsPerItem = charsPerItem;
|
||||||
}
|
}
|
||||||
@ -2613,12 +2612,12 @@ static Size2D SpecialInputWidget_MeasureTitles(struct SpecialInputWidget* w) {
|
|||||||
for (i = 0; i < Array_Elems(w->tabs); i++) {
|
for (i = 0; i < Array_Elems(w->tabs); i++) {
|
||||||
args.text = w->tabs[i].title;
|
args.text = w->tabs[i].title;
|
||||||
|
|
||||||
w->tabs[i].titleSize = Drawer2D_MeasureText(&args);
|
w->tabs[i].titleWidth = Drawer2D_TextWidth(&args) + SPECIAL_TITLE_SPACING;
|
||||||
w->tabs[i].titleSize.Width += SPECIAL_TITLE_SPACING;
|
size.Width += w->tabs[i].titleWidth;
|
||||||
size.Width += w->tabs[i].titleSize.Width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size.Height = w->tabs[0].titleSize.Height;
|
w->titleHeight = Drawer2D_TextHeight(&args);
|
||||||
|
size.Height = w->titleHeight;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2626,20 +2625,18 @@ static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, Bitmap*
|
|||||||
BitmapCol col_selected = BITMAPCOL_CONST(30, 30, 30, 200);
|
BitmapCol col_selected = BITMAPCOL_CONST(30, 30, 30, 200);
|
||||||
BitmapCol col_inactive = BITMAPCOL_CONST( 0, 0, 0, 127);
|
BitmapCol col_inactive = BITMAPCOL_CONST( 0, 0, 0, 127);
|
||||||
BitmapCol col;
|
BitmapCol col;
|
||||||
|
|
||||||
struct DrawTextArgs args;
|
struct DrawTextArgs args;
|
||||||
Size2D size;
|
int i, width, x = 0;
|
||||||
int i, x = 0;
|
|
||||||
|
|
||||||
DrawTextArgs_MakeEmpty(&args, w->font, false);
|
DrawTextArgs_MakeEmpty(&args, w->font, false);
|
||||||
for (i = 0; i < Array_Elems(w->tabs); i++) {
|
for (i = 0; i < Array_Elems(w->tabs); i++) {
|
||||||
args.text = w->tabs[i].title;
|
args.text = w->tabs[i].title;
|
||||||
col = i == w->selectedIndex ? col_selected : col_inactive;
|
col = i == w->selectedIndex ? col_selected : col_inactive;
|
||||||
size = w->tabs[i].titleSize;
|
width = w->tabs[i].titleWidth;
|
||||||
|
|
||||||
Drawer2D_Clear(bmp, col, x, 0, size.Width, size.Height);
|
Drawer2D_Clear(bmp, col, x, 0, width, w->titleHeight);
|
||||||
Drawer2D_DrawText(bmp, &args, x + SPECIAL_TITLE_SPACING / 2, 0);
|
Drawer2D_DrawText(bmp, &args, x + SPECIAL_TITLE_SPACING / 2, 0);
|
||||||
x += size.Width;
|
x += width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,8 +251,7 @@ CC_NOINLINE void PlayerListWidget_GetNameUnder(struct PlayerListWidget* w, int m
|
|||||||
|
|
||||||
typedef void (*SpecialInputAppendFunc)(void* userData, char c);
|
typedef void (*SpecialInputAppendFunc)(void* userData, char c);
|
||||||
struct SpecialInputTab {
|
struct SpecialInputTab {
|
||||||
int itemsPerRow, charsPerItem;
|
int itemsPerRow, charsPerItem, titleWidth;
|
||||||
Size2D titleSize;
|
|
||||||
String title, contents;
|
String title, contents;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -264,6 +263,7 @@ struct SpecialInputWidget {
|
|||||||
struct InputWidget* target;
|
struct InputWidget* target;
|
||||||
struct Texture tex;
|
struct Texture tex;
|
||||||
FontDesc* font;
|
FontDesc* font;
|
||||||
|
int titleHeight;
|
||||||
struct SpecialInputTab tabs[5];
|
struct SpecialInputTab tabs[5];
|
||||||
String colString;
|
String colString;
|
||||||
char _colBuffer[DRAWER2D_MAX_COLS * 4];
|
char _colBuffer[DRAWER2D_MAX_COLS * 4];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user