28
28
#include "group_glow.h"
30
#define WIN_REAL_X(w) (w->x () - w->border ().left)
31
#define WIN_REAL_Y(w) (w->y () - w->border ().top)
32
#define WIN_REAL_WIDTH(w) (w->width () + 2 * w->geometry ().border () + \
33
w->border ().left + w->border ().right)
34
#define WIN_REAL_HEIGHT(w) (w->height () + 2 * w->geometry ().border () + \
35
w->border ().top + w->border ().bottom)
37
const GlowTextureProperties glowTextureProperties = {
30
const GlowTextureProperties glowTextureProperties =
38
32
/* GlowTextureRectangular */
39
33
glowTexRect, 32, 21
43
37
* GroupWindow::paintGlow
45
39
* Takes our glow texture, stretches the appropriate positions in the glow texture,
46
* adds those geometries (so plugins like wobby and deform this texture correctly)
40
* adds those geometries (so plugins like wobby deform this texture correctly)
47
41
* and then draws the glow texture with this geometry (plugins like wobbly and friends
48
42
* will automatically deform the texture based on our set geometry)
52
46
ExpoWindow::paintGlow (const GLMatrix &transform,
53
const GLWindowPaintAttrib &attrib,
54
const CompRegion &paintRegion,
47
const GLWindowPaintAttrib &attrib,
48
const CompRegion &paintRegion,
59
52
GLushort colorData[4];
60
53
const GLushort *selColorData = ExpoScreen::get (screen)->optionGetSelectedColor ();
61
float alpha = (float) selColorData[3] / 65535.0f;
54
float alpha = static_cast <float> (selColorData[3] / 65535.0f);
63
56
/* Premultiply color */
64
57
colorData[0] = selColorData[0] * alpha;
71
64
/* There are 8 glow parts of the glow texture which we wish to paint
72
65
* separately with different transformations
74
for (i = 0; i < NUM_GLOWQUADS; i++)
67
for (int i = 0; i < NUM_GLOWQUADS; ++i)
76
69
/* Using precalculated quads here */
77
70
reg = CompRegion (mGlowQuads[i].mBox);
88
81
matl.push_back (mGlowQuads[i].mMatrix);
89
82
/* Add color data for all 6 vertices of the quad */
90
for (int n = 0; n < 6; n++)
83
for (int n = 0; n < 6; ++n)
91
84
gWindow->vertexBuffer ()->addColors (1, colorData);
92
86
gWindow->glAddGeometry (matl, reg, paintRegion);
117
111
* ExpoWindow::computeGlowQuads
119
* This function computures the matrix transformation required for each
113
* This function computes the matrix transformation required for each
120
114
* part of the glow texture which we wish to stretch to some rectangular
154
148
ExpoWindow::computeGlowQuads (GLTexture::Matrix *matrix)
158
GLTexture::Matrix *quadMatrix;
159
int glowSize, glowOffset;
160
CompWindow *w = window;
162
150
/* Passing NULL to this function frees the glow quads
163
151
* (so the window is not painted with glow) */
176
165
delete[] mGlowQuads;
177
166
mGlowQuads = NULL;
183
glowOffset = (glowSize * ExpoScreen::get (screen)->mGlowTextureProperties->glowOffset /
184
ExpoScreen::get (screen)->mGlowTextureProperties->textureSize) + 1;
172
/* TODO: Make glowSize configurable via CCSM */
174
int glowOffset = (glowSize * ExpoScreen::get (screen)->mGlowTextureProperties->glowOffset /
175
ExpoScreen::get (screen)->mGlowTextureProperties->textureSize) + 1;
186
177
/* Top left corner */
187
box = &mGlowQuads[GLOWQUAD_TOPLEFT].mBox;
178
CompRect *box = &mGlowQuads[GLOWQUAD_TOPLEFT].mBox;
188
179
mGlowQuads[GLOWQUAD_TOPLEFT].mMatrix = *matrix;
189
quadMatrix = &mGlowQuads[GLOWQUAD_TOPLEFT].mMatrix;
180
GLTexture::Matrix *quadMatrix = &mGlowQuads[GLOWQUAD_TOPLEFT].mMatrix;
182
/* Precalculate some values we need multiple times */
184
CompWindow *w = window;
186
int winRealX = w->x () - w->border ().left;
187
int winRealY = w->y () - w->border ().top;
191
189
/* Set the desired rect dimensions
192
190
* for the part of the glow we are painting */
194
x1 = WIN_REAL_X (w) - glowSize + glowOffset;
195
y1 = WIN_REAL_Y (w) - glowSize + glowOffset;
192
int x1 = winRealX - glowSize + glowOffset;
193
int y1 = winRealY - glowSize + glowOffset;
195
int winRealWidth = w->geometry ().widthIncBorders ();
196
int winRealHeight = w->geometry ().heightIncBorders ();
198
int halfWinRealWidth = winRealWidth / 2;
199
int halfWinRealHeight = winRealHeight / 2;
201
int xPlusHalfWidth = winRealX + halfWinRealWidth;
202
int yPlusHalfHeight = winRealY + halfWinRealHeight;
204
int xPlusGlowOff = winRealX + glowOffset;
205
int yPlusGlowOff = winRealY + glowOffset;
207
int xMinusGlowOff = winRealX - glowOffset;
208
int yMinusGlowOff = winRealY - glowOffset;
210
float glowPart = 1.0f / glowSize;
197
212
/* 2x2 Matrix here, adjust both x and y scale factors
198
213
* and the x and y position
205
220
* multiplied by the scale factors
208
quadMatrix->xx = 1.0f / glowSize;
209
quadMatrix->yy = 1.0f / (glowSize);
223
quadMatrix->xx = quadMatrix->yy = glowPart;
210
224
quadMatrix->x0 = -(x1 * quadMatrix->xx);
211
225
quadMatrix->y0 = -(y1 * quadMatrix->yy);
213
x2 = MIN (WIN_REAL_X (w) + glowOffset,
214
WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
215
y2 = MIN (WIN_REAL_Y (w) + glowOffset,
216
WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
227
int x2 = MIN (xPlusGlowOff,
229
int y2 = MIN (yPlusGlowOff,
218
232
*box = CompRect (x1, y1, x2 - x1, y2 - y1);
225
239
/* Set the desired rect dimensions
226
240
* for the part of the glow we are painting */
228
x1 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
229
y1 = WIN_REAL_Y (w) - glowSize + glowOffset;
230
x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) + glowSize - glowOffset;
242
x1 = xMinusGlowOff + winRealWidth;
243
y1 = yPlusGlowOff - glowSize;
232
246
/* 2x2 Matrix here, adjust both x and y scale factors
233
247
* and the x and y position
242
256
* need the inverse of that which is 1 - x1 * xx
245
quadMatrix->xx = -1.0f / glowSize;
246
quadMatrix->yy = 1.0f / glowSize;
247
quadMatrix->x0 = 1.0 - (x1 * quadMatrix->xx);
259
quadMatrix->xx = -glowPart;
260
quadMatrix->yy = glowPart;
261
quadMatrix->x0 = 1.0 - (x1 * quadMatrix->xx);
248
262
quadMatrix->y0 = -(y1 * quadMatrix->yy);
250
x1 = MAX (WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset,
251
WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
252
y2 = MIN (WIN_REAL_Y (w) + glowOffset,
253
WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
264
x1 = MAX (xMinusGlowOff + winRealWidth,
266
y2 = MIN (yPlusGlowOff,
255
269
*box = CompRect (x1, y1, x2 - x1, y2 - y1);
259
273
mGlowQuads[GLOWQUAD_BOTTOMLEFT].mMatrix = *matrix;
260
274
quadMatrix = &mGlowQuads[GLOWQUAD_BOTTOMLEFT].mMatrix;
262
x1 = WIN_REAL_X (w) - glowSize + glowOffset;
263
y1 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
264
/* x2 = WIN_REAL_X (w) + glowOffset; */
265
y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) + glowSize - glowOffset;
276
x1 = xPlusGlowOff - glowSize;
277
y1 = yMinusGlowOff + winRealHeight;
278
/* x2 = xPlusGlowOff; */
279
y2 = yMinusGlowOff + winRealHeight + glowSize;
267
281
/* 2x2 Matrix here, adjust both x and y scale factors
268
282
* and the x and y position
277
291
* need the inverse of that which is 1 - y1 * yy
280
quadMatrix->xx = 1.0f / glowSize;
281
quadMatrix->yy = -1.0f / glowSize;
294
quadMatrix->xx = glowPart;
295
quadMatrix->yy = -glowPart;
282
296
quadMatrix->x0 = -(x1 * quadMatrix->xx);
283
297
quadMatrix->y0 = 1.0f - (y1 * quadMatrix->yy);
285
y1 = MAX (WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset,
286
WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
287
x2 = MIN (WIN_REAL_X (w) + glowOffset,
288
WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
299
y1 = MAX (winRealY + winRealHeight - glowOffset,
301
x2 = MIN (xPlusGlowOff,
290
304
*box = CompRect (x1, y1, x2 - x1, y2 - y1);
294
308
mGlowQuads[GLOWQUAD_BOTTOMRIGHT].mMatrix = *matrix;
295
309
quadMatrix = &mGlowQuads[GLOWQUAD_BOTTOMRIGHT].mMatrix;
297
x1 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
298
y1 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
299
x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) + glowSize - glowOffset;
300
y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) + glowSize - glowOffset;
311
x1 = xMinusGlowOff + winRealWidth;
312
y1 = yMinusGlowOff + winRealHeight;
302
316
/* 2x2 Matrix here, adjust both x and y scale factors
303
317
* and the x and y position
310
324
* multiplied by the scale factors
313
quadMatrix->xx = -1.0f / glowSize;
314
quadMatrix->yy = -1.0f / glowSize;
327
quadMatrix->xx = -glowPart;
328
quadMatrix->yy = -glowPart;
315
329
quadMatrix->x0 = 1.0 - (x1 * quadMatrix->xx);
316
330
quadMatrix->y0 = 1.0 - (y1 * quadMatrix->yy);
318
x1 = MAX (WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset,
319
WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
320
y1 = MAX (WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset,
321
WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
332
x1 = MAX (xMinusGlowOff + winRealWidth,
334
y1 = MAX (yMinusGlowOff + winRealHeight,
323
337
*box = CompRect (x1, y1, x2 - x1, y2 - y1);
327
341
mGlowQuads[GLOWQUAD_TOP].mMatrix = *matrix;
328
342
quadMatrix = &mGlowQuads[GLOWQUAD_TOP].mMatrix;
330
x1 = WIN_REAL_X (w) + glowOffset;
331
y1 = WIN_REAL_Y (w) - glowSize + glowOffset;
332
x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
333
y2 = WIN_REAL_Y (w) + glowOffset;
345
y1 = yPlusGlowOff - glowSize;
346
x2 = xMinusGlowOff + winRealWidth;
335
349
/* 2x2 Matrix here, adjust both x and y scale factors
336
350
* and the x and y position
355
369
mGlowQuads[GLOWQUAD_BOTTOM].mMatrix = *matrix;
356
370
quadMatrix = &mGlowQuads[GLOWQUAD_BOTTOM].mMatrix;
358
x1 = WIN_REAL_X (w) + glowOffset;
359
y1 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
360
x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
361
y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) + glowSize - glowOffset;
373
y1 = yMinusGlowOff + winRealHeight;
374
x2 = xMinusGlowOff + winRealWidth;
363
377
/* 2x2 Matrix here, adjust both x and y scale factors
364
378
* and the x and y position
383
397
mGlowQuads[GLOWQUAD_LEFT].mMatrix = *matrix;
384
398
quadMatrix = &mGlowQuads[GLOWQUAD_LEFT].mMatrix;
386
x1 = WIN_REAL_X (w) - glowSize + glowOffset;
387
y1 = WIN_REAL_Y (w) + glowOffset;
388
x2 = WIN_REAL_X (w) + glowOffset;
389
y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
400
x1 = xPlusGlowOff - glowSize;
403
y2 = yMinusGlowOff + winRealHeight;
391
405
/* 2x2 Matrix here, adjust both x and y scale factors
392
406
* and the x and y position
411
425
mGlowQuads[GLOWQUAD_RIGHT].mMatrix = *matrix;
412
426
quadMatrix = &mGlowQuads[GLOWQUAD_RIGHT].mMatrix;
414
x1 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
415
y1 = WIN_REAL_Y (w) + glowOffset;
416
x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) + glowSize - glowOffset;
417
y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
428
x1 = xMinusGlowOff + winRealWidth;
430
x2 = xMinusGlowOff + winRealWidth + glowSize;
431
y2 = yMinusGlowOff + winRealHeight;
419
433
/* 2x2 Matrix here, adjust both x and y scale factors
420
434
* and the x and y position