Sign in Join
Wiki copytemporary

Custom Drawn Interface: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-[![Warning-icon.png](/wiki-images/b/b2/Warning-icon.png)](</File:Warning-icon.png>)
2-
3-**Warning:** THIS INFORMATION IS EXTREMELY DATED AND NEEDS UPDATING as of 2015
4-
5-## Contents
6-
7- * 1 Other Interfaces
8- * 1.1 Platform specific Tips
9- * 1.2 Interface Development Articles
10- * 2 Introduction
11- * 3 FAQ
12- * 3.1 Diagram of the Custom Drawn Interface
13- * 4 The LCL-CustomDrawn Backends
14- * 4.1 LCL-CustomDrawn-Android
15- * 4.2 LCL-CustomDrawn-X11
16- * 4.3 LCL-CustomDrawn-Cocoa
17- * 4.4 LCL-CustomDrawn-Windows
18- * 4.5 LCL-CustomDrawn-iPhone
19- * 5 Canvas
20- * 5.1 Getting the TLazCanvas object inside TCanvas
21- * 5.2 Drawing optimization roadmap
22- * 5.2.1 Optimizations already done
23- * 5.2.2 Optimizations to be done
24- * 6 Font rendering
25- * 7 Message and Common Dialogs
26- * 8 Windowed visual controls
27- * 9 Conditional defines accepted by LCL-CustomDrawn
28- * 10 Screenshots
29- * 11 See Also
30-
31-## Other Interfaces
32-
33- * [[Lazarus known issues \(things that will never be fixed\|Lazarus known issues (things that will never be fixed)]]> "Lazarus known issues \(things that will never be fixed\)") \- A list of interface compatibility issues
34- * [[Win32/64 Interface]] \- The Windows API (formerly Win32 API) interface for Windows 95/98/Me/2000/XP/Vista/10, but not CE
35- * [[Windows CE Interface]] \- For Pocket PC and Smartphones
36- * [[Carbon Interface]] \- The Carbon 32 bit interface for macOS (deprecated; removed from macOS 10.15)
37- * [[Cocoa Interface]] \- The Cocoa 64 bit interface for macOS
38- * [[Qt Interface]] \- The Qt4 interface for Unixes, macOS, Windows, and Linux-based PDAs
39- * [[Qt5 Interface]] \- The Qt5 interface for Unixes, macOS, Windows, and Linux-based PDAs
40- * [[GTK1 Interface]] \- The gtk1 interface for Unixes, macOS (X11), Windows
41- * [[GTK2 Interface]] \- The gtk2 interface for Unixes, macOS (X11), Windows
42- * [[GTK3 Interface]] \- The gtk3 interface for Unixes, macOS (X11), Windows
43- * [[fpGUI Interface]] \- Based on the fpGUI library, which is a cross-platform toolkit completely written in Object Pascal
44- * Custom Drawn Interface \- A cross-platform LCL backend written completely in Object Pascal inside Lazarus. The Lazarus interface to Android.
45-
46-### Platform specific Tips
47-
48- * [[Android Programming]] \- For Android smartphones and tablets
49- * [[iPhone/iPod development]] \- About using Objective Pascal to develop iOS applications
50- * [[FreeBSD Programming Tips]] \- FreeBSD programming tips
51- * [[Linux Programming Tips]] \- How to execute particular programming tasks in Linux
52- * [[macOS Programming Tips]] \- Lazarus tips, useful tools, Unix commands, and more...
53- * [[WinCE Programming Tips]] \- Using the telephone API, sending SMSes, and more...
54- * [[Windows Programming Tips]] \- Desktop Windows programming tips
55-
56-### Interface Development Articles
57-
58- * [[Carbon interface internals]] \- If you want to help improving the Carbon interface
59- * [[Windows CE Development Notes]] \- For Pocket PC and Smartphones
60- * [[Adding a new interface]] \- How to add a new widget set interface
61- * [[LCL Defines]] \- Choosing the right options to recompile LCL
62- * [[LCL Internals]] \- Some info about the inner workings of the LCL
63- * [[Cocoa Internals]] \- Some info about the inner workings of the Cocoa widgetset
1+> **Warning:** THIS INFORMATION IS EXTREMELY DATED AND NEEDS UPDATING as of 2015
642
653## Introduction
664
67-LCL-CustomDrawn-Android has the following features:
5+LCL-CustomDrawn-Android has the following features:
686
69- * Backends for X11, Android and Windows and a partially working one for Cocoa, more can be added in the future
70- * 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
71- * 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
72- * Utilizes the Lazarus Custom Drawn Controls for implementing the LCL standard controls
73- * Utilizes as it's painting engine the lcl parts: TLazIntfImage, TRawImage, lazcanvas and lazregions
7+- Backends for X11, Android and Windows and a partially working one for Cocoa, more can be added in the future
8+- 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
9+- 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
10+- Utilizes the Lazarus Custom Drawn Controls for implementing the LCL standard controls
11+- Utilizes as it's painting engine the lcl parts: TLazIntfImage, TRawImage, lazcanvas and lazregions
7412
7513## FAQ
7614
7715### Diagram of the Custom Drawn Interface
7816
79-[![customdrawn diagram.png](/wiki-images/1/10/customdrawn_diagram.png)](</File:customdrawn_diagram.png>)
17+![](/wiki-images/8/85/Customdrawn_diagram.png)
8018
81-Legend:
19+Legend:
8220
83- * Blue - New elements implemented as part of the LCL-CustomDrawn project
84- * Yellow - Pre-existing LCL elements
85- * Gray - System APIs
21+- Blue - New elements implemented as part of the LCL-CustomDrawn project
22+- Yellow - Pre-existing LCL elements
23+- Gray - System APIs
8624
8725## The LCL-CustomDrawn Backends
8826
89-LCL-CustomDrawn needs backends to implement the most basic parts of the widgetset. Each backend should implement the following minimal parts:
27+LCL-CustomDrawn needs backends to implement the most basic parts of the widgetset. Each backend should implement the following minimal parts:
9028
91- * TWidgetSet.Run, ProcessMessages, etc
92- * TForm
93- * TWinControl with all events
94- * TTrayIcon
29+- TWidgetSet.Run, ProcessMessages, etc
30+- TForm
31+- TWinControl with all events
32+- TTrayIcon
9533
9634### LCL-CustomDrawn-Android
9735
9836This backend is working. See this page [[Custom Drawn Interface/Android]]
9937
10038And also [[Android Programming]]
10139
10240### LCL-CustomDrawn-X11
10341
10442This backend is working. See [[Custom Drawn Interface/X11]]
10543
10644### LCL-CustomDrawn-Cocoa
10745
108-This backend is working.
46+This backend is working.
10947
11048### LCL-CustomDrawn-Windows
11149
112-This backend is working.
50+This backend is working.
11351
11452### LCL-CustomDrawn-iPhone
11553
116-This is planned, but not yet started.
54+This is planned, but not yet started.
11755
11856## Canvas
11957
120-TCanvas 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.
58+TCanvas 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.
12159
12260### Getting the TLazCanvas object inside TCanvas
12361
124-This works only in the LCL-CustomDrawn interface:
125-```
62+This works only in the LCL-CustomDrawn interface:
63+
64+``` pascal
12665uses lazcanvas, lclintf;
127-
128- var
129- MyLazCanvas: TLazCanvas:
130- begin
131- if nctLazCanvas in LCLIntf.GetAvailableNativeCanvasTypes(MyCanvas.Handle) then
132- begin
133- MyLazCanvas := TLazCanvas(LCLIntf.GetNativeCanvas(MyCanvas.Handle, nctLazCanvas));
134- // do something here with TLazCanvas
135- end;
66+
67+var
68+ MyLazCanvas: TLazCanvas:
69+begin
70+ if nctLazCanvas in LCLIntf.GetAvailableNativeCanvasTypes(MyCanvas.Handle) then
71+ begin
72+ MyLazCanvas := TLazCanvas(LCLIntf.GetNativeCanvas(MyCanvas.Handle, nctLazCanvas));
73+ // do something here with TLazCanvas
74+ end;
13675```
13776
13877### Drawing optimization roadmap
13978
14079#### Optimizations already done
14180
142- * 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.
143- * Don't draw controls which are completely covered by other ones. Commits:
144- * [http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36437](<http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36437>)
145- * [http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36455](<http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36455>)
146- * 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:
147- * 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.
148- * [http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36576](<http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36576>)
149- * [http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36578](<http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36578>)
150- * 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
151- * [http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36580](<http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36580>)
81+- 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.
82+- Don't draw controls which are completely covered by other ones. Commits:
83+ - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36437>
84+ - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36455>
85+- 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:
86+- 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.
87+ - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36576>
88+ - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36578>
89+- 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
90+ - <http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&root=lazarus&revision=36580>
15291
15392#### Optimizations to be done
15493
155- * Buffer the native bitmap of the form instead of generating it on each operation
156- * Reuse the buffered native bitmap contents if they don't change
157- * Support invalidating only a rectangle instead of the entire control
94+- Buffer the native bitmap of the form instead of generating it on each operation
95+- Reuse the buffered native bitmap contents if they don't change
96+- Support invalidating only a rectangle instead of the entire control
15897
15998## Font rendering
16099
161-When 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.
100+When 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.
162101
163102## Message and Common Dialogs
164103
165-Message 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.
104+Message 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.
166105
167106## Windowed visual controls
168107
169108All Windowed visual controls (TButton, TPageControl, etc) will be based in the [[Lazarus Custom Drawn Controls]]
170109
171110## Conditional defines accepted by LCL-CustomDrawn
172111
173-One easy way to set a conditional define for the LCL-CustomDrawn is to define it in the file lcl/interfaces/customdrawn/customdrawndefines.inc
112+One easy way to set a conditional define for the LCL-CustomDrawn is to define it in the file lcl/interfaces/customdrawn/customdrawndefines.inc
174113
175-Here are defines which affect the functionality offered by this interface:
114+Here are defines which affect the functionality offered by this interface:
176115
177- * 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.
116+- 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.
178117
179-And here debug information defines:
118+And here debug information defines:
180119
181- * VerboseCDPaintProfiler - Adds profiling information to indicate how fast the paint event is processed
182- * VerboseCDWinAPI - Extended verbose information for LCLIntf calls, except those which are covered by one of these defines instead:
183- * VerboseCDText - Verbose info for text winapi calls
184- * VerboseCDDrawing - Verbose info for Canvas and drawing operations
185- * VerboseCDBitmap - Verbose info for Bitmap and rawimage creation and handling
186- * VerboseCDForms - Extended verbose information for TWSCustomForm methods and about the non-native form from customdrawnproc (when utilized)
187- * VerboseCDEvents - Extended verbose information for native events (for example mouse click, key input, etc). This excludes the paint event
188- * VerboseCDPaintEvent - Debug info for the paint event
189- * VerboseCDApplication - Verbose info for App routines from the Widgetset object
190- * VerboseCDMessages - Verbose info for messages from the operating system (Paint, keyboard, mouse)
120+- VerboseCDPaintProfiler - Adds profiling information to indicate how fast the paint event is processed
121+- VerboseCDWinAPI - Extended verbose information for LCLIntf calls, except those which are covered by one of these defines instead:
122+ - VerboseCDText - Verbose info for text winapi calls
123+ - VerboseCDDrawing - Verbose info for Canvas and drawing operations
124+ - VerboseCDBitmap - Verbose info for Bitmap and rawimage creation and handling
125+- VerboseCDForms - Extended verbose information for TWSCustomForm methods and about the non-native form from customdrawnproc (when utilized)
126+- VerboseCDEvents - Extended verbose information for native events (for example mouse click, key input, etc). This excludes the paint event
127+- VerboseCDPaintEvent - Debug info for the paint event
128+- VerboseCDApplication - Verbose info for App routines from the Widgetset object
129+- VerboseCDMessages - Verbose info for messages from the operating system (Paint, keyboard, mouse)
191130
192131## Screenshots
193132
194-[![Lazclock customdrawn.png](/wiki-images/0/05/Lazclock_customdrawn.png)](</File:Lazclock_customdrawn.png>)
133+![](/wiki-images/0/05/Lazclock_customdrawn.png)
195134
196-[![lcl android 30 mar.png](/wiki-images/3/3e/lcl_android_30_mar.png)](</File:lcl_android_30_mar.png>) [![vpr-android.png](/wiki-images/4/43/vpr-android.png)](</File:vpr-android.png>)
135+![](/wiki-images/4/4c/Lcl_android_30_mar.png) ![](/wiki-images/d/df/Vpr-android.png)
197136
198137## See Also
199138
200- * [[Lazarus Custom Drawn Controls]]
139+- [[Lazarus Custom Drawn Controls]]
201140
202141---
203-*From the Free Pascal wiki, page "Custom Drawn Interface", as the Internet Archive kept it on 2023-02-01. 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).*
142+*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).*
143+Category: Custom Drawn

Back to history