6735: Minor refactoring of `CUI` r=def- a=Robyt3


## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2023-06-12 18:05:58 +00:00 committed by GitHub
commit 3cb0160399
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 25 deletions

View file

@ -112,11 +112,10 @@ CUI::CUI()
{
m_Enabled = true;
m_pHotItem = 0;
m_pActiveItem = 0;
m_pLastActiveItem = 0;
m_pBecomingHotItem = 0;
m_pActiveTooltipItem = 0;
m_pHotItem = nullptr;
m_pActiveItem = nullptr;
m_pLastActiveItem = nullptr;
m_pBecomingHotItem = nullptr;
m_MouseX = 0;
m_MouseY = 0;
@ -125,10 +124,8 @@ CUI::CUI()
m_MouseButtons = 0;
m_LastMouseButtons = 0;
m_Screen.x = 0;
m_Screen.y = 0;
m_Screen.w = 848.0f;
m_Screen.h = 480.0f;
m_Screen.x = 0.0f;
m_Screen.y = 0.0f;
}
CUI::~CUI()
@ -226,7 +223,7 @@ void CUI::Update(float MouseX, float MouseY, float MouseDeltaX, float MouseDelta
m_pHotItem = m_pBecomingHotItem;
if(m_pActiveItem)
m_pHotItem = m_pActiveItem;
m_pBecomingHotItem = 0;
m_pBecomingHotItem = nullptr;
if(Enabled())
{
@ -246,8 +243,8 @@ void CUI::DebugRender()
MapScreen();
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "%p %p %p", HotItem(), ActiveItem(), LastActiveItem());
TextRender()->Text(10.0f, 10.0f, 10.0f, aBuf);
str_format(aBuf, sizeof(aBuf), "hot=%p nexthot=%p active=%p lastactive=%p", HotItem(), NextHotItem(), ActiveItem(), LastActiveItem());
TextRender()->Text(2.0f, Screen()->h - 12.0f, 10.0f, aBuf);
}
bool CUI::MouseInside(const CUIRect *pRect) const
@ -338,15 +335,8 @@ float CUI::ButtonColorMul(const void *pID)
const CUIRect *CUI::Screen()
{
float Aspect = Graphics()->ScreenAspect();
float w, h;
h = 600;
w = Aspect * h;
m_Screen.w = w;
m_Screen.h = h;
m_Screen.h = 600.0f;
m_Screen.w = Graphics()->ScreenAspect() * m_Screen.h;
return &m_Screen;
}
@ -763,7 +753,7 @@ bool CUI::DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize
}
else
{
SetActiveItem(0);
SetActiveItem(nullptr);
}
}
else if(HotItem() == pLineInput)

View file

@ -299,7 +299,6 @@ private:
const void *m_pActiveItem;
const void *m_pLastActiveItem;
const void *m_pBecomingHotItem;
const void *m_pActiveTooltipItem;
bool m_ActiveItemValid = false;
vec2 m_UpdatedMousePos = vec2(0.0f, 0.0f);
@ -439,12 +438,10 @@ public:
}
return false;
}
void SetActiveTooltipItem(const void *pID) { m_pActiveTooltipItem = pID; }
void ClearLastActiveItem() { m_pLastActiveItem = nullptr; }
const void *HotItem() const { return m_pHotItem; }
const void *NextHotItem() const { return m_pBecomingHotItem; }
const void *ActiveItem() const { return m_pActiveItem; }
const void *ActiveTooltipItem() const { return m_pActiveTooltipItem; }
const void *LastActiveItem() const { return m_pLastActiveItem; }
void StartCheck() { m_ActiveItemValid = false; }