Sign in Join
Wiki copytemporary

Skia: what changed

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

Title: Skia

OldNewLine
1+# Overview
2+
3+[Skia](https://skia.org)is an open source cross platform 2D graphics library used for example by Chrome and Firefox.
4+
5+The [skia4delphi](https://skia4delphi.org/)project provides shared and static libraries and Pascal units to access Skia with FPC and Delphi.
6+
7+In lazarus-ccr there are Lazarus packages and LCL components.
8+
9+# Setup
10+
11+## Requirements
12+
13+- FPC 3.3.1
14+- If you want to install the design time package, the IDE must be compiled with fpc 3.3.1.
15+
16+## Download sk4d dynamic library
17+
18+The 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:
19+
20+1. Go to <https://github.com/skia4delphi/skia4delphi/releases>
21+2. Download the Source code (zip)
22+3. Unpack the skia4delphi-6.1.0.zip
23+4. You will find the sk4d library in Binary/Shared/YourPlatform
24+
25+Your project must be able to find the library:
26+
27+- Linux: Set the LD_LIBRARY_PATH variable:
28+
29+`bash: export LD_LIBRARY_PATH=/home/user/skia4delphi-6.1.0/Binary/Shared/Linux64/`
30+
31+- MacOS: Copy the skia4delphi-6.1.0/Binary/Shared/OSX64/libsk4d.dylib to the project folder or create a symlink
32+- Windows: Copy the skia4delphi-6.1.0/Binary/Shared/Win64/sk4d.dll to the project folder
33+
34+## Download the Lazarus packages
35+
36+Download lazarus-ccr via svn:
37+
38+`svn checkout `[`https://svn.code.sf.net/p/lazarus-ccr/svn/`](https://svn.code.sf.net/p/lazarus-ccr/svn/)` lazarus-ccr-svn`
39+
40+The skia files are in the directory lazarus-ccr-svn/components/skia .
41+
42+There are three Lazarus packages:
43+
44+- design/Skia.LCL.Design.lpk - the IDE addon
45+- src/Skia.LCL.lpk - contains the LCL controls like TSkPaintBox and TSkCustomWinControl
46+- skia4d_package/Skia.lpk - the units from skia4delphi
47+
48+## Install Skia.LCL.Design
49+
50+This is optional.
51+
52+Requirements:
53+
54+- The IDE is compiled with fpc 3.3.1
55+- the sk4d library can be found by the Lazarus executable, otherwise the IDE will not start.
56+
57+Install the package Skia.LCL.Design.lpk in the IDE:
58+
59+- Open the design/Skia.LCL.Design.lpk via IDE menu *Package / Open Package File (lpk)*
60+- Then click the button *Use* and *Install*
61+- Restart the IDE
62+
63+You will find a new page **Skia** in the component palette.
64+
65+# TSkPaintBox
66+
67+This is a TGraphicControl - a lcl control without its own handle. Useful if you just want to draw something with skia. Set the OnDraw event
68+
69+``` pascal
70+procedure TForm1.FormCreate(Sender: TObject);
71+begin
72+ MySkPaintBox:=TSkPaintBox.Create(Self);
73+ with MySkPaintBox do begin
74+ Name:='MySkPaintBox';
75+ OnDraw:=@MySkPaintBoxDraw;
76+ SetBounds(10,10,50,50);
77+ Parent:=Self;
78+ end;
79+end;
80+
81+procedure TForm1.MySkPaintBoxDraw(Sender: TObject; const aCanvas: ISkCanvas; const aDest: TRectF; const aOpacity: Single);
82+begin
83+ aCanvas.Clear(TAlphaColors.Red);
84+end;
85+```
86+
87+Note: the Opacity is not yet supported.
88+
89+# TSkCustomWinControl
90+
91+This is TCustomControl - a lcl base class for custom controls with own handle and scrollbars. Override the DrawContent and Invalidate methods:
92+
93+``` pascal
94+type
95+ TMySkiaControl = class(TSkCustomWinControl)
96+ public
97+ procedure DrawContent(const ACanvas: ISkCanvas; const {%H-}ADest: TRectF;
98+ const AOpacity: Single); override;
99+ procedure Invalidate; override;
100+ end;
101+...
102+
103+procedure TMySkiaControl.DrawContent(const ACanvas: ISkCanvas; const ADest: TRectF; const AOpacity: Single);
104+begin
105+ // your drawing code
106+ aCanvas.Clear(TAlphaColors.White);
107+end;
108+
109+procedure TMySkiaControl.Invalidate;
110+begin
111+ inherited Invalidate;
112+ Render.Redraw; // force a redraw
113+end;
114+```
115+
116+Note: the Opacity is not yet supported.
117+
118+---
119+*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