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
#ifndef __CAIRO_DOCK_ANIMATIONS__
21
#define __CAIRO_DOCK_ANIMATIONS__
25
#include "cairo-dock-struct.h"
26
#include "cairo-dock-icons.h"
30
*@file cairo-dock-animations.h This class handles the icons and containers animations.
31
* Each container has a rendering loop. An iteration of this loop is separated in 2 phases : the update of each element of the container and of the container itself, and the redraw of each element and of the container itself.
32
* The loop has 2 possible frequencies : fast (~33Hz) and slow (~10Hz), to optimize the CPU load according to the needs of the animation.
33
* To be called on each iteration of the loop, you register to the CAIRO_DOCK_UPDATE_X or CAIRO_DOCK_UPDATE_X_SLOW, where X is either ICON, DOCK, DESKLET, DIALOG or FLYING_CONTAINER.
34
* If you need to draw things directly on the container, you register to CAIRO_DOCK_RENDER_X, where X is either ICON, DOCK, DESKLET, DIALOG or FLYING_CONTAINER.
37
/// callback to render the icon with libcairo at each step of the Transition.
38
typedef gboolean (*CairoDockTransitionRenderFunc) (Icon *pIcon, gpointer pUserData, cairo_t *pIconContext);
39
/// callback to render the icon with OpenGL at each step of the Transition.
40
typedef gboolean (*CairoDockTransitionGLRenderFunc) (Icon *pIcon, gpointer pUserData);
42
/// Transitions are an easy way to set an animation on an Icon to make it change from a state to another.
43
struct _CairoDockTransition {
44
/// the cairo rendering function.
45
CairoDockTransitionRenderFunc render;
46
/// the openGL rendering function (can be NULL, in which case the texture mapping from the cairo drawing is done automatically).
47
CairoDockTransitionGLRenderFunc render_opengl;
48
/// data passed to the rendering functions.
50
/// function called to destroy the data when the transition is deleted.
51
GFreeFunc pFreeUserDataFunc;
52
/// TRUE <=> the transition will be in the fast loop (high frequency refresh).
54
/// TRUE <=> the transition will be destroyed and removed from the icon when finished.
55
gboolean bRemoveWhenFinished;
56
/// duration if the transition, in ms. Can be 0 for an endless transition.
57
gint iDuration; // en ms.
58
/// elapsed time since the beginning of the transition, in ms.
60
/// number of setps since the beginning of the transition, in ms.
62
/// cairo context on the Icon.
63
cairo_t *pIconContext; // attention a bien detruire la transition
64
/// Container of the Icon.
65
CairoContainer *pContainer; // si l'un de ces 2 parametres change !
68
/// Definition of a Hiding Effect backend (used to provide an animation when the docks hides/shows itself).
69
struct _CairoDockHidingEffect {
70
/// translated name of the effect
71
const gchar *cDisplayedName;
72
/// whether the backend can display the dock even when it's hidden
73
gboolean bCanDisplayHiddenDock;
74
/// function called before the icons are drawn (cairo)
75
void (*pre_render) (CairoDock *pDock, double fOffset, cairo_t *pCairoContext);
76
/// function called before the icons are drawn (opengl)
77
void (*pre_render_opengl) (CairoDock *pDock, double fOffset);
78
/// function called afer the icons are drawn (cairo)
79
void (*post_render) (CairoDock *pDock, double fOffset, cairo_t *pCairoContext);
80
/// function called afer the icons are drawn (opengl)
81
void (*post_render_opengl) (CairoDock *pDock, double fOffset);
82
/// function called when the animation is started.
83
void (*init) (CairoDock *pDock);
86
#define CAIRO_DOCK_MIN_SLOW_DELTA_T 90
88
/** Say if a container is currently animated.
89
*@param pContainer a Container
91
#define cairo_dock_container_is_animating(pContainer) (CAIRO_CONTAINER(pContainer)->iSidGLAnimation != 0)
93
/** Say if it's usefull to launch an animation on a Dock (indeed, it's useless to launch it if it will be invisible).
94
*@param pDock the Dock to animate.
96
#define cairo_dock_animation_will_be_visible(pDock) ((pDock)->iRefCount != 0 && GTK_WIDGET_VISIBLE ((CAIRO_CONTAINER(pDock)->pWidget)) || ((pDock)->iRefCount == 0 && (! (pDock)->bAutoHide || CAIRO_CONTAINER(pDock)->bInside || (pDock)->fHideOffset < 1)))
99
/** Pop up a Dock above other windows, if it is in mode "keep below other windows"; otherwise do nothing.
100
*@param pDock the dock.
102
void cairo_dock_pop_up (CairoDock *pDock);
104
/** Pop down a Dock below other windows, if it is in mode "keep below other windows"; otherwise do nothing.
105
*@param pDock the dock.
107
void cairo_dock_pop_down (CairoDock *pDock);
110
gfloat cairo_dock_calculate_magnitude (gint iMagnitudeIndex);
112
/** Launch the animation of a Container.
113
*@param pContainer the container to animate.
115
void cairo_dock_launch_animation (CairoContainer *pContainer);
117
void cairo_dock_start_shrinking (CairoDock *pDock);
119
void cairo_dock_start_growing (CairoDock *pDock);
121
void cairo_dock_start_hiding (CairoDock *pDock);
123
void cairo_dock_start_showing (CairoDock *pDock);
125
/** Launch the animation of an Icon. Do nothing if the icon will not be animated or if the icon is at rest.
126
*@param icon the icon to animate.
127
*@param pDock the dock containing the icon.
129
void cairo_dock_start_icon_animation (Icon *icon, CairoDock *pDock);
131
/** Launch a given animation on an Icon. Do nothing if the icon will not be animated or if the animation doesn't exist.
132
*@param pIcon the icon to animate.
133
*@param pDock the dock containing the icon.
134
*@param cAnimation name of the animation.
135
*@param iNbRounds number of rounds the animation will be played.
137
void cairo_dock_request_icon_animation (Icon *pIcon, CairoDock *pDock, const gchar *cAnimation, int iNbRounds);
139
/** Stop any animation on an Icon, except the disappearance/appearance animation.
140
*@param pIcon the icon.
142
#define cairo_dock_stop_icon_animation(pIcon) do { \
143
if (pIcon->iAnimationState != CAIRO_DOCK_STATE_REMOVE_INSERT && pIcon->iAnimationState != CAIRO_DOCK_STATE_REST) {\
144
cairo_dock_notify (CAIRO_DOCK_STOP_ICON, pIcon); \
145
pIcon->iAnimationState = CAIRO_DOCK_STATE_REST; } } while (0)
147
void cairo_dock_request_icon_attention (Icon *pIcon, CairoDock *pDock, const gchar *cAnimation, int iNbRounds);
149
void cairo_dock_stop_icon_attention (Icon *pIcon, CairoDock *pDock);
151
/** Trigger the removal of an Icon from its Dock. The icon will effectively be removed at the end of the animation.
152
*If the icon is not inside a dock, nothing happens.
153
*@param pIcon the icon to remove
155
void cairo_dock_trigger_icon_removal_from_dock (Icon *pIcon);
157
/** Get the interval of time between 2 iterations of the fast loop (in ms).
158
*@param pContainer the container.
160
#define cairo_dock_get_animation_delta_t(pContainer) CAIRO_CONTAINER(pContainer)->iAnimationDeltaT
161
/** Get the interval of time between 2 iterations of the slow loop (in ms).
162
*@param pContainer the container.
164
#define cairo_dock_get_slow_animation_delta_t(pContainer) ((int) ceil (1.*CAIRO_DOCK_MIN_SLOW_DELTA_T / CAIRO_CONTAINER(pContainer)->iAnimationDeltaT) * CAIRO_CONTAINER(pContainer)->iAnimationDeltaT)
166
#define cairo_dock_set_default_animation_delta_t(pContainer) CAIRO_CONTAINER(pContainer)->iAnimationDeltaT = (g_bUseOpenGL ? mySystem.iGLAnimationDeltaT : mySystem.iCairoAnimationDeltaT)
168
void cairo_dock_mark_icon_animation_as (Icon *pIcon, CairoDockAnimationState iAnimationState);
169
void cairo_dock_stop_marking_icon_animation_as (Icon *pIcon, CairoDockAnimationState iAnimationState);
171
#define cairo_dock_mark_icon_as_hovered_by_mouse(pIcon) cairo_dock_mark_icon_animation_as (pIcon, CAIRO_DOCK_STATE_MOUSE_HOVERED)
172
#define cairo_dock_stop_marking_icon_as_hovered_by_mouse(pIcon) cairo_dock_stop_marking_icon_animation_as (pIcon, CAIRO_DOCK_STATE_MOUSE_HOVERED)
174
#define cairo_dock_mark_icon_as_clicked(pIcon) cairo_dock_mark_icon_animation_as (pIcon, CAIRO_DOCK_STATE_CLICKED)
175
#define cairo_dock_stop_marking_icon_as_clicked(pIcon) cairo_dock_stop_marking_icon_animation_as (pIcon, CAIRO_DOCK_STATE_CLICKED)
177
#define cairo_dock_mark_icon_as_avoiding_mouse(pIcon) cairo_dock_mark_icon_animation_as (pIcon, CAIRO_DOCK_STATE_AVOID_MOUSE)
178
#define cairo_dock_stop_marking_icon_as_avoiding_mouse(pIcon) cairo_dock_stop_marking_icon_animation_as (pIcon, CAIRO_DOCK_STATE_AVOID_MOUSE)
180
#define cairo_dock_mark_icon_as_following_mouse(pIcon) cairo_dock_mark_icon_animation_as (pIcon, CAIRO_DOCK_STATE_FOLLOW_MOUSE)
181
#define cairo_dock_stop_marking_icon_as_following_mouse(pIcon) cairo_dock_stop_marking_icon_animation_as (pIcon, CAIRO_DOCK_STATE_FOLLOW_MOUSE)
183
#define cairo_dock_mark_icon_as_inserting_removing(pIcon) cairo_dock_mark_icon_animation_as (pIcon, CAIRO_DOCK_STATE_REMOVE_INSERT)
184
#define cairo_dock_stop_marking_icon_as_inserting_removing(pIcon) cairo_dock_stop_marking_icon_animation_as (pIcon, CAIRO_DOCK_STATE_REMOVE_INSERT)
187
void cairo_dock_update_removing_inserting_icon_size_default (Icon *icon);
189
gboolean cairo_dock_update_inserting_removing_icon_notification (gpointer pUserData, Icon *pIcon, CairoDock *pDock, gboolean *bContinueAnimation);
190
gboolean cairo_dock_on_insert_remove_icon_notification (gpointer pUserData, Icon *pIcon, CairoDock *pDock);
191
gboolean cairo_dock_stop_inserting_removing_icon_notification (gpointer pUserData, Icon *pIcon);
194
/** Set a Transition on an Icon.
195
*@param pIcon the icon.
196
*@param pContainer the Container of the Icon. It will be shared with the transition.
197
*@param pIconContext a cairo context on the Icon for the cairo rendering. It will be shared with the transition.
198
*@param render_step_cairo the cairo rendering function.
199
*@param render_step_opengl the openGL rendering function (can be NULL, in which case the texture mapping from the cairo drawing is done automatically).
200
*@param bFastPace TRUE for a high frequency refresh (this uses of course more CPU).
201
*@param iDuration duration if the transition, in ms. Can be 0 for an endless transition, in which case you can stop the transition with #cairo_dock_remove_transition_on_icon.
202
*@param bRemoveWhenFinished TRUE to destroy and remove the transition when it is finished.
203
*@param pUserData data passed to the rendering functions.
204
*@param pFreeUserDataFunc function called to free the user data when the transition is destroyed (optionnal).
206
void cairo_dock_set_transition_on_icon (Icon *pIcon, CairoContainer *pContainer, cairo_t *pIconContext, CairoDockTransitionRenderFunc render_step_cairo, CairoDockTransitionGLRenderFunc render_step_opengl, gboolean bFastPace, gint iDuration, gboolean bRemoveWhenFinished, gpointer pUserData, GFreeFunc pFreeUserDataFunc);
208
/** Stop and remove the Transition of an Icon.
209
*@param pIcon the icon.
211
void cairo_dock_remove_transition_on_icon (Icon *pIcon);
213
/** Say if an Icon has a Transition.
214
*@param pIcon the icon.
215
*@return TRUE if the icon has a Transition.
217
#define cairo_dock_has_transition(pIcon) ((pIcon)->pTransition != NULL)
219
/** Get the the elpased number of steps since the beginning of the transition.
220
*@param pIcon the icon.
221
*@return the elpased number of steps.
223
#define cairo_dock_get_transition_count(pIcon) (pIcon)->pTransition->iCount
225
/** Get the elapsed time (in ms) since the beginning of the transition.
226
*@param pIcon the icon.
227
*@return the elapsed time.
229
#define cairo_dock_get_transition_elapsed_time(pIcon) (pIcon)->pTransition->iElapsedTime
231
/** Get the percentage of the elapsed time (between 0 and 1) since the beginning of the transition, if the transition has a fixed duration (otherwise 0).
232
*@param pIcon the icon.
233
*@return the elapsed time in [0,1].
235
#define cairo_dock_get_transition_fraction(pIcon) ((pIcon)->pTransition->iDuration ? 1.*(pIcon)->pTransition->iElapsedTime / (pIcon)->pTransition->iDuration : 0)