diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-06-29 07:15:41 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-29 07:15:41 +0000 |
commit | 3313ab8bb15867c61da035995396d8575f5eca16 (patch) | |
tree | 3239fce3f616ebceb25cb25168274b79cdc2c287 | |
parent | 449a895372354f8c9abeec28a147f6b88d53a269 (diff) | |
download | rockbox-3313ab8bb15867c61da035995396d8575f5eca16.tar.gz rockbox-3313ab8bb15867c61da035995396d8575f5eca16.zip |
Theme Editor: Implemented conditional rendering, most conditionals should work correctly now
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27169 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/themeeditor/graphics/rbimage.cpp | 14 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbimage.h | 1 | ||||
-rw-r--r-- | utils/themeeditor/models/parsetreenode.cpp | 78 |
3 files changed, 89 insertions, 4 deletions
diff --git a/utils/themeeditor/graphics/rbimage.cpp b/utils/themeeditor/graphics/rbimage.cpp index f15d1ed2aa..ce92d2fcde 100644 --- a/utils/themeeditor/graphics/rbimage.cpp +++ b/utils/themeeditor/graphics/rbimage.cpp | |||
@@ -49,7 +49,21 @@ RBImage::RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent) | |||
49 | 49 | ||
50 | } | 50 | } |
51 | else | 51 | else |
52 | { | ||
53 | size = QRectF(0, 0, 0, 0); | ||
54 | image = 0; | ||
55 | } | ||
56 | } | ||
57 | |||
58 | RBImage::RBImage(const RBImage &other, QGraphicsItem* parent) | ||
59 | : QGraphicsItem(parent), tiles(other.tiles), currentTile(other.currentTile) | ||
60 | { | ||
61 | if(other.image) | ||
62 | image = new QPixmap(*(other.image)); | ||
63 | else | ||
52 | image = 0; | 64 | image = 0; |
65 | size = other.size; | ||
66 | setPos(other.x(), other.y()); | ||
53 | } | 67 | } |
54 | 68 | ||
55 | RBImage::~RBImage() | 69 | RBImage::~RBImage() |
diff --git a/utils/themeeditor/graphics/rbimage.h b/utils/themeeditor/graphics/rbimage.h index cc949d1de1..abfe8eb052 100644 --- a/utils/themeeditor/graphics/rbimage.h +++ b/utils/themeeditor/graphics/rbimage.h | |||
@@ -29,6 +29,7 @@ class RBImage: public QGraphicsItem | |||
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0); | 31 | RBImage(QString file, int tiles, int x, int y, QGraphicsItem* parent = 0); |
32 | RBImage(const RBImage& other, QGraphicsItem* parent); | ||
32 | virtual ~RBImage(); | 33 | virtual ~RBImage(); |
33 | 34 | ||
34 | QRectF boundingRect() const; | 35 | QRectF boundingRect() const; |
diff --git a/utils/themeeditor/models/parsetreenode.cpp b/utils/themeeditor/models/parsetreenode.cpp index bdc0c309b8..1cf750904c 100644 --- a/utils/themeeditor/models/parsetreenode.cpp +++ b/utils/themeeditor/models/parsetreenode.cpp | |||
@@ -530,7 +530,7 @@ void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport) | |||
530 | else if(element->type == CONDITIONAL) | 530 | else if(element->type == CONDITIONAL) |
531 | { | 531 | { |
532 | int child = evalTag(info, true, element->children_count).toInt(); | 532 | int child = evalTag(info, true, element->children_count).toInt(); |
533 | //children[0]->render(info, viewport); | 533 | children[child]->render(info, viewport); |
534 | } | 534 | } |
535 | } | 535 | } |
536 | 536 | ||
@@ -568,12 +568,13 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport) | |||
568 | tile = c - 'a'; | 568 | tile = c - 'a'; |
569 | } | 569 | } |
570 | 570 | ||
571 | image = info.screen()->getImage(id); | 571 | if(info.screen()->getImage(id)) |
572 | if(image) | ||
573 | { | 572 | { |
573 | image = new RBImage(*(info.screen()->getImage(id)), viewport); | ||
574 | image->setTile(tile); | 574 | image->setTile(tile); |
575 | image->show(); | 575 | image->show(); |
576 | } | 576 | } |
577 | |||
577 | return true; | 578 | return true; |
578 | 579 | ||
579 | case 'l': | 580 | case 'l': |
@@ -684,5 +685,74 @@ bool ParseTreeNode::execTag(const RBRenderInfo& info, RBViewport* viewport) | |||
684 | QVariant ParseTreeNode::evalTag(const RBRenderInfo& info, bool conditional, | 685 | QVariant ParseTreeNode::evalTag(const RBRenderInfo& info, bool conditional, |
685 | int branches) | 686 | int branches) |
686 | { | 687 | { |
687 | return info.device()->data(QString(element->tag->name)); | 688 | if(!conditional) |
689 | { | ||
690 | return info.device()->data(QString(element->tag->name)); | ||
691 | } | ||
692 | else | ||
693 | { | ||
694 | /* If we're evaluating for a conditional, we return the child branch | ||
695 | * index that should be selected. For true/false values, this is | ||
696 | * 0 for true, 1 for false, and we also have to make sure not to | ||
697 | * ever exceed the number of available children | ||
698 | */ | ||
699 | |||
700 | int child; | ||
701 | QVariant val = info.device()->data("?" + QString(element->tag->name)); | ||
702 | if(val.isNull()) | ||
703 | val = info.device()->data(QString(element->tag->name)); | ||
704 | |||
705 | if(val.isNull()) | ||
706 | { | ||
707 | child = 1; | ||
708 | } | ||
709 | else if(QString(element->tag->name) == "bl") | ||
710 | { | ||
711 | /* bl has to be scaled to the number of available children, but it | ||
712 | * also has an initial -1 value for an unknown state */ | ||
713 | child = val.toInt(); | ||
714 | if(child == -1) | ||
715 | { | ||
716 | child = 0; | ||
717 | } | ||
718 | else | ||
719 | { | ||
720 | child = ((branches - 1) * child / 100) + 1; | ||
721 | } | ||
722 | } | ||
723 | else if(QString(element->tag->name) == "px") | ||
724 | { | ||
725 | child = val.toInt(); | ||
726 | child = branches * child / 100; | ||
727 | } | ||
728 | else if(val.type() == QVariant::Bool) | ||
729 | { | ||
730 | /* Boolean values have to be reversed, because conditionals are | ||
731 | * always of the form %?tag<true|false> | ||
732 | */ | ||
733 | if(val.toBool()) | ||
734 | child = 0; | ||
735 | else | ||
736 | child = 1; | ||
737 | } | ||
738 | else if(val.type() == QVariant::String) | ||
739 | { | ||
740 | if(val.toString().length() > 0) | ||
741 | child = 0; | ||
742 | else | ||
743 | child = 1; | ||
744 | } | ||
745 | else | ||
746 | { | ||
747 | child = val.toInt(); | ||
748 | } | ||
749 | |||
750 | if(child < 0) | ||
751 | child = 0; | ||
752 | |||
753 | if(child < branches) | ||
754 | return child; | ||
755 | else | ||
756 | return branches - 1; | ||
757 | } | ||
688 | } | 758 | } |