From e82eefe1dfb18f435c17bb61fa34680e7e3f2bcb Mon Sep 17 00:00:00 2001 From: mar4ello6 <44264356+mar4ello6@users.noreply.github.com> Date: Fri, 29 Sep 2023 01:13:14 +0300 Subject: [PATCH] Fixes for scroll wheel in ScrollComponent Now, the scroll wheel will only scroll in the entity where the cursor is located. The scroll bar now also recognizes the scroll wheel. --- shared/Entity/ScrollBarRenderComponent.cpp | 21 +++++++++++++++++ shared/Entity/ScrollBarRenderComponent.h | 2 ++ shared/Entity/ScrollComponent.cpp | 27 ++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/shared/Entity/ScrollBarRenderComponent.cpp b/shared/Entity/ScrollBarRenderComponent.cpp index d7eb29e4..a55adce6 100644 --- a/shared/Entity/ScrollBarRenderComponent.cpp +++ b/shared/Entity/ScrollBarRenderComponent.cpp @@ -10,6 +10,7 @@ ScrollBarRenderComponent::ScrollBarRenderComponent() m_pSurf = NULL; SetName("ScrollBarRender"); m_bUsingScrollComponent = false; + m_bFadingIn = false; } ScrollBarRenderComponent::~ScrollBarRenderComponent() @@ -33,6 +34,7 @@ void ScrollBarRenderComponent::OnAdd(Entity *pEnt) GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnRender, this, _1)); GetParent()->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnTargetOverStart, this, _1)); GetParent()->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnTargetOverEnd, this, _1)); + GetFunction("OnMouseWheel")->sig_function.connect(1, boost::bind(&ScrollBarRenderComponent::OnMouseWheel, this, _1)); //if "fileName" is set, we'll know about it here GetVar("fileName")->GetSigOnChanged()->connect(boost::bind(&ScrollBarRenderComponent::OnFileNameChanged, this, _1)); @@ -79,6 +81,21 @@ void ScrollBarRenderComponent::OnTargetOverEnd(VariantList *pVList) FadeEntity(GetParent(), false, 0.3f, 1000); } +void ScrollBarRenderComponent::OnMouseWheel(VariantList* pVList) +{ + if ((*m_pAlpha < 0.6f && !m_bFadingIn) || *m_pAlpha <= 0.3f) + { + FadeEntity(GetParent(), false, 0.6f, 100); + FadeEntity(GetParent(), false, 0.3f, 1000, 200, true); + m_bFadingIn = true; + } + if (*m_pAlpha >= 0.6f) + { + m_bFadingIn = false; + FadeEntity(GetParent(), false, 0.3f, 1000, 200); + } +} + void ScrollBarRenderComponent::OnRemove() { EntityComponent::OnRemove(); @@ -86,6 +103,10 @@ void ScrollBarRenderComponent::OnRemove() void ScrollBarRenderComponent::OnUpdate(VariantList *pVList) { + if (*m_pAlpha >= 0.6f) + { + m_bFadingIn = false; + } } void ScrollBarRenderComponent::OnRender(VariantList *pVList) diff --git a/shared/Entity/ScrollBarRenderComponent.h b/shared/Entity/ScrollBarRenderComponent.h index 67af095a..5b76cd74 100644 --- a/shared/Entity/ScrollBarRenderComponent.h +++ b/shared/Entity/ScrollBarRenderComponent.h @@ -51,6 +51,7 @@ class ScrollBarRenderComponent: public EntityComponent void OnRender(VariantList *pVList); void OnTargetOverStart(VariantList *pVList); void OnTargetOverEnd(VariantList *pVList); + void OnMouseWheel(VariantList *pVList); void OnBoundsChanged(Variant *pVariant); void OnFileNameChanged(Variant *pDataObject); CL_Vec2f *m_pPos2d; @@ -64,6 +65,7 @@ class ScrollBarRenderComponent: public EntityComponent SurfaceAnim *m_pSurf; string *m_pFileName; bool m_bUsingScrollComponent; + bool m_bFadingIn; }; diff --git a/shared/Entity/ScrollComponent.cpp b/shared/Entity/ScrollComponent.cpp index 4660b75d..7de89530 100644 --- a/shared/Entity/ScrollComponent.cpp +++ b/shared/Entity/ScrollComponent.cpp @@ -1,6 +1,7 @@ #include "PlatformPrecomp.h" #include "ScrollComponent.h" #include "BaseApp.h" +#include "Entity/EntityUtils.h" ScrollComponent::ScrollComponent() { @@ -125,10 +126,36 @@ void ScrollComponent::OnInput(VariantList* pVList) float f = pVList->Get(0).GetFloat(); if (f == MESSAGE_TYPE_GUI_MOUSEWHEEL) { +#ifdef PLATFORM_WINDOWS + POINT pt; + extern HWND g_hWnd; + if (GetCursorPos(&pt)) + { + RECT r; + + GetClientRect(g_hWnd, (LPRECT)&r); + ClientToScreen(g_hWnd, (LPPOINT)&r.left); + ClientToScreen(g_hWnd, (LPPOINT)&r.right); + + CL_Vec2f entPos = GetScreenPos2DEntity(GetParent()); + + if ((pt.x < r.left + entPos.x || pt.x > r.left + entPos.x + m_pSize2d->x) + || (pt.y < r.top + entPos.y || pt.y > r.top + entPos.y + m_pSize2d->y)) + { + return; //cursor is outside of our Entity + } + } +#endif SetIsScrolling(true); m_vecDisplacement.y += pVList->Get(4).GetVector2().x * *m_pPowerMod * 0.75f;//Maybe change if on HTML5? m_vTotalDisplacementOnCurrentSwipe.y += pVList->Get(4).GetVector2().x * *m_pPowerMod * 0.75f; SetPosition(m_vecDisplacement, false); + + EntityComponent* pScrollBar = GetParent()->GetComponentByName("ScrollBarRender"); + if (pScrollBar) + { + pScrollBar->GetFunction("OnMouseWheel")->sig_function(NULL); + } } }