FREQUENTLY ASKED QUESTIONS
22. Can I call 'C' functions from MetaCard?On UNIX systems, the file external.tar.Z in the standard distribution has templates for doing this. These same templates are placed in the Externals folder in the Win32 and MacOS distributions. MetaCard can call commands and functions in the external, and these external 'C' routines can call back to the MetaCard engine to get and set variables and to execute commands.
See the MetaCard Tutorials stacks for a demonstration of the external
capability and instructions on how to create and modify externals.
To remove these limitations the MetaCard engine is also available in an embedded version on UNIX systems. This library (libmc.a) can be linked directly to applications which can call MetaCard functions with only normal function call overhead (which can be up to 40 times faster than communicating via properties), and which can be debugged using ordinary debugging tools.
On Win32 systems, externals are built as DLLs. Since debugging DLLs
is relatively straightforward, and since performance isn't a problem
with this architecture, Embedded MetaCard is not available for Win32
systems. For MacOS, externals are stored as code resources, which
also are relatively easy to debug and don't have major performance
penalties associated with them.
You must use the "Print Setup" dialog to set the printing parameters
before printing cards. See the help for that dialog and the card
describing the print command in the MetaTalk Reference for more
information on printing.
You can also import EPS graphics on systems that support the DPS X server extension (RS/6000, SPARCSVR4, Alpha).
No support for 3D graphics is provided, but can easily be added using
externals. See the external tutorial in the MetaCard Tutorials stack
for and example of how to draw into MetaCard windows from external C
functions.
Other common debugging techniques include using the put command to
put things into the Message Box (equivalent to using printf with 'C'
programs), using "write <expression> to stdout" to trace scripts by
writing to the terminal window that MetaCard was started from, and
using the "watch" command to watch variables. For more complex
programming tasks, the external command interface can be used to
produce C or C++ back ends to MetaCard user-interfaces.
The Windows 95/NT engine can play AVI files using Video For Windows as well as any format supported by QuickTime 3.0 (and later) if QuickTime is installed on the target system. The MacOS engine requires QuickTime 3.0 or later to play movies. The UNIX engines can play QuickTime, AVI, MPEG, and FLI/FLC animations, but only a limited set of QuickTime codecs is supported (specifically, Sorenson is not supported, nor is QTVR). The files can either be played directly from disk, or imported into MetaCard stacks before playing to reduce startup times on systems with sufficient memory. MetaCard has properties for scaling the movies, playing them back at particular locations within a window, changing their frame rate, and leaving the last frame of a movie on the screen (which can be used to make transitions between movies smoother). See the documentation for the "play" command and "player" object for more information.
There are several commercial video/movie players available, all of
which can be made to work with MetaCard. MetaCard has properties and
commands that allow starting and stopping these players, playing the
movie into a MetaCard window, and sharing colormaps between the players
and the MetaCard engine. The Win32 engine has an mciSendString command
that can be used to send any command to any MCI-compatible device.
Remember that all messages sent to any of the substacks pass through
the main stack. This means you have to be careful to check the target
if you have any handlers for any of the standard MetaCard messages.
This feature does make main stack scripts a good place to put handlers
that are used in several of the other stacks in your application.
The topStack is the top-most editable stack. It will usually have a
page number in parentheses and may also have a "*" (denoting that the
cantModify property is set to false) in its title bar. To avoid
confusion, it is recommended that only a single stack be edited at a
time. Close or iconize/minimize/collapse the others.
topLevel "my stack"If your stack is saved as a substack of another stack, you can also open it from the Components dialog from the Stack Properties dialog of your mainStack.
If this stack will be used frequently, add a button to the Home stack
with the "topLevel" command in a mouseUp handler.
It is a much better design to use multiple cards for your application
rather than trying to outsmart the window manager by positioning a
stack by setting its loc or topLeft properties in a script. Also see
the "in the window" option to the go command.
The scripts should contain an "on startUp" handler, which will be
called when the script is executed. The script can
read from its standard input with the statement "read from stdin until
empty", and can write to its standard output with "write x to stdout".
The "put" command without a destination container will also write the
expression to stdout (normally it goes into the Message Box in this
case).
The easiest way to import images in MetaCard is to use the snapshot feature: open the image using the application used to create it or an image viewer application, and then import a snapshot of it with the "import snapshot" command or the "Importer" dialog. The PBMplus image conversion package is a freeware package that will convert most common image formats on UNIX systems. It can be acquired from many Internet archive sites. It is also available on many CDs including the UNIX Power Tools book/CD (O'Reilly & Associates/Bantam Book ISBN 0-553-35402-7) and most Linux CDs. If you want or need a commercial image conversion product, Image Alchemy from Handmade Software may do the trick. If you need to convert images produced on a Macintosh, DeBabelizer from Equilibrium may be a better solution.
To avoid running out of colors, in which case MetaCard does a simple
nearest-color remapping of the image, consider quantizing the images to
reduce the number of colors they use. Remapping all of the images to
use the same colormap is also a good way to reduce the number of colors
required. A good rule of thumb is to use no more than a total of 160
colors for all of the objects in a stack.
On UNIX systems you can import non-transparent images and edit them to make them transparent. To do this, choose the bucket tool from the Paint Tools palette and click mouse button 2 in the background. This will will erase all connected areas of the same color. Next, double click on the image with the pointer tool and write down the id of the image. Go to the card where you want the button to be and create a button. Make sure the button is selected and then set the icon property to the id of the image (1234 in this example) using the Message Box: set the icon of the selectedObject to 1234
The same technique can be used to set the backPattern property of a
button or any other type of object.
If you only have a few characters to enter, the easiest way is probably using the "Character Chooser" or the numToChar() function (on UNIX/X11 systems, you can get the number of the character you need by displaying the font with the "xfd" program). To access the fonts for other languages (e.g. those that use 16 bit characters), you'll need to set the textFont property to the font name in the "Object Font" dialog, or by typing it into the Message Box. To specify a font set on UNIX systems (for 16-bit fonts), put all of the fonts required (separated by commas) in the textFont property. For example, to make the first line of a field be displayed in the Kanji24 font, you'd type: set the textFont of line 1 of field "some field" to "kanji24". Use the X program "xlsfonts" to find out which fonts have been installed on your system. Note that isn't possible to edit 16 bit text, you can only import it from a file produced in another editor, or by using "quick paste" (select the text in editor window and click mouse button 2 in the MetaCard field where you want to paste the text).
Support for Unicode and other 16 bit character sets is not available
in the Win32 or MacOS engines yet.
Without a background, everything goes on the card layer. Multiple backgrounds can be created and the "Edit Backgrounds" dialog box can be used to place them on or remove them from cards.
Note that "groups" and "backgrounds" are the same thing. The only
difference in the use of the terms is that when addressing objects,
"groups" are accessed relative to the card and "backgrounds" are
accessed relative to the stack, so group 2 is the second group on the
current card, whereas background 2 is the second group in the stack,
and may not even be used on the current card.
To save any changes you make, be sure to save the tools stack, since
these dialogs are not part of the Home stack (type 'save stack
"MetaCard Menu Bar"' into the Message Box to save the tools stack.
Note that the file mctools.mc must be writable for this to work).
The second way is to set the "menuName" property of the button to a stack name (any stack can be used as a menu panel). See the MetaTalk Reference stack for details on this command and property. The "Menu Properties", accessible from the "Button Properties" palette supports setting many menu-related properties. Note that the easiest way to build these menu stacks is to clone the existing menus. See the Concepts & Techniques stacks for tips on how to do this.
The third way is to simulate a menu panel using a field (or group)
that you hide and show. Finally, you can use the "popup" command to
open a menu panel over any control.
If the first character in a line in the button contents is a - character, the menu created by that button will have a dividing line at that point. |
FAQ | Overview . Licensing . How To . Common Problems . Consultants . Testimonials |