More work on GUI components

This commit is contained in:
Alexander Bock
2014-12-19 13:17:42 +01:00
parent cd012548af
commit 7007353687
9 changed files with 115 additions and 22 deletions
+5 -1
View File
@@ -55,9 +55,13 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE )
endif(NOT CMAKE_BUILD_TYPE)
if (APPLE )
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
endif ()
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif ()
#########################################################################################
# External Third-party software
#########################################################################################
+2 -1
View File
@@ -25,7 +25,7 @@
#ifndef __GUI_H__
#define __GUI_H__
#include <openspace/gui/guicomponent.h>
#include <openspace/gui/guihelpcomponent.h>
#include <openspace/gui/guiperformancecomponent.h>
#include <openspace/gui/guipropertycomponent.h>
#include <openspace/scripting/scriptengine.h>
@@ -61,6 +61,7 @@ public:
//protected:
GuiPerformanceComponent _performance;
GuiPropertyComponent _property;
GuiHelpComponent _help;
bool _isEnabled;
+5 -1
View File
@@ -28,11 +28,15 @@
namespace openspace {
namespace gui {
class GUI;
/**
* The base class for a GUI component that can be rendered to the screen.
*/
class GuiComponent {
public:
friend class GUI;
/**
* Returns if this component is enabled, that is, if it is currently active and
* visible on the screen.
@@ -64,7 +68,7 @@ public:
protected:
/// <code>true</code> if this component is enabled and visible on the screen
bool _isEnabled;
bool _isEnabled = false;
};
} // namespace gui
+41
View File
@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __GUIHELPCOMPONENT_H__
#define __GUIHELPCOMPONENT_H__
#include <openspace/gui/guicomponent.h>
namespace openspace {
namespace gui {
class GuiHelpComponent : public GuiComponent {
public:
void render();
};
} // namespace gui
} // namespace openspace
#endif // __GUIHELPCOMPONENT_H__
@@ -37,11 +37,12 @@ namespace gui {
class GuiPerformanceComponent : public GuiComponent {
public:
void initialize();
void deinitialize();
void render();
protected:
ghoul::SharedMemory* _performanceMemory;
ghoul::SharedMemory* _performanceMemory = nullptr;
float _minMaxValues[2];
};
+8 -17
View File
@@ -1,4 +1,3 @@
GUI
/*****************************************************************************************
* *
* OpenSpace *
@@ -180,6 +179,7 @@ void GUI::initialize() {
_property.initialize();
_performance.initialize();
_help.initialize();
}
void GUI::initializeGL() {
@@ -221,6 +221,7 @@ void GUI::initializeGL() {
_property.initializeGL();
_performance.initializeGL();
_help.initializeGL();
}
void GUI::deinitializeGL() {
@@ -233,6 +234,7 @@ void GUI::deinitializeGL() {
_property.deinitializeGL();
_performance.deinitializeGL();
_help.deinitializeGL();
}
void GUI::startFrame(float deltaTime,
@@ -252,13 +254,14 @@ void GUI::startFrame(float deltaTime,
void GUI::endFrame() {
static bool show = true;
//ImGui::ShowTestWindow(&show);
renderMainWindow();
if (_property.isEnabled())
_property.render();
if (_performance.isEnabled())
_performance.render();
if (_help.isEnabled())
_help.render();
ImGui::Render();
}
@@ -303,21 +306,9 @@ bool GUI::charCallback(unsigned int character) {
void GUI::renderMainWindow() {
ImGui::Begin("OpenSpace GUI", nullptr);
bool showPropertyWindow = _property.isEnabled();
ImGui::Checkbox("Properties", &showPropertyWindow);
_property.setEnabled(showPropertyWindow);
bool showPerformanceWindow = _performance.isEnabled();
ImGui::Checkbox("Performance", &showPerformanceWindow);
_performance.setEnabled(showPerformanceWindow);
ImGui::Checkbox("Help", &_showHelp);
if (_showHelp) {
ImGui::Separator();
ImGui::ShowUserGuide();
ImGui::ShowTestWindow();
}
ImGui::Checkbox("Properties", &_property._isEnabled);
ImGui::Checkbox("Performance", &_performance._isEnabled);
ImGui::Checkbox("Help", &_help._isEnabled);
ImGui::End();
}
+43
View File
@@ -0,0 +1,43 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/gui/guihelpcomponent.h>
#include "imgui.h"
namespace {
const ImVec2 size = ImVec2(350, 500);
}
namespace openspace {
namespace gui {
void GuiHelpComponent::render() {
ImGui::Begin("Help", &_isEnabled, size, 0.5f);
ImGui::ShowUserGuide();
ImGui::End();
}
} // gui
} // openspace
+8
View File
@@ -37,6 +37,13 @@ namespace openspace {
namespace gui {
void GuiPerformanceComponent::initialize() {
_minMaxValues[0] = 100.f;
_minMaxValues[1] = 250.f;
}
void GuiPerformanceComponent::deinitialize() {
delete _performanceMemory;
_performanceMemory = nullptr;
}
void GuiPerformanceComponent::render() {
@@ -77,6 +84,7 @@ void GuiPerformanceComponent::render() {
if (!_performanceMemory)
_performanceMemory = new ghoul::SharedMemory(RenderEngine::PerformanceMeasurementSharedData);
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(_performanceMemory->pointer());
for (int i = 0; i < layout->nEntries; ++i) {