Codebot.Graphics unit

Here is a very small clip of the advanced drawing interface which will be released in the new revision of Cross Codebot. Backends have been implemented for Gdi+ and Direct2D on Windows, Cairo on Linux, and Quartz2D on Macintosh.
Click here to watch an old video made 3 years ago, but still relevant. We are producing some new videos which actually will walk users through not only the new graphic interfaces and some demo programs, but also our new control Library built on top of these interfaces. If you interested in seeing some of the old components they were previously produced for Delphi and are still listed here. The component listing has doubled since the last release listed on codebot.org.

Surface interface listing


{ Create a new matrix }
function NewMatrix: IMatrix;
{ Create a new pen using a brush as the color }
function NewPen(Brush: IBrush; Width: Float = 1): IPen; overload;
{ Create a new solid color pen }
function NewPen(Color: TColorB; Width: Float = 1): IPen; overload;
{ Create a new solid color brush }
function NewBrush(Color: TColorB): ISolidBrush; overload;
{ Create a new bitmap pattern brush }
function NewBrush(Bitmap: IBitmap): IBitmapBrush; overload;
{ Create a new linear gradient brush using four coordinates for endpoints }
function NewBrush(X1, Y1, X2, Y2: Float): ILinearGradientBrush; overload;
{ Create a new linear gradient brush using two points for endpoints }
function NewBrush(const A, B: TPointF): ILinearGradientBrush; overload;
{ Create a new radial gradient brush bounded by a rect }
function NewBrush(const Rect: TRectF): IRadialGradientBrush; overload;
{ Create a new font by copying a regular font object }
function NewFont(Font: TFont): IFont;
{ Create a new canvas using a regular canvas object }
function NewSurface(Canvas: TCanvas): ISurface; overload;
{ Create a new canvas using a window }
function NewSurface(Control: TWinControl): ISurface; overload;
{ Create a new bitmap of width and height size }
function NewBitmap(Width, Height: Integer): IBitmap;
{ Create a new splash screen }
function NewSplash: ISplash;

{ IMatrix }

type
  IMatrix = interface(ICloneable<IMatrix>)
  ['{2918AB0D-E288-4E5C-8FDE-67776EC7CFAD}']
    procedure Identity;
    procedure Multiply(M: IMatrix);
    procedure Translate(X, Y: Float);
    procedure Scale(X, Y: Float);
    procedure Rotate(Angle: Float);
  end;

{ IPen }

  TLinePattern = (pnSolid, pnDash, pnDot, pnDashDot);
  TLineCap = (cpButt, cpRound, cpSquare);
  TLineJoin = (jnMiter, jnRound, jnBevel);

  IPen = interface
  ['{F702E75F-684F-4D02-9A51-682A154DD9D5}']
    function GetBrush: IBrush;
    procedure SetBrush(Value: IBrush);
    function GetColor: TColorB;
    procedure SetColor(Value: TColorB);
    function GetWidth: Float;
    procedure SetWidth(Value: Float);
    function GetLinePattern: TLinePattern;
    procedure SetLinePattern(Value: TLinePattern);
    function GetLinePatternOffset: Float;
    procedure SetLinePatternOffset(Value: Float);
    function GetLineCap: TLineCap;
    procedure SetLineCap(Value: TLineCap);
    function GetLineJoin: TLineJoin;
    procedure SetLineJoin(Value: TLineJoin);
    function GetMiterLimit: Float;
    procedure SetMiterLimit(Value: Float);
    property Brush: IBrush read GetBrush write SetBrush;
    property Color: TColorB read GetColor write SetColor;
    property Width: Float read GetWidth write SetWidth;
    property LinePattern: TLinePattern read GetLinePattern write SetLinePattern;
    property LinePatternOffset: Float read GetLinePatternOffset write SetLinePatternOffset;
    property LineCap: TLineCap read GetLineCap write SetLineCap;
    property LineJoin: TLineJoin read GetLineJoin write SetLineJoin;
    property MiterLimit: Float read GetMiterLimit write SetMiterLimit;
  end;

{ IBrush }

  IBrush = interface
  ['{77B25395-F891-4526-A941-77C200C3F08F}']
    function GetMatrix: IMatrix;
    procedure SetMatrix(Value: IMatrix);
    function GetOpacity: Byte;
    procedure SetOpacity(Value: Byte);
    property Matrix: IMatrix read GetMatrix write SetMatrix;
    property Opacity: Byte read GetOpacity write SetOpacity;
  end;

{ ISolidBrush }

  ISolidBrush = interface(IBrush)
  ['{8F520DF0-C9F7-4C5E-8954-9A62179BB84F}']
    function GetColor: TColorB;
    procedure SetColor(Value: TColorB);
    property Color: TColorB read GetColor write SetColor;
  end;

{ IBitmapBrush }

  IBitmapBrush = interface(IBrush)
  ['{3199CC5B-5B41-4E91-BDD0-17FAB1E91ABA}']
  end;

{ IGradientBrush }

  TGradientWrap = (gwClamp, gwRepeat, gwReflect);

  IGradientBrush = interface(IBrush)
  ['{B3870AD1-4A48-4A0A-AC39-13DD43501E63}']
    function GetWrap: TGradientWrap;
    procedure SetWrap(Value: TGradientWrap);
    procedure AddStop(Color: TColorB; Offset: Float);
    property Wrap: TGradientWrap read GetWrap write SetWrap;
  end;

{ ILinearGradientBrush }

  ILinearGradientBrush = interface(IGradientBrush)
  ['{EBEC24AC-6BE7-44D1-BA4F-F11B8A206DEA}']
  end;

{ IRadialGradientBrush }

  IRadialGradientBrush = interface(IGradientBrush)
  ['{A8B230B8-4CD4-4C51-878A-D1448077F0C3}']
  end;

{ IFont }

  IFont = interface
  ['{9ACA722A-6DDE-4C15-89E0-47DD1B86B981}']
    function GetName: string;
    function GetColor: TColorB;
    procedure SetColor(Value: TColorB);
    function GetStyle: TFontStyles;
    procedure SetStyle(Value: TFontStyles);
    function GetSize: Float;
    procedure SetSize(Value: Float);
    property Name: string read GetName;
    property Color: TColorB read GetColor write SetColor;
    property Style: TFontStyles read GetStyle write SetStyle;
    property Size: Float read GetSize write SetSize;
  end;

{ IPathData }

  IPathData = interface
  ['{C2887F8D-D729-427D-90C2-F9B081697CAB}']
  end;

{ IPath }

  IPath = interface(ICloneable<IPathData>)
  ['{E2E7EC9A-74BA-4614-8809-7D828E30DD51}']
    procedure Add;
    procedure Remove;
    procedure Close;
    procedure Join(Path: IPathData);
    procedure Clip;
    procedure Unclip;
  end;

{ ISurface is the main interface used to draw high quality fast vector graphics }

  ISurface = interface
  ['{6C23D3BC-6D74-4EDD-B0B9-EB55BF655E80}']
    function GetMatrix: IMatrix;
    procedure SetMatrix(Value: IMatrix);
    function GetPath: IPath;
    procedure Flush;
    procedure Clear(Color: TColorB);
    procedure CopyTo(const Source: TRectF; Surface: ISurface; const Dest: TRectF; Alpha: Byte = $FF);
    procedure Save;
    procedure Restore;
    procedure MoveTo(X, Y: Float);
    procedure LineTo(X, Y: Float);
    procedure ArcTo(const Rect: TRectF; BeginAngle, EndAngle: Float);
    procedure CurveTo(X, Y: Float; const C1, C2: TPointF);
    procedure Ellipse(const Rect: TRectF);
    procedure Rectangle(const Rect: TRectF);
    procedure RoundRectangle(const Rect: TRectF; Radius: Float);
    function TextSize(Font: IFont; const Text: string): TPointF;
    function TextHeight(Font: IFont; const Text: string; Width: Float): Float;
    procedure TextOut(Font: IFont; const Text: string; const Rect: TRectF;
      Direction: TDirection; Immediate: Boolean = True);
    procedure Stroke(Pen: IPen; Preserve: Boolean = False);
    procedure Fill(Brush: IBrush; Preserve: Boolean = False);
    procedure StrokeRect(Pen: IPen; const Rect: TRectF);
    procedure FillRect(Brush: IBrush; const Rect: TRectF);
    procedure StrokeRoundRect(Pen: IPen; const Rect: TRectF; Radius: Float);
    procedure FillRoundRect(Brush: IBrush; const Rect: TRectF; Radius: Float);
    property Matrix: IMatrix read GetMatrix write SetMatrix;
    property Path: IPath read GetPath;
  end;

{ IBitmap can load and save images as well as allow ISurface drawing in memory }

  TImageFormat = (fmPng, fmJpeg, fmGif, fmBmp, fmIco, fmTiff);
  TResampleQuality = (rqLowest, rqNormal, rqBest);

  IBitmap = interface(ICloneable<IBitmap>)
  ['{DB935633-A218-4181-96A2-B0808697150F}']
    function GetEmpty: Boolean;
    function GetSurface: ISurface;
    function GetClientRect: TRectI;
    function GetFormat: TImageFormat;
    procedure SetFormat(Value: TImageFormat);
    function GetHeight: Integer;
    function GetWidth: Integer;
    function GetPixels: PPixel;
    procedure Clear;
    function Resample(Width, Height: Integer; Quality: TResampleQuality = rqNormal): IBitmap;
    procedure LoadFromFile(const FileName: string);
    procedure LoadFromStream(Stream: TStream);
    procedure SaveToFile(const FileName: string);
    procedure SaveToStream(Stream: TStream);
    procedure SetSize(Width, Height: Integer);
    property Empty: Boolean read GetEmpty;
    property Surface: ISurface read GetSurface;
    property ClientRect: TRectI read GetClientRect;
    property Format: TImageFormat read GetFormat write SetFormat;
    property Width: Integer read GetWidth;
    property Height: Integer read GetHeight;
    property Pixels: PPixel read GetPixels;
  end;

type
  TSurfaceOptions = record
    { Use hardware rendering when possbile }
    HardwareRendering: Boolean;
    { Use double buffering if hardware rendering is not supported }
    SoftwareBuffering: Boolean;
    { Correct small render errors with possible degraded performance or loss of
      features. Enabling this causes text to fill the current path immediately,
      which in Windows has the effect of nicer text when unscaled or rotated. }
    ErrorCorrection: Boolean;
    { Use gamma corrected gradients on supported back ends }
    GammaCorrection: Boolean;
  end;

var
  SurfaceOptions: TSurfaceOptions = (
    HardwareRendering: True;
    SoftwareBuffering: False;
    ErrorCorrection: False;
    GammaCorrection: False;
  );