From 8da37b0437e130832072b14ffe08d1593971cc4b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 24 Aug 2019 20:34:05 +1000 Subject: [PATCH] WIP on getting alt text input to layout properly on unminimise --- src/Screens.c | 6 +++--- src/Widgets.c | 21 +++++++++++---------- src/Widgets.h | 1 + 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Screens.c b/src/Screens.c index 25ee65e96..07dbcb0cb 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -119,7 +119,7 @@ static void InventoryScreen_Init(void* screen) { TableWidget_Create(&s->table); s->table.font = &s->font; s->table.blocksPerRow = Game_PureClassic ? 9 : 10; - Elem_Init(&s->table); + TableWidget_RecreateBlocks(&s->table); /* Can't immediately move to selected here, because cursor grabbed */ /* status might be toggled after InventoryScreen_Init() is called. */ @@ -672,8 +672,8 @@ static void HUDScreen_UpdateAltTextY(struct HUDScreen* s) { int height = max(input->height + input->yOffset, HUDScreen_BottomOffset()); height += input->yOffset; - s->altText.tex.Y = Window_Height - (height + s->altText.tex.Height); - s->altText.y = s->altText.tex.Y; + s->altText.yOffset = height; + Widget_Reposition(&s->altText); } static String HUDScreen_GetChat(void* obj, int i) { diff --git a/src/Widgets.c b/src/Widgets.c index 56aa8db44..a68eeb426 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -578,7 +578,7 @@ static bool TableWidget_RowEmpty(struct TableWidget* w, int start) { return true; } -static void TableWidget_RecreateElements(struct TableWidget* w) { +void TableWidget_RecreateBlocks(struct TableWidget* w) { int i, max = Game_UseCPEBlocks ? BLOCK_COUNT : BLOCK_ORIGINAL_COUNT; BlockID block; w->blocksCount = 0; @@ -597,12 +597,6 @@ static void TableWidget_RecreateElements(struct TableWidget* w) { Widget_Reposition(w); } -static void TableWidget_Init(void* widget) { - struct TableWidget* w = (struct TableWidget*)widget; - TableWidget_RecreateElements(w); - Widget_Reposition(w); -} - static void TableWidget_Render(void* widget, double delta) { struct TableWidget* w = (struct TableWidget*)widget; VertexP3fT2fC4b vertices[TABLE_MAX_VERTICES]; @@ -798,7 +792,7 @@ static bool TableWidget_KeyDown(void* widget, Key key) { } static const struct WidgetVTABLE TableWidget_VTABLE = { - TableWidget_Init, TableWidget_Render, TableWidget_Free, + Widget_NullFunc, TableWidget_Render, TableWidget_Free, TableWidget_KeyDown, Widget_Key, TableWidget_MouseDown, TableWidget_MouseUp, TableWidget_MouseMove, TableWidget_MouseScroll, TableWidget_Reposition @@ -832,7 +826,7 @@ void TableWidget_SetBlockTo(struct TableWidget* w, BlockID block) { } void TableWidget_OnInventoryChanged(struct TableWidget* w) { - TableWidget_RecreateElements(w); + TableWidget_RecreateBlocks(w); if (w->selectedIndex >= w->blocksCount) { w->selectedIndex = w->blocksCount - 1; } @@ -2700,6 +2694,7 @@ void SpecialInputWidget_Redraw(struct SpecialInputWidget* w) { w->width = w->tex.Width; w->height = w->active ? w->tex.Height : 0; w->pendingRedraw = false; + Widget_Reposition(w); } static void SpecialInputWidget_Render(void* widget, double delta) { @@ -2712,6 +2707,12 @@ static void SpecialInputWidget_Free(void* widget) { Gfx_DeleteTexture(&w->tex.ID); } +static void SpecialInputWidget_Reposition(void* widget) { + struct SpecialInputWidget* w = (struct SpecialInputWidget*)widget; + Widget_CalcPosition(w); + w->tex.X = w->x; w->tex.Y = w->y; +} + static bool SpecialInputWidget_MouseDown(void* widget, int x, int y, MouseButton btn) { struct SpecialInputWidget* w = (struct SpecialInputWidget*)widget; x -= w->x; y -= w->y; @@ -2744,7 +2745,7 @@ static const struct WidgetVTABLE SpecialInputWidget_VTABLE = { Widget_NullFunc, SpecialInputWidget_Render, SpecialInputWidget_Free, Widget_Key, Widget_Key, SpecialInputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll, - Widget_CalcPosition + SpecialInputWidget_Reposition }; void SpecialInputWidget_Create(struct SpecialInputWidget* w, FontDesc* font, struct InputWidget* target) { Widget_Reset(w); diff --git a/src/Widgets.h b/src/Widgets.h index ebd05d473..f0c71143c 100644 --- a/src/Widgets.h +++ b/src/Widgets.h @@ -88,6 +88,7 @@ CC_NOINLINE void TableWidget_Create(struct TableWidget* w); /* Sets the selected block in the table to the given block. */ /* Also adjusts scrollbar and moves cursor to be over the given block. */ CC_NOINLINE void TableWidget_SetBlockTo(struct TableWidget* w, BlockID block); +CC_NOINLINE void TableWidget_RecreateBlocks(struct TableWidget* w); CC_NOINLINE void TableWidget_OnInventoryChanged(struct TableWidget* w); CC_NOINLINE void TableWidget_MakeDescTex(struct TableWidget* w, BlockID block); CC_NOINLINE void TableWidget_Recreate(struct TableWidget* w);