PSP2: Add fit-to-height screen mode

This commit is contained in:
Jeffrey Pfau 2016-08-10 23:42:31 -07:00
parent 1402d3177e
commit 9088d8e6ef
3 changed files with 60 additions and 17 deletions

View File

@ -48,6 +48,7 @@ Misc:
- GUI: Screenshot dimensions are now passed through - GUI: Screenshot dimensions are now passed through
- GUI: Add back logging - GUI: Add back logging
- PSP2: Add rumble for PS TV - PSP2: Add rumble for PS TV
- PSP2: Add fit-to-height screen mode
0.4.1: (2016-07-11) 0.4.1: (2016-07-11)
Bugfixes: Bugfixes:

View File

@ -116,6 +116,7 @@ int main() {
"With Background", "With Background",
"Without Background", "Without Background",
"Stretched", "Stretched",
"Fit Aspect Ratio",
}, },
.nStates = 3 .nStates = 3
} }

View File

@ -38,6 +38,7 @@ static enum ScreenMode {
SM_BACKDROP, SM_BACKDROP,
SM_PLAIN, SM_PLAIN,
SM_FULL, SM_FULL,
SM_ASPECT,
SM_MAX SM_MAX
} screenMode; } screenMode;
@ -280,21 +281,72 @@ void mPSP2Teardown(struct mGUIRunner* runner) {
vita2d_free_texture(screenshot); vita2d_free_texture(screenshot);
} }
void mPSP2Draw(struct mGUIRunner* runner, bool faded) {
unsigned width, height; void _drawTex(vita2d_texture* t, unsigned width, unsigned height, bool faded) {
runner->core->desiredVideoDimensions(runner->core, &width, &height); unsigned w = width;
unsigned h = height;
// Get greatest common divisor
while (w != 0) {
int temp = h % w;
h = w;
w = temp;
}
int gcd = h;
int aspectw = width / gcd;
int aspecth = height / gcd;
float scalex;
float scaley;
switch (screenMode) { switch (screenMode) {
case SM_BACKDROP: case SM_BACKDROP:
default: default:
vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
// Fall through // Fall through
case SM_PLAIN: case SM_PLAIN:
vita2d_draw_texture_tint_part_scale(tex, (960.0f - width * 3.0f) / 2.0f, (544.0f - height * 3.0f) / 2.0f, 0, 0, width, height, 3.0f, 3.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); w = 960 / width;
h = 544 / height;
if (w * height > 544) {
scalex = h;
w = width * h;
h = height * h;
} else {
scalex = w;
w = width * w;
h = height * w;
}
scaley = scalex;
break;
case SM_ASPECT:
w = 960 / aspectw;
h = 544 / aspecth;
if (w * aspecth > 544) {
w = aspectw * h;
h = aspecth * h;
} else {
w = aspectw * w;
h = aspecth * w;
}
scalex = w / (float) width;
scaley = scalex;
break; break;
case SM_FULL: case SM_FULL:
vita2d_draw_texture_tint_scale(tex, 0, 0, 960.0f / width, 544.0f / height, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); w = 960;
h = 544;
scalex = 960.0f / width;
scaley = 544.0f / height;
break; break;
} }
vita2d_draw_texture_tint_part_scale(t,
(960.0f - w) / 2.0f, (544.0f - h) / 2.0f,
0, 0, width, height,
scalex, scaley,
(faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
}
void mPSP2Draw(struct mGUIRunner* runner, bool faded) {
unsigned width, height;
runner->core->desiredVideoDimensions(runner->core, &width, &height);
_drawTex(tex, width, height, faded);
} }
void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsigned width, unsigned height, bool faded) { void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsigned width, unsigned height, bool faded) {
@ -304,18 +356,7 @@ void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsi
for (y = 0; y < height; ++y) { for (y = 0; y < height; ++y) {
memcpy(&texpixels[256 * y], &pixels[width * y], width * 4); memcpy(&texpixels[256 * y], &pixels[width * y], width * 4);
} }
switch (screenMode) { _drawTex(screenshot, width, height, faded);
case SM_BACKDROP:
default:
vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
// Fall through
case SM_PLAIN:
vita2d_draw_texture_tint_part_scale(screenshot, (960.0f - width * 3.0f) / 2.0f, (544.0f - height * 3.0f) / 2.0f, 0, 0, width, height, 3.0f, 3.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
break;
case SM_FULL:
vita2d_draw_texture_tint_scale(screenshot, 0, 0, 960.0f / width, 544.0f / height, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
break;
}
} }
void mPSP2IncrementScreenMode(struct mGUIRunner* runner) { void mPSP2IncrementScreenMode(struct mGUIRunner* runner) {