Disable resizable window by default, added an option to enable it back

Not everyone needs a freely resizable window and it causes problems on
some systems.
This commit is contained in:
Andrei "Akari" Alexeyev 2017-03-01 02:25:52 +02:00
parent 89155e86db
commit f051a3afd9
5 changed files with 63 additions and 26 deletions

View file

@ -68,6 +68,7 @@
CONFIGDEF_INT (FULLSCREEN, "fullscreen", 0) \
CONFIGDEF_INT (VID_WIDTH, "vid_width", RESX) \
CONFIGDEF_INT (VID_HEIGHT, "vid_height", RESY) \
CONFIGDEF_INT (VID_RESIZABLE, "vid_resizable", 0) \
CONFIGDEF_INT (VSYNC, "vsync", 2) \
CONFIGDEF_INT (NO_SHADER, "disable_shader", 0) \
CONFIGDEF_INT (NO_AUDIO, "disable_audio", 0) \

View file

@ -244,6 +244,10 @@ bool bind_bgmvol_dependence(void) {
return !config_get_int(CONFIG_NO_MUSIC);
}
bool bind_resizable_dependence(void) {
return !config_get_int(CONFIG_FULLSCREEN);
}
int bind_saverpy_get(void *b) {
int v = config_get_int(((OptionBinding*)b)->configentry);
@ -273,7 +277,10 @@ void destroy_options_menu(MenuData *m) {
if(bind->selected != -1) {
VideoMode *m = video.modes + bind->selected;
video_setmode(m->width, m->height, config_get_int(CONFIG_FULLSCREEN));
video_setmode(m->width, m->height,
config_get_int(CONFIG_FULLSCREEN),
config_get_int(CONFIG_VID_RESIZABLE)
);
config_set_int(CONFIG_VID_WIDTH, video.intended.width);
config_set_int(CONFIG_VID_HEIGHT, video.intended.height);
@ -320,6 +327,11 @@ void options_sub_video(MenuData *parent, void *arg) {
b = bind_option(CONFIG_FULLSCREEN, bind_common_onoffget, bind_common_onoffset)
); bind_onoff(b);
add_menu_entry(m, "Resizable window", do_nothing,
b = bind_option(CONFIG_VID_RESIZABLE, bind_common_onoffget, bind_common_onoffset)
); bind_onoff(b);
bind_setdependence(b, bind_resizable_dependence);
add_menu_entry(m, "Vertical synchronization", do_nothing,
b = bind_option(CONFIG_VSYNC, bind_common_intget, bind_common_intset)
); bind_addvalue(b, "on");
@ -344,6 +356,7 @@ void options_sub_video(MenuData *parent, void *arg) {
b = bind_option(CONFIG_NO_STAGEBG_FPSLIMIT, bind_common_intget, bind_common_intset)
); bind_setvaluerange(b, 20, 60);
bind_setdependence(b, bind_stagebg_fpslimit_dependence);
b->pad++;
add_menu_separator(m);
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
@ -468,10 +481,12 @@ void options_sub_gamepad(MenuData *parent, void *arg) {
add_menu_entry(m, "X axis sensitivity", do_nothing,
b = bind_scale(CONFIG_GAMEPAD_AXIS_LR_SENS, -2, 2, 0.05)
); bind_setdependence(b, gamepad_sens_depencence);
b->pad++;
add_menu_entry(m, "Y axis sensitivity", do_nothing,
b = bind_scale(CONFIG_GAMEPAD_AXIS_UD_SENS, -2, 2, 0.05)
); bind_setdependence(b, gamepad_sens_depencence);
); bind_setdependence(b, gamepad_sens_depencence);
b->pad++;
add_menu_entry(m, "Dead zone", do_nothing,
b = bind_scale(CONFIG_GAMEPAD_AXIS_DEADZONE, 0, 1, 0.01)
@ -590,6 +605,7 @@ void create_options_menu(MenuData *m) {
add_menu_entry(m, "Volume", do_nothing,
b = bind_scale(CONFIG_SFX_VOLUME, 0, 1, 0.1)
); bind_setdependence(b, bind_sfxvol_dependence);
b->pad++;
add_menu_separator(m);
@ -601,6 +617,7 @@ void create_options_menu(MenuData *m) {
add_menu_entry(m, "Volume", do_nothing,
b = bind_scale(CONFIG_BGM_VOLUME, 0, 1, 0.1)
); bind_setdependence(b, bind_bgmvol_dependence);
b->pad++;
add_menu_separator(m);
add_menu_entry(m, "Video options…", options_sub_video, NULL);
@ -654,9 +671,7 @@ void draw_options_menu(MenuData *menu) {
glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, (0.7 + 0.3 * a) * alpha);
}
draw_text(AL_Left,
((bind && bind->dependence)? 20 : 0) // hack hack hack
+ 20 - e->drawdata, 20*i, e->name, _fonts.standard);
draw_text(AL_Left, (1 + (bind ? bind->pad : 0)) * 20 - e->drawdata, 20*i, e->name, _fonts.standard);
if(bind) {
int j, origin = SCREEN_W - 220;

View file

@ -46,6 +46,7 @@ typedef struct OptionBinding {
int configentry;
BindingType type;
bool blockinput;
int pad;
} OptionBinding;
void draw_options_menu_bg(MenuData*);

View file

@ -97,20 +97,12 @@ static void video_init_gl(void) {
glClear(GL_COLOR_BUFFER_BIT);
}
static void _video_setmode(int w, int h, int fs, int fallback) {
Uint32 flags = SDL_WINDOW_OPENGL;
static void _video_setmode(int w, int h, uint32_t flags, bool fallback) {
if(!libgl_loaded) {
load_gl_library();
libgl_loaded = true;
}
if(fs) {
flags |= SDL_WINDOW_FULLSCREEN;
} else {
flags |= SDL_WINDOW_RESIZABLE;
}
if(!fallback) {
video.intended.width = w;
video.intended.height = h;
@ -151,23 +143,39 @@ static void _video_setmode(int w, int h, int fs, int fallback) {
return;
}
warnx("video_setmode(): setting %dx%d (%s) failed, falling back to %dx%d (windowed)", w, h, fs ? "fullscreen" : "windowed", RESX, RESY);
_video_setmode(RESX, RESY, false, true);
warnx("video_setmode(): setting %dx%d (%s) failed, falling back to %dx%d (windowed)", w, h,
(flags & SDL_WINDOW_FULLSCREEN) ? "fullscreen" : "windowed", RESX, RESY);
_video_setmode(RESX, RESY, flags & ~SDL_WINDOW_FULLSCREEN, true);
}
void video_setmode(int w, int h, int fs) {
if(w == video.current.width && h == video.current.height && fs == video_isfullscreen())
return;
void video_setmode(int w, int h, bool fs, bool resizable) {
if( w == video.current.width &&
h == video.current.height &&
fs == video_isfullscreen() &&
resizable == video_isresizable()
) return;
_video_setmode(w, h, fs, false);
uint32_t flags = SDL_WINDOW_OPENGL;
if(fs) {
flags |= SDL_WINDOW_FULLSCREEN;
} else if(flags & SDL_WINDOW_RESIZABLE) {
flags |= SDL_WINDOW_RESIZABLE;
}
_video_setmode(w, h, flags, false);
}
int video_isfullscreen(void) {
return !!(SDL_GetWindowFlags(video.window) & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP));
bool video_isresizable(void) {
return SDL_GetWindowFlags(video.window) & SDL_WINDOW_RESIZABLE;
}
bool video_isfullscreen(void) {
return SDL_GetWindowFlags(video.window) & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
}
void video_set_fullscreen(bool fullscreen) {
video_setmode(video.intended.width, video.intended.height, fullscreen);
video_setmode(video.intended.width, video.intended.height, fullscreen, video_isresizable());
}
void video_toggle_fullscreen(void) {
@ -189,6 +197,10 @@ static void video_cfg_vsync_callback(ConfigIndex idx, ConfigValue v) {
video_update_vsync();
}
static void video_cfg_resizable_callback(ConfigIndex idx, ConfigValue v) {
SDL_SetWindowResizable(video.window, config_set_int(idx, v.i));
}
void video_init(void) {
int i, s;
bool fullscreen_available = false;
@ -223,10 +235,16 @@ void video_init(void) {
// sort it, mainly for the options menu
qsort(video.modes, video.mcount, sizeof(VideoMode), video_compare_modes);
video_setmode(config_get_int(CONFIG_VID_WIDTH), config_get_int(CONFIG_VID_HEIGHT), config_get_int(CONFIG_FULLSCREEN));
video_setmode(
config_get_int(CONFIG_VID_WIDTH),
config_get_int(CONFIG_VID_HEIGHT),
config_get_int(CONFIG_FULLSCREEN),
config_get_int(CONFIG_VID_RESIZABLE)
);
config_set_callback(CONFIG_FULLSCREEN, video_cfg_fullscreen_callback);
config_set_callback(CONFIG_VSYNC, video_cfg_vsync_callback);
config_set_callback(CONFIG_VID_RESIZABLE, video_cfg_resizable_callback);
}
void video_shutdown(void) {

View file

@ -12,6 +12,7 @@
#define WINDOW_TITLE "TaiseiProject"
#define VIEWPORT_ASPECT_RATIO (4.0f/3.0f)
#include <SDL.h>
#include <stdbool.h>
typedef struct VideoMode {
@ -33,9 +34,10 @@ Video video;
void video_init(void);
void video_shutdown(void);
void video_setmode(int w, int h, int fs);
void video_setmode(int w, int h, bool fs, bool resizable);
void video_set_viewport(void);
int video_isfullscreen(void);
bool video_isfullscreen(void);
bool video_isresizable(void);
void video_set_fullscreen(bool);
void video_toggle_fullscreen(void);
void video_resize(int w, int h);