From a3971bfcfd58c35b39f6eedfa73ade9018cb3162 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 24 Nov 2022 11:51:26 +0100 Subject: [PATCH] Sketcher: [skip ci] refactor SoDatumLabel --- src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 24 ++++++++++++++++-------- src/Mod/Sketcher/Gui/SoDatumLabel.h | 25 ++++++++++++++----------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index 285f982b7c..926d291172 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp @@ -417,15 +417,8 @@ void SoDatumLabel::notify(SoNotList * l) inherited::notify(l); } -void SoDatumLabel::GLRender(SoGLRenderAction * action) +float SoDatumLabel::getScaleFactor(SoState* state) const { - SoState *state = action->getState(); - - if (!shouldGLRender(action)) - return; - if (action->handleTransparency(true)) - return; - /**Remark from Stefan Tröger: * The scale calculation is based on knowledge of SbViewVolume::getWorldToScreenScale * implementation internals. The factor returned from this function is calculated from the view frustums @@ -448,6 +441,20 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) SbVec2s vp_size = vp.getViewportSizePixels(); scale /= float(vp_size[0]); + return scale; +} + +void SoDatumLabel::GLRender(SoGLRenderAction * action) +{ + SoState *state = action->getState(); + + if (!shouldGLRender(action)) + return; + if (action->handleTransparency(true)) + return; + + float scale = getScaleFactor(state); + const SbString* s = string.getValues(0); bool hasText = (s->getLength() > 0) ? true : false; @@ -903,6 +910,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) const unsigned char * dataptr = this->image.getValue(imgsize, nc); //Get the camera z-direction + const SbViewVolume & vv = SoViewVolumeElement::get(state); SbVec3f z = vv.zVector(); bool flip = norm.getValue().dot(z) > FLT_EPSILON; diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.h b/src/Mod/Sketcher/Gui/SoDatumLabel.h index be80cea548..7e629c78b1 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.h +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.h @@ -47,16 +47,16 @@ class SketcherGuiExport SoDatumLabel : public SoShape { SO_NODE_HEADER(SoDatumLabel); public: - enum Type - { - ANGLE, - DISTANCE, - DISTANCEX, - DISTANCEY, - RADIUS, - DIAMETER, - SYMMETRIC - }; + enum Type + { + ANGLE, + DISTANCE, + DISTANCEX, + DISTANCEY, + RADIUS, + DIAMETER, + SYMMETRIC + }; static void initClass(); SoDatumLabel(); @@ -76,12 +76,15 @@ public: bool useAntialiasing; protected: - ~SoDatumLabel() override {}; + ~SoDatumLabel() override {} void GLRender(SoGLRenderAction *action) override; void computeBBox(SoAction *, SbBox3f &box, SbVec3f ¢er) override; void generatePrimitives(SoAction * action) override; void notify(SoNotList * l) override; +private: + float getScaleFactor(SoState*) const; + private: void drawImage(); SbBox3f bbox;