CompassMarks.cpp   CompassMarks.cpp 
skipping to change at line 19 skipping to change at line 19
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* 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 "config.h"
#include "VecMath.hpp" #include "VecMath.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelPainter.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "CompassMarks.hpp" #include "CompassMarks.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelIniParser.hpp"
#include "renderer/StelCircleArcRenderer.hpp"
#include "renderer/StelRenderer.hpp"
#include <QAction>
#include <QDebug> #include <QDebug>
#include <QPixmap> #include <QPixmap>
#include <QSettings> #include <QSettings>
#include <QKeyEvent> #include <QKeyEvent>
#include <QtNetwork> #include <QtNetwork>
#include <cmath> #include <cmath>
//! This method is the one called automatically by the StelModuleMgr just
//! after loading the dynamic library
StelModule* CompassMarksStelPluginInterface::getStelModule() const StelModule* CompassMarksStelPluginInterface::getStelModule() const
{ {
return new CompassMarks(); return new CompassMarks();
} }
StelPluginInfo CompassMarksStelPluginInterface::getPluginInfo() const StelPluginInfo CompassMarksStelPluginInterface::getPluginInfo() const
{ {
// Allow to load the resources when used as a static plugin // Allow to load the resources when used as a static plugin
Q_INIT_RESOURCE(CompassMarks); Q_INIT_RESOURCE(CompassMarks);
StelPluginInfo info; StelPluginInfo info;
info.id = "CompassMarks"; info.id = "CompassMarks";
info.displayedName = N_("Compass Marks"); info.displayedName = N_("Compass Marks");
info.authors = "Matthew Gates"; info.authors = "Matthew Gates";
info.contact = "http://porpoisehead.net/"; info.contact = "http://porpoisehead.net/";
info.description = N_("Displays compass bearing marks along the hori zon"); info.description = N_("Displays compass bearing marks along the hori zon");
info.version = COMPASSMARKS_VERSION;
return info; return info;
} }
Q_EXPORT_PLUGIN2(CompassMarks, CompassMarksStelPluginInterface)
CompassMarks::CompassMarks() CompassMarks::CompassMarks()
: markColor(1,1,1), pxmapGlow(NULL), pxmapOnIcon(NULL), pxmapOffIcon : displayedAtStartup(false)
(NULL), toolbarButton(NULL) , markColor(1,1,1)
, toolbarButton(NULL)
, cardinalPointsState(false)
{ {
setObjectName("CompassMarks"); setObjectName("CompassMarks");
conf = StelApp::getInstance().getSettings();
QSettings* conf = StelApp::getInstance().getSettings();
// Setup defaults if not present
if (!conf->contains("CompassMarks/mark_color"))
conf->setValue("CompassMarks/mark_color", "1,0,0");
if (!conf->contains("CompassMarks/font_size"))
conf->setValue("CompassMarks/font_size", 10);
if (!conf->contains("CompassMarks/enable_at_startup"))
conf->setValue("CompassMarks/enable_at_startup", false);
// Load settings from main config file
markColor = StelUtils::strToVec3f(conf->value("CompassMarks/mark_col
or", "1,0,0").toString());
font.setPixelSize(conf->value("CompassMarks/font_size", 10).toInt())
;
} }
CompassMarks::~CompassMarks() CompassMarks::~CompassMarks()
{ {
if (pxmapGlow!=NULL) //
delete pxmapGlow;
if (pxmapOnIcon!=NULL)
delete pxmapOnIcon;
if (pxmapOffIcon!=NULL)
delete pxmapOffIcon;
// TODO (requires work in core API)
// 1. Remove button from toolbar
// 2. Remove action from GUI
// 3. Delete GUI objects. I'll leave this commented right now becau
se
// unloading (when implemented) might cause problems if we do it bef
ore we
// can do parts 1 and 2.
//if (toolbarButton!=NULL)
// delete toolbarButton;
// BTW, the above remark is from 2009 --BM
// See http://stellarium.svn.sourceforge.net/viewvc/stellarium/trunk
/extmodules/CompassMarks/src/CompassMarks.cpp?r1=4333&r2=4332&pathrev=4333
} }
//! Determine which "layer" the plugin's drawing will happen on. //! Determine which "layer" the plugin's drawing will happen on.
double CompassMarks::getCallOrder(StelModuleActionName actionName) const double CompassMarks::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+10.; return StelApp::getInstance().getModuleMgr().getModule("Land scapeMgr")->getCallOrder(actionName)+10.;
return 0; return 0;
} }
void CompassMarks::init() void CompassMarks::init()
{ {
qDebug() << "CompassMarks plugin - press control-C to toggle compass // Because the plug-in has no configuration GUI, users rely on what'
marks"; s
// written in the configuration file to know what can be configured.
Q_ASSERT(conf);
if (!conf->childGroups().contains("CompassMarks"))
restoreDefaultConfiguration();
loadConfiguration();
try try
{ {
addAction("actionShow_Compass_Marks", N_("Compass Marks"), N
_("Compass marks"), "marksVisible");
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
pxmapGlow = new QPixmap(":/graphicGui/glow32x32.png"); if (gui != NULL)
pxmapOnIcon = new QPixmap(":/compassMarks/bt_compass_on.png" {
); toolbarButton = new StelButton(NULL,
pxmapOffIcon = new QPixmap(":/compassMarks/bt_compass_off.pn QPixmap(":/compassMar
g"); ks/bt_compass_on.png"),
QPixmap(":/compassMar
QAction *showCompassAction = gui->getGuiAction("actionShow_C ks/bt_compass_off.png"),
ompass_Marks"); QPixmap(":/graphicGui
//showCompassAction->setChecked(markFader); /glow32x32.png"),
toolbarButton = new StelButton(NULL, *pxmapOnIcon, *pxmapOff "actionShow_Compass_M
Icon, *pxmapGlow, showCompassAction); arks");
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr gui->getButtonBar()->addButton(toolbarButton, "065-p
oup"); luginsGroup");
connect(showCompassAction, SIGNAL(toggled(bool)), this, SLOT }
(setCompassMarks(bool))); connect(GETSTELMODULE(LandscapeMgr), SIGNAL(cardinalsPointsD
connect(gui->getGuiAction("actionShow_Cardinal_Points"), SIG isplayedChanged(bool)), this, SLOT(cardinalPointsChanged(bool)));
NAL(toggled(bool)), this, SLOT(cardinalPointsChanged(bool)));
cardinalPointsState = false; cardinalPointsState = false;
QSettings* conf = StelApp::getInstance().getSettings(); setCompassMarks(displayedAtStartup);
setCompassMarks(conf->value("CompassMarks/enable_at_startup"
, false).toBool());
// GZ: This must go here, else button may show wrong state
gui->getGuiAction("actionShow_Compass_Marks")->setChecked(ma
rkFader);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: unable create toolbar button for Com passMarks plugin: " << e.what(); qWarning() << "WARNING: unable create toolbar button for Com passMarks plugin: " << e.what();
} }
} }
//! Draw any parts on the screen which are for our module //! Draw any parts on the screen which are for our module
void CompassMarks::draw(StelCore* core, StelRenderer* renderer) void CompassMarks::draw(StelCore* core)
{ {
if (markFader.getInterstate() <= 0.0) { return; } if (markFader.getInterstate() <= 0.0) { return; }
Vec3f pos; Vec3d pos;
StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelC StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelC
ore::RefractionOff); // Maybe conflict with Scenery3d branch. AW20120214 No ore::RefractionOff);
. GZ20120826.yy StelPainter painter(prj);
painter.setFont(font);
renderer->setFont(font);
const Vec3f mColor = StelApp::getInstance().getVisionModeNight() painter.setColor(markColor[0], markColor[1], markColor[2], markFader
? StelUtils::getNightColor(markColor) : markColor .getInterstate());
; glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
renderer->setGlobalColor(mColor[0], mColor[1], mColor[2], markFader. glEnable(GL_BLEND);
getInterstate()); // OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH
renderer->setBlendMode(BlendMode_Alpha); // glEnable(GL_LINE_SMOOTH);
const QFontMetrics fontMetrics(font);
for(int i=0; i<360; i++) for(int i=0; i<360; i++)
{ {
float a = i*M_PI/180; float a = i*M_PI/180;
pos.set(sin(a),cos(a), 0.f); pos.set(sin(a),cos(a), 0.f);
float h = -0.002; float h = -0.002;
if (i % 15 == 0) if (i % 15 == 0)
{ {
h = -0.02; // the size of the mark every 15 degrees h = -0.02; // the size of the mark every 15 degrees
QString s = QString("%1").arg((i+90)%360); QString s = QString("%1").arg((i+90)%360);
const float shiftx = fontMetrics.width(s) / 2.;
const float shifty = fontMetrics.height() / 2.; float shiftx = painter.getFontMetrics().width(s) / 2
renderer->drawText(TextParams(pos, prj, s).shift(-sh .;
iftx, shifty)); float shifty = painter.getFontMetrics().height() / 2
.;
painter.drawText(pos, s, 0, -shiftx, shifty);
} }
else if (i % 5 == 0) else if (i % 5 == 0)
{ {
h = -0.01; // the size of the mark every 5 degrees h = -0.01; // the size of the mark every 5 degrees
} }
Vec3f win1, win2; glDisable(GL_TEXTURE_2D);
if(prj->project(pos, win1) && prj->project(Vec3f(pos[0], pos painter.drawGreatCircleArc(pos, Vec3d(pos[0], pos[1], h), NU
[1], h), win2)) LL);
{ glEnable(GL_TEXTURE_2D);
renderer->drawLine(win1[0], win1[1], win2[0], win2[1 }
]); // OpenGL ES 2.0 doesn't have GL_LINE_SMOOTH
} // glDisable(GL_LINE_SMOOTH);
} glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
} }
void CompassMarks::update(double deltaTime) void CompassMarks::update(double deltaTime)
{ {
markFader.update((int)(deltaTime*1000)); markFader.update((int)(deltaTime*1000));
} }
void CompassMarks::setCompassMarks(bool b) void CompassMarks::setCompassMarks(bool b)
{ {
markFader = b; if (b == markFader)
if (markFader) return;
if (b)
{ {
// Save the display state of the cardinal points // Save the display state of the cardinal points and hide th em.
cardinalPointsState = GETSTELMODULE(LandscapeMgr)->getFlagCa rdinalsPoints(); cardinalPointsState = GETSTELMODULE(LandscapeMgr)->getFlagCa rdinalsPoints();
GETSTELMODULE(LandscapeMgr)->setFlagCardinalsPoints(false);
} else {
// Restore the cardinal points state.
GETSTELMODULE(LandscapeMgr)->setFlagCardinalsPoints(cardinal
PointsState);
} }
else markFader = b;
{ emit compassMarksChanged(b);
} }
if(cardinalPointsState) void CompassMarks::loadConfiguration()
{ {
// Using QActions instead of directly calling Q_ASSERT(conf);
// setFlagCardinalsPoints() in order to sync with the button conf->beginGroup("CompassMarks");
s markColor = StelUtils::strToVec3f(conf->value("mark_color", "1,0,0")
dynamic_cast<StelGui*>(StelApp::getInstance().getGui())->get .toString());
GuiAction("actionShow_Cardinal_Points")->trigger(); font.setPixelSize(conf->value("font_size", 10).toInt());
} displayedAtStartup = conf->value("enable_at_startup", false).toBool(
);
conf->endGroup();
}
void CompassMarks::saveConfiguration()
{
Q_ASSERT(conf);
conf->beginGroup("CompassMarks");
conf->setValue("font_size", font.pixelSize());
conf->setValue("enable_at_startup", displayedAtStartup);
// The rest is not saved!
conf->endGroup();
}
void CompassMarks::restoreDefaultConfiguration()
{
Q_ASSERT(conf);
// Remove the whole section from the configuration file
conf->remove("CompassMarks");
// Load the default values...
loadConfiguration();
// ... then save them.
saveConfiguration();
// But this doesn't save the color, so...
conf->beginGroup("CompassMarks");
conf->setValue("mark_color", "1,0,0");
conf->endGroup();
} }
void CompassMarks::cardinalPointsChanged(bool b) void CompassMarks::cardinalPointsChanged(bool b)
{ {
if(b) if (b && getCompassMarks()) {
{ cardinalPointsState = true;
// If the compass marks are displayed when cardinal points setCompassMarks(false);
// are about to be shown, hide the compass marks
if(markFader)
{
cardinalPointsState = false; // actionShow_Cardinal_
Points should not be triggered again
dynamic_cast<StelGui*>(StelApp::getInstance().getGui
())->getGuiAction("actionShow_Compass_Marks")->trigger();
}
} }
} }
 End of changes. 24 change blocks. 
125 lines changed or deleted 119 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/