Skip to content

Commit

Permalink
Fix compilation with the hidpi nCine branch
Browse files Browse the repository at this point in the history
  • Loading branch information
encelo committed Dec 7, 2022
1 parent b7a80b8 commit fa95f81
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/particle_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 26 additions & 20 deletions src/particle_editor_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,22 +1725,28 @@ 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);

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 &currentVideoMode = 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);
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/particle_editor_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -226,7 +226,7 @@ bool LuaLoader::loadConfig(const char *filename, const nc::EmscriptenLocalFile *

nc::LuaUtils::tryRetrieveGlobal<int32_t>(L, CfgNames::width, config_.width);
nc::LuaUtils::tryRetrieveGlobal<int32_t>(L, CfgNames::height, config_.height);
nc::LuaUtils::tryRetrieveGlobal<bool>(L, CfgNames::fullscreen, config_.fullscreen);
nc::LuaUtils::tryRetrieveGlobal<bool>(L, CfgNames::fullScreen, config_.fullScreen);
nc::LuaUtils::tryRetrieveGlobal<unsigned long>(L, CfgNames::vboSize, config_.vboSize);
nc::LuaUtils::tryRetrieveGlobal<unsigned long>(L, CfgNames::iboSize, config_.iboSize);
nc::LuaUtils::tryRetrieveGlobal<bool>(L, CfgNames::batching, config_.batching);
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/particle_editor_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fa95f81

Please sign in to comment.