~ubuntu-branches/ubuntu/maverick/cairo-dock/maverick

« back to all changes in this revision

Viewing changes to src/implementations/cairo-dock-icon-container.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-09 23:26:12 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100809232612-yp4c6ig3jt1bzpdv
Tags: 2.2.0~0beta4-0ubuntu1
* New Upstream Version (LP: #614624)
* Fixed a few bugs on LP:
 - LP: #518453: Dock appears under all windows
                 (Compiz - fullscreen window)
 - LP: #521369: Separator are not removed when closing
                 grouped windows
 - LP: #521762: Some sentences are not correct
 - LP: #526466: Icons of apps with same class shouldn't
                 be stacked by default
 - LP: #535083: Dialogues looks ugly when a lot of them
                 appears at the same time
 - More details on the 'ChangeLog' file
* debian/rules:
 - Autotools has been replaced by CMake
 - Man pages are now included in the source code
* debian/copyright:
 - Updated with the new pathes and new files
* debian/control:
 - Autotools has been replaced by CMake
 - Added libcurl4-gnutls-dev as Build-deps
 - Bump Standard-Version to 3.9.1
* debian/cairo-dock-core.install:
 - Man pages are now included in the source code
 - All sonames are now installed into lib32 or lib64
* debian/cairo-dock-dev.install:
 - pkgconfig is now installed into lib32 or lib64

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
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.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#include <math.h>
 
21
#include <string.h>
 
22
#include <stdlib.h>
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#ifdef HAVE_GLITZ
 
27
#include <gdk/gdkx.h>
 
28
#include <glitz-glx.h>
 
29
#include <cairo-glitz.h>
 
30
#endif
 
31
 
 
32
#include <gtk/gtkgl.h>
 
33
 
 
34
#include "../config.h"
 
35
#include "cairo-dock-load.h"
 
36
#include "cairo-dock-log.h"
 
37
#include "cairo-dock-draw.h"
 
38
#include "cairo-dock-draw-opengl.h"
 
39
#include "cairo-dock-internal-icons.h"
 
40
#include "cairo-dock-emblem.h"
 
41
#include "cairo-dock-backends-manager.h"
 
42
#include "cairo-dock-icon-container.h"
 
43
 
 
44
#define CAIRO_DOCK_DEFAULT_APPLI_ICON_NAME "default-icon-appli.svg"
 
45
 
 
46
CairoDockImageBuffer g_pBoxAboveBuffer;
 
47
CairoDockImageBuffer g_pBoxBelowBuffer;
 
48
 
 
49
extern CairoDock *g_pMainDock;
 
50
extern CairoDockDesktopGeometry g_desktopGeometry;
 
51
 
 
52
extern gchar *g_cCurrentThemePath;
 
53
 
 
54
extern CairoDockImageBuffer g_pIconBackgroundBuffer;
 
55
 
 
56
extern gboolean g_bUseOpenGL;
 
57
 
 
58
 
 
59
static void _cairo_dock_draw_subdock_content_as_emblem (Icon *pIcon, CairoContainer *pContainer, int w, int h, cairo_t *pCairoContext)
 
60
{
 
61
        //\______________ On dessine les 4 premieres icones du sous-dock en embleme.
 
62
        CairoEmblem e;
 
63
        memset (&e, 0, sizeof (CairoEmblem));
 
64
        e.fScale = .5;
 
65
        int i;
 
66
        Icon *icon;
 
67
        GList *ic;
 
68
        for (ic = pIcon->pSubDock->icons, i = 0; ic != NULL && i < 4; ic = ic->next, i++)
 
69
        {
 
70
                icon = ic->data;
 
71
                if (CAIRO_DOCK_IS_SEPARATOR (icon))
 
72
                {
 
73
                        i --;
 
74
                        continue;
 
75
                }
 
76
                e.iPosition = i;
 
77
                e.pSurface = icon->pIconBuffer;
 
78
                cairo_dock_get_icon_extent (icon, CAIRO_CONTAINER (pIcon->pSubDock), &e.iWidth, &e.iHeight);
 
79
                
 
80
                cairo_save (pCairoContext);
 
81
                _cairo_dock_apply_emblem_surface (&e, w, h, pCairoContext);
 
82
                cairo_restore (pCairoContext);
 
83
        }
 
84
}
 
85
 
 
86
static void _cairo_dock_draw_subdock_content_as_emblem_opengl (Icon *pIcon, CairoContainer *pContainer, int w, int h)
 
87
{
 
88
        //\______________ On dessine les 4 premieres icones du sous-dock en embleme.
 
89
        CairoEmblem e;
 
90
        memset (&e, 0, sizeof (CairoEmblem));
 
91
        e.fScale = .5;
 
92
        int i;
 
93
        Icon *icon;
 
94
        GList *ic;
 
95
        for (ic = pIcon->pSubDock->icons, i = 0; ic != NULL && i < 4; ic = ic->next, i++)
 
96
        {
 
97
                icon = ic->data;
 
98
                if (CAIRO_DOCK_IS_SEPARATOR (icon))
 
99
                {
 
100
                        i --;
 
101
                        continue;
 
102
                }
 
103
                e.iPosition = i;
 
104
                e.iTexture = icon->iIconTexture;
 
105
                _cairo_dock_apply_emblem_texture (&e, w, h);
 
106
        }
 
107
}
 
108
 
 
109
static void _cairo_dock_draw_subdock_content_as_stack (Icon *pIcon, CairoContainer *pContainer, int w, int h, cairo_t *pCairoContext)
 
110
{
 
111
        //\______________ On dessine les 4 premieres icones du sous-dock en pile.
 
112
        CairoEmblem e;
 
113
        memset (&e, 0, sizeof (CairoEmblem));
 
114
        e.fScale = .8;
 
115
        int i;
 
116
        Icon *icon;
 
117
        GList *ic;
 
118
        for (ic = pIcon->pSubDock->icons, i = 0; ic != NULL && i < 3; ic = ic->next, i++)
 
119
        {
 
120
                icon = ic->data;
 
121
                if (CAIRO_DOCK_IS_SEPARATOR (icon))
 
122
                {
 
123
                        i --;
 
124
                        continue;
 
125
                }
 
126
                switch (i)
 
127
                {
 
128
                        case 0:
 
129
                                e.iPosition = CAIRO_DOCK_EMBLEM_UPPER_RIGHT;
 
130
                        break;
 
131
                        case 1:
 
132
                                if (ic->next == NULL)
 
133
                                        e.iPosition = CAIRO_DOCK_EMBLEM_LOWER_LEFT;
 
134
                                else
 
135
                                        e.iPosition = CAIRO_DOCK_EMBLEM_MIDDLE;
 
136
                        break;
 
137
                        case 2:
 
138
                                e.iPosition = CAIRO_DOCK_EMBLEM_LOWER_LEFT;
 
139
                        break;
 
140
                        default : break;
 
141
                }
 
142
                
 
143
                e.pSurface = icon->pIconBuffer;
 
144
                cairo_dock_get_icon_extent (icon, CAIRO_CONTAINER (pIcon->pSubDock), &e.iWidth, &e.iHeight);
 
145
                
 
146
                cairo_save (pCairoContext);
 
147
                _cairo_dock_apply_emblem_surface (&e, w, h, pCairoContext);
 
148
                cairo_restore (pCairoContext);
 
149
        }
 
150
}
 
151
 
 
152
static void _cairo_dock_draw_subdock_content_as_stack_opengl (Icon *pIcon, CairoContainer *pContainer, int w, int h)
 
153
{
 
154
        //\______________ On dessine les 4 premieres icones du sous-dock en pile.
 
155
        CairoEmblem e;
 
156
        memset (&e, 0, sizeof (CairoEmblem));
 
157
        e.fScale = .8;
 
158
        int i;
 
159
        Icon *icon;
 
160
        GList *ic;
 
161
        for (ic = pIcon->pSubDock->icons, i = 0; ic != NULL && i < 3; ic = ic->next, i++)
 
162
        {
 
163
                icon = ic->data;
 
164
                if (CAIRO_DOCK_IS_SEPARATOR (icon))
 
165
                {
 
166
                        i --;
 
167
                        continue;
 
168
                }
 
169
                switch (i)
 
170
                {
 
171
                        case 0:
 
172
                                e.iPosition = CAIRO_DOCK_EMBLEM_UPPER_RIGHT;
 
173
                        break;
 
174
                        case 1:
 
175
                                if (ic->next == NULL)
 
176
                                        e.iPosition = CAIRO_DOCK_EMBLEM_LOWER_LEFT;
 
177
                                else
 
178
                                        e.iPosition = CAIRO_DOCK_EMBLEM_MIDDLE;
 
179
                        break;
 
180
                        case 2:
 
181
                                e.iPosition = CAIRO_DOCK_EMBLEM_LOWER_LEFT;
 
182
                        break;
 
183
                        default : break;
 
184
                }
 
185
                e.iTexture = icon->iIconTexture;
 
186
                _cairo_dock_apply_emblem_texture (&e, w, h);
 
187
        }
 
188
}
 
189
 
 
190
 
 
191
static void _cairo_dock_load_box_surface (void)
 
192
{
 
193
        double fMaxScale = cairo_dock_get_max_scale (g_pMainDock);
 
194
        
 
195
        cairo_dock_unload_image_buffer (&g_pBoxAboveBuffer);
 
196
        cairo_dock_unload_image_buffer (&g_pBoxBelowBuffer);
 
197
        
 
198
        int iSize = myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER];
 
199
        if (iSize == 0)
 
200
                iSize = 48;
 
201
        iSize *= fMaxScale;
 
202
        
 
203
        gchar *cUserPath = cairo_dock_generate_file_path ("box-front.png");
 
204
        if (! g_file_test (cUserPath, G_FILE_TEST_EXISTS))
 
205
        {
 
206
                g_free (cUserPath);
 
207
                cUserPath = NULL;
 
208
        }
 
209
        cairo_dock_load_image_buffer (&g_pBoxAboveBuffer,
 
210
                cUserPath ? cUserPath : CAIRO_DOCK_SHARE_DATA_DIR"/box-front.png",
 
211
                iSize,
 
212
                iSize,
 
213
                CAIRO_DOCK_FILL_SPACE);
 
214
        
 
215
        cUserPath = cairo_dock_generate_file_path ("box-back.png");
 
216
        if (! g_file_test (cUserPath, G_FILE_TEST_EXISTS))
 
217
        {
 
218
                g_free (cUserPath);
 
219
                cUserPath = NULL;
 
220
        }
 
221
        cairo_dock_load_image_buffer (&g_pBoxBelowBuffer,
 
222
                CAIRO_DOCK_SHARE_DATA_DIR"/box-back.png",
 
223
                iSize,
 
224
                iSize,
 
225
                CAIRO_DOCK_FILL_SPACE);
 
226
}
 
227
 
 
228
static void _cairo_dock_unload_box_surface (void)
 
229
{
 
230
        cairo_dock_unload_image_buffer (&g_pBoxAboveBuffer);
 
231
        cairo_dock_unload_image_buffer (&g_pBoxBelowBuffer);
 
232
}
 
233
 
 
234
static void _cairo_dock_draw_subdock_content_as_box (Icon *pIcon, CairoContainer *pContainer, int w, int h, cairo_t *pCairoContext)
 
235
{
 
236
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
 
237
        cairo_save (pCairoContext);
 
238
        cairo_scale(pCairoContext,
 
239
                (double) w / g_pBoxBelowBuffer.iWidth,
 
240
                (double) h / g_pBoxBelowBuffer.iHeight);
 
241
        cairo_dock_draw_surface (pCairoContext,
 
242
                g_pBoxBelowBuffer.pSurface,
 
243
                g_pBoxBelowBuffer.iWidth, g_pBoxBelowBuffer.iHeight,
 
244
                pContainer->bDirectionUp,
 
245
                pContainer->bIsHorizontal,
 
246
                1.);
 
247
        /**cairo_set_source_surface (pCairoContext,
 
248
                g_pBoxBelowBuffer.pSurface,
 
249
                0.,
 
250
                0.);
 
251
        cairo_paint (pCairoContext);*/
 
252
        cairo_restore (pCairoContext);
 
253
        
 
254
        cairo_save (pCairoContext);
 
255
        if (pContainer->bIsHorizontal)
 
256
        {
 
257
                if (!pContainer->bDirectionUp)
 
258
                        cairo_translate (pCairoContext, 0., .2*h);
 
259
        }
 
260
        else
 
261
        {
 
262
                if (! pContainer->bDirectionUp)
 
263
                        cairo_translate (pCairoContext, .2*h, 0.);
 
264
        }
 
265
        cairo_scale(pCairoContext,
 
266
                .8,
 
267
                .8);
 
268
        int i;
 
269
        double dx, dy;
 
270
        Icon *icon;
 
271
        GList *ic;
 
272
        for (ic = pIcon->pSubDock->icons, i = 0; ic != NULL && i < 3; ic = ic->next, i++)
 
273
        {
 
274
                icon = ic->data;
 
275
                if (CAIRO_DOCK_IS_SEPARATOR (icon))
 
276
                {
 
277
                        i --;
 
278
                        continue;
 
279
                }
 
280
                
 
281
                if (pContainer->bIsHorizontal)
 
282
                {
 
283
                        dx = .1*w;
 
284
                        if (pContainer->bDirectionUp)
 
285
                                dy = .1*i*h;
 
286
                        else
 
287
                                dy = - .1*i*h;
 
288
                }
 
289
                else
 
290
                {
 
291
                        dy = .1*w;
 
292
                        if (pContainer->bDirectionUp)
 
293
                                dx = .1*i*h;
 
294
                        else
 
295
                                dx = - .1*i*h;
 
296
                }
 
297
                cairo_set_source_surface (pCairoContext,
 
298
                        icon->pIconBuffer,
 
299
                        dx,
 
300
                        dy);
 
301
                cairo_paint (pCairoContext);
 
302
        }
 
303
        cairo_restore (pCairoContext);
 
304
        
 
305
        cairo_scale(pCairoContext,
 
306
                (double) w / g_pBoxAboveBuffer.iWidth,
 
307
                (double) h / g_pBoxAboveBuffer.iHeight);
 
308
        cairo_dock_draw_surface (pCairoContext,
 
309
                g_pBoxAboveBuffer.pSurface,
 
310
                g_pBoxAboveBuffer.iWidth, g_pBoxAboveBuffer.iHeight,
 
311
                pContainer->bDirectionUp,
 
312
                pContainer->bIsHorizontal,
 
313
                1.);
 
314
        /**cairo_set_source_surface (pCairoContext,
 
315
                g_pBoxAboveBuffer.pSurface,
 
316
                0.,
 
317
                0.);
 
318
        cairo_paint (pCairoContext);*/
 
319
}
 
320
 
 
321
static void _cairo_dock_draw_subdock_content_as_box_opengl (Icon *pIcon, CairoContainer *pContainer, int w, int h)
 
322
{
 
323
        _cairo_dock_set_blend_source ();
 
324
        glPushMatrix ();
 
325
        if (pContainer->bIsHorizontal)
 
326
        {
 
327
                if (! pContainer->bDirectionUp)
 
328
                        glScalef (1., -1., 1.);
 
329
        }
 
330
        else
 
331
        {
 
332
                glRotatef (90., 0., 0., 1.);
 
333
                if (! pContainer->bDirectionUp)
 
334
                        glScalef (1., -1., 1.);
 
335
        }
 
336
        _cairo_dock_apply_texture_at_size (g_pBoxBelowBuffer.iTexture, w, h);
 
337
        
 
338
        glMatrixMode(GL_TEXTURE);
 
339
        glPushMatrix ();
 
340
        if (pContainer->bIsHorizontal)
 
341
        {
 
342
                if (! pContainer->bDirectionUp)
 
343
                        glScalef (1., -1., 1.);
 
344
        }
 
345
        else
 
346
        {
 
347
                glRotatef (-90., 0., 0., 1.);
 
348
                if (! pContainer->bDirectionUp)
 
349
                        glScalef (1., -1., 1.);
 
350
        }
 
351
        glMatrixMode (GL_MODELVIEW);
 
352
        _cairo_dock_set_blend_alpha ();
 
353
        int i;
 
354
        Icon *icon;
 
355
        GList *ic;
 
356
        for (ic = pIcon->pSubDock->icons, i = 0; ic != NULL && i < 3; ic = ic->next, i++)
 
357
        {
 
358
                icon = ic->data;
 
359
                if (CAIRO_DOCK_IS_SEPARATOR (icon))
 
360
                {
 
361
                        i --;
 
362
                        continue;
 
363
                }
 
364
                glBindTexture (GL_TEXTURE_2D, icon->iIconTexture);
 
365
                _cairo_dock_apply_current_texture_at_size_with_offset (.8*w, .8*h, 0., .1*(1-i)*h);
 
366
        }
 
367
        glMatrixMode(GL_TEXTURE);
 
368
        glPopMatrix ();
 
369
        glMatrixMode (GL_MODELVIEW);
 
370
        
 
371
        _cairo_dock_apply_texture_at_size (g_pBoxAboveBuffer.iTexture, w, h);
 
372
        glPopMatrix ();
 
373
}
 
374
 
 
375
 
 
376
void cairo_dock_register_icon_container_renderers (void)
 
377
{
 
378
        CairoIconContainerRenderer *p;
 
379
        p = g_new0 (CairoIconContainerRenderer, 1);
 
380
        p->render = _cairo_dock_draw_subdock_content_as_emblem;
 
381
        p->render_opengl = _cairo_dock_draw_subdock_content_as_emblem_opengl;
 
382
        cairo_dock_register_icon_container_renderer ("Emblem", p);
 
383
        
 
384
        p = g_new0 (CairoIconContainerRenderer, 1);
 
385
        p->render = _cairo_dock_draw_subdock_content_as_stack;
 
386
        p->render_opengl = _cairo_dock_draw_subdock_content_as_stack_opengl;
 
387
        cairo_dock_register_icon_container_renderer ("Stack", p);
 
388
        
 
389
        p = g_new0 (CairoIconContainerRenderer, 1);
 
390
        p->load = _cairo_dock_load_box_surface;
 
391
        p->unload = _cairo_dock_unload_box_surface;
 
392
        p->render = _cairo_dock_draw_subdock_content_as_box;
 
393
        p->render_opengl = _cairo_dock_draw_subdock_content_as_box_opengl;
 
394
        cairo_dock_register_icon_container_renderer ("Box", p);
 
395
        
 
396
        memset (&g_pBoxAboveBuffer, 0, sizeof (CairoDockImageBuffer));
 
397
        memset (&g_pBoxBelowBuffer, 0, sizeof (CairoDockImageBuffer));
 
398
}