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
This commit is contained in:
parent
002743ef08
commit
05fc39e40f
@ -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--;
|
||||
}
|
@ -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);
|
||||
};
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user