- use a floating point origin in the menu's implementation

Using fixed point here makes no sense, let's keep that to the code that still lives in the 90's.
This commit is contained in:
Christoph Oelckers 2019-11-26 00:20:21 +01:00
parent f2cfad8d9b
commit dce633de8b
3 changed files with 26 additions and 25 deletions

View file

@ -290,7 +290,7 @@ void FListMenuItem::Ticker()
{ {
} }
void FListMenuItem::Drawer(DListMenu* menu, const vec2_t& origin, bool selected) void FListMenuItem::Drawer(DListMenu* menu, const DVector2& origin, bool selected)
{ {
} }
@ -389,7 +389,7 @@ FListMenuItemStaticPatch::FListMenuItemStaticPatch(int x, int y, FTexture *patch
mCentered = centered; mCentered = centered;
} }
void FListMenuItemStaticPatch::Drawer(DListMenu* menu, const vec2_t& origin, bool selected) void FListMenuItemStaticPatch::Drawer(DListMenu* menu, const DVector2& origin, bool selected)
{ {
if (!mTexture) if (!mTexture)
{ {
@ -426,7 +426,7 @@ FListMenuItemStaticText::FListMenuItemStaticText(int x, int y, const char *text,
mCentered = centered; mCentered = centered;
} }
void FListMenuItemStaticText::Drawer(DListMenu* menu, const vec2_t& origin, bool selected) void FListMenuItemStaticText::Drawer(DListMenu* menu, const DVector2& origin, bool selected)
{ {
const char *text = mText; const char *text = mText;
if (text != NULL) if (text != NULL)
@ -529,7 +529,7 @@ FListMenuItemText::~FListMenuItemText()
{ {
} }
void FListMenuItemText::Drawer(DListMenu* menu, const vec2_t& origin, bool selected) void FListMenuItemText::Drawer(DListMenu* menu, const DVector2& origin, bool selected)
{ {
const char *text = mText; const char *text = mText;
if (mText.Len()) if (mText.Len())
@ -571,14 +571,14 @@ FListMenuItemNativeText::~FListMenuItemNativeText()
{ {
} }
void FListMenuItemNativeText::Drawer(DListMenu* menu, const vec2_t& origin, bool selected) void FListMenuItemNativeText::Drawer(DListMenu* menu, const DVector2& origin, bool selected)
{ {
const char* text = mText; const char* text = mText;
if (mText.Len() && !mHidden) if (mText.Len() && !mHidden)
{ {
if (*text == '$') text = GStrings(text + 1); if (*text == '$') text = GStrings(text + 1);
auto state = selected ? NIT_SelectedState : mEnabled ? NIT_ActiveState : NIT_InactiveState; auto state = selected ? NIT_SelectedState : mEnabled ? NIT_ActiveState : NIT_InactiveState;
gi->DrawNativeMenuText(mFontnum, state, (mXpos << 16) + origin.x, (mYpos << 16) + origin.y, 1.f, text, menu->Descriptor()->mFlags); gi->DrawNativeMenuText(mFontnum, state, int((origin.X + mXpos) / 65536) , int((origin.Y + mYpos) / 65536), 1.f, text, menu->Descriptor()->mFlags);
} }
} }
@ -601,7 +601,7 @@ FListMenuItemPatch::FListMenuItemPatch(int x, int y, int height, int hotkey, FTe
mTexture = patch; mTexture = patch;
} }
void FListMenuItemPatch::Drawer(DListMenu* menu, const vec2_t& origin, bool selected) void FListMenuItemPatch::Drawer(DListMenu* menu, const DVector2& origin, bool selected)
{ {
DrawTexture (&twod, mTexture, mXpos, mYpos, DTA_Clean, true, TAG_DONE); DrawTexture (&twod, mTexture, mXpos, mYpos, DTA_Clean, true, TAG_DONE);
} }

View file

@ -318,10 +318,11 @@ public:
static int MenuTime; static int MenuTime;
DMenu *mParentMenu; DMenu *mParentMenu;
vec2_t origin; DVector2 origin;
int scriptID = INT_MAX; int scriptID = INT_MAX;
DMenu(DMenu *parent = NULL); DMenu(DMenu *parent = NULL);
virtual ~DMenu() = default;
virtual bool Responder (event_t *ev); virtual bool Responder (event_t *ev);
virtual bool MenuEvent (int mkey, bool fromcontroller); virtual bool MenuEvent (int mkey, bool fromcontroller);
virtual void Ticker (); virtual void Ticker ();
@ -374,7 +375,7 @@ public:
virtual bool CheckCoordinate(int x, int y); virtual bool CheckCoordinate(int x, int y);
virtual void Ticker(); virtual void Ticker();
virtual void Drawer(DListMenu *menu, const vec2_t& origin, bool selected); virtual void Drawer(DListMenu *menu, const DVector2& origin, bool selected);
virtual bool Selectable(); virtual bool Selectable();
virtual bool Activate(FName caller); virtual bool Activate(FName caller);
virtual FName GetAction(int *pparam); virtual FName GetAction(int *pparam);
@ -405,7 +406,7 @@ protected:
public: public:
FListMenuItemStaticPatch(int x, int y, FTexture *patch, bool centered); FListMenuItemStaticPatch(int x, int y, FTexture *patch, bool centered);
void Drawer(DListMenu* menu, const vec2_t& origin, bool selected); void Drawer(DListMenu* menu, const DVector2& origin, bool selected);
}; };
class FListMenuItemStaticText : public FListMenuItem class FListMenuItemStaticText : public FListMenuItem
@ -419,7 +420,7 @@ protected:
public: public:
FListMenuItemStaticText(int x, int y, const char *text, FFont *font, EColorRange color, bool centered); FListMenuItemStaticText(int x, int y, const char *text, FFont *font, EColorRange color, bool centered);
~FListMenuItemStaticText(); ~FListMenuItemStaticText();
void Drawer(DListMenu* menu, const vec2_t& origin, bool selected) override; void Drawer(DListMenu* menu, const DVector2& origin, bool selected) override;
}; };
//============================================================================= //=============================================================================
@ -453,7 +454,7 @@ class FListMenuItemText : public FListMenuItemSelectable
public: public:
FListMenuItemText(int x, int y, int height, int hotkey, const FString &text, FFont *font, EColorRange color, EColorRange color2, FName child, int param = 0); FListMenuItemText(int x, int y, int height, int hotkey, const FString &text, FFont *font, EColorRange color, EColorRange color2, FName child, int param = 0);
~FListMenuItemText(); ~FListMenuItemText();
void Drawer(DListMenu* menu, const vec2_t& origin, bool selected) override; void Drawer(DListMenu* menu, const DVector2& origin, bool selected) override;
int GetWidth() override; int GetWidth() override;
}; };
@ -467,7 +468,7 @@ class FListMenuItemNativeText : public FListMenuItemSelectable
public: public:
FListMenuItemNativeText(int x, int y, int height, int hotkey, const FString& text, int fontnum, int palnum, float fontscale, FName child, int param = 0); FListMenuItemNativeText(int x, int y, int height, int hotkey, const FString& text, int fontnum, int palnum, float fontscale, FName child, int param = 0);
~FListMenuItemNativeText(); ~FListMenuItemNativeText();
void Drawer(DListMenu* menu, const vec2_t& origin, bool selected) override; void Drawer(DListMenu* menu, const DVector2& origin, bool selected) override;
int GetWidth() override; int GetWidth() override;
void DrawSelector(int xofs, int yofs, FTexture* tex) override { } // The text drawer handles this itself. void DrawSelector(int xofs, int yofs, FTexture* tex) override { } // The text drawer handles this itself.
}; };
@ -478,7 +479,7 @@ class FListMenuItemPatch : public FListMenuItemSelectable
FTexture* mTexture; FTexture* mTexture;
public: public:
FListMenuItemPatch(int x, int y, int height, int hotkey, FTexture* patch, FName child, int param = 0); FListMenuItemPatch(int x, int y, int height, int hotkey, FTexture* patch, FName child, int param = 0);
void Drawer(DListMenu* menu, const vec2_t& origin, bool selected) override; void Drawer(DListMenu* menu, const DVector2& origin, bool selected) override;
int GetWidth() override; int GetWidth() override;
}; };

View file

@ -131,13 +131,13 @@ void Menu_Init(void)
#endif #endif
} }
static void Menu_DrawTopBar(const vec2_t origin) static void Menu_DrawTopBar(const DVector2 &origin)
{ {
if ((G_GetLogoFlags() & LOGO_NOTITLEBAR) == 0) if ((G_GetLogoFlags() & LOGO_NOTITLEBAR) == 0)
rotatesprite_fs(origin.x + (MENU_MARGIN_CENTER<<16), origin.y + (19<<16), MF_Redfont.cursorScale, 0,MENUBAR,16,0,10); rotatesprite_fs(int(origin.X*65536) + (MENU_MARGIN_CENTER<<16), int(origin.Y*65536) + (19<<16), MF_Redfont.cursorScale, 0,MENUBAR,16,0,10);
} }
static void Menu_DrawTopBarCaption(const char *caption, const vec2_t origin) static void Menu_DrawTopBarCaption(const char *caption, const DVector2 &origin)
{ {
static char t[64]; static char t[64];
if (*caption == '$') caption = GStrings(caption + 1); if (*caption == '$') caption = GStrings(caption + 1);
@ -148,7 +148,7 @@ static void Menu_DrawTopBarCaption(const char *caption, const vec2_t origin)
char *p = &t[dstlen-1]; char *p = &t[dstlen-1];
if (*p == ':') if (*p == ':')
*p = '\0'; *p = '\0';
captionmenutext(origin.x + (MENU_MARGIN_CENTER<<16), origin.y + (24<<16) + ((15>>1)<<16), t); captionmenutext(int(origin.X*65536) + (MENU_MARGIN_CENTER<<16), int(origin.Y*65536) + (24<<16) + ((15>>1)<<16), t);
} }
static void Menu_GetFmt(const MenuFont_t* font, uint8_t const status, int32_t* s, int32_t* z) static void Menu_GetFmt(const MenuFont_t* font, uint8_t const status, int32_t* s, int32_t* z)
@ -227,7 +227,7 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, int xpos, int ypo
{ {
int ydim_upper = 0; int ydim_upper = 0;
int ydim_lower = ydim - 1; int ydim_lower = ydim - 1;
int32_t const indent = 0; // not set for any relevant menu //int32_t const indent = 0; // not set for any relevant menu
int32_t x = xpos; int32_t x = xpos;
uint8_t status = 0; uint8_t status = 0;
@ -271,14 +271,14 @@ protected:
virtual void CallScript(int event, bool getorigin = false) virtual void CallScript(int event, bool getorigin = false)
{ {
ud.returnvar[0] = origin.x; ud.returnvar[0] = int(origin.X * 65536);
ud.returnvar[1] = origin.y; ud.returnvar[1] = int(origin.Y * 65536);
ud.returnvar[2] = mDesc->mSelectedItem; ud.returnvar[2] = mDesc->mSelectedItem;
VM_OnEventWithReturn(event, g_player[screenpeek].ps->i, screenpeek, mDesc->mScriptId); VM_OnEventWithReturn(event, g_player[screenpeek].ps->i, screenpeek, mDesc->mScriptId);
if (getorigin) if (getorigin)
{ {
origin.x = ud.returnvar[0]; origin.X = ud.returnvar[0] / 65536.;
origin.y = ud.returnvar[1]; origin.Y = ud.returnvar[1] / 65536.;
} }
} }
@ -369,9 +369,9 @@ class MainMenu : public DukeListMenu
DukeListMenu::PreDraw(); DukeListMenu::PreDraw();
if ((G_GetLogoFlags() & LOGO_NOGAMETITLE) == 0) if ((G_GetLogoFlags() & LOGO_NOGAMETITLE) == 0)
{ {
rotatesprite_fs((origin.x << 16) + (MENU_MARGIN_CENTER<<16), (origin.y << 16) + ((28)<<16), 65536L,0,INGAMEDUKETHREEDEE,0,0,10); rotatesprite_fs(int(origin.X * 65536) + (MENU_MARGIN_CENTER<<16), int(origin.Y * 65536) + ((28)<<16), 65536L,0,INGAMEDUKETHREEDEE,0,0,10);
if (PLUTOPAK) // JBF 20030804 if (PLUTOPAK) // JBF 20030804
rotatesprite_fs((origin.y << 16) + ((MENU_MARGIN_CENTER+100)<<16), (origin.y << 16) + (36<<16), 65536L,0,PLUTOPAKSPRITE+2,(sintable[((int32_t) totalclock<<4)&2047]>>11),0,2+8); rotatesprite_fs(int(origin.X * 65536) + ((MENU_MARGIN_CENTER+100)<<16), int(origin.Y * 65536) + (36<<16), 65536L,0,PLUTOPAKSPRITE+2,(sintable[((int32_t) totalclock<<4)&2047]>>11),0,2+8);
} }
} }
}; };