The Animation Architecture

Employing the animation architecture directly can be quite complex, requiring the implementation of a specific DLL for each desired animation. The main advantage of this approach is that the animation is able to run within the thread of the Window Server. As this is a high-priority thread, performance benefits are guaranteed. Client-side approaches must use Active Objects, which will not enjoy the priority advantages afforded by the thread of the Window Server.

The provided animation classes use a Client/Server mechanism in order to animate, with the client and server being wrapped up inside the DLL. The client in this case should not be confused with the alternative "client-side" approach.

Animation clients should derive from the RAnim class and are used to pass the Animation Server relevant information, such as the number of frames per second. Deriving from RAnimDLL provides the DLL interface. On the server side, CAnim-derived classes must be implemented to perform the animation, with CAnimDLL being used for the DLL interface.

Implementing your own animation DLL is beyond the scope of this chapter, however the SDK documentation provides an in-depth explanation of the key animation classes and how to use them. An example can also be found in the directory \Series60Ex\Animation in the root of your SDK.

In truth, there is no real need to implement a DLL for animating bitmaps, as the CAknBitmapAnimation class (as used in the Animation example) provides an interface to an animation DLL—you need only provide it with some images and attribute data.

The simplest way to use the CAknBitmapAnimation class is to define its relevant parts inside a resource file and then initialize the class with this data. Three essential resources are needed to construct an animation: the bitmap animation data (BMPANIM_DATA), an array of bitmap frames (ARRAY), and the individual bitmap frames themselves (BMPANIM_FRAME). Table 11-10 lists the elements of the STRUCT definitions from the Avkon.rh file. ARRAY is ignored, as it is generic and not specific to animation as such. Resource files are covered in more detail in Chapter 5.

_Table 11-10. Animation Resource Components_

STRUCT Element Type Element Name Role

BMP_ANIMDATA WORD frameinterval Delay between frames.

WORD playmode Three playmodes—see

\epoc32\include\avkon.hrh in the root directory of your SDK:

Cycle— repeat from the first frame to the last.

Bounce— play the first frame to the last and then back down to the first, repeatedly.

BYTE

flash

Causes the animation to flash, or

not, while playing.

LTEXT

bmpfile

The .mbm file containing the

animation frame.

LLINK frames Reference to the ARRAY

resource of BMPANIM_FRAME definitions.

LLINK backgroundframe Reference to the background frame definitions.

BMPANIM_FRAME WORD time Time that frame is displayed for.

WORD

posxx

x coordinate of top left of frame.

WORD

posyy

/coordinate of top left of frame.

WORD

bmpid

ID (from the .mbg file) of the desired bitmap from the .mbm file for this frame.

WORD

maskid

ID (from the .mbg file) of the desired masking bitmap from .mbm file for this frame.

The following resource structures show part of the concrete implementation from the Animation example. However, it should be noted that all elements do not have to be assigned values for the resource to be valid: RESOURCE BMPANIM_DATA r_animation_example_data frameinterval = 50;

playmode = EAknBitmapAnimationPlayModeBounce; flash = 0;

bmpfile = ANIMATION_BMPFILE_NAME; frames = r_animation_example_array ;

RESOURCE ARRAY r_animation_example_array items = {

BMPANIM_FRAME {

bmpid = EMbmAnimationDisplayimageframel; },

BMPANIM_FRAME {

bmpid = EMbmAnimationDisplaytextframe;

The animation control can be fully constructed via the resource and started as shown here: IView full width!

// instantiate CAknBitmapAnimation ¡Animation = CAknBitmapAnimation::Newl_();

TResourceReader reader;

¡CoeEnv->CreateResourceReaderLC(reader, R_ANIMATION_EXAMPLE_DATA); // map resource to * resource reader

// provide animation control with animation data ¡Animation->ConstructFromResourcel_(reader); // animation control needs a window ¡Animation->SetContainerWindowl_(*this); ¡Animation->StartAnimationl_(); // start animation CleanupStack::PopAndDestroy(); // resource reader created

Initially the CAknBitmapAnimation object is created. However, it does not contain any data relating to the animation itself—as the animation has been defined in a resource file, you need to read in the resource, and this is achieved by creating a TResourceReader object pointing to the animation resource.

The CAknBitmapAnimation::ConstructFromResourceL() can then be used to provide the animation data to the animation control. A window to draw to is required by the animation control, and this is assigned through the SetContainerWindowL() function in the Animation example application.

Should you choose to write your own CAknBitmapAnimation-derived class, then there is also the option of the animation control being "window-owning" by calling the CreateWindowL() function. The animation can be started and stopped by using the StartAnimationl_() and CancelAnimation() methods, respectively.

Practical use of CAknBitmapAnimation can be found throughout Series 60, as it is employed by numerous user interface controls, such as CAknNoteControl and CAknQueryControl.

+1 0

Average user rating: 5 stars out of 1 votes

Post a comment

  • Receive news updates via email from this site