|
@@ -12,6 +12,8 @@ using namespace CamelotFramework;
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
|
|
+ const UINT32 GUIScrollBarHandle::DefaultPageScrollAmount = 100;
|
|
|
|
|
+
|
|
|
const String& GUIScrollBarHandle::getGUITypeName()
|
|
const String& GUIScrollBarHandle::getGUITypeName()
|
|
|
{
|
|
{
|
|
|
static String name = "ScrollBarHandle";
|
|
static String name = "ScrollBarHandle";
|
|
@@ -20,7 +22,7 @@ namespace BansheeEngine
|
|
|
|
|
|
|
|
GUIScrollBarHandle::GUIScrollBarHandle(GUIWidget& parent, bool horizontal, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
|
|
GUIScrollBarHandle::GUIScrollBarHandle(GUIWidget& parent, bool horizontal, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
|
|
|
:GUIElement(parent, style, layoutOptions), mHorizontal(horizontal), mHandleSize(2), mMouseOverHandle(false), mHandlePos(0), mDragStartPos(0),
|
|
:GUIElement(parent, style, layoutOptions), mHorizontal(horizontal), mHandleSize(2), mMouseOverHandle(false), mHandlePos(0), mDragStartPos(0),
|
|
|
- mHandleDragged(false)
|
|
|
|
|
|
|
+ mHandleDragged(false), mPageSize(DefaultPageScrollAmount)
|
|
|
{
|
|
{
|
|
|
mImageSprite = cm_new<ImageSprite, PoolAlloc>();
|
|
mImageSprite = cm_new<ImageSprite, PoolAlloc>();
|
|
|
mCurTexture = style->normal.texture;
|
|
mCurTexture = style->normal.texture;
|
|
@@ -67,6 +69,22 @@ namespace BansheeEngine
|
|
|
markContentAsDirty();
|
|
markContentAsDirty();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void GUIScrollBarHandle::setPageSize(UINT32 size)
|
|
|
|
|
+ {
|
|
|
|
|
+ mPageSize = size;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ float GUIScrollBarHandle::getHandlePos() const
|
|
|
|
|
+ {
|
|
|
|
|
+ UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
|
|
|
|
|
+ return (float)mHandlePos / maxScrollAmount;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ UINT32 GUIScrollBarHandle::getScrollableSize() const
|
|
|
|
|
+ {
|
|
|
|
|
+ return getMaxSize() - mHandleSize;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
UINT32 GUIScrollBarHandle::getNumRenderElements() const
|
|
UINT32 GUIScrollBarHandle::getNumRenderElements() const
|
|
|
{
|
|
{
|
|
|
return mImageSprite->getNumRenderElements();
|
|
return mImageSprite->getNumRenderElements();
|
|
@@ -208,10 +226,10 @@ namespace BansheeEngine
|
|
|
UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
|
|
UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
|
|
|
mHandlePos = Math::Clamp(mHandlePos, 0, (INT32)maxScrollAmount);
|
|
mHandlePos = Math::Clamp(mHandlePos, 0, (INT32)maxScrollAmount);
|
|
|
|
|
|
|
|
- if(!handleMoved.empty())
|
|
|
|
|
|
|
+ if(!onHandleMoved.empty())
|
|
|
{
|
|
{
|
|
|
float pct = (float)mHandlePos / maxScrollAmount;
|
|
float pct = (float)mHandlePos / maxScrollAmount;
|
|
|
- handleMoved(pct);
|
|
|
|
|
|
|
+ onHandleMoved(pct);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
markContentAsDirty();
|
|
markContentAsDirty();
|
|
@@ -233,6 +251,39 @@ namespace BansheeEngine
|
|
|
else
|
|
else
|
|
|
mCurTexture = mStyle->normal.texture;
|
|
mCurTexture = mStyle->normal.texture;
|
|
|
|
|
|
|
|
|
|
+ // If we clicked above or below the scroll handle, scroll by one page
|
|
|
|
|
+ INT32 handleOffset = 0;
|
|
|
|
|
+ if(mHorizontal)
|
|
|
|
|
+ {
|
|
|
|
|
+ INT32 handleLeft = (INT32)mOffset.x + mHandlePos;
|
|
|
|
|
+ INT32 handleRight = handleLeft + mHandleSize;
|
|
|
|
|
+
|
|
|
|
|
+ if(ev.getPosition().x < handleLeft)
|
|
|
|
|
+ handleOffset -= mPageSize;
|
|
|
|
|
+ else if(ev.getPosition().x > handleRight)
|
|
|
|
|
+ handleOffset += mPageSize;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ INT32 handleTop = (INT32)mOffset.y + mHandlePos;
|
|
|
|
|
+ INT32 handleBottom = handleTop + mHandleSize;
|
|
|
|
|
+
|
|
|
|
|
+ if(ev.getPosition().y < handleTop)
|
|
|
|
|
+ handleOffset -= mPageSize;
|
|
|
|
|
+ else if(ev.getPosition().y > handleBottom)
|
|
|
|
|
+ handleOffset += mPageSize;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mHandlePos += handleOffset;
|
|
|
|
|
+ UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
|
|
|
|
|
+ mHandlePos = Math::Clamp(mHandlePos, 0, (INT32)maxScrollAmount);
|
|
|
|
|
+
|
|
|
|
|
+ if(!onHandleMoved.empty())
|
|
|
|
|
+ {
|
|
|
|
|
+ float pct = (float)mHandlePos / maxScrollAmount;
|
|
|
|
|
+ onHandleMoved(pct);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
markContentAsDirty();
|
|
markContentAsDirty();
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|