2010-10-01 01:32:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* MeshLab o o *
|
|
|
|
* An extendible mesh processor o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2005, 2009 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef VCG_WRAP_QT_GLLABEL_H
|
|
|
|
#define VCG_WRAP_QT_GLLABEL_H
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <wrap/qt/col_qt_convert.h>
|
2010-10-01 10:57:46 +02:00
|
|
|
#include <wrap/qt/checkGLError.h>
|
2010-10-04 10:45:30 +02:00
|
|
|
#include <QPainter>
|
2010-10-01 01:32:26 +02:00
|
|
|
namespace vcg
|
|
|
|
{
|
2010-10-31 14:06:03 +01:00
|
|
|
/*
|
|
|
|
*/
|
2010-10-01 01:32:26 +02:00
|
|
|
class glLabel
|
|
|
|
{
|
|
|
|
public:
|
2010-10-31 14:06:03 +01:00
|
|
|
class Mode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Mode()
|
|
|
|
{
|
|
|
|
color=vcg::Color4b(vcg::Color4b::White);
|
|
|
|
angle=0;
|
|
|
|
rightAlign = false;
|
|
|
|
qFont.setStyleStrategy(QFont::NoAntialias);
|
|
|
|
qFont.setFamily("Helvetica");
|
|
|
|
qFont.setPixelSize(12);
|
|
|
|
}
|
|
|
|
|
|
|
|
Mode(QFont &_qFont, vcg::Color4b _color, float _angle,bool _rightAlign)
|
|
|
|
{
|
|
|
|
qFont=_qFont;
|
|
|
|
color=_color;
|
|
|
|
angle=_angle;
|
|
|
|
rightAlign=_rightAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
float angle;
|
|
|
|
bool rightAlign;
|
|
|
|
vcg::Color4b color;
|
|
|
|
QFont qFont;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void enter2D(QPainter *painter)
|
|
|
|
{
|
|
|
|
glPushAttrib(GL_ENABLE_BIT);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
painter->endNativePainting();
|
|
|
|
painter->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exit2D(QPainter *painter)
|
|
|
|
{
|
2013-03-24 20:50:48 +01:00
|
|
|
//checkGLError::qDebug("glLabel");
|
2010-10-31 14:06:03 +01:00
|
|
|
painter->restore();
|
|
|
|
painter->beginNativePainting();
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
2013-03-24 20:50:48 +01:00
|
|
|
//checkGLError::qDebug("glLabel");
|
2010-10-31 14:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum LabelPosition { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT} ;
|
|
|
|
|
|
|
|
static void render2D(QPainter *painter, const LabelPosition pos, const QString &text, const Mode &m=Mode())
|
|
|
|
{
|
|
|
|
render2D(painter,pos,0,text,m);
|
|
|
|
}
|
|
|
|
static void render2D(QPainter *painter, const LabelPosition pos, int linePos, const QString &text, const Mode &m=Mode())
|
|
|
|
{
|
|
|
|
Mode lm = m;
|
|
|
|
if(pos == TOP_RIGHT || pos == BOTTOM_RIGHT)
|
|
|
|
lm.rightAlign=true;
|
|
|
|
|
|
|
|
GLint view[4];
|
|
|
|
glGetIntegerv(GL_VIEWPORT, view);
|
|
|
|
QFontMetrics qfm(m.qFont);
|
|
|
|
float delta = qfm.ascent()/2;
|
|
|
|
switch(pos)
|
|
|
|
{
|
|
|
|
case TOP_LEFT : render2D(painter,vcg::Point2f(delta, view[3]-3*delta - delta*3*linePos),text,lm); break;
|
|
|
|
case TOP_RIGHT : render2D(painter,vcg::Point2f(view[2]-delta, view[3]-3*delta - delta*3*linePos),text,lm); break;
|
|
|
|
case BOTTOM_LEFT : render2D(painter,vcg::Point2f(delta, 3*delta + delta*3*linePos),text,lm); break;
|
|
|
|
case BOTTOM_RIGHT : render2D(painter,vcg::Point2f(view[2]-delta, 3*delta + delta*3*linePos),text,lm); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
|
|
|
static void render2D(QPainter *painter, const vcg::Point2f &p, const QString &text, const Mode &m)
|
|
|
|
{
|
|
|
|
GLint view[4];
|
|
|
|
glGetIntegerv(GL_VIEWPORT, view);
|
|
|
|
QFontMetrics qfm(m.qFont);
|
|
|
|
QRect textBox = qfm.boundingRect(text);
|
|
|
|
glLabel::enter2D(painter);
|
|
|
|
painter->setRenderHint(QPainter::TextAntialiasing);
|
|
|
|
painter->setPen(vcg::ColorConverter::ToQColor(m.color));
|
|
|
|
painter->setFont(m.qFont);
|
2010-10-01 01:32:26 +02:00
|
|
|
|
2010-10-31 14:06:03 +01:00
|
|
|
painter->translate(QPointF(p[0],view[3]-p[1]));
|
|
|
|
painter->rotate(m.angle);
|
|
|
|
QPoint base(0,qfm.ascent()/2);
|
|
|
|
if(m.rightAlign)
|
|
|
|
base.setX(-textBox.width() -qfm.maxWidth());
|
|
|
|
painter->drawText(base,text);
|
|
|
|
glLabel::exit2D(painter);
|
|
|
|
}
|
2010-10-01 01:32:26 +02:00
|
|
|
|
|
|
|
static void render(QPainter *painter, const vcg::Point3f &p, const QString &text)
|
|
|
|
{
|
2010-10-31 14:06:03 +01:00
|
|
|
Mode m;
|
|
|
|
render(painter,p,text,m);
|
2010-10-01 01:32:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-31 14:06:03 +01:00
|
|
|
static void render(QPainter *painter, const vcg::Point3f &p, const QString &text, Mode &m)
|
2010-10-01 01:32:26 +02:00
|
|
|
{
|
|
|
|
GLdouble model[16];
|
|
|
|
GLdouble proj[16];
|
|
|
|
GLint view[4];
|
|
|
|
|
|
|
|
glGetDoublev(GL_MODELVIEW_MATRIX, model);
|
|
|
|
glGetDoublev(GL_PROJECTION_MATRIX, proj);
|
|
|
|
glGetIntegerv(GL_VIEWPORT, view);
|
|
|
|
GLdouble winx,winy,winz;
|
|
|
|
|
|
|
|
gluProject(p[0],p[1],p[2],model,proj,view,&winx,&winy,&winz);
|
|
|
|
|
2010-10-31 14:06:03 +01:00
|
|
|
QFontMetrics qfm(m.qFont);
|
2010-10-01 01:32:26 +02:00
|
|
|
QRect textBox = qfm.boundingRect(text);
|
2010-10-31 14:06:03 +01:00
|
|
|
glLabel::enter2D(painter);
|
|
|
|
|
2010-10-01 01:32:26 +02:00
|
|
|
painter->setRenderHint(QPainter::TextAntialiasing);
|
2010-10-31 14:06:03 +01:00
|
|
|
painter->setPen(vcg::ColorConverter::ToQColor(m.color));
|
|
|
|
painter->setFont(m.qFont);
|
2010-10-01 01:32:26 +02:00
|
|
|
painter->translate(QPointF(winx,view[3]-winy));
|
2010-10-31 14:06:03 +01:00
|
|
|
painter->rotate(m.angle);
|
2010-10-01 01:32:26 +02:00
|
|
|
QPoint base(0,qfm.ascent()/2);
|
2010-10-31 14:06:03 +01:00
|
|
|
if(m.rightAlign)
|
2010-10-01 01:32:26 +02:00
|
|
|
base.setX(-textBox.width() -qfm.maxWidth());
|
|
|
|
painter->drawText(base,text);
|
2010-10-31 14:06:03 +01:00
|
|
|
|
|
|
|
glLabel::exit2D(painter);
|
2010-10-01 01:32:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void render(QPainter *painter, const vcg::Point3d &p, const QString &text)
|
|
|
|
{ render(painter,Point3f::Construct(p),text); }
|
2010-10-31 14:06:03 +01:00
|
|
|
static void render(QPainter *painter, const vcg::Point3d &p, const QString &text, Mode &m)
|
|
|
|
{ render(painter,Point3f::Construct(p),text,m); }
|
2010-10-01 01:32:26 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
#endif
|