Squaby Demo
import QtQuick 2.0
import Felgo 4.0
Item {
id:healthbar
property url spriteSheetSource: Qt.resolvedUrl("")
property bool useSpriteVersion: false
property real percent: 1.0
onPercentChanged: {
}
property bool ignoreParentRotation: true
Binding {
target: healthbar
property: "rotation"
value: -healthbar.parent.rotation
when: ignoreParentRotation && visible
}
property alias absoluteX: nonRotatedItem.x
property alias absoluteY: nonRotatedItem.y
transformOrigin: Item.TopLeft
Loader {
id: nonRotatedItem
sourceComponent: (useSpriteVersion || spriteSheetSource!="") ? spriteBarsComponent : rectangleBarsComponent
}
Component {
id: spriteBarsComponent
Item {
Component.onCompleted: console.debug("Healthbars loaded from spritesheet with source", spriteSheetSource)
width: healthbar.width
height: healthbar.height
MultiResolutionImage {
id: greenHealthbarSprite
source: Qt.resolvedUrl("../../assets/img/menu_labels/green.png")
width: healthbar.width*healthbar.percent
height: healthbar.height
translateToCenterAnchor: false
}
MultiResolutionImage {
id: redHealthbarSprite
source: Qt.resolvedUrl("../../assets/img/menu_labels/red.png")
width: healthbar.width*(1-healthbar.percent)
height: healthbar.height
translateToCenterAnchor: false
anchors.right: parent.right
}
}
}
Component {
id: rectangleBarsComponent
Item {
Component.onCompleted: console.debug("Healthbars loaded from rectangle")
width: healthbar.width
height: healthbar.height
Rectangle {
width: healthbar.width*healthbar.percent
height: healthbar.height
color: "#2cc908"
}
Rectangle {
width: healthbar.width*(1-healthbar.percent)
height: healthbar.height
color: "#e00f0f"
anchors.right: parent.right
}
}