customdrawn: The common button is now win2k

git-svn-id: trunk@33265 -
This commit is contained in:
sekelsenmat 2011-11-03 14:22:06 +00:00
parent 30fd618333
commit 78da9b52f1
3 changed files with 122 additions and 127 deletions

View File

@ -151,62 +151,74 @@ end;
procedure TCDDrawerCommon.DrawButton(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
var
TmpB: TBitmap;
Str: string;
begin
// Button shape -> This crashes in Gtk2
TmpB := TBitmap.Create;
TmpB.Width := ASize.cx;
TmpB.Height := ASize.cy;
TmpB.Canvas.Brush.Color := AStateEx.RGBColor;
TmpB.Canvas.Brush.Style := bsSolid;
TmpB.Canvas.RoundRect(0, 0, TmpB.Width, TmpB.Height, 8, 8);
// CDButton.SetShape(TmpB);
ADest.Brush.Color := AStateEx.RGBColor;
ADest.Brush.Style := bsSolid;
ADest.RoundRect(0, 0, ASize.cx, ASize.cy, 8, 8);
ADest.Brush.Style := bsSolid;
ADest.Brush.Color := AStateEx.RGBColor;
ADest.Pen.Color := clWhite;
ADest.Pen.Style := psSolid;
ADest.Rectangle(0, 0, ASize.cx - 1, ASize.cy - 1);
ADest.Pen.Color := clWhite;
ADest.Line(0, 0, ASize.cx - 1, 0);
ADest.Line(0, 0, 0, ASize.cy - 1);
ADest.Pen.Color := clGray;
ADest.Line(0, ASize.cy - 1, ASize.cx - 1, ASize.cy - 1);
ADest.Line(ASize.cx - 1, ASize.cy - 1, ASize.cx - 1, -1);
ADest.Pen.Color := $0099A8AC;
ADest.Line(1, ASize.cy - 2, ASize.cx - 2, ASize.cy - 2);
ADest.Line(ASize.cx - 2, ASize.cx - 2, ASize.cx - 2, 0);
ADest.Pen.Color := $00E2EFF1;
ADest.Line(1, 1, ASize.cx - 2, 1);
ADest.Line(1, 1, 1, ASize.cy - 2);
// Button image
if csfSunken in AState then
begin
TmpB.Canvas.Brush.Style := bsSolid;
TmpB.Canvas.Brush.Color := RGBToColor(230, 230, 230);
TmpB.Canvas.Pen.Color := clBlack;
TmpB.Canvas.Pen.Style := psSolid;
TmpB.Canvas.Rectangle(0, 0, TmpB.Canvas.Width, TmpB.Canvas.Height);
ADest.Brush.Style := bsSolid;
ADest.Brush.Color := AStateEx.RGBColor;
ADest.Pen.Color := clWhite;
ADest.Pen.Style := psSolid;
ADest.Rectangle(0, 0, ASize.cx - 1, ASize.cy - 1);
ADest.Pen.Color := clGray;
ADest.Line(0, 0, ASize.cx - 1, 0);
ADest.Line(0, 0, 0, ASize.cy - 1);
ADest.Pen.Color := clWhite;
ADest.Line(0, ASize.cy - 1, ASize.cx - 1, ASize.cy - 1);
ADest.Line(ASize.cx - 1, ASize.cy - 1, ASize.cx - 1, -1);
ADest.Pen.Color := $00E2EFF1;
ADest.Line(1, ASize.cy - 2, ASize.cx - 2, ASize.cy - 2);
ADest.Line(ASize.cx - 2, ASize.cy - 2, ASize.cx - 2, 0);
ADest.Pen.Color := $0099A8AC;
ADest.Line(1, 1, ASize.cx - 2, 1);
ADest.Line(1, 1, 1, ASize.cy - 2);
end
else if csfHasFocus in AState then
begin
with TmpB.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := RGBToColor($FD, $FD, $FD);
Pen.Color := clBlack;
Pen.Style := psSolid;
Rectangle(0, 0, Width, Height);
Rectangle(1, 1, Width - 1, Height - 1); // The border is thicken when focused
end;
end
else
begin
with TmpB.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := AStateEx.RGBColor;
Pen.Color := clBlack;
Pen.Style := psSolid;
Rectangle(0, 0, Width, Height);
end;
ADest.Brush.Style := bsClear;
ADest.Pen.Color := clWhite;
ADest.Pen.Style := psSolid;
ADest.Rectangle(3, 3, ASize.cx - 4, ASize.cy - 4);
ADest.Pen.Color := clBlack;
ADest.Pen.Style := psDot;
ADest.Rectangle(3, 3, ASize.cx - 4, ASize.cy - 4);
end;
ADest.Draw(0, 0, TmpB);
TmpB.Free;
// Button text
ADest.Font.Assign(AStateEx.Font);
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psSolid;
Str := AStateEx.Caption;
ADest.TextOut((ASize.cx - ADest.TextWidth(Str)) div 2,
(ASize.cy - ADest.TextHeight(Str)) div 2, Str);
if csfSunken in AState then
ADest.TextOut((ASize.cx - ADest.TextWidth(Str)) div 2 + 1,
(ASize.cy - ADest.TextHeight(Str)) div 2 + 1, Str)
else
ADest.TextOut((ASize.cx - ADest.TextWidth(Str)) div 2,
(ASize.cy - ADest.TextHeight(Str)) div 2, Str);
end;
procedure TCDDrawerCommon.DrawEditBackground(ADest: TCanvas;

View File

@ -15,99 +15,15 @@ uses
customdrawndrawers, customdrawn_common;
type
{ TCDDrawerWin2k }
TCDDrawerWin2k = class(TCDDrawerCommon)
public
end;
implementation
{procedure TCDButtonDrawerWin2k.DrawToIntfImage(ADest: TFPImageCanvas;
CDButton: TCDButton);
begin
end;
procedure TCDButtonDrawerWin2k.DrawToCanvas(ADest: TCanvas; CDButton: TCDButton);
var
TmpB: TBitmap;
Str: string;
begin
// Button shape -> This crashes in Gtk2
TmpB := TBitmap.Create;
TmpB.Width := CDButton.Width;
TmpB.Height := CDButton.Height;
TmpB.Canvas.Brush.Color := CDButton.Color;
TmpB.Canvas.Brush.Style := bsSolid;
TmpB.Canvas.RoundRect(0, 0, TmpB.Width, TmpB.Height, 8, 8);
with TmpB.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := CDButton.Color;
Pen.Color := clWhite;
Pen.Style := psSolid;
Rectangle(0, 0, Width - 1, Height - 1);
Pen.Color := clWhite;
Line(0, 0, Width - 1, 0);
Line(0, 0, 0, Height - 1);
Pen.Color := clGray;
Line(0, Height - 1, Width - 1, Height - 1);
Line(Width - 1, Height - 1, Width - 1, -1);
Pen.Color := $0099A8AC;
Line(1, Height - 2, Width - 2, Height - 2);
Line(Width - 2, Height - 2, Width - 2, 0);
Pen.Color := $00E2EFF1;
Line(1, 1, Width - 2, 1);
Line(1, 1, 1, Height - 2);
end;
// Button image
if CDButton.IsDown then
begin
with TmpB.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := CDButton.Color;
Pen.Color := clWhite;
Pen.Style := psSolid;
Rectangle(0, 0, Width - 1, Height - 1);
Pen.Color := clGray;
Line(0, 0, Width - 1, 0);
Line(0, 0, 0, Height - 1);
Pen.Color := clWhite;
Line(0, Height - 1, Width - 1, Height - 1);
Line(Width - 1, Height - 1, Width - 1, -1);
Pen.Color := $00E2EFF1;
Line(1, Height - 2, Width - 2, Height - 2);
Line(Width - 2, Height - 2, Width - 2, 0);
Pen.Color := $0099A8AC;
Line(1, 1, Width - 2, 1);
Line(1, 1, 1, Height - 2);
end;
end
else if CDButton.Focused then
begin
with TmpB.Canvas do
DrawFocusRect(Rect(3, 3, Width - 4, Height - 4))
end;
ADest.Draw(0, 0, TmpB);
TmpB.Free;
// Button text
ADest.Font.Assign(CDButton.Font);
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psSolid;
Str := CDButton.Caption;
if CDButton.IsDown then
ADest.TextOut((CDButton.Width - ADest.TextWidth(Str)) div 2 + 1,
(CDButton.Height - ADest.TextHeight(Str)) div 2 + 1, Str)
else
ADest.TextOut((CDButton.Width - ADest.TextWidth(Str)) div 2,
(CDButton.Height - ADest.TextHeight(Str)) div 2, Str);
end;}
initialization
RegisterDrawer(TCDDrawerWin2k.Create, dsWin2000);
end.

View File

@ -6,7 +6,7 @@ interface
uses
// RTL
Classes, SysUtils,
Classes, SysUtils, Types,
// LCL -> Use only TForm, TWinControl, TCanvas and TLazIntfImage
Graphics, Controls, LCLType,
// Others only for types
@ -17,10 +17,77 @@ uses
type
TCDDrawerWinCE = class(TCDDrawerCommon)
public
// ===================================
// Standard Tab
// ===================================
// TCDButton
procedure DrawButton(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDControlStateEx); override;
end;
implementation
procedure TCDDrawerWinCE.DrawButton(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
var
TmpB: TBitmap;
Str: string;
begin
// Button shape -> This crashes in Gtk2
TmpB := TBitmap.Create;
TmpB.Width := ASize.cx;
TmpB.Height := ASize.cy;
TmpB.Canvas.Brush.Color := AStateEx.RGBColor;
TmpB.Canvas.Brush.Style := bsSolid;
TmpB.Canvas.RoundRect(0, 0, TmpB.Width, TmpB.Height, 8, 8);
// CDButton.SetShape(TmpB);
// Button image
if csfSunken in AState then
begin
TmpB.Canvas.Brush.Style := bsSolid;
TmpB.Canvas.Brush.Color := RGBToColor(230, 230, 230);
TmpB.Canvas.Pen.Color := clBlack;
TmpB.Canvas.Pen.Style := psSolid;
TmpB.Canvas.Rectangle(0, 0, TmpB.Canvas.Width, TmpB.Canvas.Height);
end
else if csfHasFocus in AState then
begin
with TmpB.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := RGBToColor($FD, $FD, $FD);
Pen.Color := clBlack;
Pen.Style := psSolid;
Rectangle(0, 0, Width, Height);
Rectangle(1, 1, Width - 1, Height - 1); // The border is thicken when focused
end;
end
else
begin
with TmpB.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := AStateEx.RGBColor;
Pen.Color := clBlack;
Pen.Style := psSolid;
Rectangle(0, 0, Width, Height);
end;
end;
ADest.Draw(0, 0, TmpB);
TmpB.Free;
// Button text
ADest.Font.Assign(AStateEx.Font);
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psSolid;
Str := AStateEx.Caption;
ADest.TextOut((ASize.cx - ADest.TextWidth(Str)) div 2,
(ASize.cy - ADest.TextHeight(Str)) div 2, Str);
end;
initialization
RegisterDrawer(TCDDrawerWinCE.Create, dsWinCE);
end.