File indexing completed on 2024-05-05 03:49:48

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2006-2007 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2008, 2009, 2010 Jens-Michael Hoffmann <jmho@c-xx.com>
0006 // SPDX-FileCopyrightText: 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
0007 //
0008 
0009 #include "FogLayer.h"
0010 
0011 #include "GeoPainter.h"
0012 #include "ViewportParams.h"
0013 #include "RenderState.h"
0014 
0015 namespace Marble
0016 {
0017     
0018 QStringList FogLayer::renderPosition() const
0019 {
0020     return QStringList(QStringLiteral("ATMOSPHERE"));
0021 }
0022 
0023 bool FogLayer::render( GeoPainter *painter,
0024                        ViewportParams *viewParams,
0025                        const QString &renderPos,
0026                        GeoSceneLayer *layer )
0027 {
0028     Q_UNUSED(renderPos)
0029     Q_UNUSED(layer)
0030 
0031     // FIXME: The fog layer is really slow. That's why we defer it to
0032     //        PrintQuality. Either cache on a pixmap - or maybe
0033     //        better: Add to GlobeScanlineTextureMapper.
0034     if ( painter->mapQuality() != PrintQuality )
0035         return true;
0036 
0037     if ( viewParams->projection() != Spherical)
0038         return true;
0039 
0040     // No use to draw the fog if it's not visible in the area.
0041     if ( viewParams->mapCoversViewport() )
0042         return true;
0043 
0044     int imgWidth2  = viewParams->width() / 2;
0045     int imgHeight2 = viewParams->height() / 2;
0046 
0047     int radius = viewParams->radius();
0048 
0049     // Recalculate the atmosphere effect and paint it to canvasImage.
0050     QRadialGradient grad1( QPointF( imgWidth2, imgHeight2 ), radius );
0051 
0052     // FIXME: Add a cosine relationship
0053     grad1.setColorAt( 0.85, QColor( 255, 255, 255, 0 ) );
0054     grad1.setColorAt( 1.00, QColor( 255, 255, 255, 64 ) );
0055 
0056     QBrush    brush1( grad1 );
0057     QPen      pen1( Qt::NoPen );
0058 
0059     painter->save();
0060 
0061     painter->setBrush( brush1 );
0062     painter->setPen( pen1 );
0063     painter->setRenderHint( QPainter::Antialiasing, false );
0064 
0065     // FIXME: Cut out what's really needed
0066     painter->drawEllipse( imgWidth2  - radius,
0067                          imgHeight2 - radius,
0068                          2 * radius,
0069                          2 * radius );
0070 
0071     painter->restore();
0072 
0073     return true;
0074 }
0075 
0076 RenderState FogLayer::renderState() const
0077 {
0078     return RenderState(QStringLiteral("Fog"));
0079 }
0080 
0081 }