diff --git a/.gitignore b/.gitignore index 7eac9fc7b..7369df040 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ modules/* !modules/gui !modules/tbs .vscode/ +/external/* #Ignore this, don't know why it's being created for me. imgui.ini diff --git a/src/kre/WindowManager.hpp b/src/kre/WindowManager.hpp index 959edbeff..0b2999a2b 100644 --- a/src/kre/WindowManager.hpp +++ b/src/kre/WindowManager.hpp @@ -34,12 +34,6 @@ namespace KRE { - enum class FullScreenMode { - WINDOWED, - FULLSCREEN_WINDOWED, - FULLSCREEN_EXCLUSIVE, - }; - struct WindowMode { int width; diff --git a/src/kre/WindowManagerFwd.hpp b/src/kre/WindowManagerFwd.hpp index a014958ab..de0990f51 100644 --- a/src/kre/WindowManagerFwd.hpp +++ b/src/kre/WindowManagerFwd.hpp @@ -27,6 +27,12 @@ namespace KRE { + enum class FullScreenMode { + WINDOWED, + FULLSCREEN_WINDOWED, + FULLSCREEN_EXCLUSIVE, + }; + class Surface; typedef std::shared_ptr SurfacePtr; diff --git a/src/level_runner.cpp b/src/level_runner.cpp index 639a0eeea..ab014b225 100644 --- a/src/level_runner.cpp +++ b/src/level_runner.cpp @@ -84,7 +84,6 @@ extern std::map g_user_info_registry; PREF_STRING(editor_object, "", "Object to use for the editor"); -extern bool g_desktop_fullscreen; extern bool g_particle_editor; extern int g_vsync; @@ -1592,45 +1591,12 @@ bool LevelRunner::play_cycle() const int virtual_height = gs.getVirtualHeight(); last_pushed = nevent_frame; - LOG_DEBUG("ctrl-f pushed"); - // XXX this changes if editor is active. - if(wnd->fullscreenMode() == KRE::FullScreenMode::WINDOWED) { - - LOG_DEBUG("Enter full-screen mode"); - wnd->setFullscreenMode(KRE::FullScreenMode::FULLSCREEN_WINDOWED); - - if(preferences::auto_size_window() || g_desktop_fullscreen) { - SDL_DisplayMode dm; - if(SDL_GetDesktopDisplayMode(0, &dm) == 0) { - preferences::adjust_virtual_width_to_match_physical(dm.w, dm.h); - wnd->setWindowSize(dm.w, dm.h); - gs.setDimensions(dm.w, dm.h); - gs.setVirtualDimensions(preferences::requested_virtual_window_width(), preferences::requested_virtual_window_height()); - } - - } - - } else { - LOG_DEBUG("Enter windowed mode"); - wnd->setFullscreenMode(KRE::FullScreenMode::WINDOWED); - - if(preferences::auto_size_window() || g_desktop_fullscreen) { - int width = 0, height = 0; - - if(preferences::requested_window_width() > 0 && preferences::requested_window_height() > 0) { - width = preferences::requested_window_width(); - height = preferences::requested_window_height(); - } else { - auto_select_resolution(wnd, width, height, true, false); - } - - preferences::adjust_virtual_width_to_match_physical(width, height); - - wnd->setWindowSize(width, height); - gs.setDimensions(width, height); - gs.setVirtualDimensions(preferences::requested_virtual_window_width(), preferences::requested_virtual_window_height()); - } - } + // This changes if editor is active. + gs.setFullscreen( + wnd->fullscreenMode() == KRE::FullScreenMode::WINDOWED + ? KRE::FullScreenMode::FULLSCREEN_WINDOWED + : KRE::FullScreenMode::WINDOWED + ); } else if(key == SDLK_F7) { if(formula_profiler::Manager::get()) { if(formula_profiler::Manager::get()->is_profiling()) { diff --git a/src/main.cpp b/src/main.cpp index 8f7ee83c9..d662b5a96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,16 +122,9 @@ namespace PREF_INT(auto_update_timeout, 5000, "Timeout to use on auto updates (given in milliseconds)"); PREF_BOOL(resizeable, false, "Window is dynamically resizeable."); - PREF_INT(min_window_width, 934, "Minimum window width when auto-determining window size"); - PREF_INT(min_window_height, 700, "Minimum window height when auto-determining window size"); - - PREF_INT(max_window_width, 10240, "Minimum window width when auto-determining window size"); - PREF_INT(max_window_height, 7680, "Minimum window height when auto-determining window size"); PREF_BOOL(disable_global_alpha_filter, false, "Disables using alpha-colors.png to denote some special colors as 'alpha colors'"); - PREF_INT(auto_size_ideal_width, 0, ""); - PREF_INT(auto_size_ideal_height, 0, ""); PREF_BOOL(desktop_fullscreen_force, false, "(Windows) forces desktop fullscreen to actually use fullscreen rather than a borderless window the size of the desktop"); PREF_BOOL(msaa, false, "Use msaa"); @@ -355,84 +348,6 @@ namespace // behavior of the module. The `frogatto` module does not use this. PREF_BOOL(remember_me, true, "Remember me (my gamer account) when connecting to the server"); -// Seemingly, this is to select the "next common resolution down" for windowed mode. -// Takes a window, two out params for the best common w/h which will fit in the screen at 2x (?), and "reduce" (?). -void auto_select_resolution(const KRE::WindowPtr& wm, int& width, int& height, bool reduce, bool isFullscreen) -{ - auto mode = wm->getDisplaySize(); - auto best_mode = mode; - bool found = false; - - if(isFullscreen) { - LOG_INFO("RESOLUTION SET TO FULLSCREEN RESOLUTION " << mode.width << "x" << mode.height); - - width = mode.width; - height = mode.height; - - return; - } - - LOG_INFO("TARGET RESOLUTION IS " << mode.width << "x" << mode.height); - - const float MinReduction = reduce ? 0.9f : 2.0f; - for(auto& candidate_mode : wm->getWindowModes([](const KRE::WindowMode&){ return true; })) { - if(g_auto_size_ideal_width && g_auto_size_ideal_height) { - if(found && candidate_mode.width < best_mode.width) { - continue; - } - - if(candidate_mode.width > mode.width * MinReduction) { - LOG_INFO("REJECTED MODE IS " << candidate_mode.width << "x" << candidate_mode.height - << "; (width " << candidate_mode.width << " > " << mode.width * MinReduction << ")"); - continue; - } - - int h = (candidate_mode.width * g_auto_size_ideal_height) / g_auto_size_ideal_width; - if(h > mode.height * MinReduction) { - continue; - } - - best_mode = candidate_mode; - best_mode.height = h; - found = true; - - LOG_INFO("BETTER MODE IS " << best_mode.width << "x" << best_mode.height); - - } else - if( candidate_mode.width < mode.width * MinReduction - && candidate_mode.height < mode.height * MinReduction - && ((candidate_mode.width >= best_mode.width - && candidate_mode.height >= best_mode.height) || !found) - ) { - found = true; - LOG_INFO("BETTER MODE IS " << candidate_mode.width << "x" << candidate_mode.height << " vs " << best_mode.width << "x" << best_mode.height); - best_mode = candidate_mode; - } else { - LOG_INFO("REJECTED MODE IS " << candidate_mode.width << "x" << candidate_mode.height); - } - } - - if (best_mode.width < g_min_window_width || - best_mode.height < g_min_window_height) { - - best_mode.width = g_min_window_width; - best_mode.height = g_min_window_height; - } - - if (best_mode.width > g_max_window_width) { - best_mode.width = g_max_window_width; - } - - if (best_mode.height > g_max_window_height) { - best_mode.height = g_max_window_height; - } - - LOG_INFO("CHOSEN MODE IS " << best_mode.width << "x" << best_mode.height); - - width = best_mode.width; - height = best_mode.height; -} - extern int g_tile_scale; extern int g_tile_size; @@ -1033,7 +948,7 @@ int main(int argcount, char* argvec[]) int height = 0; bool isFullscreen = preferences::get_screen_mode() != preferences::ScreenMode::WINDOWED; - auto_select_resolution(main_wnd, width, height, true, isFullscreen); + graphics::GameScreen::autoSelectResolution(main_wnd, width, height, true, isFullscreen); preferences::adjust_virtual_width_to_match_physical(width, height); diff --git a/src/screen_handling.cpp b/src/screen_handling.cpp index 7e2b5fdd3..a701fb98a 100644 --- a/src/screen_handling.cpp +++ b/src/screen_handling.cpp @@ -27,9 +27,19 @@ #include "asserts.hpp" #include "screen_handling.hpp" +#include "preferences.hpp" + +extern bool g_desktop_fullscreen; //test namespace graphics { + PREF_INT(min_window_width, 934, "Minimum window width when auto-determining window size"); + PREF_INT(min_window_height, 700, "Minimum window height when auto-determining window size"); + PREF_INT(max_window_width, 10240, "Minimum window width when auto-determining window size"); + PREF_INT(max_window_height, 7680, "Minimum window height when auto-determining window size"); + PREF_INT(auto_size_ideal_width, 0, ""); + PREF_INT(auto_size_ideal_height, 0, ""); + GameScreen::GameScreen() : width_(0), height_(0), @@ -78,6 +88,128 @@ namespace graphics cam_ = std::make_shared("gs.cam", x_, virtual_width_, y_, virtual_height_); } + //should use the fullscreen mode from preferences.hpp + void GameScreen::setFullscreen(KRE::FullScreenMode mode) { + auto wnd = KRE::WindowManager::getMainWindow(); + auto& gs = graphics::GameScreen::get(); + + if(mode == KRE::FullScreenMode::FULLSCREEN_WINDOWED) + { + LOG_DEBUG("Entering full-screen mode."); + wnd->setFullscreenMode(KRE::FullScreenMode::FULLSCREEN_WINDOWED); + + if(preferences::auto_size_window() || g_desktop_fullscreen) { + SDL_DisplayMode dm; + if(SDL_GetDesktopDisplayMode(0, &dm) == 0) { + preferences::adjust_virtual_width_to_match_physical(dm.w, dm.h); + wnd->setWindowSize(dm.w, dm.h); + gs.setDimensions(dm.w, dm.h); + gs.setVirtualDimensions(preferences::requested_virtual_window_width(), preferences::requested_virtual_window_height()); + } + + } + } else { + LOG_DEBUG("Entering windowed mode."); + wnd->setFullscreenMode(KRE::FullScreenMode::WINDOWED); + + if(preferences::auto_size_window() || g_desktop_fullscreen) { + int width = 0, height = 0; + + if(preferences::requested_window_width() > 0 && preferences::requested_window_height() > 0) { + width = preferences::requested_window_width(); + height = preferences::requested_window_height(); + } else { + GameScreen::autoSelectResolution(wnd, width, height, true, false); + } + + preferences::adjust_virtual_width_to_match_physical(width, height); + + wnd->setWindowSize(width, height); + gs.setDimensions(width, height); + gs.setVirtualDimensions(preferences::requested_virtual_window_width(), preferences::requested_virtual_window_height()); + } + } + } + + + // Seemingly, this is to select the "next common resolution down" for windowed mode. + // Takes a window, two out params for the best common w/h which will fit in the screen at 2x (?), and "reduce" (?). + void GameScreen::autoSelectResolution(KRE::WindowPtr wm, int& width, int& height, bool reduce, bool isFullscreen) + { + auto mode = wm->getDisplaySize(); + auto best_mode = mode; + bool found = false; + + if(isFullscreen) { + LOG_INFO("RESOLUTION SET TO FULLSCREEN RESOLUTION " << mode.width << "x" << mode.height); + + width = mode.width; + height = mode.height; + + return; + } + + LOG_INFO("TARGET RESOLUTION IS " << mode.width << "x" << mode.height); + + const float MinReduction = reduce ? 0.9f : 2.0f; + for(auto& candidate_mode : wm->getWindowModes([](const KRE::WindowMode&){ return true; })) { + if(g_auto_size_ideal_width && g_auto_size_ideal_height) { + if(found && candidate_mode.width < best_mode.width) { + continue; + } + + if(candidate_mode.width > mode.width * MinReduction) { + LOG_INFO("REJECTED MODE IS " << candidate_mode.width << "x" << candidate_mode.height + << "; (width " << candidate_mode.width << " > " << mode.width * MinReduction << ")"); + continue; + } + + int h = (candidate_mode.width * g_auto_size_ideal_height) / g_auto_size_ideal_width; + if(h > mode.height * MinReduction) { + continue; + } + + best_mode = candidate_mode; + best_mode.height = h; + found = true; + + LOG_INFO("BETTER MODE IS " << best_mode.width << "x" << best_mode.height); + + } else + if( candidate_mode.width < mode.width * MinReduction + && candidate_mode.height < mode.height * MinReduction + && ((candidate_mode.width >= best_mode.width + && candidate_mode.height >= best_mode.height) || !found) + ) { + found = true; + LOG_INFO("BETTER MODE IS " << candidate_mode.width << "x" << candidate_mode.height << " vs " << best_mode.width << "x" << best_mode.height); + best_mode = candidate_mode; + } else { + LOG_INFO("REJECTED MODE IS " << candidate_mode.width << "x" << candidate_mode.height); + } + } + + if (best_mode.width < g_min_window_width || + best_mode.height < g_min_window_height) { + + best_mode.width = g_min_window_width; + best_mode.height = g_min_window_height; + } + + if (best_mode.width > g_max_window_width) { + best_mode.width = g_max_window_width; + } + + if (best_mode.height > g_max_window_height) { + best_mode.height = g_max_window_height; + } + + LOG_INFO("CHOSEN MODE IS " << best_mode.width << "x" << best_mode.height); + + width = best_mode.width; + height = best_mode.height; + } + void GameScreen::setupForDraw(KRE::WindowPtr wnd) { last_cam_ = KRE::DisplayDevice::getCurrent()->setDefaultCamera(cam_); @@ -102,4 +234,6 @@ namespace graphics { GameScreen::get().cleanupAfterDraw(wnd_); } + + extern bool g_desktop_fullscreen; } diff --git a/src/screen_handling.hpp b/src/screen_handling.hpp index e64f1d954..e3b71ce1f 100644 --- a/src/screen_handling.hpp +++ b/src/screen_handling.hpp @@ -51,6 +51,8 @@ namespace graphics void setLocation(int x, int y); void setDimensions(int width, int height); void setVirtualDimensions(int vwidth, int vheight); + void setFullscreen(KRE::FullScreenMode mode); + static void autoSelectResolution(KRE::WindowPtr wm, int& width, int& height, bool reduce, bool isFullscreen); KRE::CameraPtr getCurrentCamera() const { return cam_; } diff --git a/src/utils.cpp b/src/utils.cpp index ee418212d..8daec422a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -50,12 +50,6 @@ void write_autosave() sys::write_file(std::string(preferences::auto_save_file_path()) + ".stat", "1"); } -void toggle_fullscreen() -{ - auto wnd = KRE::WindowManager::getMainWindow(); - wnd->setFullscreenMode(wnd->fullscreenMode() == KRE::FullScreenMode::WINDOWED ? KRE::FullScreenMode::FULLSCREEN_WINDOWED : KRE::FullScreenMode::WINDOWED); -} - std::string get_http_datetime() { time_t rawtime; diff --git a/src/utils.hpp b/src/utils.hpp index e0856515d..3318154a5 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -32,7 +32,6 @@ std::string get_http_datetime(); int truncate_to_char(int value); void write_autosave(); -void toggle_fullscreen(); #if defined(_MSC_VER) int gettimeofday(struct timeval *tv, struct timezone2 *tz); diff --git a/src/video_selections.cpp b/src/video_selections.cpp index b7cb71151..929584ea3 100644 --- a/src/video_selections.cpp +++ b/src/video_selections.cpp @@ -114,18 +114,19 @@ void show_video_selection_dialog() int selected_mode = -1; - std::function make_font_label; + std::function make_font_label; if(module::get_default_font() == "bitmap") { - make_font_label = [](const std::string& label){ - return WidgetPtr(new GraphicalFontLabel(label, "door_label", 2)); + make_font_label = [](const int size, const std::string& label){ + return WidgetPtr(new GraphicalFontLabel(label, "door_label", size)); }; } else { - make_font_label = [](const std::string& label){ - return WidgetPtr(new Label(label, 16, module::get_default_font())); + make_font_label = [](const int size, const std::string& label){ + static constexpr int sizes[] {12, 16, 18}; + return WidgetPtr(new Label(label, sizes[size], module::get_default_font())); }; } - d.addWidget(make_font_label(_("Select video options:")), padding, padding); + d.addWidget(make_font_label(2, _("Select video options:")), padding, padding); WindowModeList display_modes; int current_mode_index = enumerate_video_modes(&display_modes); if(!display_modes.empty()) { @@ -137,6 +138,7 @@ void show_video_selection_dialog() // Video mode list. DropdownWidget* mode_list = new DropdownWidget(display_strings, 260, 20); + mode_list->setDropdownHeight(420); mode_list->setSelection(current_mode_index); mode_list->setZOrder(10); mode_list->setOnSelectHandler([&selected_mode](int selection,const std::string& s){ @@ -144,25 +146,18 @@ void show_video_selection_dialog() }); d.addWidget(WidgetPtr(mode_list)); } else { - d.addWidget(make_font_label(_("Unable to enumerate video modes"))); + d.addWidget(make_font_label(2, _("Unable to enumerate video modes"))); } - + // Fullscreen selection - preferences::ScreenMode fs_mode = preferences::get_screen_mode(); - std::vector fs_options; - fs_options.emplace_back(_("Windowed mode")); - fs_options.emplace_back(_("Fullscreen Windowed")); - //fs_options.push_back("Fullscreen"); - DropdownWidget* fs_list = new DropdownWidget(fs_options, 260, 20); - fs_list->setSelection(static_cast(preferences::get_screen_mode())); - fs_list->setZOrder(9); - fs_list->setOnSelectHandler([&fs_mode](int selection,const std::string& s){ - switch(selection) { - case 0: fs_mode = preferences::ScreenMode::WINDOWED; break; - case 1: fs_mode = preferences::ScreenMode::FULLSCREEN_WINDOWED; break; - } - }); - d.addWidget(WidgetPtr(fs_list)); + Checkbox* fullscreenCheckbox = new Checkbox( + _("Fullscreen"), + KRE::WindowManager::getMainWindow()->fullscreenMode() != KRE::FullScreenMode::WINDOWED, + [](bool checked) { /* Do nothing here, only apply on dialog OK. */ } + ); + if(!preferences::no_fullscreen_ever()) { + d.addWidget(WidgetPtr(fullscreenCheckbox)); + } // Vertical sync options std::vector vsync_options; @@ -181,10 +176,10 @@ void show_video_selection_dialog() }); d.addWidget(WidgetPtr(synch_list)); - WidgetPtr b_okay = new Button(make_font_label(_("OK")), [&d](){ + WidgetPtr b_okay = new Button(make_font_label(2, _("OK")), [&d](){ d.close(); }); - WidgetPtr b_cancel = new Button(make_font_label(_("Cancel")), [&d](){ + WidgetPtr b_cancel = new Button(make_font_label(2, _("Cancel")), [&d](){ d.cancel(); }); b_okay->setDim(button_width, button_height); @@ -198,6 +193,13 @@ void show_video_selection_dialog() if(selected_mode >= 0 && static_cast(selected_mode) < display_modes.size()) { KRE::WindowManager::getMainWindow()->setWindowSize(display_modes[selected_mode].width, display_modes[selected_mode].height); } - //preferences::set_screen_mode(fs_mode); + + KRE::WindowManager::getMainWindow()->setFullscreenMode(fullscreenCheckbox->checked() + ? KRE::FullScreenMode::FULLSCREEN_WINDOWED + : KRE::FullScreenMode::WINDOWED); + preferences::set_screen_mode( + KRE::WindowManager::getMainWindow()->fullscreenMode() == KRE::FullScreenMode::WINDOWED + ? preferences::ScreenMode::WINDOWED + : preferences::ScreenMode::FULLSCREEN_WINDOWED); } }