![]() |
|||||||
|
Welcome to the TAgg2D Documentation Tutorial !
This documentation tries to provide a complete resource about vector graphics in relation to the AggPas open source library. Each API command (over 100) is documented, almost all have also a commented example. Some examples can be downloaded directly, and for the others the drawing routine can be cut and pasted to see it in action. This documentation is not a part of AggPas library, because I plan to make improvements over time and I want to make it independent from the main software distribution package. Where apropriate, I link directly to the articles on www.antigrain.com site containing excellent informations on some of the topics. If You are a vector graphics beginner, You can read this documentation from top to bottom, try out all of the examples and at the end, you should understand all important concepts. On top of that if You will read this document carefully, You will discover also how to do some nice little tricks (like reflections). Don't hesitate to send me Your comments. Enjoy, Milano. |
Example download: |
| TAgg2D - Functionality & Capabilities | ||
|
| TAgg2D - Introduction to the Application Programming Interface (API) | ||
To use TAgg2D vector graphics engine in your software project you just:
TAgg2D is located in the file "Agg2D.pas" which
is in "../src" subdirectory. So the whole setup of AggPas library is to add
a search path to "../AggPas24-rm3/src" and to include AggPas with
"uses Agg2D" clause.
It is recommended to create each instance of TAgg2D just once for the whole life of TForm. More instances of TAgg2D can coexist simultaneously and they can be attached to the same TBitmap surface at the same time. It's sence is in having a different states of vector engine in one place (each instance can have a different state of coordinates transformations for example, or anything that can be set up). TAgg2D is not thread safe, so each thread should own it's own vector engine. After attachement (to the TBitmap) the state of the vector engine becomes default. It's due to achieving the same starting conditions for the drawing routine. So you have to set up the line color, fill rule, transformations, clipping, etc. Since TAgg2D renders on fly directly to the physical surface of TBitmap, the drawing routine (after attachement) can be performed anytime it is required. It can be outside the OnPaint method and also outside WM_PAINT windows message. But as well it can be also a part of those painting methods. Here is an introductory example of drawing with TAgg2D: Which results in:if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll (255 ,255 ,255 ); VG.LineWidth(10 ); VG.LineColor($32 ,$cd ,$32 ); VG.FillColor($ff ,$d7 ,$00 ); VG.Star(100 ,100 ,30 ,70 ,55 ,5 ); end;
|
| TAgg2D API Overview | ||
Vector Graphics Engine Initialization
Attach (bitmap, flip_y ) : booleanMaster Rendering Properties BlendMode (m )Affine Transformations Transformations : TAggTransformations [*]Coordinates Conversions WorldToScreen (x, y )Clipping ClipBox (x1, y1, x2, y2 )Basic Shapes Line (x1, y1, x2, y2 )Path Commands ResetPathText Rendering FlipText (flip )Image Rendering ImageFilter (f )Standalone API Deg2Rad (v ) : doubleAPI Related Types TAggColor |
| TAgg2D.ClipBox : TAggRectD [*] | ||
Description
Retrieves the current clipping area rectangle.Returns Returned is data structure with clipping rectangle coordinates [in pixels]. |
|
TAgg2D.ClearAll
(c ) TAgg2D.ClearAll (r, g, b, a ) |
||
Description
Erases the whole surface of attached TBitmap to the color provided.Parameters c : TAggColor [*]Example if VG.Attach(Image1.Picture.Bitmap ) then begin // Erasing whole background to Fuchsia VG.ClearAll(255 ,0 ,255 ); end; |
|
TAgg2D.ClearClipBox
(c ) TAgg2D.ClearClipBox (r, g, b, a ) |
||
Description
Erases the area defined by clipping rectangle with provided color. If there is no clipping rectangle defined yet, whole surface of attached TBitmap is considered to be the clipping rectangle.Parameters c : TAggColor [*]Example if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll (255 ,255 ,255 ); VG.ClipBox(50 ,50 ,140 ,140 ); // Erasing clipping box to Fuchsia VG.ClearClipBox(255 ,0 ,255 ); end; |
| TAgg2D.AlignPoint (x, y ) | ||
Description
Due to the Anti Aliasing technique (that's heavily used in AGG), it may be sometimes hard to achieve rendering of lines, that are eg. exactly 1 pixel wide.Parameters x : PDoubleExample var x1 ,y1 ,x2 ,y2 : double; if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Initial coordinates x1:=10; y1:=30; x2:=150; y2:=30; // This line seems to be bold with line width = 1 VG.Line(x1 ,y1 ,x2 ,y2 ); // We correct coordinates VG.AlignPoint(@x1 ,@y1 ); VG.AlignPoint(@x2 ,@y2 ); // We shift coordinates down to see the result beneath VG.Translate(0 ,50 ); // After correction, // this line seems to be ok with line width = 1 VG.Line(x1 ,y1 ,x2 ,y2 ); end; |
| TAgg2D.BlendMode (m ) | ||
Description
Changes the general rendering composition mode (compliant with SVG). This method applies only to the TBitmap surfaces with Alpha channel present (pf32bit).Parameters m : TAggBlendMode [*]Example if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Draw basic blue rectangle VG.NoLine; VG.FillColor(0 ,0 ,255 ); VG.Rectangle(50 ,50 ,150 ,150 ); // Rotate coordinates by 45 degrees VG.Translate(-ClientWidth / 2 ,-ClientHeight / 2 ); VG.Rotate (Deg2Rad(45 ) ); VG.Translate(ClientWidth / 2 ,ClientHeight / 2 ); // Changing the general composition mode VG.BlendMode(AGG_BlendContrast ); // Draw the same blue rectangle but with red color // Result comes from applying composition mode VG.FillColor(255 ,0 ,0 ); VG.Rectangle(50 ,50 ,150 ,150 ); end; More complex example:
|
| TAgg2D.BlendMode : TAggBlendMode [*] | ||
Description
Retrieves the current general composition mode.Returns Returned is constant identifying the current general composition mode. |
| TAgg2D.AntiAliasGamma (g ) | ||
Description
Changes the value of Anti Alias Gamma correction.Parameters g : doubleExample For Gamma correction demo see the example 08 above. |
|
TAgg2D.FillColor
(c ) TAgg2D.FillColor (r, g, b, a ) |
||
Description
Changes the color used to fill interior of objects being drawn.Parameters c : TAggColor [*]Example if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Changing fill color to HTML color Gold #FFD700 VG.FillColor($FF ,$D7 ,$00 ); VG.Rectangle(30 ,30 ,180 ,80 ); // Adding Alpha Transparency to previous fill color VG.Translate(0 ,80 ); VG.FillColor($FF ,$D7 ,$00 ,128 ); VG.Rectangle(30 ,30 ,180 ,80 ); end; |
| TAgg2D.FillColor : TAggColor [*] | ||
Description
Retrieves the current color used to fill interior of objects being drawn.Returns Returned is Fill color in one data structure (r,g,b,a). |
|
TAgg2D.LineColor
(c ) TAgg2D.LineColor (r, g, b, a ) |
||
Description
Changes the color used on stroke of objects being drawn.Parameters c : TAggColor [*]Example if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Changing Line color to HTML color Medium Blue #0000CD VG.LineColor($00 ,$00 ,$CD ); VG.Rectangle(30 ,30 ,180 ,80 ); // Adding Alpha Transparency to previous Line color VG.Translate(0 ,80 ); VG.LineColor($00 ,$00 ,$CD ,128 ); VG.Rectangle(30 ,30 ,180 ,80 ); end; |
| TAgg2D.LineColor : TAggColor [*] | ||
Description
Retrieves the current color used on stroke of objects being drawn.Returns Returned is Line color in one data structure (r,g,b,a). |
| TAgg2D.FillLinearGradient (x1, y1, x2, y2, c1, c2, profile ) | ||
Description
Linear fill gradient increases linearly along the line from starting to ending point and it is constant along perpendicular lines.Parameters x1 : doubleExample if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Gradient colors - from Red to Yellow c1.Construct(255 ,0 ,0 ); c2.Construct(255 ,255 ,0 ); // Gradient proceeds from Top Left corner (10:10) // to the Bottom Right corner // (ClientWidth - 10:ClientHeight - 10) VG.FillLinearGradient( 10 ,10 , ClientWidth - 10 , ClientHeight - 10 , c1 ,c2 ,0.9 ); // Gradient appears as a filling of objects // consequently being drawn VG.Rectangle( 10 ,10 , ClientWidth - 10 , ClientHeight - 10 ); end; Remarks One important note about gradients in TAgg2D is that gradients are defined per surface and not per rendering object. Gradient location and dimensions relates to origin of surface and coordinates transformations transform also gradients definition. So after setup of one gradient (for fill or stroke) a series of drawing shapes will render across the last defined gradient. |
| TAgg2D.LineLinearGradient (x1, y1, x2, y2, c1, c2, profile ) | ||
Description
Linear line gradient increases linearly along the line from starting to ending point and it is constant along perpendicular lines.Parameters x1 : doubleExample if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Turn off filling & Set wide stroke VG.NoFill; VG.LineWidth(20 ); // Gradient colors // from DeepSkyBlue #00BFFF - DarkRed #8B0000 c1.Construct($00 ,$BF ,$FF ); c2.Construct($8B ,$00 ,$00 ); // Gradient proceeds from Top Left corner (20:20) // to the Bottom Right corner // (ClientWidth - 20:ClientHeight - 20) VG.LineLinearGradient( 20 ,20 , ClientWidth - 20 , ClientHeight - 20 , c1 ,c2 ,0.9 ); // Gradient appears as a filling of objects stroke VG.Rectangle( 20 ,20 , ClientWidth - 20 , ClientHeight - 20 ); end; |
| TAgg2D.FillRadialGradient (x, y, r, c1, c2, profile ) | ||
Description
Radial fill gradient produces equally proportioned circles of colors increasing from the origin to the outer bound.Parameters x : doubleExample if VG.Attach(Image1.Picture.Bitmap ) then begin VG.ClearAll(255 ,255 ,255 ); // Gradient colors // from DeepSkyBlue #00BFFF - Red #FF0000 c1.Construct($00 ,$BF ,$FF ); c2.Construct($FF ,$00 ,$00 ); // Gradient proceeds from center point // (ClientWidth / 2:ClientHeight / 2 ) // with extent of (ClientWidth - 30 ) / 2 VG.FillRadialGradient( ClientWidth / 2 ,ClientHeight / 2 , (ClientWidth - 30 ) / 2 , c1 ,c2 ,1.0 ); // Gradient appears as a filling of objects being drawn VG.Ellipse( ClientWidth / 2 ,ClientHeight / 2 , (ClientWidth - 30 ) / 2 , (ClientWidth - 30 ) / 2 ); end; |