From a30eff82a3befb40ad004e9989bd4fc77fb5a897 Mon Sep 17 00:00:00 2001 From: LordSk Date: Wed, 14 Nov 2018 15:18:32 +0100 Subject: [PATCH] Take ClipEnable/Disable into account when checking mouse pos --- src/game/client/components/menus.cpp | 2 +- src/game/client/ui.cpp | 16 ++++++++++++++-- src/game/client/ui.h | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index d195ff371..0fc9b3afd 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -1014,7 +1014,7 @@ int CMenus::DoKeyReader(CButtonContainer *pBC, const CUIRect *pRect, int Key) static const void *pGrabbedID = 0; static bool MouseReleased = true; static int ButtonUsed = 0; - int Inside = UI()->MouseInside(pRect); + int Inside = UI()->MouseInside(pRect) && UI()->MouseInsideClip(); int NewKey = Key; if(!UI()->MouseButton(0) && !UI()->MouseButton(1) && pGrabbedID == pBC->GetID()) diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 8e152476d..0f6a67467 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -17,6 +17,7 @@ CUI::CUI() m_pActiveItem = 0; m_pLastActiveItem = 0; m_pBecommingHotItem = 0; + m_Clipped = false; m_MouseX = 0; m_MouseY = 0; @@ -53,6 +54,11 @@ int CUI::MouseInside(const CUIRect *r) const return 0; } +bool CUI::MouseInsideClip() const +{ + return !m_Clipped || MouseInside(&m_ClipRect) == 1; +} + void CUI::ConvertMouseMove(float *x, float *y) const { float Fac = (float)(g_Config.m_UiMousesens)/g_Config.m_InpMousesens; @@ -91,6 +97,8 @@ float CUIRect::Scale() const void CUI::ClipEnable(const CUIRect *r) { + m_ClipRect = *r; + m_Clipped = true; float XScale = Graphics()->ScreenWidth()/Screen()->w; float YScale = Graphics()->ScreenHeight()/Screen()->h; Graphics()->ClipEnable((int)(r->x*XScale), (int)(r->y*YScale), (int)(r->w*XScale), (int)(r->h*YScale)); @@ -99,6 +107,8 @@ void CUI::ClipEnable(const CUIRect *r) void CUI::ClipDisable() { Graphics()->ClipDisable(); + m_ClipRect = {}; + m_Clipped = false; } void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom) const @@ -273,6 +283,8 @@ int CUI::DoButtonLogic(const void *pID, const char *pText, int Checked, const CU // logic int ReturnValue = 0; int Inside = MouseInside(pRect); + if(m_Clipped) + Inside &= MouseInside(&m_ClipRect); static int ButtonUsed = 0; if(CheckActiveItem(pID)) @@ -319,7 +331,7 @@ int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float * if(MouseButton(0)) SetActiveItem(pID); } - + if(Inside) SetHotItem(pID); @@ -411,4 +423,4 @@ void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, EAlignment Al void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, EAlignment Align, int MaxWidth) { DoLabel(r, pText, Size*Scale(), Align, MaxWidth); -} \ No newline at end of file +} diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 163e6940d..c0f20f169 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -30,12 +30,14 @@ class CUI const void *m_pLastActiveItem; const void *m_pBecommingHotItem; bool m_ActiveItemValid; + bool m_Clipped; float m_MouseX, m_MouseY; // in gui space float m_MouseWorldX, m_MouseWorldY; // in world space unsigned m_MouseButtons; unsigned m_LastMouseButtons; CUIRect m_Screen; + CUIRect m_ClipRect; class IGraphics *m_pGraphics; class ITextRender *m_pTextRender; @@ -101,6 +103,7 @@ public: void FinishCheck() { if(!m_ActiveItemValid) SetActiveItem(0); }; int MouseInside(const CUIRect *pRect) const; + bool MouseInsideClip() const; void ConvertMouseMove(float *x, float *y) const; CUIRect *Screen();