Next: Color Handling, Up: Part IV Drawing Objects [Contents][Index]

### 28.1 General Remarks

An important aspect of a new object class (or a free object) is how to draw it. As indicated above this should happen when the event `FL_DRAW` is received by the object. The place and size, i.e., the bounding box, of the object are indicated by the object tructure fields `obj->x`, `obj->y`, `obj->w` and `obj->h`. Forms are drawn in the Forms Library default visual or the user requested visual, which could be any of the X supported visuals. Hence, preferably your classes should run well in all visuals. The Forms Library tries to hide as much as possible the information about graphics mode and, in general, using the built-in drawing routines is the best approach. Here are some details about graphics state in case such information is needed.

All state information is kept in a global structure of type `FL_State` and there is a total of six such structures, `fl_state[6]`, each for every visual class.

The structure contains among others the following members:

`XVisualInfo *xvinfo`

  Many properties of the current visual can be obtained from this member.

`int depth`

  The depth of the visual. Same as what you get from `xvinfo`.

`int vclass`

  The visual class, `PseudoColor`, `TrueColor` etc.

`Colormap colormap`

  Current active colormap valid for the current visual for the entire Forms Library (except `FL_CANVAS`). You can allocate colors from this colormap, but you should never free it.

`Window trailblazer`

  This is a valid window resource ID created in the current visual with the colormap mentioned above. This member is useful if you have to call, before the form becomes active (thus does not have a window ID), some Xlib routines that require a valid window. A macro, `fl_default_window()`, is defined to return this member and use of the macro is encouraged.

`GC gc[16]`

  A total of 16 GCs appropriate for the current visual and depth. The first (`gc[0]`) is the default `GC` used by many internal routines and should be modified with care. It is a good idea to use only the top 8 `GC`s (8-15) for your free object so that future Forms Library extensions won’t interfere with your program. Since many internal drawing routines use the Forms Library’s default `GC` (`gc[0]`), it can change anytime whenever drawing occurs. Therefore, if you are using this GC for some of your own drawing routines make sure to always set the proper value before using it.

The currently active visual class (`TrueColor`, `PseudoColor` etc.) can be obtained by the following function/macro:

    int fl_get_form_vclass(FL_FORM *form);
    int fl_get_vclass(void);

The value returned can be used as an index into the array `fl_state` of `FL_State` structures. Note that `fl_get_vclass()` should only be used within a class/new object module where there can be no confusion what the "current" form is.

Other information about the graphics mode can be obtained by using visual class as an index into the `fl_state` structure array. For example, to print the current visual depth, code similar to the following can be used:

    int vmode = fl_get_vclass();
    printf("depth: %d\n", fl_state[vmode].depth);

Note that `fl_state[]` for indices other than the currently active visual class might not be valid. In almost all Xlib calls, the connection to the X server and current window ID are needed. The Forms Library comes with some utility functions/macros to facilitate easy utilization of Xlib calls. Since the current version of Forms Library only maintains a single connection, the global variable `fl_display` can be used where required. However, it is recommended that you use `fl_get_display()` or `FL_FormDisplay(Form *form)` instead since the function/macro version has the advantage that your program will remain compatible with future (possibly multi-connection) versions of the Forms Library.

There are a couple of ways to find out the "current" window ID, defined as the window ID the object receiving dispatcher’s messages like `FL_DRAW` etc. belongs to. If the object’s address is available, `FL_ObjWin(obj)` will suffice. Otherwise the function `fl_winget()` (see below) can be used.

There are other routines that might be useful:

    FL_FORM *fl_win_to_form(Window win);

This function takes a window ID win and returns the form the window belongs to or `None` on failure.

Next: Color Handling, Up: Part IV Drawing Objects [Contents][Index]