2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
******************************************************************************/
33
#include "applet-struct.h"
34
#include "applet-draw.h"
37
void cd_xkbd_update_icon (const gchar *cGroupName, const gchar *cShortGroupName, const gchar *cIndicatorName, gboolean bRedrawSurface)
39
//g_print ("%s (%s;%s;%d)\n", __func__, cGroupName, cShortGroupName, bRedrawSurface);
43
//\__________________ On sauvegarde l'ancienne surface/texture.
44
if (myData.pOldSurface != NULL)
45
cairo_surface_destroy (myData.pOldSurface);
46
if (myData.iOldTexture != 0)
47
_cairo_dock_delete_texture (myData.iOldTexture);
48
myData.pOldSurface = myData.pCurrentSurface;
49
myData.iOldTexture = myData.iCurrentTexture;
50
myData.iOldTextWidth = myData.iCurrentTextWidth;
51
myData.iOldTextHeight = myData.iCurrentTextHeight;
53
//\__________________ On cree la nouvelle surface (la taille du texte peut avoir change).
55
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
56
double fMaxScale = cairo_dock_get_max_scale (myContainer);
57
double fTextXOffset, fTextYOffset;
58
myData.pCurrentSurface = cairo_dock_create_surface_from_text_full (cShortGroupName,
60
&myConfig.textDescription,
63
&myData.iCurrentTextWidth, &myData.iCurrentTextHeight, &fTextXOffset, &fTextYOffset);
64
myData.iCurrentTextWidth *= fMaxScale;
65
myData.iCurrentTextHeight *= fMaxScale;
68
myData.iCurrentTexture = cairo_dock_create_texture_from_surface (myData.pCurrentSurface);
71
//\__________________ On lance une transition entre ancienne et nouvelle surface/texture, ou on dessine direct.
72
if (myConfig.iTransitionDuration != 0 && myData.pOldSurface != NULL)
74
CD_APPLET_SET_TRANSITION_ON_MY_ICON (cd_xkbd_render_step_cairo,
75
cd_xkbd_render_step_opengl,
76
g_bUseOpenGL, // bFastPace : vite si opengl, lent si cairo.
77
myConfig.iTransitionDuration,
78
TRUE); // bRemoveWhenFinished
82
if (CD_APPLET_MY_CONTAINER_IS_OPENGL)
84
CD_APPLET_START_DRAWING_MY_ICON_OR_RETURN ();
85
cd_xkbd_render_step_opengl (myApplet);
86
CD_APPLET_FINISH_DRAWING_MY_ICON;
90
cairo_dock_erase_cairo_context (myDrawContext);
91
cd_xkbd_render_step_cairo (myApplet);
92
CD_APPLET_UPDATE_REFLECT_ON_MY_ICON;
94
CD_APPLET_REDRAW_MY_ICON;
97
//\__________________ On met a jour le reste.
98
CD_APPLET_SET_NAME_FOR_MY_ICON (cGroupName);
99
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (cIndicatorName);
103
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (cIndicatorName);
104
CD_APPLET_REDRAW_MY_ICON;
109
gboolean cd_xkbd_render_step_opengl (CairoDockModuleInstance *myApplet)
111
double f = CD_APPLET_GET_TRANSITION_FRACTION ();
112
//g_print ("%s (%.2f)\n", __func__, f);
115
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
117
cairo_dock_set_perspective_view (iWidth, iHeight);
118
glScalef (1., -1., 1.);
120
double fTheta = - 45. + f * 90.; // -45 -> 45
121
glTranslatef (0., 0., - iWidth * sqrt(2)/2 * cos (fTheta/180.*G_PI)); // pour faire tenir le cube dans la fenetre.
122
glEnable (GL_DEPTH_TEST);
123
_cairo_dock_enable_texture ();
124
_cairo_dock_set_blend_alpha ();
125
_cairo_dock_set_alpha (1.);
128
if (myData.iBackgroundTexture != 0)
129
cairo_dock_apply_texture_at_size (myData.iBackgroundTexture, iWidth, iHeight);
132
if (fTheta < 25 && myData.iOldTexture != 0) // inutile de dessiner si elle est derriere l'image courante, par l'effet de perspective (en fait 22.5, mais bizarrement ca a l'air un peu trop tot).
135
glRotatef (45. + fTheta, 0., 1., 0.); // 0 -> 90
136
glTranslatef (0., 0., (myData.iCurrentTextWidth ? myData.iCurrentTextWidth : iWidth)/2);
137
cairo_dock_apply_texture_at_size (myData.iOldTexture, myData.iOldTextWidth, MIN (iHeight, myData.iOldTextHeight));
141
// image courante a 90deg.
142
glRotatef (45. + fTheta, 0., 1., 0.); // 0 -> 90
143
glTranslatef (- (myData.iOldTextWidth ? myData.iOldTextWidth : iWidth)/2, 0., 0.);
145
glRotatef (-90., 0., 1., 0.);
146
cairo_dock_apply_texture_at_size (myData.iCurrentTexture, myData.iCurrentTextWidth, MIN (iHeight, myData.iCurrentTextHeight));
148
glDisable (GL_DEPTH_TEST);
149
_cairo_dock_disable_texture ();
153
cairo_dock_set_ortho_view (iWidth, iHeight);
160
gboolean cd_xkbd_render_step_cairo (CairoDockModuleInstance *myApplet)
162
double f = CD_APPLET_GET_TRANSITION_FRACTION ();
164
//g_print ("%s (%.2f)\n", __func__, f);
166
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
168
if (myData.pBackgroundSurface != NULL)
170
cairo_set_source_surface (
172
myData.pBackgroundSurface,
175
cairo_paint (myDrawContext);
176
cairo_dock_set_icon_surface_full (myDrawContext, myData.pBackgroundSurface, 1., 1., myIcon, myContainer);
179
double dx, dy, fScale=0;
180
if (myData.pOldSurface != NULL && 1-f > .01)
182
dx = (iWidth - myData.iOldTextWidth)/2;
183
dy = (iHeight - myData.iOldTextHeight)/2;
184
if (dy < 0) // peut arriver si une police de la taille de l'icone n'existe pas.
187
fScale = 1.*iHeight / myData.iOldTextHeight;
188
cairo_save (myDrawContext);
189
cairo_scale (myDrawContext, 1., fScale); // a priori la difference n'est pas enorme, on laisse donc remplit en largeur.
191
cairo_set_source_surface (
196
cairo_paint_with_alpha (myDrawContext, 1-f);
198
cairo_restore (myDrawContext);
200
if (myData.pCurrentSurface != NULL)
202
dx = (iWidth - myData.iCurrentTextWidth)/2;
203
dy = (iHeight - myData.iCurrentTextHeight)/2;
207
fScale = 1.*iHeight / myData.iCurrentTextHeight;
208
cairo_save (myDrawContext);
209
cairo_scale (myDrawContext, 1., fScale);
211
cairo_set_source_surface (
213
myData.pCurrentSurface,
216
cairo_paint_with_alpha (myDrawContext, f);
218
cairo_restore (myDrawContext);