Browse Source

Add pixelRatio to settings.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
8caf9842b8
4 changed files with 22 additions and 5 deletions
  1. +4
    -0
      include/settings.hpp
  2. +9
    -4
      src/Window.cpp
  3. +7
    -0
      src/settings.cpp
  4. +2
    -1
      src/widget/FramebufferWidget.cpp

+ 4
- 0
include/settings.hpp View File

@@ -43,6 +43,10 @@ static const float zoomMax = 2.f;
static const float zoomMin = -2.f;
/** Reverse the zoom scroll direction */
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] */
extern float cableOpacity;
/** Straightness of cables in the range [0, 1]. Unitless and arbitrary. */


+ 9
- 4
src/Window.cpp View File

@@ -435,13 +435,18 @@ void Window::step() {
internal->lastWindowTitle = windowTitle;
}

// Get desired scaling
// Get desired pixel ratio
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) {
APP->event->handleDirty();
pixelRatio = newPixelRatio;
APP->event->handleDirty();
}

// Get framebuffer/window ratio


+ 7
- 0
src/settings.cpp View File

@@ -26,6 +26,7 @@ math::Vec windowSize = math::Vec(1024, 768);
math::Vec windowPos = math::Vec(NAN, NAN);
float zoom = 0.0;
bool invertZoom = false;
float pixelRatio = 0.0;
float cableOpacity = 0.5;
float cableTension = 0.5;
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, "pixelRatio", json_real(pixelRatio));

json_object_set_new(rootJ, "cableOpacity", json_real(cableOpacity));

json_object_set_new(rootJ, "cableTension", json_real(cableTension));
@@ -224,6 +227,10 @@ void fromJson(json_t* rootJ) {
if (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");
if (cableOpacityJ)
cableOpacity = json_number_value(cableOpacityJ);


+ 2
- 1
src/widget/FramebufferWidget.cpp View File

@@ -191,7 +191,8 @@ void FramebufferWidget::render(math::Vec scale, math::Vec offsetF, math::Rect cl
internal->fbBox = math::Rect::fromMinMax(min, max);
// 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
if (!internal->fb || !newFbSize.equals(internal->fbSize)) {


Loading…
Cancel
Save