Commit caff066b authored by Matthias Möller's avatar Matthias Möller
Browse files

add ruleroffset for better ruler position

refs #1626

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17432 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 35caf4f8
......@@ -102,7 +102,8 @@ TextNode( BaseNode* _parent,
depthEnabled_(false),
alwaysOnTop_(_alwaysOnTop),
blendSrc_(0),
blendDest_(0)
blendDest_(0),
lastScale_(0.f)
{
updateFont();
......@@ -635,6 +636,7 @@ void TextNode::applyScreenAligned(GLState &_state)
ACG::Vec3d nullUnproj = _state.unproject(nullProj);
ACG::Vec3d heightUnproj = _state.unproject(nullProj+ACG::Vec3d(0.0,pixelSize_,0.0));
scale *= heightUnproj.length();
lastScale_ = scale;
}
_state.scale(scale);
......
......@@ -158,6 +158,14 @@ public:
/// sets the font to be used for generating a texture with most characters of the chosen font
void setFont(const QFont& _font);
/** \brief returns the scaling factor for screen aligned text the text. returns 0, if textmode is not SCREEN_ALIGNED_STATIC_SIZE
*
* screen aligned static size text will be scaled up/down in 3d space to achieve the static size in screen space
* lastScale returns the last scaling factor where the text was multiplied, to compute e.g. a distance
* which is also static in screen space
*/
float lastScale() {return lastScale_;};
protected:
/**
* Generates a texture by drawing most characters into one texture.
......@@ -237,6 +245,9 @@ private:
/// stores the vertex declaration
ACG::VertexDeclaration vertexDecl_;
/// stores the last scaling factor the text computed to SCREEN_ALIGNED_STATIC_SIZE
float lastScale_;
/// maps most readable characters to indices for texture coordinate calculation in updateVBO()
static std::map< char, std::pair<unsigned int, unsigned int> > charToIndex_;
......
......@@ -9,6 +9,7 @@ Ruler::Ruler(BaseObjectData* _obj,const QString &_pluginName, unsigned index)
lineNode_(0),
textNode_(0),
textTransformNode_(0),
offset_(),
obj_(_obj)
{
points_[0] = points_[1] = ACG::Vec3d(0.0,0.0,0.0);
......@@ -89,11 +90,18 @@ void Ruler::updateNodes()
textNode_->setText(distanceStr.toStdString());
textNode_->multipassNodeSetActive(8, true);
//translate and scale text
textTransformNode_->loadIdentity();
textTransformNode_->translate(Point1);
ACG::Vec3d halfDist = distVec/2.f;
textTransformNode_->translate(-halfDist);
//translate
setTextOffset(offset_);
emit updateView();
}
void Ruler::setTextOffset(const ACG::Vec3d& offset)
{
offset_ = offset;
ACG::Vec3d distVec = points_[0] - points_[1];
ACG::Vec3d halfDist = distVec/2.f;
textTransformNode_->loadIdentity();
textTransformNode_->translate((points_[0]-halfDist)+offset_);
}
......@@ -65,13 +65,17 @@ public:
void setPoints(const ACG::Vec3d& _start,const ACG::Vec3d& _end);
void setStartPoint(const ACG::Vec3d& _start);
void setEndPoint(const ACG::Vec3d& _end);
void setTextOffset(const ACG::Vec3d& offset);
const ACG::Vec3d* points() const{return points_;}
const BaseObject* getBaseObj(){return obj_;}
float textScale(){return textNode_->lastScale();}
public slots:
// set text size in pixels
void setTextSize(const unsigned _size){textNode_->setPixelSize(_size); emit updateView();}
private:
......@@ -88,5 +92,6 @@ private:
ACG::SceneGraph::TransformNode* textTransformNode_;
ACG::Vec3d points_[2];
ACG::Vec3d offset_;
BaseObjectData* obj_;
};
......@@ -53,6 +53,7 @@ buttonAction_(0),
pickModeName_("MeasureDistance"),
lineDrag_(-1),
dblClickCheck_(false),
viewupdated_(false),
optionsWidget_(0),
textSizeSettingName_(name()+QString("/TextSize"))
{
......@@ -194,11 +195,10 @@ void RulerPlugin::slotMouseEvent(QMouseEvent* _event)
currentRuler_->setPoints(hitPoints[0],hitPoints[1]);
}
///////////////////////Reset/////////////////////////////////
else if (_event->type() == QEvent::MouseButtonDblClick)
{//reset
reset();
currentRuler_.reset();
dblClickCheck_ = true;
}
if (dblClickCheck_ && _event->type() == QEvent::MouseButtonRelease)
......@@ -208,6 +208,7 @@ void RulerPlugin::slotMouseEvent(QMouseEvent* _event)
//------------------------------------------------------------------------------
void RulerPlugin::reset()
{
currentRuler_.reset();
lineDrag_ = -1;
}
//------------------------------------------------------------------------------
......@@ -277,6 +278,49 @@ void RulerPlugin::applyOptions()
currentRuler_->setTextSize(textSize);
OpenFlipperSettings().setValue(textSizeSettingName_,textSize);
}
//------------------------------------------------------------------------------
void RulerPlugin::slotViewChanged()
{
if (!currentRuler_)
return;
// check, if this function requested a viewupdate
if (viewupdated_)
{
viewupdated_ = false;
return;
}
//compute line direction
ACG::Vec3d lineVector = currentRuler_->points()[0] - currentRuler_->points()[1];
ACG::Vec3d rightVec = (PluginFunctions::viewingDirection() % -PluginFunctions::upVector()).normalize();
float cosAngleLineRight = lineVector.normalize() | rightVec;
float cosAngleUpLine = PluginFunctions::upVector().normalized() | lineVector.normalized() ;
rightVec *= -0.5f*currentRuler_->textScale();
ACG::Vec3d updownVec = PluginFunctions::upVector()*currentRuler_->textScale();
//compute up/down offset
if (cosAngleLineRight > 0.f)
{
updownVec *= (cosAngleUpLine < 0.f) ? -2.f : 0.5f;
}
else
{
updownVec *= (cosAngleUpLine < 0.f) ? 0.5f : -2.0f;
}
// small offset to the right and big offset up/down depending on the line
currentRuler_->setTextOffset(rightVec+updownVec);
viewupdated_ = true;
emit updateView();
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( rulerPlugin , RulerPlugin );
......
......@@ -55,10 +55,6 @@
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/OptionsInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include "Ruler.hh"
#include "RulerOptions.hh"
......@@ -91,7 +87,7 @@ public slots:
void slotMouseEvent(QMouseEvent* _event);
void slotViewChanged();
public:
// OptionsInterface
......@@ -123,6 +119,8 @@ private:
//checks if a double click was provided for resetting
bool dblClickCheck_;
bool viewupdated_;
ptr::shared_ptr<Ruler> currentRuler_;
RulerOptions* optionsWidget_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment