summaryrefslogtreecommitdiff
path: root/src/interface/ScrollPanel.cpp
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2012-12-14 18:34:00 (GMT)
committer jacob1 <jfu614@gmail.com>2012-12-14 18:34:00 (GMT)
commit05fc39e40faa817cdbf3e50de94d28a5ef9349dc (patch)
tree449557cc23018e9b0257786fd4ccab75ca94e5d1 /src/interface/ScrollPanel.cpp
parent002743ef085b21789e02505c30d5186c043d92b5 (diff)
downloadpowder-05fc39e40faa817cdbf3e50de94d28a5ef9349dc.zip
powder-05fc39e40faa817cdbf3e50de94d28a5ef9349dc.tar.gz
a working scrollbar in the save preview. Also, fix the bug where you couldn't go back up a page when there weren't enough comments to fill a page
Diffstat (limited to 'src/interface/ScrollPanel.cpp')
-rw-r--r--src/interface/ScrollPanel.cpp62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/interface/ScrollPanel.cpp b/src/interface/ScrollPanel.cpp
index c2d4f66..74f6b62 100644
--- a/src/interface/ScrollPanel.cpp
+++ b/src/interface/ScrollPanel.cpp
@@ -10,17 +10,21 @@ ScrollPanel::ScrollPanel(Point position, Point size):
offsetY(0),
yScrollVel(0.0f),
xScrollVel(0.0f),
- scrollBarWidth(0)
+ scrollBarWidth(0),
+ isMouseInsideScrollbar(false),
+ scrollbarSelected(false),
+ scrollbarInitialYOffset(0),
+ scrollbarInitialYClick(0)
{
}
int ScrollPanel::GetScrollLimit()
{
- if(maxOffset.Y == -ViewportPosition.Y)
- return 1;
- else if(ViewportPosition.Y == 0)
+ if(ViewportPosition.Y == 0)
return -1;
+ else if(maxOffset.Y == -ViewportPosition.Y)
+ return 1;
return 0;
}
@@ -52,6 +56,54 @@ void ScrollPanel::Draw(const Point& screenPos)
}
}
+void ScrollPanel::XOnMouseClick(int x, int y, unsigned int button)
+{
+ if (isMouseInsideScrollbar)
+ {
+ scrollbarSelected = true;
+ scrollbarInitialYOffset = offsetY;
+ scrollbarInitialYClick = y;
+ }
+}
+
+void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button)
+{
+ scrollbarSelected = false;
+}
+
+void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
+{
+ 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)
+ {
+ scrollPos = float(Size.Y-scrollHeight)*(float(offsetY)/float(maxOffset.Y));
+ }
+
+ if (scrollbarSelected)
+ {
+ if (x > 0)
+ {
+ int scrollY = float(y-scrollbarInitialYClick)/float(Size.Y)*float(InnerSize.Y)+scrollbarInitialYOffset;
+ ViewportPosition.Y = -scrollY;
+ offsetY = scrollY;
+ }
+ else
+ {
+ ViewportPosition.Y = -scrollbarInitialYOffset;
+ offsetY = scrollbarInitialYOffset;
+ }
+ }
+
+ if (x > (Size.X-scrollBarWidth) && x < (Size.X-scrollBarWidth)+scrollBarWidth && y > scrollPos && y < scrollPos+scrollHeight)
+ isMouseInsideScrollbar = true;
+ else
+ isMouseInsideScrollbar = false;
+ }
+}
+
void ScrollPanel::XTick(float dt)
{
//if(yScrollVel > 7.0f) yScrollVel = 7.0f;
@@ -116,6 +168,6 @@ void ScrollPanel::XTick(float dt)
if(mouseInside && scrollBarWidth < 6)
scrollBarWidth++;
- else if(!mouseInside && scrollBarWidth > 0)
+ else if(!mouseInside && scrollBarWidth > 0 && !scrollbarSelected)
scrollBarWidth--;
} \ No newline at end of file