From 49c516e071aa2d4e999d3c6b7ae86ea09acab565 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Wed, 25 Sep 2024 01:12:45 +0200 Subject: [PATCH] feat: Play movies in full screen Enable aspect ratio corection - SDL2 only --- src/io/gfx/video.cpp | 49 ++++++++++++++++++++++++++++++++++---- src/io/gfx/video.h | 3 +++ src/jj1/scene/jj1scene.cpp | 6 +++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/io/gfx/video.cpp b/src/io/gfx/video.cpp index c8fc17ae..f7fa8d3a 100644 --- a/src/io/gfx/video.cpp +++ b/src/io/gfx/video.cpp @@ -91,6 +91,7 @@ Video::Video () { scaleFactor = 1; #endif fullscreen = false; + isPlayingMovie = false; // Generate the logical palette for (int i = 0; i < MAX_PALETTE_COLORS; i++) @@ -296,6 +297,7 @@ bool Video::reset (int width, int height) { #if OJ_SDL2 SDL_SetWindowSize(window, screenW, screenH); + SDL_RenderSetLogicalSize(renderer, screenW, screenH); SDL_SetWindowFullscreen(window, fullscreen? SDL_WINDOW_FULLSCREEN_DESKTOP: 0); #else screen = SDL_SetVideoMode(screenW, screenH, 8, fullscreen? FULLSCREEN_FLAGS: WINDOWED_FLAGS); @@ -658,7 +660,7 @@ void Video::flip (int mspf, PaletteEffect* paletteEffects, bool effectsStopped) SDL_Color shownPalette[MAX_PALETTE_COLORS]; #ifdef SCALE - if (canvas != NULL && canvas != screen) { + if (canvas != nullptr && canvas != screen) { // Copy everything that has been drawn so far if (setup.scale2x) @@ -667,7 +669,7 @@ void Video::flip (int mspf, PaletteEffect* paletteEffects, bool effectsStopped) canvas->pixels, canvas->pitch, screen->format->BytesPerPixel, canvas->w, canvas->h); else - SDL_SoftStretch(canvas, NULL, screen, NULL); + SDL_SoftStretch(canvas, nullptr, screen, nullptr); } #endif @@ -682,10 +684,15 @@ void Video::flip (int mspf, PaletteEffect* paletteEffects, bool effectsStopped) // Show what has been drawn #if OJ_SDL2 - SDL_BlitSurface(screen, NULL, textureSurface, NULL); - SDL_UpdateTexture(texture, NULL, textureSurface->pixels, textureSurface->pitch); + SDL_BlitSurface(screen, nullptr, textureSurface, nullptr); + SDL_UpdateTexture(texture, nullptr, textureSurface->pixels, textureSurface->pitch); SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, texture, NULL, NULL); + if (isPlayingMovie) { + SDL_Rect src = {0, 0, canvasW, canvasH}; + SDL_RenderCopy(renderer, texture, &src, nullptr); + } else { + SDL_RenderCopy(renderer, texture, nullptr, nullptr); + } SDL_RenderPresent(renderer); #else SDL_Flip(screen); @@ -713,6 +720,38 @@ void Video::clearScreen (int index) { } +/** + * Sets up scaling for movie mode. + * + * @param status Whether or not movie mode will be enabled + */ +void Video::moviePlayback (bool status) { +#if OJ_SDL2 + static int movieW = SW; + static int movieH = SH; + + if(isPlayingMovie == status) + return; + + isPlayingMovie = status; + + if (isPlayingMovie) { + // save size + movieW = canvasW; + movieH = canvasH; + + canvasW = SW; + canvasH = SH; + } else { + // reset + canvasW = movieW; + canvasH = movieH; + } + SDL_RenderSetLogicalSize(renderer, canvasW, canvasH); +#endif +} + + /** * Fill a specified rectangle of the screen with a colour. * diff --git a/src/io/gfx/video.h b/src/io/gfx/video.h index 5ab72123..4bb31da9 100644 --- a/src/io/gfx/video.h +++ b/src/io/gfx/video.h @@ -144,6 +144,7 @@ class Video { int scaleFactor; ///< Scaling factor #endif bool fullscreen; ///< Full-screen mode + bool isPlayingMovie; void findResolutions (); void expose (); @@ -176,6 +177,8 @@ class Video { bool isFullscreen (); #endif + void moviePlayback (bool status); + void update (SDL_Event *event); void flip (int mspf, PaletteEffect* paletteEffects = NULL, bool effectsStopped = false); diff --git a/src/jj1/scene/jj1scene.cpp b/src/jj1/scene/jj1scene.cpp index bb655c0e..9020ea4e 100644 --- a/src/jj1/scene/jj1scene.cpp +++ b/src/jj1/scene/jj1scene.cpp @@ -279,6 +279,7 @@ int JJ1Scene::play () { SDL_Rect textRect = {0, 0, SW, SH}; video.clearScreen(0); + video.moviePlayback(true); while (true) { @@ -289,6 +290,7 @@ int JJ1Scene::play () { if (loop(NORMAL_LOOP, paletteEffect) == E_QUIT) { if (paletteEffect) delete paletteEffect; + video.moviePlayback(false); return E_QUIT; @@ -306,6 +308,7 @@ int JJ1Scene::play () { (downOrRight && (x >= 0) && (x < 100) && (y >= SH - 12) && (y < SH))) { if (paletteEffect) delete paletteEffect; + video.moviePlayback(false); return E_NONE; @@ -335,6 +338,7 @@ int JJ1Scene::play () { if (sceneIndex == scriptItems) { if (paletteEffect) delete paletteEffect; + video.moviePlayback(false); return E_NONE; @@ -553,6 +557,8 @@ int JJ1Scene::play () { } + video.moviePlayback(false); + return E_NONE; }