StelAppGraphicsScene.cpp   StelAppGraphicsScene.cpp 
skipping to change at line 24 skipping to change at line 24
* *
* 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 <config.h> #include <config.h>
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp"
#include "Projector.hpp"
#include "fixx11h.h"
#include "StelAppGraphicsScene.hpp" #include "StelAppGraphicsScene.hpp"
#include "ViewportDistorter.hpp" #include "StelViewportDistorter.hpp"
#include "StelModuleMgr.hpp"
#include "StelMainWindow.hpp"
#include "StelMainGraphicsView.hpp" #include "StelMainGraphicsView.hpp"
#include <QtOpenGL> #include <QtOpenGL>
#include <QTimer> #include <QTimer>
StelAppGraphicsScene* StelAppGraphicsScene::singleton = NULL; StelAppGraphicsScene* StelAppGraphicsScene::singleton = NULL;
StelAppGraphicsScene::StelAppGraphicsScene() : tempPainter(NULL), cursorTim eout(-1.f), flagCursorTimeout(false) StelAppGraphicsScene::StelAppGraphicsScene() : cursorTimeout(-1.f), flagCur sorTimeout(false), minFpsTimer(NULL)
{ {
assert(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
distorter = ViewportDistorter::create("none",800,600,NULL); distorter = StelViewportDistorter::create("none",800,600,StelProject orP());
lastEventTimeSec = StelApp::getTotalRunTime(); lastEventTimeSec = StelApp::getTotalRunTime();
previousTime = lastEventTimeSec; previousTime = lastEventTimeSec;
} }
StelAppGraphicsScene::~StelAppGraphicsScene() StelAppGraphicsScene::~StelAppGraphicsScene()
{ {
if (distorter) if (distorter)
{ {
delete distorter; delete distorter;
distorter=NULL; distorter=NULL;
skipping to change at line 65 skipping to change at line 60
} }
void StelAppGraphicsScene::init() void StelAppGraphicsScene::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
setViewPortDistorterType(conf->value("video/distorter","none").toStr ing()); setViewPortDistorterType(conf->value("video/distorter","none").toStr ing());
setFlagCursorTimeout(conf->value("gui/flag_mouse_cursor_timeout", fa lse).toBool()); setFlagCursorTimeout(conf->value("gui/flag_mouse_cursor_timeout", fa lse).toBool());
setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.).toDoub le()); setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.).toDoub le());
connect(&StelApp::getInstance(), SIGNAL(minFpsChanged()), this, SLOT
(minFpsChanged()));
startMainLoop(); startMainLoop();
} }
void StelAppGraphicsScene::glWindowHasBeenResized(int w, int h) void StelAppGraphicsScene::glWindowHasBeenResized(int w, int h)
{ {
if (!distorter || (distorter && distorter->getType() == "none")) if (!distorter || (distorter && distorter->getType() == "none"))
{ {
StelApp::getInstance().glWindowHasBeenResized(w, h); StelApp::getInstance().glWindowHasBeenResized(w, h);
} }
} }
//! Switch to native OpenGL painting, i.e not using QPainter void StelAppGraphicsScene::drawBackground(QPainter* painter, const QRectF &
//! After this call revertToQtPainting MUST be called )
void StelAppGraphicsScene::switchToNativeOpenGLPainting()
{
// Save openGL projection state
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glShadeModel(GL_FLAT);
glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_MULTISAMPLE);
glDisable(GL_DITHER);
glDisable(GL_ALPHA_TEST);
}
//! Revert openGL state so that Qt painting works again
//! @return a painter that can be used
QPainter* StelAppGraphicsScene::revertToQtPainting()
{
// Restore openGL projection state for Qt drawings
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
return tempPainter;
}
QPainter* StelAppGraphicsScene::switchToQPainting()
{
if (tempPainter)
{
tempPainter->save();
tempPainter->resetTransform();
}
// Save openGL projection state
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
if (!tempPainter)
return NULL;
return tempPainter;
}
//! Revert openGL state so that Qt painting works again
//! @return a painter that can be used
void StelAppGraphicsScene::revertToOpenGL()
{
if (tempPainter)
tempPainter->restore();
// Restore openGL projection state for Qt drawings
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}
void StelAppGraphicsScene::drawBackground(QPainter *painter, const QRectF &
)
{ {
if (painter->paintEngine()->type() != QPaintEngine::OpenGL) if (painter->paintEngine()->type() != QPaintEngine::OpenGL)
{ {
qWarning("StelAppGraphicsScene: drawBackground needs a QGLWi dget to be set as viewport on the graphics view"); qWarning("StelAppGraphicsScene: drawBackground needs a QGLWi dget to be set as viewport on the graphics view");
return; return;
} }
const double now = StelApp::getTotalRunTime(); const double now = StelApp::getTotalRunTime();
double dt = now-previousTime; double dt = now-previousTime;
previousTime = now; previousTime = now;
if (dt<0) // This fix the star scale bug!! if (dt<0) // This fix the star scale bug!!
return; return;
// Update the core and all modules // Update the core and all modules
StelApp::getInstance().update(dt); StelApp::getInstance().update(dt);
switchToNativeOpenGLPainting(); painter->save();
StelApp::getInstance().glWindowHasBeenResized((int)(width()), (int)( height())); StelApp::getInstance().glWindowHasBeenResized((int)(width()), (int)( height()));
// And draw them // And draw them
distorter->prepare(); distorter->prepare();
StelApp::getInstance().draw(); StelApp::getInstance().draw();
distorter->distort(); distorter->distort();
revertToQtPainting(); painter->restore();
// Determines when the next display will need to be triggered // Determines when the next display will need to be triggered
// The current policy is that after an event, the FPS is maximum for 2.5 seconds // The current policy is that after an event, the FPS is maximum for 2.5 seconds
// after that, it switches back to the minfps value to save power // after that, it switches back to the default minfps value to save
double duration = 1./StelApp::getInstance().minfps; power
if (now-lastEventTimeSec<2.5) if (now-lastEventTimeSec<2.5)
duration = 1./StelApp::getInstance().maxfps; {
int dur = (int)(duration*1000); double duration = 1./StelApp::getInstance().maxfps;
QTimer::singleShot(dur<5 ? 5 : dur, this, SLOT(update())); int dur = (int)(duration*1000);
QTimer::singleShot(dur<5 ? 5 : dur, this, SLOT(update()));
}
// Manage cursor timeout // Manage cursor timeout
if (cursorTimeout>0.f && (now-lastEventTimeSec>cursorTimeout) && fla gCursorTimeout) if (cursorTimeout>0.f && (now-lastEventTimeSec>cursorTimeout) && fla gCursorTimeout)
{ {
if (QApplication::overrideCursor()==0) if (QApplication::overrideCursor()==0)
QApplication::setOverrideCursor(Qt::BlankCursor); QApplication::setOverrideCursor(Qt::BlankCursor);
} }
else else
{ {
if (QApplication::overrideCursor()!=0) if (QApplication::overrideCursor()!=0)
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
skipping to change at line 212 skipping to change at line 146
else else
{ {
StelMainGraphicsView::getInstance().getOpenGLWin()-> setFixedSize((int)(width()), (int)(height())); StelMainGraphicsView::getInstance().getOpenGLWin()-> setFixedSize((int)(width()), (int)(height()));
} }
} }
if (distorter) if (distorter)
{ {
delete distorter; delete distorter;
distorter = NULL; distorter = NULL;
} }
distorter = ViewportDistorter::create(type,(int)width(),(int)height( ),StelApp::getInstance().getCore()->getProjection()); distorter = StelViewportDistorter::create(type,(int)width(),(int)hei ght(),StelApp::getInstance().getCore()->getProjection2d());
} }
QString StelAppGraphicsScene::getViewPortDistorterType() const QString StelAppGraphicsScene::getViewPortDistorterType() const
{ {
if (distorter) if (distorter)
return distorter->getType(); return distorter->getType();
return "none"; return "none";
} }
void StelAppGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void StelAppGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
skipping to change at line 347 skipping to change at line 281
{ {
event->accept(); event->accept();
return; return;
} }
StelApp::getInstance().handleKeys(event); StelApp::getInstance().handleKeys(event);
} }
void StelAppGraphicsScene::startMainLoop() void StelAppGraphicsScene::startMainLoop()
{ {
QTimer* timer = new QTimer(this); // Set a timer refreshing for every minfps frames
connect(timer, SIGNAL(timeout()), this, SLOT(update())); minFpsChanged();
timer->start((int)(1./StelApp::getInstance().minfps*1000)); }
void StelAppGraphicsScene::minFpsChanged()
{
if (minFpsTimer!=NULL)
{
disconnect(minFpsTimer, SIGNAL(timeout()), 0, 0);
delete minFpsTimer;
minFpsTimer = NULL;
}
minFpsTimer = new QTimer(this);
connect(minFpsTimer, SIGNAL(timeout()), this, SLOT(update()));
minFpsTimer->start((int)(1./StelApp::getInstance().minfps*1000.));
} }
 End of changes. 13 change blocks. 
87 lines changed or deleted 36 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/