Using Markers (XForms (Forms Library) - Version 1.2 (Rev. 4) A Graphical User Interface Toolkit for X)

Next: Pixelizing the Annotation, Previous: Using Text Strings, Up: Image Annotation [Contents][Index]

#### 37.7.9.2 Using Markers

In addition to text strings you can also add simple markers (arrows, circles etc) to your image.

To add a marker to an image use the following routines

    int flimage_add_marker(FL_IMAGE *im, const char *name,
                           double x, double y, double w, double h,
                           int linestyle, int fill, int rotation,
                           FL_COLOR, FL_COLOR bcol);
    int flimage_add_marker_struct(FL_IMAGE *im, const FLIMAGE_MARKER *m);

where `name` is the marker name (see below for a list of built-in markers). The marker name must consist of regular ASCII characters. `linestyle` indicates the line style (`FL_SOLID`, `FL DOT` etc., see Chapter 27 for a complete list. `fill` indicates if the marker should be filled or not. `x` and `y` are the coordinates of the center of the marker in physical coordinates (i.e., the same transformation as described above for annotated texts is applied), `w` and `h` are the size of the bounding box of the marker, again in physical coordinates. Every marker has a natural orientation from which you can rotate it. The angle of rotation is given by `rotation` in tenth of a degree. `col` is the color of the marker, in packed RGB format. `bcol` is currently un-used.

The second function takes a structure that specifies the marker. The members of the structure are as follows:

`name`

  The name of the marker.

`x, y`

  Position of center of the marker in pixel coordinates, relative to the origin of the image.

`w, h`

  The size of the bounding box in pixel coordinates.

`color`

  The color of the marker in packed RGB format.

`fill`

  If true the marker is filled.

`thickness`

  The line line thickness used for drawing.

`style`

  The line style to be used for drawing.

`angle`

  Angle of rotation in tenth of a degree from the marker’s nature orientation.

If successful both functions return the number of markers that are currently associated with the image, otherwise a negative number.

Some built-in markers in different orientations are shown in Fig. 22.1.

To delete all markers added to an image use the function

    void flimage_delete_all_markers(FL_IMAGE *im);

Of course the library would not be complete without the ability for applications to define new markers. The following function is provided so you can define your own markers:

    int flimage_define_marker(const char *name,
                              void (*draw) (FLIMAGE_MARKER *marker),
                              const char *psdraw);

When the marker is to be drawn the function `draw()` is called with the marker structure. In addition to the fields listed above the following fields are filled by the library to facilitate the operation of drawing the marker

`display`

  The display to be drawn on.

`gc`

  The GC to be used in drawing

`win`

  The window to draw to.

`psdraw`

  A string that draws a marker in a square with the corner coordinates (-1, -1), (-1, 1), (1, 1) and (1, -1) in PostScript. For example the rectangle marker has the following `psdraw` string:

           -1 -1 moveto
           -1  1 lineto
            1  1 lineto
            1 -1 lineto
            closepath

Defining new markers is the preferred method of placing arbitary drawings onto an image as it works well with double-buffering and pixelization of the markers.

Next: Pixelizing the Annotation, Previous: Using Text Strings, Up: Image Annotation [Contents][Index]