Merge lp:~cairo-dock-team/cairo-dock-plug-ins/desklet-rendering-pan-view into lp:~cairo-dock-team/cairo-dock-plug-ins/plug-ins
- desklet-rendering-pan-view
- Merge into plug-ins
Proposed by
Tofe
Status: | Merged |
---|---|
Approved by: | Tofe |
Approved revision: | 1702 |
Merged at revision: | 1702 |
Proposed branch: | lp:~cairo-dock-team/cairo-dock-plug-ins/desklet-rendering-pan-view |
Merge into: | lp:~cairo-dock-team/cairo-dock-plug-ins/plug-ins |
Diff against target: |
826 lines (+768/-2) 5 files modified
Folders/src/applet-load-icons.c (+1/-1) desklet-rendering/src/CMakeLists.txt (+1/-0) desklet-rendering/src/rendering-desklet-viewport.c (+707/-0) desklet-rendering/src/rendering-desklet-viewport.h (+56/-0) desklet-rendering/src/rendering-init.c (+3/-1) |
To merge this branch: | bzr merge lp:~cairo-dock-team/cairo-dock-plug-ins/desklet-rendering-pan-view |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tofe (community) | Approve | ||
Review via email: mp+30172@code.launchpad.net |
Commit message
Description of the change
Added view "Viewport", which is alike "Slide", but with panning possibilites. Also default view of "Folders" is now "Viewport".
To post a comment you must log in.
Revision history for this message
Tofe (chris-chapuis) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Folders/src/applet-load-icons.c' |
2 | --- Folders/src/applet-load-icons.c 2010-07-17 00:33:47 +0000 |
3 | +++ Folders/src/applet-load-icons.c 2010-07-17 12:02:42 +0000 |
4 | @@ -353,7 +353,7 @@ |
5 | pList = g_list_prepend (pList, pIcon); |
6 | } |
7 | pList = g_list_reverse (pList); |
8 | - CD_APPLET_LOAD_MY_ICONS_LIST (pList, myConfig.cRenderer, "Slide", NULL); |
9 | + CD_APPLET_LOAD_MY_ICONS_LIST (pList, myConfig.cRenderer, "Viewport", NULL); |
10 | myData.iNbIcons = myConfig.iNbIcons; |
11 | |
12 | //\_______________________ On se place en ecoute. |
13 | |
14 | === modified file 'desklet-rendering/src/CMakeLists.txt' |
15 | --- desklet-rendering/src/CMakeLists.txt 2010-07-06 00:03:56 +0000 |
16 | +++ desklet-rendering/src/CMakeLists.txt 2010-07-17 12:02:42 +0000 |
17 | @@ -9,6 +9,7 @@ |
18 | rendering-desklet-simple.c rendering-desklet-simple.h |
19 | rendering-desklet-decorations.c rendering-desklet-decorations.h |
20 | rendering-desklet-slide.c rendering-desklet-slide.h |
21 | + rendering-desklet-viewport.c rendering-desklet-viewport.h |
22 | rendering-struct.h |
23 | ) |
24 | |
25 | |
26 | === modified file 'desklet-rendering/src/rendering-desklet-slide.c' (properties changed: +x to -x) |
27 | === modified file 'desklet-rendering/src/rendering-desklet-slide.h' (properties changed: +x to -x) |
28 | === added file 'desklet-rendering/src/rendering-desklet-viewport.c' |
29 | --- desklet-rendering/src/rendering-desklet-viewport.c 1970-01-01 00:00:00 +0000 |
30 | +++ desklet-rendering/src/rendering-desklet-viewport.c 2010-07-17 12:02:42 +0000 |
31 | @@ -0,0 +1,707 @@ |
32 | +/** |
33 | +* This file is a part of the Cairo-Dock project |
34 | +* |
35 | +* Copyright : (C) see the 'copyright' file. |
36 | +* E-mail : see the 'copyright' file. |
37 | +* |
38 | +* This program is free software; you can redistribute it and/or |
39 | +* modify it under the terms of the GNU General Public License |
40 | +* as published by the Free Software Foundation; either version 3 |
41 | +* of the License, or (at your option) any later version. |
42 | +* |
43 | +* This program is distributed in the hope that it will be useful, |
44 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
45 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
46 | +* GNU General Public License for more details. |
47 | +* You should have received a copy of the GNU General Public License |
48 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. |
49 | +*/ |
50 | + |
51 | +#include <string.h> |
52 | +#include <math.h> |
53 | +#include <cairo-dock.h> |
54 | + |
55 | +#include "rendering-desklet-viewport.h" |
56 | + |
57 | +#define _cairo_dock_set_path_as_current(...) _cairo_dock_set_vertex_pointer(pVertexTab) |
58 | + |
59 | + |
60 | +static gboolean on_enter_icon_viewport (gpointer pUserData, Icon *pPointedIcon, CairoContainer *pContainer, gboolean *bStartAnimation) |
61 | +{ |
62 | + gtk_widget_queue_draw (pContainer->pWidget); // et oui, on n'a rien d'autre a faire. |
63 | + |
64 | + return CAIRO_DOCK_LET_PASS_NOTIFICATION; |
65 | +} |
66 | + |
67 | +static inline void _viewport_pan_delta(CairoDesklet *pDesklet, double fDeltaX, double fDeltaY) |
68 | +{ |
69 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
70 | + pViewportConf->fCurrentPanXSpeed = fDeltaX; |
71 | + pViewportConf->fCurrentPanYSpeed = fDeltaY; |
72 | + pViewportConf->iCurrentOffsetX += fDeltaX; |
73 | + pViewportConf->iCurrentOffsetY += fDeltaY; |
74 | + if (pViewportConf->iCurrentOffsetX < 0) |
75 | + { |
76 | + pViewportConf->iCurrentOffsetX = 0; |
77 | + pViewportConf->fCurrentPanXSpeed = 0; |
78 | + } |
79 | + else if( pViewportConf->iCurrentOffsetX > pViewportConf->iMaxOffsetX ) |
80 | + { |
81 | + pViewportConf->iCurrentOffsetX = pViewportConf->iMaxOffsetX; |
82 | + pViewportConf->fCurrentPanXSpeed = 0; |
83 | + } |
84 | + if (pViewportConf->iCurrentOffsetY < 0) |
85 | + { |
86 | + pViewportConf->iCurrentOffsetY = 0; |
87 | + pViewportConf->fCurrentPanYSpeed = 0; |
88 | + } |
89 | + else if( pViewportConf->iCurrentOffsetY > pViewportConf->iMaxOffsetY ) |
90 | + { |
91 | + pViewportConf->iCurrentOffsetY = pViewportConf->iMaxOffsetY; |
92 | + pViewportConf->fCurrentPanYSpeed = 0; |
93 | + } |
94 | + |
95 | + gtk_widget_queue_draw (pDesklet->container.pWidget); |
96 | +} |
97 | + |
98 | +static gboolean on_update_desklet (gpointer pUserData, CairoDesklet *pDesklet, gboolean *bContinueAnimation) |
99 | +{ |
100 | + if (pDesklet->icons != NULL) |
101 | + { |
102 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
103 | + if (pViewportConf == NULL) |
104 | + return CAIRO_DOCK_LET_PASS_NOTIFICATION; |
105 | + |
106 | + if (! pDesklet->container.bInside) // on est en-dehors du desklet, on ralentit. |
107 | + { |
108 | + _viewport_pan_delta (pDesklet, pViewportConf->fCurrentPanXSpeed*.85, pViewportConf->fCurrentPanYSpeed*.85); |
109 | + if (fabs (pViewportConf->fCurrentPanXSpeed)+fabs (pViewportConf->fCurrentPanYSpeed) < pViewportConf->iIconSize/15) |
110 | + // vitesse de translation epsilonesque, on quitte. |
111 | + { |
112 | + pViewportConf->fCurrentPanXSpeed = 0; |
113 | + pViewportConf->fCurrentPanYSpeed = 0; |
114 | + return CAIRO_DOCK_LET_PASS_NOTIFICATION; |
115 | + } |
116 | + *bContinueAnimation = TRUE; |
117 | + } |
118 | + else |
119 | + { |
120 | + double fDeltaX = 0; |
121 | + double fDeltaY = 0; |
122 | + // si on est dans la marge de 20% de la largeur du desklet a gauche, |
123 | + // alors on translate a droite |
124 | + if (pDesklet->container.iMouseX <= pDesklet->container.iWidth*0.2) |
125 | + { |
126 | + // La force de translation va de 0 (lorsqu'on est a 20%) jusqu'a |
127 | + // pViewportConf->iIconSize / 2. (lorsqu'on est a 0%) |
128 | + fDeltaX = (pViewportConf->iIconSize / 10) * |
129 | + (pDesklet->container.iWidth*0.2 - pDesklet->container.iMouseX)/(pDesklet->container.iWidth*0.2); |
130 | + *bContinueAnimation = TRUE; |
131 | + } |
132 | + // si on est dans la marge de 20% de la largeur du desklet a droite, |
133 | + // alors on translate a gauche (-1) |
134 | + else if( pDesklet->container.iMouseX >= pDesklet->container.iWidth*0.8 ) |
135 | + { |
136 | + // La force de translation va de 0 (lorsqu'on est a 80%) jusqu'a |
137 | + // pViewportConf->iIconSize / 2. (lorsqu'on est a 100%) |
138 | + fDeltaX = -(pViewportConf->iIconSize / 10) * |
139 | + (pDesklet->container.iMouseX - pDesklet->container.iWidth*0.8)/(pDesklet->container.iWidth*0.2); |
140 | + *bContinueAnimation = TRUE; |
141 | + } |
142 | + // si on est dans la marge de 20% de la hauteur du desklet en haut, |
143 | + // alors on translate en bas |
144 | + if (pDesklet->container.iMouseY <= pDesklet->container.iHeight*0.2) |
145 | + { |
146 | + // La force de translation va de 0 (lorsqu'on est a 20%) jusqu'a |
147 | + // pViewportConf->iIconSize / 2. (lorsqu'on est a 0%) |
148 | + fDeltaY = -(pViewportConf->iIconSize / 10) * |
149 | + (pDesklet->container.iHeight*0.2 - pDesklet->container.iMouseY)/(pDesklet->container.iHeight*0.2); |
150 | + *bContinueAnimation = TRUE; |
151 | + } |
152 | + // si on est dans la marge de 20% de la hauteur du desklet en bas, |
153 | + // alors on translate en haut (-1) |
154 | + else if( pDesklet->container.iMouseY >= pDesklet->container.iHeight*0.8 ) |
155 | + { |
156 | + // La force de translation va de 0 (lorsqu'on est a 80%) jusqu'a |
157 | + // pViewportConf->iIconSize / 2. (lorsqu'on est a 100%) |
158 | + fDeltaY = (pViewportConf->iIconSize / 10) * |
159 | + (pDesklet->container.iMouseY - pDesklet->container.iHeight*0.8)/(pDesklet->container.iHeight*0.2); |
160 | + *bContinueAnimation = TRUE; |
161 | + } |
162 | + if( *bContinueAnimation == TRUE ) |
163 | + { |
164 | + _viewport_pan_delta( pDesklet, fDeltaX, fDeltaY ); |
165 | + } |
166 | + else |
167 | + { |
168 | + pViewportConf->fCurrentPanXSpeed = 0.; |
169 | + pViewportConf->fCurrentPanYSpeed = 0.; |
170 | + } |
171 | + } |
172 | + } |
173 | + return CAIRO_DOCK_LET_PASS_NOTIFICATION; |
174 | +} |
175 | + |
176 | +static gboolean on_mouse_move (gpointer pUserData, CairoDesklet *pDesklet, gboolean *bStartAnimation) |
177 | +{ |
178 | + if (pDesklet->icons != NULL) |
179 | + { |
180 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
181 | + if (pViewportConf == NULL) |
182 | + return CAIRO_DOCK_LET_PASS_NOTIFICATION; |
183 | + if (pViewportConf->bInfiniteWidth && (pDesklet->container.iMouseX <= pDesklet->container.iWidth*0.2 || pDesklet->container.iMouseX >= pDesklet->container.iWidth*0.8)) |
184 | + *bStartAnimation = TRUE; |
185 | + if (pViewportConf->bInfiniteHeight && (pDesklet->container.iMouseY <= pDesklet->container.iHeight*0.2 || pDesklet->container.iMouseY >= pDesklet->container.iHeight*0.8)) |
186 | + *bStartAnimation = TRUE; |
187 | + } |
188 | + return CAIRO_DOCK_LET_PASS_NOTIFICATION; |
189 | +} |
190 | + |
191 | +static CDViewportParameters *configure (CairoDesklet *pDesklet, gpointer *pConfig) // gboolean, int, gdouble[4] |
192 | +{ |
193 | + CDViewportParameters *pViewportConf = g_new0 (CDViewportParameters, 1); |
194 | + if (pConfig != NULL) |
195 | + { |
196 | + pViewportConf->bRoundedRadius = GPOINTER_TO_INT (pConfig[0]); |
197 | + pViewportConf->iRadius = GPOINTER_TO_INT (pConfig[1]); |
198 | + if (pConfig[2] != NULL) |
199 | + memcpy (pViewportConf->fLineColor, pConfig[2], 4 * sizeof (gdouble)); |
200 | + } |
201 | + |
202 | + pViewportConf->iLineWidth = 2; |
203 | + pViewportConf->iGapBetweenIcons = 10; |
204 | + pViewportConf->iMinimumIconSize = 48; |
205 | + pViewportConf->iCurrentOffsetX = 0; |
206 | + pViewportConf->iCurrentOffsetY = 0; |
207 | + pViewportConf->fCurrentPanXSpeed = 0; |
208 | + pViewportConf->fCurrentPanYSpeed = 0; |
209 | + pViewportConf->iMaxOffsetX = 0; |
210 | + pViewportConf->iMaxOffsetY = 0; |
211 | + pViewportConf->bInfiniteHeight=TRUE; |
212 | + pViewportConf->bInfiniteWidth=FALSE; |
213 | + |
214 | + cairo_dock_register_notification_on_container (CAIRO_CONTAINER (pDesklet), CAIRO_DOCK_ENTER_ICON, (CairoDockNotificationFunc) on_enter_icon_viewport, CAIRO_DOCK_RUN_FIRST, NULL); |
215 | + |
216 | + cairo_dock_register_notification_on_container (CAIRO_CONTAINER (pDesklet), CAIRO_DOCK_UPDATE_DESKLET, (CairoDockNotificationFunc) on_update_desklet, CAIRO_DOCK_RUN_AFTER, NULL); |
217 | + cairo_dock_register_notification_on_container (CAIRO_CONTAINER (pDesklet), CAIRO_DOCK_MOUSE_MOVED, (CairoDockNotificationFunc) on_mouse_move, CAIRO_DOCK_RUN_AFTER, NULL); |
218 | + |
219 | + return pViewportConf; |
220 | +} |
221 | + |
222 | + |
223 | +static inline void _compute_icons_grid (CairoDesklet *pDesklet, CDViewportParameters *pViewportConf) |
224 | +{ |
225 | + pViewportConf->fMargin = (pViewportConf->bRoundedRadius ? |
226 | + .5 * pViewportConf->iLineWidth + (1. - sqrt (2) / 2) * pViewportConf->iRadius : |
227 | + .5 * pViewportConf->iLineWidth + .5 * pViewportConf->iRadius); |
228 | + |
229 | + int iNbIcons = 0; |
230 | + Icon *pIcon; |
231 | + GList *ic; |
232 | + for (ic = pDesklet->icons; ic != NULL; ic = ic->next) |
233 | + { |
234 | + pIcon = ic->data; |
235 | + if (! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) |
236 | + iNbIcons ++; |
237 | + } |
238 | + pViewportConf->iNbIcons = iNbIcons; |
239 | + |
240 | + double w = pDesklet->container.iWidth - 2 * pViewportConf->fMargin; |
241 | + double h = pDesklet->container.iHeight - 2 * pViewportConf->fMargin; |
242 | + int dh = myLabels.iLabelSize; // taille verticale ajoutee a chaque icone. |
243 | + int dw = 2 * dh; // taille horizontale ajoutee a chaque icone. |
244 | + int di = pViewportConf->iGapBetweenIcons; // ecart entre 2 lignes/colonnes. |
245 | + |
246 | + int p, q; // nombre de lignes et colonnes. |
247 | + int iSize; |
248 | + pViewportConf->iIconSize = 0, pViewportConf->iNbLines = 0, pViewportConf->iNbColumns = 0; |
249 | + //g_print ("%d icones sur %dx%d (%d)\n", pViewportConf->iNbIcons, (int)w, (int)h, myLabels.iLabelSize); |
250 | + for (p = 1; p <= pViewportConf->iNbIcons; p ++) |
251 | + { |
252 | + q = (int) ceil ((double)pViewportConf->iNbIcons / p); |
253 | + iSize = MIN ((h - (p - 1) * di) / p - dh, (w - (q - 1) * di) / q - dw); |
254 | + //g_print (" %dx%d -> %d\n", p, q, iSize); |
255 | + if (iSize > pViewportConf->iIconSize) |
256 | + { |
257 | + pViewportConf->iIconSize = iSize; |
258 | + pViewportConf->iNbLines = p; |
259 | + pViewportConf->iNbColumns = q; |
260 | + } |
261 | + else if(iSize > 0) // there is only one maximum |
262 | + { |
263 | + break; |
264 | + } |
265 | + } |
266 | + // si les icones sont trop petites, et qu'on a une largeur et/ou une |
267 | + // hauteur infinie(s), essayer d'avoir au moins une taille minimale |
268 | + if( pViewportConf->iIconSize < pViewportConf->iMinimumIconSize && |
269 | + (pViewportConf->bInfiniteWidth || pViewportConf->bInfiniteHeight) ) |
270 | + { |
271 | + if( pViewportConf->bInfiniteWidth && pViewportConf->bInfiniteHeight ) |
272 | + { |
273 | + // surface infinie: on garde le meme nb de colonnes&lignes, |
274 | + // mais on met la taille d'icone a iMinimumIconSize |
275 | + pViewportConf->iIconSize = pViewportConf->iMinimumIconSize; |
276 | + } |
277 | + else if( pViewportConf->bInfiniteHeight ) |
278 | + { |
279 | + // hauteur infinie et largeur fixe: on calcule le nombre de colonnes |
280 | + // maxi avec pViewportConf->iIconSize = pViewportConf->iMinimumIconSize |
281 | + pViewportConf->iIconSize = pViewportConf->iMinimumIconSize; |
282 | + pViewportConf->iNbColumns = (w + di) / ( pViewportConf->iIconSize + dw + di ); |
283 | + if( pViewportConf->iNbColumns < 1 ) |
284 | + { |
285 | + pViewportConf->iNbColumns = 1; |
286 | + pViewportConf->iIconSize = w - dw; |
287 | + } |
288 | + pViewportConf->iNbLines = (int) ceil ((double)pViewportConf->iNbIcons / pViewportConf->iNbColumns); |
289 | + } |
290 | + else if( pViewportConf->bInfiniteWidth ) |
291 | + { |
292 | + // largeur infinie et hauteur fixe: on calcule le nombre de lignes |
293 | + // maxi avec pViewportConf->iIconSize = pViewportConf->iMinimumIconSize |
294 | + pViewportConf->iIconSize = pViewportConf->iMinimumIconSize; |
295 | + pViewportConf->iNbLines = (h + di) / ( pViewportConf->iIconSize + dh + di ); |
296 | + if( pViewportConf->iNbLines < 1 ) |
297 | + { |
298 | + pViewportConf->iNbLines = 1; |
299 | + pViewportConf->iIconSize = h - dh; |
300 | + } |
301 | + pViewportConf->iNbColumns = (int) ceil ((double)pViewportConf->iNbIcons / pViewportConf->iNbLines); |
302 | + } |
303 | + // on calcule l'offset maximal atteignable en X |
304 | + pViewportConf->iMaxOffsetX = MAX(( pViewportConf->iIconSize + dw + di )*pViewportConf->iNbColumns - (w + di), 0); |
305 | + // on calcule l'offset maximal atteignable en Y |
306 | + pViewportConf->iMaxOffsetY = MAX(( pViewportConf->iIconSize + dh + di )*pViewportConf->iNbLines - (h + di), 0); |
307 | + } |
308 | +} |
309 | + |
310 | +static void load_data (CairoDesklet *pDesklet) |
311 | +{ |
312 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
313 | + if (pViewportConf == NULL) |
314 | + return ; |
315 | + |
316 | + _compute_icons_grid (pDesklet, pViewportConf); |
317 | +} |
318 | + |
319 | + |
320 | +static void free_data (CairoDesklet *pDesklet) |
321 | +{ |
322 | + cairo_dock_remove_notification_func_on_container (CAIRO_CONTAINER (pDesklet), CAIRO_DOCK_ENTER_ICON, (CairoDockNotificationFunc) on_enter_icon_viewport, NULL); |
323 | + |
324 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
325 | + if (pViewportConf == NULL) |
326 | + return ; |
327 | + |
328 | + g_free (pViewportConf); |
329 | + pDesklet->pRendererData = NULL; |
330 | +} |
331 | + |
332 | + |
333 | +static void set_icon_size (CairoDesklet *pDesklet, Icon *pIcon) |
334 | +{ |
335 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
336 | + if (pViewportConf == NULL) |
337 | + return ; |
338 | + |
339 | + if (pIcon == pDesklet->pIcon) |
340 | + { |
341 | + pIcon->fWidth = 0.; |
342 | + pIcon->fHeight = 0.; |
343 | + } |
344 | + else |
345 | + { |
346 | + pIcon->fWidth = pViewportConf->iIconSize; |
347 | + pIcon->fHeight = pViewportConf->iIconSize; |
348 | + } |
349 | +} |
350 | + |
351 | +static void calculate_icons (CairoDesklet *pDesklet) |
352 | +{ |
353 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
354 | + if (pViewportConf == NULL) |
355 | + return ; |
356 | + |
357 | + _compute_icons_grid (pDesklet, pViewportConf); |
358 | + cd_debug ("pViewportConf->iIconSize : %d\n", pViewportConf->iIconSize); |
359 | + |
360 | + Icon *pIcon = pDesklet->pIcon; |
361 | + if (pIcon != NULL) // on ne veut pas charger cette icone. |
362 | + { |
363 | + pIcon->fWidth = -1; |
364 | + pIcon->fHeight = -1; |
365 | + } |
366 | + |
367 | + GList* ic; |
368 | + for (ic = pDesklet->icons; ic != NULL; ic = ic->next) |
369 | + { |
370 | + pIcon = ic->data; |
371 | + if (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) |
372 | + { |
373 | + pIcon->fWidth = -1; |
374 | + pIcon->fHeight = -1; |
375 | + } |
376 | + else |
377 | + { |
378 | + pIcon->fWidth = pViewportConf->iIconSize; |
379 | + pIcon->fHeight = pViewportConf->iIconSize; |
380 | + |
381 | + pIcon->fScale = 1.; |
382 | + pIcon->fAlpha = 1.; |
383 | + pIcon->fWidthFactor = 1.; |
384 | + pIcon->fHeightFactor = 1.; |
385 | + pIcon->fGlideScale = 1.; |
386 | + } |
387 | + } |
388 | +} |
389 | + |
390 | + |
391 | +static void render (cairo_t *pCairoContext, CairoDesklet *pDesklet) |
392 | +{ |
393 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
394 | + //g_print ("%s(%x)\n", __func__, pViewportConf); |
395 | + if (pViewportConf == NULL) |
396 | + return ; |
397 | + |
398 | + double fRadius = pViewportConf->iRadius; |
399 | + double fLineWidth = pViewportConf->iLineWidth; |
400 | + // le cadre. |
401 | + cairo_set_line_width (pCairoContext, pViewportConf->iLineWidth); |
402 | + if (pViewportConf->bRoundedRadius) |
403 | + { |
404 | + cairo_translate (pCairoContext, 0., .5 * fLineWidth); |
405 | + cairo_dock_draw_rounded_rectangle (pCairoContext, |
406 | + fRadius, |
407 | + fLineWidth, |
408 | + pDesklet->container.iWidth - 2 * fRadius - fLineWidth, |
409 | + pDesklet->container.iHeight - 2*fLineWidth); |
410 | + } |
411 | + else |
412 | + { |
413 | + cairo_move_to (pCairoContext, 0., 0.); |
414 | + cairo_rel_line_to (pCairoContext, |
415 | + 0., |
416 | + pDesklet->container.iHeight - fRadius - fLineWidth); |
417 | + cairo_rel_line_to (pCairoContext, |
418 | + pViewportConf->iRadius, |
419 | + pViewportConf->iRadius); |
420 | + cairo_rel_line_to (pCairoContext, |
421 | + pDesklet->container.iWidth - fRadius - fLineWidth, |
422 | + 0.); |
423 | + } |
424 | + cairo_set_source_rgba (pCairoContext, pViewportConf->fLineColor[0], pViewportConf->fLineColor[1], pViewportConf->fLineColor[2], pViewportConf->fLineColor[3]); |
425 | + cairo_stroke (pCairoContext); |
426 | + |
427 | + // les icones. |
428 | + double w = pDesklet->container.iWidth - 2 * pViewportConf->fMargin; |
429 | + double h = pDesklet->container.iHeight - 2 * pViewportConf->fMargin; |
430 | + int dh = myLabels.iLabelSize; // taille verticale ajoutee a chaque icone. |
431 | + int dw = 2 * dh; // taille horizontale ajoutee a chaque icone. |
432 | + if( pViewportConf->iMaxOffsetY == 0 ) |
433 | + { |
434 | + dh = (h - pViewportConf->iNbLines * (pViewportConf->iIconSize + myLabels.iLabelSize)) / pViewportConf->iNbLines; // ecart entre 2 lignes. |
435 | + } |
436 | + if( pViewportConf->iMaxOffsetX == 0 ) |
437 | + { |
438 | + dw = (w - pViewportConf->iNbColumns * pViewportConf->iIconSize) / pViewportConf->iNbColumns; // ecart entre 2 colonnes. |
439 | + } |
440 | + |
441 | + // on determine la 1ere icone a tracer : l'icone suivant l'icone pointee. |
442 | + |
443 | + double x = pViewportConf->fMargin + dw/2, y = pViewportConf->fMargin + dh/2; |
444 | + int q = 0; |
445 | + Icon *pIcon; |
446 | + GList *ic; |
447 | + GList *pVisibleIcons = NULL; |
448 | + for (ic = pDesklet->icons; ic != NULL; ic = ic->next) |
449 | + { |
450 | + pIcon = ic->data; |
451 | + if (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) |
452 | + continue; |
453 | + |
454 | + pIcon->fDrawX = x - pViewportConf->iCurrentOffsetX; |
455 | + pIcon->fDrawY = y - pViewportConf->iCurrentOffsetY; |
456 | + |
457 | + x += pViewportConf->iIconSize + dw; |
458 | + q ++; |
459 | + if (q == pViewportConf->iNbColumns) |
460 | + { |
461 | + q = 0; |
462 | + x = pViewportConf->fMargin + dw/2; |
463 | + y += pViewportConf->iIconSize + myLabels.iLabelSize + dh; |
464 | + } |
465 | + // On ne dessine que les icones qui sont visibles |
466 | + if( pIcon->fDrawX - pViewportConf->fMargin + dw/2 >= 0 && |
467 | + pIcon->fDrawY - pViewportConf->fMargin + myLabels.iLabelSize >= 0 && |
468 | + pIcon->fDrawX - pViewportConf->fMargin + dw/2 <= w - (pViewportConf->iIconSize + dw) && |
469 | + pIcon->fDrawY - pViewportConf->fMargin + myLabels.iLabelSize <= h - (pViewportConf->iIconSize + myLabels.iLabelSize + dh)) |
470 | + { |
471 | + pVisibleIcons = g_list_append(pVisibleIcons, pIcon); |
472 | + } |
473 | + } |
474 | + |
475 | + GList *pFirstDrawnElement = cairo_dock_get_first_drawn_element_linear (pVisibleIcons); |
476 | + if (pFirstDrawnElement == NULL) |
477 | + return; |
478 | + ic = pFirstDrawnElement; |
479 | + do |
480 | + { |
481 | + pIcon = ic->data; |
482 | + if (pIcon->pIconBuffer != NULL && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) |
483 | + { |
484 | + cairo_save (pCairoContext); |
485 | + |
486 | + cairo_dock_render_one_icon_in_desklet (pIcon, pCairoContext, FALSE, FALSE, pDesklet->container.iWidth); |
487 | + |
488 | + cairo_restore (pCairoContext); |
489 | + |
490 | + |
491 | + if (pIcon->pTextBuffer != NULL) |
492 | + { |
493 | + cairo_save (pCairoContext); |
494 | + cairo_translate (pCairoContext, pIcon->fDrawX, pIcon->fDrawY); |
495 | + |
496 | + double fOffsetX = 0., fAlpha; |
497 | + if (pIcon->bPointed) |
498 | + { |
499 | + fAlpha = 1.; |
500 | + if (pIcon->fDrawX + pIcon->fWidth/2 + pIcon->iTextWidth/2 > pDesklet->container.iWidth) |
501 | + fOffsetX = pDesklet->container.iWidth - (pIcon->fDrawX + pIcon->fWidth/2 + pIcon->iTextWidth/2); |
502 | + if (pIcon->fDrawX + pIcon->fWidth/2 - pIcon->iTextWidth/2 < 0) |
503 | + fOffsetX = pIcon->iTextWidth/2 - (pIcon->fDrawX + pIcon->fWidth/2); |
504 | + cairo_set_source_surface (pCairoContext, |
505 | + pIcon->pTextBuffer, |
506 | + fOffsetX + pIcon->fWidth/2 - pIcon->iTextWidth/2, |
507 | + -myLabels.iLabelSize); |
508 | + cairo_paint_with_alpha (pCairoContext, fAlpha); |
509 | + } |
510 | + else |
511 | + { |
512 | + fAlpha = .6; |
513 | + if (pIcon->iTextWidth > pIcon->fWidth + 2 * myLabels.iLabelSize) |
514 | + { |
515 | + fOffsetX = - myLabels.iLabelSize; |
516 | + cairo_pattern_t *pGradationPattern = cairo_pattern_create_linear (fOffsetX, |
517 | + 0., |
518 | + fOffsetX + pIcon->fWidth + 2*myLabels.iLabelSize, |
519 | + 0.); |
520 | + cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE); |
521 | + cairo_pattern_add_color_stop_rgba (pGradationPattern, |
522 | + 0., |
523 | + 0., |
524 | + 0., |
525 | + 0., |
526 | + fAlpha); |
527 | + cairo_pattern_add_color_stop_rgba (pGradationPattern, |
528 | + 0.75, |
529 | + 0., |
530 | + 0., |
531 | + 0., |
532 | + fAlpha); |
533 | + cairo_pattern_add_color_stop_rgba (pGradationPattern, |
534 | + 1., |
535 | + 0., |
536 | + 0., |
537 | + 0., |
538 | + 0.); |
539 | + cairo_set_source_surface (pCairoContext, |
540 | + pIcon->pTextBuffer, |
541 | + fOffsetX, |
542 | + -myLabels.iLabelSize); |
543 | + cairo_mask (pCairoContext, pGradationPattern); |
544 | + cairo_pattern_destroy (pGradationPattern); |
545 | + } |
546 | + else |
547 | + { |
548 | + fOffsetX = pIcon->fWidth/2 - pIcon->iTextWidth/2; |
549 | + cairo_set_source_surface (pCairoContext, |
550 | + pIcon->pTextBuffer, |
551 | + fOffsetX, |
552 | + -myLabels.iLabelSize); |
553 | + cairo_paint_with_alpha (pCairoContext, fAlpha); |
554 | + } |
555 | + } |
556 | + |
557 | + cairo_restore (pCairoContext); |
558 | + } |
559 | + } |
560 | + ic = cairo_dock_get_next_element (ic, pVisibleIcons); |
561 | + } |
562 | + while (ic != pFirstDrawnElement); |
563 | +} |
564 | + |
565 | + |
566 | +static void render_opengl (CairoDesklet *pDesklet) |
567 | +{ |
568 | + CDViewportParameters *pViewportConf = (CDViewportParameters *) pDesklet->pRendererData; |
569 | + if (pViewportConf == NULL) |
570 | + return ; |
571 | + |
572 | + // le cadre. |
573 | + double fRadius = (pViewportConf->bRoundedRadius ? pViewportConf->iRadius : 0.); |
574 | + double fLineWidth = pViewportConf->iLineWidth; |
575 | + if (fLineWidth != 0 && pViewportConf->fLineColor[3] != 0) |
576 | + { |
577 | + cairo_dock_draw_rounded_rectangle_opengl (pDesklet->container.iWidth - 2 * fRadius, |
578 | + pDesklet->container.iHeight, |
579 | + fRadius, |
580 | + fLineWidth, |
581 | + pViewportConf->fLineColor); |
582 | + glTranslatef (-pDesklet->container.iWidth/2, -pDesklet->container.iHeight/2, 0.); |
583 | + } |
584 | + |
585 | + glTranslatef (-pDesklet->container.iWidth/2, -pDesklet->container.iHeight/2, 0.); |
586 | + |
587 | + // les icones. |
588 | + double w = pDesklet->container.iWidth - 2 * pViewportConf->fMargin; |
589 | + double h = pDesklet->container.iHeight - 2 * pViewportConf->fMargin; |
590 | + int dh = myLabels.iLabelSize; // taille verticale ajoutee a chaque icone. |
591 | + int dw = 2 * dh; // taille horizontale ajoutee a chaque icone. |
592 | + if( pViewportConf->iMaxOffsetY == 0 ) |
593 | + { |
594 | + // ecart entre 2 lignes si il faut repartir vertivalement les icones. |
595 | + dh = (h - pViewportConf->iNbLines * (pViewportConf->iIconSize + myLabels.iLabelSize) - 2*pViewportConf->fMargin - myLabels.iLabelSize) / pViewportConf->iNbLines; |
596 | + } |
597 | + if( pViewportConf->iMaxOffsetX == 0 ) |
598 | + { |
599 | + // ecart entre 2 colonnes si il faut repartir horizontalement les icones. |
600 | + dw = (w - pViewportConf->iNbColumns * pViewportConf->iIconSize - 2*pViewportConf->fMargin) / pViewportConf->iNbColumns; |
601 | + } |
602 | + |
603 | + _cairo_dock_enable_texture (); |
604 | + _cairo_dock_set_blend_alpha (); |
605 | + _cairo_dock_set_alpha (1.); |
606 | + |
607 | + |
608 | + double x = pViewportConf->fMargin + dw/2, y = pViewportConf->fMargin + myLabels.iLabelSize + dh/2; |
609 | + int q = 0; |
610 | + Icon *pIcon; |
611 | + GList *ic; |
612 | + GList *pVisibleIcons = NULL; |
613 | + for (ic = pDesklet->icons; ic != NULL; ic = ic->next) |
614 | + { |
615 | + pIcon = ic->data; |
616 | + if (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) |
617 | + continue; |
618 | + |
619 | + pIcon->fDrawX = x - pViewportConf->iCurrentOffsetX; |
620 | + pIcon->fDrawY = y - pViewportConf->iCurrentOffsetY; |
621 | + |
622 | + x += pViewportConf->iIconSize + dw; |
623 | + q ++; |
624 | + if (q == pViewportConf->iNbColumns) |
625 | + { |
626 | + q = 0; |
627 | + x = pViewportConf->fMargin + dw/2; |
628 | + y += pViewportConf->iIconSize + myLabels.iLabelSize + dh; |
629 | + } |
630 | + // On ne dessine que les icones qui sont visibles |
631 | + if( pIcon->fDrawX - pViewportConf->fMargin - dw/2 >= 0 && |
632 | + pIcon->fDrawY - pViewportConf->fMargin - myLabels.iLabelSize - dh/2 >= 0 && |
633 | + pIcon->fDrawX - pViewportConf->fMargin - dw/2 <= w - (pViewportConf->iIconSize + dw/2) && |
634 | + pIcon->fDrawY - pViewportConf->fMargin - myLabels.iLabelSize - dh/2 <= h - (pViewportConf->iIconSize + myLabels.iLabelSize + dh/2)) |
635 | + { |
636 | + pVisibleIcons = g_list_append(pVisibleIcons, pIcon); |
637 | + } |
638 | + } |
639 | + |
640 | + |
641 | + GList *pFirstDrawnElement = cairo_dock_get_first_drawn_element_linear (pVisibleIcons); |
642 | + if (pFirstDrawnElement == NULL) |
643 | + return; |
644 | + ic = pFirstDrawnElement; |
645 | + do |
646 | + { |
647 | + pIcon = ic->data; |
648 | + |
649 | + if (pIcon->iIconTexture != 0 && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (pIcon)) |
650 | + { |
651 | + glPushMatrix (); |
652 | + |
653 | + glTranslatef (pIcon->fDrawX + pIcon->fWidth/2, |
654 | + pDesklet->container.iHeight - pIcon->fDrawY - pIcon->fHeight/2, |
655 | + 0.); |
656 | + //g_print (" %d) %d;%d %dx%d\n", pIcon->iIconTexture, (int)(pIcon->fDrawX + pIcon->fWidth/2), (int)(pDesklet->container.iHeight - pIcon->fDrawY - pIcon->fHeight/2), (int)(pIcon->fWidth/2), (int)(pIcon->fHeight/2)); |
657 | + _cairo_dock_apply_texture_at_size (pIcon->iIconTexture, pIcon->fWidth, pIcon->fHeight); |
658 | + |
659 | + /// generer une notification ... |
660 | + /*if (pIcon->bHasIndicator && g_pIndicatorBuffer.iTexture != 0) |
661 | + { |
662 | + glPushMatrix (); |
663 | + glTranslatef (0., - pIcon->fHeight/2 + g_pIndicatorBuffer.iHeight/2 * pIcon->fWidth / g_pIndicatorBuffer.iWidth, 0.); |
664 | + _cairo_dock_apply_texture_at_size (g_pIndicatorBuffer.iTexture, pIcon->fWidth, g_pIndicatorBuffer.iHeight * pIcon->fWidth / g_pIndicatorBuffer.iWidth); |
665 | + glPopMatrix (); |
666 | + }*/ |
667 | + |
668 | + if (pIcon->iLabelTexture != 0) |
669 | + { |
670 | + glPushMatrix (); |
671 | + |
672 | + double dx = .5 * (pIcon->iTextWidth & 1); // on decale la texture pour la coller sur la grille des coordonnees entieres. |
673 | + double dy = .5 * (pIcon->iTextHeight & 1); |
674 | + double u0 = 0., u1 = 1.; |
675 | + double fOffsetX = 0.; |
676 | + if (pIcon->bPointed) |
677 | + { |
678 | + _cairo_dock_set_alpha (1.); |
679 | + if (pIcon->fDrawX + pIcon->fWidth/2 + pIcon->iTextWidth/2 > pDesklet->container.iWidth) |
680 | + fOffsetX = pDesklet->container.iWidth - (pIcon->fDrawX + pIcon->fWidth/2 + pIcon->iTextWidth/2); |
681 | + if (pIcon->fDrawX + pIcon->fWidth/2 - pIcon->iTextWidth/2 < 0) |
682 | + fOffsetX = pIcon->iTextWidth/2 - (pIcon->fDrawX + pIcon->fWidth/2); |
683 | + } |
684 | + else |
685 | + { |
686 | + _cairo_dock_set_alpha (.6); |
687 | + if (pIcon->iTextWidth > pIcon->fWidth + 2 * myLabels.iLabelSize) |
688 | + { |
689 | + fOffsetX = 0.; |
690 | + u1 = (double) (pIcon->fWidth + 2 * myLabels.iLabelSize) / pIcon->iTextWidth; |
691 | + } |
692 | + } |
693 | + |
694 | + glTranslatef (ceil (fOffsetX) + dx, ceil (pIcon->fHeight/2 + pIcon->iTextHeight / 2) + dy, 0.); |
695 | + |
696 | + glBindTexture (GL_TEXTURE_2D, pIcon->iLabelTexture); |
697 | + _cairo_dock_apply_current_texture_portion_at_size_with_offset (u0, 0., |
698 | + u1 - u0, 1., |
699 | + pIcon->iTextWidth * (u1 - u0), pIcon->iTextHeight, |
700 | + 0., 0.); |
701 | + _cairo_dock_set_alpha (1.); |
702 | + |
703 | + glPopMatrix (); |
704 | + } |
705 | + |
706 | + if (pIcon->iQuickInfoTexture != 0) |
707 | + { |
708 | + glTranslatef (0., (- pIcon->fHeight + pIcon->iQuickInfoHeight)/2, 0.); |
709 | + |
710 | + _cairo_dock_apply_texture_at_size (pIcon->iQuickInfoTexture, |
711 | + pIcon->iQuickInfoWidth, |
712 | + pIcon->iQuickInfoHeight); |
713 | + } |
714 | + |
715 | + glPopMatrix (); |
716 | + } |
717 | + |
718 | + ic = cairo_dock_get_next_element (ic, pVisibleIcons); |
719 | + |
720 | + } while (ic != pFirstDrawnElement); |
721 | + |
722 | + _cairo_dock_disable_texture (); |
723 | +} |
724 | + |
725 | + |
726 | + |
727 | +void rendering_register_viewport_desklet_renderer (void) |
728 | +{ |
729 | + CairoDeskletRenderer *pRenderer = g_new0 (CairoDeskletRenderer, 1); |
730 | + pRenderer->render = (CairoDeskletRenderFunc) render; |
731 | + pRenderer->configure = (CairoDeskletConfigureRendererFunc) configure; |
732 | + pRenderer->load_data = (CairoDeskletLoadRendererDataFunc) load_data; |
733 | + pRenderer->free_data = (CairoDeskletFreeRendererDataFunc) free_data; |
734 | + pRenderer->calculate_icons = (CairoDeskletCalculateIconsFunc) calculate_icons; |
735 | + pRenderer->render_opengl = (CairoDeskletGLRenderFunc) render_opengl; |
736 | + |
737 | + cairo_dock_register_desklet_renderer ("Viewport", pRenderer); |
738 | +} |
739 | |
740 | === added file 'desklet-rendering/src/rendering-desklet-viewport.h' |
741 | --- desklet-rendering/src/rendering-desklet-viewport.h 1970-01-01 00:00:00 +0000 |
742 | +++ desklet-rendering/src/rendering-desklet-viewport.h 2010-07-17 12:02:42 +0000 |
743 | @@ -0,0 +1,56 @@ |
744 | +/** |
745 | +* This file is a part of the Cairo-Dock project |
746 | +* |
747 | +* Copyright : (C) see the 'copyright' file. |
748 | +* E-mail : see the 'copyright' file. |
749 | +* |
750 | +* This program is free software; you can redistribute it and/or |
751 | +* modify it under the terms of the GNU General Public License |
752 | +* as published by the Free Software Foundation; either version 3 |
753 | +* of the License, or (at your option) any later version. |
754 | +* |
755 | +* This program is distributed in the hope that it will be useful, |
756 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
757 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
758 | +* GNU General Public License for more details. |
759 | +* You should have received a copy of the GNU General Public License |
760 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. |
761 | +*/ |
762 | + |
763 | + |
764 | +#ifndef __RENDERING_DESKLET_VIEWPORT__ |
765 | +#define __RENDERING_DESKLET_VIEWPORT__ |
766 | + |
767 | +#include "cairo-dock.h" |
768 | + |
769 | + |
770 | +typedef struct { |
771 | + // from config |
772 | + gboolean bRoundedRadius; |
773 | + gint iRadius; |
774 | + gdouble fLineColor[4]; |
775 | + gint iLineWidth; |
776 | + gint iGapBetweenIcons; |
777 | + gint iMinimumIconSize; |
778 | + gboolean bInfiniteWidth; |
779 | + gboolean bInfiniteHeight; |
780 | + // computed data |
781 | + gdouble fMargin; |
782 | + gint iNbIcons; |
783 | + GList* iFirstIconToShow; |
784 | + gint iIconSize; |
785 | + gint iNbLines, iNbColumns; |
786 | + gint iMaxOffsetX; |
787 | + gint iMaxOffsetY; |
788 | + // current state |
789 | + gint iCurrentOffsetX; |
790 | + gint iCurrentOffsetY; |
791 | + gint fCurrentPanXSpeed; |
792 | + gint fCurrentPanYSpeed; |
793 | + } CDViewportParameters; |
794 | + |
795 | + |
796 | +void rendering_register_viewport_desklet_renderer (void); |
797 | + |
798 | + |
799 | +#endif |
800 | |
801 | === modified file 'desklet-rendering/src/rendering-init.c' |
802 | --- desklet-rendering/src/rendering-init.c 2010-07-06 00:03:56 +0000 |
803 | +++ desklet-rendering/src/rendering-init.c 2010-07-17 12:02:42 +0000 |
804 | @@ -26,12 +26,13 @@ |
805 | //#include "rendering-desklet-controler.h" |
806 | //#include "rendering-desklet-mediaplayer.h" |
807 | #include "rendering-desklet-slide.h" |
808 | +#include "rendering-desklet-viewport.h" |
809 | #include "rendering-desklet-decorations.h" |
810 | #include "rendering-init.h" |
811 | |
812 | |
813 | CD_APPLET_DEFINE_BEGIN (N_("desklet rendering"), |
814 | - 2,0,0, |
815 | + 2,1,0, |
816 | CAIRO_DOCK_CATEGORY_THEME, |
817 | N_("This module provides different views for your desklets."), |
818 | "Fabounet (Fabrice Rey)") |
819 | @@ -47,6 +48,7 @@ |
820 | //rendering_register_controler_desklet_renderer (); |
821 | //rendering_register_mediaplayer_desklet_renderer (); // By ChAnGFu |
822 | rendering_register_slide_desklet_renderer (); // By ChAnGFu |
823 | + rendering_register_viewport_desklet_renderer (); // By Tofe |
824 | |
825 | //\_______________ On enregistre les decorations. |
826 | cd_rendering_register_desklet_decorations (); |