Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2010 Robert Bieber |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include <QPainter> |
| 23 | #include <QPainterPath> |
Robert Bieber | a83adc7 | 2010-08-03 08:42:30 +0000 | [diff] [blame] | 24 | #include <QGraphicsSceneMouseEvent> |
| 25 | #include <QTransform> |
| 26 | |
| 27 | #include <QDebug> |
| 28 | |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 29 | #include <cmath> |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 30 | |
| 31 | #include "rbviewport.h" |
| 32 | #include "rbscreen.h" |
| 33 | #include "rbrenderinfo.h" |
| 34 | #include "parsetreemodel.h" |
| 35 | #include "tag_table.h" |
| 36 | #include "skin_parser.h" |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 37 | #include "skindocument.h" |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 38 | |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 39 | /* Pixels/second of text scrolling */ |
| 40 | const double RBViewport::scrollRate = 30; |
| 41 | |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 42 | RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info, |
| 43 | ParseTreeNode* pNode) |
Robert Bieber | 83c60a1 | 2010-08-03 22:29:26 +0000 | [diff] [blame] | 44 | : RBMovable(info.screen()), foreground(info.screen()->foreground()), |
Robert Bieber | 273b9d6 | 2010-06-25 05:14:13 +0000 | [diff] [blame] | 45 | background(info.screen()->background()), textOffset(0,0), |
Robert Bieber | 35150b6 | 2010-06-30 21:28:11 +0000 | [diff] [blame] | 46 | screen(info.screen()), textAlign(Left), showStatusBar(false), |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 47 | statusBarTexture(":/render/statusbar.png"), |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 48 | leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0), |
| 49 | node(pNode), doc(info.document()) |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 50 | { |
Robert Bieber | 1ee2cdd | 2010-08-12 23:05:53 +0000 | [diff] [blame] | 51 | |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 52 | if(!node->tag) |
| 53 | { |
| 54 | /* Default viewport takes up the entire screen */ |
| 55 | size = QRectF(0, 0, info.screen()->getWidth(), |
| 56 | info.screen()->getHeight()); |
Robert Bieber | d302705 | 2010-06-23 07:18:22 +0000 | [diff] [blame] | 57 | customUI = false; |
Robert Bieber | 39e2520 | 2010-07-06 19:19:11 +0000 | [diff] [blame] | 58 | font = screen->getFont(1); |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 59 | |
Robert Bieber | d1a392a | 2010-08-09 19:37:23 +0000 | [diff] [blame] | 60 | screen->setDefault(this); |
| 61 | |
| 62 | if(screen->getCustomUI()) |
| 63 | { |
| 64 | RBViewport* cui = screen->getCustomUI(); |
| 65 | size = cui->boundingRect(); |
| 66 | setPos(cui->pos()); |
| 67 | |
| 68 | } |
| 69 | |
Robert Bieber | 87d2590 | 2010-08-06 08:01:07 +0000 | [diff] [blame] | 70 | /* Making sure the default viewport can't be graphically manipulated */ |
| 71 | setFlag(ItemIsSelectable, false); |
| 72 | setFlag(ItemIsMovable, false); |
| 73 | |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 74 | if(info.model()->rowCount(QModelIndex()) > 1) |
| 75 | { |
| 76 | /* If there is more than one viewport in the document */ |
Robert Bieber | 364af4f | 2010-07-11 04:36:05 +0000 | [diff] [blame] | 77 | textOffset.setX(-1); |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 78 | } |
| 79 | else |
| 80 | { |
Robert Bieber | ac9287b | 2010-06-22 07:55:50 +0000 | [diff] [blame] | 81 | setVisible(true); |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | else |
| 85 | { |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 86 | QString ident; |
| 87 | int x,y,w,h; |
| 88 | /* Rendering one of the other types of viewport */ |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 89 | switch(node->tag->name[1]) |
| 90 | { |
| 91 | case '\0': |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 92 | customUI = false; |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 93 | baseParam= 0; |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 94 | break; |
| 95 | |
| 96 | case 'l': |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 97 | /* A preloaded viewport definition */ |
| 98 | ident = node->params[0].data.text; |
| 99 | customUI = false; |
Robert Bieber | 1fbea62 | 2010-06-29 21:09:29 +0000 | [diff] [blame] | 100 | if(!screen->viewPortDisplayed(ident)) |
| 101 | hide(); |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 102 | info.screen()->loadViewport(ident, this); |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 103 | baseParam= 1; |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 104 | break; |
| 105 | |
| 106 | case 'i': |
| 107 | /* Custom UI Viewport */ |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 108 | customUI = true; |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 109 | baseParam= 1; |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 110 | if(node->params[0].type == skin_tag_parameter::DEFAULT) |
| 111 | { |
Robert Bieber | ac9287b | 2010-06-22 07:55:50 +0000 | [diff] [blame] | 112 | setVisible(true); |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 113 | } |
| 114 | else |
| 115 | { |
Robert Bieber | ac9287b | 2010-06-22 07:55:50 +0000 | [diff] [blame] | 116 | hide(); |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 117 | info.screen()->loadViewport(ident, this); |
| 118 | } |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 119 | break; |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 120 | } |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 121 | /* Now we grab the info common to all viewports */ |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 122 | int param = baseParam; |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 123 | x = node->params[param++].data.number; |
Robert Bieber | 8cd51a7 | 2010-07-01 02:07:41 +0000 | [diff] [blame] | 124 | if(x < 0) |
| 125 | x = info.screen()->boundingRect().right() + x; |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 126 | y = node->params[param++].data.number; |
Robert Bieber | 8cd51a7 | 2010-07-01 02:07:41 +0000 | [diff] [blame] | 127 | if(y < 0) |
| 128 | y = info.screen()->boundingRect().bottom() + y; |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 129 | |
| 130 | if(node->params[param].type == skin_tag_parameter::DEFAULT) |
| 131 | w = info.screen()->getWidth() - x; |
| 132 | else |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 133 | w = node->params[param].data.number; |
Robert Bieber | 8cd51a7 | 2010-07-01 02:07:41 +0000 | [diff] [blame] | 134 | if(w < 0) |
| 135 | w = info.screen()->getWidth() + w - x; |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 136 | |
| 137 | if(node->params[++param].type == skin_tag_parameter::DEFAULT) |
| 138 | h = info.screen()->getHeight() - y; |
| 139 | else |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 140 | h = node->params[param].data.number; |
Robert Bieber | 8cd51a7 | 2010-07-01 02:07:41 +0000 | [diff] [blame] | 141 | if(h < 0) |
| 142 | h = info.screen()->getHeight() + h - y; |
Robert Bieber | e1d8a3d | 2010-06-21 20:11:58 +0000 | [diff] [blame] | 143 | |
Robert Bieber | 2f68e5b | 2010-07-03 22:57:42 +0000 | [diff] [blame] | 144 | /* Adjusting to screen coordinates if necessary */ |
| 145 | if(screen->parentItem() != 0) |
| 146 | { |
| 147 | x -= screen->parentItem()->pos().x(); |
| 148 | y -= screen->parentItem()->pos().y(); |
| 149 | } |
| 150 | |
Robert Bieber | 39e2520 | 2010-07-06 19:19:11 +0000 | [diff] [blame] | 151 | if(node->params[++param].type == skin_tag_parameter::DEFAULT) |
| 152 | font = screen->getFont(1); |
| 153 | else |
Robert Bieber | 15488a0 | 2010-07-15 06:24:11 +0000 | [diff] [blame] | 154 | font = screen->getFont(node->params[param].data.number); |
Robert Bieber | 2f68e5b | 2010-07-03 22:57:42 +0000 | [diff] [blame] | 155 | |
Robert Bieber | f4fd16c | 2010-06-23 07:23:47 +0000 | [diff] [blame] | 156 | setPos(x, y); |
| 157 | size = QRectF(0, 0, w, h); |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 158 | } |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 159 | |
Robert Bieber | 9d68516 | 2010-07-02 05:58:06 +0000 | [diff] [blame] | 160 | debug = info.device()->data("showviewports").toBool(); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 161 | lineHeight = font->lineHeight(); |
Robert Bieber | b477463 | 2010-08-13 02:05:38 +0000 | [diff] [blame] | 162 | |
| 163 | if(info.screen()->isRtlMirrored() && info.device()->data("rtl").toBool()) |
| 164 | { |
| 165 | /* Mirroring the viewport */ |
| 166 | double x = screen->boundingRect().width() - 2 * pos().x(); |
| 167 | QTransform t; |
| 168 | t.translate(x, 0); |
| 169 | t.scale(-1, 1); |
| 170 | setTransform(t); |
| 171 | } |
| 172 | |
Robert Bieber | 2f68e5b | 2010-07-03 22:57:42 +0000 | [diff] [blame] | 173 | if(customUI) |
| 174 | screen->setCustomUI(this); |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | RBViewport::~RBViewport() |
| 178 | { |
| 179 | } |
| 180 | |
| 181 | QPainterPath RBViewport::shape() const |
| 182 | { |
| 183 | QPainterPath retval; |
| 184 | retval.addRect(size); |
| 185 | return retval; |
| 186 | } |
| 187 | |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 188 | void RBViewport::paint(QPainter *painter, |
| 189 | const QStyleOptionGraphicsItem *option, QWidget *widget) |
| 190 | { |
Robert Bieber | 273b9d6 | 2010-06-25 05:14:13 +0000 | [diff] [blame] | 191 | if(!screen->hasBackdrop() && background != screen->background()) |
| 192 | { |
| 193 | painter->fillRect(size, QBrush(background)); |
| 194 | } |
| 195 | |
Robert Bieber | d302705 | 2010-06-23 07:18:22 +0000 | [diff] [blame] | 196 | painter->setBrush(Qt::NoBrush); |
| 197 | painter->setPen(customUI ? Qt::blue : Qt::red); |
Robert Bieber | 5300c70 | 2010-06-26 05:51:07 +0000 | [diff] [blame] | 198 | if(debug) |
| 199 | painter->drawRect(size); |
Robert Bieber | 35150b6 | 2010-06-30 21:28:11 +0000 | [diff] [blame] | 200 | |
| 201 | if(showStatusBar) |
| 202 | painter->fillRect(QRectF(0, 0, size.width(), 8), statusBarTexture); |
Robert Bieber | 83c60a1 | 2010-08-03 22:29:26 +0000 | [diff] [blame] | 203 | |
| 204 | RBMovable::paint(painter, option, widget); |
Robert Bieber | d8827b5 | 2010-06-18 21:10:01 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Robert Bieber | a54bfaa | 2010-07-01 20:30:19 +0000 | [diff] [blame] | 207 | void RBViewport::newLine() |
Robert Bieber | ac9287b | 2010-06-22 07:55:50 +0000 | [diff] [blame] | 208 | { |
Robert Bieber | 364af4f | 2010-07-11 04:36:05 +0000 | [diff] [blame] | 209 | if(textOffset.x() < 0) |
| 210 | return; |
| 211 | |
Robert Bieber | 8814565 | 2010-07-07 07:49:00 +0000 | [diff] [blame] | 212 | if(leftText != "") |
| 213 | alignLeft(); |
| 214 | |
| 215 | if(centerText != "") |
| 216 | alignCenter(); |
| 217 | |
| 218 | if(rightText != "") |
| 219 | alignRight(); |
| 220 | |
Robert Bieber | a54bfaa | 2010-07-01 20:30:19 +0000 | [diff] [blame] | 221 | textOffset.setY(textOffset.y() + lineHeight); |
| 222 | textOffset.setX(0); |
| 223 | textAlign = Left; |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 224 | |
Robert Bieber | a54bfaa | 2010-07-01 20:30:19 +0000 | [diff] [blame] | 225 | leftText.clear(); |
| 226 | rightText.clear(); |
| 227 | centerText.clear(); |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 228 | |
| 229 | leftGraphic = 0; |
| 230 | centerGraphic = 0; |
| 231 | rightGraphic = 0; |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 232 | |
| 233 | scrollTime = 0; |
Robert Bieber | 273b9d6 | 2010-06-25 05:14:13 +0000 | [diff] [blame] | 234 | } |
Robert Bieber | ac9287b | 2010-06-22 07:55:50 +0000 | [diff] [blame] | 235 | |
Robert Bieber | 273b9d6 | 2010-06-25 05:14:13 +0000 | [diff] [blame] | 236 | void RBViewport::write(QString text) |
| 237 | { |
Robert Bieber | 364af4f | 2010-07-11 04:36:05 +0000 | [diff] [blame] | 238 | if(textOffset.x() < 0) |
| 239 | return; |
| 240 | |
Robert Bieber | 1ee2cdd | 2010-08-12 23:05:53 +0000 | [diff] [blame] | 241 | Alignment align = textAlign; |
Robert Bieber | 1ee2cdd | 2010-08-12 23:05:53 +0000 | [diff] [blame] | 242 | |
| 243 | if(align == Left) |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 244 | { |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 245 | leftText.append(text); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 246 | } |
Robert Bieber | 1ee2cdd | 2010-08-12 23:05:53 +0000 | [diff] [blame] | 247 | else if(align == Center) |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 248 | { |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 249 | centerText.append(text); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 250 | } |
Robert Bieber | 1ee2cdd | 2010-08-12 23:05:53 +0000 | [diff] [blame] | 251 | else if(align == Right) |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 252 | { |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 253 | rightText.append(text); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 254 | } |
Robert Bieber | ac9287b | 2010-06-22 07:55:50 +0000 | [diff] [blame] | 255 | } |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 256 | |
Robert Bieber | 26a2f81 | 2010-07-01 21:49:55 +0000 | [diff] [blame] | 257 | void RBViewport::showPlaylist(const RBRenderInfo &info, int start, |
Robert Bieber | b413169 | 2010-08-15 02:04:06 +0000 | [diff] [blame] | 258 | ParseTreeNode* lines) |
Robert Bieber | 26a2f81 | 2010-07-01 21:49:55 +0000 | [diff] [blame] | 259 | { |
Robert Bieber | 26a2f81 | 2010-07-01 21:49:55 +0000 | [diff] [blame] | 260 | |
| 261 | int song = start + info.device()->data("pp").toInt(); |
| 262 | int numSongs = info.device()->data("pe").toInt(); |
| 263 | |
| 264 | while(song <= numSongs && textOffset.y() + lineHeight < size.height()) |
| 265 | { |
Robert Bieber | b413169 | 2010-08-15 02:04:06 +0000 | [diff] [blame] | 266 | lines->render(info, this); |
Robert Bieber | 26a2f81 | 2010-07-01 21:49:55 +0000 | [diff] [blame] | 267 | newLine(); |
| 268 | song++; |
| 269 | } |
| 270 | } |
| 271 | |
Robert Bieber | d1a392a | 2010-08-09 19:37:23 +0000 | [diff] [blame] | 272 | void RBViewport::makeFullScreen() |
| 273 | { |
| 274 | size = screen->boundingRect(); |
| 275 | setPos(screen->pos()); |
| 276 | } |
| 277 | |
Robert Bieber | 83c60a1 | 2010-08-03 22:29:26 +0000 | [diff] [blame] | 278 | void RBViewport::saveGeometry() |
Robert Bieber | a83adc7 | 2010-08-03 08:42:30 +0000 | [diff] [blame] | 279 | { |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 280 | QRectF bounds = boundingRect(); |
| 281 | QPointF origin = pos(); |
Robert Bieber | a83adc7 | 2010-08-03 08:42:30 +0000 | [diff] [blame] | 282 | |
Robert Bieber | 49865b2 | 2010-08-04 09:16:52 +0000 | [diff] [blame] | 283 | node->modParam(static_cast<int>(origin.x()), baseParam); |
| 284 | node->modParam(static_cast<int>(origin.y()), baseParam + 1); |
| 285 | node->modParam(static_cast<int>(bounds.width()), baseParam + 2); |
| 286 | node->modParam(static_cast<int>(bounds.height()), baseParam + 3); |
Robert Bieber | a83adc7 | 2010-08-03 08:42:30 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 289 | void RBViewport::alignLeft() |
| 290 | { |
| 291 | int y = textOffset.y(); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 292 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 293 | if(leftGraphic) |
| 294 | delete leftGraphic; |
| 295 | |
| 296 | leftGraphic = font->renderText(leftText, foreground, size.width(), this); |
| 297 | leftGraphic->setPos(0, y); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 298 | |
| 299 | /* Setting scroll position if necessary */ |
| 300 | int difference = leftGraphic->realWidth() |
| 301 | - leftGraphic->boundingRect().width(); |
| 302 | if(difference > 0) |
| 303 | { |
| 304 | /* Subtracting out complete cycles */ |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 305 | double totalTime = 2 * difference / scrollRate; |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 306 | scrollTime -= totalTime * std::floor(scrollTime / totalTime); |
| 307 | |
| 308 | /* Calculating the offset */ |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 309 | if(scrollTime < static_cast<double>(difference) / scrollRate) |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 310 | { |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 311 | leftGraphic->setOffset(scrollRate * scrollTime); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 312 | } |
| 313 | else |
| 314 | { |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 315 | scrollTime -= static_cast<double>(difference) / scrollRate; |
| 316 | leftGraphic->setOffset(difference - scrollRate * scrollTime); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void RBViewport::alignCenter() |
| 322 | { |
| 323 | int y = textOffset.y(); |
| 324 | int x = 0; |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 325 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 326 | if(centerGraphic) |
| 327 | delete centerGraphic; |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 328 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 329 | centerGraphic = font->renderText(centerText, foreground, size.width(), |
| 330 | this); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 331 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 332 | if(centerGraphic->boundingRect().width() < size.width()) |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 333 | { |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 334 | x = size.width() - centerGraphic->boundingRect().width(); |
| 335 | x /= 2; |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 336 | } |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 337 | else |
| 338 | { |
| 339 | x = 0; |
| 340 | } |
| 341 | |
| 342 | centerGraphic->setPos(x, y); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 343 | |
| 344 | /* Setting scroll position if necessary */ |
| 345 | int difference = centerGraphic->realWidth() |
| 346 | - centerGraphic->boundingRect().width(); |
| 347 | if(difference > 0) |
| 348 | { |
| 349 | /* Subtracting out complete cycles */ |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 350 | double totalTime = 2 * difference / scrollRate; |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 351 | scrollTime -= totalTime * std::floor(scrollTime / totalTime); |
| 352 | |
| 353 | /* Calculating the offset */ |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 354 | if(scrollTime < static_cast<double>(difference) / scrollRate) |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 355 | { |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 356 | centerGraphic->setOffset(scrollRate * scrollTime); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 357 | } |
| 358 | else |
| 359 | { |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 360 | scrollTime -= static_cast<double>(difference) / scrollRate; |
| 361 | centerGraphic->setOffset(difference - scrollRate * scrollTime); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void RBViewport::alignRight() |
| 368 | { |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 369 | int y = textOffset.y(); |
| 370 | int x = 0; |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 371 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 372 | if(rightGraphic) |
| 373 | delete rightGraphic; |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 374 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 375 | rightGraphic = font->renderText(rightText, foreground, size.width(), this); |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 376 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 377 | if(rightGraphic->boundingRect().width() < size.width()) |
| 378 | x = size.width() - rightGraphic->boundingRect().width(); |
| 379 | else |
| 380 | x = 0; |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 381 | |
Robert Bieber | 3214e37 | 2010-07-07 06:50:30 +0000 | [diff] [blame] | 382 | rightGraphic->setPos(x, y); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 383 | |
| 384 | /* Setting scroll position if necessary */ |
| 385 | int difference = rightGraphic->realWidth() |
| 386 | - rightGraphic->boundingRect().width(); |
| 387 | if(difference > 0) |
| 388 | { |
| 389 | /* Subtracting out complete cycles */ |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 390 | double totalTime = 2 * difference / scrollRate; |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 391 | scrollTime -= totalTime * std::floor(scrollTime / totalTime); |
| 392 | |
| 393 | /* Calculating the offset */ |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 394 | if(scrollTime < static_cast<double>(difference) / scrollRate) |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 395 | { |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 396 | rightGraphic->setOffset(scrollRate * scrollTime); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 397 | } |
| 398 | else |
| 399 | { |
Robert Bieber | eb93e3b | 2010-07-08 05:30:00 +0000 | [diff] [blame] | 400 | scrollTime -= static_cast<double>(difference) / scrollRate; |
| 401 | rightGraphic->setOffset(difference - scrollRate * scrollTime); |
Robert Bieber | 13e97cd | 2010-07-07 22:25:42 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
Robert Bieber | d2ed594 | 2010-06-30 07:00:05 +0000 | [diff] [blame] | 404 | } |
| 405 | |