Gui: add method to convert between QPoint and SbVec2s considering device pixel ratio

This commit is contained in:
wmayer
2023-04-08 12:37:15 +02:00
committed by wwmayer
parent 88caeca1b2
commit 6509cc72e7
3 changed files with 53 additions and 2 deletions

View File

@@ -2424,6 +2424,34 @@ SbVec2s View3DInventorViewer::getPointOnScreen(const SbVec3f& pnt) const
return SbVec2s(x, y);
}
QPoint View3DInventorViewer::toQPoint(const SbVec2s& pnt) const
{
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
const SbVec2s& vps = vp.getViewportSizePixels();
int xpos = pnt[0];
int ypos = vps[1] - pnt[0] - 1;
qreal dev_pix_ratio = devicePixelRatio();
xpos = int(std::roundf(xpos / dev_pix_ratio));
ypos = int(std::roundf(ypos / dev_pix_ratio));
return QPoint(xpos, ypos);
}
SbVec2s View3DInventorViewer::fromQPoint(const QPoint& pnt) const
{
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
const SbVec2s& vps = vp.getViewportSizePixels();
int xpos = pnt.x();
int ypos = pnt.y();
qreal dev_pix_ratio = devicePixelRatio();
xpos = int(std::roundf(xpos * dev_pix_ratio));
ypos = int(std::roundf(ypos * dev_pix_ratio));
return SbVec2s(short(xpos), vps[1] - short(ypos) - 1);
}
void View3DInventorViewer::getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const
{
SoCamera* pCam = getSoRenderManager()->getCamera();