summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor/graphics')
-rw-r--r--utils/themeeditor/graphics/rbtext.cpp9
-rw-r--r--utils/themeeditor/graphics/rbtext.h4
-rw-r--r--utils/themeeditor/graphics/rbviewport.cpp90
-rw-r--r--utils/themeeditor/graphics/rbviewport.h6
4 files changed, 106 insertions, 3 deletions
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp
index 4666f9ae99..8de5d57897 100644
--- a/utils/themeeditor/graphics/rbtext.cpp
+++ b/utils/themeeditor/graphics/rbtext.cpp
@@ -24,7 +24,7 @@
#include <QPainter>
RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent)
- :QGraphicsItem(parent), image(image), maxWidth(maxWidth)
+ :QGraphicsItem(parent), image(image), maxWidth(maxWidth), offset(0)
{
}
@@ -39,8 +39,13 @@ QRectF RBText::boundingRect() const
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
+ /* Making sure the offset is within bounds */
+ if(image->width() > maxWidth)
+ if(offset > image->width() - maxWidth)
+ offset = image->width() - maxWidth;
+
if(image->width() < maxWidth)
painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height());
else
- painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height());
+ painter->drawImage(0, 0, *image, offset, 0, maxWidth, image->height());
}
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h
index 936a809f6c..b4d9ae3c54 100644
--- a/utils/themeeditor/graphics/rbtext.h
+++ b/utils/themeeditor/graphics/rbtext.h
@@ -34,9 +34,13 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
+ int realWidth(){ return image->width(); }
+ void setOffset(int offset){ this->offset = offset; }
+
private:
QImage* image;
int maxWidth;
+ int offset;
};
diff --git a/utils/themeeditor/graphics/rbviewport.cpp b/utils/themeeditor/graphics/rbviewport.cpp
index 18029a57f6..3a239c7f35 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);
+ }
+ }
+
}
diff --git a/utils/themeeditor/graphics/rbviewport.h b/utils/themeeditor/graphics/rbviewport.h
index c557632a40..eeeb7191ef 100644
--- a/utils/themeeditor/graphics/rbviewport.h
+++ b/utils/themeeditor/graphics/rbviewport.h
@@ -40,6 +40,9 @@ public:
Right
};
+ static const double scrollRate;
+ static const double scrollPause;
+
RBViewport(skin_element* node, const RBRenderInfo& info);
virtual ~RBViewport();
@@ -66,6 +69,7 @@ public:
alignRight();
alignCenter();
}
+ void scrollText(double time){ scrollTime = time; }
void enableStatusBar(){ showStatusBar = true; }
@@ -101,6 +105,8 @@ private:
RBText* leftGraphic;
RBText* centerGraphic;
RBText* rightGraphic;
+
+ double scrollTime;
};
#endif // RBVIEWPORT_H