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.

ParameterTypeDescription
hDCHandle / ObjectDevice context handle, TWindow, TDialog, or TPrinter object
aRectArray{ nTop, nLeft, nBottom, nRight } in pixels
uPenVariousPen color (numeric), { color, nWidth } array, TPen object, or handle
uBrushVariousBrush color, gradient array, TBrush object, or image handle
aTextArray / NilOptional { cText, oFont, nClrText, cAlign } to draw inside the shape
nShapeNumericShape 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.

FlagMeaning
CCenter horizontally
LLeft-align
RRight-align
TTop-align vertically
BBottom-align vertically
WWord-wrap

Alignment flags combine freely: "CR" = center-right, "TL" = top-left, "CB" = center-bottom.

Text Variants

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.

nResizeConstantBehavior
0FIT_CENTERCenter at original size, no scaling
1FIT_WIDTHScale to match rectangle width, maintain aspect ratio
2FIT_HEIGHTScale to match rectangle height, maintain aspect ratio
3FIT_RECTStretch to fill the target rectangle (may distort)
4FIT_ORGLDisplay 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

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

See Also