3
* Compiz show mouse pointer plugin
7
* Copyright : (C) 2008 by Dennis Kasprzyk
8
* E-mail : onestone@opencompositing.org
10
* Ported to Compiz 0.9 by:
11
* Copyright : (C) 2009 by Sam Spilsbury
12
* E-mail : smpillaz@gmail.com
15
* This program is free software; you can redistribute it and/or
16
* modify it under the terms of the GNU General Public License
17
* as published by the Free Software Foundation; either version 2
18
* of the License, or (at your option) any later version.
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
27
#include "showmouse.h"
29
COMPIZ_PLUGIN_20090315 (showmouse, ShowmousePluginVTable);
32
ShowmouseScreen::genNewParticles (int f_time)
37
Bool rColor = optionGetRandom ();
38
float life = optionGetLife ();
39
float lifeNeg = 1 - life;
40
float fadeExtra = 0.2f * (1.01 - life);
41
float max_new = ps->particles.size () * ((float)f_time / 50) * (1.05 - life);
43
unsigned short *c = optionGetColor ();
45
float colr1 = (float)c[0] / 0xffff;
46
float colg1 = (float)c[1] / 0xffff;
47
float colb1 = (float)c[2] / 0xffff;
48
float colr2 = 1.0 / 4.0 * (float)c[0] / 0xffff;
49
float colg2 = 1.0 / 4.0 * (float)c[1] / 0xffff;
50
float colb2 = 1.0 / 4.0 * (float)c[2] / 0xffff;
51
float cola = (float)c[3] / 0xffff;
54
float partw = optionGetSize () * 5;
60
int nE = MIN (10, optionGetEmiters ());
61
float rA = (2 * M_PI) / nE;
62
int radius = optionGetRadius ();
63
for (i = 0; i < nE; i++)
65
pos[i][0] = sin (rot + (i * rA)) * radius;
66
pos[i][0] += mousePos.x ();
67
pos[i][1] = cos (rot + (i * rA)) * radius;
68
pos[i][1] += mousePos.y ();
71
for (i = 0; i < ps->particles.size () && max_new > 0; i++)
73
Particle *part = ps->particles.at (i);
74
if (part->life <= 0.0f)
77
rVal = (float)(random() & 0xff) / 255.0;
79
part->fade = rVal * lifeNeg + fadeExtra; // Random Fade Value
84
rVal = (float)(random() & 0xff) / 255.0;
85
part->w_mod = part->h_mod = -1;
87
// choose random position
97
// set speed and direction
98
rVal = (float)(random() & 0xff) / 255.0;
99
part->xi = ((rVal * 20.0) - 10.0f);
100
rVal = (float)(random() & 0xff) / 255.0;
101
part->yi = ((rVal * 20.0) - 10.0f);
106
// Random colors! (aka Mystical Fire)
107
rVal = (float)(random() & 0xff) / 255.0;
109
rVal = (float)(random() & 0xff) / 255.0;
111
rVal = (float)(random() & 0xff) / 255.0;
116
rVal = (float)(random() & 0xff) / 255.0;
117
part->r = colr1 - rVal * colr2;
118
part->g = colg1 - rVal * colg2;
119
part->b = colb1 - rVal * colb2;
134
fprintf (stderr, "generated new particles at mean position %i %i\n", mousePos.x (), mousePos.y ());
140
ShowmouseScreen::damageRegion ()
143
float w, h, x1, x2, y1, y2;
148
x1 = screen->width ();
150
y1 = screen->height ();
153
for (i = 0; i < ps->particles.size (); i++)
155
Particle *p = ps->particles.at (i);
163
w += (w * p->w_mod) * p->life;
164
h += (h * p->h_mod) * p->life;
166
x1 = MIN (x1, p->x - w);
167
x2 = MAX (x2, p->x + w);
168
y1 = MIN (y1, p->y - h);
169
y2 = MAX (y2, p->y + h);
172
CompRegion r (floor (x1), floor (y1), (ceil (x2) - floor (x1)),
173
(ceil (y2) - floor (y1)));
174
cScreen->damageRegion (r);
178
ShowmouseScreen::positionUpdate (const CompPoint &p)
185
ShowmouseScreen::preparePaint (int f_time)
187
if (active && !pollHandle.active ())
189
mousePos = MousePoller::getCurrentPosition ();
195
ps = new ParticleSystem (optionGetNumParticles ());
198
cScreen->preparePaint (f_time);
202
ps->slowdown = optionGetSlowdown ();
203
ps->darken = optionGetDarken ();
204
ps->blendMode = (optionGetBlend()) ? GL_ONE :
205
GL_ONE_MINUS_SRC_ALPHA;
207
glGenTextures(1, &ps->tex);
208
glBindTexture(GL_TEXTURE_2D, ps->tex);
210
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
211
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
213
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0,
214
GL_RGBA, GL_UNSIGNED_BYTE, starTex);
215
glBindTexture(GL_TEXTURE_2D, 0);
218
rot = fmod (rot + (((float)f_time / 1000.0) * 2 * M_PI *
219
optionGetRotationSpeed ()), 2 * M_PI);
221
if (ps && ps->active)
223
ps->updateParticles (f_time);
228
genNewParticles (f_time);
230
cScreen->preparePaint (f_time);
234
ShowmouseScreen::donePaint ()
236
if (active || (ps && ps->active))
239
if (!active && pollHandle.active ())
244
if (!active && ps && !ps->active)
246
ps->finiParticles ();
251
cScreen->donePaint ();
255
ShowmouseScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
256
const GLMatrix &transform,
257
const CompRegion ®ion,
265
status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
267
if (!ps || !ps->active)
270
//sTransform.reset ();
272
sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
275
glLoadMatrixf (sTransform.getMatrix ());
277
ps->drawParticles ();
279
fprintf (stderr, "drawing particles\n");
283
glColor4usv (defaultColor);
289
ShowmouseScreen::terminate (CompAction *action,
290
CompAction::State state,
291
CompOption::Vector options)
300
ShowmouseScreen::initiate (CompAction *action,
301
CompAction::State state,
302
CompOption::Vector options)
305
return terminate (action, state, options);
312
ShowmouseScreen::ShowmouseScreen (CompScreen *screen) :
313
PluginClassHandler <ShowmouseScreen, CompScreen> (screen),
314
cScreen (CompositeScreen::get (screen)),
315
gScreen (GLScreen::get (screen)),
320
CompositeScreenInterface::setHandler (cScreen);
321
GLScreenInterface::setHandler (gScreen);
323
pollHandle.setCallback (boost::bind (&ShowmouseScreen::positionUpdate, this,
326
optionSetInitiateInitiate (boost::bind (&ShowmouseScreen::initiate, this,
328
optionSetInitiateTerminate (boost::bind (&ShowmouseScreen::terminate, this,
331
optionSetInitiateButtonInitiate (boost::bind (&ShowmouseScreen::initiate,
333
optionSetInitiateButtonTerminate (boost::bind (&ShowmouseScreen::terminate,
336
optionSetInitiateEdgeInitiate (boost::bind (&ShowmouseScreen::initiate,
338
optionSetInitiateEdgeTerminate (boost::bind (&ShowmouseScreen::terminate,
342
ShowmouseScreen::~ShowmouseScreen ()
346
ps->finiParticles ();
350
if (pollHandle.active ())
355
ShowmousePluginVTable::init ()
357
if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
358
!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) ||
359
!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI) ||
360
!CompPlugin::checkPluginABI ("particlesystem", COMPIZ_PARTICLESYSTEM_ABI) ||
361
!CompPlugin::checkPluginABI ("mousepoll", COMPIZ_MOUSEPOLL_ABI))