@@ -161,6 +161,7 @@ FocusScope {
161
161
162
162
layer .enabled : true
163
163
164
+
164
165
property string pictureMode: gameSettings .pictureMode
165
166
property real aspectRatio: {
166
167
let mode = gameSettings .aspectRatioMode
@@ -172,13 +173,45 @@ FocusScope {
172
173
}
173
174
}
174
175
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
+
175
208
width: {
176
209
if (emulator .pictureMode === " stretch" ) {
177
210
return root .width
178
211
} else if (emulator .pictureMode === " aspect-ratio-fill" ) {
179
- return height * aspectRatio
212
+ return emulator . videoWidth * fitScale
180
213
} else if (emulator .pictureMode === " integer-scale" ) {
181
- return height * aspectRatio
214
+ return sourceWidth * integerScale
182
215
}
183
216
184
217
return emulator .videoWidth
@@ -187,10 +220,9 @@ FocusScope {
187
220
if (emulator .pictureMode === " stretch" ) {
188
221
return root .height
189
222
} else if (emulator .pictureMode === " aspect-ratio-fill" ) {
190
- return root . height
223
+ return ( emulator . videoWidth * fitScale) / aspectRatio
191
224
} else if (emulator .pictureMode === " integer-scale" ){
192
- let num = root .height / emulator .videoHeight
193
- return Math .floor (num) * emulator .videoHeight
225
+ return sourceHeight * integerScale
194
226
}
195
227
196
228
return emulator .videoHeight
0 commit comments