summaryrefslogtreecommitdiff
path: root/src/preview/PreviewView.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-26 20:51:30 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-26 20:51:30 (GMT)
commitf8ca8af387b8611c18ca7c5357efd19c8bc28941 (patch)
treefe790e2abede326949bb299b564ba8e75a979ecf /src/preview/PreviewView.cpp
parent121e7c772cfc7b3e1305a03144264fc5b66564c2 (diff)
downloadpowder-f8ca8af387b8611c18ca7c5357efd19c8bc28941.zip
powder-f8ca8af387b8611c18ca7c5357efd19c8bc28941.tar.gz
Scroll Panel
Diffstat (limited to 'src/preview/PreviewView.cpp')
-rw-r--r--src/preview/PreviewView.cpp189
1 files changed, 54 insertions, 135 deletions
diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp
index e586f32..f20df6f 100644
--- a/src/preview/PreviewView.cpp
+++ b/src/preview/PreviewView.cpp
@@ -17,6 +17,7 @@
#include "Style.h"
#include "search/Thumbnail.h"
#include "client/Client.h"
+#include "interface/ScrollPanel.h"
class PreviewView::LoginAction: public ui::ButtonAction
{
@@ -54,11 +55,6 @@ PreviewView::PreviewView():
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
savePreview(NULL),
doOpen(false),
- commentsOffset(0),
- commentsVel(0),
- maxOffset(0),
- commentsBegin(true),
- commentsEnd(false),
addCommentBox(NULL),
submitCommentButton(NULL),
commentBoxHeight(20)
@@ -160,6 +156,9 @@ PreviewView::PreviewView():
pageInfo = new ui::Label(ui::Point((XRES/2) + 5, Size.Y+1), ui::Point(Size.X-((XRES/2) + 10), 15), "Page 1 of 1");
pageInfo->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
+ commentsPanel = new ui::ScrollPanel(ui::Point(XRES/2, 0), ui::Point(Size.X-(XRES/2), Size.Y-commentBoxHeight));
+ AddComponent(commentsPanel);
+
AddComponent(pageInfo);
}
@@ -170,7 +169,7 @@ void PreviewView::commentBoxAutoHeight()
int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str());
if(textWidth+5 > Size.X-(XRES/2)-48)
{
- commentBoxHeight = 58;
+ commentBoxHeight = 59;
addCommentBox->SetMultiline(true);
addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop;
@@ -190,7 +189,7 @@ void PreviewView::commentBoxAutoHeight()
commentBoxSizeX = Size.X-(XRES/2)-48;
commentBoxSizeY = 17;
}
- displayComments(commentsOffset);
+ commentsPanel->Size.Y = Size.Y-commentBoxHeight;
}
void PreviewView::DoDraw()
@@ -237,52 +236,19 @@ void PreviewView::OnDraw()
for(int i = 0; i < commentTextComponents.size(); i++)
{
+ int linePos = commentTextComponents[i]->Position.Y+commentsPanel->ViewportPosition.Y+commentTextComponents[i]->Size.Y+4;
+ if(linePos > 0 && linePos < Size.Y-commentBoxHeight)
g->draw_line(
Position.X+XRES/2,
- Position.Y+commentTextComponents[i]->Position.Y+commentTextComponents[i]->Size.Y+4,
+ Position.Y+linePos,
Position.X+Size.X-1,
- Position.Y+commentTextComponents[i]->Position.Y+commentTextComponents[i]->Size.Y+4,
+ Position.Y+linePos,
100, 100, 100, 255);
}
}
void PreviewView::OnTick(float dt)
{
- if(commentsVel > 5.0f) commentsVel = 5.0f;
- if(commentsVel < -5.0f) commentsVel = -5.0f;
- if(commentsVel > -0.5f && commentsVel < 0.5)
- commentsVel = 0;
-
- int oldOffset = commentsOffset;
- commentsOffset += commentsVel;
-
- commentsVel*=0.99f;
-
- if(oldOffset!=int(commentsOffset))
- {
- if(commentsOffset<0)
- {
- commentsOffset = 0;
- commentsVel = 0;
- commentsBegin = true;
- commentsEnd = false;
- }
- else if(commentsOffset>maxOffset)
- {
- commentsOffset = maxOffset;
- commentsVel = 0;
- commentsEnd = true;
- commentsBegin = false;
- }
- else
- {
- commentsEnd = false;
- commentsBegin = false;
- }
-
- displayComments(commentsOffset);
- }
-
if(addCommentBox)
{
ui::Point positionDiff = ui::Point(commentBoxPositionX, commentBoxPositionY)-addCommentBox->Position;
@@ -309,6 +275,7 @@ void PreviewView::OnTick(float dt)
if(xdiff == 0)
xdiff = 1*isign(sizeDiff.X);
addCommentBox->Size.X += xdiff;
+ addCommentBox->Invalidate();
}
if(sizeDiff.Y!=0)
{
@@ -316,6 +283,7 @@ void PreviewView::OnTick(float dt)
if(ydiff == 0)
ydiff = 1*isign(sizeDiff.Y);
addCommentBox->Size.Y += ydiff;
+ addCommentBox->Invalidate();
}
}
@@ -328,6 +296,15 @@ void PreviewView::OnMouseDown(int x, int y, unsigned button)
c->Exit();
}
+void PreviewView::OnMouseWheel(int x, int y, int d)
+{
+ if(commentsPanel->GetScrollLimit() == 1 && d < 0)
+ c->NextCommentPage();
+ if(commentsPanel->GetScrollLimit() == -1 && d > 0)
+ c->PrevCommentPage();
+
+}
+
void PreviewView::NotifySaveChanged(PreviewModel * sender)
{
SaveInfo * save = sender->GetSave();
@@ -392,60 +369,6 @@ void PreviewView::submitComment()
}
}
-void PreviewView::displayComments(int yOffset)
-{
- for(int i = 0; i < commentComponents.size(); i++)
- {
- RemoveComponent(commentComponents[i]);
- delete commentComponents[i];
- }
- commentComponents.clear();
- commentTextComponents.clear();
-
- int currentY = -yOffset;
- ui::Label * tempUsername;
- ui::Label * tempComment;
- for(int i = 0; i < comments.size(); i++)
- {
- int usernameY = currentY+5, commentY;
- tempUsername = new ui::Label(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), 16), comments[i].authorName);
- tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
- currentY += 16;
-
- if(currentY+5 > Size.Y-commentBoxHeight || usernameY < 0)
- {
- delete tempUsername;
- if(currentY+5 > Size.Y-commentBoxHeight)
- break;
- }
- else
- {
- commentComponents.push_back(tempUsername);
- AddComponent(tempUsername);
- }
-
- commentY = currentY+5;
- tempComment = new ui::Label(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
- tempComment->SetMultiline(true);
- tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
- tempComment->SetTextColour(ui::Colour(180, 180, 180));
- currentY += tempComment->Size.Y+4;
-
- if(currentY+5 > Size.Y-commentBoxHeight || commentY < 0)
- {
- delete tempComment;
- if(currentY+5 > Size.Y-commentBoxHeight)
- break;
- }
- else
- {
- commentComponents.push_back(tempComment);
- AddComponent(tempComment);
- commentTextComponents.push_back(tempComment);
- }
- }
-}
-
void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
{
if(addCommentBox)
@@ -502,48 +425,44 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
comments.clear();
}
- ui::Label * tempUsername;
- ui::Label * tempComment;
- int maxY = 0;
- for(int i = 0; i < comments.size(); i++)
{
- tempUsername = new ui::Label(ui::Point(0, 0), ui::Point(Size.X-((XRES/2) + 10), 16), comments[i].authorName);
- tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
- tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
- maxY += 16;
- tempComment = new ui::Label(ui::Point(0, 0), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
- tempComment->SetMultiline(true);
- tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
- tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
- tempComment->SetTextColour(ui::Colour(180, 180, 180));
- maxY += tempComment->Size.Y+4;
-
- delete tempUsername;
- delete tempComment;
- }
+ for(int i = 0; i < commentComponents.size(); i++)
+ {
+ commentsPanel->RemoveChild(commentComponents[i]);
+ delete commentComponents[i];
+ }
+ commentComponents.clear();
+ commentTextComponents.clear();
+ int currentY = 0;//-yOffset;
+ ui::Label * tempUsername;
+ ui::Label * tempComment;
+ 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->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
+ currentY += 16;
- maxOffset = (maxY-(Size.Y-commentBoxHeight))+16;
- commentsBegin = true;
- commentsEnd = false;
- commentsOffset = 0;
- commentsVel = 0;
- displayComments(commentsOffset);
-}
+ commentComponents.push_back(tempUsername);
+ commentsPanel->AddChild(tempUsername);
-void PreviewView::OnMouseWheel(int x, int y, int d)
-{
- if(!d)
- return;
- commentsVel-=d;
- if(d<0)
- {
- if(commentsEnd)
- c->NextCommentPage();
- } else {
- if(commentsBegin)
- c->PrevCommentPage();
+ commentY = currentY+5;
+ tempComment = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
+ tempComment->SetMultiline(true);
+ tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
+ tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
+ tempComment->SetTextColour(ui::Colour(180, 180, 180));
+ currentY += tempComment->Size.Y+4;
+
+ commentComponents.push_back(tempComment);
+ commentsPanel->AddChild(tempComment);
+ commentTextComponents.push_back(tempComment);
+ }
+
+ commentsPanel->InnerSize = ui::Point(commentsPanel->Size.X, currentY+4);
}
}