Overview
Examples
Screenshots
Comparisons
Applications
Download
Manual
Status & Roadmap
FAQ
Authors & License
Forums
Wiki
Funding Ultimate++
Search on this site











SourceForge.net Logo



Draw

class Draw

 

 

The class encapsulates system-dependent internals of graphical output. Whenever you need to paint something in a window, you need a Draw object for it. The standard Paint method of the Ctrl class takes a Draw& parameter as well. In that case the underlying mechanism passes a Draw which is already initialized for output into the respective control, knows about the current clipping, resolution etc. In a similar manner you can create your own Draw objects to draw onto Images, Drawings (vector metafiles used for serialization of graphical operations) or to perform printer output. You can also use a Draw to query graphics-related properties of various output devices, like pixel size, resolution, supported color model, available fonts etc.

 

Although the internals of graphical output are very system-dependent, the Draw class is designed so as to hide most of the OS-specific details and present a unified portable interface regardless of the actual target device or object. The downside of this approach is that Draw capabilities are somewhat limited to cover most frequently used graphical objects and attributes. It is quite possible (and in certain situations rather common) that its interface lacks some advanced capabilities, although they are supported in the target operating system. For these situations the Draw object supports also methods which allow you to extend its capabilities by utilizing low-level, system specific code, and accessing the output device at the native system level. Of course, heavy use of such capabilities makes writing portable code very difficult.

 

The operations supported by the Draw class can be divided into several categories:

 

initialization and configuration of the output device

querying output device properties

managing colors

managing text styles

controlling current clipping region and drawing offset

drawing basic vector primitives (lines, polygons)

drawing raster primitives

drawing text

accessing Drawing-specific functions

accessing unified virtual output interface

accessing the underlying physical output device interface

accessing device-secific functions

 

Initialization and configuration of the output device

 

Draw(HDC hdc)

Win32-specific: initializes the Draw object to output on a Window device context (HDC). This is the usual Windows method to paint into windows, on memory-mapped bitmaps and on the printer.

Note: it is seldom necessary to construct the Draw object in this way. System-independent U++ layer hides such system-specific internals within upper-level abstract objects (PrintDraw, ImageDraw, ViewDraw). Remember that, by directly handling device contexts, you are depraved of a multitude of U++ internal housekeeping chores and checks which ensure that the device context and potentially its attributes are properly allocated and destroyed as necessary. For a complete set of rules for working with device contexts, see Microsoft Windows documentation.

hdc

handle to output device context

 

Draw(Drawable dw, GC gc, XftDraw *xftdraw, const Vector<Rect>& clip)

X11-specific: initializes the draw object to output on a X-Windows drawable using a given graphics context (GC). This is the usual X-Windows method to paint into windows and on memory-mapped bitmaps.

Note: it is seldom necessary to construct the Draw object in this way. System-independent U++ layer hides such system-specific internals within upper-level abstract objects (ImageDraw, ViewDraw). Remember that, by directly handling device contexts, you are depraved of a multitude of U++ internal housekeeping chores and checks which ensure that the device context and potentially its attributes are properly allocated and destroyed as necessary. For a complete set of rules for working with device contexts, see X Windows documentation.

dw

output drawable

gc

output graphic context

xftdraw

XFT interface object

clip

clipping region

 

Draw(Drawable dw, GC gc, const Vector<Rect>& clip)

X11-specific: initializes the draw object to output on a X-Windows drawable using a given graphics context (GC). This is the usual X-Windows method to paint into windows and on memory-mapped bitmaps.

Note: it is seldom necessary to construct the Draw object in this way. System-independent U++ layer hides such system-specific internals within upper-level abstract objects (ImageDraw, ViewDraw). Remember that, by directly handling device contexts, you are depraved of a multitude of U++ internal housekeeping chores and checks which ensure that the device context and potentially its attributes are properly allocated and destroyed as necessary. For a complete set of rules for working with device contexts, see X Windows documentation.

dw

output drawable

gc

output graphic context

clip

clipping region

 

void Init()

Initializes internal variables for output on a previously set output device.

Note: this is normally not necessary. This function is called only from derived classes which need to set the output device handle (HDC under Win32, GC under X Windows) manually.

 

void Init(const Vector<Rect>& clip, Point offset = Point(0, 0))

X Windows-specific: initializes Draw internals for output on a previously set output device. The parameters give clipping region and output offset to initialize the clipping stack with.

clip

clipping region of the output device (in device coordinates)

offset

initial output offset (device coordinates)

 

Querying output device properties

 

bool PaletteMode() const

Checks whether the current output device is palette-based or RGB-based. Monochrome devices are treated as RGB-based.

Return value

true = device uses palette-based color management, false = device pixels contain direct RGB color values.

 

bool IsMono() const

Check whether the current output device is monochrome.

Return value

true = monochrome, false = grayscale or color device.

 

Size GetPagePixels() const

Returns pixel page size. For virtual output devices (like Drawings), this is the same as dot page size.

Return value

Pixel width and height of the output page.

 

Size GetPageMMs() const

Returns physical output page size in millimeters.

Return value

Output page width and height in millimeters.

 

Size GetPixelsPerInch() const

Returns the resolution of the output device.

Return value

Number of pixels horizontally and vertically across a squared inch.

 

Size GetSheetPixels() const

Returns pixel size of the output page including physical margins. This is meaningful only for printers for which the printable area is sometimes smaller than the actual paper size. For such devices GetSheetPixels returns pixel size of the original (full) paper including the margins unsuitable for printing, whereas GetPagePixels returns the printable area size (paper size minus physically enforced margins).

Return value

Pixel width and height of the physical output medium (paper in printer)

 

Point GetPageOffset() const

Returns pixel offset of the topleft corner of the printable output area from the topleft corner of the physical output medium (printer paper). This is meaningful only for printers where the printable area is sometimes smaller than the actual paper size (see also GetSheetPixels). By subtracting GetPageOffset() from a pair of coordinates it is possible to position objects absolutely with respect to the paper edges.

Return value

Horizontal and vertical displacement from the topleft corner of the physical output medium to the topleft corner of the printable area.

 

bool Pixels() const

Checks whether the output device coordinates are pixel-based or dot-based. This is the negation of the Dots() function. Window and image draws are pixel-based, whereas printer and Drawing draws are normally dot-based.

Return value

true = device is pixel-based, false = device is dot-based.

 

bool Dots() const

Checks whether the output device coordinates are pixel-based or dot-based. This is the negation of the Pixels() function. Window and image draws are pixel-based, whereas printer and Drawing draws are normally dot-based.

Return value

true = device is dot-based, false = device is pixel-based.

 

bool IsPrinter() const

Checks whether the output device is a printer.

Return value

true = device is a printer.

 

bool IsAborted() const

Checks whether the output job has been aborted. This is meaningful mainly for printers.

Return value

true = job has been aborted.

 

bool IsBack() const

Checks whether output device supports double-buffering. For devices with double-buffering it is not necessary (and is usually counterproductive) to take measures to prevent flickering as the whole output is composed offscreen. Output devices without direct video output (like Drawings or Images) are return true (as there is no direct video output, it is not necessary to prevent flickering).

Return value

true = device is double-buffered, false = output goes directly to video

 

bool IsDrawing() const

Checks whether the output device is a Drawing.

Return value

true = device is a Drawing.

 

bool IsMetaFile() const

Win32-specific: Checks whether the output device is a Windows Metafile.

Return value

true = device is a Windows Enhanced Metafile.

 

Managing colors

 

Different output devices and their technologies pose natural limitations on producing color output. The basic classes of devices with respect to their color management are:

 

Monochrome devices (like monochrome laser printers or certains specialized displays) support no color at all. Every pixel of the output device can be black or white.

Palette-based devices (like old 16- or 256-color displays) support a fixed set of distinct color slots, called a palette. Colors of the individual slots can be either user-settable or fixed (system-set). Every pixel of the output device is an index into the palette.

RGB-based devices (HiColor or TrueColor displays), in which every pixel of the output device can be set to any of the colors displayable by the device. Typically each pixel has at least 16 bits comprising of 5- or 8-bit subfields for the red, green, and blue color component.

 

Logical color model used by the Draw class communicates colors using device-independent color values (as represented by the Color class). Graphical output functions convert these colors on-the-fly to physical colors supported by the system. Pixel- and line-oriented output objects (lines, polylines, ellipses) paint the requested objects with the nearest available physical color to the requested logical color, whereas area- and raster-oriented output objects (rectangles, polygons, and images) use dithering to approximate logical colors not directly produceable by the device.

 

Draw supports two ways of using palette-based output devices:

 

Automatic palette: upon initialization Draw sets up the system palette to contain a matrix of 6x6x6 RGB triplets for all combinations of 6 equidistant intensities of the color components, a 16-level gray scale plus 16 basic system colors. This fixed color palette enables the system to closely mimic the behaviour of RGB-based color systems.

User palette: Draw works with the current palette as set by the system / user. Nearest match is used for logical color mapping.

 

static bool AutoPalette()

Checks palette mode of the active output device.

Return value

true = automatic palette mode, false = user palette mode

 

static void SetAutoPalette(bool ap)

Turns automatic palette mode on or off.

ap

true = activate automatic palette, false = activate user palette mode

 

void Win32UpdateSColors()

Updates logical palette of basic system-dependent colors (SLtGray, SWhite, SBlack etc.).

 

Managing text styles

 

static int CALLBACK AddFace(const LOGFONT *logfont, const TEXTMETRIC *, dword type, LPARAM param)

 

font

angle

device

Return value

 

static void SetStdFont(Font font)

Sets the font to be used as the standard font (StdFont, Font::STDFONT).

font

new standard font

 

static Font GetStdFont()

Returns the current standard font.

Return value

previously set or system-default standard font

 

static Size GetStdFontSize()

Returns the letter box width and height of the current standard font.

Return value

cx = GetWidth(), cy = GetHeight() of the current standard font. When cx == 0, standard font has default width.

 

static int GetStdFontCy()

Returns letter box width and height of the current standard font

Return value

cx = GetWidth(), cy = GetHeight() of the current standard font. When cx == 0, standard font has default width.

 

FontInfo GetFontInfo(byte charset, Font font = StdFont())

Returns font information object describing given font and charset.

charset

character set to use (from the CHARSET_xxx enumeration)

font

font to retrieve information for.

Return value

FontInfo structure describing metrics of system-allocated font for the given font object.

 

FontInfo GetFontInfo(Font font = StdFont())

Returns font information object describing given font.

font

font to retrieve information for.

Return value

FontInfo structure describing metrics of system-allocated font for the given Font object.

 

FontInfo GetFontInfoW(Font font = StdFont())

Returns Unicode font information for a given font.

font

font to retrieve information for.

Return value

FontInfo structure describing Unicode metrics of system-allocated font for the given Font object.

 

Controlling current clipping region and drawing offset

Sometimes it is necessary or at least handy to move the logical coordinate origin and limit output clipping for a part of the drawing process. For this reason, coordinate origin displacement together with current clipping region is kept as a stack in the Draw object. Certain function push a new offset / clipping entry to the stack, other functions manipulate the current top of stack. Actual coordinate origin and clipping in effect while drawing corresponds to the entry on top of the stack. At the beginning the coordinate origin is usually set to topleft corner of the output medium and the clipping box encapsulates all available output area (or, like in case of Ctrl::Paint, the current "dirty" area that needs to be repainted in a window).

 

void Begin()

Duplicates the current entry on the top of the coordinate / clipping stack. This effectively doesn't change the current coordinate / clipping setting but creates a new entry which can be further manipulated by other methods like IntersectClip or ExcludeClip.

 

void End()

Discards one coordinate / clipping entry from top of the stack.

 

void Offset(Point p)

Creates a new coordinate / clipping entry on top of the stack equal to the previous entry with coordinate origin shifted by p pixels.

p

number of pixels to add to coordinate origin (p.x > 0 = right, p.x < 0 = left, p.y > 0 = down, p.y < 0 = up).

 

void Offset(int x, int y)

Creates a new coordinate / clipping entry on top of the stack equal to the previous entry with coordinate origin shifted by (x, y) pixels.

x

number of pixels to add to horizontal coordinate origin (x > 0 = right, x < 0 = left).

y

number of pixels to add to vertical coordinate origin (y > 0 = down, y < 0 = up).

 

bool Clip(const Rect& r)

Creates a new coordinate / clipping entry on top of the stack with coordinate origin equal to the previous value and clipping equal to the intersection of the previous clipping region with the rectangle r.

r

rectangle to intersect with current clipping region (relative to the current coordinate origin)

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool Clip(int x, int y, int cx, int cy)

Creates a new coordinate / clipping entry on top of the stack with coordinate origin equal to the previous value and clipping equal to the intersection of the previous clipping region with the rectangle given by its topleft origin (relative to the current coordinate origin) (x, y), width cx and height cy.

 

x

left side of rectangle to intersect with current clipping region (relative to current coordinate origin)

y

top side of rectangle to intersect with current clipping region (relative to current coordinate origin)

cx

rectangle width

cy

rectangle height

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool Clipoff(const Rect& r)

Creates a new coordinate / clipping entry on top of the stack with clipping equal to the intersection of the previous clipping region with the rectangle r and with the coordinate origin shifted by r.TopLeft() pixels. For further drawing operations the current pixel r.TopLeft() will correspond to (0, 0) and r.BottomRight() to (r.Width(), r.Height()).

r

rectangle to intersect with current clipping region (relative to current coordinate origin); r.left is added to the horizontal coordinate origin and r.top to the vertical coordinate origin.

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool Clipoff(int x, int y, int cx, int cy)

Creates a new coordinate / clipping entry on top of the stack with clipping equal to the intersection of the previous clipping region with the rectangle r and with the coordinate origin shifted by (x, y) pixels. For further drawing operations the current pixel (x, y) will correspond to (0, 0).

 

x

left side of rectangle to intersect with current clipping region (relative to current coordinate origin) and the amount to add to horizontal coordinate origin

y

top side of rectangle to intersect with current clipping region (relative to current coordinate origin) and the amount to add to vertical coordinate origin

cx

rectangle width

cy

rectangle height

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool ExcludeClip(const Rect& r)

Updates the current clipping region on top of the coordinate / clipping stack by subtracting the rectangle r from the current clipping region.

r

rectangle to subtract from current clipping region (relative to current coordinate origin)

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool ExcludeClip(int x, int y, int cx, int cy)

Updates the current clipping region on top of the coordinate / clipping stack by subtracting the rectangle RectC(x, y, cx, cy) from the current clipping region.

x

left side of rectangle to subtract from current clipping region (relative to current coordinate origin)

y

top side of rectangle to subtract from current clipping region (relative to current coordinate origin)

cx

rectangle width

cy

rectangle height

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool IntersectClip(const Rect& r)

Updates the current clipping region on top of the coordinate / clipping stack by intersecting the rectangle r with the current clipping region.

r

rectangle to intersect with current clipping region (relative to current coordinate origin)

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

bool IntersectClip(int x, int y, int cx, int cy)

Updates the current clipping region on top of the coordinate / clipping stack by intersecting the rectangle RectC(x, y, cx, cy) with the current clipping region.

x

left side of rectangle to intersect with current clipping region (relative to current coordinate origin)

y

top side of rectangle to intersect with current clipping region (relative to current coordinate origin)

cx

rectangle width

cy

rectangle height

Return value

true = the new clipping region is non-empty, false = the new clipping is empty (it is not necessary to draw anything as nothing is visible)

 

Rect GetClip() const

Returns the smallest rectangle fully covering the current clipping region. The value can be used to limit output to the visible area. Take care not to mix the current clipping region with the output rectangle as the clipping region can be just a subset of this output rectangle (like in case of Ctrl::Paint when a part of the window is obscured).

Return value

Smallest rectangle fully covering the current clipping region (relative to current coordinate origin)

 

Point GetOffset() const

Returns the current coordinate origin. This is naturally in absolute coordinates relative to the topleft corner of the output medium.

Return value

Current coordinate origin (relative to topleft corner of the output medium)

 

int GetCloffLevel() const

Returns the number of entries on the coordinate / clipping stack. This is normally used for self-consistency check where the drawing routine ASSERTs that after drawing something the stack depth is the same as it was before (to check whether there is not a stack 'leak' when the drawing routine forgets to End some coordinate / clipping entries it has previously pushed on the stack).

Return value

number of entries on the coordinate / clipping stack

 

Point LPtoDP(Point pconst

Converts a point from coordinates relative to current coordinate origin to absolute coordinates from the topleft corner of the output medium. This effectively adds the current coordinate origin to the given point p.

p

Point to convert (relative to current coordinate origin)

Return value

Absolute coordinates of point p from the topleft corner of the output medium

 

Point DPtoLP(Point pconst

Converts a point from the absolute coordinates (from the topleft corner of the output medium) to coordinates relative to current coordinate origin. This effectively subtracts the current coordinate origin from the point p.

p

Point to convert (absolute coordinates)

Return value

Relative coordinates of p with respect to the current coordinate origin

 

Rect LPtoDP(const Rectrconst

Converts a rectangle from coordinates relative to current coordinate origin to absolute coordinates from the topleft corner of the output medium. This effectively offsets the rectangle r by the amount given by the current coordinate origin.

r

Rectangle to convert (relative to current coordinate origin)

Return value

Rectangle r in absolute coordinates with respect to the topleft corner of the output medium

 

Rect DPtoLP(const Rectrconst

Converts a rectangle from the absolute coordinates (with respect to the topleft corner of the output medium) to coordinates relative to current coordinate origin. This effectively offsets the rectangle r by the negative value of the current coordinate origin.

r

Rectangle to convert (absolute coordinates)

Return value

Rectangle r in coordinates relative to current coordinate origin

 

Drawing basic vector primitives (lines, polygons)

 

void DrawRect(int x, int y, int cx, int cy, Color color)

Fills rectangle RectC(x, y, cx, cy) with the color color. On palette-based devices dithering is sometimes used for approximation when the given color doesn't closely correnspond to one of the available colors (see Managing colors).

x

left side to rectangle to fill (relative to coordinate origin)

y

top side of rectangle to fill

cx

rectangle width

cy

rectangle height

color

color used for filling. When color == Null, nothing is done. The special color InvertColor() can be used to logically invert all pixel bits within the given area. This has the effect of changing white to black and vice versa and changing color hues to their complements. Note, however, that due to gamma-correction, the output image is not a photometrical complement of the original image.

 

void DrawRect(const Rect& rect, Color color)

Fills rectangle rect with the color color. On palette-based devices dithering is sometimes used for approximation when the given color doesn't closely correnspond to one of the available colors (see Managing colors).

rect

area to fill (relative to coordinate origin)

color

color used for filling. When color == Null, nothing is done. The special color InvertColor() can be used to logically invert all pixel bits within the given area.

 

void DrawLine(int x1, int y1, int x2, int y2, int width = 0, Color color = DefaultInk)

Draws a line from the point (x1, y1) to (x2, y2) with color color. When width is positive, solid line width pixels wide is drawn. When width is negative, function draws a dashed line 1 pixel wide. width is then one of the PEN_... enumeration constants defining the desired line pattern. The fact that the function doesn't support wide dashed lines is a sad limitation of the older Win32 GDI which under Windows 95, 98 and ME doesn't support this. When wide dashed lines are needed, it is necessary to generate the segments manually and split the line patterns into individual line segments or into polygonal patches (depending on the precision requirements and time issues in given context). Under Win32 GDI the point (x1, y1) is not drawn.

x1, y1

line beginning (relative to current coordinate origin)

x2, y2

line end

width

line width or one of the PEN_ constants for dashed lines

color

line color. When color == Null, nothing is drawn. On palette-based devices the nearest palette color is used (no dithering is made).

 

 

enum { PEN_NULL, PEN_SOLID, PEN_DASH, PEN_DOT, PEN_DASHDOT, PEN_DASHDOTDOT }

 

PEN_NULL

empty pen (nothing is drawn)

PEN_SOLID

solid pen

PEN_DASH

dashed pen - - -

PEN_DOT

dotted pen (dashes are shorter) . . .

PEN_DASHDOT

dash - dot - dash - dot pattern

PEN_DASHDOTDOT

dash - dot - dot - dash - dot - dot pattern

 

 

void DrawLine(Point p1, Point p2, int width = 0, Color color = DefaultInk)

Draws a line from the point p1 to p2 with color color. width gives line width (positive) or dash pattern (negative). Under Win32 GDI the point (x1, y1) is not drawn.

 

p1

line beginning (relative to coordinate origin)

p2

line end

width

line width or dash pattern

color

line color

 

void DrawEllipse(const Rect& r, Color color = DefaultInk, int pen = Null, Color pencolor = DefaultInk)

Draws the largest ellipse with both axes parallel to coordinate axes fully within rectangle r, i.e. with center point at r.CenterPoint(), semi major axis and semi minor axis equal to r.Width() / 2 and r.Height() / 2.

r

ellipse's bounding rectangle

color

color to fill the ellipse inside with (Null = no filling)

pen

pen width / dash style to used for drawing the ellipse circumference

pencolor

pen color for drawing the ellipse circumference (Null = circumference is not drawn)

 

void DrawEllipse(int x, int y, int cx, int cy, Color color = DefaultInk, int pen = Null, Color pencolor = DefaultInk)

Draws the largest ellipse with both axes parallel to coordinate axes fully within rectangle RectC(x, y, cx, cy), i.e. with center point at x + cx / 2 and y + cy / 2, semi major axis and semi minor axis equal to cx / 2 and cy / 2.

 

x

left side of ellipse's bounding rectangle

y

top side of ellipse's bounding rectangle

cx

rectangle width

cy

rectangle height

color

color to fill ellipse inside with (Null = interior is not filled)

pen

pen width / dash style for drawing ellipse circumference

pencolor

pen color for drawing ellipse circumference (Null = not drawn)

 

void DrawArc(const Rect& rc, Point start, Point end, int width = 0, Color color = DefaultInk)

Draws elliptic arc corresponding to the largest ellipse fully within the rectangle rc and running counterclockwise from the direction corresponding to the line connecting the centre of the ellipse (rc.CenterPoint()) with the point start and ending at direction of the point end from the ellipse centre. When start == end, the full ellipse is drawn.

rc

ellipse's bounding rectangle

start

direction at which to start the arc

end

direction of arc end (from the ellipsec centre)

width

pen width or dash style

color

color to used for drawing. On palette-based devices the nearest palette color is used (no dithering).

 

void DrawPolyPolyline(const Point *vertices, int vertex_count, const int *counts, int count_count, int width = 0, Color color = DefaultInk, Color doxor = Null)

Draws a series of polylines. Polyline vertices are kept in the array vertices. The parameter vertext_count gives the total number of vertices of all polylines in the array. The array counts gives numbers of points defining the individual polylines and count_count gives number of entries in this array (i.e. the number of connected polylines). The first polyline comprises vertices vertices[0], vertices[1] ... vertices[counts[0] - 1], the second polyline vertices[counts[0]], vertices[counts[0] + 1] ... vertices[counts[0] + counts[1] - 1], etc.

vertices

array of polyline vertices (relative to coordinate origin)

vertex_count

total number of vertices of all polylines

counts

array of polyline vertex counts

count_count

number of entries in the counts array, i.e. the number of polylines

width

pen width or dash style.

color

polyline color.

doxor

used to draw a xor'ed polyline set. Useful for drag & drop animations where it is needed to draw and undraw the rubber rectangle or line repeatedly without having to repaint the whole display image. When set to non-Null value, it gives the 'background' color on which polyline pixels will have color color after xoring.

 

void DrawPolyPolyline(const Vector<Point>& vertices, const Vector<int>& counts, int width = 0, Color color = DefaultInk, Color doxor = Null)

Draws a series of polylines. Polyline vertices are kept in the array vertices. The array counts gives numbers of points defining the individual polylines (i.e. the number of connected polylines is equal to counts.GetCount()). The first polyline comprises vertices vertices[0], vertices[1] ... vertices[counts[0] - 1], the second polyline vertices[counts[0]], vertices[counts[0] + 1] ... vertices[counts[0] + counts[1] - 1], etc.

 

vertices

vertices of all polylines to draw

counts

vertex counts in individual polyline segments

width

pen width / dash style

color

polyline color

doxor

background value for xor'ed drawing (Null = draw normally)

 

void DrawPolyline(const Point *vertices, int count, int width = 0, Color color = DefaultInk, Color doxor = Null)

Draws a single polyline connecting all count vertices.

vertices

Polyline vertices

count

number of vertices

width

pen width / dash style

color

polyline color

doxor

background value for xor'ed drawing (Null = draw normally)

 

void DrawPolyline(const Vector<Point>& vertices, int width = 0, Color color = DefaultInk, Color doxor = Null)

Draws a single polyline connecting all vertices.

vertices

polyline vertices

width

pen width / dash style

color

polyline color

doxor

background value for xor'ed drawing (Null = draw normally)

 

void DrawPolyPolyPolygon(const Point *vertices, int vertex_count, const int *subpolygon_counts, int subpolygon_count_count, const int *disjunct_polygon_counts, int disjunct_polygon_count_count, Color color = DefaultInk, int width = 0, Color outline = Null, Image image = Null, Color doxor = Null)

Draws a series of complex polygons (i.e. polygons which may contain holes). The vertices array holds all polygon defining vertices. The array is divided into sections corresponding to the whole complex polygons (parameters disjunct_polygon_counts and disjunct_polygon_count_count) and these sections are further divided into the individual polygons defining one complex polygon (i.e. outer boundary and holes). Numbers of vertices in the individual polygons are held in the array subpolygon_counts (total number of simple polygons = subpolygon_count_count).

vertices

all polygon vertices

vertex_count

number of polygon vertices

subpolygon_counts

vertex counts in individual simple polygons

subpolygon_count_count

number of entries in subpolygon_counts

disjunct_polygon_counts

vertex counts of the whole complex polygons

disjunct_polygon_count_count

number of disjunct_polygon_counts

color

polygon fill color (Null = no fill)

width

pen width / dash style to draw polygon boundary with

outline

pen color for drawing polygon boundary (Null = no boundary)

image

pattern for filling polygon interior. Due to Win32 GDI limitations image must be 8 pixels wide and high.

doxor

Background color for xor'ed drawing.

 

Drawing raster primitives

 

void DrawImage(int x, int y, int cx, int cy, const Imageimg, const Rect& src)

void DrawImage(int x, int y, int cx, int cy, const Imageimg)

void DrawImage(int x, int y, int cx, int cy, const Imageimg, const Rect& src, Color color)

void DrawImage(int x, int y, int cx, int cy, const Imageimg, Color color)

void DrawImage(const Rectr, const Imageimg, const Rect& src)

void DrawImage(const Rectr, const Imageimg)

void DrawImage(const Rectr, const Imageimg, const Rect& src, Color color)

void DrawImage(const Rectr, const Imageimg, Color color)

void DrawImage(int x, int y, const Imageimg, const Rect& src)

void DrawImage(int x, int y, const Imageimg)

void DrawImage(int x, int y, const Imageimg, const Rect& src, Color color)

void DrawImage(int x, int y, const Imageimg, Color color)

Draws an Image at specified position. If the position specifies dimension (cx, cy or is defined using  Rect r, Image is rescaled. If color is provided, only Image alpha channel is used and painted with the specified color. src can be used specify only a portion of the source Image to be painted.

 

Size GetTextSize(const wchar *text, Font font = StdFont(), int n = -1)

Measures width and height of a Unicode text (as when painted using given font).

text

Unicode text to measure

font

font to use for the metrics measurements

n

number of letters in the array text. When n < 0, text length is counted using wcslen.

Return value

cx = output text pixel width, cy = line height of given font

 

void DrawText(int x, int y, int angle, const wchar *text, Font font = StdFont(), Color ink = SBlack, int n = -1, const int *dx = NULL)

Draws text on the output device.

Note: when working with rotated texts, always remember that [x, y] define the topleft corner of the text box. Box size is that returned by the function GetTextSize. In case of rotated texts, the text box is naturally not aligned with the coordinate axes. Also, some system fonts do not support rotation (bitmap fonts). Unfortunately there is currently no reliable way to detect if a font supports rotation. FontInfo::IsScaleable should provide a good guess as to whether a given font supports rotation.

x

x coordinate of the topleft corner of the text box

y

y coordinate of the topleft corner of the text box

angle

angle for the text in tenths of degrees (full circle = 3600). 0 = to the right (normal text orientation), 900 = upwards, 1800 = head down left, 2700 downwards.

text

Unicode text to draw

font

font to use for drawing text

ink

text color; the text is always drawn as transparent. To set the background under the text to a given color, you must first measure the text size using GetTextSize and then call DrawRect to set the text box to a given color. When using rotated text (angle != 0) the situation is naturally much more complicated and a DrawPolygon would be needed to clear the rotated text box.

n

number of letters in the array text. When n < 0, text length is counted using wcslen.

dx

array of letter widths. This can be used to set explicit spacings for the individual letters in the text. When NULL, default letters widths are used. When not NULL, it must contain (at least) as many entries as are being painted from the given text.

 

void DrawText(int x, int y, const wchar *text, Font font = StdFont(), Color ink = SBlack, int n = -1, const int *dx = NULL)

Draws text on the output device. This is a simplified version of the above function for the most common case when angle == 0 (i.e. the text is being painted in the ordinary direction from left to right).

x

x coordinate of the topleft corner of the text box

y

y coordinate of the topleft corner of the text box

text

Unicode text to draw

font

font to use for drawing text

ink

text color; the text is always drawn as transparent. To set the background under the text to a given color, you must first measure the text size using GetTextSize and then call DrawRect to set the text box to a given color.

n

number of letters in the array text. When n < 0, text length is counted using wcslen.

dx

array of letter widths. This can be used to set explicit spacings for the individual letters in the text. When NULL, default letters widths are used. When not NULL, it must contain (at least) as many entries as are being painted from the given text.

 

Size GetTextSize(const WString& text, Font font = StdFont())

Measures width and height of a Unicode text (as when painted using given font).

text

text string to measure

font

font to use for metrics measurements

Return value

cx = text box width, cy = text box height (font ascent + descent).

 

void DrawText(int x, int y, const WString& text, Font font = StdFont(), Color ink = SBlack, const int *dx = NULL)

Draws text on the output device (from left to right). This is a variation of one of the above function for the case when the input parameter is a WString. In such situation the number of letters is known (text.GetLength()) and doesn't (indeed shoudn't) be measured using wcslen.

x

x coordinate of the topleft corner of the text box

y

y coordinate of the topleft corner of the text box

text

Unicode text to draw

font

font to use for drawing text

ink

text color; the text is always drawn as transparent.

dx

array of letter widths. This can be used to set explicit spacings for the individual letters in the text. When NULL, default letters widths are used. When not NULL, it must contain (at least) as many entries as are being painted from the given text.

 

void DrawText(int x, int y, int angle, const WString& text, Font font = StdFont(), Color ink = SBlack, const int *dx = NULL)

Draws text on the output device. A variation of the above function allowing text rotation. See above notes concerning text rotation issues.

x

x coordinate of the topleft corner of the text box

y

y coordinate of the topleft corner of the text box

angle

angle for the text in tenths of degrees (full circle = 3600). 0 = to the right (normal text orientation), 900 = upwards, 1800 = head down left, 2700 downwards.

text

Unicode text to draw

font

font to use for drawing text

ink

text color; the text is always drawn as transparent.

dx

array of letter widths. This can be used to set explicit spacings for the individual letters in the text. When NULL, default letters widths are used. When not NULL, it must contain (at least) as many entries as are being painted from the given text.

 

Size GetTextSize(const char *text, byte charset, Font font = StdFont(), int n = -1)

Measures text box size for text in given character set.

text

text to measure

charset

text character set

font

font to use for the metrics measurements

n

number of letters in text. When n < 0, text length is counted using strlen (or utf8len, when charset == CHARSET_UTF8).

Return value

 

void DrawText(int x, int y, int angle, const char *text, byte charset, Font font = StdFont(), Color ink = SBlack, int n = -1, const int *dx = NULL)

Draw given text in a given character set to the ouput device. This variant allows text rotation.

x

x coordinate of the topleft corner of the text box

y

y coordinate of the topleft corner of the text box

angle

angle for the text in tenths of degrees (full circle = 3600). 0 = to the right (normal text orientation), 900 = upwards, 1800 = head down left, 2700 downwards.

text

text to draw

charset

output text character set (from the CHARSET_xxx enumeration)

font

font to use for drawing text

ink

text color; the text is always drawn as transparent.

n

number of letters in text. When n < 0, text length is counted using strlen.

dx

array of letter widths. This can be used to set explicit spacings for the individual letters in the text. When NULL, default letters widths are used. When not NULL, it must contain (at least) as many entries as are being painted from the given text.

 

void DrawText(int x, int y, const char *text, byte charset, Font font = StdFont(), Color ink = SBlack, int n = -1, const int *dx = NULL)

Draws text in given character set to the output device (from left to right).

x

x coordinate of the topleft corner of the text box

y

y coordinate of the topleft corner of the text box

text

text to draw

charset

output text character set (from the CHARSET_xxx enumeration)

font

font to use for drawing text

ink

text color; the text is always drawn as transparent.

n

number of letters in text. When n < 0, text length is counted using strlen (or utf8len, when charset == CHARSET_UTF8).

dx

array of letter widths. This can be used to set explicit spacings for the individual letters in the text. When NULL, default letters widths are used. When not NULL, it must contain (at least) as many entries as are being painted from the given text.

 

Size GetTextSize(const char *text, Font font = StdFont(), int n = -1)

Measures text box size for a text encoded in system-defau