Sign in Join
Wiki copytemporary

Custom Drawn Interface: what changed

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

OldNewLine
11> **Warning:** THIS INFORMATION IS EXTREMELY DATED AND NEEDS UPDATING as of 2015
22
33## Introduction
44
55LCL-CustomDrawn-Android has the following features:
66
77- Backends for X11, Android and Windows and a partially working one for Cocoa, more can be added in the future
88- Painting is done completely inside Lazarus without any interference from the native libraries except for text drawing. This assures a complete perfection of the executed drawings in all platforms and a uniform level of supported features
99- Only 1 native window is utilized for each form, in the Android backend at the moment this is 1 native window for the entire application
1010- Utilizes the Lazarus Custom Drawn Controls for implementing the LCL standard controls
1111- Utilizes as it's painting engine the lcl parts: TLazIntfImage, TRawImage, lazcanvas and lazregions
1212
1313## FAQ
1414
1515### Diagram of the Custom Drawn Interface
1616
17-<figure>
18-<img src="customdrawn_diagram.png" title="customdrawn_diagram.png" />
19-<figcaption>customdrawn_diagram.png</figcaption>
20-</figure>
17+![](/wiki-images/8/85/Customdrawn_diagram.png)
2118
2219Legend:
2320
2421- Blue - New elements implemented as part of the LCL-CustomDrawn project
2522- Yellow - Pre-existing LCL elements
2623- Gray - System APIs
2724
2825## The LCL-CustomDrawn Backends
2926
3027LCL-CustomDrawn needs backends to implement the most basic parts of the widgetset. Each backend should implement the following minimal parts:
3128
3229- TWidgetSet.Run, ProcessMessages, etc
3330- TForm
3431- TWinControl with all events
3532- TTrayIcon
3633
3734### LCL-CustomDrawn-Android
3835
3936This backend is working. See this page [[Custom Drawn Interface/Android]]
4037
4138And also [[Android Programming]]
4239
4340### LCL-CustomDrawn-X11
4441
4542This backend is working. See [[Custom Drawn Interface/X11]]
4643
4744### LCL-CustomDrawn-Cocoa
4845
4946This backend is working.
5047
5148### LCL-CustomDrawn-Windows
5249
5350This backend is working.
5451
5552### LCL-CustomDrawn-iPhone
5653
5754This is planned, but not yet started.
5855
5956## Canvas
6057
6158TCanvas will be fully non-native in this widgetset and based on [[Developing with Graphics|LazCanvas]]. All drawings to visual controls and on the OnPaint event of controls of the form are naturally double-buffered because the entire drawing of the form is first performed on an off-screen buffer and then copied in 1 operation to the form native canvas. In reality there is only 1 TLazCanvas for the entire form, but sub-controls will think they are on a separate canvas because the property BaseWindowOrg sets an internal start position of the canvas and also because all drawings will be clipped to reflect the size and shape of the sub-control.
6259
6360### Getting the TLazCanvas object inside TCanvas
6461
6562This works only in the LCL-CustomDrawn interface:
6663
6764``` pascal
6865uses lazcanvas, lclintf;
6966
7067var
7168 MyLazCanvas: TLazCanvas:
7269begin
7370 if nctLazCanvas in LCLIntf.GetAvailableNativeCanvasTypes(MyCanvas.Handle) then
7471 begin
7572 MyLazCanvas := TLazCanvas(LCLIntf.GetNativeCanvas(MyCanvas.Handle, nctLazCanvas));
7673 // do something here with TLazCanvas
7774 end;
7875```
7976
8077### Drawing optimization roadmap
8178
8279#### Optimizations already done
8380
8481- Give 1 bitmap to each control and buffer the control images and only redraw them if invalidated. This greatly helps in large forms when invalidating only 1 control.
8582- Don't draw controls which are completely covered by other ones. Commits:
8683 - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36437>
8784 - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36455>
8885- Change the control bitmaps to use the native format (with ifdefs for ARGB32 for alpha blending support). This was implemented together with the next optimization:
8986- Optimize the case of drawing a bitmap to a canvas, when the pixel formats match and the clip rect is inexistent or rectangular. The magnifier full painting went from 630ms to 477ms for me.
9087 - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36576>
9188 - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36578>
9289- Optimize rectangle area filling if the clip rect is inexistent or rectangular. Decreased the drawing of a fullscreen form in X11 with 4 buttons from 95ms to 33ms for me
9390 - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36580>
9491
9592#### Optimizations to be done
9693
9794- Buffer the native bitmap of the form instead of generating it on each operation
9895- Reuse the buffered native bitmap contents if they don't change
9996- Support invalidating only a rectangle instead of the entire control
10097
10198## Font rendering
10299
103100When the define CD_UseNativeText is activated, LCL-CustomDrawn will use the native text rendering of the platform as provided by the backend. If it isn't activated, then it will use [[LazFreeType]] to render the text. The define is automatically activated for some backends if convenient when using them.
104101
105102## Message and Common Dialogs
106103
107104Message and Common Dialogs might be native if this is considered very convenient for the backend. If not, they will be non-native. At the moment the Android backend has native message boxes.
108105
109106## Windowed visual controls
110107
111108All Windowed visual controls (TButton, TPageControl, etc) will be based in the [[Lazarus Custom Drawn Controls]]
112109
113110## Conditional defines accepted by LCL-CustomDrawn
114111
115112One easy way to set a conditional define for the LCL-CustomDrawn is to define it in the file lcl/interfaces/customdrawn/customdrawndefines.inc
116113
117114Here are defines which affect the functionality offered by this interface:
118115
119116- CD_UseNativeText - Activates using native text instead of PasFreeType. This define will be automatically set if convenient for a particular backend, don't set it manually unless you know what you are doing.
120117
121118And here debug information defines:
122119
123120- VerboseCDPaintProfiler - Adds profiling information to indicate how fast the paint event is processed
124121- VerboseCDWinAPI - Extended verbose information for LCLIntf calls, except those which are covered by one of these defines instead:
125122 - VerboseCDText - Verbose info for text winapi calls
126123 - VerboseCDDrawing - Verbose info for Canvas and drawing operations
127124 - VerboseCDBitmap - Verbose info for Bitmap and rawimage creation and handling
128125- VerboseCDForms - Extended verbose information for TWSCustomForm methods and about the non-native form from customdrawnproc (when utilized)
129126- VerboseCDEvents - Extended verbose information for native events (for example mouse click, key input, etc). This excludes the paint event
130127- VerboseCDPaintEvent - Debug info for the paint event
131128- VerboseCDApplication - Verbose info for App routines from the Widgetset object
132129- VerboseCDMessages - Verbose info for messages from the operating system (Paint, keyboard, mouse)
133130
134131## Screenshots
135132
136-<figure>
137-<img src="Lazclock_customdrawn.png" title="Lazclock_customdrawn.png" />
138-<figcaption>Lazclock_customdrawn.png</figcaption>
139-</figure>
133+![](/wiki-images/0/05/Lazclock_customdrawn.png)
140134
141135![](/wiki-images/4/4c/Lcl_android_30_mar.png) ![](/wiki-images/d/df/Vpr-android.png)
142136
143137## See Also
144138
145139- [[Lazarus Custom Drawn Controls]]
146140
147141---
148142*From the Free Pascal wiki, page "Custom Drawn Interface", as it stood on 2020-02-08 after a change by Trev, 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).*
149143Category: Custom Drawn

Back to history