Difference between revisions of "Lazarus Custom Drawn Controls"

From Free Pascal wiki
Jump to navigationJump to search
m (Typos/grammar/formatting)
Line 1: Line 1:
The '''Lazarus Custom Drawn Controls''' are a set of controls equivalent to the standard Lazarus controls, but which draw themselves. They can have many uses, including the hability to fully customize the drawing, the hability to have exactly the same look in different platforms and also a higher consistency of behavior.
+
The '''Lazarus Custom Drawn Controls''' are a set of controls equivalent to the standard Lazarus controls, but which draw themselves. They can have many uses, including the ability to fully customize the drawing, the ability to have exactly the same look in different platforms and also a higher consistency of behavior.
  
This set of controls is divided into two parts: The custom drawn controls which are necessary for implementing Lazarus widgetsets and will futurelly be located in the unit lazarus/lcl/customdrawncontrols.pas, and all other custom drawn controls, which are used often, but aren't indispensable to implement a LCL custom drawn widgetset. Those are located in the package lazarus/components/customdrawn. At the moment all custom drawn controls are in the customdrawn package.
+
This set of controls is divided into two parts:
 +
* the custom drawn controls which are necessary for implementing Lazarus widgetsets and will in future be located in the unit lazarus/lcl/customdrawncontrols.pas
 +
* all other custom drawn controls, which are used often, but aren't indispensable to implement a LCL custom drawn widgetset. Those are located in the package lazarus/components/customdrawn.  
 +
 
 +
At the moment all custom drawn controls are in the customdrawn package.
  
 
__TOC__
 
__TOC__
Line 9: Line 13:
 
The basic programming technique utilized by this set of controls is explained in the page [[Developing with Graphics#Create a custom control which draws itself]]. Besides using a TCustomControl descendent, these components also use a TLazIntfImage and TFPImageCanvas instead of the usual TCanvas, in order to have a drawing precisely equal among platforms, as well as the possibility of fast pixel access. This programming technique is described in [[Developing with Graphics#Working with TLazIntfImage]].
 
The basic programming technique utilized by this set of controls is explained in the page [[Developing with Graphics#Create a custom control which draws itself]]. Besides using a TCustomControl descendent, these components also use a TLazIntfImage and TFPImageCanvas instead of the usual TCanvas, in order to have a drawing precisely equal among platforms, as well as the possibility of fast pixel access. This programming technique is described in [[Developing with Graphics#Working with TLazIntfImage]].
  
==Custom Drawn Controls which might be moved to the LCL==
+
==Custom drawn controls which might be moved to the LCL==
  
 
===TCDButton===
 
===TCDButton===
Line 15: Line 19:
 
This is a fully custom drawn button.
 
This is a fully custom drawn button.
  
Current location in the code: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/customdrawn/customdrawnextras.pas?view=markup&root=lazarus
+
Current location in the code: [http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/customdrawn/customdrawnextras.pas?view=markup&root=lazarus]
  
 
Usage example:
 
Usage example:
Line 43: Line 47:
 
This is a fully custom drawn group box.
 
This is a fully custom drawn group box.
  
Current location in the code: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/customdrawn/customdrawnextras.pas?view=markup&root=lazarus
+
Current location in the code: [http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/customdrawn/customdrawnextras.pas?view=markup&root=lazarus]
  
 
==Other Custom Drawn Controls==
 
==Other Custom Drawn Controls==
Line 49: Line 53:
 
===TCDBitmappedButton===
 
===TCDBitmappedButton===
  
This is a button which draws it's image from bitmaps.
+
This is a button which draws its image from bitmaps.
  
 
Usage example:
 
Usage example:

Revision as of 10:34, 5 August 2011

The Lazarus Custom Drawn Controls are a set of controls equivalent to the standard Lazarus controls, but which draw themselves. They can have many uses, including the ability to fully customize the drawing, the ability to have exactly the same look in different platforms and also a higher consistency of behavior.

This set of controls is divided into two parts:

  • the custom drawn controls which are necessary for implementing Lazarus widgetsets and will in future be located in the unit lazarus/lcl/customdrawncontrols.pas
  • all other custom drawn controls, which are used often, but aren't indispensable to implement a LCL custom drawn widgetset. Those are located in the package lazarus/components/customdrawn.

At the moment all custom drawn controls are in the customdrawn package.

How do these components work?

The basic programming technique utilized by this set of controls is explained in the page Developing with Graphics#Create a custom control which draws itself. Besides using a TCustomControl descendent, these components also use a TLazIntfImage and TFPImageCanvas instead of the usual TCanvas, in order to have a drawing precisely equal among platforms, as well as the possibility of fast pixel access. This programming technique is described in Developing with Graphics#Working with TLazIntfImage.

Custom drawn controls which might be moved to the LCL

TCDButton

This is a fully custom drawn button.

Current location in the code: [1]

Usage example:

<delphi> uses customdrawnextras;

procedure TForm1.FormCreate(Sender: TObject); var

 MyButton: TCDButton;

begin

 MyButton := TCDButton.Create(Self);
 MyButton.Parent := Self;
 MyButton.DrawStyle := dsWin2000;
 MyButton.Left := 100;
 MyButton.Top := 100;
 MyButton.Width := 200;
 MyButton.Height := 50;
 MyButton.Caption := 'My Button';
 MyButton.Color := clRed;
 MyButton.OnClick := @HandleButtonClick;

end; </delphi>

TCDGroupBox

This is a fully custom drawn group box.

Current location in the code: [2]

Other Custom Drawn Controls

TCDBitmappedButton

This is a button which draws its image from bitmaps.

Usage example:

<delphi> uses customdrawnextras;

var

 ActionButton: TBitmappedButton;

begin

 ActionButton := TBitmappedButton.Create(Self);
 ActionButton.Options := [bboUseImageForSelection];
 ActionButton.TabStop := True;
 ActionButton.OnClick := HandleActionButtonClick;
 ActionButton.Tag := i;
 ActionButton.Font.Size := 12;
 ActionButton.Font.Name := 'Times New Roman';
 ActionButton.Font.Color := clWhite;
 ActionButton.Parent := Self;
 ActionButton.Visible := True;
 ActionButton.Height := GetSkins().GetButton(sbSmall).Height;
 ActionButton.Width := GetSkins().GetButton(sbSmall).Width;
 ActionButton.Left := lLeft;
 ActionButton.Top := lTop;
 ActionButton.ImageBtn.Assign(GetSkins().GetButton(sbSmall));
 ActionButton.ImageBtnFocused.Assign(GetSkins().GetButtonFocused(sbSmall));
 ActionButton.ImageBtnDown.Assign(GetSkins().GetButtonDown(sbSmall));
 ActionButton.Caption := FModel.ActionButtons[i].Caption;

</delphi>

Custom Drawn Packages

Moved here: Lazarus Custom Drawn Package

Other good custom drawn components for Lazarus

Maintainers

See Also