Make the ShowFps effect show the FPS as a number.

Patch by  Carlo Segato <brandon.ml@gmail.com>.
FEATURE: 155638


svn path=/trunk/KDE/kdebase/workspace/; revision=771282
This commit is contained in:
Luboš Luňák 2008-02-05 17:20:08 +00:00
parent ab0e78d937
commit a6e8d860a1
8 changed files with 507 additions and 2 deletions

View file

@ -162,6 +162,7 @@ if(KWIN_HAVE_OPENGL_COMPOSITING)
magnifier_config.desktop
mousemark_config.desktop
sharpen_config.desktop
showfps_config.desktop
snow_config.desktop
trackmouse_config.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
@ -177,6 +178,13 @@ if(KWIN_HAVE_OPENGL_COMPOSITING AND KWIN_HAVE_XRENDER_COMPOSITING)
showfps.desktop
showpaint.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
SET(kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources}
showfps_config.cpp
showfps_config.ui
)
install( FILES
showfps_config.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
endif(KWIN_HAVE_OPENGL_COMPOSITING AND KWIN_HAVE_XRENDER_COMPOSITING)
# add the plugin

View file

@ -38,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sharpen_config.h"
#include "snow_config.h"
#include "trackmouse_config.h"
#include "showfps_config.h"
#endif
#include <kwineffects.h>
@ -65,6 +66,7 @@ KWIN_EFFECT_CONFIG_FACTORY
registerPlugin<KWin::SharpenEffectConfig>("sharpen"); \
registerPlugin<KWin::SnowEffectConfig>("snow"); \
registerPlugin<KWin::TrackMouseEffectConfig>("trackmouse"); \
registerPlugin<KWin::ShowFpsEffectConfig> ("showfps"); \
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
K_PLUGIN_FACTORY_DEFINITION(EffectFactory,

View file

@ -35,7 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#include <math.h>
#include <QPainter>
namespace KWin
{
@ -48,6 +48,7 @@ const int MAX_TIME = 100;
ShowFpsEffect::ShowFpsEffect()
: paints_pos( 0 )
, frames_pos( 0 )
, fpsText(0)
{
for( int i = 0;
i < NUM_PAINTS;
@ -73,8 +74,46 @@ ShowFpsEffect::ShowFpsEffect()
else if ( y < 0 )
y = displayHeight() - MAX_TIME - y;
fps_rect = QRect( x, y, FPS_WIDTH + 2*NUM_PAINTS, MAX_TIME );
config = effects->effectConfig("ShowFps");
int textPosition = config.readEntry("TextPosition", int(INSIDE_GRAPH));
textFont = config.readEntry("TextFont", QFont());
textColor = config.readEntry("TextColor", QColor());
double textAlpha = config.readEntry("TextAlpha", 1.0);
if(!textColor.isValid())
textColor = QPalette().color(QPalette::Active, QPalette::WindowText);
textColor.setAlphaF(textAlpha);
switch(textPosition)
{
case TOP_LEFT:
fpsTextRect = QRect(0, 0, 100, 100);
textAlign = Qt::AlignTop|Qt::AlignLeft;
break;
case TOP_RIGHT:
fpsTextRect = QRect(displayWidth()-100, 0, 100, 100);
textAlign = Qt::AlignTop|Qt::AlignRight;
break;
case BOTTOM_LEFT:
fpsTextRect = QRect(0, displayHeight()-100, 100, 100);
textAlign = Qt::AlignBottom|Qt::AlignLeft;
break;
case BOTTOM_RIGHT:
fpsTextRect = QRect(displayWidth()-100, displayHeight()-100, 100, 100);
textAlign = Qt::AlignBottom|Qt::AlignRight;
break;
case NOWHERE:
fpsTextRect = QRect();
break;
case INSIDE_GRAPH:
default:
fpsTextRect = QRect(x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME);
textAlign = Qt::AlignTop|Qt::AlignRight;
break;
}
}
void ShowFpsEffect::prePaintScreen( ScreenPrePaintData& data, int time )
{
if( time == 0 ) {
@ -176,6 +215,9 @@ void ShowFpsEffect::paintGL( int fps )
// Paint amount of rendered pixels graph
paintDrawSizeGraph( x, y );
// Paint FPS numerical value
paintFPSText(fps);
// Paint paint sizes
glPopAttrib();
@ -382,4 +424,25 @@ void ShowFpsEffect::postPaintScreen()
effects->addRepaint( fps_rect );
}
void ShowFpsEffect::paintFPSText(int fps)
{
if( !fpsTextRect.isValid())
return;
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
QImage im(100, 100, QImage::Format_ARGB32);
im.fill(Qt::transparent);
QPainter painter(&im);
painter.setFont(textFont);
painter.setPen(textColor);
painter.drawText(QRect(0, 0, 100, 100), textAlign, QString::number(fps));
if(fpsText)
delete fpsText;
fpsText = new GLTexture(im);
fpsText->bind();
fpsText->render(false, QRegion(fpsTextRect), fpsTextRect);
fpsText->unbind();
effects->addRepaint(fpsTextRect);
#endif
}
} // namespace

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KWIN_SHOWFPS_H
#include <kwineffects.h>
#include <kwinglutils.h>
#include <QDateTime>
@ -37,12 +38,14 @@ class ShowFpsEffect
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
virtual void postPaintScreen();
enum { INSIDE_GRAPH, NOWHERE, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; // fps text position
private:
void paintGL( int fps );
void paintXrender( int fps );
void paintFPSGraph(int x, int y);
void paintDrawSizeGraph(int x, int y);
void paintGraph( int x, int y, QList<int> values, QList<int> lines, bool colorize);
void paintFPSText(int fps);
QTime t;
enum { NUM_PAINTS = 100 }; // remember time needed to paint this many paints
int paints[ NUM_PAINTS ]; // time needed to paint
@ -55,6 +58,12 @@ class ShowFpsEffect
int x;
int y;
QRect fps_rect;
GLTexture *fpsText;
int textPosition;
QFont textFont;
QColor textColor;
QRect fpsTextRect;
int textAlign;
};
} // namespace

121
effects/showfps_config.cpp Normal file
View file

@ -0,0 +1,121 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "showfps_config.h"
#include <kwineffects.h>
#include <klocale.h>
#include <kdebug.h>
#include <QVBoxLayout>
#ifndef KDE_USE_FINAL
KWIN_EFFECT_CONFIG_FACTORY
#endif
namespace KWin
{
ShowFpsEffectConfig::ShowFpsEffectConfig(QWidget* parent, const QVariantList& args) :
KCModule(EffectFactory::componentData(), parent, args)
{
kDebug();
m_ui = new Ui::ShowFpsEffectConfigForm;
m_ui->setupUi(this);
connect(m_ui->textPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
connect(m_ui->textFont, SIGNAL(fontSelected(const QFont&)), this, SLOT(changed()));
connect(m_ui->textColor, SIGNAL(changed(const QColor&)), this, SLOT(changed()));
connect(m_ui->textAlpha, SIGNAL(valueChanged(double)), this, SLOT(changed()));
load();
}
ShowFpsEffectConfig::~ShowFpsEffectConfig()
{
delete m_ui;
kDebug();
}
void ShowFpsEffectConfig::load()
{
kDebug();
KCModule::load();
KConfigGroup conf = EffectsHandler::effectConfig("ShowFps");
int position = conf.readEntry("TextPosition", int(ShowFpsEffect::INSIDE_GRAPH));
if(position > -1)
m_ui->textPosition->setCurrentIndex(position);
QFont font = conf.readEntry("TextFont", QFont());
m_ui->textFont->setFont(font);
QColor color = conf.readEntry("TextColor", QColor());
if(color.isValid())
m_ui->textColor->setColor(color);
double alpha = conf.readEntry("TextAlpha", 1.0);
m_ui->textAlpha->setValue(alpha);
emit changed(false);
}
void ShowFpsEffectConfig::save()
{
kDebug();
KCModule::save();
KConfigGroup conf = EffectsHandler::effectConfig("ShowFps");
int position = m_ui->textPosition->currentIndex();
conf.writeEntry("TextPosition", position);
QFont font = m_ui->textFont->font();
conf.writeEntry("TextFont", font);
QColor color = m_ui->textColor->color();
conf.writeEntry("TextColor", color);
double alpha = m_ui->textAlpha->value();
conf.writeEntry("TextAlpha", alpha);
conf.sync();
emit changed(false);
EffectsHandler::sendReloadMessage("showfps");
}
void ShowFpsEffectConfig::defaults()
{
kDebug();
m_ui->textPosition->setCurrentIndex(0);
m_ui->textFont->setFont(QFont());
m_ui->textColor->setColor(QColor());
m_ui->textAlpha->setValue(1.0);
emit changed(true);
}
} // namespace
#include "showfps_config.moc"

View file

@ -0,0 +1,57 @@
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kcm_kwin4_effect_builtins
X-KDE-ParentComponents=kwin4_effect_showfps
X-KDE-PluginKeyword=showfps
Name=Show FPS
Name[ar]=أظهر FPS
Name[bg]=Показване на к/с
Name[ca]=Mostra els FPS
Name[csb]=Wëskrzëni FPS
Name[da]=Vis FPS
Name[de]=Bilder pro Sekunde anzeigen
Name[el]=Εμφάνιση καρέ ανά δευτερόλεπτο
Name[eo]=Montri FPS
Name[es]=Muestra FPS
Name[et]=FPS-i näitamine
Name[eu]=Erakutsi FPS
Name[fa]=نمایش FPS
Name[fi]=Näytä FPS
Name[fr]=Affiche l'im/s
Name[fy]=FPS sjen litte
Name[ga]=Taispeáin FSS
Name[gl]=Mostrar os FPS
Name[he]=הצג מסגרות לשנייה
Name[hi]= ि
Name[hu]=Képkockaszámláló megjelenítése
Name[is]=Sýna FPS (rammar á sekúndu)
Name[it]=Mostra FPS
Name[ja]= (FPS)
Name[kk]=FPS-ты көрсету
Name[km]= FPS
Name[ko]=FPS
Name[lv]=Rādīt kadrus/sek
Name[nb]=Vis FPS
Name[nds]=Bps wiesen
Name[ne]=
Name[nl]=FPS tonen
Name[nn]=Vis FPS
Name[pa]=FPS
Name[pl]=Pokaż FPS
Name[pt]=Mostrar as IPS
Name[pt_BR]=Mostrar FPS
Name[se]=Čájet rámmaid sekunddas
Name[sl]=Sličice na sekundo
Name[sr]=Кадрови/секунди
Name[sr@latin]=Kadrovi/sekundi
Name[sv]=Visa ramar/s
Name[tr]=FPS Göster
Name[uk]=Показати FPS
Name[vi]=Hin FPS
Name[wa]=Mostrer FPS
Name[x-test]=xxShow FPSxx
Name[zh_CN]= FPS
Name[zh_TW]=

52
effects/showfps_config.h Normal file
View file

@ -0,0 +1,52 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_SHOWFPS_CONFIG_H
#define KWIN_SHOWFPS_CONFIG_H
#define KDE3_SUPPORT
#include <kcmodule.h>
#undef KDE3_SUPPORT
#include "ui_showfps_config.h"
#include "showfps.h"
namespace KWin
{
class ShowFpsEffectConfig : public KCModule
{
Q_OBJECT
public:
explicit ShowFpsEffectConfig(QWidget* parent = 0, const QVariantList& args = QVariantList());
~ShowFpsEffectConfig();
public slots:
virtual void save();
virtual void load();
virtual void defaults();
private:
Ui::ShowFpsEffectConfigForm *m_ui;
};
} // namespace
#endif

193
effects/showfps_config.ui Normal file
View file

@ -0,0 +1,193 @@
<ui version="4.0" >
<class>KWin::ShowFpsEffectConfigForm</class>
<widget class="QWidget" name="KWin::ShowFpsEffectConfigForm" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>194</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Text</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Text Position</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="textPosition" >
<item>
<property name="text" >
<string>Inside Graph</string>
</property>
</item>
<item>
<property name="text" >
<string>Nowhere</string>
</property>
</item>
<item>
<property name="text" >
<string>Top Left</string>
</property>
</item>
<item>
<property name="text" >
<string>Top Right</string>
</property>
</item>
<item>
<property name="text" >
<string>Bottom Left</string>
</property>
</item>
<item>
<property name="text" >
<string>Bottom Right</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Text Font</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="KFontRequester" native="1" name="textFont" />
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Text Color</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="KColorButton" name="textColor" />
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>Text Alpha</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDoubleSpinBox" name="textAlpha" >
<property name="decimals" >
<number>2</number>
</property>
<property name="maximum" >
<double>1.000000000000000</double>
</property>
<property name="singleStep" >
<double>0.100000000000000</double>
</property>
<property name="value" >
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
<customwidget>
<class>KFontRequester</class>
<extends>QWidget</extends>
<header>kfontrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>