Draw the sibling svg elements (and their children) of the specified element (i.e., the elements that have the same parent but are before the specified element in the parent's Items property) to the specified canvas inside the specified rectangle.
The ancestors of the specified element are also drawn. The svg sibling elements are drawn where they would be if the entire SVG was drawn.
Namespace: FMX.RS.SVG
Parameters
Element
Type: TSVGGraphicElement
Draw "older" siblings (and ancestors)of this element
aMatrix
Type: System.Void
cumulative transformations from the Parent element (and its Parents) to apply when drawing the element.
Canvas
Type: System.Void
Canvas to draw on
aRect
Type: System.Void
Rectangle to draw within
IncludeElement
Type: Boolean
Draw element and its children as well
The following example uses the DrawBeforeElement, DrawElement, and DrawAfterElement methods to optimize the drawing of an svg where one element may be changed often (such as in an editor):
Delphi
|
procedure TfrmSVGEditor.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
var
aRect: TSVGRect;
begin
// do we need to update the background (elements before) and foreground (elements
// after) the current Element. By creating a bitmap of the background and
// foreground, we can optimize the drawing of the SVG as the current Element
// changes
if UpdateBackground then
begin
// draw background and foreground
Background.Canvas.BeginScene;
try
Background.Clear(TAlphaColorRec.Null);
if Element is TSVGGraphicElement then
SVG.DrawBeforeElement(TSVGGraphicElement(Element), Background.Canvas, RectF(0,0,Background.Width, Background.Height));
finally
Background.Canvas.EndScene;
end;
Foreground.Canvas.BeginScene;
try
Foreground.Clear(TAlphaColorRec.Null);
if Element is TSVGGraphicElement then
SVG.DrawAfterElement(TSVGGraphicElement(Element), Foreground.Canvas, RectF(0,0,Foreground.Width, Foreground.Height));
finally
Foreground.Canvas.EndScene;
end;
FUpdateBackground := False;
end;
if Element is TSVGGraphicElement then
begin
// if current Element is a graphical element, draw the background
aRect := RectF(0, 0, Background.Width, Background.Height);
Canvas.DrawBitmap(Background, aRect, aRect, 1);
// draw the element
SVG.DrawElement(TSVGGraphicElement(Element), Canvas, PaintBox1.ClipRect);
// draw the foreground
Canvas.DrawBitmap(Foreground, aRect, aRect, 1);
end
else
// just draw the entire SVG without any background/foreground caching
SVG.Draw(Canvas, PaintBox1.ClipRect);
// draw the focus rectangle
Canvas.DrawFocusRect(SelectRect);
end;
|
|