From f3b6343e53f3cc846f12af182572abd3413db665 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Feb 2017 17:24:30 +0100 Subject: [PATCH] - use floats for menu item coordinates. This only has an effect in the ListMenu because the OptionMenu uses fixed offsets which work differently. --- src/menu/menu.cpp | 4 +-- src/menu/menu.h | 14 ++++---- src/menu/menudef.cpp | 32 +++++++++---------- wadsrc/static/zscript/menu/listmenu.txt | 14 ++++---- wadsrc/static/zscript/menu/listmenuitems.txt | 30 ++++++++--------- wadsrc/static/zscript/menu/menuitembase.txt | 12 +++---- wadsrc/static/zscript/menu/playercontrols.txt | 24 +++++++------- wadsrc/static/zscript/menu/playerdisplay.txt | 4 +-- 8 files changed, 68 insertions(+), 66 deletions(-) diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 9a8860510..fe5af6268 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -1117,7 +1117,7 @@ DMenuItemBase * CreateOptionMenuItemControl(const char *label, FName cmd, FKeyBi return (DMenuItemBase*)p; } -DMenuItemBase * CreateListMenuItemPatch(int x, int y, int height, int hotkey, FTextureID tex, FName command, int param) +DMenuItemBase * CreateListMenuItemPatch(double x, double y, int height, int hotkey, FTextureID tex, FName command, int param) { auto c = PClass::FindClass("ListMenuItemPatchItem"); auto p = c->CreateNew(); @@ -1127,7 +1127,7 @@ DMenuItemBase * CreateListMenuItemPatch(int x, int y, int height, int hotkey, FT return (DMenuItemBase*)p; } -DMenuItemBase * CreateListMenuItemText(int x, int y, int height, int hotkey, const char *text, FFont *font, PalEntry color1, PalEntry color2, FName command, int param) +DMenuItemBase * CreateListMenuItemText(double x, double y, int height, int hotkey, const char *text, FFont *font, PalEntry color1, PalEntry color2, FName command, int param) { auto c = PClass::FindClass("ListMenuItemTextItem"); auto p = c->CreateNew(); diff --git a/src/menu/menu.h b/src/menu/menu.h index 1b4b22255..8922147e1 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -138,11 +138,11 @@ class DListMenuDescriptor : public DMenuDescriptor public: TArray mItems; int mSelectedItem; - int mSelectOfsX; - int mSelectOfsY; + double mSelectOfsX; + double mSelectOfsY; FTextureID mSelector; int mDisplayTop; - int mXpos, mYpos; + double mXpos, mYpos; int mWLeft, mWRight; int mLinespacing; // needs to be stored for dynamically created menus int mAutoselect; // this can only be set by internal menu creation functions @@ -288,7 +288,7 @@ class DMenuItemBase : public DObject { DECLARE_CLASS(DMenuItemBase, DObject) public: - int mXpos, mYpos; + double mXpos, mYpos; FNameNoInit mAction; bool mEnabled; @@ -298,7 +298,7 @@ public: bool SetValue(int i, int value); bool GetValue(int i, int *pvalue); void OffsetPositionY(int ydelta) { mYpos += ydelta; } - int GetY() { return mYpos; } + double GetY() { return mYpos; } }; //============================================================================= @@ -355,7 +355,7 @@ DMenuItemBase * CreateOptionMenuItemStaticText(const char *name, bool v); DMenuItemBase * CreateOptionMenuItemSubmenu(const char *label, FName cmd, int center); DMenuItemBase * CreateOptionMenuItemControl(const char *label, FName cmd, FKeyBindings *bindings); DMenuItemBase * CreateOptionMenuItemJoyConfigMenu(const char *label, IJoystickConfig *joy); -DMenuItemBase * CreateListMenuItemPatch(int x, int y, int height, int hotkey, FTextureID tex, FName command, int param); -DMenuItemBase * CreateListMenuItemText(int x, int y, int height, int hotkey, const char *text, FFont *font, PalEntry color1, PalEntry color2, FName command, int param); +DMenuItemBase * CreateListMenuItemPatch(double x, double y, int height, int hotkey, FTextureID tex, FName command, int param); +DMenuItemBase * CreateListMenuItemText(double x, double y, int height, int hotkey, const char *text, FFont *font, PalEntry color1, PalEntry color2, FName command, int param); #endif diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index f9ecbd808..cf986ee58 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -305,11 +305,11 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) sc.MustGetString(); desc->mSelector = GetMenuTexture(sc.String); sc.MustGetStringName(","); - sc.MustGetNumber(); - desc->mSelectOfsX = sc.Number; + sc.MustGetFloat(); + desc->mSelectOfsX = sc.Float; sc.MustGetStringName(","); - sc.MustGetNumber(); - desc->mSelectOfsY = sc.Number; + sc.MustGetFloat(); + desc->mSelectOfsY = sc.Float; } else if (sc.Compare("Linespacing")) { @@ -318,11 +318,11 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) } else if (sc.Compare("Position")) { - sc.MustGetNumber(); - desc->mXpos = sc.Number; + sc.MustGetFloat(); + desc->mXpos = sc.Float; sc.MustGetStringName(","); - sc.MustGetNumber(); - desc->mYpos = sc.Number; + sc.MustGetFloat(); + desc->mYpos = sc.Float; } else if (sc.Compare("Centermenu")) { @@ -973,13 +973,13 @@ static void BuildEpisodeMenu() if ((*desc)->IsKindOf(RUNTIME_CLASS(DListMenuDescriptor))) { DListMenuDescriptor *ld = static_cast(*desc); - int posy = ld->mYpos; + int posy = (int)ld->mYpos; int topy = posy; // Get lowest y coordinate of any static item in the menu for(unsigned i = 0; i < ld->mItems.Size(); i++) { - int y = ld->mItems[i]->GetY(); + int y = (int)ld->mItems[i]->GetY(); if (y < topy) topy = y; } @@ -1073,13 +1073,13 @@ static void BuildPlayerclassMenu() // add player display ld->mSelectedItem = ld->mItems.Size(); - int posy = ld->mYpos; + int posy = (int)ld->mYpos; int topy = posy; // Get lowest y coordinate of any static item in the menu for(unsigned i = 0; i < ld->mItems.Size(); i++) { - int y = ld->mItems[i]->GetY(); + int y = (int)ld->mItems[i]->GetY(); if (y < topy) topy = y; } @@ -1333,8 +1333,8 @@ void M_StartupSkillMenu(FGameStartup *gs) if ((*desc)->IsKindOf(RUNTIME_CLASS(DListMenuDescriptor))) { DListMenuDescriptor *ld = static_cast(*desc); - int x = ld->mXpos; - int y = ld->mYpos; + int x = (int)ld->mXpos; + int y = (int)ld->mYpos; // Delete previous contents for(unsigned i=0; imItems.Size(); i++) @@ -1363,7 +1363,7 @@ void M_StartupSkillMenu(FGameStartup *gs) // Get lowest y coordinate of any static item in the menu for(unsigned i = 0; i < ld->mItems.Size(); i++) { - int y = ld->mItems[i]->GetY(); + int y = (int)ld->mItems[i]->GetY(); if (y < topy) topy = y; } @@ -1380,7 +1380,7 @@ void M_StartupSkillMenu(FGameStartup *gs) { ld->mItems[i]->OffsetPositionY(topdelta); } - y = ld->mYpos = posy - topdelta; + ld->mYpos = y = posy - topdelta; } } else diff --git a/wadsrc/static/zscript/menu/listmenu.txt b/wadsrc/static/zscript/menu/listmenu.txt index 5821d0323..a7a9f71ae 100644 --- a/wadsrc/static/zscript/menu/listmenu.txt +++ b/wadsrc/static/zscript/menu/listmenu.txt @@ -4,11 +4,11 @@ class ListMenuDescriptor : MenuDescriptor native { native Array mItems; native int mSelectedItem; - native int mSelectOfsX; - native int mSelectOfsY; + native double mSelectOfsX; + native double mSelectOfsY; native TextureID mSelector; native int mDisplayTop; - native int mXpos, mYpos; + native double mXpos, mYpos; native int mWLeft, mWRight; native int mLinespacing; // needs to be stored for dynamically created menus native int mAutoselect; // this can only be set by internal menu creation functions @@ -51,16 +51,16 @@ class ListMenu : Menu mDesc = desc; if (desc.mCenter) { - int center = 160; + double center = 160; for(int i=0; i < mDesc.mItems.Size(); i++) { - int xpos = mDesc.mItems[i].GetX(); + double xpos = mDesc.mItems[i].GetX(); int width = mDesc.mItems[i].GetWidth(); - int curx = mDesc.mSelectOfsX; + double curx = mDesc.mSelectOfsX; if (width > 0 && mDesc.mItems[i].Selectable()) { - int left = 160 - (width - curx) / 2 - curx; + double left = 160 - (width - curx) / 2 - curx; if (left < center) center = left; } } diff --git a/wadsrc/static/zscript/menu/listmenuitems.txt b/wadsrc/static/zscript/menu/listmenuitems.txt index e3eec6dd1..c1bafeaf9 100644 --- a/wadsrc/static/zscript/menu/listmenuitems.txt +++ b/wadsrc/static/zscript/menu/listmenuitems.txt @@ -35,7 +35,7 @@ class ListMenuItem : MenuItemBase { - void DrawSelector(int xofs, int yofs, TextureID tex) + void DrawSelector(double xofs, double yofs, TextureID tex) { if (tex.isNull()) { @@ -68,7 +68,7 @@ class ListMenuItemStaticPatch : ListMenuItem TextureID mTexture; bool mCentered; - void Init(int x, int y, TextureID patch, bool centered = false) + void Init(double x, double y, TextureID patch, bool centered = false) { Super.Init(x, y); mTexture = patch; @@ -82,17 +82,17 @@ class ListMenuItemStaticPatch : ListMenuItem return; } - int x = mXpos; + double x = mXpos; Vector2 vec = TexMan.GetScaledSize(mTexture); if (mYpos >= 0) { - if (mCentered) x -= int(vec.X) / 2; + if (mCentered) x -= vec.X / 2; screen.DrawTexture (mTexture, true, x, mYpos, DTA_Clean, true); } else { - int x = (mXpos - 160) * CleanXfac + (Screen.GetWidth()>>1); - if (mCentered) x -= (int(vec.X) * CleanXfac)/2; + x = (mXpos - 160) * CleanXfac + (Screen.GetWidth()>>1); + if (mCentered) x -= (vec.X * CleanXfac)/2; screen.DrawTexture (mTexture, true, x, -mYpos*CleanYfac, DTA_CleanNoMove, true); } } @@ -100,7 +100,7 @@ class ListMenuItemStaticPatch : ListMenuItem class ListMenuItemStaticPatchCentered : ListMenuItemStaticPatch { - void Init(int x, int y, TextureID patch) + void Init(double x, double y, TextureID patch) { Super.Init(x, y, patch, true); } @@ -119,7 +119,7 @@ class ListMenuItemStaticText : ListMenuItem int mColor; bool mCentered; - void Init(ListMenuDescriptor desc, int x, int y, String text, int color = Font.CR_UNTRANSLATED) + void Init(ListMenuDescriptor desc, double x, double y, String text, int color = Font.CR_UNTRANSLATED) { Super.Init(x, y); mText = text; @@ -128,7 +128,7 @@ class ListMenuItemStaticText : ListMenuItem mCentered = false; } - void InitDirect(int x, int y, String text, Font font, int color = Font.CR_UNTRANSLATED, bool centered = false) + void InitDirect(double x, double y, String text, Font font, int color = Font.CR_UNTRANSLATED, bool centered = false) { Super.Init(x, y); mText = text; @@ -144,13 +144,13 @@ class ListMenuItemStaticText : ListMenuItem String text = Stringtable.Localize(mText); if (mYpos >= 0) { - int x = mXpos; + double x = mXpos; if (mCentered) x -= mFont.StringWidth(text)/2; screen.DrawText(mFont, mColor, x, mYpos, text, DTA_Clean, true); } else { - int x = (mXpos - 160) * CleanXfac + (Screen.GetWidth() >> 1); + double x = (mXpos - 160) * CleanXfac + (Screen.GetWidth() >> 1); if (mCentered) x -= (mFont.StringWidth(text) * CleanXfac)/2; screen.DrawText (mFont, mColor, x, -mYpos*CleanYfac, text, DTA_CleanNoMove, true); } @@ -160,7 +160,7 @@ class ListMenuItemStaticText : ListMenuItem class ListMenuItemStaticTextCentered : ListMenuItemStaticText { - void Init(ListMenuDescriptor desc, int x, int y, String text, int color = -1) + void Init(ListMenuDescriptor desc, double x, double y, String text, int color = -1) { Super.Init(desc, x, y, text, color); mCentered = true; @@ -179,7 +179,7 @@ class ListMenuItemSelectable : ListMenuItem int mHeight; int mParam; - protected void Init(int x, int y, int height, Name childmenu, int param = -1) + protected void Init(double x, double y, int height, Name childmenu, int param = -1) { Super.Init(x, y, childmenu); mHeight = height; @@ -250,7 +250,7 @@ class ListMenuItemTextItem : ListMenuItemSelectable mHotkey = hotkey.CharCodeAt(0); } - void InitDirect(int x, int y, int height, String hotkey, String text, Font font, int color, int color2, Name child, int param = 0) + void InitDirect(double x, double y, int height, String hotkey, String text, Font font, int color, int color2, Name child, int param = 0) { Super.Init(x, y, height, child, param); mText = text; @@ -288,7 +288,7 @@ class ListMenuItemPatchItem : ListMenuItemSelectable mTexture = patch; } - void InitDirect(int x, int y, int height, TextureID patch, String hotkey, Name child, int param = 0) + void InitDirect(double x, double y, int height, TextureID patch, String hotkey, Name child, int param = 0) { Super.Init(x, y, height, child, param); mHotkey = hotkey.CharCodeAt(0); diff --git a/wadsrc/static/zscript/menu/menuitembase.txt b/wadsrc/static/zscript/menu/menuitembase.txt index de5f05a42..35663d8b2 100644 --- a/wadsrc/static/zscript/menu/menuitembase.txt +++ b/wadsrc/static/zscript/menu/menuitembase.txt @@ -6,11 +6,11 @@ class MenuItemBase : Object native { - protected native int mXpos, mYpos; + protected native double mXpos, mYpos; protected native Name mAction; native bool mEnabled; - void Init(int xpos = 0, int ypos = 0, Name actionname = 'None') + void Init(double xpos = 0, double ypos = 0, Name actionname = 'None') { mXpos = xpos; mYpos = ypos; @@ -36,10 +36,10 @@ class MenuItemBase : Object native virtual int GetIndent() { return 0; } virtual int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) { return indent; } - void OffsetPositionY(int ydelta) { mYpos += ydelta; } - int GetY() { return mYpos; } - int GetX() { return mXpos; } - void SetX(int x) { mXpos = x; } + void OffsetPositionY(double ydelta) { mYpos += ydelta; } + double GetY() { return mYpos; } + double GetX() { return mXpos; } + void SetX(double x) { mXpos = x; } } // this is only used to parse font color ranges in MENUDEF diff --git a/wadsrc/static/zscript/menu/playercontrols.txt b/wadsrc/static/zscript/menu/playercontrols.txt index 389c34043..b7b4f05f4 100644 --- a/wadsrc/static/zscript/menu/playercontrols.txt +++ b/wadsrc/static/zscript/menu/playercontrols.txt @@ -71,7 +71,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable // //============================================================================= - void InitDirect(int x, int y, int height, int frameofs, String text, Font font, int color, Name command) + void InitDirect(double x, double y, int height, int frameofs, String text, Font font, int color, Name command) { Super.Init(x, y, height, command); mText = text; @@ -113,7 +113,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable // //============================================================================= - protected void DrawBorder (int x, int y, int len) + protected void DrawBorder (double x, double y, int len) { let left = TexMan.CheckForTexture("M_LSLEFT", TexMan.Type_MiscPatch); let mid = TexMan.CheckForTexture("M_LSCNTR", TexMan.Type_MiscPatch); @@ -141,7 +141,9 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable } else { - screen.Clear(x, y, x + len, y + SmallFont.GetHeight() * 3/2, 0); + int xx = int(x - 160) * CleanXfac + screen.GetWidth()/2; + int yy = int(y - 100) * CleanXfac + screen.GetHeight()/2; + screen.Clear(xx, yy, xx + len*CleanXfac, yy + SmallFont.GetHeight() * CleanYfac * 3/2, 0); } } } @@ -161,7 +163,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable } // Draw player name box - int x = mXpos + mFont.StringWidth(text) + 16 + mFrameSize; + double x = mXpos + mFont.StringWidth(text) + 16 + mFrameSize; DrawBorder (x, mYpos - mFrameSize, MAXPLAYERNAME+1); if (!mEnter) { @@ -246,7 +248,7 @@ class ListMenuItemValueText : ListMenuItemSelectable // //============================================================================= - void InitDirect(int x, int y, int height, String text, Font font, int color, int valuecolor, Name command, Name values) + void InitDirect(double x, double y, int height, String text, Font font, int color, int valuecolor, Name command, Name values) { Super.Init(x, y, height, command); mText = text; @@ -337,7 +339,7 @@ class ListMenuItemValueText : ListMenuItemSelectable String text = Stringtable.Localize(mText); screen.DrawText(mFont, selected? OptionMenuSettings.mFontColorSelection : mFontColor, mXpos, mYpos, text, DTA_Clean, true); - int x = mXpos + mFont.StringWidth(text) + 8; + double x = mXpos + mFont.StringWidth(text) + 8; if (mSelections.Size() > 0) { screen.DrawText(mFont, mFontColor2, x, mYpos, mSelections[mSelection], DTA_Clean, true); @@ -385,7 +387,7 @@ class ListMenuItemSlider : ListMenuItemSelectable // //============================================================================= - void InitDirect(int x, int y, int height, String text, Font font, int color, Name command, int min, int max, int step) + void InitDirect(double x, double y, int height, String text, Font font, int color, Name command, int min, int max, int step) { Super.Init(x, y, height, command); mText = text; @@ -463,7 +465,7 @@ class ListMenuItemSlider : ListMenuItemSelectable lm.ReleaseFocus(); } - int slide_left = SmallFont.StringWidth ("Green") + 8 + mXpos; + int slide_left = SmallFont.StringWidth ("Green") + 8 + int(mXpos); int slide_right = slide_left + 12*8; // 12 char cells with 8 pixels each. if (type == Menu.MOUSE_Click) @@ -491,7 +493,7 @@ class ListMenuItemSlider : ListMenuItemSelectable // //============================================================================= - protected void DrawSlider (int x, int y) + protected void DrawSlider (double x, double y) { int range = mMaxrange - mMinrange; int cur = mSelection - mMinrange; @@ -515,8 +517,8 @@ class ListMenuItemSlider : ListMenuItemSelectable screen.DrawText(mFont, selected? OptionMenuSettings.mFontColorSelection : mFontColor, mXpos, mYpos, text, DTA_Clean, true); - int x = SmallFont.StringWidth ("Green") + 8 + mXpos; - int x2 = SmallFont.StringWidth (text) + 8 + mXpos; + double x = SmallFont.StringWidth ("Green") + 8 + mXpos; + double x2 = SmallFont.StringWidth (text) + 8 + mXpos; DrawSlider (MAX(x2, x), mYpos); } } \ No newline at end of file diff --git a/wadsrc/static/zscript/menu/playerdisplay.txt b/wadsrc/static/zscript/menu/playerdisplay.txt index 492ba978c..da64559c8 100644 --- a/wadsrc/static/zscript/menu/playerdisplay.txt +++ b/wadsrc/static/zscript/menu/playerdisplay.txt @@ -252,8 +252,8 @@ class ListMenuItemPlayerDisplay : ListMenuItem } else { - int x = (mXpos - 160) * CleanXfac + (screen.GetWidth() >> 1); - int y = (mYpos - 100) * CleanYfac + (screen.GetHeight() >> 1); + int x = int(mXpos - 160) * CleanXfac + (screen.GetWidth() >> 1); + int y = int(mYpos - 100) * CleanYfac + (screen.GetHeight() >> 1); screen.DrawTexture(mBackdrop, false, x, y - 1, DTA_DestWidth, 72 * CleanXfac,