Sketcher: [skip ci] refactor SoDatumLabel

This commit is contained in:
wmayer
2022-11-24 11:51:26 +01:00
parent 3f29b6cfd3
commit a3971bfcfd
2 changed files with 30 additions and 19 deletions

View File

@@ -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;

View File

@@ -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 &center) override;
void generatePrimitives(SoAction * action) override;
void notify(SoNotList * l) override;
private:
float getScaleFactor(SoState*) const;
private:
void drawImage();
SbBox3f bbox;