summaryrefslogtreecommitdiff
path: root/src/gui/interface
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-07-21 21:05:55 (GMT)
committer jacob1 <jfu614@gmail.com>2013-07-21 21:05:55 (GMT)
commite0913d2639dbec89d7ab795be8de12d1e9ec0efb (patch)
treeebada7a67debd5985bc11faf9bd5c1739bad06bb /src/gui/interface
parenta63f5b875b9d31f8932ca62537ae7b863ef7f8b8 (diff)
downloadpowder-e0913d2639dbec89d7ab795be8de12d1e9ec0efb.zip
powder-e0913d2639dbec89d7ab795be8de12d1e9ec0efb.tar.gz
can change comment pages without the scrollwheel, click and hold scrollbar area to have it scroll to that point
Diffstat (limited to 'src/gui/interface')
-rw-r--r--src/gui/interface/ScrollPanel.cpp79
-rw-r--r--src/gui/interface/ScrollPanel.h2
2 files changed, 50 insertions, 31 deletions
diff --git a/src/gui/interface/ScrollPanel.cpp b/src/gui/interface/ScrollPanel.cpp
index f1e8094..cf1dcf1 100644
--- a/src/gui/interface/ScrollPanel.cpp
+++ b/src/gui/interface/ScrollPanel.cpp
@@ -12,6 +12,8 @@ ScrollPanel::ScrollPanel(Point position, Point size):
xScrollVel(0.0f),
scrollBarWidth(0),
isMouseInsideScrollbar(false),
+ isMouseInsideScrollbarArea(false),
+ scrollbarClickLocation(0),
scrollbarSelected(false),
scrollbarInitialYOffset(0),
scrollbarInitialYClick(0)
@@ -21,9 +23,9 @@ ScrollPanel::ScrollPanel(Point position, Point size):
int ScrollPanel::GetScrollLimit()
{
- if(ViewportPosition.Y == 0)
+ if (ViewportPosition.Y == 0)
return -1;
- else if(maxOffset.Y == -ViewportPosition.Y)
+ else if (maxOffset.Y == -ViewportPosition.Y)
return 1;
return 0;
}
@@ -31,11 +33,12 @@ int ScrollPanel::GetScrollLimit()
void ScrollPanel::SetScrollPosition(int position)
{
offsetY = position;
+ ViewportPosition.Y = position;
}
void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d)
{
- if(!d)
+ if (!d)
return;
yScrollVel -= d*2;
}
@@ -47,11 +50,11 @@ void ScrollPanel::Draw(const Point& screenPos)
Graphics * g = ui::Engine::Ref().g;
//Vertical scroll bar
- if(maxOffset.Y>0 && InnerSize.Y>0)
+ if (maxOffset.Y>0 && InnerSize.Y>0)
{
float scrollHeight = float(Size.Y)*(float(Size.Y)/float(InnerSize.Y));
float scrollPos = 0;
- if(-ViewportPosition.Y>0)
+ if (-ViewportPosition.Y>0)
{
scrollPos = float(Size.Y-scrollHeight)*(float(offsetY)/float(maxOffset.Y));
}
@@ -67,13 +70,16 @@ void ScrollPanel::XOnMouseClick(int x, int y, unsigned int button)
{
scrollbarSelected = true;
scrollbarInitialYOffset = offsetY;
- scrollbarInitialYClick = y;
}
+ scrollbarInitialYClick = y;
+ scrollbarClickLocation = 100;
}
void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button)
{
scrollbarSelected = false;
+ isMouseInsideScrollbarArea = false;
+ scrollbarClickLocation = 0;
}
void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
@@ -82,7 +88,7 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
{
float scrollHeight = float(Size.Y)*(float(Size.Y)/float(InnerSize.Y));
float scrollPos = 0;
- if(-ViewportPosition.Y>0)
+ if (-ViewportPosition.Y>0)
{
scrollPos = float(Size.Y-scrollHeight)*(float(offsetY)/float(maxOffset.Y));
}
@@ -102,8 +108,12 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
}
}
- if (x > (Size.X-scrollBarWidth) && x < (Size.X-scrollBarWidth)+scrollBarWidth && y > scrollPos && y < scrollPos+scrollHeight)
- isMouseInsideScrollbar = true;
+ if (x > (Size.X-scrollBarWidth) && x < (Size.X-scrollBarWidth)+scrollBarWidth)
+ {
+ if (y > scrollPos && y < scrollPos+scrollHeight)
+ isMouseInsideScrollbar = true;
+ isMouseInsideScrollbarArea = true;
+ }
else
isMouseInsideScrollbar = false;
}
@@ -111,14 +121,12 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
void ScrollPanel::XTick(float dt)
{
- //if(yScrollVel > 7.0f) yScrollVel = 7.0f;
- //if(yScrollVel < -7.0f) yScrollVel = -7.0f;
- if(yScrollVel > -0.5f && yScrollVel < 0.5)
+ if (yScrollVel > -0.5f && yScrollVel < 0.5)
yScrollVel = 0;
- if(xScrollVel > 7.0f) xScrollVel = 7.0f;
- if(xScrollVel < -7.0f) xScrollVel = -7.0f;
- if(xScrollVel > -0.5f && xScrollVel < 0.5)
+ if (xScrollVel > 7.0f) xScrollVel = 7.0f;
+ if (xScrollVel < -7.0f) xScrollVel = -7.0f;
+ if (xScrollVel > -0.5f && xScrollVel < 0.5)
xScrollVel = 0;
maxOffset = InnerSize-Size;
@@ -133,46 +141,55 @@ void ScrollPanel::XTick(float dt)
yScrollVel*=0.98f;
xScrollVel*=0.98f;
- if(oldOffsetY!=int(offsetY))
+ if (oldOffsetY!=int(offsetY))
{
- if(offsetY<0)
+ if (offsetY<0)
{
offsetY = 0;
yScrollVel = 0;
- //commentsBegin = true;
- //commentsEnd = false;
}
- else if(offsetY>maxOffset.Y)
+ else if (offsetY>maxOffset.Y)
{
offsetY = maxOffset.Y;
yScrollVel = 0;
- //commentsEnd = true;
- //commentsBegin = false;
- }
- else
- {
- //commentsEnd = false;
- //commentsBegin = false;
}
ViewportPosition.Y = -offsetY;
}
else
{
- if(offsetY<0)
+ if (offsetY<0)
{
offsetY = 0;
yScrollVel = 0;
ViewportPosition.Y = -offsetY;
}
- else if(offsetY>maxOffset.Y)
+ else if (offsetY>maxOffset.Y)
{
offsetY = maxOffset.Y;
ViewportPosition.Y = -offsetY;
}
}
- if(mouseInside && scrollBarWidth < 6)
+ if (mouseInside && scrollBarWidth < 6)
scrollBarWidth++;
- else if(!mouseInside && scrollBarWidth > 0 && !scrollbarSelected)
+ else if (!mouseInside && scrollBarWidth > 0 && !scrollbarSelected)
scrollBarWidth--;
+
+ if (isMouseInsideScrollbarArea && scrollbarClickLocation && !scrollbarSelected)
+ {
+ float scrollHeight = float(Size.Y)*(float(Size.Y)/float(InnerSize.Y));
+ float scrollPos = 0;
+ if (-ViewportPosition.Y > 0)
+ scrollPos = float(Size.Y-scrollHeight)*(float(offsetY)/float(maxOffset.Y));
+
+ if (scrollbarInitialYClick <= scrollPos)
+ scrollbarClickLocation = -1;
+ else if (scrollbarInitialYClick >= scrollPos+scrollHeight)
+ scrollbarClickLocation = 1;
+ else
+ scrollbarClickLocation = 0;
+
+ offsetY += scrollbarClickLocation*scrollHeight/10;
+ ViewportPosition.Y -= scrollbarClickLocation*scrollHeight/10;
+ }
}
diff --git a/src/gui/interface/ScrollPanel.h b/src/gui/interface/ScrollPanel.h
index 0d48658..ea56ac9 100644
--- a/src/gui/interface/ScrollPanel.h
+++ b/src/gui/interface/ScrollPanel.h
@@ -14,9 +14,11 @@ namespace ui
float yScrollVel;
float xScrollVel;
bool isMouseInsideScrollbar;
+ bool isMouseInsideScrollbarArea;
bool scrollbarSelected;
int scrollbarInitialYOffset;
int scrollbarInitialYClick;
+ int scrollbarClickLocation;
public:
ScrollPanel(Point position, Point size);