unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes , SysUtils , Forms , Controls , Graphics , Dialogs , StdCtrls , Types,
BGRABitmapTypes, BGRABitmap;
type
{ TForm1 }
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
procedure FormCreate(Sender: TObject);
private
procedure DrawPenItem(const anIndex: integer; ARect: TRect);
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
with ComboBox1 do
begin
Items.Clear;
Style:= csOwnerDrawEditableVariable;
With Items do
begin
Add('Solid' );
Add('Dash' );
Add('DashDot' );
Add('DashDotDot' );
Add('Dot' );
Add('Clear' );
end;
end;
end;
procedure TForm1.DrawPenItem(const anIndex: integer; ARect: TRect);
var aBitmap : TBGRABitmap;
aColor : TColor ;
aBGRAColor : TBGRAPixel ;
begin
aColor := ComboBox1.Color;
aBGRAColor := ColorToBGRA(aColor);
aBitmap := TBGRABitmap.Create(aRect.Width div 2, aRect.Height, aBGRAColor);
case ComboBox1.Items[anIndex] of
'Solid' : aBitmap.PenStyle := psSolid;
'Dash' : aBitmap.PenStyle := psDash;
'DashDot' : aBitmap.PenStyle := psDashDot;
'DashDotDot': aBitmap.PenStyle := psDashDotDot;
'Dot' : aBitmap.PenStyle := psDot;
'Clear' : aBitmap.PenStyle := psClear;
end;
aBitmap.DrawLineAntiAlias({x1 = } aRect.Left ,
{y1 = } aRect.Top + aRect.Height div 2 ,
{x2 = } aRect.Right div 2,
{y2 = } aRect.Top + aRect.Height div 2 ,
{aBGRAColor = } BGRABlack ,
{aThickenss = } 1
);
aBitmap.FontHeight := 10;
aBitmap.FontAntialias := true;
abitmap.FontStyle := [];
aBitmap.TextOut(ARect.Right div 2 + 10, ARect.Top, ComboBox1.Items[anIndex],BGRABlack);
aBitmap.Draw(ComboBox1.Canvas,0,0,True);
aBitmap.Free;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);
begin
DrawPenItem(Index,aRect);
end;
end.