diff options
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 18029a57f6..3a239c7f35 100644 --- a/utils/themeeditor/graphics/rbviewport.cpp +++ b/utils/themeeditor/graphics/rbviewport.cpp | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <QPainter> | 22 | #include <QPainter> |
23 | #include <QPainterPath> | 23 | #include <QPainterPath> |
24 | #include <cmath> | ||
24 | 25 | ||
25 | #include "rbviewport.h" | 26 | #include "rbviewport.h" |
26 | #include "rbscreen.h" | 27 | #include "rbscreen.h" |
@@ -29,12 +30,17 @@ | |||
29 | #include "tag_table.h" | 30 | #include "tag_table.h" |
30 | #include "skin_parser.h" | 31 | #include "skin_parser.h" |
31 | 32 | ||
33 | /* Pause at beginning/end of scroll */ | ||
34 | const double RBViewport::scrollPause = 0.5; | ||
35 | /* Pixels/second of text scrolling */ | ||
36 | const double RBViewport::scrollRate = 30; | ||
37 | |||
32 | RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) | 38 | RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) |
33 | : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), | 39 | : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), |
34 | background(info.screen()->background()), textOffset(0,0), | 40 | background(info.screen()->background()), textOffset(0,0), |
35 | screen(info.screen()), textAlign(Left), showStatusBar(false), | 41 | screen(info.screen()), textAlign(Left), showStatusBar(false), |
36 | statusBarTexture(":/render/statusbar.png"), | 42 | statusBarTexture(":/render/statusbar.png"), |
37 | leftGraphic(0), centerGraphic(0), rightGraphic(0) | 43 | leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0) |
38 | { | 44 | { |
39 | if(!node->tag) | 45 | if(!node->tag) |
40 | { | 46 | { |
@@ -191,6 +197,8 @@ void RBViewport::newLine() | |||
191 | leftGraphic = 0; | 197 | leftGraphic = 0; |
192 | centerGraphic = 0; | 198 | centerGraphic = 0; |
193 | rightGraphic = 0; | 199 | rightGraphic = 0; |
200 | |||
201 | scrollTime = 0; | ||
194 | } | 202 | } |
195 | 203 | ||
196 | void RBViewport::write(QString text) | 204 | void RBViewport::write(QString text) |
@@ -287,6 +295,32 @@ void RBViewport::alignLeft() | |||
287 | 295 | ||
288 | leftGraphic = font->renderText(leftText, foreground, size.width(), this); | 296 | leftGraphic = font->renderText(leftText, foreground, size.width(), this); |
289 | leftGraphic->setPos(0, y); | 297 | leftGraphic->setPos(0, y); |
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 */ | ||
305 | double totalTime = 2 * scrollPause + difference / scrollRate; | ||
306 | scrollTime -= totalTime * std::floor(scrollTime / totalTime); | ||
307 | |||
308 | /* Calculating the offset */ | ||
309 | if(scrollTime < scrollPause) | ||
310 | { | ||
311 | return; | ||
312 | } | ||
313 | else if(scrollTime < scrollPause + difference / scrollRate) | ||
314 | { | ||
315 | scrollTime -= scrollPause; | ||
316 | int offset = scrollRate * scrollTime; | ||
317 | leftGraphic->setOffset(offset); | ||
318 | } | ||
319 | else | ||
320 | { | ||
321 | leftGraphic->setOffset(difference); | ||
322 | } | ||
323 | } | ||
290 | } | 324 | } |
291 | 325 | ||
292 | void RBViewport::alignCenter() | 326 | void RBViewport::alignCenter() |
@@ -311,6 +345,33 @@ void RBViewport::alignCenter() | |||
311 | } | 345 | } |
312 | 346 | ||
313 | centerGraphic->setPos(x, y); | 347 | centerGraphic->setPos(x, y); |
348 | |||
349 | /* Setting scroll position if necessary */ | ||
350 | int difference = centerGraphic->realWidth() | ||
351 | - centerGraphic->boundingRect().width(); | ||
352 | if(difference > 0) | ||
353 | { | ||
354 | /* Subtracting out complete cycles */ | ||
355 | double totalTime = 2 * scrollPause + difference / scrollRate; | ||
356 | scrollTime -= totalTime * std::floor(scrollTime / totalTime); | ||
357 | |||
358 | /* Calculating the offset */ | ||
359 | if(scrollTime < scrollPause) | ||
360 | { | ||
361 | return; | ||
362 | } | ||
363 | else if(scrollTime < scrollPause + difference / scrollRate) | ||
364 | { | ||
365 | scrollTime -= scrollPause; | ||
366 | int offset = scrollRate * scrollTime; | ||
367 | centerGraphic->setOffset(offset); | ||
368 | } | ||
369 | else | ||
370 | { | ||
371 | centerGraphic->setOffset(difference); | ||
372 | } | ||
373 | } | ||
374 | |||
314 | } | 375 | } |
315 | 376 | ||
316 | void RBViewport::alignRight() | 377 | void RBViewport::alignRight() |
@@ -329,5 +390,32 @@ void RBViewport::alignRight() | |||
329 | x = 0; | 390 | x = 0; |
330 | 391 | ||
331 | rightGraphic->setPos(x, y); | 392 | rightGraphic->setPos(x, y); |
393 | |||
394 | /* Setting scroll position if necessary */ | ||
395 | int difference = rightGraphic->realWidth() | ||
396 | - rightGraphic->boundingRect().width(); | ||
397 | if(difference > 0) | ||
398 | { | ||
399 | /* Subtracting out complete cycles */ | ||
400 | double totalTime = 2 * scrollPause + difference / scrollRate; | ||
401 | scrollTime -= totalTime * std::floor(scrollTime / totalTime); | ||
402 | |||
403 | /* Calculating the offset */ | ||
404 | if(scrollTime < scrollPause) | ||
405 | { | ||
406 | return; | ||
407 | } | ||
408 | else if(scrollTime < scrollPause + difference / scrollRate) | ||
409 | { | ||
410 | scrollTime -= scrollPause; | ||
411 | int offset = scrollRate * scrollTime; | ||
412 | rightGraphic->setOffset(offset); | ||
413 | } | ||
414 | else | ||
415 | { | ||
416 | rightGraphic->setOffset(difference); | ||
417 | } | ||
418 | } | ||
419 | |||
332 | } | 420 | } |
333 | 421 | ||