~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to switcher/src/applet-draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

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
/************************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Cchumi & Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
************************************************************************************/
 
28
#include <string.h>
 
29
#include <glib/gstdio.h>
 
30
#include <math.h>
 
31
 
 
32
#include "applet-struct.h"
 
33
#include "applet-load-icons.h"
 
34
#include "applet-draw.h"
 
35
 
 
36
gboolean my_bRotateIconsOnEllipse = TRUE;
 
37
 
 
38
 
 
39
static void _cd_switcher_draw_windows_on_viewport (Icon *pIcon, gint *data)
 
40
{
 
41
        if (pIcon == NULL || pIcon->fPersonnalScale > 0)
 
42
                return ;
 
43
        if (pIcon->bIsHidden && ! myConfig.bDisplayHiddenWindows)
 
44
                return ;
 
45
        int iNumDesktop = data[0];
 
46
        int iNumViewportX = data[1];
 
47
        int iNumViewportY = data[2];
 
48
        int iOneViewportWidth = data[3];
 
49
        int iOneViewportHeight = data[4];
 
50
        cairo_t *pCairoContext = GINT_TO_POINTER (data[5]);
 
51
        
 
52
        // On calcule les coordonnees en repere absolu.
 
53
        int x = pIcon->windowGeometry.x;  // par rapport au viewport courant.
 
54
        x += myData.switcher.iCurrentViewportX * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];  // repere absolu
 
55
        if (x < 0)
 
56
                x += g_iNbViewportX * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
 
57
        int y = pIcon->windowGeometry.y;
 
58
        y += myData.switcher.iCurrentViewportY * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
 
59
        if (y < 0)
 
60
                y += g_iNbViewportY * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
 
61
        int w = pIcon->windowGeometry.width, h = pIcon->windowGeometry.height;
 
62
        
 
63
        // test d'intersection avec le viewport donne.
 
64
        //g_print (" %s : (%d;%d) %dx%d\n", pIcon->acName, x, y, w, h);
 
65
        if ((pIcon->iNumDesktop != -1 && pIcon->iNumDesktop != iNumDesktop) ||
 
66
                x + w <= iNumViewportX * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] ||
 
67
                x >= (iNumViewportX + 1) * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] ||
 
68
                y + h <= iNumViewportY * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL] ||
 
69
                y >= (iNumViewportY + 1) * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL])
 
70
                return ;
 
71
        //g_print (" > on la dessine (%x)\n", pIcon->pIconBuffer);
 
72
        
 
73
        // on dessine ses traits.
 
74
        cairo_save (pCairoContext);
 
75
        
 
76
        cairo_set_source_rgba (pCairoContext, myConfig.RGBWLineColors[0], myConfig.RGBWLineColors[1], myConfig.RGBWLineColors[2], myConfig.RGBWLineColors[3]);
 
77
        cairo_rectangle (pCairoContext,
 
78
                (1.*x/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] - iNumViewportX)*iOneViewportWidth,
 
79
                (1.*y/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL] - iNumViewportY)*iOneViewportHeight,
 
80
                1.*w/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL]*iOneViewportWidth,
 
81
                1.*h/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL]*iOneViewportHeight);
 
82
        if (pIcon->Xid == cairo_dock_get_current_active_window ())
 
83
        {
 
84
                //g_print (" %s est la fenetre active\n", pIcon->acName);
 
85
                cairo_fill (pCairoContext);
 
86
        }
 
87
        else
 
88
        {
 
89
                cairo_stroke (pCairoContext);
 
90
        }
 
91
        
 
92
        if (pIcon->pIconBuffer != NULL)
 
93
        {
 
94
                CairoDock *pParentDock = NULL;
 
95
                pParentDock = cairo_dock_search_dock_from_name (pIcon->cParentDockName);
 
96
                if (pParentDock == NULL)
 
97
                        pParentDock = g_pMainDock;
 
98
                int iWidth, iHeight;
 
99
                cairo_dock_get_icon_extent (pIcon, pParentDock, &iWidth, &iHeight);
 
100
                double fZoomX = (double) w/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL]*iOneViewportWidth / iWidth;
 
101
                double fZoomY = (double) h/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL]*iOneViewportHeight / iHeight;
 
102
                double fZoom = MIN (fZoomX, fZoomY);  // on garde le ratio.
 
103
                
 
104
                cairo_translate (pCairoContext,
 
105
                        (1.*x/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] - iNumViewportX)*iOneViewportWidth + (fZoomX - fZoom) * iWidth/2,
 
106
                        (1.*y/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL] - iNumViewportY)*iOneViewportHeight + (fZoomY - fZoom) * iHeight/2);
 
107
                cairo_scale (pCairoContext,
 
108
                        fZoom,
 
109
                        fZoom);
 
110
                cairo_set_source_surface (pCairoContext,
 
111
                        pIcon->pIconBuffer,
 
112
                        0.,
 
113
                        0.);
 
114
                cairo_paint (pCairoContext);
 
115
        }
 
116
        
 
117
        cairo_restore (pCairoContext);
 
118
}
 
119
 
 
120
 
 
121
static int _compare_icons_stack_order (Icon *icon1, Icon *icon2)
 
122
{
 
123
        if (icon1 == NULL)  // les icones nulles vont a la fin.
 
124
                return 1;
 
125
        if (icon2 == NULL)
 
126
                return -1;
 
127
        if (icon1->iStackOrder < icon2->iStackOrder)  // ordre petit => dessus => dessinee en dernier.
 
128
                return -1;
 
129
        else
 
130
                return 1;
 
131
}
 
132
void cd_switcher_draw_main_icon_compact_mode (void)
 
133
{
 
134
        //cd_debug ("%s (%d;%d)", __func__, myData.switcher.iCurrentLine, myData.switcher.iCurrentColumn);
 
135
        // On efface l'icone.
 
136
        cairo_dock_erase_cairo_context (myDrawContext);
 
137
        
 
138
        // definition des parametres de dessin.
 
139
        //double fRatio = (myDock ? myDock->fRatio : 1.);
 
140
        //double fMaxScale = cairo_dock_get_max_scale (myContainer); //coefficient Max icone Width
 
141
        int iWidth, iHeight;
 
142
        CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
 
143
        myData.switcher.fOneViewportHeight = (iHeight - 2 * myConfig.iLineSize - (myData.switcher.iNbLines - 1) * myConfig.iInLineSize) / myData.switcher.iNbLines; //hauteur d'un bureau/viewport sans compter les lignes exterieures et interieures.
 
144
        myData.switcher.fOneViewportWidth = (iWidth - 2 * myConfig.iLineSize - (myData.switcher.iNbColumns - 1) * myConfig.iInLineSize) / myData.switcher.iNbColumns; //largeur d'un bureau/viewport sans compter les lignes exterieures et interieures.
 
145
        
 
146
        cairo_surface_t *pSurface = NULL;
 
147
        double fZoomX, fZoomY;
 
148
        if (myConfig.bMapWallpaper)
 
149
        {
 
150
                pSurface = cairo_dock_get_desktop_bg_surface ();
 
151
                fZoomX = (double) myData.switcher.fOneViewportWidth / g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
 
152
                fZoomY= (double) myData.switcher.fOneViewportHeight / g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
 
153
        }
 
154
        if (pSurface == NULL)
 
155
        {
 
156
                pSurface = myData.pDefaultMapSurface;
 
157
                fZoomX = (double) myData.switcher.fOneViewportWidth / iWidth;
 
158
                fZoomY = (double) myData.switcher.fOneViewportHeight / iHeight;
 
159
        }
 
160
        
 
161
        // cadre exterieur.
 
162
        cairo_set_line_width (myDrawContext,myConfig.iLineSize);
 
163
        cairo_set_source_rgba(myDrawContext,myConfig.RGBLineColors[0],myConfig.RGBLineColors[1],myConfig.RGBLineColors[2],myConfig.RGBLineColors[3]);
 
164
        cairo_rectangle(myDrawContext,
 
165
                .5*myConfig.iLineSize,
 
166
                .5*myConfig.iLineSize,
 
167
                iWidth - myConfig.iLineSize,
 
168
                iHeight - myConfig.iLineSize);
 
169
 
 
170
        cairo_stroke (myDrawContext);
 
171
        
 
172
        // lignes interieures.
 
173
        cairo_set_line_width (myDrawContext,myConfig.iInLineSize);
 
174
        cairo_set_source_rgba(myDrawContext,myConfig.RGBInLineColors[0],myConfig.RGBInLineColors[1],myConfig.RGBInLineColors[2],myConfig.RGBInLineColors[3]);
 
175
        double xi, yj;
 
176
        int i, j;
 
177
        for (i = 1; i <myData.switcher.iNbColumns; i ++)  // lignes verticales.
 
178
        {
 
179
                xi = myConfig.iLineSize + i * (myData.switcher.fOneViewportWidth + myConfig.iInLineSize) - .5*myConfig.iInLineSize;
 
180
                cairo_move_to (myDrawContext, xi, myConfig.iLineSize);
 
181
                cairo_rel_line_to (myDrawContext, 0, iHeight - 2*myConfig.iLineSize);
 
182
                cairo_stroke (myDrawContext);
 
183
        }
 
184
        for (j = 1; j < myData.switcher.iNbLines; j ++)  // lignes horizontales.
 
185
        {
 
186
                yj = myConfig.iLineSize + j * (myData.switcher.fOneViewportHeight + myConfig.iInLineSize) - .5*myConfig.iInLineSize;
 
187
                cairo_move_to (myDrawContext, myConfig.iLineSize, yj);
 
188
                cairo_rel_line_to (myDrawContext, iWidth - 2*myConfig.iLineSize, 0);
 
189
                cairo_stroke (myDrawContext);
 
190
        }
 
191
        
 
192
        GList *pWindowList = NULL;
 
193
        if (myConfig.bDrawWindows)
 
194
        {
 
195
                pWindowList = cairo_dock_get_current_applis_list ();
 
196
                pWindowList = g_list_sort (pWindowList, (GCompareFunc) _compare_icons_stack_order);
 
197
        }
 
198
        
 
199
        // chaque bureau/viewport.
 
200
        int iNumDesktop=0, iNumViewportX=0, iNumViewportY=0;
 
201
        for (j = 0; j < myData.switcher.iNbLines; j ++)
 
202
        {
 
203
                for (i = 0; i < myData.switcher.iNbColumns; i ++)
 
204
                {
 
205
                        cairo_save (myDrawContext);
 
206
 
 
207
                        xi = myConfig.iLineSize + i * (myData.switcher.fOneViewportWidth + myConfig.iInLineSize);
 
208
                        yj = myConfig.iLineSize + j * (myData.switcher.fOneViewportHeight + myConfig.iInLineSize);
 
209
 
 
210
                        cairo_translate (myDrawContext,
 
211
                                xi,
 
212
                                yj);
 
213
 
 
214
                        cairo_scale (myDrawContext,
 
215
                                fZoomX,
 
216
                                fZoomY);
 
217
                        cairo_set_source_surface (myDrawContext,
 
218
                                pSurface,
 
219
                                0.,
 
220
                                0.);
 
221
                        cairo_paint(myDrawContext);
 
222
                        
 
223
                        cairo_restore (myDrawContext);
 
224
                        
 
225
                        if (myConfig.iDrawCurrentDesktopMode == SWICTHER_FILL_INVERTED && (i != myData.switcher.iCurrentColumn || j != myData.switcher.iCurrentLine))
 
226
                        {
 
227
                                cairo_save (myDrawContext);
 
228
                                
 
229
                                cairo_set_source_rgba (myDrawContext, myConfig.RGBIndColors[0], myConfig.RGBIndColors[1], myConfig.RGBIndColors[2], myConfig.RGBIndColors[3]);
 
230
                                cairo_rectangle(myDrawContext,
 
231
                                        xi - .5*myConfig.iLineSize,
 
232
                                        yj - .5*myConfig.iLineSize,
 
233
                                        myData.switcher.fOneViewportWidth + myConfig.iLineSize,
 
234
                                        myData.switcher.fOneViewportHeight + myConfig.iLineSize);
 
235
                                cairo_fill (myDrawContext);
 
236
                                
 
237
                                cairo_restore (myDrawContext);
 
238
                        }
 
239
                        
 
240
                        if (myConfig.bDrawWindows)
 
241
                        {
 
242
                                cairo_save (myDrawContext);
 
243
                                
 
244
                                cairo_translate (myDrawContext,
 
245
                                        xi,
 
246
                                        yj);
 
247
                                cairo_set_line_width (myDrawContext, 1.);
 
248
                                cairo_rectangle (myDrawContext,
 
249
                                        0.,
 
250
                                        0.,
 
251
                                        myData.switcher.fOneViewportWidth,
 
252
                                        myData.switcher.fOneViewportHeight);
 
253
                                cairo_clip (myDrawContext);
 
254
                                
 
255
                                //g_print (" dessin des fenetres du bureau (%d;%d;%d) ...\n", iNumDesktop, iNumViewportX, iNumViewportY);
 
256
                                gint data[6] = {iNumDesktop, iNumViewportX, iNumViewportY, (int) myData.switcher.fOneViewportWidth, (int) myData.switcher.fOneViewportHeight, GPOINTER_TO_INT (myDrawContext)};
 
257
                                g_list_foreach (pWindowList, (GFunc) _cd_switcher_draw_windows_on_viewport, data);
 
258
                                
 
259
                                cairo_restore (myDrawContext);
 
260
                        }
 
261
                        
 
262
                        iNumViewportX ++;
 
263
                        if (iNumViewportX == g_iNbViewportX)
 
264
                        {
 
265
                                iNumViewportY ++;
 
266
                                if (iNumViewportY == g_iNbViewportY)
 
267
                                        iNumDesktop ++;
 
268
                        }
 
269
                }
 
270
        }
 
271
        
 
272
        // dessin de l'indicateur sur le bureau courant (on le fait maintenant car dans le cas ou la ligne interieure est plus petite que la ligne de l'indicateur, les surfaces suivantes recouvreraient en partie la ligne.
 
273
        if (myConfig.iDrawCurrentDesktopMode != SWICTHER_FILL_INVERTED)
 
274
        {
 
275
                i = myData.switcher.iCurrentColumn;
 
276
                j = myData.switcher.iCurrentLine;
 
277
                xi = myConfig.iLineSize + i * (myData.switcher.fOneViewportWidth + myConfig.iInLineSize);
 
278
                yj = myConfig.iLineSize + j * (myData.switcher.fOneViewportHeight + myConfig.iInLineSize);
 
279
                
 
280
                cairo_set_line_width (myDrawContext,myConfig.iLineSize);
 
281
                cairo_set_source_rgba (myDrawContext,myConfig.RGBIndColors[0],myConfig.RGBIndColors[1],myConfig.RGBIndColors[2],myConfig.RGBIndColors[3]);
 
282
                cairo_rectangle(myDrawContext,
 
283
                        xi - .5*myConfig.iLineSize,
 
284
                        yj - .5*myConfig.iLineSize,
 
285
                        myData.switcher.fOneViewportWidth + myConfig.iLineSize,
 
286
                        myData.switcher.fOneViewportHeight + myConfig.iLineSize);
 
287
                
 
288
                if (myConfig.iDrawCurrentDesktopMode == SWICTHER_FILL)
 
289
                        cairo_fill (myDrawContext);
 
290
                else
 
291
                        cairo_stroke(myDrawContext);
 
292
        }
 
293
        
 
294
        g_list_free (pWindowList);  // le contenu appartient a la hash table, mais pas la liste.
 
295
        
 
296
        if (CD_APPLET_MY_CONTAINER_IS_OPENGL)
 
297
                cairo_dock_update_icon_texture (myIcon);
 
298
        else
 
299
                CD_APPLET_UPDATE_REFLECT_ON_MY_ICON;
 
300
}
 
301
 
 
302
 
 
303
void cd_switcher_draw_main_icon_expanded_mode (void)
 
304
{
 
305
        // definition des parametres de dessin.
 
306
        int iWidth, iHeight;
 
307
        CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
 
308
        //double fRatio = (myDock ? myDock->fRatio : 1.);
 
309
        //double fMaxScale = cairo_dock_get_max_scale (myContainer); //coefficient Max icone Width
 
310
        myData.switcher.fOneViewportHeight = (iHeight - 2 * myConfig.iLineSize - (myData.switcher.iNbLines - 1) * myConfig.iInLineSize) / myData.switcher.iNbLines; //hauteur d'un bureau/viewport sans compter les lignes exterieures et interieures.
 
311
        myData.switcher.fOneViewportWidth = (iWidth - 2 * myConfig.iLineSize - (myData.switcher.iNbColumns - 1) * myConfig.iInLineSize) / myData.switcher.iNbColumns; //largeur d'un bureau/viewport sans compter les lignes exterieures et interieures.
 
312
 
 
313
        cairo_surface_t *pSurface = NULL;
 
314
        double fZoomX, fZoomY;
 
315
        if (myConfig.bMapWallpaper)
 
316
        {
 
317
                cairo_dock_erase_cairo_context (myDrawContext);
 
318
                
 
319
                pSurface = cairo_dock_get_desktop_bg_surface ();
 
320
                fZoomX = 1. * iWidth / g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
 
321
                fZoomY= 1. * iHeight / g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
 
322
                cairo_translate (myDrawContext,
 
323
                        0.,
 
324
                        0.);
 
325
 
 
326
                cairo_save (myDrawContext);
 
327
                cairo_scale (myDrawContext,
 
328
                        fZoomX ,
 
329
                        fZoomY );
 
330
                cairo_set_source_surface (myDrawContext,
 
331
                        pSurface,
 
332
                        0.,
 
333
                        0.);
 
334
                cairo_paint(myDrawContext);
 
335
                cairo_restore (myDrawContext);
 
336
                
 
337
                if (CD_APPLET_MY_CONTAINER_IS_OPENGL)
 
338
                        cairo_dock_update_icon_texture (myIcon);
 
339
                else
 
340
                        CD_APPLET_UPDATE_REFLECT_ON_MY_ICON;
 
341
        }
 
342
        else
 
343
        {
 
344
                CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON (MY_APPLET_ICON_FILE);
 
345
        }
 
346
 
 
347
        if (myConfig.bDrawWindows)
 
348
        {
 
349
                GList *pWindowList = cairo_dock_get_current_applis_list ();
 
350
                pWindowList = g_list_sort (pWindowList, (GCompareFunc) _compare_icons_stack_order);
 
351
                
 
352
                //fMaxScale = (myIcon->pSubDock != NULL ? cairo_dock_get_max_scale (myIcon->pSubDock) : 1);
 
353
                //fRatio = (myIcon->pSubDock != NULL ? myIcon->pSubDock->fRatio : 1);
 
354
                gint data[6];
 
355
                int iNumDesktop=0, iNumViewportX=0, iNumViewportY=0;
 
356
                cairo_t *pCairoContext;
 
357
                Icon *pIcon;
 
358
                CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
 
359
                GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
 
360
                GList *ic;
 
361
                for (ic = pIconsList; ic != NULL; ic = ic->next)
 
362
                {
 
363
                        pIcon = ic->data;
 
364
                        cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
 
365
                        
 
366
                        data[0] = iNumDesktop;
 
367
                        data[1] = iNumViewportX;
 
368
                        data[2] = iNumViewportY;
 
369
                        data[3] = iWidth;
 
370
                        data[4] = iHeight;
 
371
                        pCairoContext = cairo_create (pIcon->pIconBuffer);
 
372
                        data[5] = GPOINTER_TO_INT (pCairoContext);
 
373
                        cairo_set_line_width (pCairoContext, 1.);
 
374
                        cairo_set_source_rgba (pCairoContext, myConfig.RGBWLineColors[0], myConfig.RGBWLineColors[1], myConfig.RGBWLineColors[2], myConfig.RGBWLineColors[3]);
 
375
                
 
376
                        g_list_foreach (pWindowList, (GFunc) _cd_switcher_draw_windows_on_viewport, data);
 
377
                        
 
378
                        iNumViewportX ++;
 
379
                        if (iNumViewportX == g_iNbViewportX)
 
380
                        {
 
381
                                iNumViewportY ++;
 
382
                                if (iNumViewportY == g_iNbViewportY)
 
383
                                        iNumDesktop ++;
 
384
                        }
 
385
                        cairo_destroy (pCairoContext);
 
386
                }
 
387
                g_list_free (pWindowList);  // le contenu appartient a la hash table, mais pas la liste.
 
388
        }
 
389
}
 
390
 
 
391
/*Fonction de base pour toutes les autres*/
 
392
void cd_switcher_draw_main_icon (void)
 
393
{
 
394
        cd_message ("%s (%d)", __func__, myConfig.bCompactView);
 
395
        if (myConfig.bCompactView)
 
396
        {
 
397
                cd_switcher_draw_main_icon_compact_mode ();
 
398
        }
 
399
        else
 
400
        {
 
401
                cd_switcher_draw_main_icon_expanded_mode ();
 
402
        }
 
403
        
 
404
        CD_APPLET_REDRAW_MY_ICON;
 
405
}