Skip to content

Commit 5009c52

Browse files
committed
Fix the video modes to not overflow and account for width
1 parent 9b011ed commit 5009c52

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

qml/components/MainContent.qml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ FocusScope {
4949
function goToContent(title, page, args, transition) {
5050
content.title = title
5151
contentStack.replaceCurrentItem(page, args, transition)
52-
content.forceActiveFocus()
5352

5453
}
5554

qml/pages/NewEmulatorPage.qml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ FocusScope {
161161

162162
layer.enabled: true
163163

164+
164165
property string pictureMode: gameSettings.pictureMode
165166
property real aspectRatio: {
166167
let mode = gameSettings.aspectRatioMode
@@ -172,13 +173,45 @@ FocusScope {
172173
}
173174
}
174175

176+
property real fitScale: {
177+
if (!emulator.videoWidth || !emulator.videoHeight) {
178+
return 1.0 // Avoid division by zero
179+
}
180+
181+
// Calculate the ratio of the container itself
182+
const containerRatio = root.width / root.height
183+
184+
// If the container is wider than the target aspect ratio, fit to height.
185+
// Otherwise, fit to width.
186+
if (containerRatio > aspectRatio) {
187+
return root.height / (emulator.videoWidth / aspectRatio)
188+
} else {
189+
return root.width / emulator.videoWidth
190+
}
191+
}
192+
193+
property real sourceHeight: emulator.videoHeight
194+
property real sourceWidth: sourceHeight * aspectRatio
195+
196+
property int integerScale: {
197+
if (!sourceWidth || !sourceHeight) {
198+
return 1 // Avoid division by zero
199+
}
200+
// Find how many times our correct shape fits into the container
201+
const widthScale = root.width / sourceWidth
202+
const heightScale = root.height / sourceHeight
203+
204+
// Take the smaller of the two, and floor it to get the largest whole number scale
205+
return Math.floor(Math.min(widthScale, heightScale))
206+
}
207+
175208
width: {
176209
if (emulator.pictureMode === "stretch") {
177210
return root.width
178211
} else if (emulator.pictureMode === "aspect-ratio-fill") {
179-
return height * aspectRatio
212+
return emulator.videoWidth * fitScale
180213
} else if (emulator.pictureMode === "integer-scale") {
181-
return height * aspectRatio
214+
return sourceWidth * integerScale
182215
}
183216

184217
return emulator.videoWidth
@@ -187,10 +220,9 @@ FocusScope {
187220
if (emulator.pictureMode === "stretch") {
188221
return root.height
189222
} else if (emulator.pictureMode === "aspect-ratio-fill") {
190-
return root.height
223+
return (emulator.videoWidth * fitScale) / aspectRatio
191224
} else if (emulator.pictureMode === "integer-scale"){
192-
let num = root.height / emulator.videoHeight
193-
return Math.floor(num) * emulator.videoHeight
225+
return sourceHeight * integerScale
194226
}
195227

196228
return emulator.videoHeight

0 commit comments

Comments
 (0)