mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
Fix chat input caret appearing at wrong Y position after resize with opengl
This commit is contained in:
parent
2dea000b71
commit
bad7f79b7a
@ -292,27 +292,27 @@ void Drawer2D_Clear(Bitmap* bmp, BitmapCol col, int x, int y, int width, int hei
|
||||
}
|
||||
|
||||
|
||||
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, int X, int Y) {
|
||||
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) {
|
||||
static struct Texture empty = { GFX_NULL, Tex_Rect(0,0, 0,0), Tex_UV(0,0, 1,1) };
|
||||
Size2D size;
|
||||
Bitmap bmp;
|
||||
|
||||
size = Drawer2D_MeasureText(args);
|
||||
/* height is only 0 when width is 0 */
|
||||
if (!size.Width) { *tex = empty; tex->X = X; tex->Y = Y; return; }
|
||||
if (!size.Width) { *tex = empty; return; }
|
||||
|
||||
Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
|
||||
{
|
||||
Drawer2D_DrawText(&bmp, args, 0, 0);
|
||||
Drawer2D_Make2DTexture(tex, &bmp, size, X, Y);
|
||||
Drawer2D_Make2DTexture(tex, &bmp, size);
|
||||
}
|
||||
Mem_Free(bmp.Scan0);
|
||||
}
|
||||
|
||||
void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used, int X, int Y) {
|
||||
void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used) {
|
||||
tex->ID = Gfx_CreateTexture(bmp, false, false);
|
||||
tex->X = X; tex->Width = used.Width;
|
||||
tex->Y = Y; tex->Height = used.Height;
|
||||
tex->X = 0; tex->Width = used.Width;
|
||||
tex->Y = 0; tex->Height = used.Height;
|
||||
|
||||
tex->uv.U1 = 0.0f; tex->uv.V1 = 0.0f;
|
||||
tex->uv.U2 = (float)used.Width / (float)bmp->Width;
|
||||
|
@ -76,11 +76,11 @@ int Drawer2D_FontHeight(const FontDesc* font, bool useShadow);
|
||||
|
||||
/* Creates a texture consisting only of the given text drawn onto it. */
|
||||
/* NOTE: The returned texture is always padded up to nearest power of two dimensions. */
|
||||
CC_API void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, int X, int Y);
|
||||
CC_API void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args);
|
||||
/* Creates a texture consisting of the pixels from the given bitmap. */
|
||||
/* NOTE: bmp must always have power of two dimensions. */
|
||||
/* used specifies what region of the texture actually should be drawn. */
|
||||
CC_API void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used, int X, int Y);
|
||||
CC_API void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used);
|
||||
|
||||
/* Returns whether the given colour code is used/valid. */
|
||||
/* NOTE: This can change if the server defines custom colour codes. */
|
||||
|
@ -267,7 +267,7 @@ static void Entity_MakeNameTexture(struct Entity* e) {
|
||||
args.text = name;
|
||||
Drawer2D_DrawText(&bmp, &args, 0, 0);
|
||||
}
|
||||
Drawer2D_Make2DTexture(&e->NameTex, &bmp, size, 0, 0);
|
||||
Drawer2D_Make2DTexture(&e->NameTex, &bmp, size);
|
||||
Mem_Free(bmp.Scan0);
|
||||
}
|
||||
Drawer2D_BitmappedText = bitmapped;
|
||||
|
@ -320,7 +320,7 @@ void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc
|
||||
args.text = String_UNSAFE_Substring(chars, i, 1);
|
||||
Drawer2D_DrawText(&bmp, &args, atlas->offsets[i], 0);
|
||||
}
|
||||
Drawer2D_Make2DTexture(&atlas->tex, &bmp, size, 0, 0);
|
||||
Drawer2D_Make2DTexture(&atlas->tex, &bmp, size);
|
||||
}
|
||||
Mem_Free(bmp.Scan0);
|
||||
|
||||
|
@ -543,7 +543,6 @@ void Launcher_MarkAllDirty(void) {
|
||||
*#########################################################################################################################*/
|
||||
static TimeMS lastJoin;
|
||||
bool Launcher_StartGame(const String* user, const String* mppass, const String* ip, const String* port, const String* server) {
|
||||
String path; char pathBuffer[FILENAME_SIZE];
|
||||
String args; char argsBuffer[512];
|
||||
TimeMS now;
|
||||
ReturnCode res;
|
||||
|
@ -104,10 +104,12 @@ static int Program_Run(int argc, char** argv) {
|
||||
uint16_t port;
|
||||
|
||||
int argsCount = Platform_GetCommandLineArgs(argc, argv, args);
|
||||
#ifdef _MSC_VER
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
/* String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565"); */
|
||||
/* String rawArgs = String_FromConst("UnknownShadow200"); */
|
||||
/* argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); */
|
||||
String rawArgs = String_FromConst("UnknownShadow200");
|
||||
argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
|
||||
#endif
|
||||
|
||||
if (argsCount == 0) {
|
||||
#ifdef CC_BUILD_WEB
|
||||
|
@ -67,7 +67,7 @@ void TextWidget_Set(struct TextWidget* w, const String* text, const FontDesc* fo
|
||||
w->tex.Height = Drawer2D_FontHeight(font, true);
|
||||
} else {
|
||||
DrawTextArgs_Make(&args, text, font, true);
|
||||
Drawer2D_MakeTextTexture(&w->tex, &args, 0, 0);
|
||||
Drawer2D_MakeTextTexture(&w->tex, &args);
|
||||
}
|
||||
|
||||
if (w->reducePadding) {
|
||||
@ -170,7 +170,7 @@ void ButtonWidget_Set(struct ButtonWidget* w, const String* text, const FontDesc
|
||||
w->tex.Height = Drawer2D_FontHeight(font, true);
|
||||
} else {
|
||||
DrawTextArgs_Make(&args, text, font, true);
|
||||
Drawer2D_MakeTextTexture(&w->tex, &args, 0, 0);
|
||||
Drawer2D_MakeTextTexture(&w->tex, &args);
|
||||
}
|
||||
|
||||
w->width = max(w->tex.Width, w->minWidth);
|
||||
@ -563,7 +563,7 @@ void TableWidget_MakeDescTex(struct TableWidget* w, BlockID block) {
|
||||
TableWidget_MakeBlockDesc(&desc, block);
|
||||
|
||||
DrawTextArgs_Make(&args, &desc, w->font, true);
|
||||
Drawer2D_MakeTextTexture(&w->descTex, &args, 0, 0);
|
||||
Drawer2D_MakeTextTexture(&w->descTex, &args);
|
||||
TableWidget_UpdateDescTexPos(w);
|
||||
}
|
||||
|
||||
@ -897,7 +897,7 @@ static void InputWidget_UpdateCaret(struct InputWidget* w) {
|
||||
|
||||
if (!w->caretTex.ID) {
|
||||
DrawTextArgs_Make(&args, &caret, w->font, true);
|
||||
Drawer2D_MakeTextTexture(&w->caretTex, &args, 0, 0);
|
||||
Drawer2D_MakeTextTexture(&w->caretTex, &args);
|
||||
w->caretWidth = (uint16_t)((w->caretTex.Width * 3) / 4);
|
||||
}
|
||||
|
||||
@ -1399,7 +1399,7 @@ static void MenuInputWidget_RemakeTexture(void* widget) {
|
||||
}
|
||||
|
||||
tex = &w->base.inputTex;
|
||||
Drawer2D_Make2DTexture(tex, &bmp, adjSize, 0, 0);
|
||||
Drawer2D_Make2DTexture(tex, &bmp, adjSize);
|
||||
Mem_Free(bmp.Scan0);
|
||||
|
||||
Widget_Reposition(&w->base);
|
||||
@ -1506,7 +1506,7 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
|
||||
y += w->lineHeight;
|
||||
}
|
||||
|
||||
Drawer2D_Make2DTexture(&w->inputTex, &bmp, size, 0, 0);
|
||||
Drawer2D_Make2DTexture(&w->inputTex, &bmp, size);
|
||||
Mem_Free(bmp.Scan0);
|
||||
w->caretAccumulator = 0;
|
||||
|
||||
@ -1720,6 +1720,7 @@ void ChatInputWidget_SetFont(struct ChatInputWidget* w, FontDesc* font) {
|
||||
w->base.font = font;
|
||||
w->base.prefixWidth = Drawer2D_TextWidth(&args);
|
||||
w->base.lineHeight = Drawer2D_TextHeight(&args);
|
||||
Gfx_DeleteTexture(&w->base.caretTex.ID);
|
||||
}
|
||||
|
||||
|
||||
@ -1743,7 +1744,7 @@ static void PlayerListWidget_DrawName(struct Texture* tex, struct PlayerListWidg
|
||||
}
|
||||
|
||||
DrawTextArgs_Make(&args, &tmp, w->font, !w->classic);
|
||||
Drawer2D_MakeTextTexture(tex, &args, 0, 0);
|
||||
Drawer2D_MakeTextTexture(tex, &args);
|
||||
Drawer2D_ReducePadding_Tex(tex, w->font->Size, 3);
|
||||
}
|
||||
|
||||
@ -2408,7 +2409,7 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
|
||||
|
||||
x += partWidths[i];
|
||||
}
|
||||
Drawer2D_Make2DTexture(tex, &bmp, size, 0, 0);
|
||||
Drawer2D_Make2DTexture(tex, &bmp, size);
|
||||
}
|
||||
Mem_Free(bmp.Scan0);
|
||||
}
|
||||
@ -2431,7 +2432,7 @@ void TextGroupWidget_Redraw(struct TextGroupWidget* w, int index) {
|
||||
if (w->underlineUrls && TextGroupWidget_MightHaveUrls(w)) {
|
||||
TextGroupWidget_DrawAdvanced(w, &tex, &args, index, &text);
|
||||
} else {
|
||||
Drawer2D_MakeTextTexture(&tex, &args, 0, 0);
|
||||
Drawer2D_MakeTextTexture(&tex, &args);
|
||||
}
|
||||
Drawer2D_ReducePadding_Tex(&tex, w->font->Size, 3);
|
||||
} else {
|
||||
@ -2685,7 +2686,7 @@ static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct Special
|
||||
Drawer2D_Clear(&bmp, col, 0, titles.Height, size.Width, content.Height);
|
||||
SpecialInputWidget_DrawContent(w, tab, &bmp, titles.Height);
|
||||
}
|
||||
Drawer2D_Make2DTexture(&w->tex, &bmp, size, w->x, w->y);
|
||||
Drawer2D_Make2DTexture(&w->tex, &bmp, size);
|
||||
Mem_Free(bmp.Scan0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user