Made GUI optional

This commit is contained in:
Alexander Bock
2014-12-06 18:33:11 +01:00
parent 40415a2eee
commit 2c85d53164
4 changed files with 83 additions and 47 deletions

View File

@@ -45,6 +45,7 @@ namespace configurationmanager {
const std::string keyLuaDocumentationType = "LuaDocumentationFile.Type";
const std::string keyLuaDocumentationFile = "LuaDocumentationFile.File";
const std::string keyConfigScene = "Scene";
const std::string keyEnableGui = "EnableGUI";
const std::string keyStartupScript = "StartupScripts";
const std::string keySpiceTimeKernel = "SpiceKernel.Time";
const std::string keySpiceLeapsecondKernel = "SpiceKernel.LeapSecond";

View File

@@ -19,22 +19,23 @@ return {
Mono = "${FONTS}/Droid_Sans_Mono/DroidSansMono.ttf",
Light = "${FONTS}/Roboto/Roboto-Regular.ttf"
},
SGCTConfig = "${SGCT}/single.xml",
--SGCTConfig = "${SGCT}/two_nodes.xml",
--SGCTConfig = "${SGCT}/single_sbs_stereo.xml",
Scene = "${OPENSPACE_DATA}/scene/default.scene",
StartupScripts = {
"${SCRIPTS}/default_startup.lua"
},
Logging = {
StartupScripts = {
"${SCRIPTS}/default_startup.lua"
},
Logging = {
LogLevel = "Debug",
ImmediateFlush = true,
Logs = {
{ Type = "HTML", FileName = "${BASE_PATH}/log.html", Append = false }
}
},
LuaDocumentationFile = {
Type = "text",
File = "${BASE_PATH}/LuaScripting.txt"
}
Logs = {
{ Type = "HTML", FileName = "${BASE_PATH}/log.html", Append = false }
}
},
LuaDocumentationFile = {
Type = "text",
File = "${BASE_PATH}/LuaScripting.txt"
},
EnableGUI = true,
SGCTConfig = "${SGCT}/single.xml",
--SGCTConfig = "${SGCT}/two_nodes.xml",
--SGCTConfig = "${SGCT}/single_sbs_stereo.xml",
Scene = "${OPENSPACE_DATA}/scene/default.scene",
}

View File

@@ -37,6 +37,9 @@
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/optionproperty.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/cachemanager.h>
#include <imgui.h>
#include <sgct.h>
#define STB_IMAGE_IMPLEMENTATION
@@ -44,6 +47,7 @@
namespace {
const std::string _loggerCat = "GUI";
const std::string configurationFile = "imgui.ini";
GLuint fontTex = 0;
GLint positionLocation = 0;
@@ -132,7 +136,11 @@ static void ImImpl_RenderDrawLists(ImDrawList** const commandLists, int nCommand
namespace openspace {
GUI::GUI() {
std::string cachedFile;
FileSys.cacheManager()->getCachedFile(configurationFile, "", cachedFile, true);
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = cachedFile.c_str();
io.DeltaTime = 1.f / 60.f;
io.PixelCenterOffset = 0.5f;
io.KeyMap[ImGuiKey_Tab] = SGCT_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
@@ -371,7 +379,21 @@ void renderVec3Property(properties::Property* prop, const std::string& ownerName
void GUI::renderGuiElements() {
using namespace properties;
ImGui::Begin("Properties");
const ImVec2 size = ImVec2(350, 500);
ImGui::Begin("Properties", nullptr, size, 0.5f);
ImGuiIO& io = ImGui::GetIO();
ImVec2 displaySize = io.DisplaySize;
ImVec2 position;
position.x = displaySize.x - (size.x + 50);
position.y = 50;
ImGui::SetWindowPos(position);
//ImGui::ShowUserGuide();
ImGui::Spacing();
for (auto p : _propertiesByOwner) {
if (ImGui::CollapsingHeader(p.first.c_str())) {

View File

@@ -113,7 +113,6 @@ void OpenSpaceEngine::clearAllWindows() {
GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle();
glfwSwapBuffers(win);
}
}
bool OpenSpaceEngine::gatherCommandlineArguments() {
@@ -437,10 +436,6 @@ bool OpenSpaceEngine::initialize() {
if (success)
sceneGraph->scheduleLoadSceneFile(sceneDescriptionPath);
// Initialize OpenSpace input devices
//DeviceIdentifier::init();
//DeviceIdentifier::ref().scanDevices();
_interactionHandler.setKeyboardController(new interaction::KeyboardControllerFixed);
//_interactionHandler.setKeyboardController(new interaction::KeyboardControllerLua);
_interactionHandler.setMouseController(new interaction::TrackballMouseController);
@@ -451,7 +446,12 @@ bool OpenSpaceEngine::initialize() {
// Load a light and a monospaced font
loadFonts();
_gui = new GUI;
using constants::configurationmanager::keyEnableGui;
bool enableGUI = false;
configurationManager().getValue(keyEnableGui, enableGUI);
if (enableGUI) {
_gui = new GUI;
}
return true;
}
@@ -478,7 +478,8 @@ LuaConsole& OpenSpaceEngine::console() {
bool OpenSpaceEngine::initializeGL() {
bool success = _renderEngine.initializeGL();
_gui->initializeGL();
if (_gui)
_gui->initializeGL();
return success;
}
@@ -498,19 +499,20 @@ void OpenSpaceEngine::preSynchronization() {
void OpenSpaceEngine::postSynchronizationPreDraw() {
_renderEngine.postSynchronizationPreDraw();
double posX, posY;
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
if (_gui) {
double posX, posY;
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
int x,y;
sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y);
int x,y;
sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y);
int button0 = sgct::Engine::instance()->getMouseButton(0, 0);
int button1 = sgct::Engine::instance()->getMouseButton(0, 1);
bool buttons[2] = { button0 != 0, button1 != 0 };
int button0 = sgct::Engine::instance()->getMouseButton(0, 0);
int button1 = sgct::Engine::instance()->getMouseButton(0, 1);
bool buttons[2] = { button0 != 0, button1 != 0 };
double dt = std::max(sgct::Engine::instance()->getDt(), 1.0/60.0);
_gui->startFrame(dt, glm::vec2(glm::ivec2(x,y)), glm::vec2(posX, posY), buttons);
double dt = std::max(sgct::Engine::instance()->getDt(), 1.0/60.0);
_gui->startFrame(dt, glm::vec2(glm::ivec2(x,y)), glm::vec2(posX, posY), buttons);
}
}
void OpenSpaceEngine::render() {
@@ -521,7 +523,9 @@ void OpenSpaceEngine::render() {
if (sgct::Engine::instance()->isMaster() && !w->isUsingFisheyeRendering() && _console.isVisible()) {
_console.render();
}
_gui->endFrame();
if (_gui)
_gui->endFrame();
}
void OpenSpaceEngine::postDraw() {
@@ -533,9 +537,11 @@ void OpenSpaceEngine::postDraw() {
void OpenSpaceEngine::keyboardCallback(int key, int action) {
if (sgct::Engine::instance()->isMaster()) {
bool isConsumed = _gui->keyCallback(key, action);
if (isConsumed)
return;
if (_gui) {
bool isConsumed = _gui->keyCallback(key, action);
if (isConsumed)
return;
}
if (key == _console.commandInputButton() && (action == SGCT_PRESS || action == SGCT_REPEAT))
_console.toggleVisibility();
@@ -550,9 +556,11 @@ void OpenSpaceEngine::keyboardCallback(int key, int action) {
}
void OpenSpaceEngine::charCallback(unsigned int codepoint) {
bool isConsumed = _gui->charCallback(codepoint);
if (isConsumed)
return;
if (_gui) {
bool isConsumed = _gui->charCallback(codepoint);
if (isConsumed)
return;
}
if (_console.isVisible()) {
_console.charCallback(codepoint);
@@ -560,9 +568,11 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint) {
}
void OpenSpaceEngine::mouseButtonCallback(int key, int action) {
bool isConsumed = _gui->mouseButtonCallback(key, action);
if (isConsumed && action != SGCT_RELEASE)
return;
if (_gui) {
bool isConsumed = _gui->mouseButtonCallback(key, action);
if (isConsumed && action != SGCT_RELEASE)
return;
}
_interactionHandler.mouseButtonCallback(key, action);
}
@@ -572,9 +582,11 @@ void OpenSpaceEngine::mousePositionCallback(int x, int y) {
}
void OpenSpaceEngine::mouseScrollWheelCallback(int pos) {
bool isConsumed = _gui->mouseWheelCallback(pos);
if (isConsumed)
return;
if (_gui) {
bool isConsumed = _gui->mouseWheelCallback(pos);
if (isConsumed)
return;
}
_interactionHandler.mouseScrollWheelCallback(pos);
}