LabelMgr.cpp   LabelMgr.cpp 
skipping to change at line 25 skipping to change at line 25
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "LabelMgr.hpp" #include "LabelMgr.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 "StelFont.hpp"
#include "StelFontMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.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 "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, StelFont* 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, const StelPainter& sPainter) = 0; virtual bool draw(StelCore* core, StelPainter& sPainter) = 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);
//! Get value of flag used to turn on and off the label
virtual void setText(const QString& newText);
protected: protected:
QString labelText; QString labelText;
StelFont* labelFont; QFont labelFont;
Vec3f labelColor; Vec3f labelColor;
LinearFader labelFader; LinearFader labelFader;
}; };
//! @class SkyLabel //! @class SkyLabel
//! Used to create user labels which are bound to some object on the celest ial sphere. //! Used to create user labels which are bound to some object on the celest ial sphere.
//! The object in question can be any existing StelObject or celestial coor dinates. //! The object in question can be any existing StelObject or celestial coor dinates.
class SkyLabel : public StelLabel class SkyLabel : public StelLabel
{ {
public: public:
skipping to change at line 92 skipping to change at line 93
//! Constructor of a SkyLabel which is attached to an existing objec t //! Constructor of a SkyLabel which is attached to an existing objec t
//! @param text the text which will be displayed //! @param text the text which will be displayed
//! @param bindObject a pointer to an existing object to which the l abel will be attached //! @param bindObject a pointer to an existing object to which the l abel will be attached
//! @param font a pointer the font to use for this label //! @param font a pointer the font to use for this label
//! @param color choose a color for the label //! @param color choose a color for the label
//! @param side which side of the object to draw the label, values N , S, E, W, NE, NW, SE, SW, C (C is centred on the object) //! @param side which side of the object to draw the label, values N , S, E, W, NE, NW, SE, SW, C (C is centred on the object)
//! @param distance the distance from the object to draw the label. If < 0.0, placement is automatic. //! @param distance the distance from the object to draw the label. If < 0.0, placement is automatic.
//! @param style determines how the label is drawn //! @param style determines how the label is drawn
//! @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, StelFont* font , 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 sPainter the StelPainter to use for drawing operations
virtual bool draw(StelCore* core, const StelPainter& sPainter); virtual bool draw(StelCore* core, StelPainter& sPainter);
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;
}; };
//! @class ScreenLabel //! @class ScreenLabel
//! Used to create user labels which are bound to a fixed point on the scre en. //! Used to create user labels which are bound to a fixed point on the scre en.
class ScreenLabel : public StelLabel class ScreenLabel : public StelLabel
{ {
public: public:
//! Constructor of a SkyLabel which is to be displayed at a fixed po sition on the screen. //! Constructor of a SkyLabel which is to be displayed at a fixed po sition on the screen.
//! @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 bottom si de) //! @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, StelFont* font, 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 sPainter the StelPainter to use for drawing operations
virtual bool draw(StelCore* core, const StelPainter& sPainter); virtual bool draw(StelCore* core, StelPainter& sPainter);
private: private:
int screenX; int screenX;
int screenY; int screenY;
}; };
///////////////////// /////////////////////
// StelLabel class // // StelLabel class //
///////////////////// /////////////////////
StelLabel::StelLabel(const QString& text, StelFont* font, const Vec3f& colo r) StelLabel::StelLabel(const QString& text, const QFont& font, const Vec3f& c olor)
: labelText(text), : labelText(text),
labelFont(font), labelFont(font),
labelColor(color) labelColor(color)
{ {
} }
void StelLabel::update(double deltaTime) void StelLabel::update(double deltaTime)
{ {
labelFader.update((int)(deltaTime*1000)); labelFader.update((int)(deltaTime*1000));
} }
skipping to change at line 173 skipping to change at line 174
void StelLabel::setFlagShow(bool b) void StelLabel::setFlagShow(bool b)
{ {
labelFader = b; labelFader = b;
} }
bool StelLabel::getFlagShow(void) bool StelLabel::getFlagShow(void)
{ {
return labelFader; return labelFader;
} }
void StelLabel::setText(const QString& newText)
{
labelText = newText;
}
SkyLabel::Style SkyLabel::stringToStyle(const QString& s) SkyLabel::Style SkyLabel::stringToStyle(const QString& s)
{ {
if (s=="Line") if (s=="Line")
return SkyLabel::Line; return SkyLabel::Line;
else else
return SkyLabel::TextOnly; return SkyLabel::TextOnly;
} }
//////////////////// ////////////////////
// SkyLabel class // // SkyLabel class //
//////////////////// ////////////////////
SkyLabel::SkyLabel(const QString& text, StelObjectP bindObject, StelFont* f ont, SkyLabel::SkyLabel(const QString& text, StelObjectP bindObject, const QFont & font,
Vec3f color, QString side, double distance, SkyLabel::St yle style, Vec3f color, QString side, double distance, SkyLabel::St yle style,
double enclosureSize) double enclosureSize)
: StelLabel(text, font, color), : StelLabel(text, font, color),
labelObject(bindObject), labelObject(bindObject),
labelSide(side), labelSide(side),
labelDistance(distance), labelDistance(distance),
labelStyle(style), labelStyle(style),
labelEnclosureSize(enclosureSize) labelEnclosureSize(enclosureSize)
{ {
} }
SkyLabel::~SkyLabel() SkyLabel::~SkyLabel()
{ {
} }
bool SkyLabel::draw(StelCore* core, const StelPainter& sPainter) bool SkyLabel::draw(StelCore* core, StelPainter& sPainter)
{ {
if(labelFader.getInterstate() <= 0.0) if(labelFader.getInterstate() <= 0.0)
return false; return false;
Vec3d objectPos = labelObject->getJ2000EquatorialPos(core->getNaviga tor()); Vec3d objectPos = labelObject->getJ2000EquatorialPos(core->getNaviga tor());
Vec3d labelXY; Vec3d labelXY;
sPainter.getProjector()->project(objectPos,labelXY); sPainter.getProjector()->project(objectPos,labelXY);
sPainter.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 justufy text vJustify = 'b'; // bottom justify text
} }
else if (labelSide.toUpper().contains("S")) else if (labelSide.toUpper().contains("S"))
{ {
yOffset = -1.0; yOffset = -1.0;
vJustify = 't'; // top justufy text vJustify = 't'; // top justufy text
} }
if (labelSide.toUpper().contains("E")) if (labelSide.toUpper().contains("E"))
{ {
xOffset = 1.0; xOffset = 1.0;
skipping to change at line 252 skipping to change at line 260
{ {
float shift = 4.f + labelObject->getAngularSize(core)*M_PI/1 80.*sPainter.getProjector()->getPixelPerRadAtCenter()/1.8f; float shift = 4.f + labelObject->getAngularSize(core)*M_PI/1 80.*sPainter.getProjector()->getPixelPerRadAtCenter()/1.8f;
// use the object size // use the object size
xOffset *= shift; xOffset *= shift;
yOffset *= shift; yOffset *= shift;
} }
double jxOffset(0.); double jxOffset(0.);
double jyOffset(0.); double jyOffset(0.);
if (hJustify == 'r') if (hJustify == 'r')
jxOffset = labelFont->getStrLen(labelText); jxOffset = sPainter.getFontMetrics().width(labelText);
else if (hJustify == 'c') else if (hJustify == 'c')
jxOffset = labelFont->getStrLen(labelText) / 2.; jxOffset = sPainter.getFontMetrics().width(labelText) / 2.;
if (vJustify == 't') if (vJustify == 't')
jyOffset = labelFont->getLineHeight(); jyOffset = sPainter.getFontMetrics().height();
else if (vJustify == 'c') else if (vJustify == 'c')
jyOffset = labelFont->getLineHeight() / 2.; jyOffset = sPainter.getFontMetrics().height() / 2.;
glColor4f(labelColor[0], labelColor[1], labelColor[2], labelFader.ge sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], label
tInterstate()); Fader.getInterstate());
sPainter.drawText(labelFont, labelXY[0]+xOffset-jxOffset, labelXY[1] sPainter.drawText(labelXY[0]+xOffset-jxOffset, labelXY[1]+yOffset-jy
+yOffset-jyOffset, labelText, 0, 0, 0, false); Offset, labelText, 0, 0, 0, false);
if (labelStyle == SkyLabel::Line) if (labelStyle == SkyLabel::Line)
{ {
glDisable(GL_TEXTURE_2D); sPainter.enableTexture2d(false);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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); sPainter.getProjector()->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;
glColor4f(labelColor[0], labelColor[1], labelColor[2], label Fader.getInterstate()); sPainter.setColor(labelColor[0], labelColor[1], labelColor[2 ], labelFader.getInterstate());
glEnable(GL_LINE_SMOOTH); sPainter.drawLine2d(lineEndX,lineEndY,objXY[0], objXY[1]);
glBegin(GL_LINES);
glVertex2f(lineEndX,lineEndY);
glVertex2f(objXY[0], objXY[1]);
glEnd();
glDisable(GL_LINE_SMOOTH);
} }
return true; return true;
} }
/////////////////////// ///////////////////////
// ScreenLabel class // // ScreenLabel class //
/////////////////////// ///////////////////////
ScreenLabel::ScreenLabel(const QString& text, int x, int y, StelFont* font, 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)
screenY(y)
{ {
QFontMetrics metrics(font);
screenY = StelApp::getInstance().getCore()->getProjection2d()->getVi
ewportHeight() - y - metrics.height();
} }
ScreenLabel::~ScreenLabel() ScreenLabel::~ScreenLabel()
{ {
} }
bool ScreenLabel::draw(StelCore* core, const StelPainter& sPainter) bool ScreenLabel::draw(StelCore* core, StelPainter& sPainter)
{ {
if(labelFader.getInterstate() <= 0.0) if (labelFader.getInterstate() <= 0.0)
return false; return false;
glColor4f(labelColor[0], labelColor[1], labelColor[2], labelFader.ge sPainter.setColor(labelColor[0], labelColor[1], labelColor[2], label
tInterstate()); Fader.getInterstate());
sPainter.drawText(labelFont, screenX, screenY, labelText, 0, 0, 0, f sPainter.setFont(labelFont);
alse); 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");
} }
skipping to change at line 357 skipping to change at line 362
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)
{ {
StelFont* font = &StelApp::getInstance().getFontManager().getStandar QFont font;
dFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize); font.setPixelSize(fontSize);
Q_ASSERT(font);
StelObjectP obj = GETSTELMODULE(StelObjectMgr)->searchByName(objectN ame); StelObjectP obj = GETSTELMODULE(StelObjectMgr)->searchByName(objectN ame);
if (!obj) if (!obj)
{ {
qWarning() << "LabelMgr::labelObject object not found: " << objectName; qWarning() << "LabelMgr::labelObject object not found: " << objectName;
return -1; return -1;
} }
StelLabel* l = new SkyLabel(text, obj, font, StelUtils::htmlColorToV ec3f(fontColor), side, labelDistance, SkyLabel::stringToStyle(style)); StelLabel* l = new SkyLabel(text, obj, font, StelUtils::htmlColorToV ec3f(fontColor), side, labelDistance, SkyLabel::stringToStyle(style));
if (l==NULL) if (l==NULL)
return -1; return -1;
if (visible) if (visible)
l->setFlagShow(true); l->setFlagShow(true);
allLabels.append(l); allLabels.append(l);
return allLabels.size()-1; return allLabels.size()-1;
} }
int LabelMgr::labelScreen(const QString& text, int LabelMgr::labelScreen(const QString& text,
int x, int x,
int y, int y,
bool visible, bool visible,
float fontSize, float fontSize,
const QString& fontColor) const QString& fontColor)
{ {
StelFont* font = &StelApp::getInstance().getFontManager().getStandar QFont font;
dFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize); font.setPixelSize(fontSize);
Q_ASSERT(font);
ScreenLabel* l = new ScreenLabel(text, x, y, font, StelUtils::htmlCo lorToVec3f(fontColor)); ScreenLabel* l = new ScreenLabel(text, x, y, font, StelUtils::htmlCo lorToVec3f(fontColor));
if (l==NULL) if (l==NULL)
return -1; return -1;
if (visible) if (visible)
l->setFlagShow(true); l->setFlagShow(true);
allLabels.append(l); allLabels.append(l);
return allLabels.size()-1; return allLabels.size()-1;
} }
skipping to change at line 411 skipping to change at line 416
else else
return false; return false;
} }
void LabelMgr::setLabelShow(int id, bool show) void LabelMgr::setLabelShow(int id, bool show)
{ {
if (allLabels.at(id)!=NULL) if (allLabels.at(id)!=NULL)
allLabels.at(id)->setFlagShow(show); allLabels.at(id)->setFlagShow(show);
} }
void LabelMgr::setLabelText(int id, const QString& newText)
{
if (allLabels.at(id)!=NULL)
allLabels.at(id)->setText(newText);
}
bool LabelMgr::deleteLabel(int id) bool LabelMgr::deleteLabel(int id)
{ {
if (allLabels.at(id)!=NULL) if (allLabels.at(id)!=NULL)
{ {
delete allLabels.at(id); delete allLabels.at(id);
allLabels[id] = NULL; allLabels[id] = NULL;
return true; return true;
} }
else else
return false; return false;
 End of changes. 35 change blocks. 
50 lines changed or deleted 59 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/