Sign in Join
Wiki copytemporary

Skia: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# Overview
22
33[Skia](https://skia.org)is an open source cross platform 2D graphics library used for example by Chrome and Firefox.
44
55The [skia4delphi](https://skia4delphi.org/)project provides shared and static libraries and Pascal units to access Skia with FPC and Delphi.
66
77In lazarus-ccr there are Lazarus packages and LCL components.
88
99# Setup
1010
1111## Requirements
1212
1313- FPC 3.3.1
1414- If you want to install the design time package, the IDE must be compiled with fpc 3.3.1.
1515
1616## Download sk4d dynamic library
1717
1818The sk4d dynamic library is provided by the skia4delphi project. Their installer is for Windows Delphi users. For Lazarus download the sources or clone the git:
1919
20201. Go to <https://github.com/skia4delphi/skia4delphi/releases>
21212. Download the Source code (zip)
22223. Unpack the skia4delphi-6.1.0.zip
23234. You will find the sk4d library in Binary/Shared/YourPlatform
2424
2525Your project must be able to find the library:
2626
2727- Linux: Set the LD_LIBRARY_PATH variable:
2828
29-`bash: export LD_LIBRARY_PATH=/home/user/skia4delphi-6.1.0/Binary/Shared/Linux64/`
29+```text
30+bash: export LD_LIBRARY_PATH=/home/user/skia4delphi-6.1.0/Binary/Shared/Linux64/
31+```
3032
3133- MacOS: Copy the skia4delphi-6.1.0/Binary/Shared/OSX64/libsk4d.dylib to the project folder or create a symlink
3234- Windows: Copy the skia4delphi-6.1.0/Binary/Shared/Win64/sk4d.dll to the project folder
3335
3436## Download the Lazarus packages
3537
3638Download lazarus-ccr via svn:
3739
38-`svn checkout `[`https://svn.code.sf.net/p/lazarus-ccr/svn/`](https://svn.code.sf.net/p/lazarus-ccr/svn/)` lazarus-ccr-svn`
40+```text
41+svn checkout https://svn.code.sf.net/p/lazarus-ccr/svn/ lazarus-ccr-svn
42+```
3943
4044The skia files are in the directory lazarus-ccr-svn/components/skia .
4145
4246There are three Lazarus packages:
4347
4448- design/Skia.LCL.Design.lpk - the IDE addon
4549- src/Skia.LCL.lpk - contains the LCL controls like TSkPaintBox and TSkCustomWinControl
4650- skia4d_package/Skia.lpk - the units from skia4delphi
4751
4852## Install Skia.LCL.Design
4953
5054This is optional.
5155
5256Requirements:
5357
5458- The IDE is compiled with fpc 3.3.1
5559- the sk4d library can be found by the Lazarus executable, otherwise the IDE will not start.
5660
5761Install the package Skia.LCL.Design.lpk in the IDE:
5862
5963- Open the design/Skia.LCL.Design.lpk via IDE menu *Package / Open Package File (lpk)*
6064- Then click the button *Use* and *Install*
6165- Restart the IDE
6266
6367You will find a new page **Skia** in the component palette.
6468
6569# TSkPaintBox
6670
6771This is a TGraphicControl - a lcl control without its own handle. Useful if you just want to draw something with skia. Set the OnDraw event
6872
6973``` pascal
7074procedure TForm1.FormCreate(Sender: TObject);
7175begin
7276 MySkPaintBox:=TSkPaintBox.Create(Self);
7377 with MySkPaintBox do begin
7478 Name:='MySkPaintBox';
7579 OnDraw:=@MySkPaintBoxDraw;
7680 SetBounds(10,10,50,50);
7781 Parent:=Self;
7882 end;
7983end;
8084
8185procedure TForm1.MySkPaintBoxDraw(Sender: TObject; const aCanvas: ISkCanvas; const aDest: TRectF; const aOpacity: Single);
8286begin
8387 aCanvas.Clear(TAlphaColors.Red);
8488end;
8589```
8690
8791Note: the Opacity is not yet supported.
8892
8993# TSkCustomWinControl
9094
9195This is TCustomControl - a lcl base class for custom controls with own handle and scrollbars. Override the DrawContent and Invalidate methods:
9296
9397``` pascal
9498type
9599 TMySkiaControl = class(TSkCustomWinControl)
96100 public
97101 procedure DrawContent(const ACanvas: ISkCanvas; const {%H-}ADest: TRectF;
98102 const AOpacity: Single); override;
99103 procedure Invalidate; override;
100104 end;
101105...
102106
103107procedure TMySkiaControl.DrawContent(const ACanvas: ISkCanvas; const ADest: TRectF; const AOpacity: Single);
104108begin
105109 // your drawing code
106110 aCanvas.Clear(TAlphaColors.White);
107111end;
108112
109113procedure TMySkiaControl.Invalidate;
110114begin
111115 inherited Invalidate;
112116 Render.Redraw; // force a redraw
113117end;
114118```
115119
116120Note: the Opacity is not yet supported.
117121
118122---
119123*From the Free Pascal wiki, page "Skia", as it stood on 2024-04-26 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history