Make it possible to rescale web gui

This commit is contained in:
Emil Axelsson
2019-01-19 19:16:56 -05:00
parent c7639adb15
commit c3cc53f08d
5 changed files with 42 additions and 1 deletions
+21 -1
View File
@@ -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<std::string>(GuiUrlInfo.identifier)) {
_url = configuration.value<std::string>(GuiUrlInfo.identifier);
} else {
@@ -141,6 +157,10 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration)
std::to_string(webGuiModule->port()) + "/#/onscreen";
}
if (configuration.hasValue<float>(GuiScaleInfo.identifier)) {
_guiScale = configuration.value<float>(GuiScaleInfo.identifier);
}
_enabled = configuration.hasValue<bool>(EnabledInfo.identifier) &&
configuration.value<bool>(EnabledInfo.identifier);
+2
View File
@@ -28,6 +28,7 @@
#include <openspace/util/openspacemodule.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/stringproperty.h>
namespace openspace {
@@ -48,6 +49,7 @@ private:
properties::BoolProperty _enabled;
properties::BoolProperty _visible;
properties::StringProperty _url;
properties::FloatProperty _guiScale;
std::unique_ptr<BrowserInstance> _instance;
};
@@ -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<CefBrowser>& getBrowser() const;
@@ -111,6 +118,7 @@ private:
CefRefPtr<BrowserClient> _client;
CefRefPtr<CefBrowser> _browser;
bool _isInitialized = false;
double _zoomLevel = 1.0;
};
} // namespace openspace
@@ -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<double>(ratio))/glm::log(1.2);
_browser->GetHost()->SetZoomLevel(_zoomLevel);
}
void BrowserInstance::reloadBrowser() {
_browser->Reload();
}
+1
View File
@@ -121,6 +121,7 @@ ModuleConfigurations = {
},
CefWebGui = {
-- GuiUrl = "http://localhost:4680/#/onscreen/",
-- GuiScale = 2.0,
Enabled = true,
Visible = true
}