A wrapping of the Animation Control

By: Steve Waring
Home Pages: Journal Dolphinharbor
Created: 20021123
Last Update: 20021123

Overview

The Windows Animation Control is a simple control that displays AVI clips. This article contains a wrapper for the control and a sample ToGo application that contains a toolbar animation.

animationControl

Quick Guide to using the Control

In the ViewComposer, add the "Default view" resource of AnimationPresenter. This resource is configured to auto-play, be centered, and be transparent.

Create an Animation model on the AVI. Like Bitmaps and Icons, AVI clips resources can either be loaded from a file or a DLL. There are restrictions on what AVI's the control will play. The workspace example uses the mouse.avi

animationControl

Design Decisions

The wrapping is implemented as typical value MVP triad.

My main goal for the implementation was that I could manage AVI resources the same way that I manage Bitmap resources, ie I could reuse my strategies for working with Bitmaps in development images and deployed executables.

Model

Animation is a model class. Instances should be treated as immutable, ie to change the animation that is playing, create a new instance and set it into the AnimationPresenter's valueModel.

Animation has the same instance creation protocol (fromFile* and fromId*) as Bitmap/Icon etc.

AnimationView>>openAnimation
"Opens the animation and displays its first frame in an animation control.

This is designed to behave similarly to loading bitmaps:
- First try to open a resource, using the instanceHandle/identifier
- If fail, try to open a file using the fileLocator/fileSpec
- If fail, try to open a resource using the defaultResourceLibrary/identifier"

Presenter

AnimationPresenter is a ValuePresenter.

It implements a number of helper commands; #play, #stop and #reset.

View

AnimationView is a ValueConvertingControlView.

I decided to use the value protocol because it was the simplest approach. If the Control allowed me to ask for its state (ie are you playing or stopped?) I may have used a different approach and given Animation the responsibility of controlling the state of the animation.

The control does send two notifications ACN_START and ACN_STOP, but I would have had to track the state myself. I decided that the increase in complexity offered little, and this comment in MSDN; "Most applications do not handle either notification" sealed the decision.

Downloads

The packages are released under the OpenBSD license (ie free). The "SWAnimationControl.pac" includes the MVP classes. The "SW AnimationControl Sample" contains a Sample shell and the SessionManager that was used to deploy the test ToGo.

The Sample package expects to be installed from the "[image directory]\Steve Waring\Utilities\UI\" folder. Included is my "SW BitmapFileLocator" package which contains the FileLocator class I use with Bitmaps (and now AVIs).

The "[image directory]\Steve Waring\Utilities\UI\resources\" folder contains a number of animations obtained from http://www.webdeveloper.com/animations/. Animation Shop was used to convert GIF animations to AVIs.

The ToGo is released as TestWare ... if you have a problem with the code or technique in your environment, you will be doing me a big favor by letting me know about it.

The test ToGo has been run successfully on WinXP, Win2k and Win95 (with IE5) machines.


Copyright Steve Waring 2002.