Skip to content

Commit

Permalink
avoid collisions between very long left/right aligned widgets (#1070)
Browse files Browse the repository at this point in the history
* avoid collisions between very long left/right aligned widgets

* text widget with a cursor (i.e. chat widget) gets a line on its own

* build fix

* draw chat widget before messages

* add an align_topleft_exclusive mode for the chat and message widgets, which will always reserve a whole line for them
  • Loading branch information
fabiangreffrath authored May 22, 2023
1 parent 118d192 commit 6167d92
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
37 changes: 20 additions & 17 deletions src/hu_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,38 +195,41 @@ static void HUlib_alignWidget(hu_textline_t *l, align_t align)
switch (align)
{
case align_topleft:
case align_topleft_exclusive:
l->x = HU_GAPX_L;
l->y = align_offset[align];
align_offset[align] += font_height;
l->y = align_offset[align_topleft];
align_offset[align_topleft] += font_height;
if (align == align_topleft_exclusive)
align_offset[align_topright] = align_offset[align_topleft];
break;
case align_topright:
l->x = HU_GAPX_R - l->width;
l->y = align_offset[align];
align_offset[align] += font_height;
l->y = align_offset[align_topright];
align_offset[align_topright] += font_height;
break;
case align_bottomleft:
align_offset[align] -= font_height;
align_offset[align_bottomleft] -= font_height;
l->x = HU_GAPX_L;
l->y = align_offset[align];
l->y = align_offset[align_bottomleft];
break;
case align_bottomright:
align_offset[align] -= font_height;
align_offset[align_bottomright] -= font_height;
l->x = HU_GAPX_R - l->width;
l->y = align_offset[align];
l->y = align_offset[align_bottomright];
break;
case align_topcenter:
l->x = ORIGWIDTH / 2 - l->width / 2;
align_offset[align] = MAX(align_offset[align_topleft], align_offset[align_topright]);
l->y = align_offset[align];
align_offset[align] += font_height;
align_offset[align_topleft] = align_offset[align_topright] = align_offset[align];
align_offset[align_topcenter] = MAX(align_offset[align_topleft], align_offset[align_topright]);
l->y = align_offset[align_topcenter];
align_offset[align_topcenter] += font_height;
align_offset[align_topleft] = align_offset[align_topright] = align_offset[align_topcenter];
break;
case align_bottomcenter:
l->x = ORIGWIDTH / 2 - l->width / 2;
align_offset[align] = MIN(align_offset[align_bottomleft], align_offset[align_bottomright]);
align_offset[align] -= font_height;
l->y = align_offset[align];
align_offset[align_bottomleft] = align_offset[align_bottomright] = align_offset[align];
align_offset[align_bottomcenter] = MIN(align_offset[align_bottomleft], align_offset[align_bottomright]);
align_offset[align_bottomcenter] -= font_height;
l->y = align_offset[align_bottomcenter];
align_offset[align_bottomleft] = align_offset[align_bottomright] = align_offset[align_bottomcenter];
break;
default:
case align_direct:
Expand Down Expand Up @@ -282,7 +285,7 @@ static void HUlib_drawTextLineAligned(hu_textline_t *l, boolean drawcursor)
// draw the cursor if requested
// killough 1/18/98 -- support multiple lines
if (drawcursor && x + SHORT(f['_' - l->sc]->width) <= SCREENWIDTH)
V_DrawPatchDirect(x, y, FG, f['_' - l->sc]);
V_DrawPatchTranslated(x, y, FG, f['_' - l->sc], l->cr);
}

void HUlib_drawTextLine(hu_textline_t *l, align_t align, boolean drawcursor)
Expand Down
1 change: 1 addition & 0 deletions src/hu_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct

typedef enum {
align_topleft,
align_topleft_exclusive,
align_topright,
align_topcenter,
align_bottomleft,
Expand Down
4 changes: 2 additions & 2 deletions src/hu_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ int hud_level_stats, hud_level_time;
void HU_Drawer(void)
{
widget_t *w = widget;
align_t align_text = message_centered ? align_topcenter : align_topleft;
align_t align_text = message_centered ? align_topcenter : align_topleft_exclusive;

HUlib_resetAlignOffsets();

Expand All @@ -1387,7 +1387,7 @@ void HU_Drawer(void)
HUlib_drawSText(&w_message, align_text);

// display the interactive buffer for chat entry
HUlib_drawIText(&w_chat, align_topleft);
HUlib_drawIText(&w_chat, align_topleft_exclusive);

HUlib_drawSText(&w_secret, align_direct);

Expand Down

0 comments on commit 6167d92

Please sign in to comment.