@@ -43,6 +43,10 @@ static const float zoomMax = 2.f; | |||||
static const float zoomMin = -2.f; | static const float zoomMin = -2.f; | ||||
/** Reverse the zoom scroll direction */ | /** Reverse the zoom scroll direction */ | ||||
extern bool invertZoom; | extern bool invertZoom; | ||||
/** Ratio between UI pixel and physical screen pixel. | |||||
0 for auto. | |||||
*/ | |||||
extern float pixelRatio; | |||||
/** Opacity of cables in the range [0, 1] */ | /** Opacity of cables in the range [0, 1] */ | ||||
extern float cableOpacity; | extern float cableOpacity; | ||||
/** Straightness of cables in the range [0, 1]. Unitless and arbitrary. */ | /** Straightness of cables in the range [0, 1]. Unitless and arbitrary. */ | ||||
@@ -435,13 +435,18 @@ void Window::step() { | |||||
internal->lastWindowTitle = windowTitle; | internal->lastWindowTitle = windowTitle; | ||||
} | } | ||||
// Get desired scaling | |||||
// Get desired pixel ratio | |||||
float newPixelRatio; | float newPixelRatio; | ||||
glfwGetWindowContentScale(win, &newPixelRatio, NULL); | |||||
newPixelRatio = std::floor(newPixelRatio + 0.5); | |||||
if (settings::pixelRatio > 0.0) { | |||||
newPixelRatio = settings::pixelRatio; | |||||
} | |||||
else { | |||||
glfwGetWindowContentScale(win, &newPixelRatio, NULL); | |||||
newPixelRatio = std::floor(newPixelRatio + 0.5); | |||||
} | |||||
if (newPixelRatio != pixelRatio) { | if (newPixelRatio != pixelRatio) { | ||||
APP->event->handleDirty(); | |||||
pixelRatio = newPixelRatio; | pixelRatio = newPixelRatio; | ||||
APP->event->handleDirty(); | |||||
} | } | ||||
// Get framebuffer/window ratio | // Get framebuffer/window ratio | ||||
@@ -26,6 +26,7 @@ math::Vec windowSize = math::Vec(1024, 768); | |||||
math::Vec windowPos = math::Vec(NAN, NAN); | math::Vec windowPos = math::Vec(NAN, NAN); | ||||
float zoom = 0.0; | float zoom = 0.0; | ||||
bool invertZoom = false; | bool invertZoom = false; | ||||
float pixelRatio = 0.0; | |||||
float cableOpacity = 0.5; | float cableOpacity = 0.5; | ||||
float cableTension = 0.5; | float cableTension = 0.5; | ||||
float rackBrightness = 1.0; | float rackBrightness = 1.0; | ||||
@@ -104,6 +105,8 @@ json_t* toJson() { | |||||
json_object_set_new(rootJ, "invertZoom", json_boolean(invertZoom)); | json_object_set_new(rootJ, "invertZoom", json_boolean(invertZoom)); | ||||
json_object_set_new(rootJ, "pixelRatio", json_real(pixelRatio)); | |||||
json_object_set_new(rootJ, "cableOpacity", json_real(cableOpacity)); | json_object_set_new(rootJ, "cableOpacity", json_real(cableOpacity)); | ||||
json_object_set_new(rootJ, "cableTension", json_real(cableTension)); | json_object_set_new(rootJ, "cableTension", json_real(cableTension)); | ||||
@@ -224,6 +227,10 @@ void fromJson(json_t* rootJ) { | |||||
if (invertZoomJ) | if (invertZoomJ) | ||||
invertZoom = json_boolean_value(invertZoomJ); | invertZoom = json_boolean_value(invertZoomJ); | ||||
json_t* pixelRatioJ = json_object_get(rootJ, "pixelRatio"); | |||||
if (pixelRatioJ) | |||||
pixelRatio = json_number_value(pixelRatioJ); | |||||
json_t* cableOpacityJ = json_object_get(rootJ, "cableOpacity"); | json_t* cableOpacityJ = json_object_get(rootJ, "cableOpacity"); | ||||
if (cableOpacityJ) | if (cableOpacityJ) | ||||
cableOpacity = json_number_value(cableOpacityJ); | cableOpacity = json_number_value(cableOpacityJ); | ||||
@@ -191,7 +191,8 @@ void FramebufferWidget::render(math::Vec scale, math::Vec offsetF, math::Rect cl | |||||
internal->fbBox = math::Rect::fromMinMax(min, max); | internal->fbBox = math::Rect::fromMinMax(min, max); | ||||
// DEBUG("%g %g %g %g", RECT_ARGS(internal->fbBox)); | // DEBUG("%g %g %g %g", RECT_ARGS(internal->fbBox)); | ||||
math::Vec newFbSize = internal->fbBox.size.mult(APP->window->pixelRatio).ceil(); | |||||
float pixelRatio = std::fmax(1.f, std::floor(APP->window->pixelRatio)); | |||||
math::Vec newFbSize = internal->fbBox.size.mult(pixelRatio).ceil(); | |||||
// Create framebuffer if a new size is needed | // Create framebuffer if a new size is needed | ||||
if (!internal->fb || !newFbSize.equals(internal->fbSize)) { | if (!internal->fb || !newFbSize.equals(internal->fbSize)) { | ||||