From fa95f813b15e61e8dd55566549c2714aa473cfcc Mon Sep 17 00:00:00 2001 From: Angelo Theodorou Date: Wed, 7 Dec 2022 01:37:10 +0100 Subject: [PATCH] Fix compilation with the `hidpi` nCine branch --- src/particle_editor.cpp | 4 ++-- src/particle_editor_gui.cpp | 46 +++++++++++++++++++++---------------- src/particle_editor_lua.cpp | 6 ++--- src/particle_editor_lua.h | 2 +- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/particle_editor.cpp b/src/particle_editor.cpp index c884f36..ffa1ff9 100644 --- a/src/particle_editor.cpp +++ b/src/particle_editor.cpp @@ -96,8 +96,8 @@ void MyEventHandler::onPreInit(nc::AppConfiguration &config) luaConfig.backgroundsPath = nc::fs::joinPath(nc::fs::dataPath(), "backgrounds"); config.resolution.set(luaConfig.width, luaConfig.height); - config.inFullscreen = luaConfig.fullscreen; - config.isResizable = luaConfig.resizable; + config.fullScreen = luaConfig.fullScreen; + config.resizable = luaConfig.resizable; config.frameLimit = luaConfig.frameLimit; config.useBufferMapping = luaConfig.useBufferMapping; config.vboSize = luaConfig.vboSize; diff --git a/src/particle_editor_gui.cpp b/src/particle_editor_gui.cpp index 2150ab6..d58c528 100644 --- a/src/particle_editor_gui.cpp +++ b/src/particle_editor_gui.cpp @@ -1725,6 +1725,7 @@ void MyEventHandler::createGuiConfigWindow() { if (showConfigWindow_) { + nc::IGfxDevice &gfxDevice = nc::theApplication().gfxDevice(); const ImVec2 windowSize = ImVec2(450.0f, 450.0f); ImGui::SetNextWindowSize(windowSize, ImGuiCond_FirstUseEver); ImGui::Begin("Config", &showConfigWindow_, 0); @@ -1732,15 +1733,20 @@ void MyEventHandler::createGuiConfigWindow() LuaLoader::Config &cfg = loader_->config(); #ifdef __ANDROID__ - ImGui::Text("Screen Width: %d", nc::theApplication().widthInt()); - ImGui::Text("Screen Height: %d", nc::theApplication().heightInt()); - ImGui::Text("Resizable: false"); - ImGui::SameLine(); - ImGui::Text("Fullscreen: true"); + ImGui::Text("Screen Resolution: %d x %d", gfxDevice.width(), gfxDevice.height()); + ImGui::TextUnformatted("Resizable: false"); + ImGui::TextUnformatted("Fullscreen: true"); #else static int selectedVideoMode = -1; - const nc::IGfxDevice::VideoMode currentVideoMode = nc::theApplication().gfxDevice().currentVideoMode(); - if (cfg.fullscreen == false) + static int monitorIndex = gfxDevice.windowMonitorIndex(); + if (monitorIndex != gfxDevice.windowMonitorIndex()) + { + selectedVideoMode = -1; + monitorIndex = gfxDevice.windowMonitorIndex(); + } + const nc::IGfxDevice::VideoMode ¤tVideoMode = gfxDevice.currentVideoMode(monitorIndex); + const nc::IGfxDevice::Monitor &monitor = gfxDevice.monitor(monitorIndex); + if (cfg.fullScreen == false) { ImGui::SliderInt("Window Width", &cfg.width, 0, currentVideoMode.width); ImGui::SliderInt("Window Height", &cfg.height, 0, currentVideoMode.height); @@ -1751,12 +1757,12 @@ void MyEventHandler::createGuiConfigWindow() else { unsigned int currentVideoModeIndex = 0; - const unsigned int numVideoModes = nc::theApplication().gfxDevice().numVideoModes(); + const unsigned int numVideoModes = monitor.numVideoModes; comboString_.clear(); for (unsigned int i = 0; i < numVideoModes; i++) { - const nc::IGfxDevice::VideoMode &mode = nc::theApplication().gfxDevice().videoMode(i); - comboString_.formatAppend("%ux%u, %uHz", mode.width, mode.height, mode.refreshRate); + const nc::IGfxDevice::VideoMode &mode = monitor.videoModes[i]; + comboString_.formatAppend("%ux%u, %.2f Hz", mode.width, mode.height, mode.refreshRate); comboString_.setLength(comboString_.length() + 1); if (mode == currentVideoMode) @@ -1770,27 +1776,27 @@ void MyEventHandler::createGuiConfigWindow() selectedVideoMode = currentVideoModeIndex; ImGui::Combo("Video Mode", &selectedVideoMode, comboString_.data()); - cfg.width = nc::theApplication().gfxDevice().videoMode(selectedVideoMode).width; - cfg.height = nc::theApplication().gfxDevice().videoMode(selectedVideoMode).height; + cfg.width = monitor.videoModes[selectedVideoMode].width; + cfg.height = monitor.videoModes[selectedVideoMode].height; } - ImGui::Checkbox("Fullscreen", &cfg.fullscreen); + ImGui::Checkbox("Fullscreen", &cfg.fullScreen); ImGui::SameLine(); if (ImGui::Button(Labels::Apply)) { - nc::theApplication().gfxDevice().setFullScreen(cfg.fullscreen); - if (cfg.fullscreen == false) - nc::theApplication().gfxDevice().setResolution(cfg.width, cfg.height); - else - nc::theApplication().gfxDevice().setVideoMode(selectedVideoMode); + if (cfg.fullScreen) + gfxDevice.setVideoMode(selectedVideoMode); + gfxDevice.setFullScreen(cfg.fullScreen); + if (cfg.fullScreen == false) + gfxDevice.setWindowSize(cfg.width, cfg.height); } ImGui::SameLine(); if (ImGui::Button(Labels::Current)) { cfg.width = nc::theApplication().widthInt(); cfg.height = nc::theApplication().heightInt(); - cfg.fullscreen = nc::theApplication().gfxDevice().isFullScreen(); - cfg.resizable = nc::theApplication().gfxDevice().isResizable(); + cfg.fullScreen = gfxDevice.isFullScreen(); + cfg.resizable = gfxDevice.isResizable(); selectedVideoMode = -1; } #endif diff --git a/src/particle_editor_lua.cpp b/src/particle_editor_lua.cpp index a7ed137..3228aff 100644 --- a/src/particle_editor_lua.cpp +++ b/src/particle_editor_lua.cpp @@ -85,7 +85,7 @@ namespace CfgNames { const char *version = "config_version"; // version 2 const char *width = "width"; const char *height = "height"; - const char *fullscreen = "fullscreen"; + const char *fullScreen = "fullscreen"; const char *resizable = "resizable"; // version 8 const char *frameLimit = "frame_limit"; // version 10 const char *useBufferMapping = "buffer_mapping"; // version 9 @@ -226,7 +226,7 @@ bool LuaLoader::loadConfig(const char *filename, const nc::EmscriptenLocalFile * nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::width, config_.width); nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::height, config_.height); - nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::fullscreen, config_.fullscreen); + nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::fullScreen, config_.fullScreen); nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::vboSize, config_.vboSize); nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::iboSize, config_.iboSize); nc::LuaUtils::tryRetrieveGlobal(L, CfgNames::batching, config_.batching); @@ -324,7 +324,7 @@ bool LuaLoader::saveConfig(const char *filename) indent(file, amount).formatAppend("%s = %u\n", CfgNames::version, ConfigFileVersion); indent(file, amount).formatAppend("%s = %d\n", CfgNames::width, config_.width); indent(file, amount).formatAppend("%s = %d\n", CfgNames::height, config_.height); - indent(file, amount).formatAppend("%s = %s\n", CfgNames::fullscreen, config_.fullscreen ? "true" : "false"); + indent(file, amount).formatAppend("%s = %s\n", CfgNames::fullScreen, config_.fullScreen ? "true" : "false"); indent(file, amount).formatAppend("%s = %s\n", CfgNames::resizable, config_.resizable ? "true" : "false"); indent(file, amount).formatAppend("%s = %u\n", CfgNames::frameLimit, config_.frameLimit); indent(file, amount).formatAppend("%s = %s\n", CfgNames::useBufferMapping, config_.useBufferMapping ? "true" : "false"); diff --git a/src/particle_editor_lua.h b/src/particle_editor_lua.h index 5fd3d8c..ab96ad8 100644 --- a/src/particle_editor_lua.h +++ b/src/particle_editor_lua.h @@ -112,7 +112,7 @@ class LuaLoader { int width = 1280; int height = 720; - bool fullscreen = false; + bool fullScreen = false; bool resizable = false; unsigned int frameLimit = 0; bool useBufferMapping = false;