From 9abe8f79587202ed7d661b3c7c5d8b22bddeea96 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 19 Jun 2017 23:06:45 +0000 Subject: [PATCH] Factor some menu code. git-svn-id: https://svn.eduke32.com/eduke32@6200 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/menus.cpp | 13 ++++++------- source/duke3d/src/menus.h | 5 ++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index 7aef8b494..e130bdfde 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -3984,7 +3984,7 @@ static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *current ++numvalidentries; // assumes height == font->get_yline()! - totalheight += entry->type == Spacer ? entry->getSpacerHeight() : entry->font->get_yline(); + totalheight += entry->getHeight(); } calculatedentryspacing = (klabs(menu->format->bottomcutoff) - menu->format->pos.y - totalheight) / (numvalidentries > 1 ? numvalidentries - 1 : 1); @@ -3998,7 +3998,7 @@ static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *current if (entry == NULL) continue; - int32_t const height = entry->type == Spacer ? entry->getSpacerHeight() : entry->font->get_yline(); + int32_t const height = entry->getHeight(); y += height; totalHeight = y; @@ -4021,15 +4021,13 @@ static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *current for (e = 0; e < menu->numEntries; ++e) { MenuEntry_t *entry = menu->entrylist[e]; - uint8_t status = 0; - int32_t height, x; - vec2_t textsize; if (entry == NULL) continue; - x = menu->format->pos.x + entry->getIndent(); + int32_t x = menu->format->pos.x + entry->getIndent(); + uint8_t status = 0; if (e == menu->currentEntry) status |= MT_Selected; if (entry->flags & Disabled) @@ -4039,10 +4037,11 @@ static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *current const int32_t dodraw = entry->type != Spacer && 0 <= y - menu->scrollPos + entry->font->get_yline() && y - menu->scrollPos <= klabs(menu->format->bottomcutoff) - menu->format->pos.y; + vec2_t textsize; if (dodraw) textsize = Menu_Text(origin.x + x, origin.y + y_upper + y - menu->scrollPos, entry->font, entry->name, status, ydim_upper, ydim_lower); - height = entry->type == Spacer ? entry->getSpacerHeight() : entry->font->get_yline(); // max(textsize.y, entry->font->get_yline()); // bluefont Q ruins this + int32_t const height = entry->getHeight(); // max(textsize.y, entry->font->get_yline()); // bluefont Q ruins this if (entry->format->width < 0) status |= MT_XRight; diff --git a/source/duke3d/src/menus.h b/source/duke3d/src/menus.h index abc8ea76f..4f843463e 100644 --- a/source/duke3d/src/menus.h +++ b/source/duke3d/src/menus.h @@ -324,10 +324,9 @@ typedef struct MenuEntry_t int32_t getMarginBottom() const { return scale(format->marginBottom, font->zoom, 65536); } int32_t getIndent() const { return scale(format->indent, font->zoom, 65536); } - int32_t getSpacerHeight() const + int32_t getHeight() const { - Bassert(type == Spacer); - return scale(((MenuSpacer_t *)entry)->height, font->zoom, 65536); + return type == Spacer ? scale(((MenuSpacer_t *)entry)->height, font->zoom, 65536) : font->get_yline(); } } MenuEntry_t;