Building Applications - a Tutorial

Gamma/Photon: Using Gamma™ with the Photon microGUIŽ, Version 4.0
Prev |  | Next

# Chapter 4. Building Applications - a Tutorial

Here is a graduated tutorial that introduces some of the key features of Gamma, such as creating widgets, attaching callbacks, setting flags, and manipulating widget files for reuse. The programs and any associated widget files are in the examples/ directory. They are numbered t_01 through t_11, and are included in the `gamma_ph_`#`_examples_1_QNX4.tgz` file available on the Cogent Web Site. You can run them from the command line by using the command phgamma followed by the name of the tutorial. For example, type `phgamma t_04` to run Tutorial 4: Load a Window Created in PhAB.

# 4.1. Create a Window

    #!/usr/cogent/bin/phgamma

    /*
     * This example demonstrates how to create a Photon application in Gamma.
     * Since the Photon widget set is mapped as OOP classes in Gamma, any
     * Photon widget can be created using the 'new' function and then
     * manipulated by simply modifying its instance variables.
     *
     * This file is best viewed with a tab width of 4.
     *
     * First, we load some Photon Widget convenience functions to make our
     * job easier.  In this case, we are loading support for the SetDim,
     * SetPos and other functions which we use in this and later examples.
     */
    require_lisp("PhotonWidgets");

    /*
     * Initiate the graphics session with the Photon window manager.  This
     * must always be done before any Photon call can be made.
     */
    PtInit(nil);

    /*
     * Create a new instance of a PtWindow object.  You can look up PtWindow
     * in the Reference Manual, which is also linked to the online help for
     * Photon.  Gamma uses the same resources and constants as Photon widgets,
     * except that resource names are in lower case, and have the Pt_ARG_
     * prefix removed.  All constants are named identically to the ones named
     * in the Photon documentation.
     */
    window = new(PtWindow);

    /*
     * Set the width and height of the window.
     */
    window.SetDim(300,250);

    /*
     * Set the fill color of the window.
     */
    window.fill_color = PgRGB(240,220,220);

    /*
     * Realize the window widget on the screen.  A widget is not visible
     * until it has been explicitly realized, or until its container is
     * realized.
     */
    PtRealizeWidget(window);

    /*
     * Start an infinite event loop to handle Photon events. This keeps the
     * window open until the program exits (such as when Alt_F4 is pressed).
     */
    PtMainLoop();

Prev | Home | Next
A Few Precautions | Up | Add an Exit Button

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.