can change comment pages without the scrollwheel, click and hold scrollbar area to have it scroll to that point
This commit is contained in:
parent
a63f5b875b
commit
e0913d2639
@ -12,6 +12,8 @@ ScrollPanel::ScrollPanel(Point position, Point size):
|
|||||||
xScrollVel(0.0f),
|
xScrollVel(0.0f),
|
||||||
scrollBarWidth(0),
|
scrollBarWidth(0),
|
||||||
isMouseInsideScrollbar(false),
|
isMouseInsideScrollbar(false),
|
||||||
|
isMouseInsideScrollbarArea(false),
|
||||||
|
scrollbarClickLocation(0),
|
||||||
scrollbarSelected(false),
|
scrollbarSelected(false),
|
||||||
scrollbarInitialYOffset(0),
|
scrollbarInitialYOffset(0),
|
||||||
scrollbarInitialYClick(0)
|
scrollbarInitialYClick(0)
|
||||||
@ -31,6 +33,7 @@ int ScrollPanel::GetScrollLimit()
|
|||||||
void ScrollPanel::SetScrollPosition(int position)
|
void ScrollPanel::SetScrollPosition(int position)
|
||||||
{
|
{
|
||||||
offsetY = position;
|
offsetY = position;
|
||||||
|
ViewportPosition.Y = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d)
|
void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d)
|
||||||
@ -67,13 +70,16 @@ void ScrollPanel::XOnMouseClick(int x, int y, unsigned int button)
|
|||||||
{
|
{
|
||||||
scrollbarSelected = true;
|
scrollbarSelected = true;
|
||||||
scrollbarInitialYOffset = offsetY;
|
scrollbarInitialYOffset = offsetY;
|
||||||
scrollbarInitialYClick = y;
|
|
||||||
}
|
}
|
||||||
|
scrollbarInitialYClick = y;
|
||||||
|
scrollbarClickLocation = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button)
|
void ScrollPanel::XOnMouseUp(int x, int y, unsigned int button)
|
||||||
{
|
{
|
||||||
scrollbarSelected = false;
|
scrollbarSelected = false;
|
||||||
|
isMouseInsideScrollbarArea = false;
|
||||||
|
scrollbarClickLocation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
|
void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
|
||||||
@ -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)
|
if (x > (Size.X-scrollBarWidth) && x < (Size.X-scrollBarWidth)+scrollBarWidth)
|
||||||
|
{
|
||||||
|
if (y > scrollPos && y < scrollPos+scrollHeight)
|
||||||
isMouseInsideScrollbar = true;
|
isMouseInsideScrollbar = true;
|
||||||
|
isMouseInsideScrollbarArea = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
isMouseInsideScrollbar = false;
|
isMouseInsideScrollbar = false;
|
||||||
}
|
}
|
||||||
@ -111,8 +121,6 @@ void ScrollPanel::XOnMouseMoved(int x, int y, int dx, int dy)
|
|||||||
|
|
||||||
void ScrollPanel::XTick(float dt)
|
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;
|
yScrollVel = 0;
|
||||||
|
|
||||||
@ -139,20 +147,11 @@ void ScrollPanel::XTick(float dt)
|
|||||||
{
|
{
|
||||||
offsetY = 0;
|
offsetY = 0;
|
||||||
yScrollVel = 0;
|
yScrollVel = 0;
|
||||||
//commentsBegin = true;
|
|
||||||
//commentsEnd = false;
|
|
||||||
}
|
}
|
||||||
else if (offsetY>maxOffset.Y)
|
else if (offsetY>maxOffset.Y)
|
||||||
{
|
{
|
||||||
offsetY = maxOffset.Y;
|
offsetY = maxOffset.Y;
|
||||||
yScrollVel = 0;
|
yScrollVel = 0;
|
||||||
//commentsEnd = true;
|
|
||||||
//commentsBegin = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//commentsEnd = false;
|
|
||||||
//commentsBegin = false;
|
|
||||||
}
|
}
|
||||||
ViewportPosition.Y = -offsetY;
|
ViewportPosition.Y = -offsetY;
|
||||||
}
|
}
|
||||||
@ -175,4 +174,22 @@ void ScrollPanel::XTick(float dt)
|
|||||||
scrollBarWidth++;
|
scrollBarWidth++;
|
||||||
else if (!mouseInside && scrollBarWidth > 0 && !scrollbarSelected)
|
else if (!mouseInside && scrollBarWidth > 0 && !scrollbarSelected)
|
||||||
scrollBarWidth--;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,11 @@ namespace ui
|
|||||||
float yScrollVel;
|
float yScrollVel;
|
||||||
float xScrollVel;
|
float xScrollVel;
|
||||||
bool isMouseInsideScrollbar;
|
bool isMouseInsideScrollbar;
|
||||||
|
bool isMouseInsideScrollbarArea;
|
||||||
bool scrollbarSelected;
|
bool scrollbarSelected;
|
||||||
int scrollbarInitialYOffset;
|
int scrollbarInitialYOffset;
|
||||||
int scrollbarInitialYClick;
|
int scrollbarInitialYClick;
|
||||||
|
int scrollbarClickLocation;
|
||||||
public:
|
public:
|
||||||
ScrollPanel(Point position, Point size);
|
ScrollPanel(Point position, Point size);
|
||||||
|
|
||||||
|
@ -162,16 +162,24 @@ void PreviewController::OpenInBrowser()
|
|||||||
OpenURI(uriStream.str());
|
OpenURI(uriStream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewController::NextCommentPage()
|
bool PreviewController::NextCommentPage()
|
||||||
{
|
{
|
||||||
if(previewModel->GetCommentsPageNum() < previewModel->GetCommentsPageCount() && previewModel->GetCommentsLoaded())
|
if(previewModel->GetCommentsPageNum() < previewModel->GetCommentsPageCount() && previewModel->GetCommentsLoaded())
|
||||||
|
{
|
||||||
previewModel->UpdateComments(previewModel->GetCommentsPageNum()+1);
|
previewModel->UpdateComments(previewModel->GetCommentsPageNum()+1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewController::PrevCommentPage()
|
bool PreviewController::PrevCommentPage()
|
||||||
{
|
{
|
||||||
if(previewModel->GetCommentsPageNum()>1 && previewModel->GetCommentsLoaded())
|
if(previewModel->GetCommentsPageNum()>1 && previewModel->GetCommentsLoaded())
|
||||||
|
{
|
||||||
previewModel->UpdateComments(previewModel->GetCommentsPageNum()-1);
|
previewModel->UpdateComments(previewModel->GetCommentsPageNum()-1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewController::Exit()
|
void PreviewController::Exit()
|
||||||
|
@ -36,8 +36,8 @@ public:
|
|||||||
void FavouriteSave();
|
void FavouriteSave();
|
||||||
bool SubmitComment(std::string comment);
|
bool SubmitComment(std::string comment);
|
||||||
|
|
||||||
void NextCommentPage();
|
bool NextCommentPage();
|
||||||
void PrevCommentPage();
|
bool PrevCommentPage();
|
||||||
|
|
||||||
virtual ~PreviewController();
|
virtual ~PreviewController();
|
||||||
};
|
};
|
||||||
|
@ -376,12 +376,23 @@ void PreviewView::OnMouseWheel(int x, int y, int d)
|
|||||||
c->NextCommentPage();
|
c->NextCommentPage();
|
||||||
if(commentsPanel->GetScrollLimit() == -1 && d > 0)
|
if(commentsPanel->GetScrollLimit() == -1 && d > 0)
|
||||||
{
|
{
|
||||||
|
if (c->PrevCommentPage())
|
||||||
prevPage = true;
|
prevPage = true;
|
||||||
c->PrevCommentPage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewView::OnMouseUp(int x, int y, unsigned int button)
|
||||||
|
{
|
||||||
|
if(commentsPanel->GetScrollLimit() == 1)
|
||||||
|
c->NextCommentPage();
|
||||||
|
if(commentsPanel->GetScrollLimit() == -1)
|
||||||
|
{
|
||||||
|
if (c->PrevCommentPage())
|
||||||
|
prevPage = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
void PreviewView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
if ((key == KEY_ENTER || key == KEY_RETURN) && (!addCommentBox || !addCommentBox->IsFocused()))
|
if ((key == KEY_ENTER || key == KEY_RETURN) && (!addCommentBox || !addCommentBox->IsFocused()))
|
||||||
@ -558,7 +569,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(showAvatars)
|
if(showAvatars)
|
||||||
tempUsername = new ui::Label(ui::Point(31, currentY+3), ui::Point(Size.X-((XRES/2) + 13), 16), comments->at(i)->authorNameFormatted);
|
tempUsername = new ui::Label(ui::Point(31, currentY+3), ui::Point(Size.X-((XRES/2) + 13 + 26), 16), comments->at(i)->authorNameFormatted);
|
||||||
else
|
else
|
||||||
tempUsername = new ui::Label(ui::Point(5, currentY+3), ui::Point(Size.X-((XRES/2) + 13), 16), comments->at(i)->authorNameFormatted);
|
tempUsername = new ui::Label(ui::Point(5, currentY+3), ui::Point(Size.X-((XRES/2) + 13), 16), comments->at(i)->authorNameFormatted);
|
||||||
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
@ -593,8 +604,6 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
|||||||
{
|
{
|
||||||
prevPage = false;
|
prevPage = false;
|
||||||
commentsPanel->SetScrollPosition(currentY);
|
commentsPanel->SetScrollPosition(currentY);
|
||||||
//update positions of the comments so that it doesn't start at the top for a frame
|
|
||||||
commentsPanel->Tick(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ public:
|
|||||||
virtual void OnTick(float dt);
|
virtual void OnTick(float dt);
|
||||||
virtual void OnTryExit(ExitMethod method);
|
virtual void OnTryExit(ExitMethod method);
|
||||||
virtual void OnMouseWheel(int x, int y, int d);
|
virtual void OnMouseWheel(int x, int y, int d);
|
||||||
|
virtual void OnMouseUp(int x, int y, unsigned int button);
|
||||||
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
virtual ~PreviewView();
|
virtual ~PreviewView();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user