[Marble-commits] KDE/kdeedu/marble/src/lib

Bastian Holst bastianholst at gmx.de
Thu Oct 14 22:07:53 CEST 2010


SVN commit 1185961 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

 M  +0 -68     MarbleMap.cpp  
 M  +0 -3      MarbleMap_p.h  
 M  +51 -0     MarbleModel.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/MarbleMap.cpp #1185960:1185961
@@ -78,7 +78,6 @@
                        m_parent, SLOT( setNeedsUpdate() ) );
 
     m_justModified = false;
-    m_dirtyAtmosphere = false;
 
     m_logzoom  = 0;
 
@@ -111,10 +110,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 ));
@@ -153,49 +148,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() ) {
@@ -204,11 +156,6 @@
         return;
     }
 
-    if ( m_dirtyAtmosphere ) {
-        drawAtmosphere();
-        m_dirtyAtmosphere = false;
-    }
-
     m_model->paintGlobe( &painter, &m_viewParams,
                          needsUpdate() || m_viewParams.canvasImage()->isNull(),
                          dirtyRect );
@@ -672,14 +619,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 )
@@ -759,10 +699,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:
@@ -829,11 +765,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();
     }
--- trunk/KDE/kdeedu/marble/src/lib/MarbleMap_p.h #1185960:1185961
@@ -41,8 +41,6 @@
 
     void paintMarbleSplash( GeoPainter &painter, QRect &dirtyRect );
 
-    void drawAtmosphere();
-    void drawFog(QPainter &painter);
     void setBoundingBox();
     void doResize();
 
@@ -70,7 +68,6 @@
     int              m_height;
     ViewParams       m_viewParams;
     bool             m_justModified; // FIXME: Rename to isDirty
-    bool             m_dirtyAtmosphere;
 
     // zoom related
     int              m_logzoom;
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1185960:1185961
@@ -124,6 +124,7 @@
     void notifyModelChanged();
     GeoSceneGroup * textureLayerProperties() const;
 
+    void drawAtmosphere( QPainter *painter, ViewParams *viewParams );
     void drawFog( QPainter *painter, ViewParams *viewParams );
 
     static QAtomicInt       refCounter;
@@ -650,6 +651,8 @@
         d->m_layerManager->renderLayers( painter, viewParams, renderPositions );
     }
 
+    d->drawAtmosphere( painter, viewParams );
+
     if ( redrawBackground ) {
         if ( d->m_mapTheme->map()->hasTextureLayers() ) {
 
@@ -875,6 +878,54 @@
     painter->restore();
 }
 
+void MarbleModelPrivate::drawAtmosphere( QPainter *painter,
+                                         ViewParams *viewParams )
+{
+    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  = viewParams->width() / 2;
+    int  imageHalfHeight = viewParams->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