From 61d185e3371c96fb99e4147e09df4cc2d2b0646f Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 27 Feb 2015 09:44:14 +0100 Subject: [PATCH] Fixing on-screen gui for multiple nodes --- include/openspace/rendering/renderengine.h | 10 ++++ src/gui/guipropertycomponent.cpp | 18 +++++- src/rendering/renderengine.cpp | 66 +++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 4127731039..b5db036f27 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -27,6 +27,9 @@ #include +#include +#include + namespace ghoul { class SharedMemory; } @@ -97,6 +100,13 @@ public: //temporaray fade functionality void startFading(int direction, float fadeDuration); + // This is temporary until a proper screenspace solution is found ---abock + struct { + glm::vec2 _position; + float _size; + int _node; + } _onScreenInformation; + private: void storePerformanceMeasurements(); diff --git a/src/gui/guipropertycomponent.cpp b/src/gui/guipropertycomponent.cpp index 633a079544..a406cda663 100644 --- a/src/gui/guipropertycomponent.cpp +++ b/src/gui/guipropertycomponent.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -426,8 +427,23 @@ void GuiPropertyComponent::handleProperty(const ghoul::Dictionary& dictionary) { void GuiPropertyComponent::render() { ImGui::Begin("Properties", &_isEnabled, size, 0.5f); + if (ImGui::CollapsingHeader("OnScreen GUI")) { + glm::vec2& pos = OsEng.renderEngine()->_onScreenInformation._position; + Vec2Property::ValueType value = pos; + ImGui::SliderFloat2("Position", &value.x, -1.f, 1.f); + pos = value; + + float& size = OsEng.renderEngine()->_onScreenInformation._size; + float fValue = size; + ImGui::SliderFloat("Size", &fValue, 0.f, 36.f); + size = fValue; + + int& node = OsEng.renderEngine()->_onScreenInformation._node; + int iValue = node; + ImGui::SliderInt("Node#", &iValue, 0, 30); + node = iValue; + } - //ImGui::ShowUserGuide(); ImGui::Spacing(); for (const auto& p : _propertiesByOwner) { diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 5a7fa9325b..4b283206ca 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -228,6 +228,11 @@ namespace openspace { , _fadeDirection(0) , _sgctRenderStatisticsVisible(false) { + _onScreenInformation = { + glm::vec2(0.f), + 12.f, + -1 + }; } RenderEngine::~RenderEngine() @@ -489,6 +494,65 @@ namespace openspace { } #if 1 +#define PrintText(i, format, ...) Freetype::print(font, 10.f, static_cast(startY - font_size_mono * i * 2), format, __VA_ARGS__); +#define PrintColorText(i, format, size, color, ...) Freetype::print(font, size, static_cast(startY - font_size_mono * i * 2), color, format, __VA_ARGS__); + + LINFO("Window id " << sgct::Engine::instance()->getWindowPtr(0)->getId()); + if (_onScreenInformation._node != -1) { + int thisId = sgct::Engine::instance()->getWindowPtr(0)->getId(); + + if (thisId == _onScreenInformation._node) { + const int font_size_mono = _onScreenInformation._size; + int x1, xSize, y1, ySize; + const sgct_text::Font* font = sgct_text::FontManager::instance()->getFont(constants::fonts::keyMono, font_size_mono); + sgct::Engine::instance()->getActiveWindowPtr()->getCurrentViewportPixelCoords(x1, y1, xSize, ySize); + int startY = ySize - 2 * font_size_mono; + + double currentTime = Time::ref().currentTime(); + ImageSequencer::ref().findActiveInstrument(currentTime); + + double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - currentTime; + double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength(); + std::string progress = "|"; + int g = ((t)* 20) + 1; + for (int i = 0; i < g; i++) progress.append("-"); progress.append(">"); + for (int i = 0; i < 21 - g; i++) progress.append(" "); + + std::string str = ""; + openspace::SpiceManager::ref().getDateFromET(openspace::ImageSequencer::ref().getNextCaptureTime(), str); + + progress.append("|"); + if (remaining > 0){ + glm::vec4 g1(0, t, 0, 1); + glm::vec4 g2(1 - t); + Freetype::print(font, + _onScreenInformation._position.x * xSize, + _onScreenInformation._position.y * ySize, + g1 + g2, + "Next projection in | %.0f seconds", + remaining + ); + Freetype::print(font, + _onScreenInformation._position.x * xSize, + _onScreenInformation._position.y * ySize - font_size_mono * 2, + g1 + g2, + "%s %.1f %%", + progress.c_str(), t * 100 + ); + + } + + std::string active = ImageSequencer::ref().getActiveInstrument(); + Freetype::print(font, + _onScreenInformation._position.x * xSize, + _onScreenInformation._position.y * ySize - font_size_mono * 2 * 2, + glm::vec4(0.3, 0.6, 1, 1), + "Active Instrument : %s", + active.c_str() + ); + + } + } // Print some useful information on the master viewport if (OsEng.ref().isMaster() && !w->isUsingFisheyeRendering()) { @@ -513,8 +577,6 @@ namespace openspace { // GUI PRINT // Using a macro to shorten line length and increase readability -#define PrintText(i, format, ...) Freetype::print(font, 10.f, static_cast(startY - font_size_mono * i * 2), format, __VA_ARGS__); -#define PrintColorText(i, format, size, color, ...) Freetype::print(font, size, static_cast(startY - font_size_mono * i * 2), color, format, __VA_ARGS__); int i = 0;