| 40 | } |
| 41 | |
| 42 | void Simulator_GUI_imgui::init(const char *name) |
| 43 | { |
| 44 | m_logWindow = new LogWindow(); |
| 45 | |
| 46 | // Setup Dear ImGui context |
| 47 | IMGUI_CHECKVERSION(); |
| 48 | m_context = ImGui::CreateContext(); |
| 49 | |
| 50 | // Add .ini handle for UserData type |
| 51 | ImGuiSettingsHandler ini_handler; |
| 52 | ini_handler.TypeName = "SPHSimulator"; |
| 53 | ini_handler.TypeHash = ImHashStr("SPHSimulator"); |
| 54 | ini_handler.ReadOpenFn = readOpenIni; |
| 55 | ini_handler.ReadLineFn = readIni; |
| 56 | ini_handler.WriteAllFn = writeIni; |
| 57 | ini_handler.ApplyAllFn = applySettings; |
| 58 | ini_handler.UserData = this; |
| 59 | m_context->SettingsHandlers.push_back(ini_handler); |
| 60 | |
| 61 | // load ini file before window is created |
| 62 | ImGuiIO& io = ImGui::GetIO(); (void)io; |
| 63 | io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking |
| 64 | ImGui::LoadIniSettingsFromDisk(io.IniFilename); |
| 65 | |
| 66 | MiniGL::init(1280, 960, name, m_userSettings.vsync, m_userSettings.maximized, m_userSettings.alt_camera); |
| 67 | MiniGL::initLights(); |
| 68 | |
| 69 | const Utilities::SceneLoader::Scene& scene = SceneConfiguration::getCurrent()->getScene(); |
| 70 | const bool sim2D = scene.sim2D; |
| 71 | if (sim2D) |
| 72 | MiniGL::setViewport(40.0, 0.1f, 500.0, m_simulatorBase->getCameraPosition(), m_simulatorBase->getCameraLookAt()); |
| 73 | else |
| 74 | MiniGL::setViewport(40.0, 0.1f, 500.0, m_simulatorBase->getCameraPosition(), m_simulatorBase->getCameraLookAt()); |
| 75 | MiniGL::setSelectionFunc(selection, this); |
| 76 | MiniGL::addKeyFunc(GLFW_KEY_I, 0, std::bind(&Simulator_GUI_imgui::particleInfo, this)); |
| 77 | MiniGL::addKeyFunc(GLFW_KEY_S, GLFW_MOD_CONTROL, std::bind(&SimulatorBase::saveState, m_simulatorBase, "")); |
| 78 | #ifdef USE_NFD_FILE_DIALOG |
| 79 | MiniGL::addKeyFunc(GLFW_KEY_L, GLFW_MOD_CONTROL, std::bind(&SimulatorBase::loadStateDialog, m_simulatorBase)); |
| 80 | #endif |
| 81 | MiniGL::addKeyFunc(GLFW_KEY_W, GLFW_MOD_CONTROL, std::bind(&SimulatorBase::writeScene, m_simulatorBase)); |
| 82 | MiniGL::addKeyFunc(GLFW_KEY_KP_ADD, 0, std::bind(&SimulatorBase::singleTimeStep, m_simulatorBase)); |
| 83 | |
| 84 | Simulator_OpenGL::initShaders(m_simulatorBase->getExePath() + "/resources/shaders"); |
| 85 | |
| 86 | const int width = MiniGL::getWidth(); |
| 87 | const int height = MiniGL::getHeight(); |
| 88 | |
| 89 | initImgui(); |
| 90 | initImguiParameters(); |
| 91 | |
| 92 | MiniGL::addKeyboardFunc([](int key, int scancode, int action, int mods) -> bool { ImGui_ImplGlfw_KeyCallback(MiniGL::getWindow(), key, scancode, action, mods); return ImGui::GetIO().WantCaptureKeyboard; }); |
| 93 | MiniGL::addCharFunc([](int key, int action) -> bool { ImGui_ImplGlfw_CharCallback(MiniGL::getWindow(), key); return ImGui::GetIO().WantCaptureKeyboard; }); |
| 94 | MiniGL::addMousePressFunc([](int button, int action, int mods) -> bool { ImGui_ImplGlfw_MouseButtonCallback(MiniGL::getWindow(), button, action, mods); return ImGui::GetIO().WantCaptureMouse; }); |
| 95 | MiniGL::addMouseWheelFunc([](int pos, double xoffset, double yoffset) -> bool { ImGui_ImplGlfw_ScrollCallback(MiniGL::getWindow(), xoffset, yoffset); return ImGui::GetIO().WantCaptureMouse; }); |
| 96 | |
| 97 | MiniGL::setClientIdleFunc(std::bind(&SimulatorBase::timeStep, m_simulatorBase)); |
| 98 | MiniGL::setClientDestroyFunc(std::bind(&Simulator_GUI_imgui::destroy, this)); |
| 99 | MiniGL::addKeyFunc(GLFW_KEY_R, 0, std::bind(&SimulatorBase::reset, m_simulatorBase)); |
nothing calls this directly
no test coverage detected