From bef57bf7738c4a5d11240b3d09e07290f9028403 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 27 Aug 2020 00:23:13 +1000 Subject: [PATCH 1/3] Get tab list to mostly DPI scale --- src/Screens.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Screens.c b/src/Screens.c index 3ffbd22d8..f31d9e352 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -289,15 +289,13 @@ struct Widget* HUDScreen_GetHotbar(void) { *#########################################################################################################################*/ #define GROUP_NAME_ID UInt16_MaxValue #define LIST_COLUMN_PADDING 5 -#define LIST_BOUNDS_SIZE 10 #define LIST_NAMES_PER_COLUMN 16 typedef int (*TabListEntryCompare)(int x, int y); static struct TabListOverlay { Screen_Body - int x, y, width, height; /* Top left corner, and dimensions, of this widget */ - cc_bool active; /* Whether this widget is currently being moused over */ - cc_bool classic; + int x, y, width, height; + cc_bool active, classic; int namesCount, elementOffset; struct TextWidget title; struct FontDesc font; @@ -364,31 +362,39 @@ static void TabListOverlay_SetColumnPos(struct TabListOverlay* s, int column, in static void TabListOverlay_Layout(void* screen) { struct TabListOverlay* s = (struct TabListOverlay*)screen; + int minWidth, minHeight, paddingX, paddingY; int i, x, y, width = 0, height = 0; int columns = Math_CeilDiv(s->namesCount, LIST_NAMES_PER_COLUMN); for (i = 0; i < columns; i++) { - width += TabListOverlay_GetColumnWidth(s, i); + width += TabListOverlay_GetColumnWidth(s, i); y = TabListOverlay_GetColumnHeight(s, i); height = max(height, y); } - if (width < 480) width = 480; - s->width = width + LIST_BOUNDS_SIZE * 2; - s->height = height + LIST_BOUNDS_SIZE * 2; + minWidth = Display_ScaleX(480); + width = max(width, minWidth); + paddingX = Display_ScaleX(10); + paddingY = Display_ScaleY(10); - y = WindowInfo.Height / 4 - s->height / 2; + width += paddingX * 2; + height += paddingY * 2; - s->x = Gui_CalcPos(ANCHOR_CENTRE, 0, s->width , WindowInfo.Width ); - s->y = Gui_CalcPos(ANCHOR_CENTRE, -max(0, y), s->height, WindowInfo.Height); + y = WindowInfo.Height / 4 - height / 2; + s->x = Gui_CalcPos(ANCHOR_CENTRE, 0, width , WindowInfo.Width ); + s->y = Gui_CalcPos(ANCHOR_CENTRE, -max(0, y), height, WindowInfo.Height); - x = s->x + LIST_BOUNDS_SIZE; - y = s->y + LIST_BOUNDS_SIZE; + x = s->x + paddingX; + y = s->y + paddingY; for (i = 0; i < columns; i++) { TabListOverlay_SetColumnPos(s, i, x, y); x += TabListOverlay_GetColumnWidth(s, i); } + + s->width = width; + minHeight = Display_ScaleY(300); + s->height = max(minHeight, height + s->title.height); } static void TabListOverlay_AddName(struct TabListOverlay* s, EntityID id, int index) { @@ -617,9 +623,9 @@ static void TabListOverlay_ContextRecreated(void* screen) { if (!TabList.NameOffsets[id]) continue; TabListOverlay_AddName(s, (EntityID)id, -1); } - TabListOverlay_SortAndLayout(s); /* TODO: Not do layout here too */ TextWidget_SetConst(&s->title, "Connected players:", &s->font); + TabListOverlay_SortAndLayout(s); /* TODO: Not do layout here too */ } static void TabListOverlay_BuildMesh(void* screen) { } @@ -629,15 +635,14 @@ static void TabListOverlay_Render(void* screen, double delta) { struct TextWidget* title = &s->title; struct Screen* grabbed; struct Texture tex; - int i, offset, height; + int i, offset; PackedCol topCol = PackedCol_Make( 0, 0, 0, 180); PackedCol bottomCol = PackedCol_Make(50, 50, 50, 205); if (Game_HideGui || !IsOnlyChatActive()) return; Gfx_SetTexturing(false); offset = title->height + 10; - height = max(300, s->height + title->height); - Gfx_Draw2DGradient(s->x, s->y - offset, s->width, height, topCol, bottomCol); + Gfx_Draw2DGradient(s->x, s->y - offset, s->width, s->height, topCol, bottomCol); Gfx_SetTexturing(true); title->yOffset = s->y - offset + 5; From 077829cf44e127641c8afb30ea3f9b0ff8343280 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 27 Aug 2020 00:47:38 +1000 Subject: [PATCH 2/3] and fix 'connected players' to offset properly with DPI scale too --- src/Screens.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Screens.c b/src/Screens.c index f31d9e352..a913c8463 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -294,7 +294,7 @@ typedef int (*TabListEntryCompare)(int x, int y); static struct TabListOverlay { Screen_Body - int x, y, width, height; + int x, y, width, height; cc_bool active, classic; int namesCount, elementOffset; struct TextWidget title; @@ -392,9 +392,13 @@ static void TabListOverlay_Layout(void* screen) { x += TabListOverlay_GetColumnWidth(s, i); } + s->y -= (s->title.height + paddingY); s->width = width; minHeight = Display_ScaleY(300); s->height = max(minHeight, height + s->title.height); + + s->title.yOffset = s->y + paddingY / 2; + Widget_Layout(&s->title); } static void TabListOverlay_AddName(struct TabListOverlay* s, EntityID id, int index) { @@ -635,18 +639,15 @@ static void TabListOverlay_Render(void* screen, double delta) { struct TextWidget* title = &s->title; struct Screen* grabbed; struct Texture tex; - int i, offset; + int i; PackedCol topCol = PackedCol_Make( 0, 0, 0, 180); PackedCol bottomCol = PackedCol_Make(50, 50, 50, 205); if (Game_HideGui || !IsOnlyChatActive()) return; Gfx_SetTexturing(false); - offset = title->height + 10; - Gfx_Draw2DGradient(s->x, s->y - offset, s->width, s->height, topCol, bottomCol); + Gfx_Draw2DGradient(s->x, s->y, s->width, s->height, topCol, bottomCol); Gfx_SetTexturing(true); - title->yOffset = s->y - offset + 5; - Widget_Layout(title); Elem_Render(title, delta); grabbed = Gui_GetInputGrab(); From d41f1a9a6eb76a2c6d17e62f3ff765cccf2273a7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 4 Sep 2020 00:39:33 +1000 Subject: [PATCH 3/3] add Screen_LockVb method --- src/Gui.c | 9 +++++++-- src/Gui.h | 1 + src/Menus.c | 3 +-- src/Screens.c | 9 +++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Gui.c b/src/Gui.c index 4d9ed7e6e..1836b1a9b 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -419,6 +419,12 @@ void Screen_CreateVb(void* screen) { s->vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, s->maxVertices); } +struct VertexTextured* Screen_LockVb(void* screen) { + struct Screen* s = (struct Screen*)screen; + return (struct VertexTextured*)Gfx_LockDynamicVb(s->vb, + VERTEX_FORMAT_TEXTURED, s->maxVertices); +} + void Screen_BuildMesh(void* screen) { struct Screen* s = (struct Screen*)screen; struct Widget** widgets = s->widgets; @@ -426,8 +432,7 @@ void Screen_BuildMesh(void* screen) { struct VertexTextured** ptr; int i; - data = (struct VertexTextured*)Gfx_LockDynamicVb(s->vb, - VERTEX_FORMAT_TEXTURED, s->maxVertices); + data = Screen_LockVb(s); ptr = &data; for (i = 0; i < s->numWidgets; i++) { diff --git a/src/Gui.h b/src/Gui.h index 05e0e310f..255eb81b9 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -104,6 +104,7 @@ void Screen_Layout(void* screen); /* Also deletes the screen's vb. */ void Screen_ContextLost(void* screen); void Screen_CreateVb(void* screen); +struct VertexTextured* Screen_LockVb(void* screen); void Screen_BuildMesh(void* screen); typedef void (*Widget_LeftClick)(void* screen, void* widget); diff --git a/src/Menus.c b/src/Menus.c index 58954e9bf..7a77357f3 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -3192,8 +3192,7 @@ static void TexIdsOverlay_BuildMesh(void* screen) { struct VertexTextured* data; struct VertexTextured** ptr; - data = (struct VertexTextured*)Gfx_LockDynamicVb(s->vb, - VERTEX_FORMAT_TEXTURED, s->maxVertices); + data = Screen_LockVb(s); ptr = &data; Widget_BuildMesh(&s->title, ptr); diff --git a/src/Screens.c b/src/Screens.c index a913c8463..f79bf15fc 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -290,6 +290,7 @@ struct Widget* HUDScreen_GetHotbar(void) { #define GROUP_NAME_ID UInt16_MaxValue #define LIST_COLUMN_PADDING 5 #define LIST_NAMES_PER_COLUMN 16 +#define TABLIST_MAX_ENTRIES (TABLIST_MAX_NAMES * 2) typedef int (*TabListEntryCompare)(int x, int y); static struct TabListOverlay { @@ -300,9 +301,10 @@ static struct TabListOverlay { struct TextWidget title; struct FontDesc font; TabListEntryCompare compare; - cc_uint16 ids[TABLIST_MAX_NAMES * 2]; - struct Texture textures[TABLIST_MAX_NAMES * 2]; + cc_uint16 ids[TABLIST_MAX_ENTRIES]; + struct Texture textures[TABLIST_MAX_ENTRIES]; } TabListOverlay_Instance; +#define TABLIST_MAX_VERTICES (TEXTWIDGET_MAX + 4 * TABLIST_MAX_ENTRIES) static void TabListOverlay_DrawName(struct Texture* tex, struct TabListOverlay* s, const String* name) { String tmp; char tmpBuffer[STRING_SIZE]; @@ -1525,8 +1527,7 @@ static void LoadingScreen_BuildMesh(void* screen) { TextureLoc loc; int atlasIndex, i; - data = (struct VertexTextured*)Gfx_LockDynamicVb(s->vb, - VERTEX_FORMAT_TEXTURED, s->maxVertices); + data = Screen_LockVb(s); ptr = &data; loc = Block_Tex(BLOCK_DIRT, FACE_YMAX);