not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / effects / test / demo_showpicture.cpp
blobe69cb61b54cba577de4f60b36205277d3b6fe400
1 /*****************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
7 You can Freely distribute this program under the GNU General Public
8 License. See the file "COPYING" for the exact licensing terms.
9 ******************************************************************/
11 #include "demo_showpicture.h"
13 #include <kstandarddirs.h>
14 #include <qimage.h>
16 namespace KWin
19 KWIN_EFFECT( demo_showpicture, ShowPictureEffect )
21 ShowPictureEffect::ShowPictureEffect()
22 : init( true )
23 , picture( NULL )
27 ShowPictureEffect::~ShowPictureEffect()
29 delete picture;
32 void ShowPictureEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
34 effects->paintScreen( mask, region, data );
35 if( init )
37 loadPicture();
38 init = false;
40 if( picture && region.intersects( pictureRect ))
42 glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
43 picture->bind();
44 glEnable( GL_BLEND );
45 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
46 picture->render( region, pictureRect );
47 picture->unbind();
48 glPopAttrib();
52 void ShowPictureEffect::loadPicture()
54 QString file = KGlobal::dirs()->findResource( "appdata", "showpicture.png" );
55 if( file.isEmpty())
56 return;
57 QImage im( file );
58 QRect area = effects->clientArea( PlacementArea, effects->activeScreen(), effects->currentDesktop());
59 picture = new GLTexture( im );
60 pictureRect = QRect( area.x() + ( area.width() - im.width()) / 2,
61 area.y() + ( area.height() - im.height()) / 2, im.width(), im.height());
64 } // namespace