Merge pull request #706 from UnknownShadow200/Guifixes45

DPI scale tab list, cleanup code for tab list
This commit is contained in:
UnknownShadow200 2020-09-05 14:19:36 +10:00 committed by GitHub
commit 0877f01775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 28 deletions

View File

@ -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++) {

View File

@ -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);

View File

@ -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);

View File

@ -289,22 +289,22 @@ 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
#define TABLIST_MAX_ENTRIES (TABLIST_MAX_NAMES * 2)
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;
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];
@ -364,31 +364,43 @@ 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->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) {
@ -617,9 +629,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,19 +641,15 @@ 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;
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, 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();
@ -1519,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);