Graphics Rendering Functions
Source: source/function/imgtxtio.prg, source/winapi/gdipfwh.cpp
FiveWin's graphics rendering functions provide the core drawing primitives for all visual output across windows, dialogs, printers, and PDF documents. They abstract Windows GDI and GDI+ operations, handling resource conversion, alpha blending, gradient fills, and coordinate transformations. The middleware layer in imgtxtio.prg converts Harbour data types (colors, arrays, objects) into low-level GDI handles.
FW_Box() - Shape Rendering
FW_Box( hDC, aRect, uPen, uBrush, aText, nShape )
Draws rectangles, rounded rectangles, or ellipses with customizable pens and brushes. Supports gradient fills, alpha blending, and optional text inside the shape.
| Parameter | Type | Description |
|---|---|---|
hDC | Handle / Object | Device context handle, TWindow, TDialog, or TPrinter object |
aRect | Array | { nTop, nLeft, nBottom, nRight } in pixels |
uPen | Various | Pen color (numeric), { color, nWidth } array, TPen object, or handle |
uBrush | Various | Brush color, gradient array, TBrush object, or image handle |
aText | Array / Nil | Optional { cText, oFont, nClrText, cAlign } to draw inside the shape |
nShape | Numeric | Shape constant: 0 = Rectangle, 1 = RoundRect, 2 = Ellipse |
FW_SayText() - Text Rendering
FW_SayText( oWnd, cText, aRect, cAlign, oFont, nClrText, nClrBack, lBorder, nAddStyle )
Draws text with full alignment control, word wrapping, and optional background fill. Supports GDI+ rendering for alpha colors and basic RTF formatting.
| Flag | Meaning |
|---|---|
C | Center horizontally |
L | Left-align |
R | Right-align |
T | Top-align vertically |
B | Bottom-align vertically |
W | Word-wrap |
Alignment flags combine freely: "CR" = center-right, "TL" = top-left, "CB" = center-bottom.
Text Variants
FW_SayHollow( hDC, cText, aRect, cAlign, oFont, nClrText, nClrBack )- Renders text as hollow (outline only) using GDI or GDI+.FW_SayTextHilite( oWnd, cText, aRect, cAlign, oFont, nClrText, nClrBack, aHilite, aFonts, aClrs )- Renders text with specific words highlighted in different fonts and colors.FW_SayTextSpread( hDC, cText, aRect, oFont, nClrText, nClrBack, nAngle )- Distributes characters evenly across the full width of the target rectangle.
FW_DrawImage() - Image Rendering
FW_DrawImage( oWnd, hBmp, aRect, lTransp, nResize, nAlpha, lGray, cAlign, aColorMap )
Draws a bitmap on a window or device context with support for resize modes, alpha blending, grayscale, and color mapping.
| nResize | Constant | Behavior |
|---|---|---|
| 0 | FIT_CENTER | Center at original size, no scaling |
| 1 | FIT_WIDTH | Scale to match rectangle width, maintain aspect ratio |
| 2 | FIT_HEIGHT | Scale to match rectangle height, maintain aspect ratio |
| 3 | FIT_RECT | Stretch to fill the target rectangle (may distort) |
| 4 | FIT_ORGL | Display at original pixel size, clipped if larger |
Set nAlpha to a value between 0 (invisible) and 255 (opaque) for semi-transparent rendering. Set lGray to .T. for grayscale conversion. aColorMap is an optional array of { nFrom, nTo } color replacements.
FW_DrawShadow()
FW_DrawShadow( hDC, aRect, nSize, nAlpha )
Draws a drop shadow effect around a rectangle. nSize controls the shadow width in pixels (typically 4-12), and nAlpha (0-255) controls the opacity. The shadow fades from opaque at the edge to transparent outward.
GradientFill()
GradientFill( hDC, nTop, nLeft, nBottom, nRight, aGradInfo, lVert )
Fills a rectangular region with a multi-stop gradient. aGradInfo is an array of { nColor } stops; two stops give a simple blend, three or more create multi-step transitions. Set lVert to .T. for a vertical gradient (top-to-bottom) or .F. for horizontal (left-to-right).
Additional Drawing Functions
FW_DrawShapes( oWnd, aShapes, aRect )- Batch-draws multiple shapes (rect, roundrect, ellipse, line, polygon) from an array of{ nShape, aRect, uPen, uBrush }descriptors.FW_PieChart( oWnd, aRect, aValues, aColors )- Draws a pie/donut chart from numeric data and color arrays.FillRectEx( hDC, aRect, nClr )- Solid-color rectangle fill without brush creation overhead.RingGradientFill( hDC, nTop, nLeft, nBottom, nRight, aGradInfo, nAngle )- Radial/ring gradient fill for glossy effects and custom backgrounds.
Example: Box with Text and Shadow
#include "FiveWin.ch"
function DrawSample( hDC, oWnd )
local aRect := { 50, 50, 350, 250 }
local oFont := TFont():New( "Segoe UI", 0, -18 )
// Draw drop shadow first
FW_DrawShadow( hDC, aRect, 8, 80 )
// Draw a rounded rectangle with gradient fill
FW_Box( hDC, aRect, CLR_BLUE, ;
{ CLR_WHITE, CLR_HBLUE }, ;
{ "Hello FWH Graphics", oFont, CLR_BLACK, "CR" }, ;
1 ) // RoundRect
oFont:End()
return nil