Example: Software Characters

The SWchars example is the program used to create the display showing all the software characters in the previous section. Its WM_CREATE handler calls fg_initw() to initialize the default world space parameters; this is required since the software character drawing functions internally use world space coordinates. The call to fg_setworld() establishes a world space coordinate system with 0.01 world space units per virtual buffer pixel. Following this, fg_setsizew() defines the character height as 0.21 world space units, or 21 pixels. Note we could have instead used fg_setsize() here with an integer parameter of 21.

The next part of the WM_CREATE handler draws the characters in the primary font in the upper part of the virtual buffer. After doing this, it draws the alternate font characters beneath them. In each case it does this with fg_swchar(). By default, the string passed to fg_swchar() will produce characters from the primary font. However, you can insert a back slash character (\) in the string to toggle between the two fonts. Don't forget that C and C++ apply a special meaning to the back slash character within strings, so you must use two consecutive back slashes to insert a single back slash in the string.

In addition to the font change operator (the back slash character), fg_swchar() recognizes three other operators. The superscript operator is a back slash followed by a caret (\^). It causes the next character to appear as a superscript. Similarly, the subscript operator is a back slash followed by a lower case v (\v); it causes the next character to appear as a subscript. The size of superscripted and subscripted characters is one-half the height of the other characters. The underline operator is the underscore character (_). It causes all subsequent characters in the string to be underlined until another underscore character is found, or until the end of the string. When using these operators, be sure to include them as part of the string length count passed to fg_swchar(). The last part of our example's WM_CREATE handler illustrates to use of the font change, superscript, subscript, and underline operators for software characters.

The theta symbol (?) in the equation string is produced by displaying the character "h" in the alternate font. Note another font selection operator (\) appears immediately after the "h" to revert to the primary font. This string also includes superscript operators (\^) to display the exponents in the equation. The next string includes a single subscripted character, and then shows how to display three consecutive subscripted characters. The last string illustrates how to underline characters.

Note how SWchars uses world space coordinates to position the strings and draw the lines between the sections in this example. We could have used screen space coordinates instead, but as the program defines a world space coordinate system, we might as well use it.

Another feature introduced in this example is the specific use of fg_vbpaste(). Software characters are drawn with narrow lines, and using fg_vbscale() often removes rows and columns that happen to be crucial parts of the characters when scaling the virtual buffer into a smaller client area. The SWchars program solves this problem by always using fg_vbpaste(). When the window size is smaller than the virtual buffer, the program displays as much of the lower left corner of the virtual buffer as possible. When it is larger, the program centers the 640x480 virtual buffer in the client area. Note how the WM_SIZE handler calculates the destination coordinates, xDest and yDest, representing the client area coordinates for the lower left corner of the virtual buffer.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.