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