SoShapeScale: Fix SoShapeScale does not take DPI scaling into account

This commit is contained in:
PaddleStroke
2024-12-09 14:26:28 +01:00
committed by wwmayer
parent dbdbc9934e
commit 1c9ce3e028
6 changed files with 116 additions and 2 deletions

View File

@@ -1066,6 +1066,7 @@ SET(Inventor_CPP_SRCS
SoFCSelectionAction.cpp
SoFCVectorizeSVGAction.cpp
SoFCVectorizeU3DAction.cpp
SoDevicePixelRatioElement.cpp
SoTextLabel.cpp
SoDatumLabel.cpp
SoTouchEvents.cpp
@@ -1097,6 +1098,7 @@ SET(Inventor_SRCS
SoFCSelectionAction.h
SoFCVectorizeSVGAction.h
SoFCVectorizeU3DAction.h
SoDevicePixelRatioElement.h
SoTextLabel.h
SoDatumLabel.h
SoTouchEvents.h

View File

@@ -51,11 +51,10 @@
#endif
#include "SoAxisCrossKit.h"
#include "SoDevicePixelRatioElement.h"
using namespace Gui;
SO_KIT_SOURCE(SoShapeScale)
// Constructor.
@@ -101,6 +100,9 @@ SoShapeScale::GLRender(SoGLRenderAction * action)
float nsize = this->scaleFactor.getValue() / float(vp.getViewportSizePixels()[0]);
SoModelMatrixElement::get(state).multVecMatrix(center, center); // world coords
float sf = vv.getWorldToScreenScale(center, nsize);
sf *= SoDevicePixelRatioElement::get(state);
SbVec3f v(sf, sf, sf);
if (scale->scaleFactor.getValue() != v){
scale->scaleFactor = v;

View File

@@ -0,0 +1,55 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2024 Pierre-Louis Boyer <development@ondsel.com> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <Inventor/actions/SoGLRenderAction.h>
# include <Inventor/misc/SoState.h>
#endif
#include "SoDevicePixelRatioElement.h"
SO_ELEMENT_SOURCE(SoDevicePixelRatioElement);
void SoDevicePixelRatioElement::initClass() {
SO_ELEMENT_INIT_CLASS(SoDevicePixelRatioElement, SoFloatElement);
// Ensure the element is enabled for GLRenderAction
SO_ENABLE(SoGLRenderAction, SoDevicePixelRatioElement);
}
void SoDevicePixelRatioElement::init(SoState* state) {
SoFloatElement::init(state);
data = 1.0f; // Default to a device pixel ratio of 1.0
}
void SoDevicePixelRatioElement::set(SoState* state, float dpr) {
SoFloatElement::set(classStackIndex, state, dpr);
}
float SoDevicePixelRatioElement::get(SoState* state) {
return SoFloatElement::get(classStackIndex, state);
}
SoDevicePixelRatioElement::~SoDevicePixelRatioElement() {}

View File

@@ -0,0 +1,51 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/****************************************************************************
* *
* Copyright (c) 2024 Pierre-Louis Boyer <development@ondsel.com> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#ifndef SO_DEVICE_PIXEL_RATIO_ELEMENT_H
#define SO_DEVICE_PIXEL_RATIO_ELEMENT_H
#include <Inventor/elements/SoFloatElement.h>
class SoState;
class SoDevicePixelRatioElement : public SoFloatElement {
SO_ELEMENT_HEADER(SoDevicePixelRatioElement);
public:
// Initializes the class
static void initClass();
// Initializes the element
virtual void init(SoState* state) override;
// Sets the device pixel ratio
static void set(SoState* state, float dpr);
// Retrieves the device pixel ratio
static float get(SoState* state);
protected:
virtual ~SoDevicePixelRatioElement();
};
#endif // SO_DEVICE_PIXEL_RATIO_ELEMENT_H

View File

@@ -53,6 +53,7 @@
#include "GestureNavigationStyle.h"
#include "NavigationStyle.h"
#include "SelectionObject.h"
#include "SoDevicePixelRatioElement.h"
#include "SoFCColorBar.h"
#include "SoFCColorGradient.h"
#include "SoFCColorLegend.h"
@@ -94,6 +95,7 @@ SbBool Gui::SoFCDB::isInitialized()
void Gui::SoFCDB::init()
{
SoInteraction ::init();
SoDevicePixelRatioElement ::initClass();
SoGLRenderActionElement ::initClass();
SoFCInteractiveElement ::initClass();
SoGLWidgetElement ::initClass();

View File

@@ -107,6 +107,7 @@
#include "NaviCube.h"
#include "NavigationStyle.h"
#include "Selection.h"
#include "SoDevicePixelRatioElement.h"
#include "SoFCDB.h"
#include "SoFCInteractiveElement.h"
#include "SoFCOffscreenRenderer.h"
@@ -2360,6 +2361,7 @@ void View3DInventorViewer::renderScene()
// Render our scenegraph with the image.
SoGLRenderAction* glra = this->getSoRenderManager()->getGLRenderAction();
SoState* state = glra->getState();
SoDevicePixelRatioElement::set(state, devicePixelRatio());
SoGLWidgetElement::set(state, qobject_cast<QtGLWidget*>(this->getGLWidget()));
SoGLRenderActionElement::set(state, glra);
SoGLVBOActivatedElement::set(state, this->vboEnabled);