LabelMgr.cpp   LabelMgr.cpp 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "LabelMgr.hpp" #include "LabelMgr.hpp"
#include "renderer/StelRenderer.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelModule.hpp" #include "StelModule.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "StelObjectType.hpp" #include "StelObjectType.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "VecMath.hpp" #include "VecMath.hpp"
#include "StelPainter.hpp"
#include <vector> #include <vector>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QtOpenGL>
// Base class from which other label types inherit // Base class from which other label types inherit
class StelLabel class StelLabel
{ {
public: public:
StelLabel(const QString& text, const QFont& font, const Vec3f& color ); StelLabel(const QString& text, const QFont& font, const Vec3f& color );
virtual ~StelLabel() {;} virtual ~StelLabel() {;}
//! draw the label on the sky //! Draw the label on the sky
//! @param core the StelCore object //! @param core the StelCore object
virtual bool draw(StelCore* core, StelPainter& sPainter) = 0; //! @param renderer Renderer used for drawing.
//! @param projection Projection to project to screen coordinates.
virtual bool draw(StelCore* core, StelRenderer* renderer, StelProjec
torP projector) = 0;
//! update fade for on/off action //! update fade for on/off action
virtual void update(double deltaTime); virtual void update(double deltaTime);
//! Set the duration used for the fade in / fade out of the label. //! Set the duration used for the fade in / fade out of the label.
virtual void setFadeDuration(float duration); virtual void setFadeDuration(float duration);
//! Set the font color used for the font //! Set the font color used for the font
virtual void setFontColor(const Vec3f& color); virtual void setFontColor(const Vec3f& color);
//! Show or hide the label. It will fade in/out. //! Show or hide the label. It will fade in/out.
virtual void setFlagShow(bool b); virtual void setFlagShow(bool b);
//! Get value of flag used to turn on and off the label //! Get value of flag used to turn on and off the label
virtual bool getFlagShow(void); virtual bool getFlagShow(void);
skipping to change at line 102 skipping to change at line 103
//! @param enclosureSize determines the size of the enclosure for st yles Box and Circle //! @param enclosureSize determines the size of the enclosure for st yles Box and Circle
SkyLabel(const QString& text, StelObjectP bindObject, const QFont& f ont, Vec3f color, SkyLabel(const QString& text, StelObjectP bindObject, const QFont& f ont, Vec3f color,
QString side="NE", double distance=-1.0, SkyLabel:: Style style=TextOnly, QString side="NE", double distance=-1.0, SkyLabel:: Style style=TextOnly,
double enclosureSize=0.0); double enclosureSize=0.0);
virtual ~SkyLabel(); virtual ~SkyLabel();
// SkyLabel(const QString& text, Vec3d coords, QString side="NE", do uble distance=-1.0, SkyLabel::Style style=TextOnly, double enclosureSize=-1 .0); // SkyLabel(const QString& text, Vec3d coords, QString side="NE", do uble distance=-1.0, SkyLabel::Style style=TextOnly, double enclosureSize=-1 .0);
//! Draw the label on the sky //! Draw the label on the sky
//! @param core the StelCore object //! @param core the StelCore object
//! @param sPainter the StelPainter to use for drawing operations //! @param renderer Renderer used for drawing.
virtual bool draw(StelCore* core, StelPainter& sPainter); //! @param projection Projection to project to screen coordinates.
virtual bool draw(StelCore* core, StelRenderer* renderer, StelProjec
torP projector);
static SkyLabel::Style stringToStyle(const QString& s); static SkyLabel::Style stringToStyle(const QString& s);
private: private:
StelObjectP labelObject; StelObjectP labelObject;
QString labelSide; QString labelSide;
double labelDistance; double labelDistance;
SkyLabel::Style labelStyle; SkyLabel::Style labelStyle;
double labelEnclosureSize; double labelEnclosureSize;
}; };
skipping to change at line 131 skipping to change at line 133
//! @param text the text for the label //! @param text the text for the label
//! @param x the x-position on the screen (pixels from the left side ) //! @param x the x-position on the screen (pixels from the left side )
//! @param y the y-position on the screen (pixels from the top side) //! @param y the y-position on the screen (pixels from the top side)
//! @param font the font to use //! @param font the font to use
//! @param color the color for the label //! @param color the color for the label
ScreenLabel(const QString& text, int x, int y, const QFont& font, co nst Vec3f& color); ScreenLabel(const QString& text, int x, int y, const QFont& font, co nst Vec3f& color);
virtual ~ScreenLabel(); virtual ~ScreenLabel();
//! draw the label on the sky //! draw the label on the sky
//! @param core the StelCore object //! @param core the StelCore object
//! @param sPainter the StelPainter to use for drawing operations //! @param renderer Renderer used for drawing.
virtual bool draw(StelCore* core, StelPainter& sPainter); //! @param projection Projection to project to screen coordinates.
virtual bool draw(StelCore* core, StelRenderer* renderer, StelProjec
torP projector);
private: private:
int screenX; int screenX;
int screenY; int screenY;
}; };
///////////////////// /////////////////////
// StelLabel class // // StelLabel class //
///////////////////// /////////////////////
StelLabel::StelLabel(const QString& text, const QFont& font, const Vec3f& c olor) StelLabel::StelLabel(const QString& text, const QFont& font, const Vec3f& c olor)
skipping to change at line 206 skipping to change at line 209
labelDistance(distance), labelDistance(distance),
labelStyle(style), labelStyle(style),
labelEnclosureSize(enclosureSize) labelEnclosureSize(enclosureSize)
{ {
} }
SkyLabel::~SkyLabel() SkyLabel::~SkyLabel()
{ {
} }
bool SkyLabel::draw(StelCore* core, StelPainter& sPainter) bool SkyLabel::draw(StelCore* core, StelRenderer* renderer, StelProjectorP projector)
{ {
if(labelFader.getInterstate() <= 0.0) if(labelFader.getInterstate() <= 0.0)
return false; return false;
Vec3d objectPos = labelObject->getJ2000EquatorialPos(core); Vec3d objectPos = labelObject->getJ2000EquatorialPos(core);
Vec3d labelXY; Vec3d labelXY;
sPainter.getProjector()->project(objectPos,labelXY);
sPainter.setFont(labelFont); projector->project(objectPos, labelXY);
renderer->setFont(labelFont);
double xOffset(0.); double xOffset(0.);
double yOffset(0.); double yOffset(0.);
char hJustify = 'c'; char hJustify = 'c';
char vJustify = 'c'; char vJustify = 'c';
if (labelSide.toUpper().contains("N")) if (labelSide.toUpper().contains("N"))
{ {
yOffset = 1.0; yOffset = 1.0;
vJustify = 'b'; // bottom justify text vJustify = 'b'; // bottom justify text
skipping to change at line 251 skipping to change at line 254
hJustify = 'r'; // left justify text hJustify = 'r'; // left justify text
} }
if (labelDistance >= 0.0) if (labelDistance >= 0.0)
{ {
xOffset *= labelDistance; xOffset *= labelDistance;
yOffset *= labelDistance; yOffset *= labelDistance;
} }
else else
{ {
float shift = 4.f + labelObject->getAngularSize(core)*M_PI/1 float shift = 4.0f + labelObject->getAngularSize(core) * M_P
80.*sPainter.getProjector()->getPixelPerRadAtCenter()/1.8f; I / 180.0f *
projector->getPixelPerRadAtCenter() / 1.8f;
// use the object size // use the object size
xOffset *= shift; xOffset *= shift;
yOffset *= shift; yOffset *= shift;
} }
double jxOffset(0.); QFontMetrics fontMetrics(labelFont);
double jyOffset(0.); const float jxOffset = hJustify == 'r' ? fontMetrics.width(labelText
if (hJustify == 'r') ) :
jxOffset = sPainter.getFontMetrics().width(labelText); hJustify == 'c' ? fontMetrics.width(labelText
else if (hJustify == 'c') ) * 0.5 :
jxOffset = sPainter.getFontMetrics().width(labelText) / 2.; 0.0;
const float jyOffset = vJustify == 't' ? fontMetrics.height() :
if (vJustify == 't') vJustify == 'c' ? fontMetrics.height() * 0.5
jyOffset = sPainter.getFontMetrics().height(); :
else if (vJustify == 'c') 0.0;
jyOffset = sPainter.getFontMetrics().height() / 2.;
renderer->setGlobalColor(labelColor[0], labelColor[1],
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], label labelColor[2], labelFader.getInterstate());
Fader.getInterstate()); renderer->drawText(TextParams(labelXY[0] + xOffset - jxOffset,
sPainter.drawText(labelXY[0]+xOffset-jxOffset, labelXY[1]+yOffset-jy labelXY[1] + yOffset - jyOffset,
Offset, labelText, 0, 0, 0, false); labelText).useGravity());
if (labelStyle == SkyLabel::Line) if (labelStyle == SkyLabel::Line)
{ {
sPainter.enableTexture2d(false); renderer->setBlendMode(BlendMode_Alpha);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// screen coordinates of object // screen coordinates of object
Vec3d objXY; Vec3d objXY;
sPainter.getProjector()->project(objectPos,objXY); projector->project(objectPos, objXY);
double lineEndX = labelXY[0]+xOffset; double lineEndX = labelXY[0]+xOffset;
double lineEndY = labelXY[1]+yOffset; double lineEndY = labelXY[1]+yOffset;
if (vJustify == 'b') if (vJustify == 'b')
lineEndY -= 5; lineEndY -= 5;
else if (vJustify == 't') else if (vJustify == 't')
lineEndY += 5; lineEndY += 5;
if (hJustify == 'l') if (hJustify == 'l')
lineEndX -= 5; lineEndX -= 5;
else if (hJustify == 'r') else if (hJustify == 'r')
lineEndX += 5; lineEndX += 5;
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2 renderer->setGlobalColor(labelColor[0], labelColor[1], label
], labelFader.getInterstate()); Color[2],
labelFader.getInterstate());
sPainter.drawLine2d(lineEndX,lineEndY,objXY[0], objXY[1]); renderer->drawLine(lineEndX,lineEndY,objXY[0], objXY[1]);
} }
return true; return true;
} }
/////////////////////// ///////////////////////
// ScreenLabel class // // ScreenLabel class //
/////////////////////// ///////////////////////
ScreenLabel::ScreenLabel(const QString& text, int x, int y, const QFont& fo nt, const Vec3f& color) ScreenLabel::ScreenLabel(const QString& text, int x, int y, const QFont& fo nt, const Vec3f& color)
: StelLabel(text, font, color), : StelLabel(text, font, color),
screenX(x) screenX(x)
{ {
QFontMetrics metrics(font); QFontMetrics metrics(font);
screenY = StelApp::getInstance().getCore()->getProjection2d()->getVi ewportHeight() - y - metrics.height(); screenY = StelApp::getInstance().getCore()->getProjection2d()->getVi ewportHeight() - y - metrics.height();
} }
ScreenLabel::~ScreenLabel() ScreenLabel::~ScreenLabel()
{ {
} }
bool ScreenLabel::draw(StelCore*, StelPainter& sPainter) bool ScreenLabel::draw(StelCore*, StelRenderer* renderer, StelProjectorP pr ojector)
{ {
Q_UNUSED(projector);
if (labelFader.getInterstate() <= 0.0) if (labelFader.getInterstate() <= 0.0)
{
return false; return false;
}
renderer->setGlobalColor(labelColor[0], labelColor[1],
labelColor[2], labelFader.getInterstate());
renderer->setFont(labelFont);
renderer->drawText(TextParams(screenX, screenY, labelText).useGravit
y());
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], label
Fader.getInterstate());
sPainter.setFont(labelFont);
sPainter.drawText(screenX, screenY, labelText, 0, 0, 0, false);
return true; return true;
} }
/////////////////////// ///////////////////////
// LabelMgr class // // LabelMgr class //
/////////////////////// ///////////////////////
LabelMgr::LabelMgr() LabelMgr::LabelMgr()
{ {
setObjectName("LabelMgr"); setObjectName("LabelMgr");
} }
LabelMgr::~LabelMgr() LabelMgr::~LabelMgr()
{ {
} }
void LabelMgr::init() void LabelMgr::init()
{ {
} }
void LabelMgr::draw(StelCore* core) void LabelMgr::draw(StelCore* core, StelRenderer* renderer)
{ {
StelPainter sPainter(core->getProjection(StelCore::FrameJ2000));
foreach(StelLabel* l, allLabels) foreach(StelLabel* l, allLabels)
if (l!=NULL) {
l->draw(core, sPainter); if (l != NULL)
{
l->draw(core, renderer, core->getProjection(StelCore
::FrameJ2000));
}
}
} }
int LabelMgr::labelObject(const QString& text, int LabelMgr::labelObject(const QString& text,
const QString& objectName, const QString& objectName,
bool visible, bool visible,
float fontSize, float fontSize,
const QString& fontColor, const QString& fontColor,
const QString& side, const QString& side,
double labelDistance, double labelDistance,
const QString& style) const QString& style)
 End of changes. 24 change blocks. 
45 lines changed or deleted 61 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/