diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-07-07 22:25:42 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-07 22:25:42 +0000 |
| commit | 13e97cd5f5330e5c7f52f243ddee5cdce61edfa6 (patch) | |
| tree | ee53f022c50fc005665597b4f8146809a053016f /utils/themeeditor/graphics/rbviewport.cpp | |
| parent | d4f4104a4ab04cbca75dff874e57dbe34002ded7 (diff) | |
| download | rockbox-13e97cd5f5330e5c7f52f243ddee5cdce61edfa6.zip rockbox-13e97cd5f5330e5c7f52f243ddee5cdce61edfa6.tar.gz rockbox-13e97cd5f5330e5c7f52f243ddee5cdce61edfa6.tar.bz2 rockbox-13e97cd5f5330e5c7f52f243ddee5cdce61edfa6.tar.xz | |
Theme Editor: Implemented line scrolling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27344 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/graphics/rbviewport.cpp')
| -rw-r--r-- | utils/themeeditor/graphics/rbviewport.cpp | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp index 18029a5..3a239c7 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp @@ -21,6 +21,7 @@ #include <QPainter> #include <QPainterPath> +#include <cmath> #include "rbviewport.h" #include "rbscreen.h" @@ -29,12 +30,17 @@ #include "tag_table.h" #include "skin_parser.h" +/* Pause at beginning/end of scroll */ +const double RBViewport::scrollPause = 0.5; +/* Pixels/second of text scrolling */ +const double RBViewport::scrollRate = 30; + RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), background(info.screen()->background()), textOffset(0,0), screen(info.screen()), textAlign(Left), showStatusBar(false), statusBarTexture(":/render/statusbar.png"), - leftGraphic(0), centerGraphic(0), rightGraphic(0) + leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0) { if(!node->tag) { @@ -191,6 +197,8 @@ void RBViewport::newLine() leftGraphic = 0; centerGraphic = 0; rightGraphic = 0; + + scrollTime = 0; } void RBViewport::write(QString text) @@ -287,6 +295,32 @@ void RBViewport::alignLeft() leftGraphic = font->renderText(leftText, foreground, size.width(), this); leftGraphic->setPos(0, y); + + /* Setting scroll position if necessary */ + int difference = leftGraphic->realWidth() + - leftGraphic->boundingRect().width(); + if(difference > 0) + { + /* Subtracting out complete cycles */ + double totalTime = 2 * scrollPause + difference / scrollRate; + scrollTime -= totalTime * std::floor(scrollTime / totalTime); + + /* Calculating the offset */ + if(scrollTime < scrollPause) + { + return; + } + else if(scrollTime < scrollPause + difference / scrollRate) + { + scrollTime -= scrollPause; + int offset = scrollRate * scrollTime; + leftGraphic->setOffset(offset); + } + else + { + leftGraphic->setOffset(difference); + } + } } void RBViewport::alignCenter() @@ -311,6 +345,33 @@ void RBViewport::alignCenter() } centerGraphic->setPos(x, y); + + /* Setting scroll position if necessary */ + int difference = centerGraphic->realWidth() + - centerGraphic->boundingRect().width(); + if(difference > 0) + { + /* Subtracting out complete cycles */ + double totalTime = 2 * scrollPause + difference / scrollRate; + scrollTime -= totalTime * std::floor(scrollTime / totalTime); + + /* Calculating the offset */ + if(scrollTime < scrollPause) + { + return; + } + else if(scrollTime < scrollPause + difference / scrollRate) + { + scrollTime -= scrollPause; + int offset = scrollRate * scrollTime; + centerGraphic->setOffset(offset); + } + else + { + centerGraphic->setOffset(difference); + } + } + } void RBViewport::alignRight() @@ -329,5 +390,32 @@ void RBViewport::alignRight() x = 0; rightGraphic->setPos(x, y); + + /* Setting scroll position if necessary */ + int difference = rightGraphic->realWidth() + - rightGraphic->boundingRect().width(); + if(difference > 0) + { + /* Subtracting out complete cycles */ + double totalTime = 2 * scrollPause + difference / scrollRate; + scrollTime -= totalTime * std::floor(scrollTime / totalTime); + + /* Calculating the offset */ + if(scrollTime < scrollPause) + { + return; + } + else if(scrollTime < scrollPause + difference / scrollRate) + { + scrollTime -= scrollPause; + int offset = scrollRate * scrollTime; + rightGraphic->setOffset(offset); + } + else + { + rightGraphic->setOffset(difference); + } + } + } |