
CHAPTER 1 Introduction
A note about the source code shown in this tutorial:
In the latest version of Fresco, the format of the examples has
changed somewhat. For example, main() is no long found in each example
program. Instead, a dynmamic initializer automatically registers the
examples inside an "examples program" dialog box. These changes are not
reflected in the text. For the most up-to-date version of the source code, please see
the Fresco's examples directory.

Line 5 creates a Fresco naming context which can be used to access objects by name. For example, the name "FigureKit" on line 9 is indeed found within the Fresco naming context, so a FigureKit object is returned for it. Kits in Fresco can be thought of as "object factories" which provide an implementation independent means to create new Fresco objects. The value of this separation of interface and implementation is evident in the creation of widgets. By using Fresco's WidgetKit interface, a programmer can create "GUI independent" widgets. This means the program's look and feel can be switched at runtime (for example, from Motif to OpenLook) simply by the end-user specifying a different location for the loading of the WidgetKit's implementation code. (The default is to load a Motif implementatation.) In Fresco, such implemenation specific code is dynamically loaded at runtime.
Fresco provides a number of Kits. The LayoutKit provides objects that can compose and align glyphs. Hboxes, for example, come from the LayoutKit. The DrawingKit provides immediate mode, resolution independent drawing objects. The FigureKit provides 2D structured graphics objects. Finally, as explained above, the WidgetKit provides GUI-independent widgets.
Notice in the listing the use of the "_var" variables such as FigureKit_var. These are "smart pointers". Their purpose is to simplify life for the programmer by automating memory management. Specifically, when a smart pointer goes out of scope (at the end of a function call, for example), its destructor will automatically release the object reference.
Fresco's IDL to C++ translator ix generates smart pointers for each interface specified in IDL. Note that, since the FrescoContext retuned on line 5 is not defined in IDL, it does not have a smart pointer defined for it. Therefore the programmer must explicitly release the FrescoContext object. This is done on line 13.
On line 12, a new label glyph is passed to the run() operation which will enter into an event handling loop. Run() takes two arguments. The first is a Fresco viewer object. Again, viewers are glyphs responsible for handling input. Since the hello world program does not deal with input, we simply pass nil. The second argument is a glyph to be displayed on the screen. Of course, this glyph can be the root of an arbitrarily complex structure, but in this case it just is a simple label.
Generated with CERN WebMaker