Skip to main content

Overview

TPainter is an abstract base class that provides platform-agnostic methods for drawing shapes, text, and graphics in TeeGrid. Framework-specific implementations (VCL and FireMonkey) inherit from this class to provide actual rendering functionality. Unit: Tee.Painter.pas

Architecture

TPainter provides an abstraction layer that allows TeeGrid to work identically across different frameworks:
  • VCL: VCLTee.Painter unit implements TPainter using GDI/GDI+
  • FireMonkey: FMXTee.Painter unit implements TPainter using FMX canvas
  • Lazarus/LCL: Compatible with VCL painter implementation
This design allows the same rendering code to work on Windows, macOS, Linux, iOS, and Android.

Type Definitions

THorizontalAlign

Horizontal text alignment options.

TVerticalAlign

Vertical text alignment options.

TTrimmingMode

Text trimming modes:
  • None: No trimming
  • Character: Trim at character boundary
  • Word: Trim at word boundary

TPointsF

Array of floating-point coordinates for polylines and polygons.

Drawing Methods

Draw (Rectangle)

Draws the outline of a rectangle using the current stroke. Parameters:
  • R: Rectangle bounds
Example:

Draw (Polyline)

Draws a polyline (connected line segments). Parameters:
  • P: Array of points
Example:

Draw (Picture)

Draws a picture at specified position or within a rectangle. Parameters:
  • APicture: Picture to draw
  • X, Y: Top-left coordinates
  • R: Rectangle to draw within (stretches if picture has Stretch = True)
Example:

DrawEllipse

Draws the outline of an ellipse. Parameters:
  • R: Bounding rectangle
Example:

Filling Methods

Fill (Rectangle)

Fills a rectangle with the current brush or specified color. Parameters:
  • R: Rectangle bounds
  • AColor: Fill color (optional)
Example:

Fill (Polygon)

Fills a polygon using the current brush. Parameters:
  • P: Array of points (automatically closed)
Example:

FillEllipse

Fills an ellipse with the current brush. Parameters:
  • R: Bounding rectangle

Line Drawing Methods

Line

Draws a line from (X0, Y0) to (X1, Y1). Example:

HorizontalLine

Draws a horizontal line (optimized). Parameters:
  • Y: Vertical position
  • X0: Start X coordinate
  • X1: End X coordinate

VerticalLine

Draws a vertical line (optimized). Parameters:
  • X: Horizontal position
  • Y0: Start Y coordinate
  • Y1: End Y coordinate
Example:

Lines

Draws multiple connected line segments. Parameters:
  • P: Array of points

Text Methods

TextOut

Draws text within a rectangle using current font and alignment. Parameters:
  • ARect: Rectangle bounds
  • AText: Text to draw
Example:

TextWidth

Calculates the width of text in pixels. Parameters:
  • AText: Text to measure
Returns: Width in pixels Example:

TextHeight

Calculates the height of text in pixels. Parameters:
  • AText: Text to measure
  • AFont: Font to use for measurement
Returns: Height in pixels

CalcTextLines

Counts the number of lines in multi-line text. Parameters:
  • AText: Text with potential line breaks
Returns: Number of lines

Style Setting Methods

SetBrush

Sets the current brush for filling operations. Example:

HideBrush

Disables brush (for drawing outlines only).

SetStroke

Sets the current stroke (pen) for drawing operations. Example:

SetFont

Sets the current font for text operations.

SetFontColor

Sets the font color directly.

SetHorizontalAlign

Sets horizontal text alignment. Values: Left, Center, Right

SetVerticalAlign

Sets vertical text alignment. Values: Top, Center, Bottom

SetTextTrimming

Sets text trimming mode and ellipsis display. Parameters:
  • ATrimming: Trimming mode (None, Character, Word)
  • Ellipsi: Show ”…” when trimmed

Format Painting Methods

Paint (Format + Rectangle)

Paints a rectangle using a format (brush and stroke). Example:

Paint (Format + Polygon)

Paints a polygon using a format.

Clipping Methods

Clip

Sets a clipping region. All subsequent drawing is clipped to this rectangle. Parameters:
  • R: Clipping rectangle
Example:

UnClip

Removes the current clipping region.

TryClip

Attempts to clip text if it exceeds bounds. Parameters:
  • AText: Text to check
  • ARect: Bounding rectangle
  • AMinX: Minimum X coordinate
Returns: True if clipping was applied

Usage Example: Complete Rendering

Platform-Specific Notes

VCL Implementation

  • Uses GDI+ for smooth rendering
  • Supports all standard Windows fonts
  • Hardware-accelerated on modern systems

FireMonkey Implementation

  • Uses native FMX canvas
  • Cross-platform compatible (Windows, macOS, iOS, Android, Linux)
  • Supports GPU acceleration on mobile

Performance Tips

  1. Minimize state changes: Group operations that use the same brush/stroke/font
  2. Reuse objects: Don’t create new TFormat/TFont objects for every cell
  3. Use clipping: Prevent overdraw by clipping to visible region
  4. Batch similar operations: Draw all horizontal lines together, then all vertical lines

See Also