mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-10 18:51:05 +00:00
Allow toggling fullscreen without restart and add keybind (#14714)
This commit is contained in:
parent
981d67324b
commit
833bb542fc
14 changed files with 120 additions and 15 deletions
|
@ -1164,7 +1164,8 @@ void Game::run()
|
|||
g_settings->getU16("screen_w"),
|
||||
g_settings->getU16("screen_h")
|
||||
);
|
||||
const bool initial_window_maximized = g_settings->getBool("window_maximized");
|
||||
const bool initial_window_maximized = !g_settings->getBool("fullscreen") &&
|
||||
g_settings->getBool("window_maximized");
|
||||
|
||||
while (m_rendering_engine->run()
|
||||
&& !(*kill || g_gamecallback->shutdown_requested
|
||||
|
|
|
@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "settings.h"
|
||||
#include "util/numeric.h"
|
||||
#include "inputhandler.h"
|
||||
#include "gui/mainmenumanager.h"
|
||||
|
@ -113,6 +114,19 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
|
|||
return true;
|
||||
}
|
||||
|
||||
// This is separate from other keyboard handling so that it also works in menus.
|
||||
if (event.EventType == EET_KEY_INPUT_EVENT) {
|
||||
const KeyPress keyCode(event.KeyInput);
|
||||
if (keyCode == getKeySetting("keymap_fullscreen")) {
|
||||
if (event.KeyInput.PressedDown && !fullscreen_is_down) {
|
||||
bool fullscreen = RenderingEngine::get_raw_device()->isFullscreen();
|
||||
g_settings->setBool("fullscreen", !fullscreen);
|
||||
}
|
||||
fullscreen_is_down = event.KeyInput.PressedDown;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Let the menu handle events, if one is active.
|
||||
if (isMenuActive()) {
|
||||
if (g_touchscreengui)
|
||||
|
|
|
@ -220,6 +220,9 @@ private:
|
|||
// often changing keys, and keysListenedFor is expected
|
||||
// to change seldomly but contain lots of keys.
|
||||
KeyList keysListenedFor;
|
||||
|
||||
// Intentionally not reset by clearInput/releaseAllKeys.
|
||||
bool fullscreen_is_down = false;
|
||||
};
|
||||
|
||||
class InputHandler
|
||||
|
|
|
@ -207,7 +207,12 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
|
|||
#else
|
||||
u16 screen_w = std::max<u16>(g_settings->getU16("screen_w"), 1);
|
||||
u16 screen_h = std::max<u16>(g_settings->getU16("screen_h"), 1);
|
||||
bool window_maximized = g_settings->getBool("window_maximized");
|
||||
// If I…
|
||||
// 1. … set fullscreen = true and window_maximized = true on startup
|
||||
// 2. … set fullscreen = false later
|
||||
// on Linux with SDL, everything breaks.
|
||||
// => Don't do it.
|
||||
bool window_maximized = !fullscreen && g_settings->getBool("window_maximized");
|
||||
#endif
|
||||
|
||||
// bpp, fsaa, vsync
|
||||
|
@ -249,18 +254,40 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
|
|||
gui::EGST_WINDOWS_METALLIC, driver);
|
||||
m_device->getGUIEnvironment()->setSkin(skin);
|
||||
skin->drop();
|
||||
|
||||
g_settings->registerChangedCallback("fullscreen", settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("window_maximized", settingChangedCallback, this);
|
||||
}
|
||||
|
||||
RenderingEngine::~RenderingEngine()
|
||||
{
|
||||
sanity_check(s_singleton == this);
|
||||
|
||||
g_settings->deregisterChangedCallback("fullscreen", settingChangedCallback, this);
|
||||
g_settings->deregisterChangedCallback("window_maximized", settingChangedCallback, this);
|
||||
|
||||
core.reset();
|
||||
m_device->closeDevice();
|
||||
m_device->drop();
|
||||
s_singleton = nullptr;
|
||||
}
|
||||
|
||||
void RenderingEngine::settingChangedCallback(const std::string &name, void *data)
|
||||
{
|
||||
IrrlichtDevice *device = static_cast<RenderingEngine*>(data)->m_device;
|
||||
if (name == "fullscreen") {
|
||||
device->setFullscreen(g_settings->getBool("fullscreen"));
|
||||
|
||||
} else if (name == "window_maximized") {
|
||||
if (!device->isFullscreen()) {
|
||||
if (g_settings->getBool("window_maximized"))
|
||||
device->maximizeWindow();
|
||||
else
|
||||
device->restoreWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v2u32 RenderingEngine::_getWindowSize() const
|
||||
{
|
||||
if (core)
|
||||
|
|
|
@ -168,6 +168,7 @@ public:
|
|||
const bool initial_window_maximized);
|
||||
|
||||
private:
|
||||
static void settingChangedCallback(const std::string &name, void *data);
|
||||
v2u32 _getWindowSize() const;
|
||||
|
||||
std::unique_ptr<RenderingCore> core;
|
||||
|
|
|
@ -182,6 +182,7 @@ void set_default_settings()
|
|||
settings->setDefault("keymap_toggle_profiler", "KEY_F6");
|
||||
settings->setDefault("keymap_camera_mode", "KEY_KEY_C");
|
||||
settings->setDefault("keymap_screenshot", "KEY_F12");
|
||||
settings->setDefault("keymap_fullscreen", "KEY_F11");
|
||||
settings->setDefault("keymap_increase_viewing_range_min", "+");
|
||||
settings->setDefault("keymap_decrease_viewing_range_min", "-");
|
||||
settings->setDefault("keymap_slot1", "KEY_KEY_1");
|
||||
|
|
|
@ -193,6 +193,8 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||
|
||||
m_script = std::make_unique<MainMenuScripting>(this);
|
||||
|
||||
g_settings->registerChangedCallback("fullscreen", fullscreenChangedCallback, this);
|
||||
|
||||
try {
|
||||
m_script->setMainMenuData(&m_data->script_data);
|
||||
m_data->script_data.errormessage.clear();
|
||||
|
@ -319,7 +321,8 @@ void GUIEngine::run()
|
|||
g_settings->getU16("screen_w"),
|
||||
g_settings->getU16("screen_h")
|
||||
);
|
||||
const bool initial_window_maximized = g_settings->getBool("window_maximized");
|
||||
const bool initial_window_maximized = !g_settings->getBool("fullscreen") &&
|
||||
g_settings->getBool("window_maximized");
|
||||
|
||||
FpsControl fps_control;
|
||||
f32 dtime = 0.0f;
|
||||
|
@ -377,6 +380,8 @@ void GUIEngine::run()
|
|||
/******************************************************************************/
|
||||
GUIEngine::~GUIEngine()
|
||||
{
|
||||
g_settings->deregisterChangedCallback("fullscreen", fullscreenChangedCallback, this);
|
||||
|
||||
// deinitialize script first. gc destructors might depend on other stuff
|
||||
infostream << "GUIEngine: Deinitializing scripting" << std::endl;
|
||||
m_script.reset();
|
||||
|
@ -666,3 +671,9 @@ void GUIEngine::updateTopLeftTextSize()
|
|||
m_irr_toplefttext = gui::StaticText::add(m_rendering_engine->get_gui_env(),
|
||||
m_toplefttext, rect, false, true, 0, -1);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void GUIEngine::fullscreenChangedCallback(const std::string &name, void *data)
|
||||
{
|
||||
static_cast<GUIEngine*>(data)->getScriptIface()->handleMainMenuEvent("FullscreenChange");
|
||||
}
|
||||
|
|
|
@ -296,4 +296,6 @@ private:
|
|||
bool m_clouds_enabled = true;
|
||||
/** data used to draw clouds */
|
||||
clouddata m_cloud;
|
||||
|
||||
static void fullscreenChangedCallback(const std::string &name, void *data);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue