A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

Theme Editor: Implemented line scrolling

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27344 a1c6a512-1295-4272-9138-f99709370657

+126 -3
+7 -2
utils/themeeditor/graphics/rbtext.cpp
··· 24 24 #include <QPainter> 25 25 26 26 RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent) 27 - :QGraphicsItem(parent), image(image), maxWidth(maxWidth) 27 + :QGraphicsItem(parent), image(image), maxWidth(maxWidth), offset(0) 28 28 { 29 29 } 30 30 ··· 39 39 void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 40 40 QWidget *widget) 41 41 { 42 + /* Making sure the offset is within bounds */ 43 + if(image->width() > maxWidth) 44 + if(offset > image->width() - maxWidth) 45 + offset = image->width() - maxWidth; 46 + 42 47 if(image->width() < maxWidth) 43 48 painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height()); 44 49 else 45 - painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height()); 50 + painter->drawImage(0, 0, *image, offset, 0, maxWidth, image->height()); 46 51 }
+4
utils/themeeditor/graphics/rbtext.h
··· 34 34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 35 35 QWidget *widget); 36 36 37 + int realWidth(){ return image->width(); } 38 + void setOffset(int offset){ this->offset = offset; } 39 + 37 40 private: 38 41 QImage* image; 39 42 int maxWidth; 43 + int offset; 40 44 41 45 }; 42 46
+89 -1
utils/themeeditor/graphics/rbviewport.cpp
··· 21 21 22 22 #include <QPainter> 23 23 #include <QPainterPath> 24 + #include <cmath> 24 25 25 26 #include "rbviewport.h" 26 27 #include "rbscreen.h" ··· 29 30 #include "tag_table.h" 30 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 38 RBViewport::RBViewport(skin_element* node, const RBRenderInfo& info) 33 39 : QGraphicsItem(info.screen()), foreground(info.screen()->foreground()), 34 40 background(info.screen()->background()), textOffset(0,0), 35 41 screen(info.screen()), textAlign(Left), showStatusBar(false), 36 42 statusBarTexture(":/render/statusbar.png"), 37 - leftGraphic(0), centerGraphic(0), rightGraphic(0) 43 + leftGraphic(0), centerGraphic(0), rightGraphic(0), scrollTime(0) 38 44 { 39 45 if(!node->tag) 40 46 { ··· 191 197 leftGraphic = 0; 192 198 centerGraphic = 0; 193 199 rightGraphic = 0; 200 + 201 + scrollTime = 0; 194 202 } 195 203 196 204 void RBViewport::write(QString text) ··· 287 295 288 296 leftGraphic = font->renderText(leftText, foreground, size.width(), this); 289 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 326 void RBViewport::alignCenter() ··· 311 345 } 312 346 313 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 377 void RBViewport::alignRight() ··· 329 390 x = 0; 330 391 331 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
+6
utils/themeeditor/graphics/rbviewport.h
··· 40 40 Right 41 41 }; 42 42 43 + static const double scrollRate; 44 + static const double scrollPause; 45 + 43 46 RBViewport(skin_element* node, const RBRenderInfo& info); 44 47 virtual ~RBViewport(); 45 48 ··· 66 69 alignRight(); 67 70 alignCenter(); 68 71 } 72 + void scrollText(double time){ scrollTime = time; } 69 73 70 74 void enableStatusBar(){ showStatusBar = true; } 71 75 ··· 101 105 RBText* leftGraphic; 102 106 RBText* centerGraphic; 103 107 RBText* rightGraphic; 108 + 109 + double scrollTime; 104 110 }; 105 111 106 112 #endif // RBVIEWPORT_H
+20
utils/themeeditor/models/parsetreenode.cpp
··· 29 29 #include "rbprogressbar.h" 30 30 31 31 #include <iostream> 32 + #include <cmath> 32 33 33 34 int ParseTreeNode::openConditionals = 0; 34 35 bool ParseTreeNode::breakFlag = false; ··· 552 553 for(int i = 0; i < children.count() ; i++) 553 554 times.append(findBranchTime(children[i], info)); 554 555 556 + double totalTime = 0; 557 + for(int i = 0; i < children.count(); i++) 558 + totalTime += times[i]; 559 + 555 560 /* Now we figure out which branch to select */ 556 561 double timeLeft = info.device()->data(QString("simtime")).toDouble(); 562 + 563 + /* Skipping any full cycles */ 564 + timeLeft -= totalTime * std::floor(timeLeft / totalTime); 565 + 557 566 int branch = 0; 558 567 while(timeLeft > 0) 559 568 { ··· 649 658 /* %pb */ 650 659 new RBProgressBar(viewport, info, element->params_count, 651 660 element->params); 661 + return true; 662 + } 663 + 664 + return false; 665 + 666 + case 's': 667 + switch(element->tag->name[1]) 668 + { 669 + case '\0': 670 + /* %s */ 671 + viewport->scrollText(info.device()->data("simtime").toDouble()); 652 672 return true; 653 673 } 654 674