summaryrefslogtreecommitdiff
path: root/include/wizard.h
blob: 5b86b5cc03ce47b3ee0da750c1ca2724e97fbbc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Compiz wizard particle system plugin
 *
 * wizard.c
 *
 * Written by : Sebastian Kuhlen
 * E-mail     : DiCon@tankwar.de
 *
 * This plugin and parts of its code have been inspired by the showmouse plugin
 * by Dennis Kasprzyk
 *
 * 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.
 *
 */

#include <core/core.h>
#include <composite/composite.h>
#include <opengl/opengl.h>
#include <mousepoll/mousepoll.h>

#include "wizard_options.h"
#include "wizard_tex.h"

static float
rRange (float avg, float range)
{
    return avg + (float)((random () & 0xff)/127.5-1.)*range;
}

typedef enum
{
    TRIGGER_PERSISTENT = 0,
    TRIGGER_MOUSEMOVEMENT,
    TRIGGER_RANDOMSHOT,
    TRIGGER_RANDOMPERIOD
} TriggerType;

typedef enum
{
    MOVEMENT_MOUSEPOSITION = 0,
    MOVEMENT_FOLLOWMOUSE,
    MOVEMENT_BOUNCE,
    MOVEMENT_WRAP
} MovementType;

class GPoint
{
    public:

	float strength;		// Strength of this gravity source
	float x;			// X position
	float y;			// Y position
	float espeed;		// Speed of the gravity source
	float eangle;		// Angle for the movement of this gravity source
	int   movement;		// Type of movement of this gravity source
};

class Particle
{
    public:

	float c[3];			// Color
	float a;			// alpha value
	float x;			// X position
	float y;			// Y position
	float t;			// t position (age, born at 1, dies at 0)
	float phi;			// Orientation of texture
	float vx;			// X speed
	float vy;			// Y speed
	float vt;			// t speed (aging speed)
	float vphi;			// Rotation speed
	float s;			// size (side of the square)
	float snew;			// Size when born (reduced to s while new)
	float g;			// Gravity from this particle
};

class Emitter
{
    public:

	bool  set_active;		// Set to active in the settings
	bool  active;		// Currently active (differs from set_active for
				    //                   the random period trigger)
	int   trigger;		// When to generate particles
	int   count;		// Amount of particles to be generated
	float h;			// color hue (0..1)
	float dh;			// color hue range
	float l;			// color lightness (0..1)
	float dl;			// color lightness range
	float a;			// Alpha
	float da;			// Alpha range
	float x;			// X position
	float y;			// Y position
	float espeed;		// Speed of the emitter
	float eangle;		// Angle for the movement of this emitter
	int   movement;		// Type of movement of this emitter
	float dx;			// X range
	float dy;			// Y range
	float dcirc;		// Circular range
	float vx;			// X speed
	float vy;			// Y speed
	float vt;			// t speed (aging speed)
	float vphi;			// Rotation speed
	float dvx;			// X speed range
	float dvy;			// Y speed range
	float dvcirc;		// Circular speed range
	float dvt;			// t speed (aging speed) range
	float dvphi;		// Rotation speed range
	float s;			// size (side of the square)
	float ds;			// size (side of the square) range
	float snew;			// Size when born (reduced to s while new)
	float dsnew;		// Size when born (reduced to s while new) range
	float g;			// Gravity of particles
	float dg;			// Gravity range
	float gp;			// Part of particles that have gravity
};

class ParticleSystem
{
    public:

	int      hardLimit;		// Not to be exceeded
	int      softLimit;		// If exceeded, old particles age faster
	int      lastCount;		// Living particle count to evaluate softLimit
	float    tnew;		// Particle is new if t > tnew
	float    told;		// Particle is old if t < told
	float    gx;		// Global gravity x
	float    gy;		// Global gravity y
	Particle *particles;	// The actual particles
	GLuint   tex;		// Particle Texture
	bool     active;
	float    darken;		// Darken background
	GLuint   blendMode;
	Emitter  *e;		// All emitters in here
	GPoint   *g;		// All gravity point sources in here
	int      ne;		// Emitter count
	int      ng;		// GPoint count

	GLfloat *vertices_cache;
	int     vertex_cache_count;
	GLfloat *coords_cache;
	int     coords_cache_count;
	GLfloat *colors_cache;
	int     color_cache_count;
	GLfloat *dcolors_cache;
	int     dcolors_cache_count;
};

class WizardScreen :
    public PluginClassHandler <WizardScreen, CompScreen>,
    public WizardOptions,
    public ScreenInterface,
    public CompositeScreenInterface,
    public GLScreenInterface
{
    public:
	WizardScreen (CompScreen *screen);
	~WizardScreen ();

	CompositeScreen *cScreen;
	GLScreen	*gScreen;

	int mx, my; //Mouse Position from polling

	bool active;

	ParticleSystem *ps;

	MousePoller pollHandle;

	void loadGPoints (ParticleSystem *ps);

	void loadEmitters (ParticleSystem *ps);

	void drawParticles (ParticleSystem * ps);

	void positionUpdate (const CompPoint &pos);

	void preparePaint (int time);

	void donePaint ();

	bool
	glPaintOutput (const GLScreenPaintAttrib	&sa,
		       const GLMatrix		&transform,
		       const CompRegion		&region,
		       CompOutput			*output,
		       unsigned int		mask);

	bool toggle ();

	void
	optionChanged (CompOption	      *opt,
		       WizardOptions::Options num);
};

class WizardPluginVTable :
    public CompPlugin::VTableForScreen <WizardScreen>
{
    public:
	bool init ();
};

COMPIZ_PLUGIN_20090315 (wizard, WizardPluginVTable);