Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions shared/Entity/ScrollBarRenderComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ScrollBarRenderComponent::ScrollBarRenderComponent()
m_pSurf = NULL;
SetName("ScrollBarRender");
m_bUsingScrollComponent = false;
m_bFadingIn = false;
}

ScrollBarRenderComponent::~ScrollBarRenderComponent()
Expand All @@ -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));

Expand Down Expand Up @@ -79,13 +81,32 @@ 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();
}

void ScrollBarRenderComponent::OnUpdate(VariantList *pVList)
{
if (*m_pAlpha >= 0.6f)
{
m_bFadingIn = false;
}
}

void ScrollBarRenderComponent::OnRender(VariantList *pVList)
Expand Down
2 changes: 2 additions & 0 deletions shared/Entity/ScrollBarRenderComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,6 +65,7 @@ class ScrollBarRenderComponent: public EntityComponent
SurfaceAnim *m_pSurf;
string *m_pFileName;
bool m_bUsingScrollComponent;
bool m_bFadingIn;

};

Expand Down
27 changes: 27 additions & 0 deletions shared/Entity/ScrollComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "PlatformPrecomp.h"
#include "ScrollComponent.h"
#include "BaseApp.h"
#include "Entity/EntityUtils.h"

ScrollComponent::ScrollComponent()
{
Expand Down Expand Up @@ -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);
}
}
}

Expand Down