1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "trackmouse.h"
25 #include <kwinconfig.h>
28 #include <kstandarddirs.h>
32 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
41 KWIN_EFFECT( trackmouse
, TrackMouseEffect
)
46 TrackMouseEffect::TrackMouseEffect()
53 TrackMouseEffect::~TrackMouseEffect()
58 void TrackMouseEffect::prePaintScreen( ScreenPrePaintData
& data
, int time
)
61 QTime t
= QTime::currentTime();
62 angle
= ((t
.second() % 4) * 90.0) + (t
.msec() / 1000.0 * 90.0);
64 effects
->prePaintScreen( data
, time
);
67 void TrackMouseEffect::paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
)
69 effects
->paintScreen( mask
, region
, data
); // paint normal screen
72 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
75 glPushAttrib( GL_CURRENT_BIT
| GL_ENABLE_BIT
);
78 glBlendFunc( GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
83 QRect r
= starRect( i
);
84 texture
->render( region
, r
);
92 void TrackMouseEffect::postPaintScreen()
99 effects
->addRepaint( starRect( i
));
101 effects
->postPaintScreen();
104 void TrackMouseEffect::mouseChanged( const QPoint
&, const QPoint
&, Qt::MouseButtons
,
105 Qt::MouseButtons
, Qt::KeyboardModifiers modifiers
, Qt::KeyboardModifiers
)
107 if( modifiers
== ( Qt::CTRL
| Qt::META
))
111 if( texture
== NULL
)
113 if( texture
== NULL
)
121 effects
->addRepaint( starRect( i
));
130 effects
->addRepaint( starRect( i
));
136 QRect
TrackMouseEffect::starRect( int num
) const
138 int a
= angle
+ 360 / STARS
* num
;
139 int x
= cursorPos().x() + int( DIST
* cos( a
* ( 2 * M_PI
/ 360 )));
140 int y
= cursorPos().y() + int( DIST
* sin( a
* ( 2 * M_PI
/ 360 )));
141 return QRect( QPoint( x
- textureSize
.width() / 2,
142 y
- textureSize
.height() / 2 ), textureSize
);
145 void TrackMouseEffect::loadTexture()
147 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
148 QString file
= KGlobal::dirs()->findResource( "appdata", "trackmouse.png" );
152 texture
= new GLTexture( im
);
153 textureSize
= im
.size();