Defines a cross-library (VCL or FMX) type for a rectangle. In VCL, the rectangle used in canvas functions is a TRect. In FMX, the rectangle used in canvas functions is a TRectF.
Use this type to create code that can copy and paste between libraries.
Namespace: RSGraphics
Delphi
|
type
TCanvasRect = TRect;
|
The following is a example of using the CanvasXXX types, constants, and functions to write cross-library graphics code:
Delphi
|
{$DEFINE FMX} // should only define in FMX applications only
var
CenterPt: TCanvasPoint;
LowerRightQuadrant: TCanvasRect;
begin
// get center point using cross-library CenterPoint
CenterPt := CanvasCenterPoint(ARect);
// create a rectangle using cross-library Rect
LowerRightQuadrant := CanvasRect(CenterPt.X, CenterPt.Y, ARect.Right, ARect.Bottom);
// FMX does not have Canvas.Pen property, it is exposed by FMX.RS.CanvasHelper
// as equivalent to Canvas.Stroke
// clxCOLORS are from RSGraphics
Canvas.Pen.Color := clxBlue;
// FMX does not have Canvas.Brush property, it is exposed in FMX.RS.CanvasHelper
// as equivalent to Canvas.Fill
Canvas.Brush.Color := clxRed;
{$IFDEF FMX}
Canvas.StrokeDash := TStrokeDash.sdDash; // <--- not cross-library compatible
{$ELSE}
Canvas.Pen.Style := psDash; // <--- not cross-library compatible
{$ENDIF}
// FMX does not have Canvas.Rectangle method, added in FMX.RS.CanvasHelper
Canvas.Rectangle(LowerRightQuadrant);
// Move text down by around a third of width/height of LowerRightQuadrant, use
// CanvasDiv function from RSGraphics to make the code cross-library
Canvas.TextOut( CenterPt.X + CanvasDiv(LowerRightQuadrant.Width,3.3),
CenterPt.Y + CanvasDiv(LowerRightQuadrant.Height,3.3),
'Hello World' );
end;
|
|
Reference
•RSGraphics.TCanvasPixel •RSGraphics.TCanvasPoint •RSGraphics.TCanvasSize •RSGraphics.CanvasRect(Single,Single,Single,Single) •RSGraphics.RectGradient(TCanvas,TCanvasRect,TCanvasColor[],Integer,Single) •RSGraphics.ProgressPie(TCanvas,TCanvasRect,Integer,Integer,Integer,Integer,TColors,Boolean,Integer,Integer,TProgressDirection,TProgressDisplayType) •RSGraphics.DrawShape(TCanvas,TCanvasRect,TBitmap,TRSShapeStyle,Boolean,TCanvasColor,TCanvasColor,TCanvasPixel,Single) •RSGraphics |