From a63f5b875b9d31f8932ca62537ae7b863ef7f8b8 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 21 Jul 2013 15:59:51 -0400 Subject: [PATCH] when scrolling up through comments, it starts at the bottom of the page instead of the top --- src/gui/interface/ScrollPanel.cpp | 5 +++++ src/gui/interface/ScrollPanel.h | 1 + src/gui/preview/PreviewView.cpp | 28 ++++++++++++---------------- src/gui/preview/PreviewView.h | 1 + 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/gui/interface/ScrollPanel.cpp b/src/gui/interface/ScrollPanel.cpp index 11a4f71a6..f1e80949b 100644 --- a/src/gui/interface/ScrollPanel.cpp +++ b/src/gui/interface/ScrollPanel.cpp @@ -28,6 +28,11 @@ int ScrollPanel::GetScrollLimit() return 0; } +void ScrollPanel::SetScrollPosition(int position) +{ + offsetY = position; +} + void ScrollPanel::XOnMouseWheelInside(int localx, int localy, int d) { if(!d) diff --git a/src/gui/interface/ScrollPanel.h b/src/gui/interface/ScrollPanel.h index 08b50699b..0d48658fe 100644 --- a/src/gui/interface/ScrollPanel.h +++ b/src/gui/interface/ScrollPanel.h @@ -21,6 +21,7 @@ namespace ui ScrollPanel(Point position, Point size); int GetScrollLimit(); + void SetScrollPosition(int position); virtual void Draw(const Point& screenPos); virtual void XTick(float dt); diff --git a/src/gui/preview/PreviewView.cpp b/src/gui/preview/PreviewView.cpp index f55f6b5fb..590798e3f 100644 --- a/src/gui/preview/PreviewView.cpp +++ b/src/gui/preview/PreviewView.cpp @@ -69,7 +69,8 @@ PreviewView::PreviewView(): addCommentBox(NULL), submitCommentButton(NULL), commentBoxHeight(20), - showAvatars(true) + showAvatars(true), + prevPage(false) { class FavAction: public ui::ButtonAction { @@ -374,7 +375,10 @@ void PreviewView::OnMouseWheel(int x, int y, int d) if(commentsPanel->GetScrollLimit() == 1 && d < 0) c->NextCommentPage(); if(commentsPanel->GetScrollLimit() == -1 && d > 0) + { + prevPage = true; c->PrevCommentPage(); + } } @@ -585,24 +589,16 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender) } commentsPanel->InnerSize = ui::Point(commentsPanel->Size.X, currentY+4); + if (prevPage) + { + prevPage = false; + commentsPanel->SetScrollPosition(currentY); + //update positions of the comments so that it doesn't start at the top for a frame + commentsPanel->Tick(0); + } } } -/*void PreviewView::NotifyPreviewChanged(PreviewModel * sender) -{ - savePreview = sender->GetGameSave(); - if(savePreview && savePreview->Data && !(savePreview->Width == XRES/2 && savePreview->Height == YRES/2)) - { - int newSizeX, newSizeY; - float factorX = ((float)XRES/2)/((float)savePreview->Width); - float factorY = ((float)YRES/2)/((float)savePreview->Height); - float scaleFactor = factorY < factorX ? factorY : factorX; - savePreview->Data = Graphics::resample_img(savePreview->Data, savePreview->Width, savePreview->Height, savePreview->Width*scaleFactor, savePreview->Height*scaleFactor); - savePreview->Width *= scaleFactor; - savePreview->Height *= scaleFactor; - } -}*/ - PreviewView::~PreviewView() { if(addCommentBox) diff --git a/src/gui/preview/PreviewView.h b/src/gui/preview/PreviewView.h index 25c377207..9ddbb712e 100644 --- a/src/gui/preview/PreviewView.h +++ b/src/gui/preview/PreviewView.h @@ -49,6 +49,7 @@ class PreviewView: public ui::Window { int votesDown; bool doOpen; bool showAvatars; + bool prevPage; int commentBoxHeight; float commentBoxPositionX;