[Marble-commits] branches/KDE/4.5/kdeedu/marble/src/lib
Bastian Holst
bastianholst at gmx.de
Thu Oct 14 22:23:59 CEST 2010
SVN commit 1185965 by bholst:
Corrected Marble's atmosphere painting:
* We have to paint the atmosphere in any case (because we update the background, stars).
* We have to paint the atmosphere at the correct moment (between stars and ground).
BUG: 254154
backport r1185961
M +0 -69 MarbleMap.cpp
M +0 -3 MarbleMap_p.h
M +53 -0 MarbleModel.cpp
--- branches/KDE/4.5/kdeedu/marble/src/lib/MarbleMap.cpp #1185964:1185965
@@ -87,14 +87,12 @@
m_parent, SLOT( updateChangedMap() ) );
m_justModified = false;
- m_dirtyAtmosphere = false;
m_measureTool = new MeasureTool( m_model, m_parent );
m_parent->connect( m_model, SIGNAL( timeout() ),
m_parent, SLOT( updateGps() ) );
-
m_logzoom = 0;
m_zoomStep = 40;
@@ -143,10 +141,6 @@
m_viewParams.setCanvasImage( new QImage( m_parent->width(), m_parent->height(),
imageFormat ));
- if ( m_viewParams.showAtmosphere() ) {
- m_dirtyAtmosphere=true;
- }
-
// Recreate the coastline detection offscreen image
m_viewParams.setCoastImage( new QImage( m_parent->width(), m_parent->height(),
QImage::Format_RGB32 ));
@@ -185,49 +179,6 @@
painter.restore();
}
-void MarbleMapPrivate::drawAtmosphere()
-{
- // Only draw an atmosphere if planet is earth
- GeoSceneDocument * mapTheme = m_viewParams.mapTheme();
- if ( mapTheme ) {
- if ( mapTheme->head()->target() != "earth" )
- return;
- }
-
- // Only draw an atmosphere if projection is spherical
- if ( m_viewParams.projection() != Spherical )
- return;
-
- // No use to draw atmosphere if it's not visible in the area.
- if ( m_viewParams.viewport()->mapCoversViewport() )
- return;
-
- // Ok, now we know that at least a little of the atmosphere is
- // visible, if nothing else in the corners. Draw the atmosphere
- // by using a circular gradient. This is a pure visual effect and
- // has nothing to do with real physics.
-
- int imageHalfWidth = m_parent->width() / 2;
- int imageHalfHeight = m_parent->height() / 2;
-
- // Recalculate the atmosphere effect and paint it to canvasImage.
- QRadialGradient grad1( QPointF( imageHalfWidth, imageHalfHeight ),
- 1.05 * m_parent->radius() );
- grad1.setColorAt( 0.91, QColor( 255, 255, 255, 255 ) );
- grad1.setColorAt( 1.00, QColor( 255, 255, 255, 0 ) );
-
- QBrush brush1( grad1 );
- QPen pen1( Qt::NoPen );
- QPainter painter( m_viewParams.canvasImage() );
- painter.setBrush( brush1 );
- painter.setPen( pen1 );
- painter.setRenderHint( QPainter::Antialiasing, false );
- painter.drawEllipse( imageHalfWidth - (int)( (qreal)(m_parent->radius()) * 1.05 ),
- imageHalfHeight - (int)( (qreal)(m_parent->radius()) * 1.05 ),
- (int)( 2.1 * (qreal)(m_parent->radius()) ),
- (int)( 2.1 * (qreal)(m_parent->radius()) ) );
-}
-
void MarbleMapPrivate::paintGround( GeoPainter &painter, QRect &dirtyRect )
{
if ( !m_viewParams.mapTheme() ) {
@@ -236,11 +187,6 @@
return;
}
- if ( m_dirtyAtmosphere ) {
- drawAtmosphere();
- m_dirtyAtmosphere = false;
- }
-
m_model->paintGlobe( &painter,
m_parent->width(), m_parent->height(), &m_viewParams,
m_parent->needsUpdate() || m_viewParams.canvasImage()->isNull(),
@@ -708,14 +654,7 @@
emit zoomChanged( d->m_logzoom );
emit distanceChanged( distanceString() );
emit visibleLatLonAltBoxChanged( d->m_viewParams.viewport()->viewLatLonAltBox() );
-
- // We don't do this on every paintEvent to improve performance.
- // Redrawing the atmosphere is only needed if the size of the
- // globe changes.
- if ( d->m_viewParams.showAtmosphere() ) {
- d->m_dirtyAtmosphere=true;
}
-}
void MarbleMap::zoomViewBy( int zoomStep )
@@ -805,10 +744,6 @@
d->m_viewParams.setProjection( projection );
- if ( d->m_viewParams.showAtmosphere() ) {
- d->m_dirtyAtmosphere=true;
- }
-
d->m_model->setupTextureMapper( projection );
// Update texture map during the repaint that follows:
@@ -944,11 +879,7 @@
if ( mapTheme ) {
d->m_model->setMapTheme( mapTheme, d->m_viewParams.projection() );
- // We don't do this on every paintEvent to improve performance.
- // Redrawing the atmosphere is only needed if the size of the
- // globe changes.
d->doResize();
- d->m_dirtyAtmosphere=true;
centerSun();
--- branches/KDE/4.5/kdeedu/marble/src/lib/MarbleMap_p.h #1185964:1185965
@@ -42,8 +42,6 @@
void paintMarbleSplash( GeoPainter &painter, QRect &dirtyRect );
- void drawAtmosphere();
- void drawFog(QPainter &painter);
void setBoundingBox();
void doResize();
@@ -61,7 +59,6 @@
int m_height;
ViewParams m_viewParams;
bool m_justModified; // FIXME: Rename to isDirty
- bool m_dirtyAtmosphere;
// The home position
GeoDataCoordinates m_homePoint;
--- branches/KDE/4.5/kdeedu/marble/src/lib/MarbleModel.cpp #1185964:1185965
@@ -108,6 +108,7 @@
void notifyModelChanged();
GeoSceneGroup * textureLayerProperties() const;
+ void drawAtmosphere( QPainter *painter, ViewParams *viewParams, int width, int height );
void drawFog( QPainter *painter, ViewParams *viewParams, int width, int height );
static QAtomicInt refCounter;
@@ -583,9 +584,12 @@
static_cast<GeoSceneLayer*>( d->m_mapTheme->map()->layer( themeID ) );
QStringList renderPositions;
+
renderPositions << "STARS" << "BEHIND_TARGET";
d->m_layerManager->renderLayers( painter, viewParams, renderPositions );
+ d->drawAtmosphere( painter, viewParams, width, height );
+
if ( redrawBackground ) {
if ( d->m_mapTheme->map()->hasTextureLayers() ) {
@@ -817,6 +821,55 @@
painter->restore();
}
+void MarbleModelPrivate::drawAtmosphere( QPainter *painter,
+ ViewParams *viewParams,
+ int width, int height )
+{
+ if( !viewParams->showAtmosphere() ) {
+ return;
+ }
+
+ // Only draw an atmosphere if planet is earth
+ GeoSceneDocument *mapTheme = viewParams->mapTheme();
+ if ( mapTheme ) {
+ if ( mapTheme->head()->target() != "earth" )
+ return;
+ }
+
+ // Only draw an atmosphere if projection is spherical
+ if ( viewParams->projection() != Spherical )
+ return;
+
+ // No use to draw atmosphere if it's not visible in the area.
+ if ( viewParams->viewport()->mapCoversViewport() )
+ return;
+
+ // Ok, now we know that at least a little of the atmosphere is
+ // visible, if nothing else in the corners. Draw the atmosphere
+ // by using a circular gradient. This is a pure visual effect and
+ // has nothing to do with real physics.
+
+ int imageHalfWidth = width / 2;
+ int imageHalfHeight = height / 2;
+
+ // Recalculate the atmosphere effect and paint it to canvasImage.
+ QRadialGradient grad1( QPointF( imageHalfWidth, imageHalfHeight ),
+ 1.05 * viewParams->radius() );
+ grad1.setColorAt( 0.91, QColor( 255, 255, 255, 255 ) );
+ grad1.setColorAt( 1.00, QColor( 255, 255, 255, 0 ) );
+
+ QBrush brush1( grad1 );
+ QPen pen1( Qt::NoPen );
+
+ painter->setBrush( brush1 );
+ painter->setPen( pen1 );
+ painter->setRenderHint( QPainter::Antialiasing, false );
+ painter->drawEllipse( imageHalfWidth - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
+ imageHalfHeight - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
+ (int) ( 2.1 * (qreal) ( viewParams->radius()) ),
+ (int) ( 2.1 * (qreal) ( viewParams->radius()) ) );
+}
+
void MarbleModel::update()
{
mDebug() << "MarbleModel::update()";
More information about the Marble-commits
mailing list