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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2006-2009 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0005 //
0006 
0007 
0008 #include "FpsLayer.h"
0009 
0010 #include <QPoint>
0011 #include <QElapsedTimer>
0012 #include <QFont>
0013 #include <QPainter>
0014 
0015 namespace Marble
0016 {
0017 
0018 FpsLayer::FpsLayer( QElapsedTimer *time )
0019     : m_time( time )
0020 {
0021 }
0022 
0023 void FpsLayer::paint( QPainter *painter ) const
0024 {
0025     const qreal fps = 1000.0 / (qreal)( m_time->elapsed() );
0026     const QString fpsString = QString("Speed: %1 fps").arg(fps, 5, 'f', 1, QLatin1Char(' '));
0027 
0028     const QPoint fpsLabelPos( 10, 20 );
0029 
0030     painter->setFont( QFont( QStringLiteral( "Sans Serif" ), 10 ) );
0031 
0032     painter->setPen( Qt::black );
0033     painter->setBrush( Qt::black );
0034     painter->drawText( fpsLabelPos, fpsString );
0035 
0036     painter->setPen( Qt::white );
0037     painter->setBrush( Qt::white );
0038     painter->drawText( fpsLabelPos.x() - 1, fpsLabelPos.y() - 1, fpsString );
0039 }
0040 
0041 }