Make video struct private

Also display actual window size in settings when no known mode is
selected
This commit is contained in:
Andrei Alexeyev 2019-09-11 18:42:13 +03:00
parent 2b58c3515f
commit 28ba4dc955
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
4 changed files with 51 additions and 28 deletions

View file

@ -483,7 +483,7 @@ static bool events_handler_key_down(SDL_Event *event, void *arg) {
SDL_Scancode scan = event->key.keysym.scancode;
bool repeat = event->key.repeat;
if(video.backend == VIDEO_BACKEND_EMSCRIPTEN && scan == SDL_SCANCODE_TAB) {
if(video_get_backend() == VIDEO_BACKEND_EMSCRIPTEN && scan == SDL_SCANCODE_TAB) {
scan = SDL_SCANCODE_ESCAPE;
}

View file

@ -196,12 +196,15 @@ static OptionBinding* bind_stroption(ConfigIndex cfgentry) {
// BT_Resolution: super-special binding type for the resolution setting
static void bind_resolution_update(OptionBinding *bind) {
bind->valrange_min = 0;
bind->valrange_max = video.mcount - 1;
uint nmodes = video_get_num_modes();
VideoMode cur = video_get_current_mode();
for(int i = 0; i < video.mcount; ++i) {
VideoMode *m = video.modes + i;
if(m->width == video.current.width && m->height == video.current.height) {
bind->valrange_min = 0;
bind->valrange_max = nmodes - 1;
for(int i = 0; i < nmodes; ++i) {
VideoMode m = video_get_mode(i);
if(m.width == cur.width && m.height == cur.height) {
bind->selected = i;
}
}
@ -391,9 +394,9 @@ static bool bind_fullscreen_dependence(void) {
static int bind_resolution_set(OptionBinding *b, int v) {
if(v >= 0) {
VideoMode *m = video.modes + v;
config_set_int(CONFIG_VID_WIDTH, m->width);
config_set_int(CONFIG_VID_HEIGHT, m->height);
VideoMode m = video_get_mode(v);
config_set_int(CONFIG_VID_WIDTH, m.width);
config_set_int(CONFIG_VID_HEIGHT, m.height);
}
return v;
@ -426,9 +429,9 @@ static void destroy_options_menu(MenuData *m) {
if(bind->type == BT_Resolution && video_query_capability(VIDEO_CAP_CHANGE_RESOLUTION) == VIDEO_AVAILABLE) {
if(bind->selected != -1) {
VideoMode *mode = video.modes + bind->selected;
config_set_int(CONFIG_VID_WIDTH, mode->width);
config_set_int(CONFIG_VID_HEIGHT, mode->height);
VideoMode mode = video_get_mode(bind->selected);
config_set_int(CONFIG_VID_WIDTH, mode.width);
config_set_int(CONFIG_VID_HEIGHT, mode.height);
change_vidmode = true;
}
}
@ -1180,16 +1183,17 @@ static void draw_options_menu(MenuData *menu) {
case BT_Resolution: {
char tmp[16];
int w, h;
VideoMode m;
if(bind->selected == -1) {
w = video.intended.width;
h = video.intended.height;
m = video_get_current_mode();
} else {
VideoMode *m = video.modes + bind->selected;
w = m->width;
h = m->height;
m = video_get_mode(bind->selected);
}
w = m.width;
h = m.height;
snprintf(tmp, 16, "%dx%d", w, h);
text_draw(tmp, &(TextParams) {
.pos = { origin, 20*i },

View file

@ -18,7 +18,14 @@
#include "taskmanager.h"
#include "video_postprocess.h"
Video video;
static struct {
VideoMode *modes;
SDL_Window *window;
uint mcount;
VideoMode intended;
VideoMode current;
VideoBackend backend;
} video;
typedef struct ScreenshotTaskData {
char *dest_path;
@ -766,3 +773,20 @@ void video_swap_buffers(void) {
// XXX: Unfortunately, there seems to be no reliable way to sync this up with events
config_set_int(CONFIG_FULLSCREEN, video_is_fullscreen());
}
VideoBackend video_get_backend(void) {
return video.backend;
}
VideoMode video_get_mode(uint idx) {
assert(idx < video.mcount);
return video.modes[idx];
}
uint video_get_num_modes(void) {
return video.mcount;
}
VideoMode video_get_current_mode(void) {
return video.current;
}

View file

@ -26,6 +26,7 @@
#define VIDEO_ASPECT_RATIO ((double)SCREEN_W/SCREEN_H)
enum {
// virtual screen coordinates
SCREEN_W = 800,
SCREEN_H = 600,
};
@ -47,14 +48,6 @@ typedef enum VideoBackend {
} VideoBackend;
// TODO make this struct private
typedef struct {
VideoMode *modes;
SDL_Window *window;
uint mcount;
VideoMode intended;
VideoMode current;
VideoBackend backend;
} Video;
typedef enum VideoCapability {
VIDEO_CAP_FULLSCREEN,
@ -70,8 +63,6 @@ typedef enum VideoCapabilityState {
VIDEO_CURRENTLY_UNAVAILABLE,
} VideoCapabilityState;
extern Video video;
void video_init(void);
void video_post_init(void);
void video_shutdown(void);
@ -89,5 +80,9 @@ uint video_current_display(void);
void video_set_display(uint idx);
const char *video_display_name(uint id) attr_returns_nonnull;
Framebuffer *video_get_screen_framebuffer(void);
VideoBackend video_get_backend(void);
VideoMode video_get_mode(uint idx);
uint video_get_num_modes(void);
VideoMode video_get_current_mode(void);
#endif // IGUARD_video_h