Animate 1.0 for Tcl/Tk 8.2.x and later versions under Windows
The Animate 1.0 package is an extension to the Tcl/Tk 8.2.x or later BINARY release for WIndows that provides the capability to do rapid frame animation of images stored in Windows .BMP format. With even modest hardware, such as a P1 90MHZ and IDE disks, reasonable frame animation rates can be achieved. The package comes with a demonstration script that shows how to loop through a series of images on disk.
This package works by creating a pseudo-widget that directly accesses native Windows feature that allow rapid display of image files. It by-passes the Tcl/Tk "image" command and does not go through the X emulation layer of Tcl/Tk. The package would be of interest to those who have a frame animation requirement that exceeds the performance capabilities of the Native Tcl/Tk resources.
The picture pseudo widget acts in most respects like a normal Tcl/Tk widget, however, there may be some applications in which it can not be effectively used.
Installation
Download the Animate 1.0 package into your $tcl_library directory. Upack the archive using a utility that preserves the embedded directory structure (for example, use unzip.exe). This should create a sub-directory named animate1.0 with the extension .DLL file and the demonstration script.
Using the Animate 1.0 Package
Load the package with the command...
package require Animate 1.0This package provides only 1 command, the "picture" command. The demonstration script "animate.tcl" shows how to implement animation of a list of files.
Technical Caveats
This extension makes use of some native windows features to achieve animation performance that is difficult to attain using the native Tcl/Tk mechanisms provided through the "image" command. The Animate 1.0 package works by taking over a standard Tcl/Tk frame window and installing (sub-classing) within it a child window that actually does the image display and provides the supporting features of the "picture" command.
This approach imposes some constraints on the manipulation of the animation window. Since the Tcl/Tk geometry manager does not see the animation window itself (it does see the associated frame), it can only be manipulated within the context of a mapped parent frame. "Mapped" means that the parent frame must be created and displayed before the picture window is created. Depending on the geometry manager you use, this means that the parent frame needs to be "packed" or "placed" or "gridded" or whatever does your mapping before you create the picture window.
The main manifestation of this is that the following code will fail:
whereas the following code works fine...set f [frame .f]
picture $f.image ...
set f [frame .f]pack .fpicture $f.image ...
The picture command has the following format:
picture path ?-file? ?file?
?-height? ?height? ?-width? ?width? ?-background? ?background? ?-fit? ?boolean?
?-variable? ?variable? ?-scrollbars? ?boolean? ?-center? ?center? ?-resize?
?boolean?
where path is the path name of the picture pseudo widget to create. The path is a standard Tk window path specification and is treated as consisting of a root component and a name component. The name component is just the string following the last "." in the path, and it can have any value. The root component must be a valid path name to a mapped frame widget.
Here is an example:
set f [frame .top.pictures.loops]
pack $f
picture $f.image
Here the root is ".top.pictures.loops" and the name is "image".
The file parameter is a file specification for the image to be displayed. If specified, and if the image exists, then the image will be immediately displayed in the picture window.
The height and width parameters are the desired dimensions in pixels of the image window to be created. If the height and width parameters are specified, the associated parent frame will be resized to these dimensions. If the height and width parameters are not specified, then the picture window will be sized based on the size of the client area of the associated parent frame window. For anything other than a simple layout, it is probably wiser to specify the dimensions of the window using the frame widget command than to use the picture command.
The background option controls whether the WM_ERASEBKGND window message is processed by the picture window. Normally, before Windows updates a window, it sends the WM_ERASEBKGND message to cause the current contents of the window to be cleared. When doing frame animation this causes 2 possibly undesireable results. The window tends to flash, and the maximum speed of animation is cut by the time needed to erase the window.
The background option can be either erase, the default value, or noerase. If the noerase value is specified, then WM_ERASEBKGND messages are ignored. If you are animating frames that are all of the same size, then you probably want to specify noerase. You can, however, achieve interesting visual effects by using noerase with images of different sizes.
The fit option can be either "true" or "false" (the default). Setting fit to "true" causes the images to be stretched to the current size of the picture window. Depending on the images, this can result in either a useful or useless. The pixel sampling algorithm that is used by the Windows drawing function can cause some images to become so distorted that they can not be properly discerned. This is a characteristic of how Windows stretches image data. Setting fit to "true" also forces scrollbars (see below) to "false".
The variable option is used to specify the name of a Tcl variable that can act as a semaphore so that the animating script will not run so fast that you can't see the individual images. The format of the variable option is "name" or "name,index".
Where a specification for variable or the form "-variable name" is used, the picture window will manipulate a GLOBAL array variable in the current interp named "name(path)" by clearing it to 0 when the image is loaded, and setting it to 1 after the picture window has processed a WM_PAINT message. Here path is the path name of the picture pseudo-widget as defined above.
Where a specification for variable or the form "-variable name,index" is used, the picture window will manipulate a GLOBAL array variable in the current interp named "name(index,path)". Here index is just an additional value that provides for a more complex array index.
The scrollbars option controls whether the picture window displays scroll bars if the displayed image is larger than the client area of the picture window. By default, the value is "true", and when set to "false" the display of scroll bars is suppressed. Note that specifying either fit or center will also suppress scroll bars.
The center option can be used to cause the picture window to display the image centered within the window. There are 2 cases handled, that where the image is smaller than the window, and that where the window is smaller than the image. In the former case, the image is centered in the window. In the latter case, the center of the image is displayed in the window. By default, center is "false". Setting center to "true" also suppresses scrollbars and forces fit to false.
The resize option controls the behaviour of the picture window when the parent frame is resized by, for example, using the mouse to drag the borders. By default, the value of the resize option is "true", which means that the picture window will be automatically resized to fill the parent frame whenever a WM_SIZE message is posted to the frame. If the resize option is set to "false", the frame will handle WM_SIZE messages, but the picture window will remain fixed at its creation size.
Return Value
The value returned by the picture command is, assuming no error occurs, the name of the pseudo-widget command created for accessing the features of the picture window widget. In case of an error, the value returned is the error message produced by the error.
Widget Command
The picture command creates a pseudo-widget command with a name that is identical to the path specified on the picture command. The pseudo-widget command supports the config sub-function and the cget sub-function.
The pseudo-widget command can be used, via config, to set any of the option values of the picture command except for the height and width values. For example:
set i [picture $f.image]
$i config -file name.bmp -background noerase -fit true
will create a picture window and then load the file "name.bmp" into it.
The cget sub-function works in the usual manner. All of the option values can be accessed by using cget as in:
$i cget -file
to get the name of the current image file.
The animate.tcl Demonstration
The animate.tcl file is a script that demonstrates the features of the Animate 1.0 package. Start the script using the command:
source $tcl_library/animate1.0/animate.tcl
The defaults in the script set the file search path to c:/windows/*.bmp because this directory usually contains a lot of image files. You can set another path by clicking the Filter button on the button bar.
The Options button brings up a dialog that allows configuration of the picture window. The remaining buttons should be self evident as to their use. Pressing Forward will loop through the images as fast as your system will do the job, and continue until you press Stop. Similarly, Backward loops in reverse. You can page through the images using Next and Previous.
In this demonstration, the parent frame is resizeable, so you can adjust the size of the animation window by dragging the edges or corners of the window. Usually, the larger the window, the slower the animation, although modern processors can animate fairly large frames with good speed.
Warranty
None. This package is provided as is, without warranty of any kind. Use at your own risk.
License
Free for private, non-commercial use. Redistribution is permitted for non-commercial purposes only. Resale is prohibited.
Source
Yes, you can have it. Its written in C++ using the Borland OWL package, so before you ask for it, think about what you will do with it.
Email : customclients@videotron.ca