00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef SIMPLEANIMATION_H__ 00011 #define SIMPLEANIMATION_H__ 00012 00013 #include "AppConfig.h" 00014 #include "SpecialMetadata.h" 00015 00016 #define FRAME_TIMES_METADATA_NAME (std::string("FrameTimes")) 00017 #define FRAME_TIMES_METADATA_PATH (SPECIAL_METADATA_NAME + "/" + BAND_METADATA_NAME + "/" + FRAME_TIMES_METADATA_NAME) 00018 00019 class AnimationController; 00020 class Layer; 00021 00022 #ifdef __cplusplus 00023 extern "C" 00024 { 00025 #endif 00026 /** \addtogroup simple_api */ 00027 /*@{*/ 00028 00029 /** 00030 * @file SimpleAnimation.h 00031 * This file contains API utilities for controlling animations. 00032 */ 00033 00034 /** 00035 * Animation callback function prototype. 00036 * 00037 * Passed a pointer to the Animation which caused the callback to execute. 00038 * The name, number, and time for the frame are passed in but may be invalid depending 00039 * on the AnimationController type. (frame type does not have valid frame times). 00040 * A caller specified value is also passed. 00041 */ 00042 typedef void(*animation_callback_t)(const char* pAnimation, const char* pFrameName, 00043 uint32_t frameNumber, double frameTime, void* pUser); 00044 00045 /** 00046 * Get a handle to a named AnimationController. 00047 * 00048 * @param pName 00049 * \c NULL terminated name of the animation controller. If this is \c NULL 00050 * the active controller will be returned. 00051 * @return The AnimationController handle or \c NULL on error. 00052 */ 00053 EXPORT_SYMBOL AnimationController* getAnimationController(const char* pName); 00054 00055 /** 00056 * Create a new AnimationController. 00057 * 00058 * @param pName 00059 * \c NULL terminated name for the animation controller. 00060 * If this exists, an error will be set. 00061 * @param timeBased 00062 * If non-zero, a time based controller is created (using real numbers for times). 00063 * If zero, a frame based controller is created (using intergers for frame numbers). 00064 * @return The new AnimationController handle or \c NULL on error. 00065 */ 00066 EXPORT_SYMBOL AnimationController* createAnimationController(const char* pName, int timeBased); 00067 00068 /** 00069 * Permanently destroy an AnimationController. 00070 * 00071 * Suitable for use as a cleanup callback. 00072 * 00073 * @param pController 00074 * The AnimationController to destroy. 00075 * No error checking is performed on this value and a \c NULL will cause a NOOP. 00076 */ 00077 EXPORT_SYMBOL void destroyAnimationController(AnimationController* pController); 00078 00079 /** 00080 * Activate an AnimationController so that it is controlled by the animation toolbar. 00081 * 00082 * @param pController 00083 * The AnimationController to activate. 00084 * @return Zero on success, non-zero on error. 00085 */ 00086 EXPORT_SYMBOL int activateAnimationController(AnimationController* pController); 00087 00088 /** 00089 * Get the state of the AnimationController. 00090 * 00091 * @param pController 00092 * The AnimationController to query. 00093 * @return The state of the controller. 00094 * 0 -> Stopped, 1 -> Playing forward, 2 -> Playing backward, 00095 * 3 -> Paused and will play forward on resume, 4 -> Paused and will play backward on resume 00096 * Zero may indicate an error and getLastError() should be checked. 00097 */ 00098 EXPORT_SYMBOL uint32_t getAnimationControllerState(AnimationController* pController); 00099 00100 /** 00101 * Set the state of the AnimationController. 00102 * 00103 * @param pController 00104 * The AnimationController to mutate. 00105 * @param state 00106 * The new state of the controller. 00107 * 0 -> Stop, 1 -> Play forward, 2 -> Play backward, 00108 * 3 -> Pause and play forward on resume, 4 -> Pause and will play backward on resume 00109 * @return Zero on success or non-zero on error. 00110 */ 00111 EXPORT_SYMBOL int setAnimationControllerState(AnimationController* pController, uint32_t state); 00112 00113 /** 00114 * Begin playback of an animation controller in the current direction. 00115 * 00116 * @param pController 00117 * The AnimationController to mutate. 00118 * @return Zero on success or non-zero on error. 00119 */ 00120 EXPORT_SYMBOL int playAnimationController(AnimationController* pController); 00121 00122 /** 00123 * Pause playback of an animation controller. 00124 * 00125 * @param pController 00126 * The AnimationController to mutate. 00127 * @return Zero on success or non-zero on error. 00128 */ 00129 EXPORT_SYMBOL int pauseAnimationController(AnimationController* pController); 00130 00131 /** 00132 * Stop playback of an animation controller. 00133 * 00134 * @param pController 00135 * The AnimationController to mutate. 00136 * @return Zero on success or non-zero on error. 00137 */ 00138 EXPORT_SYMBOL int stopAnimationController(AnimationController* pController); 00139 00140 /** 00141 * Get the cycle mode of the AnimationController. 00142 * 00143 * @param pController 00144 * The AnimationController to query. 00145 * @return The cycle mode of the controller. 00146 * 0 -> Play once and reset, 1 -> Repeat play, 2 -> Reverse direction at end, 00147 * Zero may indicate an error and getLastError() should be checked. 00148 */ 00149 EXPORT_SYMBOL uint32_t getAnimationControllerCycle(AnimationController* pController); 00150 00151 /** 00152 * Set the cycle mode of the AnimationController. 00153 * 00154 * @param pController 00155 * The AnimationController to mutate. 00156 * @param cycle 00157 * The new cycle mode of the controller. 00158 * 0 -> Play once and reset, 1 -> Repeat play, 2 -> Reverse direction at end, 00159 * @return Zero on success or non-zero on error. 00160 */ 00161 EXPORT_SYMBOL int setAnimationControllerCycle(AnimationController* pController, uint32_t cycle); 00162 00163 /** 00164 * Will the AnimationController drop frames to maintain the play rate? 00165 * 00166 * @param pController 00167 * The AnimationController to query. 00168 * @return Zero if the controller will slow playback instead of dropping frames. 00169 * Non-zero if the controller will drop frames to maintain the playback rate. 00170 * Zero may indicate an error and getLastError() should be checked. 00171 */ 00172 EXPORT_SYMBOL int canAnimationControllerDropFrames(AnimationController* pController); 00173 00174 /** 00175 * Allow the AnimationController to drop frames to maintain the play rate/ 00176 * 00177 * @param pController 00178 * The AnimationController to mutate. 00179 * @param dropFrames 00180 * Zero if the controller should slow playback instead of dropping frames. 00181 * Non-zero if the controller should drop frames to maintain the playback rate. 00182 * @return Zero on success or non-zero on error. 00183 */ 00184 EXPORT_SYMBOL int setAnimationControllerCanDropFrames(AnimationController* pController, int dropFrames); 00185 00186 /** 00187 * Get the interval multiplier of an AnimationController. 00188 * 00189 * @param pController 00190 * The AnimationController to query. 00191 * @return The interval multiplier. This speeds up or slows down 00192 * the playback in a linear fashion. For example: a value 00193 * of 2.0 doubles the playback rate and a value of 0.5 halves 00194 * the playback rate. A value of NaN indicates an error. 00195 */ 00196 EXPORT_SYMBOL double getAnimationControllerIntervalMultiplier(AnimationController* pController); 00197 00198 /** 00199 * Set the interval multiplier of an AnimationController. 00200 * 00201 * @param pController 00202 * The AnimationController to query. 00203 * @param multiplier 00204 * The interval multiplier. This speeds up or slows down 00205 * the playback in a linear fashion. For example: a value 00206 * of 2.0 doubles the playback rate and a value of 0.5 halves 00207 * the playback rate. 00208 * @return Zero on success or non-zero on error. 00209 */ 00210 EXPORT_SYMBOL int setAnimationControllerIntervalMultiplier(AnimationController* pController, double multiplier); 00211 00212 /** 00213 * Attach a RasterLayer to an AnimationController. 00214 * 00215 * If the controller if frame based, this will attach frames on a one-to-one basis. 00216 * If the controller is time based, this will attach frames starting at the AnimationController's start time 00217 * (or current system time if there are no frames in the controller) with a frame rate of 1fps. 00218 * If the RasterElement in the RasterLayer has a metadata entry in "Special/Band/FrameTimes" 00219 * which is a vector<double> with a frame time for each frame in the RasterElement, those frame 00220 * times will be used. 00221 * 00222 * The name of the Animation which attaches the RaseterLayer will be the same as the Layer. 00223 * If an attachment with this name exists already, an error will occur. 00224 * 00225 * @param pController 00226 * The AnimationController to mutate. 00227 * @param pLayer 00228 * The RasterLayer to attach. 00229 * @return Zero on success or non-zero on error. 00230 */ 00231 EXPORT_SYMBOL int attachRasterLayerToAnimationController(AnimationController* pController, Layer* pLayer); 00232 00233 /** 00234 * Attach a callback function to an AnimationController. 00235 * 00236 * @param pController 00237 * The AnimationController to mutate. 00238 * @param pName 00239 * The \c NULL terminate name of the Animation which attaches the callback. 00240 * If an attachment with this name exists already, an error will occur. 00241 * @param pCallback 00242 * The callback function. 00243 * @param pUser 00244 * Handle to pass to the pUser field in the callback. This may be \c NULL. 00245 * @param frameCount 00246 * The number of frames which will be animated. 00247 * @param pFrameTimes 00248 * If \c pController is a frame based AnimationController, this should be \c NULL. 00249 * If \c pController is a time based AnimationController, this is an array of length \c frameCount 00250 * with the frame times or if \c NULL, the start time (or current system time) will be user to generate 00251 * \c frameCount times 1 second appart. 00252 * @return \c NULL on error or a callback handle. This must be passed to destroyAnimationControllerAttachment() 00253 * to clean up and release the allocated memory. 00254 */ 00255 EXPORT_SYMBOL void* attachCallbackToAnimationController(AnimationController* pController, const char* pName, 00256 animation_callback_t pCallback, void* pUser, 00257 uint32_t frameCount, double* pFrameTimes); 00258 00259 /** 00260 * Permanently destroy an attachment point from an AnimationController. 00261 * 00262 * Suitable for use as a cleanup callback. 00263 * 00264 * @param pController 00265 * The AnimationController to mutate. 00266 * No error checking is performed on this value and a \c NULL will cause a NOOP. 00267 * @param pName 00268 * The name of the Animation attachment point to destroy. 00269 * No error checking is performed on this value and a \c NULL will cause a NOOP. 00270 * @param pHandler 00271 * If the attachment was a callback attachment, this is the return value of 00272 * attachCallbackToAnimationController(). If the attachment was not a 00273 * callback attachment, this is \c NULL. 00274 */ 00275 EXPORT_SYMBOL void destroyAnimationControllerAttachment(AnimationController* pController, 00276 const char* pName, void* pHandler); 00277 00278 /*@}*/ 00279 #ifdef __cplusplus 00280 } 00281 #endif 00282 00283 #endif