Skip to content

Commit

Permalink
feat: Play movies in full screen
Browse files Browse the repository at this point in the history
Enable aspect ratio corection - SDL2 only
  • Loading branch information
carstene1ns committed Sep 25, 2024
1 parent aa862ed commit 49c516e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
49 changes: 44 additions & 5 deletions src/io/gfx/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions src/io/gfx/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Video {
int scaleFactor; ///< Scaling factor
#endif
bool fullscreen; ///< Full-screen mode
bool isPlayingMovie;

void findResolutions ();
void expose ();
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/jj1/scene/jj1scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ int JJ1Scene::play () {
SDL_Rect textRect = {0, 0, SW, SH};

video.clearScreen(0);
video.moviePlayback(true);

while (true) {

Expand All @@ -289,6 +290,7 @@ int JJ1Scene::play () {
if (loop(NORMAL_LOOP, paletteEffect) == E_QUIT) {

if (paletteEffect) delete paletteEffect;
video.moviePlayback(false);

return E_QUIT;

Expand All @@ -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;

Expand Down Expand Up @@ -335,6 +338,7 @@ int JJ1Scene::play () {
if (sceneIndex == scriptItems) {

if (paletteEffect) delete paletteEffect;
video.moviePlayback(false);

return E_NONE;

Expand Down Expand Up @@ -553,6 +557,8 @@ int JJ1Scene::play () {

}

video.moviePlayback(false);

return E_NONE;

}

0 comments on commit 49c516e

Please sign in to comment.