From 35ff0a42a637c3a36e9e7eb9a2cc4c37fdf0ef8e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 4 Oct 2020 23:26:29 +0200 Subject: [PATCH] - restructured the option menu drawer for easier replacement of the caption handler. --- wadsrc/static/zscript/ui/menu/optionmenu.zs | 60 +++++++++++++-------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/wadsrc/static/zscript/ui/menu/optionmenu.zs b/wadsrc/static/zscript/ui/menu/optionmenu.zs index 14a2f95abb..31aee1d02b 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenu.zs @@ -235,19 +235,11 @@ class OptionMenu : Menu if (mDesc.mSelectedItem < 0) { // Figure out how many lines of text fit on the menu - int y = mDesc.mPosition; + int y = mDesc.mPosition; if (y <= 0) { - let font = generic_ui || !mDesc.mFont? NewSmallFont : mDesc.mFont; - if (font && mDesc.mTitle.Length() > 0) - { - y = -y + font.GetHeight(); - } - else - { - y = -y; - } + y = DrawCaption(mDesc.mTitle, y, false); } y *= CleanYfac_1; int rowheight = OptionMenuSettings.mLinespacing * CleanYfac_1; @@ -430,25 +422,47 @@ class OptionMenu : Menu return screen.GetWidth() / 2 + indent * CleanXfac_1; } + //============================================================================= + // + // draws and/or measures the caption. + // + //============================================================================= + + virtual int DrawCaption(String title, int y, bool drawit) + { + let font = generic_ui || !mDesc.mFont ? NewSmallFont : mDesc.mFont; + if (font && mDesc.mTitle.Length() > 0) + { + let font = generic_ui || !mDesc.mFont ? NewSmallFont : mDesc.mFont; + if (drawit) + { + let tt = Stringtable.Localize(title); + screen.DrawText(font, OptionMenuSettings.mTitleColor, + (screen.GetWidth() - font.StringWidth(tt) * CleanXfac_1) / 2, 10 * CleanYfac_1, + tt, DTA_CleanNoMove_1, true); + } + return y + font.GetHeight(); + } + else + { + return y; + } + + } + + //============================================================================= + // + // + // + //============================================================================= + override void Drawer () { int y = mDesc.mPosition; if (y <= 0) { - let font = generic_ui || !mDesc.mFont? NewSmallFont : mDesc.mFont; - if (font && mDesc.mTitle.Length() > 0) - { - let tt = Stringtable.Localize(mDesc.mTitle); - screen.DrawText (font, OptionMenuSettings.mTitleColor, - (screen.GetWidth() - font.StringWidth(tt) * CleanXfac_1) / 2, 10*CleanYfac_1, - tt, DTA_CleanNoMove_1, true); - y = -y + font.GetHeight(); - } - else - { - y = -y; - } + y = DrawCaption(mDesc.mTitle, -y, true); } mDesc.mDrawTop = y; int fontheight = OptionMenuSettings.mLinespacing * CleanYfac_1;