summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/interface/ScrollPanel.cpp62
-rw-r--r--src/interface/ScrollPanel.h7
-rw-r--r--src/preview/PreviewModel.cpp1
-rw-r--r--src/preview/PreviewView.cpp6
4 files changed, 67 insertions, 9 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
diff --git a/src/interface/ScrollPanel.h b/src/interface/ScrollPanel.h
index fc54b31..c26c420 100644
--- a/src/interface/ScrollPanel.h
+++ b/src/interface/ScrollPanel.h
@@ -13,6 +13,10 @@ namespace ui
float offsetY;
float yScrollVel;
float xScrollVel;
+ bool isMouseInsideScrollbar;
+ bool scrollbarSelected;
+ int scrollbarInitialYOffset;
+ int scrollbarInitialYClick;
public:
ScrollPanel(Point position, Point size);
@@ -21,5 +25,8 @@ namespace ui
virtual void Draw(const Point& screenPos);
virtual void XTick(float dt);
virtual void XOnMouseWheelInside(int localx, int localy, int d);
+ virtual void XOnMouseClick(int localx, int localy, unsigned int button);
+ virtual void XOnMouseUp(int x, int y, unsigned int button);
+ virtual void XOnMouseMoved(int localx, int localy, int dx, int dy);
};
} \ No newline at end of file
diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp
index 20f6bfd..399fedf 100644
--- a/src/preview/PreviewModel.cpp
+++ b/src/preview/PreviewModel.cpp
@@ -63,7 +63,6 @@ void * PreviewModel::updateSaveDataT()
void * PreviewModel::updateSaveCommentsT()
{
- //Haha, j/k
std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(tSaveID, (commentsPageNumber-1)*20, 20);
updateSaveCommentsFinished = true;
return tempComments;
diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp
index 445142a..d6c4448 100644
--- a/src/preview/PreviewView.cpp
+++ b/src/preview/PreviewView.cpp
@@ -53,7 +53,7 @@ public:
};
PreviewView::PreviewView():
- ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
+ ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+210, (YRES/2)+150)),
savePreview(NULL),
doOpen(false),
addCommentBox(NULL),
@@ -514,7 +514,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
for(int i = 0; i < comments.size(); i++)
{
int usernameY = currentY+5, commentY;
- tempUsername = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), 16), comments[i].authorName);
+ tempUsername = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 13), 16), comments[i].authorName);
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
currentY += 16;
@@ -524,7 +524,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
commentY = currentY+5;
- tempComment = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
+ tempComment = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 13), -1), comments[i].comment);
tempComment->SetMultiline(true);
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;