Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Draw

 

class Draw : private NoCopy

The class provides an abstract interface to basic graphical output, possibly HW accelerated. 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 derived SystemDraw 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 some graphics-related properties, like the size of output area or native resolution.

When Draw represents screen output, all metrics are always in pixels. If Draw represents any physical device (like printer), it uses artificial unit, "dot", by default, which is equivalent to 1/600 of inch. In other words, it is the same as pixels size of 600dpi printer (standard printer resolution).

However, it is also possible to switch to "Native" mode in some cases. In that case, Draw works in "native" pixels, for example 1/720 inch for some printers. Draw provides necessary metrics information to adjust graphic output.

Some methods have several overloaded variants, for example DrawRect has variants that specify the rectangle using Rect type or x, y, cx, cy coordinates. In that case, implementation is provided by single abstract virtual backend method ending with Op (DrawRectOp) and non-virtual frontend methods are then used to provide overloading (via parameter translation to backend method parameters).

Painting outside the output size is always legal - necessary clipping is performed in that case.

 

 

Public Member List

 

virtual dword GetInfo() const = 0

Returns some basic information about Draw as combination of flags:

 

Draw::DOTS = 0x001

Draw possibly represent physical device (printer, PDF output etc...).

Draw::GUI = 0x002

Draw encapsulates main host platform GUI graphical output (e.g. GDI in Win32).

Draw::PRINTER = 0x004

Draw represents printer.

Draw::NATIVE = 0x008

Draw is in native mode.

Draw::DATABANDS = 0x010

Draw can use banding to rescale images or for DrawData operation to reduce memory consumption.

 


 

virtual Size GetPageSize() const

Returns the size of actual output (size of window in pixels, size of printable area). If native mode is active and has different dpi, value is adjusted accordingly.

 


 

virtual void StartPage()

For printer output, starts a new page.

 


 

virtual void EndPage()

For printer output, ends page.

 


 

virtual void BeginOp() = 0

Implements Begin operation: Pushes current offset and clipping settings on Draw's internal stack.

 


 

virtual void EndOp() = 0

Implements End operation: Pops offset and clipping settings, restoring the status before pairing BeginOp, OffsetOp, ClipOp, ExcludeClipOp or IntersectClipOp.

 


 

virtual void OffsetOp(Point p) = 0

Implements Offset operation: Calls Begin and then offsets coordinates so that p becomes Point(0, 0).

 


 

virtual bool ClipOp(const Rect& r) = 0

Implements Clip operation: Calls Begin and then restricts all painting operations to r - nothing is painted outside this rectangle.

 


 

virtual bool ClipoffOp(const Rect& r) = 0

Implements ClipOff operation: Calls begin, then restricts all painting operations to r and offsets coordinates so that to left point of r becomes Point(0, 0).

 


 

virtual bool ExcludeClipOp(const Rect& r) = 0

Implements ExcludeClip operation: Excludes r from the output - nothing is painted in this area. Does not affect the offset/clipping stack. This operation is only guaranteed to work in SystemDraw.

 


 

virtual bool IntersectClipOp(const Rect& r) = 0

Implements IntersectClip operation: Intersects current clipping area with r. Does not affect the offset/clipping stack. This operation is only guaranteed to work in SystemDraw.

 


 

virtual bool IsPaintingOp(const Rect& rconst = 0

Implements IsPainting operation: Tests whether that should any painting happen in r. For example, if Draw represents graphics output to window in Ctrl::Paint, not all areas are always required to be repainted.

 


 

virtual Rect GetPaintRect() const

Provides bounding rectangle for painted areas (areas where IsPaintingOp returns true). Default implementation returns very rectangle.

 


 

virtual void DrawRectOp(int x, int y, int cx, int cy, Color color) = 0

Implements DrawRect operation: Fills rectangle x,y,cx,cy using color. As special addition, if Draw represents screen output in Ctrl::Paint, color can be assigned special value InvertColor() causing invertion of all pixels in target area. Note: On some platform, using InvertColor might results in suboptimal performance.

 


 

virtual void SysDrawImageOp(int x, int y, const Image& img, Color color)

Low-level draw of Image. It depends on second variant of SysDrawImageOp to support src parameter using Offset and Clip.

 


 

virtual void SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color)

Low(er)-level draw of Image, called by DrawImageOp. Draw derived class can either override this method and depend on DrawImageOp to do rescaling and printer banding or override DrawImageOp directly. Default implementation uses Offset and Clip to provide support for src parameter.

 


 

virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color) = 0

Implements DrawImageOp: Draws src part of Image img at x, y rescaling it to cx, cy (if they are equal to original Image size, no rescaling is performed). If color is not null, only alpha information of Image is used and color pixels are painted using color. Default implementation performs rescaling operation in software, including banding support for printer, then calls SysDrawImageOp.

 


 

virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id)

Implements DrawData operation. Draws arbitrary data of type id to rectangular area x,y,cx,cy. This can be used for example to print compressed bitmaps (e.g. in png format) directly, without the need of loading them to Image, this possibly saving memory requirements, as banding can be used to send the image to printer part by part. Actual painting process is implemented in DataDrawer and id has to be registered using DataDrawer::Register.

 


 

virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) = 0

Implements DrawLine operation. Draws line from x1,y1 to x2,y2 (included) width pixels wide, with color. Width can contain special values, in that case line with width 1 is drawn and special dash pattern is applied:

 

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 _.._.._..

 


 

virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) = 0

Implements DrawPolyPolyline operation: Draws a series of polylines. Polyline vertices are kept in the array vertices. The parameter vertex_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. The width parameter can be equal to the same PEN_* special values as width in DrawLineOp. Line is drawn with color, if doxor is not null, such color in the background gets inverted.

 


 

virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor) = 0

Implements DrawPolyPolyPolygon operation: Draws a series of complex polygons. 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 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).

 


 

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

Implements DrawArc operation: 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. width is the width of line, painted in color.

 


 

virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) = 0

Implements DrawEllipse operation: 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. If pen is not 0, Ellipse will be have border line of width pen and color pencolor.

 


 

virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) = 0

Implements DrawText operation:Draws a text at position starting at x, y (it represents top-left corner of text cell: for horizontal text, x identifies reference point and y is ascent above the baseline) going at angle using font and color ink. n is a number of characters to paint. If dx is not NULL, it specifies advancements of individual characters (it must be n elements in this array), otherwise advancements from font metrics are used.

 


 

virtual void DrawDrawingOp(const Rect& target, const Drawing& w)

Implements DrawDrawing operation: Draws Drawing w scaled into target. Base Draw provides default implementation of this function (in fact, it could most likely be non-virtual).

 


 

virtual void DrawPaintingOp(const Rect& target, const Painting& w)

Implements DrawPainting operation: Draws Drawing w scaled into target. Base Draw provides default implementation, which paints Painting using DrawImage, possibly using banding technique to reduce the memory requirements. Painter package has to be included in the project for this to work.

 


 

virtual Size GetNativeDpi() const

Returns native resolution of target device. Default implementation returns Size(600, 600) for Dots device and Size(96, 96) for screen output.

 


 

virtual void BeginNative()

Starts native resolution mode, if available. Can be called several times (only first call is effective). If device does not have native mode, it has no effect.

 


 

virtual void EndNative()

Ends native resolution mode. If BeginNative was called several times, has to be called the same number of times to end the native mode.

 


 

virtual int GetCloffLevel() const

Returns the number of elements in clip&offset stack. Mostly used for diagnostic purposes.

 


 

virtual void Escape(const String& data)

Passes additional information to Draw target instance. For example, PdfDraw understands "url:http://link.html" escapes to define text hyperlinks. Frontend to EscapeOp.

 


 

Size GetPixelsPerInch() const

Returns active resolution. Returns native resolution if native mode is active, or Size(600, 600) for physical output or Size(96, 96) for screen output.

 


 

Size GetPageMMs() const

Recomputes GetPageSize to millimeters.

 


 

bool Dots() const

Same as GetInfo() & DOTS. True for physical device.

 


 

bool Pixels() const

Same as !Dots(). True for screen output.

 


 

bool IsPrinter() const

Same as GetInfo() & PRINTER. True if output is printer.

 


 

bool IsNative() const

Same as GetInfo() & NATIVE. True if native resolution mode is active.

 


 

int GetNativeX(int xconst

Recomputes x from 600 dpi dots to native horizontal resolution.

 


 

int GetNativeY(int yconst

Recomputes y from 600 dpi dots to native vertical resolution.

 


 

void Native(int& x, int& yconst

Recomputes point coordinates from 600 dpi dots to native resolution.

 


 

void Native(Point& pconst

Recomputes point from 600 dpi dots to native resolution.

 


 

void Native(Size& szconst

Recomputes Size from 600 dpi dots to native resolution.

 


 

void Native(Rect& rconst

Recomputes Rect from 600 dpi dots to native resolution..

 


 

void Begin()

Pushes current offset and clipping settings on Draw's internal stack. Frontend to BeginOp.

 


 

void End()

Pops offset and clipping settings, restoring the status before pairing BeginOp, OffsetOp, ClipOp, ExcludeClipOp or IntersectClipOp. Frontend to EndOp.

 


 

void Offset(Point p)

void Offset(int x, int y)

Calls Begin and then offsets coordinates so that p or x,y becomes Point(0, 0). Uses OffsetOp for implementation. Frontend to OffsetOp.

 


 

bool Clip(const Rect& r)

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

Calls Begin and then restricts all painting operations to r or x,y,cx,cy rectangle - nothing is painted outside this rectangle. Frontend to ClipOp.

 


 

bool Clipoff(const Rect& r)

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

Implements ClipOff operation: Calls begin, then restricts all painting operations to r or x,y,cx,cy rectangle and offsets coordinates so that to left point of r or point x,y becomes Point(0, 0). Frontend to ClipoffOp.

 


 

bool ExcludeClip(const Rect& r)

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

Excludes r or rectangle x,y,cx,cy from the output - nothing is painted in this area. Does not affect the offset/clipping stack. This operation is only guaranteed to work in SystemDraw. Frontend to ExcludeClipOp.

 


 

bool IntersectClip(const Rect& r)

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

Intersects current clipping area with r or rectangle x,y,cx,cy. Does not affect the offset/clipping stack. This operation is only guaranteed to work in SystemDraw. Frontend to IntersectClipOp.

 


 

bool IsPainting(const Rect& rconst

bool IsPainting(int x, int y, int cx, int cyconst .

Tests whether that should any painting happen in r or rectangle x,y,cx,cy. For example, if Draw represents graphics output to window in Ctrl::Paint, not all areas are always required to be repainted. Frontend to IsPaintingOp.

 


 

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

void DrawRect(const Rect& rect, Color color)

Fills rect or rectangle x,y,cx,cy using color. As special addition, if Draw represents screen output in Ctrl::Paint, color can be assigned special value InvertColor() causing invertion of all pixels in target area. Frontend to DrawRectOp. Note: On some platform, using InvertColor might results in suboptimal performance.

 


 

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

void DrawImage(int x, int y, int cx, int cy, const Image& img)

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

void DrawImage(int x, int y, int cx, int cy, const Image& img, Color color)

void DrawImage(const Rect& r, const Image& img, const Rect& src)

void DrawImage(const Rect& r, const Image& img)

void DrawImage(const Rect& r, const Image& img, const Rect& src, Color color)

void DrawImage(const Rect& r, const Image& img, Color color)

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

void DrawImage(int x, int y, const Image& img)

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

void DrawImage(int x, int y, const Image& img, Color color)

Paints Image img. If target rectangle is present (r or x,y,cx,cy), Image is rescaled (using high quality filter) to fit the area (banding can be used in the process to reduce memory requirements). If only target point x,y is provided, Image is not rescaled. If src rectangle is provided, only that portion of Image is used. If color is provided, only alpha information is used and the color information is replaced with it. Frontend to DrawImageOp.

 


 

void DrawData(int x, int y, int cx, int cy, const String& data, const char *type)

void DrawData(const Rect& r, const String& data, const char *type)

Draws arbitrary data of type id to rectangular area r or x,y,cx,cy. This can be used for example to print compressed bitmaps (e.g. in png format) directly, without the need of loading them to Image, this possibly saving memory requirements, as banding can be used to send the image to printer part by part. Actual painting process is implemented in DataDrawer and id has to be registered using DataDrawer::Register. Frontend to DrawDataOp.

 


 

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

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

Draws line from x1,y1 or p1 to x2,y2 or p2 (included) width pixels wide, with color. Width can contain special values, in that case line with width 1 is drawn and special dash pattern is applied - see DrawLineOp for details. Frontend to DrawLineOp.

 


 

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

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 r (x,y,cx,cy), i.e. with center point at r.CenterPoint(), semi major axis and semi minor axis equal to r.Width() / 2 and r.Height() / 2. If pen is not 0, Ellipse will be have border line of width pen and color pencolor. Frontend to DrawEllipseOp.

 


 

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. width is the width of line, painted in color. Frontend to DrawArcOp.

 


 

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

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

Draws multiple polylines (polygon without filling).

 


 

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

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

Draws a polyline (polygon without filling).

 


 

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, uint64 pattern = 0, Color doxor = Null)

void DrawPolyPolyPolygon(const Vector<Point>& vertices, const Vector<int>& subpolygon_counts, const Vector<int>& disjunct_polygon_counts, Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null)

Draws poly-poly-polygon.

 


 

void DrawPolyPolygon(const Point *vertices, int vertex_count, const int *subpolygon_counts, int subpolygon_count_count, Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null)

void DrawPolyPolygon(const Vector<Point>& vertices, const Vector<int>& subpolygon_counts, Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null)

Draws poly-polygon.

 


 

void DrawPolygons(const Point *vertices, int vertex_count, const int *polygon_counts, int polygon_count_count, Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null)

void DrawPolygons(const Vector<Point>& vertices, const Vector<int>& polygon_counts, Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null)

Draws multiple polygons.

 


 

void DrawPolygon(const Point *vertices, int vertex_count, Color color = DefaultInk, int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null)

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

Draws a polygon.

 


 

void DrawDrawing(const Rect& r, const Drawing& iw)

void DrawDrawing(int x, int y, int cx, int cy, const Drawing& iw)

Draws Drawing iw scaled to rectangle r respectively x,y,cx,cy. Frontend to DrawDrawing op.

 


 

void DrawDrawing(int x, int y, const Drawing& iw)

Draws Drawing iw at x,y, using its original size. Frontend to DrawDrawing op.

 


 

void DrawPainting(const Rect& r, const Painting& iw)

void DrawPainting(int x, int y, int cx, int cy, const Painting& iw)

void DrawPainting(int x, int y, const Painting& iw)

Draws Painting iw scaled to rectangle r respectively x,y,cx,cy. Painter package has to be included in the project for this to work. Variant without cx,cy paints Painting in its original size. Frontend to DrawPaintingOp.

 


 

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

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

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

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

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

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

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

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

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

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

Draws a text at position starting at x,y (it represents top-left corner of text cell: for horizontal text, x identifies reference point and y is ascent above the baseline) going at angle using font and color ink. n is a number of characters to paint, if negative, it is retrieved using [w]strlen. If dx is not NULL, it specifies advancements of individual characters (it must be n elements in this array), otherwise advancements from font metrics are used. For 8-bit texts (text is String or const char *), if charset is present, text is converted from this charset before printing, if no charset is specified, default charset is used. DrawText also performs missing glyph replacement and composition. If Draw::GetInfo() returns DRAWTEXTLINES, DrawText uses DrawLine to provide support for Undeline and Strikeout Font styles. DrawText calls DrawTextOp for low-level glyph rendering.

 


 

static void SinCos(int angle, double& sina, double& cosa)

This simple utility function computes sin(angle) and cos(angle), where the full angle (2π) is 3600.

 

 

Do you want to contribute?