From c3cc53f08df54ba20bc8c828e30f56777d829bd6 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Sat, 19 Jan 2019 19:16:56 -0500 Subject: [PATCH] Make it possible to rescale web gui --- modules/cefwebgui/cefwebguimodule.cpp | 22 +++++++++++++++++++- modules/cefwebgui/cefwebguimodule.h | 2 ++ modules/webbrowser/include/browserinstance.h | 8 +++++++ modules/webbrowser/src/browserinstance.cpp | 10 +++++++++ openspace.cfg | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/modules/cefwebgui/cefwebguimodule.cpp b/modules/cefwebgui/cefwebguimodule.cpp index 6d649a95cd..74478683e2 100644 --- a/modules/cefwebgui/cefwebguimodule.cpp +++ b/modules/cefwebgui/cefwebguimodule.cpp @@ -57,6 +57,12 @@ namespace { "GUI URL", "The URL of the webpage that is used to load the WebGUI from." }; + + constexpr openspace::properties::Property::PropertyInfo GuiScaleInfo = { + "GuiScale", + "Gui Scale", + "GUI scale multiplier." + }; } // namespace namespace openspace { @@ -66,10 +72,12 @@ CefWebGuiModule::CefWebGuiModule() , _enabled(EnabledInfo, true) , _visible(VisibleInfo, true) , _url(GuiUrlInfo, "") + , _guiScale(GuiScaleInfo, 1.0, 0.1, 3.0) { addProperty(_enabled); addProperty(_visible); addProperty(_url); + addProperty(_guiScale); } void CefWebGuiModule::startOrStopGui() { @@ -95,6 +103,9 @@ void CefWebGuiModule::startOrStopGui() { if (_visible) { webBrowserModule->attachEventHandler(_instance.get()); } + + _instance->setZoom(2.0); + webBrowserModule->addBrowser(_instance.get()); } else if (_instance) { _instance->close(true); @@ -124,6 +135,12 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) } }); + _guiScale.onChange([this]() { + if (_instance) { + _instance->setZoom(_guiScale); + } + }); + _visible.onChange([this, webBrowserModule]() { if (_visible && _instance) { webBrowserModule->attachEventHandler(_instance.get()); @@ -132,7 +149,6 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) } }); - if (configuration.hasValue(GuiUrlInfo.identifier)) { _url = configuration.value(GuiUrlInfo.identifier); } else { @@ -141,6 +157,10 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) std::to_string(webGuiModule->port()) + "/#/onscreen"; } + if (configuration.hasValue(GuiScaleInfo.identifier)) { + _guiScale = configuration.value(GuiScaleInfo.identifier); + } + _enabled = configuration.hasValue(EnabledInfo.identifier) && configuration.value(EnabledInfo.identifier); diff --git a/modules/cefwebgui/cefwebguimodule.h b/modules/cefwebgui/cefwebguimodule.h index e506248c14..f2960a15bc 100644 --- a/modules/cefwebgui/cefwebguimodule.h +++ b/modules/cefwebgui/cefwebguimodule.h @@ -28,6 +28,7 @@ #include #include +#include #include namespace openspace { @@ -48,6 +49,7 @@ private: properties::BoolProperty _enabled; properties::BoolProperty _visible; properties::StringProperty _url; + properties::FloatProperty _guiScale; std::unique_ptr _instance; }; diff --git a/modules/webbrowser/include/browserinstance.h b/modules/webbrowser/include/browserinstance.h index aa5261d3fd..99457043e9 100644 --- a/modules/webbrowser/include/browserinstance.h +++ b/modules/webbrowser/include/browserinstance.h @@ -99,6 +99,13 @@ public: * \return if this scroll should be blocked or not */ bool sendMouseWheelEvent(const CefMouseEvent& event, const glm::ivec2& delta); + + /** + * Set the browser zoom level. + * 1.0 = default, 2.0 = double, etc. + */ + void setZoom(float ratio); + void reloadBrowser(); const CefRefPtr& getBrowser() const; @@ -111,6 +118,7 @@ private: CefRefPtr _client; CefRefPtr _browser; bool _isInitialized = false; + double _zoomLevel = 1.0; }; } // namespace openspace diff --git a/modules/webbrowser/src/browserinstance.cpp b/modules/webbrowser/src/browserinstance.cpp index 9ecccc4fd1..bc92ce429a 100644 --- a/modules/webbrowser/src/browserinstance.cpp +++ b/modules/webbrowser/src/browserinstance.cpp @@ -97,6 +97,9 @@ void BrowserInstance::reshape(const glm::ivec2& windowSize) { } void BrowserInstance::draw() { + if (_zoomLevel != _browser->GetHost()->GetZoomLevel()) { + _browser->GetHost()->SetZoomLevel(_zoomLevel); + } _renderHandler->draw(); } @@ -142,6 +145,13 @@ bool BrowserInstance::sendMouseWheelEvent(const CefMouseEvent& event, return hasContent(event.x, event.y); } +void BrowserInstance::setZoom(float ratio) { + //Zooming in CEF is non-linear according to this: + //https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11491 + _zoomLevel = glm::log(static_cast(ratio))/glm::log(1.2); + _browser->GetHost()->SetZoomLevel(_zoomLevel); +} + void BrowserInstance::reloadBrowser() { _browser->Reload(); } diff --git a/openspace.cfg b/openspace.cfg index 5a4e163781..58e0446fca 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -121,6 +121,7 @@ ModuleConfigurations = { }, CefWebGui = { -- GuiUrl = "http://localhost:4680/#/onscreen/", + -- GuiScale = 2.0, Enabled = true, Visible = true }