lazarus-ccr/components/skia/demo/paintbox/unit1.pas
mgaertner efda057bcc added skia
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9338 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2024-04-24 14:12:06 +00:00

119 lines
2.6 KiB
ObjectPascal

{
Demo for the LCL TSkPaintBox
}
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Types, Forms, Controls, Graphics, Dialogs, LCL.Skia,
System.Skia, system.UITypes;
type
{ TSkiaLCLPaintBoxDemo }
TSkiaLCLPaintBoxDemo = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure OnSkPaintBoxDraw(Sender: TObject; const aCanvas: ISkCanvas;
const {%H-}aDest: TRectF; const {%H-}aOpacity: Single);
public
LogoPNG: ISkImage;
SkPaintBox: TSkPaintBox;
end;
var
SkiaLCLPaintBoxDemo: TSkiaLCLPaintBoxDemo;
implementation
{$R *.lfm}
{ TSkiaLCLPaintBoxDemo }
procedure TSkiaLCLPaintBoxDemo.FormCreate(Sender: TObject);
var
ms: TMemoryStream;
begin
SkPaintBox:=TSkPaintBox.Create(Self);
with SkPaintBox do
begin
Name:='SkPaintBox';
Align:=alClient;
OnDraw:=@OnSkPaintBoxDraw;
Parent:=Self;
end;
ms:=TMemoryStream.Create;
try
ms.LoadFromFile('powered_by.png');
ms.Position := 0;
LogoPNG := TSkImage.MakeFromEncodedStream(ms);
finally
ms.Free;
end;
end;
procedure TSkiaLCLPaintBoxDemo.FormDestroy(Sender: TObject);
begin
LogoPNG:=nil;
end;
procedure TSkiaLCLPaintBoxDemo.OnSkPaintBoxDraw(Sender: TObject;
const aCanvas: ISkCanvas; const aDest: TRectF; const aOpacity: Single);
var
SkPaint, SkPaint2: ISkPaint;
r: TRectF;
Oval: ISkRoundRect;
aPathBuilder: ISkPathBuilder;
aPath: ISkPath;
aTypeface: ISkTypeface;
aFont: ISkFont;
aTextBlob: ISkTextBlob;
begin
aCanvas.Clear(TAlphaColors.White);
SkPaint:=TSkPaint.Create(TSkPaintStyle.Stroke);
SkPaint.SetAntiAlias(true);
SkPaint.setStrokeWidth(4);
SkPaint.setColor(TAlphaColors.Red);
r:=RectF(50, 50, 90, 110);
aCanvas.DrawRect(r, SkPaint);
Oval:=TSkRoundRect.Create;
Oval.SetOval(r);
Oval.Offset(40,60);
SkPaint.setColor(TAlphaColors.Blue);
aCanvas.DrawRoundRect(Oval, SkPaint);
SkPaint.setColor(TAlphaColors.Cyan);
aCanvas.DrawCircle(180, 50, 25, SkPaint);
r.offset(80, 0);
SkPaint.setColor(TAlphaColors.Yellow);
aCanvas.DrawRoundRect(r, 10, 10, SkPaint);
aPathBuilder:=TSkPathBuilder.Create;
aPathBuilder.cubicTo(768, 0, -512, 256, 256, 256);
aPath:=aPathBuilder.Detach;
SkPaint.setColor(TAlphaColors.Lime);
aCanvas.DrawPath(aPath, SkPaint);
aCanvas.DrawImage(LogoPNG, 128, 128);
aTypeface := TSkTypeface.MakeFromName('Monospace', TSkFontStyle.Normal);
aFont := TSkFont.Create(aTypeface, 18, 1);
aFont.Edging := TSkFontEdging.AntiAlias;
SkPaint2:=TSkPaint.Create;
aTextBlob:=TSkTextBlob.MakeFromText('Hello, Skia!',aFont);
aCanvas.DrawTextBlob(aTextBlob, 50, 25, SkPaint2);
end;
end.