Skip to content

Commit

Permalink
Resize videoson message dialogs if needed
Browse files Browse the repository at this point in the history
Also hopefully fix a bug that causes the mouse cursor to not reappear on fullscreen videos
  • Loading branch information
crudelios committed Jul 10, 2023
1 parent 962d86c commit be48712
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 44 deletions.
46 changes: 13 additions & 33 deletions src/graphics/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
#include "core/file.h"
#include "core/smacker.h"
#include "core/time.h"
#include "game/settings.h"
#include "game/system.h"
#include "graphics/renderer.h"
#include "graphics/screen.h"
#include "sound/device.h"
#include "sound/music.h"
#include "sound/speech.h"
Expand Down Expand Up @@ -182,7 +179,6 @@ static void end_video(void)
if (data.restart_music) {
sound_music_update(1);
}
system_show_cursor();
graphics_renderer()->release_custom_image_buffer(CUSTOM_IMAGE_VIDEO);
}

Expand Down Expand Up @@ -332,43 +328,27 @@ static void update_video_frame(void)
graphics_renderer()->update_custom_image(CUSTOM_IMAGE_VIDEO);
}

void video_draw(int x_offset, int y_offset)
void video_draw(int x_offset, int y_offset, int width, int height)
{
get_next_frame();
if (data.video.draw_frame) {
update_video_frame();
data.video.draw_frame = 0;
}
graphics_renderer()->draw_custom_image(CUSTOM_IMAGE_VIDEO, x_offset, y_offset, 1.0f, 0);
}

void video_draw_fullscreen(void)
{
if (setting_fullscreen()) {
system_hide_cursor();
} else {
system_show_cursor();
}
get_next_frame();
if (data.video.draw_frame) {
update_video_frame();
}
float scale = 1.0f;

int s_width = screen_width();
int s_height = screen_height();
float scale_w = data.video.width / (float) screen_width();
float scale_h = data.video.height / (float) screen_height();
float scale = scale_w > scale_h ? scale_w : scale_h;
if (data.video.width != width || data.video.height != height) {
float scale_w = data.video.width / (float) width;
float scale_h = data.video.height / (float) height;
scale = scale_w > scale_h ? scale_w : scale_h;

int x = 0;
int y = 0;
if (scale == scale_h) {
x = (int) ((s_width - data.video.width / scale) / 2 * scale);
}
if (scale == scale_w) {
y = (int) ((s_height - data.video.height / scale) / 2 * scale);
if (scale == scale_h) {
x_offset += (int) ((width - data.video.width / scale) / 2 * scale);
}
if (scale == scale_w) {
y_offset += (int) ((height - data.video.height / scale) / 2 * scale);
}
}

graphics_renderer()->clear_screen();
graphics_renderer()->draw_custom_image(CUSTOM_IMAGE_VIDEO, x, y, scale, 0);
graphics_renderer()->draw_custom_image(CUSTOM_IMAGE_VIDEO, x_offset, y_offset, scale, 0);
}
11 changes: 4 additions & 7 deletions src/graphics/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ void video_stop(void);
void video_shutdown(void);

/**
* Draws a frame of the current video at the specified position
* Draws a frame of the current video at the specified position at the specified size
* @param x_offset X offset
* @param y_offset Y offset
* @param width Width of the video container
* @param height Height of the video container
*/
void video_draw(int x_offset, int y_offset);

/**
* Draws a frame of the current video at fullscreen
*/
void video_draw_fullscreen(void);
void video_draw(int x_offset, int y_offset, int width, int height);

#endif // GRAPHICS_VIDEO_H
10 changes: 9 additions & 1 deletion src/window/intro_video.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "intro_video.h"

#include "game/settings.h"
#include "game/system.h"
#include "graphics/graphics.h"
#include "graphics/screen.h"
#include "graphics/video.h"
Expand Down Expand Up @@ -29,11 +31,16 @@ static int start_next_video(void)
static void draw_background(void)
{
graphics_clear_screen();
if (setting_fullscreen()) {
system_hide_cursor();
} else {
system_show_cursor();
}
}

static void draw_foreground(void)
{
video_draw_fullscreen();
video_draw(0, 0, screen_width(), screen_height());
}

static void handle_input(const mouse *m, const hotkeys *h)
Expand All @@ -42,6 +49,7 @@ static void handle_input(const mouse *m, const hotkeys *h)
video_stop();
if (!start_next_video()) {
sound_music_play_intro();
system_show_cursor();
window_go_back();
}
started = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/window/message_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ static void draw_background_video(void)
}

outer_panel_draw(data.x, data.y, 26, 28);
graphics_draw_rect(data.x + 7, data.y + 7, 402, 294, COLOR_BLACK);
graphics_fill_rect(data.x + 7, data.y + 7, 402, 294, COLOR_BLACK);

int y_base = data.y + 308;
int inner_height_blocks = 6;
Expand Down Expand Up @@ -619,7 +619,7 @@ static void draw_foreground_normal(void)

static void draw_foreground_video(void)
{
video_draw(data.x + 8, data.y + 8);
video_draw(data.x + 8, data.y + 8, 400, 292);
image_buttons_draw(data.x + 16, data.y + 408, get_advisor_button(), 1);
image_buttons_draw(data.x + 372, data.y + 410, &image_button_close, 1);
const lang_message *msg = get_custom_or_standard_lang_message(data.text_id);
Expand Down
10 changes: 9 additions & 1 deletion src/window/victory_video.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "victory_video.h"

#include "game/settings.h"
#include "game/system.h"
#include "graphics/graphics.h"
#include "graphics/screen.h"
#include "graphics/video.h"
Expand All @@ -26,17 +28,23 @@ static int init(const char *filename, int width, int height, void (*callback)(vo
static void draw_background(void)
{
graphics_clear_screen();
if (setting_fullscreen()) {
system_hide_cursor();
} else {
system_show_cursor();
}
}

static void draw_foreground(void)
{
video_draw_fullscreen();
video_draw(0, 0, screen_width(), screen_height());
}

static void handle_input(const mouse *m, const hotkeys *h)
{
if (m->left.went_up || m->right.went_up || video_is_finished()) {
video_stop();
system_show_cursor();
data.callback();
}
}
Expand Down

0 comments on commit be48712

Please sign in to comment.