2010-06-18 21:10:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Robert Bieber
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPainterPath>
|
2010-08-03 08:42:30 +00:00
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QTransform>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2010-07-07 22:25:42 +00:00
|
|
|
#include <cmath>
|
2010-06-18 21:10:01 +00:00
|
|
|
|
|
|
|
#include "rbviewport.h"
|
|
|
|
#include "rbscreen.h"
|
|
|
|
#include "rbrenderinfo.h"
|
|
|
|
#include "parsetreemodel.h"
|
|
|
|
#include "tag_table.h"
|
|
|
|
#include "skin_parser.h"
|
2010-08-04 09:16:52 +00:00
|
|
|
#include "skindocument.h"
|
2010-06-18 21:10:01 +00:00
|
|
|
|
2010-07-07 22:25:42 +00:00
|
|
|
/* Pixels/second of text scrolling */
|
|
|
|
const double RBViewport::scrollRate = 30;
|
|
|
|
|
2010-08-04 09:16:52 +00:00
|
|
|
RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info,
|
|
|
|
ParseTreeNode* pNode)
|
2010-08-03 22:29:26 +00:00
|
|
|
: RBMovable(info.screen()), foreground(info.screen()->foreground()),
|
2010-06-25 05:14:13 +00:00
|
|
|
background(info.screen()->background()), textOffset(0,0),
|
2010-06-30 21:28:11 +00:00
|
|
|
screen(info.screen()), textAlign(Left), showStatusBar(false),
|
2010-07-07 06:50:30 +00:00
|
|
|
statusBarTexture(":/render/statusbar.png"),
|
2010-08-04 09:16:52 +00:00
|
|
|
leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0),
|
|
|
|
node(pNode), doc(info.document())
|
2010-06-18 21:10:01 +00:00
|
|
|
{
|
2010-08-12 23:05:53 +00:00
|
|
|
mirrored = info.screen()->isRtlMirrored()
|
|
|
|
&& info.device()->data("rtl").toBool();
|
|
|
|
|
2010-06-18 21:10:01 +00:00
|
|
|
if(!node->tag)
|
|
|
|
{
|
|
|
|
/* Default viewport takes up the entire screen */
|
|
|
|
size = QRectF(0, 0, info.screen()->getWidth(),
|
|
|
|
info.screen()->getHeight());
|
2010-06-23 07:18:22 +00:00
|
|
|
customUI = false;
|
2010-07-06 19:19:11 +00:00
|
|
|
font = screen->getFont(1);
|
2010-06-18 21:10:01 +00:00
|
|
|
|
2010-08-09 19:37:23 +00:00
|
|
|
screen->setDefault(this);
|
|
|
|
|
|
|
|
if(screen->getCustomUI())
|
|
|
|
{
|
|
|
|
RBViewport* cui = screen->getCustomUI();
|
|
|
|
size = cui->boundingRect();
|
|
|
|
setPos(cui->pos());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-06 08:01:07 +00:00
|
|
|
/* Making sure the default viewport can't be graphically manipulated */
|
|
|
|
setFlag(ItemIsSelectable, false);
|
|
|
|
setFlag(ItemIsMovable, false);
|
|
|
|
|
2010-06-18 21:10:01 +00:00
|
|
|
if(info.model()->rowCount(QModelIndex()) > 1)
|
|
|
|
{
|
|
|
|
/* If there is more than one viewport in the document */
|
2010-07-11 04:36:05 +00:00
|
|
|
textOffset.setX(-1);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
setVisible(true);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-21 20:11:58 +00:00
|
|
|
QString ident;
|
|
|
|
int x,y,w,h;
|
|
|
|
/* Rendering one of the other types of viewport */
|
2010-06-18 21:10:01 +00:00
|
|
|
switch(node->tag->name[1])
|
|
|
|
{
|
|
|
|
case '\0':
|
2010-06-21 20:11:58 +00:00
|
|
|
customUI = false;
|
2010-08-04 09:16:52 +00:00
|
|
|
baseParam= 0;
|
2010-06-18 21:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
2010-06-21 20:11:58 +00:00
|
|
|
/* A preloaded viewport definition */
|
|
|
|
ident = node->params[0].data.text;
|
|
|
|
customUI = false;
|
2010-06-29 21:09:29 +00:00
|
|
|
if(!screen->viewPortDisplayed(ident))
|
|
|
|
hide();
|
2010-06-21 20:11:58 +00:00
|
|
|
info.screen()->loadViewport(ident, this);
|
2010-08-04 09:16:52 +00:00
|
|
|
baseParam= 1;
|
2010-06-18 21:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
/* Custom UI Viewport */
|
2010-06-21 20:11:58 +00:00
|
|
|
customUI = true;
|
2010-08-04 09:16:52 +00:00
|
|
|
baseParam= 1;
|
2010-06-21 20:11:58 +00:00
|
|
|
if(node->params[0].type == skin_tag_parameter::DEFAULT)
|
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
setVisible(true);
|
2010-06-21 20:11:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-22 07:55:50 +00:00
|
|
|
hide();
|
2010-06-21 20:11:58 +00:00
|
|
|
info.screen()->loadViewport(ident, this);
|
|
|
|
}
|
2010-06-18 21:10:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-21 20:11:58 +00:00
|
|
|
/* Now we grab the info common to all viewports */
|
2010-08-04 09:16:52 +00:00
|
|
|
int param = baseParam;
|
2010-07-15 06:24:11 +00:00
|
|
|
x = node->params[param++].data.number;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(x < 0)
|
|
|
|
x = info.screen()->boundingRect().right() + x;
|
2010-07-15 06:24:11 +00:00
|
|
|
y = node->params[param++].data.number;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(y < 0)
|
|
|
|
y = info.screen()->boundingRect().bottom() + y;
|
2010-06-21 20:11:58 +00:00
|
|
|
|
|
|
|
if(node->params[param].type == skin_tag_parameter::DEFAULT)
|
|
|
|
w = info.screen()->getWidth() - x;
|
|
|
|
else
|
2010-07-15 06:24:11 +00:00
|
|
|
w = node->params[param].data.number;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(w < 0)
|
|
|
|
w = info.screen()->getWidth() + w - x;
|
2010-06-21 20:11:58 +00:00
|
|
|
|
|
|
|
if(node->params[++param].type == skin_tag_parameter::DEFAULT)
|
|
|
|
h = info.screen()->getHeight() - y;
|
|
|
|
else
|
2010-07-15 06:24:11 +00:00
|
|
|
h = node->params[param].data.number;
|
2010-07-01 02:07:41 +00:00
|
|
|
if(h < 0)
|
|
|
|
h = info.screen()->getHeight() + h - y;
|
2010-06-21 20:11:58 +00:00
|
|
|
|
2010-07-03 22:57:42 +00:00
|
|
|
/* Adjusting to screen coordinates if necessary */
|
|
|
|
if(screen->parentItem() != 0)
|
|
|
|
{
|
|
|
|
x -= screen->parentItem()->pos().x();
|
|
|
|
y -= screen->parentItem()->pos().y();
|
|
|
|
}
|
|
|
|
|
2010-08-12 23:05:53 +00:00
|
|
|
/* Mirroring if necessary */
|
|
|
|
if(mirrored)
|
|
|
|
{
|
|
|
|
x = parentItem()->boundingRect().width() - w - x;
|
|
|
|
}
|
|
|
|
|
2010-07-06 19:19:11 +00:00
|
|
|
if(node->params[++param].type == skin_tag_parameter::DEFAULT)
|
|
|
|
font = screen->getFont(1);
|
|
|
|
else
|
2010-07-15 06:24:11 +00:00
|
|
|
font = screen->getFont(node->params[param].data.number);
|
2010-07-03 22:57:42 +00:00
|
|
|
|
2010-06-23 07:23:47 +00:00
|
|
|
setPos(x, y);
|
|
|
|
size = QRectF(0, 0, w, h);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-02 05:58:06 +00:00
|
|
|
debug = info.device()->data("showviewports").toBool();
|
2010-06-30 07:00:05 +00:00
|
|
|
lineHeight = font->lineHeight();
|
2010-07-03 22:57:42 +00:00
|
|
|
if(customUI)
|
|
|
|
screen->setCustomUI(this);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RBViewport::~RBViewport()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath RBViewport::shape() const
|
|
|
|
{
|
|
|
|
QPainterPath retval;
|
|
|
|
retval.addRect(size);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RBViewport::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2010-06-25 05:14:13 +00:00
|
|
|
if(!screen->hasBackdrop() && background != screen->background())
|
|
|
|
{
|
|
|
|
painter->fillRect(size, QBrush(background));
|
|
|
|
}
|
|
|
|
|
2010-06-23 07:18:22 +00:00
|
|
|
painter->setBrush(Qt::NoBrush);
|
|
|
|
painter->setPen(customUI ? Qt::blue : Qt::red);
|
2010-06-26 05:51:07 +00:00
|
|
|
if(debug)
|
|
|
|
painter->drawRect(size);
|
2010-06-30 21:28:11 +00:00
|
|
|
|
|
|
|
if(showStatusBar)
|
|
|
|
painter->fillRect(QRectF(0, 0, size.width(), 8), statusBarTexture);
|
2010-08-03 22:29:26 +00:00
|
|
|
|
|
|
|
RBMovable::paint(painter, option, widget);
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:30:19 +00:00
|
|
|
void RBViewport::newLine()
|
2010-06-22 07:55:50 +00:00
|
|
|
{
|
2010-07-11 04:36:05 +00:00
|
|
|
if(textOffset.x() < 0)
|
|
|
|
return;
|
|
|
|
|
2010-07-07 07:49:00 +00:00
|
|
|
if(leftText != "")
|
|
|
|
alignLeft();
|
|
|
|
|
|
|
|
if(centerText != "")
|
|
|
|
alignCenter();
|
|
|
|
|
|
|
|
if(rightText != "")
|
|
|
|
alignRight();
|
|
|
|
|
2010-07-01 20:30:19 +00:00
|
|
|
textOffset.setY(textOffset.y() + lineHeight);
|
|
|
|
textOffset.setX(0);
|
|
|
|
textAlign = Left;
|
2010-07-07 06:50:30 +00:00
|
|
|
|
2010-07-01 20:30:19 +00:00
|
|
|
leftText.clear();
|
|
|
|
rightText.clear();
|
|
|
|
centerText.clear();
|
2010-07-07 06:50:30 +00:00
|
|
|
|
|
|
|
leftGraphic = 0;
|
|
|
|
centerGraphic = 0;
|
|
|
|
rightGraphic = 0;
|
2010-07-07 22:25:42 +00:00
|
|
|
|
|
|
|
scrollTime = 0;
|
2010-06-25 05:14:13 +00:00
|
|
|
}
|
2010-06-22 07:55:50 +00:00
|
|
|
|
2010-06-25 05:14:13 +00:00
|
|
|
void RBViewport::write(QString text)
|
|
|
|
{
|
2010-07-11 04:36:05 +00:00
|
|
|
if(textOffset.x() < 0)
|
|
|
|
return;
|
|
|
|
|
2010-08-12 23:05:53 +00:00
|
|
|
Alignment align = textAlign;
|
|
|
|
if(mirrored && align == Left)
|
|
|
|
align = Right;
|
|
|
|
else if(mirrored && align == Right)
|
|
|
|
align = Left;
|
|
|
|
|
|
|
|
if(align == Left)
|
2010-06-30 07:00:05 +00:00
|
|
|
{
|
2010-07-07 06:50:30 +00:00
|
|
|
leftText.append(text);
|
2010-06-30 07:00:05 +00:00
|
|
|
}
|
2010-08-12 23:05:53 +00:00
|
|
|
else if(align == Center)
|
2010-06-30 07:00:05 +00:00
|
|
|
{
|
2010-07-07 06:50:30 +00:00
|
|
|
centerText.append(text);
|
2010-06-30 07:00:05 +00:00
|
|
|
}
|
2010-08-12 23:05:53 +00:00
|
|
|
else if(align == Right)
|
2010-06-30 07:00:05 +00:00
|
|
|
{
|
2010-07-07 06:50:30 +00:00
|
|
|
rightText.append(text);
|
2010-06-30 07:00:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 21:49:55 +00:00
|
|
|
void RBViewport::showPlaylist(const RBRenderInfo &info, int start,
|
|
|
|
skin_element *id3, skin_element *noId3)
|
|
|
|
{
|
|
|
|
/* Determining whether ID3 info is available */
|
2010-07-02 05:17:57 +00:00
|
|
|
skin_element* root = id3;
|
2010-07-01 21:49:55 +00:00
|
|
|
|
|
|
|
/* The line will be a linked list */
|
2010-07-02 05:17:57 +00:00
|
|
|
if(root->children_count > 0)
|
|
|
|
root = root->children[0];
|
2010-07-01 21:49:55 +00:00
|
|
|
|
|
|
|
int song = start + info.device()->data("pp").toInt();
|
|
|
|
int numSongs = info.device()->data("pe").toInt();
|
2010-07-02 05:17:57 +00:00
|
|
|
int halfWay = (numSongs - song) / 2 + 1 + song;
|
2010-07-01 21:49:55 +00:00
|
|
|
|
|
|
|
while(song <= numSongs && textOffset.y() + lineHeight < size.height())
|
|
|
|
{
|
2010-07-02 05:17:57 +00:00
|
|
|
if(song == halfWay)
|
|
|
|
{
|
|
|
|
root = noId3;
|
|
|
|
if(root->children_count > 0)
|
|
|
|
root = root->children[0];
|
|
|
|
}
|
2010-07-01 21:49:55 +00:00
|
|
|
skin_element* current = root;
|
|
|
|
while(current)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(current->type == TEXT)
|
|
|
|
{
|
|
|
|
write(QString((char*)current->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(current->type == TAG)
|
|
|
|
{
|
|
|
|
QString tag(current->tag->name);
|
|
|
|
if(tag == "pp")
|
|
|
|
{
|
|
|
|
write(QString::number(song));
|
|
|
|
}
|
|
|
|
else if(tag == "pt")
|
|
|
|
{
|
|
|
|
write(QObject::tr("00:00"));
|
|
|
|
}
|
|
|
|
else if(tag[0] == 'i' || tag[0] == 'f')
|
|
|
|
{
|
|
|
|
if(song == info.device()->data("pp").toInt())
|
|
|
|
{
|
|
|
|
write(info.device()->data(tag).toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If we're not on the current track, use the next
|
|
|
|
* track info
|
|
|
|
*/
|
|
|
|
if(tag[0] == 'i')
|
|
|
|
tag = QString("I") + tag.right(1);
|
|
|
|
else
|
|
|
|
tag = QString("F") + tag.right(1);
|
|
|
|
write(info.device()->data(tag).toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
newLine();
|
|
|
|
song++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-09 19:37:23 +00:00
|
|
|
void RBViewport::makeFullScreen()
|
|
|
|
{
|
|
|
|
size = screen->boundingRect();
|
|
|
|
setPos(screen->pos());
|
|
|
|
}
|
|
|
|
|
2010-08-03 22:29:26 +00:00
|
|
|
void RBViewport::saveGeometry()
|
2010-08-03 08:42:30 +00:00
|
|
|
{
|
2010-08-04 09:16:52 +00:00
|
|
|
QRectF bounds = boundingRect();
|
|
|
|
QPointF origin = pos();
|
2010-08-03 08:42:30 +00:00
|
|
|
|
2010-08-04 09:16:52 +00:00
|
|
|
node->modParam(static_cast<int>(origin.x()), baseParam);
|
|
|
|
node->modParam(static_cast<int>(origin.y()), baseParam + 1);
|
|
|
|
node->modParam(static_cast<int>(bounds.width()), baseParam + 2);
|
|
|
|
node->modParam(static_cast<int>(bounds.height()), baseParam + 3);
|
2010-08-03 08:42:30 +00:00
|
|
|
}
|
|
|
|
|
2010-06-30 07:00:05 +00:00
|
|
|
void RBViewport::alignLeft()
|
|
|
|
{
|
|
|
|
int y = textOffset.y();
|
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
if(leftGraphic)
|
|
|
|
delete leftGraphic;
|
|
|
|
|
|
|
|
leftGraphic = font->renderText(leftText, foreground, size.width(), this);
|
|
|
|
leftGraphic->setPos(0, y);
|
2010-07-07 22:25:42 +00:00
|
|
|
|
|
|
|
/* Setting scroll position if necessary */
|
|
|
|
int difference = leftGraphic->realWidth()
|
|
|
|
- leftGraphic->boundingRect().width();
|
|
|
|
if(difference > 0)
|
|
|
|
{
|
|
|
|
/* Subtracting out complete cycles */
|
2010-07-08 05:30:00 +00:00
|
|
|
double totalTime = 2 * difference / scrollRate;
|
2010-07-07 22:25:42 +00:00
|
|
|
scrollTime -= totalTime * std::floor(scrollTime / totalTime);
|
|
|
|
|
|
|
|
/* Calculating the offset */
|
2010-07-08 05:30:00 +00:00
|
|
|
if(scrollTime < static_cast<double>(difference) / scrollRate)
|
2010-07-07 22:25:42 +00:00
|
|
|
{
|
2010-07-08 05:30:00 +00:00
|
|
|
leftGraphic->setOffset(scrollRate * scrollTime);
|
2010-07-07 22:25:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-08 05:30:00 +00:00
|
|
|
scrollTime -= static_cast<double>(difference) / scrollRate;
|
|
|
|
leftGraphic->setOffset(difference - scrollRate * scrollTime);
|
2010-07-07 22:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-30 07:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RBViewport::alignCenter()
|
|
|
|
{
|
|
|
|
int y = textOffset.y();
|
|
|
|
int x = 0;
|
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
if(centerGraphic)
|
|
|
|
delete centerGraphic;
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
centerGraphic = font->renderText(centerText, foreground, size.width(),
|
|
|
|
this);
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
if(centerGraphic->boundingRect().width() < size.width())
|
|
|
|
{
|
|
|
|
x = size.width() - centerGraphic->boundingRect().width();
|
|
|
|
x /= 2;
|
|
|
|
}
|
|
|
|
else
|
2010-06-30 07:00:05 +00:00
|
|
|
{
|
2010-07-07 06:50:30 +00:00
|
|
|
x = 0;
|
2010-06-30 07:00:05 +00:00
|
|
|
}
|
2010-07-07 06:50:30 +00:00
|
|
|
|
|
|
|
centerGraphic->setPos(x, y);
|
2010-07-07 22:25:42 +00:00
|
|
|
|
|
|
|
/* Setting scroll position if necessary */
|
|
|
|
int difference = centerGraphic->realWidth()
|
|
|
|
- centerGraphic->boundingRect().width();
|
|
|
|
if(difference > 0)
|
|
|
|
{
|
|
|
|
/* Subtracting out complete cycles */
|
2010-07-08 05:30:00 +00:00
|
|
|
double totalTime = 2 * difference / scrollRate;
|
2010-07-07 22:25:42 +00:00
|
|
|
scrollTime -= totalTime * std::floor(scrollTime / totalTime);
|
|
|
|
|
|
|
|
/* Calculating the offset */
|
2010-07-08 05:30:00 +00:00
|
|
|
if(scrollTime < static_cast<double>(difference) / scrollRate)
|
2010-07-07 22:25:42 +00:00
|
|
|
{
|
2010-07-08 05:30:00 +00:00
|
|
|
centerGraphic->setOffset(scrollRate * scrollTime);
|
2010-07-07 22:25:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-08 05:30:00 +00:00
|
|
|
scrollTime -= static_cast<double>(difference) / scrollRate;
|
|
|
|
centerGraphic->setOffset(difference - scrollRate * scrollTime);
|
2010-07-07 22:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
}
|
2010-06-30 07:00:05 +00:00
|
|
|
|
|
|
|
void RBViewport::alignRight()
|
|
|
|
{
|
|
|
|
int y = textOffset.y();
|
|
|
|
int x = 0;
|
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
if(rightGraphic)
|
|
|
|
delete rightGraphic;
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
rightGraphic = font->renderText(rightText, foreground, size.width(), this);
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
if(rightGraphic->boundingRect().width() < size.width())
|
|
|
|
x = size.width() - rightGraphic->boundingRect().width();
|
|
|
|
else
|
|
|
|
x = 0;
|
2010-06-30 07:00:05 +00:00
|
|
|
|
2010-07-07 06:50:30 +00:00
|
|
|
rightGraphic->setPos(x, y);
|
2010-07-07 22:25:42 +00:00
|
|
|
|
|
|
|
/* Setting scroll position if necessary */
|
|
|
|
int difference = rightGraphic->realWidth()
|
|
|
|
- rightGraphic->boundingRect().width();
|
|
|
|
if(difference > 0)
|
|
|
|
{
|
|
|
|
/* Subtracting out complete cycles */
|
2010-07-08 05:30:00 +00:00
|
|
|
double totalTime = 2 * difference / scrollRate;
|
2010-07-07 22:25:42 +00:00
|
|
|
scrollTime -= totalTime * std::floor(scrollTime / totalTime);
|
|
|
|
|
|
|
|
/* Calculating the offset */
|
2010-07-08 05:30:00 +00:00
|
|
|
if(scrollTime < static_cast<double>(difference) / scrollRate)
|
2010-07-07 22:25:42 +00:00
|
|
|
{
|
2010-07-08 05:30:00 +00:00
|
|
|
rightGraphic->setOffset(scrollRate * scrollTime);
|
2010-07-07 22:25:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-08 05:30:00 +00:00
|
|
|
scrollTime -= static_cast<double>(difference) / scrollRate;
|
|
|
|
rightGraphic->setOffset(difference - scrollRate * scrollTime);
|
2010-07-07 22:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-30 07:00:05 +00:00
|
|
|
}
|
|
|
|
|