Using the GLG Widgets

In addition to the GLG Toolkit, which allows a user to build and operate elaborate animated drawings, GLG includes an extensive library of pre-built widgets that may be incorporated into a wide variety of applications. The complete list of these widgets is in The GLG Widget Library.

This chapter contains a general description of the categories of widgets in the library, and a review of some of the resource conventions in effect for those widgets. The input widget resources are listed in the sections below describing those widgets. The Graph Widget resources are described in GLG Widget Resource Sets.

Graph Widgets

Graph Widgets are used to display a collection of dynamically changing numerical data in a graphical form, like a bar graph, line graph, surface graph and others. Graph Widgets are animated in the same way as any other GLG drawing, by manipulating its resources.

Most of the graphs are available in both 2D and 3D versions. Some of them, like the surface graph, have only a three-dimensional version. For any graph, the 2D version is faster, takes less memory and intended for use with larger sets of data. The 3D version takes more memory and is slower, but in return it allows you to examine data in 3D space. For example, you can place several data sets in rows or look at them from different angles.

The graphs of the GLG Widget Library are all constructed using similar elements to represent graph components such as axes, ticks, labels, and data. A typical graph has a frame, data area, axes, grids, titles, minor and major ticks, major tick labels for each axis, a data group containing graph data samples, a group of level lines and a status object. See the figure below.

 
Components of a Graph

For convenience, these elements have identical names in all graphs, although some names may have added suffixes for certain cases. This means that editing any particular element is similar for all graphs.

The widgets in the GLG Widget Library are intended for use as templates. They may be used as they are, or easily edited with the GLG Graphics Builder to produce customized versions.

Naming Conventions

The names of resources play an important role since they are used to access objects inside a widget. There are a few naming conventions used for the Graph Widget components:

The names of the elements associated with an axis start with the name of the axis, like XLabel .

The name of a template of a series object does not have any numerical suffix, like DataGroup .

The names of the created instances of the template in a series object have a numerical suffix corresponding to the sequential number of the instance, like DataGroup3 . As with all GLG indexes, the index is based at zero, so DataGroup3 is actually the fourth object in a series.

In the case of nested groups or series objects, the names of outer objects are formed by adding a numerical suffix to the name of the bottom level composite object. This suffix indicates the level of the hierarchy and is spelled out as a word. For example, if there are two levels of series objects and the name of the inner series is DataGroup , the name of the outer series is DataGroupOne . If that series were itself the template for a third series, that third level would be called DataGroupTwo , and so on. Since the inner series is used as a template by the outer series, there are also copies of the DataGroup template in the DataGroupOne series. The final hierarchy and the corresponding names look like this:

DataGroupOne (series of series)
DataGroup (template)
DataGroup0 (copy)
DataGroup1 (copy)
...

 

Optimization

The update speed of a graph depends on the number and type of objects rendered on every update iteration. Deleting auxiliary elements of a graph such as grids, levels, a data area and a status object can substantially increase the update speed.

In a simple graph, the tick and label elements may easily be responsible for two- thirds of the memory consumed by the graph. If you have large sets of data, you may delete unnecessary elements or decrease major and minor ticks factors to minimize the number of objects in the graph. This reduces the amount of memory used by the graph and increases its update speed.

In the case of a graph with a large number of data samples, you can also reduce the computing demands made by reducing the number of times you update the graph. Instead of updating the graph each time a new data point is written, you can try updating after each second or third or more point is written.

Data Samples and the Data Group

Data samples are objects used by a graph to display its data. The type of object used as a data sample may be different depending on the type of the graph. For example, a data sample in a bar graph is represented by a polygon whose height changes with the value of the data value displayed. For a line graph, the data value is represented by the position (usually just the Y-coordinate) of a point on the line.

The method used to create multiple instances of a data sample object depends on the type of the graph as well. For example, a series object is used to create multiple instances of a data sample object for graphs like a bar chart or a pyramid graph. For a line graph, a polyline object is used, and for a surface graph a polysurface object renders the surface. Whatever the variety of composite object, such a collection of data samples is called a data group , and these are identified with the DataGroup resource.

If a series object is used to produce multiple copies of data samples, a template of the series object is usually named DataSample. The names of the created copies are formed by adding a consecutive digital index of the copy to the name of the template: DataSample0, DataSample1, and so on.

The type of object used as a data sample depends on the type of the graph. However, there are three resources present no matter the type of object. These are:

Value

The value to be represented by the data sample object. Changes made to this resource are not permanent, and will revert to an initial value when the graph is reset. To make Value resource changes permanent, explode the DataGroup object with the GLG Graphics Builder. The value of this resource for the template object is the initial value of the series members. The graph always works in a linear coordinate system. If data has to be displayed in the logarithmic format, it must be converted to the logarithmic scale before setting the Value resource.

Low and High

These resources define the range of data displayed by the graph. Data sample shapes that extend beyond these limits may be clipped. The default values are 0 and 1, respectively. These resources may be changed dynamically without losing data currently displayed in a graph. In this case the graphical attributes of data samples are automatically recalculated to display current data in the new range. This allows the application program to change the range of the data when the amplitude of the data increases (or decreases) beyond the current graph's data range. It also allows the program to scale data samples when the values get too small.

Whether part of a series or a polyline, or some other composite object, the data sample objects displayed in a typical graph are dynamically created objects whose attributes are inherited from some template object. As with any series object, changes to the template instances are not permanent, and last only until the drawing is reset or reloaded. However, you can use the GLG Graphics Builder to explode a datagroup object. This will turn a series of dynamically created objects into a group of static objects. The attributes of the static objects may then be edited, and these changes will be permanent.

Constrained Attributes Of Data Samples

In some graphs, some attributes of the data samples are constrained to have values corresponding to the value of the data sample. For example, the fill color of the bars in a bar graph may change according to the height of the bar, so that the bigger the height of the bar, the brighter the color. In this case, the fill color is the subject of a complicated set of constraints, so that directly changing the FillColor attribute does not yield the desired results.

In the graphs where a FillColor attribute is constrained, two resources are provided to define the color range: StartColor and EndColor. Together with the FillColor attribute, they define the range of colors for a data sample object. When the Value of the data sample is at the lower limit of the graph, its color is that specified by StartColor , while it takes the EndColor when the Value resource is at the upper limit of the graph. For values in between the two, the color is derived by linear interpolation between the two extremes.

Note: In order for the results to be intelligible, the StartColor resource should be set to the same value as the FillColor attribute.

If the start and the end colors are of the same hue, dithering patterns are used to provide more colors. This feature may be disabled by setting the number of dithering patterns to 1 for the graph's viewport (use pattern factor equal to 0).

On an 8-bit color machine, the number of color gradations is usually small if the start and end color do not have the same hue. You can, however, change the parameters of a colortable for the viewport to be different from the default one, providing more hues and less shades. This increases the number of color gradations available for coloring the bars.

To disable color constraints, set the StartColor and the EndColor resources to the same color. This prevents color from being dependent on the data sample value and allows colors of the bars to be set directly.

Nested Data Groups

Several kinds of graphs contain data groups whose elements are themselves composite objects. For example, a line graph with multiple lines or a 3D bar graph with several rows of bars. There are also the packed bar graphs that contain several copies of graph "packs," each of which contain several data samples.

Different standards obtain for naming nested data groups, depending on the style of graph in question. The series object used to create multiple copies of data groups in one data area is usually named DataGroupOne and its template is named DataGroup. The produced instances of a data group have names DataGroup0, DataGroup1, and so on.

In some graphs, such as the packed or stacked bar graphs, the first (inner) series object, named Pack , is used to produce the necessary number of bars in one pack. The second series object, named DataGroup , is used to reproduce the desired number of packs in the graph, which are called Pack0 , Pack1 , and so on.

In the case of nested data groups like these, either series object or both of them may be exploded with the GLG Graphics Builder to customize the graph. For example, in a packed bar graph, it may be desirable to have the corresponding bars in every pack identified by a different value of some attribute. Perhaps the first bar of every pack should be yellow, the second one should be green and so on. In order to do this, the Pack series object on the lower level has to be exploded in the Builder.

In this case, choose the desired number of bars in the pack, set the Global attribute of the FillColor attribute of the template bar to LOCAL to allow bars to have different colors in the exploded pack, then explode the Pack series object. Now for every bar in the exploded pack set the Global flag of its FillColor attribute back to GLOBAL and set the attribute to the desired color. (Remember to edit the template pack object rather than the copies.) Since the Global flag of the FillColor attribute of every bar in the pack is set to GLOBAL, the colors of corresponding bars in all packs are constrained to have the same value that you have just defined. If you change the color of one bar, all corresponding bars change.

Data Area

The Data Area is a polygon used as a background for 2D graphs. It allows you to paint the area behind data samples a color different from the background color of the viewport. In 3D versions of the graphs there are several data areas, representing the three planes of the graph's frame.

By selecting the Data Area polygon and editing it you may change its fill color, border color and border width. You may also change the geometry of the whole graph by moving control points of the Data Area. The Data Area is a parallelogram object, and has three control points.

If the Data Area parallelogram is changed to be not rectangular, the graph is distorted accordingly, displaying its samples under the angle defined by the sides of the Data Area. This can be used to create special effects.

Like any parallelogram object, the three unconstrained control points of the Data Area may be named and then accessed as resources. This gives you the ability to change the geometry of the graph dynamically from a program. Changing the geometry does not destroy data currently displayed in the graph.

Optimization

In simple graphs like a line graph or a bar graph, the Data Area may be responsible for reducing the update speed by more than a half. Eliminate the Data Area polygon if you have strict performance requirements.

Axes

An axis of a graph is just a polygon. Axes are named by the corresponding coordinate: XAxis, YAxis and ZAxis (for 3D graphs).

Some graphs, like a line graph with multiple variables, may have multiple vertical axes. In this case, an axis with a set of labels and ticks are kept in the group named YAxisGroup. This group is used as a template in the series object named YAxisGroupOne, which contains multiple copies of the axis group, called YAxisGroup0, YAxisGroup1, and so on.

To change the number of axes, change the value of the Factor attribute of the YAxisGroupOne series object. To edit attributes of all axes, edit the YAxisGroup template.

Major And Minor Ticks

A major tick is represented by a polygon object named XMajorTick for an X axis. Major ticks for Y and Z axes are named YMajorTick or ZMajorTick. Everything described below in this chapter for the X axis ticks is also applicable to the ticks on Y and Z axes.

The XMajorTick polygon is used as a template for the XMajorGroup series object to produce multiple copies of a major tick. The number of ticks is defined by the factor of the series object, and their appearance is defined by the series object template.

A minor tick is represented by a polygon named XMinorTick. The graphs use two nested series objects to produce all the minor ticks on an axis. The inner series object, named XMinorGroup, produces the necessary number of minor ticks between any pair of major ticks. The series object on the second level, named XMinorGroupOne, is used to reproduce that interval between all pairs of major ticks.

To change the number of minor ticks per major tick, change the factor of the XMinorGroup series object on the lower level. The factor of the outer XMinorGroupOne series is constrained to have the same value as the factor attribute of the major tick series.

For convenience, the factor attribute of the XMinorGroup object is also constrained to the MinorFactor resource of the major tick series.

The factor attributes of the grid and axis label series are constrained to have the same value as the factor of the major tick series. The number of data samples in the graph is not so constrained.

Optimization

Since ticks are an expensive resource, keep number of them at a necessary minimum. In general, the total number of X minor ticks should be smaller or equal to the number of data samples in the graph. In any case, the total number of minor ticks should be a factor of the number of the graph's data samples, otherwise data samples and minor ticks are misaligned. The same is true for the major ticks as well.

Logarithmic Ticks

Ticks can be displayed on a logarithmic scale if you want to display logarithmic data. In this case only minor ticks are drawn with uneven intervals. Major ticks are still drawn evenly, since they correspond to the integer powers of the logarithm base. It is the responsibility of the program or the process supplying data to provide logarithmic data sample values.

To make minor ticks logarithmic, set the LogType attribute of the lower level series object of Y minor ticks (YMinorGroup) to LOG. The factor of this series should be set to a value of the base of the logarithm minus 1. For example, for the logarithm base ten, the factor should be set to nine.

Grid Lines

The background grid lines in a GLG Graph are rendered as polygons named XGrid and YGrid. Series objects named XGridGroup and YGridGroup are used to produce the necessary number of grid lines. The factors of the series objects are constrained to have the same value as the number of major ticks on the corresponding axis.

Labels

Axis labels to be displayed at each major tick are represented by text objects named XLabel, YLabel and ZLabel. These text objects are used as templates for the series objects named XLabelGroup, YLabelGroup and ZLabelGroup, which produce the desired number of labels for the corresponding axis. Each label is positioned at the corresponding major tick. The values of the Factor attribute of each label series are constrained to have the same value as the number of major ticks on the corresponding axis. As with any other series, every individual label may be accessed with the index of the label as a suffix. For example, XLabelGroup/XLabel3 accesses the fourth label on the X axis (since the index is zero-based). The changes to the attributes of individual labels are volatile and disappear after resetting or reloading the drawing. To assign custom text strings to the labels permanently, the label series object can be exploded with the GLG Graphics Builder.

The font for a label can be changed by editing the series Font attribute in the same way as any other attribute. Changes to the series template will change the font used to display all the labels in the series, while changes to the attribute for any particular instance of the series template will affect only that copy.

If the type of the text object template for a label series is SCALED, the Global flag of the SizeConstraint attribute of the template text object controls whether or not all axis labels are displayed in one font size when labels have different length.

If the Global flag is set to LOCAL for the template label, label text strings are fitted into their boxes individually and may be displayed in different font sizes if labels have different length. If the flag is set to GLOBAL, fitting the text of one label into the corresponding box affects all other labels. It means that if the text of a label does not fit into its box, a font of the smaller size is chosen for that label. This change of a font size affects all labels on the axis, so that all of them are displayed in this smaller font size. After the conditions that caused the change of the labels' font size are eliminated, the labels stay in their current small font size until the viewport is resized or reset.

Constrained Labels and the Format Resource

Some labels, like those on the value axis (the Y axis for most of the graphs), are constrained to the values associated with the corresponding major ticks. The strings for the labels are supplied automatically depending on the graph's data range and the factor of major ticks.

For example, if the data range of the graph is [0,1] and the graph has six major ticks (the factor of major ticks is 5), then the strings displayed in the labels are"0.0", "0.2", "0.4", "0.6", "0.8" and "1.0".

The text string of a constrained label is not controlled with the TextString attribute, but with the text object's Format resource. Changing the TextString attribute of such a label does not affect the string displayed, since it is constrained. The Format resource defines a C-style format used to display a label's data value. The format string should have no more than one conversion specification requiring an argument. This conversion specification should take a double-precision value as an argument, therefore only f, g and e format specifications are allowed. The conversion specification is optional, and may be omitted, allowing you to use the Format resource to replace the label string.

For example, to specify that all labels in the label series show two digits of precision, change the Format resource of the series template to " %.2f ". The Format resource is a character string where the `%' character has a special meaning, so you may also set it to strings like " Value=%.2f ". In this case, the " %.2f " will be replaced with the label value when the label is displayed. You can omit the conversion specification entirely, so that changing the label's format string to "Level 1" simply displays "Level 1" in the label. If you want to display a "%" character in the string, use "%%" in its place. Refer to any C compiler documentation for a complete explanation of string formatting capabilities.

If you want to disable automatic labelling, make sure that the value of the Global flag of the Format resource of the template label is set to LOCAL. You may also have to use the GLG Graphics Builder to explode the label series to avoid having the changes discarded by the next drawing reset.

Attention: Be careful defining C format for the format string. The GLG Toolkit does not check the format for validity before displaying a drawing. Any entry is treated as a valid C format, in exactly the same way as any C program does. Defining the wrong format may cause unpredictable results.

Every constrained label has resources named Low and High that define the range used for labeling. These resources are constrained to have the same values as the low and high range resources of the graph. Changing these resources affects both the labeling range and the data range of the graph, rescaling currently displayed data and setting new label strings.

Scrolled And Wrapped Labels

While labels on a GLG Graph Widget's value axis are constrained, the labels on the time axis (X axis for most of the graphs) are not constrained. For most of the graphs, the XLabelGroup series is equipped with an entry point for convenience in setting graph labels. There are two methods of supplying strings for updating time axis labels.

The first method is to set the String attribute of the label directly using the name of the label text object. For example, XLabelGroup/XLabel3/String would be the resource name used to access the string of the fourth label on the X axis. Although straightforward, this method requires the application program to keep track of the current update position and to update labels differently depending on the scrolling behavior of the graph.

The second method is to use the EntryPoint resource of the label group. This method allows you to supply label strings without defining where to place them. This keeps the labels synchronous with the corresponding data samples.

The XLabelGroup/EntryPoint resource is used for updating X axis labels. Setting this resource to different values in a loop animates the X axis labels according to the graph scrolling behavior. Querying the value of the resource yields the last string used for updating.

The number of elements in a label series is constrained to be equal to the product of the number of major ticks on the axis and the number of minor ticks between a pair of major ticks. This is useful for applications that require the axis labels to scroll with the data sample values. This presents a problem because convention has it that labels are generally only displayed next to the major ticks.

GLG accommodates this convention by not displaying the label values that correspond to axis minor ticks. This means that if there is one minor tick between each pair of major ticks on an axis, only the odd-numbered labels are actually displayed. (If the axis does not have minor ticks or they were deleted, the MinorFactor resource of the major tick or label series defines the missing minor factor.) In general, if there are several minor ticks per one major tick (the minor tick factor of the axis is bigger than 1), then only every nth supplied value for the label is visible, where n is the factor of minor ticks. If this factor is equal to 1, then all supplied label values are visible.

The label series scrolling behavior is defined by the ScrollType resource of the XLabelGroup object and may have values SCROLLED or WRAPPED. If it is SCROLLED, all labels shift when updated and the new label appears at the entry point. If it is WRAPPED, only one label changes on every update, shifting the next update position to the next label in the series.

The ScrollType resource of labels is constrained to have the same value as the ScrollType resource of the DataGroup object of the graph. This ensures that the scrolling behavior of the labels is consistent with the scrolling behavior of the graph.

The Inversed resource of the XlabelGroup series controls the direction of scrolling. Setting this resource to YES reverses scrolling direction. Since this resource is constrained to the corresponding resource of the DataGroup object, changing the resource reverses the scrolling direction of the data samples as well as labels.

To use label entry points in a graph, refer to Graphs with Multiple Entry Points, below.

Graphs with Multiple Entry Points

While it is convenient to use series entry points to control multiple series in a graph, GLG contains no mechanism for synchronizing the data entered at two different entry points. This means that if your application requires labels that march along with the data entered from some external source, you must find some way to ensure that the right label is displayed with the right data value.

Axis Labels

Consider a simple bar graph where there is a minor tick on the X axis for each bar in the graph. To operate this graph properly, you must supply two pieces of data for every update iteration: the scalar value to be displayed and the character string with which to label it. The scalar value is used to set the DataGroup/EntryPoint resource, and the string is used to set the XLabelGroup/EntryPoint resource.

For this graph, the number of labels in the series is constrained to equal the number of minor ticks, which, for this example, happens to equal the number of data samples in the graph. Only the labels corresponding to the major ticks on the axis are actually displayed, however. The unseen labels cause the label values to shift if they are scrolled, or shift the update position without any visual change if labels are wrapped.

For scrolled graphs, the total number of minor ticks (the minor tick factor times the major tick factor) should be equal to the number of data samples. For wrapped graphs, the total number of minor ticks may be smaller than the number of data samples, but the total number of minor ticks should be an integer factor of the number of data samples in order for the graph's elements to be properly aligned. In this case, a value for the entry point of wrapped labels should be supplied only every nth update, where n is the number of data samples divided by the total number of minor ticks.

For example, if a graph has 100 data samples, 5 major ticks and 10 minor ticks per major tick on X axis, the total number of minor ticks is 50. The number of minor ticks is therefore half the number of data samples. Therefore a value for the label strings should be supplied for every other data sample.

This means that the sequence of the supplied data for the graph should look like:

data sample value,
data sample value,
label string value,
data sample value,
data sample value,
label string value,
data sample value,
data sample value,
label string value,

and so on.

If the axis does not have minor ticks or they were deleted, the MinorFactor resource of the major ticks' or labels' series defines the missing minor factor.

Nested Data Groups

There are also cases where a single tick on an axis might correspond to more than one data sample. For example, a graph may have multiple data groups, like a line graph with multiple lines or a 3D bar graph with several rows of bars. The total number of data samples for such a graph is equal to the number of data samples in one data group multiplied by the number of data groups.

Another example is a packed or stacked bar graph, where one pack may contain several data samples. In these graphs, one minor tick corresponds to several data samples of one pack, and the total number of data samples is equal to the number of packs multiplied by the number of bars in one pack.

Again, because GLG provides no general mechanism to synchronize two series values, you must be careful to provide synchronized data to the Graph Widget. That is to say, for graphs like these, the values for the corresponding data samples of all lines or all bars of one pack should be supplied during one update iteration, otherwise lines or packs will be out of sync.

Level Objects

In addition to grids, many of the GLG graphs have level objects . These are horizontal lines usually used to mark some special thresholds in the graph. While grid lines are always positioned automatically on the levels defined by the major ticks, level objects may be positioned arbitrarily.

A level object is represented by a polygon named LevelObject and placed inside a LevelObjectGroup series object to produce several copies of the level object. A factor of this series defines the number of level objects created. Each level object has a Value resource, controlling its position, or level.

Attributes of polygons representing every level line may be changed to distinguish different levels. As with all series, the Global flags of attributes to be changed must be set to LOCAL, otherwise all level objects are affected. The level's series object may be exploded with the GLG Graphics Builder to make the changes permanent.

Remember to delete level objects in the customized version of the graph if they are not used.

Status Object

Several graphs have a status object , indicated with the StatusObject resource. This object is used only for graphs with the WRAPPED scrolling type. It is a graphical shape, used to indicate the position of the last updated data sample. It moves after every update to the next data sample, wrapping back to the starting position after reaching the last one. The status object may be any graphical object. The object's local origin is aligned with the point on the axis corresponding to the data sample.

A status object may be deleted if not used. When a graph is just loaded or after a reset, the position of the status object coincides with the Y axis (or with the X axis for graphs with vertical scrolling).

Titles

A few freely positioned titles are used to annotate a graph and its axes. The X and Y axis titles are named XAxisLabel and YAxisLabel , respectively. The graph's title text object is named Title . A title's position, as well as direction, text string, and other attributes may be changed by moving control points or editing attributes of the text object indicated by the resource name. An unlimited number of additional titles may be created in the GLG Graphics Builder by creating new text objects and positioning them.

Optional Legends

The GLG Graph Widget set contains a set of optional legends that can be used to annotate graphs with multiple data sets, such as a line graph with multiple lines. Every legend item shows the name of the entity displayed by the corresponding data set and also the color or line attributes used to annotate it.

A legend consist of a series object named LegendGroup used to create multiple copies of a legend template. The legend template is made of a group named Legend . It contains a text object named LegendLabel and two polygons named LegendBox and LegendLine . Two marker objects named LegendMarker1 and LegendMarker2 are constrained to the ends of the LegendLine polygon.

The text object is used to name entities in the graph. The polygons are used to display the color, line width or line type associated with a particular entity. Choose which polygon, a box or a line, you want to use and delete the other one from the template.

To change attributes of the individual legend elements to correspond to the entities displayed in the graph, the legend series object has to be exploded with the GLG Graphics Builder. Before exploding, set the number of legend elements and make sure the Global attribute is set to LOCAL for the attributes that are changed individually.

If you plan to change the number of legend elements dynamically from the program, don't explode the legend series. In this case the changes made to individual legend elements are not permanent, but the increased flexibility may be worth the extra trouble.

Some graphs have preinstalled legends. The number of legend elements in the preinstalled legend is constrained to the number of the data sets in the graph. These legends may be deleted if desired.

The legend object is kept in its own file called legend1.g . The legend viewport can be loaded into an existing graph using the GLG Graphics Builder. (When loading, make sure the viewport is loaded into the graph's viewport, not into the Drawing Area's viewport.) For convenience, the legend is placed in a viewport. This is not essential to the operation of the legend, and if you do not want to use the viewport, you may cut out the legend series object and paste it directly into the graph without a viewport, deleting the viewport afterwards.

3D viewing

3D Graph Widgets have a few resources designed to control the user's view of the graph in 3D space:

XAngle, YAngle, ZAngle

Control the rotation of the whole drawing around the specified axis.

ShearFactor, ShearX, ShearY

Controls a shear transformation that may be applied to the whole drawing. The ShearFactor defines the degree of shear, and is meant to take values between 0 and 1 (although other values may be used for special effects). The ShearX and ShearY attributes determine the proportion of the shear in the X and Y direction. These two attributes should add to 1.

To obtain the best effect, use either a rotate or shear transformation but not both, since they may interfere with each other. Most of the 3D graphs use the Shear viewing transformation by default. If you must add a rotation transformation to these graphs, make sure to start from the main view if you are using the Builder.

Input Widgets

The GLG Widget Library provides a wide selection of input widgets, with which an application can receive keyboard input from a user. Though they include several special features for the user's convenience, these widgets use the input handlers described in Input Objects of the GLG User's Guide and Builder Reference Manual. The general principles of constructing such a widget are also reviewed there.

Note that the input handler for an input widget manipulates several predetermined resources. Altering the names of these resources may render the widget inoperable, and may generate an error message when the drawing is reset.

Any input widget (a meter, for example) may be used for output as well to show the value of a resource. In this case you may disable or remove the widget's input handler. Disabling the handler causes the widget not to react to the input events. The handler may be enabled again later. Deleting the handler discards it, so that it can not be restored. Deleting the handler allows the special named objects to be removed from the widget's drawing without generating an error message.

The sections that follow provide descriptions of the input widgets and their use. Some of the widgets are distributed as separate units. Others, like the Menu and Text Widgets, are used as components of other widgets, like the Font Browser Widget. Included in each section is a list of the resources used by each style of widget. For other information about the input widgets, such as the contents of the message object passed to a callback routine, see the GLG User's Guide and Builder Reference Manual .

Meters, Dials and Avionics gauges

Most of the meters, dials and avionics gauges use the rotary axis and the Knob resource set described below. Some of the avionics gauges use two sets of needles and/or two sets of rotary axes. Most of the meters and dials are available in two versions; with a viewport and viewport-less.

The viewport-based version of a dial uses the GlgKnob input handler and may be used for both input and output (the needle can be moved with the mouse if the interaction handler is not disabled). It also creates a separate child window for each dial. The viewport-less version does not create a window associated with the dial and may be used as a non-rectangular dial on top of a custom background image. Most of the avionics dials provide only viewport-less version.

Rotary Axis

The rotary axis is a part of a variety of GLG dials, meters, knobs and rotary switches, as well as most of the avionics gauges. The rotary axis includes two components: the rotary axis (named Axis in the drawing) with labels, major and minor ticks, and the alarm sector (named AlarmSector), consisting of colored arcs indicating normal and abnormal range of values (this is commonly used in tachometers).

Axis Resources

Rotary axis contains the following resources that control its appearance:

AngleStart (DDATA): The start angle of the rotary axis.

Angle (DDATA): The angle between the start and end of the axis.

Center (GDATA): The axis' center position (may also be changed by moving the arc with the mouse).

High (DDATA): The high range of the axis' labels.

Low (DDATA): The low range of the axis' labels.

InnerBorder (ARC): The inner arc outline (drawn if Visibility=ON).

OuterBorder (ARC): The outer arc outline (drawn if Visibility=ON).

OuterCircle (ARC): A full circle drawn around the axis (drawn if Visibility=ON).

InnerRadius (DDATA): The inner radius of the axis' ticks.

OuterRadius (DDATA): The outer radius of the axis' ticks.

LabelRadius (DDATA): Controls the position of the axis' labels.

NumMajorTicks (DDATA): The number of major ticks.

NumMinorTicks (DDATA): The number of minor ticks.

NumLabels (DDATA): The number of labels.

MajorTick (POLYGON): The major tick template.

InnerOffset (DDATA): The offset between the inner radius and the inner end of the major tick, used to control the tick length.

OuterOffset (DDATA): The offset between the outer radius and the outer end of the major tick, used to control the tick length.

MinorTick (POLYGON): The minor tick template.

InnerOffset (DDATA): The offset between the inner radius and the inner end of the minor tick, used to control the tick length.

OuterOffset (DDATA): The offset between the outer radius and the outer end of the minor tick, used to control the tick length.

TickLabel (TEXT): The label template.

Format (SDATA): The C-style label format.

Alarm Sector Resources

Visibility (DDATA): Controls the visibility of the alarm sector.

AngleStart (DDATA): The start angle of the alarm sector.

AngleEnd (DDATA): The end angle of the alarm sector.

BgColor (GDATA) The background color of the alarm sector; is usually constrained to the background color of the dial.

Center (GDATA): The alarm sector's center position (may also be changed by moving the arc with the mouse).

InnerRadius (DDATA): The inner radius of the alarm sector.

OuterRadius (DDATA): The outer radius of the alarm sector.

NumAlarms (DDATA): The number of arcs in the alarm sector.

Colors (GROUP): A group of the alarm sector's colors.

Color<N> (GDATA): A color of the <N>th alarm sector.

High (DDATA): The high range of the thresholds. The default value is 100, allowing the specification of thresholds as percentages of the dial's range.

Low (DDATA): The low range of the thresholds. The default value is 0.

Thresholds (GROUP): A group of the alarm sector's thresholds.

Value<N> (DDATA): A thresholds of <N>th alarm sector. Controls's the <N>th alarm sector's angle, the range of the values must match the High and Low range of the thresholds.

Slider

A Slider Widget converts a linear mouse position into one or two scalar values, and provides some appropriate visual feedback by moving its active element. When the left mouse button is pressed over the Slider Widget, the slider reacts by moving its active element to the mouse position. If the left mouse button is held down, the active element of the slider follows the mouse until the button is released.

There are several different versions of Slider Widgets in the GLG Widget Library, each with a different look and feel. There are also two-dimensional versions that control two variables, one corresponding to the X coordinate and the other corresponding to the Y coordinate. For one-dimensional sliders, there are horizontal and vertical versions of each slider.

The slider contains ValueX (for the horizontal slider) or ValueY (for the vertical slider) resource which contains the slider's value and is set by the slider each time its knob is moved. The two-dimensional slider contains both ValueX and ValueY resources, while horizontal and vertical sliders contain only one of them, depending on the slider direction. A native slider contains a Value resource instead of ValueX and ValueY.

An object called ActiveElement provides a visual feedback for the current slider value. The range of positions of the active element is associated with the range of the slider values, defined by the Low and High resources of the slider. Some sliders also have an indicator showing the current slider value in digital form.

A slider may also be used for output. When the slider's ValueX, ValueY or Value resources are set, the slider positions its active element to show the new value. If the widget will only be used for output, you may decide to delete or disable the input handler of the widget's viewport, although this is not necessary.

Resources

These are the resources you are likely to see in a Slider Widget's hierarchy. Note that while the ValueX and ValueY resources are optional, the slider widget must contain at least one of them. A native slider widget contains the Value resource instead of ValueX and ValueY.

ValueX (DDATA, optional): The slider's X value.

OutValueX (DDATA, optional): The slider's X output value. It can be used to constrain other objects to this resource.

LowX (DDATA, optional): The lower limit of the slider's X value.

HighX (DDATA, optional): The upper limit of the slider's X value.

 

ValueY (DDATA, optional): The slider's Y value.

OutValueY (DDATA, optional): The slider's Y output value. It can be used to constrain other objects to this attribute.

LowY (DDATA, optional): The lower limit of the slider's Y value

HighY (DDATA, optional): The upper limit of the slider's Y value.

 

Value (DDATA, optional): The native slider's input value.

OutValue (DDATA, optional): The native slider's X output value. It can be used to constrain other objects to this attribute.

LowX (DDATA, optional): The lower limit of the native slider's output value.

HighX (DDATA, optional): The upper limit of the native slider's output value.

 

Granularity (DDATA, optional): If this resource is present and set to a non-zero value, the slider is limited to this number of allowed positions.

DisableMotion (DDATA, optional): If this resource is present and set to a non-zero value. the slider's reaction to MotionNotify events is disabled.

Start (MARKER, optional): A marker placed at the lower limit of the slider's range.

XEnd (MARKER, optional): A marker placed at the upper limit of the slider's range of X values.

YEnd (MARKER, optional): A marker placed at the upper limit of the slider's range of Y values.

ActiveArea (POLYGON, optional): The screen cursor must be within this polygon for the slider to react to user input. This resource is not usually present in the default slider. Instead, the ActiveAreaSpare polygon (invisible by default) is defined. It may be renamed ActiveArea and positioned as desired to make only some area of the slider sensitive to mouse events.

Plane (POLYGON, optional): The slider pointer slides on the plane defined with this polygon. The points of the polygon must be coplanar.

A slider may also have buttons. A user may click on these buttons to move the slider pointer the distance specified by the Increment resource in some direction. The buttons have these names:

Increase (VIEWPORT, optional): An "increase" button for a one-dimensional slider.

Decrease (VIEWPORT, optional): A "decrease" button for a one-dimensional slider.

Left (VIEWPORT, optional): A directional button for a two-dimensional slider.

Right (VIEWPORT, optional): A directional button for a two-dimensional slider.

Up (VIEWPORT, optional): A directional button for a two-dimensional slider.

Down (VIEWPORT, optional): A directional button for a two-dimensional slider.

Increment (DDATA, optional): If the slider viewport contains motion buttons, each click of the button moves the slider by the amount specified by this resource. The value of the resource is between 0 and 1, and refers to a proportion of the total range of the slider. If this resource is not present, the default increment of motion is 0.1 times the total slider range.

Refer to GlgSlider on page 106 of the GLG User's Guide and Builder Reference Manual for information on other optional resources of the slider widgets.

Knob

A Knob Widget converts an angular mouse position into a value, providing visual feedback in the form of the angular position of the knob's active element. When the left mouse button is pressed over the Knob Widget, the knob reacts by moving its active element to the mouse position. If the left mouse button is held down, the active element of the knob follows the mouse until the button is released.

There are several different versions of Knob Widgets in the GLG Widget Library, each with a different look and feel. Each uses an object called ActiveElement to provide the visual feedback for the current knob value. The range of positions of the active element is associated with the range of the knob values, defined by the Low and High resources of the knob. Some knobs also have an indicator showing the current knob value in digital form.

A knob may also be used for output. When used this way, the widget converts a scalar values (specified with the Value resource) into the position of its active element. If the widget will only be used for output, you may decide to delete or disable the input handler of the widget's viewport, although this is not necessary.

Resources

Value (DDATA, mandatory): The knob's value.

OutValue (DDATA, optional): The knob's output value. It can be used to constrain other objects to this resource.

Low (DDATA, optional): The lower limit of the knob's value.

High (DDATA, optional): The upper limit of the knob's value.

Granularity (DDATA, optional): If this resource is present and set to a non-zero value, it specifies the number of allowed positions for the knob.

DisableMotion (DDATA, optional): If this resource is present and set to a non-zero value. the knob's reaction to MotionNotify events is disabled.

StartAngle (DDATA, optional): The Value resource is at its lower limit when the knob is at this angle.

EndAngle (DDATA, optional): The Value resource is at its upper limit when the knob is at this angle.

Center (MARKER, optional): A marker placed at the rotation center of the knob.

ActiveArea (POLYGON, optional): The screen cursor must be within this polygon for the knob to react to user input. This resource is not usually present in the default knob. Instead, the ActiveAreaSpare polygon (invisible by default) is defined. It may be renamed ActiveArea and positioned as desired to make only some area of the knob sensitive to mouse events.

Plane (POLYGON, optional): The knob pointer slides on the plane defined with this polygon. The points of the polygon must be coplanar.

A Knob Widget may also have control buttons. A user may click on these buttons to move the knob pointer a preset distance in some direction. The buttons have these names:

Increase (VIEWPORT, optional): An "increase" button for a knob.

Decrease (VIEWPORT, optional): A "decrease" button for a knob.

Increment (DDATA, optional): If the knob viewport contains control buttons, each click of the button moves the knob by the amount specified by this resource. The value of the resource is between 0 and 1, and refers to a proportion of the total range of the knob. If this resource is not present, the default increment of motion is 0.1 times the total knob range.

Refer to GlgKnob on page 109 of the GLG User's Guide and Builder Reference Manual for information on other optional resources of the knob widgets.

Button

A Button Widget is a widget activated with a mouse press. Buttons can be push buttons that produce some action when they are pushed, but do not have a "state," or toggle buttons , that have an internal state. The type and behavior of different buttons are based on the resources present in the button's viewport.

Similar to the optional bevels described in the Graph Widgets, a button's viewport may have a colortable with fewer hues, more intensities and no dithering patterns to facilitate better shading. Shading is controlled by the lighting attributes of the viewport.

Resources

OnState (DDATA, optional): The toggle state of the button. Buttons with this resource are toggle buttons. If the resource is not present, they are push buttons. If present, this resource may be 0 or 1. A toggle button will usually use this resource to create some indicator showing its state.

InState (DDATA, optional): This resource is 1 when the mouse cursor is on the button, and 0 otherwise. A button can use this resource to change some attribute when the mouse cursor enters the button viewport.

PressedState (DDATA, optional): This resource is 1 when the mouse cursor is on the button and the mouse button is depressed.

LabelString (SDATA, optional): The label for the button. This resource is used when the button is on a menu, and allows a button's label to be changed from a program.

TokenValue (DDATA, optional): The button's value. This resource is used when the button is on a menu.

ActOnPress (DDATA, optional): If this resource is present and non-zero, the button state will change with the down-click of the mouse button. Otherwise, the state changes with the up-click. This resource cannot be changed dynamically; the drawing must be reset to update it.

PressedLightCoeff (DDATA, optional): This value is added to the button's ambient light coefficient. It is used to control how much darker the button becomes when pressed.

BevelSize (DDATA, optional): Specifies the width of the bevels, if there are any. The width is given in numbers of pixels.

Refer to GlgButton on page 111 of the GLG User's Guide and Builder Reference Manual for information on other optional resources of the button widgets.

Menu

A Menu Widget is an array of button widgets. The Menu manages the buttons, allowing the application to manage the array of buttons as a single object. The use of the GlgMenu input handler is described on page 118 of the GLG User's Guide and Builder Reference Manual .

Resources

Button <n> (VIEWPORT): These are the buttons on the menu. The <n> is a zero-based index. A menu must contain at least one button.

ScrollObject (VIEWPORT, optional): The menu scroll bar. Scrolling is enabled when the menu is used as a part of some kind of browser or if the LabelList object is defined with the number of labels bigger than the number of buttons in the menu.

SelectedIndex (DDATA, optional): The index of the last selected button.

SelectedString (SDATA, optional): The label of the last selected button.

SelectedValue (DDATA, optional): The value of the last selected button.

LabelList (GROUP, optional): A list of objects. These can be of any type, and any name. Each object in this list should contain a string resource called LabelString , which is the text that will be used to represent that object in the displayed list. This resource may not be modified dynamically. The drawing must be reset after each change to the LabelList .

HighlightLabel (TEXT, optional): A text object defining the appearance of a highlighted label. This resource is used when the menu is part of the font or file browser.

RegularLabel (TEXT, optional): A text object defining the appearance of a regular label. This resource is used when the menu is part of the font or file browser.

Refer to GlgMenu on page 118 of the GLG User's Guide and Builder Reference Manual for information on other optional resources of the menu widgets.

Text

A Text Widget is used for entering a text string. There are versions of the text widget for entering numerical values, both integer and floating point.

Resources

TextString (SDATA, optional): The current value of the text string entered.

 

The following resources are present only in the numerical version of the text widget:

Value (DDATA): The current value.

MinValue (DDATA, optional): The minimum value.

MaxValue (DDATA, optional): The maximum value.

ValueFormat (SDATA, optional): The C-style format for displaying the value.

InputInvalid (DDATA): Displays the status of input parsing.

Refer to GlgNText on page 113 of the GLG User's Guide and Builder Reference Manual for information on other optional resources of the text widgets.

Spinner

A Spinner Widget is used for entering a numerical value using arrows to increase or decrease it. An optional slider may be used for changing the value with the mouse.

Resources

Value (DDATA): The spinner's value.

MinValue (DDATA, optional): The minimum allowed value.

MaxValue (DDATA, optional): The maximum allowed value.

Increment (DDATA, optional): The value increment.

PageIncrement (DDATA, optional): The value page increment.

Wrap (DDATA, optional): Enables wrap mode.

IncreaseKeys (SDATA, optional): Lists keyboard accelerators for increasing the value.

DecreaseKeys (SDATA, optional): Lists keyboard accelerators for decreasing the value.

TextInput (VIEWPORT, optional): A text input viewport for entering the value.

Increase (VIEWPORT, optional): An optional button for increasing the value by Increment.

Decrease (VIEWPORT, optional): An optional button for decreasing the value by Increment.

PageIncrease (VIEWPORT, optional): An optional button for increasing the value by PageIncrement.

PageDecrease (VIEWPORT, optional): An optional button for decreasing the value by PageIncrement.

Slider (VIEWPORT, optional): An optional slider for changing the value with the mouse.

List and Option Menu

The List and Option Menu widgets provide access to the corresponding native list and option menu or combo box widgets. Refer to the corresponding chapters on page 115 and page 117 of the GLG User's Guide and Builder Reference Manual for information on the resources of these widgets.

Clock and Stopwatch

The Clock and Stopwatch Widgets display the current time or elapsed time. Both widgets use the same input handler, The handler takes care of updating the time and reacting to the input events for the stopwatch. The Clock Widget continues updating even while being edited.

The Clock Widget does not react to input events from a user and serves to display the current time only. If the TimerState resource is present, the clock measures elapsed time instead of real time, and the widget becomes a stopwatch. The Stopwatch Widget can receive input through three buttons contained in the clock viewport.

If the input handler of the Clock Widget is deleted or disabled, the widget may be used to display user-defined time under control of an application program. In this case the application program uses the widget resources to drive the clock.

The hands and other elements of the widgets may be edited the same way as any other object.

Resources

Hour (DDATA, optional): The number of hours. (0-11)

Min (DDATA, optional): The number of minutes. (0-59)

Sec (DDATA, optional): The number of seconds. (0-59)

ValueHour (DDATA, optional): The scaled hour value. This is a value between 0 and 1, and is provided to simplify the positioning of clock hands.

ValueMin (DDATA, optional): The scaled minute value. This is a value between 0 and 1, and is provided to simplify the positioning of clock hands.

ValueSec (DDATA, optional): The scaled second value. This is a value between 0 and 1, and is provided to simplify the positioning of clock hands.

HourLabel (TEXT, optional): A title for the hour display.

MinLabel (TEXT, optional): A title for the minute display.

SecLabel (TEXT, optional): A title for the second display.

TimeString (SDATA, optional): A string describing the time in the "00:00" format.

The following resources are used for stopwatches.

TimerState (DDATA, optional): If this resource is present, the Clock Widget measures elapsed time. When the resource is 0, the clock is stopped, and when it is 1, the clock is running.

Start (VIEWPORT, optional): If a button with this name is present within the clock viewport, pressing it will cause the stopwatch to start.

Stop (VIEWPORT, optional): If a button with this name is present within the clock viewport, pressing it will cause the stopwatch to stop.

Reset (VIEWPORT, optional): If a button with this name is present within the clock viewport, pressing it will cause the stopwatch to reset to zero.

Palette

A Palette Widget is used for creating different palettes with which to present a user with choices of objects. The Palette Widget was created to help a user choose colors, but it can be used to choose one from any selection of objects. This widget is designed to be used within a program using the GLG API.

A palette contains a single resource, an object named PaletteObject . This is a group or series object that contains several objects, each corresponding to a different possible choice. The user selects one of the presented objects with the left mouse button, and the choice is returned to the calling program in the callback message object.

For more information about callbacks and message objects, see the GLG User's Guide and Builder Reference Manual .

Resources

PaletteObject (ANY OBJECT): An object displaying the set of choices.

SelectedObject (ANY OBJECT, message only): The selected object. This resource does not appear in the drawing resource hierarchy, but is passed to the user-supplied callback function inside the message object.

Font Browser

The Font Browser Widget is used to facilitate the font selection from the list of all fonts available for the X server used to display the widget. The Font Browser, in turn, uses other widgets such as Menu, Text and Slider as its components. The Font Browser Widget is not available on MS-Windows.

Note that buttons may have labels different from their names.

Resources

The FontSampleName , Filter , FieldMenu , Done , Cancel and Restore components are optional, the rest of the named components are mandatory parts of the Font Browser.

FontName (VIEWPORT): A text widget for entering and displaying the current font name selection.

Filter (VIEWPORT, optional): A text widget for entering and displaying the current value of the filter string. Only fonts that match the filter string are displayed in the selection menu.

FontSampleName (SDATA, optional): The name of the selected font.

Menu (VIEWPORT): A menu widget displaying a choice of font names or choices of font fields while editing a filter.

FieldMenu (VIEWPORT, optional): A menu widget for constructing the filter. Clicking one of the buttons shows a list of the available options for that particular field.

FontSample (VIEWPORT, optional): A viewport with a text object in it to display sample text using the selected font.

FontSampleName (SDATA, optional): The name of the selected font.

Done (VIEWPORT, optional): A button for accepting the selection. This button is used to generate an "Activate" message when the font selection is finished.

Cancel (VIEWPORT, optional): A button for cancelling the selection. This button is used to generate a "Cancel" message to indicate the user's desire to cancel the font selection process without making a selection.

Reset (VIEWPORT, optional): A button to reset the filter.

Process Control Objects

The process control symbols palettes provide the user with an easy way to create process control drawings by simply selecting the pre-built objects from a palette. Most of the objects have a built-in dynamic behavior to be used for displaying values or animation.

The resource named Value is the main dynamic resource of these objects. For example, setting the Value of a tank object to a value in the range from 0 to 1 changes the level of the tank's filling. For a valve object, the Value resource controls its opening. For fans, pumps and other dynamic equipment, changing the Value resource from 0 to 1 in small increments animates the piece of equipment.

The objects may also have other resources to control their appearance:

ForegroundColor and BackgroundColor control objects' colors.

OpenColor and CloseColor control the colors of valves.

ColorIndex controls the displayed color of various indicator objects, and Color0, Color1, ... ColorN resources define available colors.

LineWidth controls the line width of lines used to render the object.

Units controls the unit label string used by various indicator objects.

Format controls the C format used to display the object's numerical value.

The process control objects also include connector-style objects such as various pipes and lines. While most of the objects are like nodes with just one control point, the connector-style objects have two control points which may be used to define their shape. Some of the connectors have various elements replicated along the connector and have the NumElements and ElementSize resources to control the elements.

The Resource Browser may be used to list all resources of the selected process control object. Tags may be assigned to the resource names to facilitate connecting dynamic data to the objects. Refer to Using Tags on page 151 of the GLG User's Guide and Builder Reference Manual for more information about tags.