2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrlAnimation.h
20 * @brief This header file contains the declarations of the %Animation class.
22 * This header file contains the declarations of the %Animation class and its helper classes.
25 #ifndef _FUI_CTRL_ANIMATION_H_
26 #define _FUI_CTRL_ANIMATION_H_
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FBaseColArrayList.h>
31 #include <FGrpBitmap.h>
32 #include <FGrpColor.h>
33 #include <FGrpPoint.h>
34 #include <FGrpRectangle.h>
35 #include <FUiContainer.h>
36 #include <FUiCtrlAnimationFrame.h>
37 #include <FUiIAnimationEventListener.h>
39 namespace Tizen { namespace Ui { namespace Controls
43 * @enum AnimationStatus
45 * Defines the animation status.
51 ANIMATION_STOPPED, /**< The %Animation is in 'stopped' state */
52 ANIMATION_PAUSED, /**< The %Animation is in 'paused' state */
53 ANIMATION_PLAYING /**< The %Animation is in 'playing' state */
59 * @brief This class defines the common behavior of an %Animation control.
63 * The %Animation class displays a series of frames one by one that are represented by the AnimationFrame instances.
65 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_animation.htm">Animation</a>.
68 * The following example demonstrates how to use the %Animation class.
72 // Sample code for AnimationSample.h
77 : public Tizen::Ui::Controls::Form
78 , public Tizen::Ui::IAnimationEventListener
82 : __animationFrameList(){}
84 bool Initialize(void);
85 virtual result OnInitializing(void);
86 virtual result OnTerminating(void);
88 // IAnimationEventListener
89 virtual void OnAnimationStopped(const Tizen::Ui::Control& source);
92 Tizen::Base::Collection::ArrayList __animationFrameList;
99 // Sample code for AnimationSample.cpp
101 #include <FGraphics.h>
103 #include "AnimationSample.h"
105 using namespace Tizen::App;
106 using namespace Tizen::Base::Collection;
107 using namespace Tizen::Graphics;
108 using namespace Tizen::Ui::Controls;
111 AnimationSample::Initialize(void)
113 Construct(FORM_STYLE_NORMAL);
118 AnimationSample::OnInitializing(void)
120 result r = E_SUCCESS;
122 // Gets instances of Bitmap
123 AppResource *pAppResource = Application::GetInstance()->GetAppResource();
124 Bitmap* pBitmap1 = pAppResource->GetBitmapN(L"progressing00_big.png");
125 Bitmap* pBitmap2 = pAppResource->GetBitmapN(L"progressing02_big.png");
126 Bitmap* pBitmap3 = pAppResource->GetBitmapN(L"progressing04_big.png");
127 Bitmap* pBitmap4 = pAppResource->GetBitmapN(L"progressing06_big.png");
129 // Creates instances of AnimationFrame
130 AnimationFrame* pAniFrame1 = new AnimationFrame(*pBitmap1, 1000) ;
131 AnimationFrame* pAniFrame2 = new AnimationFrame(*pBitmap2, 1000) ;
132 AnimationFrame* pAniFrame3 = new AnimationFrame(*pBitmap3, 1000) ;
133 AnimationFrame* pAniFrame4 = new AnimationFrame(*pBitmap4, 1000) ;
135 __animationFrameList.Construct();
136 __animationFrameList.Add(*pAniFrame1);
137 __animationFrameList.Add(*pAniFrame2);
138 __animationFrameList.Add(*pAniFrame3);
139 __animationFrameList.Add(*pAniFrame4);
141 // Creates an instance of Animation
142 Animation* pAnimation = new Animation();
143 pAnimation->Construct(Rectangle((GetClientAreaBounds().width - pBitmap1->GetWidth()) / 2, 100,
144 pBitmap1->GetWidth(), pBitmap1->GetHeight()), __animationFrameList);
145 pAnimation->SetRepeatCount(100);
146 pAnimation->AddAnimationEventListener(*this);
148 // Adds the animation to the form
149 AddControl(*pAnimation);
151 // Plays the animation
163 AnimationSample::OnTerminating(void)
165 result r = E_SUCCESS;
167 // Deallocates added animation frames from the list
168 __animationFrameList.RemoveAll(true);
174 AnimationSample::OnAnimationStopped(const Control& source)
181 class _OSP_EXPORT_ Animation
182 : public Tizen::Ui::Control
187 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
195 * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called when the destructor of this interface is called.
199 virtual ~Animation(void);
203 * Initializes this instance of %Animation with the specified parameters. @n
204 * The input list of the AnimationFrame instances (@c aniFrames) should be deleted explicitly after use.
208 * @return An error code
209 * @param[in] rect An instance of the Rectangle class @n
210 * This instance represents the x and y coordinates of the top-left corner of the created window along with
211 * its width and height.
212 * @param[in] aniFrames An IList of %AnimationFrames used in the animation
213 * @exception E_SUCCESS The method is successful.
214 * @exception E_SYSTEM A system error has occurred.
215 * @exception E_INVALID_ARG A specified input parameter is invalid.
216 * @remarks A control is fully usable only after it has been added to a container, therefore some methods may fail if used earlier. @n
217 * @remarks The size of the control must be within the range defined by the minimum size and the maximum size.
218 * @see AnimationFrame
220 result Construct(const Tizen::Graphics::Rectangle& rect, const Tizen::Base::Collection::IList& aniFrames);
223 * Initializes this instance of %Animation with the specified parameters. @n
224 * The input list of the AnimationFrame instances (@c aniFrames) should be deleted explicitly after use.
228 * @return An error code
229 * @param[in] rect An instance of the FloatRectangle class @n
230 * This instance represents the x and y coordinates of the top-left corner of the created window along with
231 * its width and height.
232 * @param[in] aniFrames An IList of %AnimationFrames used in the animation
233 * @exception E_SUCCESS The method is successful.
234 * @exception E_SYSTEM A system error has occurred.
235 * @exception E_INVALID_ARG A specified input parameter is invalid.
236 * @remarks A control is fully usable only after it has been added to a container, therefore some methods may fail if used earlier. @n
237 * @remarks The size of the control must be within the range defined by the minimum size and the maximum size.
238 * @see AnimationFrame
240 result Construct(const Tizen::Graphics::FloatRectangle& rect, const Tizen::Base::Collection::IList& aniFrames);
244 * Adds a listener instance to the current instance of %Animation. @n
245 * The added listener can listen to the events on the given event dispatcher's context when they are fired. @n
246 * When an animation stops, a state change event with the state name "ANIMATION_NOTIFY_CLOSE" is fired.
250 * @param[in] listener The listener to add
252 void AddAnimationEventListener(Tizen::Ui::IAnimationEventListener& listener);
256 * Removes a listener instance from the current instance of %Animation. @n
257 * The removed listener cannot listen to the events when they are fired.
261 * @param[in] listener The listener to remove
263 void RemoveAnimationEventListener(Tizen::Ui::IAnimationEventListener& listener);
267 * Sets the repeat count of the animation. @n
268 * If this value is not set, the default value is @c 1.
272 * @param[in] count The repeat count
274 void SetRepeatCount(int count);
278 * Gets the total repeat count of the animation.
282 * @return The total repeat count
284 * @remarks The default repeat count is 1.
286 int GetRepeatCount(void) const;
290 * Gets the current repeated count of the animation.
294 * @return The current repeated count
296 * @remarks The default current repeated count is 0.
298 int GetCurrentRepeatedCount(void) const;
302 * Gets the total image count of the animation.
306 * @return The total image count
308 * @remarks The default image count is 0.
310 int GetImageCount(void) const;
314 * Plays the animation.
322 * Stops the animation.
330 * Pauses the animation.
338 * Gets the status of the animation.
342 * @return The status of animation
344 * @remarks The default animation status is ANIMATION_STOPPED.
346 AnimationStatus GetStatus(void) const;
350 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
352 Animation(const Animation& rhs);
355 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
357 Animation& operator =(const Animation& rhs);
359 friend class _AnimationImpl;
363 }}} // Tizen::Ui::Controls
365 #endif // _FUI_CTRL_ANIMATION_H_