1
0
Fork 0
forked from len0rd/rockbox

Theme Editor: Implemented line scrolling

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27344 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-07-07 22:25:42 +00:00
parent d4f4104a4a
commit 13e97cd5f5
5 changed files with 126 additions and 3 deletions

View file

@ -24,7 +24,7 @@
#include <QPainter> #include <QPainter>
RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent) 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, void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) 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) if(image->width() < maxWidth)
painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height()); painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height());
else else
painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height()); painter->drawImage(0, 0, *image, offset, 0, maxWidth, image->height());
} }

View file

@ -34,9 +34,13 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
int realWidth(){ return image->width(); }
void setOffset(int offset){ this->offset = offset; }
private: private:
QImage* image; QImage* image;
int maxWidth; int maxWidth;
int offset;
}; };

View file

@ -21,6 +21,7 @@
#include <QPainter> #include <QPainter>
#include <QPainterPath> #include <QPainterPath>
#include <cmath>
#include "rbviewport.h" #include "rbviewport.h"
#include "rbscreen.h" #include "rbscreen.h"
@ -29,12 +30,17 @@
#include "tag_table.h" #include "tag_table.h"
#include "skin_parser.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) RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info)
: QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()),
background(info.screen()->background()), textOffset(0,0), background(info.screen()->background()), textOffset(0,0),
screen(info.screen()), textAlign(Left), showStatusBar(false), screen(info.screen()), textAlign(Left), showStatusBar(false),
statusBarTexture(":/render/statusbar.png"), statusBarTexture(":/render/statusbar.png"),
leftGraphic(0), centerGraphic(0), rightGraphic(0) leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0)
{ {
if(!node->tag) if(!node->tag)
{ {
@ -191,6 +197,8 @@ void RBViewport::newLine()
leftGraphic = 0; leftGraphic = 0;
centerGraphic = 0; centerGraphic = 0;
rightGraphic = 0; rightGraphic = 0;
scrollTime = 0;
} }
void RBViewport::write(QString text) void RBViewport::write(QString text)
@ -287,6 +295,32 @@ void RBViewport::alignLeft()
leftGraphic = font->renderText(leftText, foreground, size.width(), this); leftGraphic = font->renderText(leftText, foreground, size.width(), this);
leftGraphic->setPos(0, y); 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() void RBViewport::alignCenter()
@ -311,6 +345,33 @@ void RBViewport::alignCenter()
} }
centerGraphic->setPos(x, y); 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() void RBViewport::alignRight()
@ -329,5 +390,32 @@ void RBViewport::alignRight()
x = 0; x = 0;
rightGraphic->setPos(x, y); 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);
}
}
} }

View file

@ -40,6 +40,9 @@ public:
Right Right
}; };
static const double scrollRate;
static const double scrollPause;
RBViewport(skin_element* node, const RBRenderInfo& info); RBViewport(skin_element* node, const RBRenderInfo& info);
virtual ~RBViewport(); virtual ~RBViewport();
@ -66,6 +69,7 @@ public:
alignRight(); alignRight();
alignCenter(); alignCenter();
} }
void scrollText(double time){ scrollTime = time; }
void enableStatusBar(){ showStatusBar = true; } void enableStatusBar(){ showStatusBar = true; }
@ -101,6 +105,8 @@ private:
RBText* leftGraphic; RBText* leftGraphic;
RBText* centerGraphic; RBText* centerGraphic;
RBText* rightGraphic; RBText* rightGraphic;
double scrollTime;
}; };
#endif // RBVIEWPORT_H #endif // RBVIEWPORT_H

View file

@ -29,6 +29,7 @@
#include "rbprogressbar.h" #include "rbprogressbar.h"
#include <iostream> #include <iostream>
#include <cmath>
int ParseTreeNode::openConditionals = 0; int ParseTreeNode::openConditionals = 0;
bool ParseTreeNode::breakFlag = false; bool ParseTreeNode::breakFlag = false;
@ -552,8 +553,16 @@ void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport,
for(int i = 0; i < children.count() ; i++) for(int i = 0; i < children.count() ; i++)
times.append(findBranchTime(children[i], info)); times.append(findBranchTime(children[i], info));
double totalTime = 0;
for(int i = 0; i < children.count(); i++)
totalTime += times[i];
/* Now we figure out which branch to select */ /* Now we figure out which branch to select */
double timeLeft = info.device()->data(QString("simtime")).toDouble(); double timeLeft = info.device()->data(QString("simtime")).toDouble();
/* Skipping any full cycles */
timeLeft -= totalTime * std::floor(timeLeft / totalTime);
int branch = 0; int branch = 0;
while(timeLeft > 0) while(timeLeft > 0)
{ {
@ -654,6 +663,17 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport)
return false; return false;
case 's':
switch(element->tag->name[1])
{
case '\0':
/* %s */
viewport->scrollText(info.device()->data("simtime").toDouble());
return true;
}
return false;
case 'w': case 'w':
switch(element->tag->name[1]) switch(element->tag->name[1])
{ {