|
You are in Section 8 of 9, Article 8.3 of 8.4, Part 8.3.5 of 8.3.6
Colors and Text
Specifying Colors
If needing to change or specify the color and/or pattern used for filling objects and regions, use the following function:
NOTE: setcolor() will specify the color used for the border of objects and normal drawing functions; setfillstyle() specifies the color to be used for the interior of objects.
There are 13 different patterns defined for the pattern of filling, including:
- EMPTY_FILL (0)
- SOLID_FILL (1)
- SLASH_FILL (4)
- BK_SLASH_FILL (5)
- HATCH_FILL (7)
- XHATCH_FILL (8)
The following section of code will draw a rectangle with a border of white and interior of red:
Displaying Graphical Text
Text can be displayed on the graphics window using the following functions:
The outtext() function displays the given string using the font, direction, and the size set by the settextstyle( ) function, which has three parameters; int font, int direction, and int size (1 - 10);
The default values for outtext() are as follows:
Direction may be one of the following: HORIZ_DIR (0) or VERT_DIR (1).
Using default values, the displayed text is practically unreadable. Experiment with the various settings to see which values appear the best for the program being written.
By default, outtext() positions the text such that the upper left corner of the first character is positioned in the current position. outtextxy() is similar to outtext() except the upper left corner of the first character is positioned at (x, y).
The settextjustify() function can be used to control the horizontal and vertical position of the text relative to the current position or (x, y). It requires two parameters: horizontal and vertical and has the following form:
The horizontal parameter may be:
- LEFT_TEXT (0)
- CENTER_TEXT (1)
- RIGHT_TEXT (2)
The horizontal parameter determines whether the text starts at the current position, is centered at the current position, or ends at the current position.
The vertical parameter may be:
- BOTTOM_TEXT (0)
- CENTER_TEXT (1)
- TOP_TEXT (2)
The vertical parameter determines whether the text is displayed above the current position, centered at the current position, or below the current position. The default values for settextjustify() are LEFT_TEXT and TOP_TEXT.
In the next part, we'll put what we've learned into action by studying example graphics programs.
Read on for more...
Next: Specific Examples
You are in Section 8 of 9, Article 8.3 of 8.4, Part 8.3.5 of 8.3.6
[Back to Top]
|