mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-27 21:10:34 +02:00
Fix image overlay's subImage property's width and height support
This commit is contained in:
parent
a5e671e0fd
commit
efd72be96f
1 changed files with 21 additions and 20 deletions
|
@ -9,33 +9,30 @@ Overlay {
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: image
|
id: image
|
||||||
property bool scaleFix: true;
|
property bool scaleFix: true
|
||||||
property real xOffset: 0
|
property real xStart: 0
|
||||||
property real yOffset: 0
|
property real yStart: 0
|
||||||
|
property real xSize: 0
|
||||||
|
property real ySize: 0
|
||||||
property real imageScale: 1.0
|
property real imageScale: 1.0
|
||||||
property var resizer: Timer {
|
property var resizer: Timer {
|
||||||
interval: 50
|
interval: 50
|
||||||
repeat: false
|
repeat: false
|
||||||
running: false
|
running: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
var targetAspect = root.width / root.height;
|
if (image.xSize === 0) {
|
||||||
var sourceAspect = image.sourceSize.width / image.sourceSize.height;
|
image.xSize = image.sourceSize.width - image.xStart;
|
||||||
if (sourceAspect <= targetAspect) {
|
|
||||||
if (root.width === image.sourceSize.width) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
image.imageScale = root.width / image.sourceSize.width;
|
|
||||||
} else if (sourceAspect > targetAspect){
|
|
||||||
if (root.height === image.sourceSize.height) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
image.imageScale = root.height / image.sourceSize.height;
|
|
||||||
}
|
}
|
||||||
image.sourceSize = Qt.size(image.sourceSize.width * image.imageScale, image.sourceSize.height * image.imageScale);
|
if (image.ySize === 0) {
|
||||||
|
image.ySize = image.sourceSize.height - image.yStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
image.anchors.leftMargin = -image.xStart * root.width / image.xSize;
|
||||||
|
image.anchors.topMargin = -image.yStart * root.height / image.ySize;
|
||||||
|
image.anchors.rightMargin = (image.xStart + image.xSize - image.sourceSize.width) * root.width / image.xSize;
|
||||||
|
image.anchors.bottomMargin = (image.yStart + image.ySize - image.sourceSize.height) * root.height / image.ySize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x: -1 * xOffset * imageScale
|
|
||||||
y: -1 * yOffset * imageScale
|
|
||||||
|
|
||||||
onSourceSizeChanged: {
|
onSourceSizeChanged: {
|
||||||
if (sourceSize.width !== 0 && sourceSize.height !== 0 && progress === 1.0 && scaleFix) {
|
if (sourceSize.width !== 0 && sourceSize.height !== 0 && progress === 1.0 && scaleFix) {
|
||||||
|
@ -43,6 +40,8 @@ Overlay {
|
||||||
resizer.start();
|
resizer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorOverlay {
|
ColorOverlay {
|
||||||
|
@ -57,8 +56,10 @@ Overlay {
|
||||||
var key = keys[i];
|
var key = keys[i];
|
||||||
var value = subImage[key];
|
var value = subImage[key];
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "x": image.xOffset = value; break;
|
case "x": image.xStart = value; break;
|
||||||
case "y": image.yOffset = value; break;
|
case "y": image.yStart = value; break;
|
||||||
|
case "width": image.xSize = value; break;
|
||||||
|
case "height": image.ySize = value; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue