Patch from JiXian Yang, improves the custom drawn components

git-svn-id: trunk@28848 -
This commit is contained in:
sekelsenmat 2010-12-31 13:41:58 +00:00
parent 9f15965b98
commit 04023695d9
2 changed files with 1171 additions and 190 deletions

File diff suppressed because it is too large Load Diff

View File

@ -13,18 +13,24 @@ interface
uses
Classes, SysUtils, LCLType, LCLIntf, LMessages, LCLProc, Controls, Graphics,
Forms, Types, IntfGraphics, FPImage, Math, FPImgCanv;
Forms, Types, IntfGraphics, FPImage, Math, FPImgCanv, FPCanvas;
function GetAColor(Color: TColor; Rate: byte): TColor;
function GetUColor(Color: TColor; Rate: byte): TColor;
procedure GradientFill(Clr1, Clr2: TColor; Canvas: TCanvas);
procedure GradientFillFP(Clr1, Clr2: TColor; Canvas: TFPImageCanvas; lRect: TRect);
procedure GradFill(Canvas: TFPImageCanvas; aRect: TRect; Clr1, Clr2: TColor);
procedure GradCenterFill(Canvas: TFPImageCanvas; aRect: TRect; Clr1, Clr2: TColor; rate: float);
procedure GradientFillRect(Clr1, Clr2: TColor; Canvas: TFPCustomCanvas; lRect: TRect);
procedure GradFill(Canvas: TFPCustomCanvas; aRect: TRect; Clr1, Clr2: TColor);
procedure GradCenterFill(Canvas: TFPCustomCanvas; aRect: TRect;
Clr1, Clr2: TColor; rate: float);
procedure DrawAndroidButton(Canvas: TCanvas; Color: TColor);
procedure DrawXPTaskbarButton(Canvas: TCanvas; Color: TColor);
procedure FPImgCloneRect(IntfImg1, IntfImg2: TLazIntfImage; lRect: TRect; Fast: boolean);
function GetUniqueName(const Name: string; PControl: TComponent): string;
procedure DrawTabHead(aDest: TFPCustomCanvas; aRect: TRect; HeadColor: TColor;
IsActive: boolean);
procedure DrawTabHeadMask(aDest: TFPCustomCanvas; aRect: TRect;
HeadColor: TColor; IsActive: boolean);
procedure DrawArrow(aDest: TFPCustomCanvas; aRect: TRect; R: boolean);
type
PRGBTripleArray = ^TRGBTripleArray;
@ -32,9 +38,155 @@ type
implementation
procedure DrawArrow(aDest: TFPCustomCanvas; aRect: TRect; R: boolean);
var
CenColor, CenColor2: TFPColor;
lWidth, lHeight, lCenter: integer;
begin
lWidth := aRect.Right - aRect.Left;
lHeight := aRect.Bottom - aRect.Top;
CenColor := aDest.Colors[aRect.Left + lWidth div 4, aRect.Top + lHeight div 2];
CenColor2 := aDest.Colors[aRect.Left + 3 * lWidth div 4, aRect.Top + lHeight div 2];
if R then
begin
aDest.Line(aRect.Left + lWidth div 4 - 1, aRect.Top + lHeight div 2,
aRect.Left + lWidth div 4 + 3, aRect.Top + lHeight div 2);
aDest.Line(aRect.Left + lWidth div 4 + 3, aRect.Top + lHeight div 2 - 4,
aRect.Left + lWidth div 4 + 3, aRect.Top + lHeight div 2 + 4);
aDest.Line(aRect.Left + lWidth div 4 + 2, aRect.Top + lHeight div 2 - 3,
aRect.Left + lWidth div 4 + 2, aRect.Top + lHeight div 2 + 3);
aDest.Line(aRect.Left + lWidth div 4 + 1, aRect.Top + lHeight div 2 - 2,
aRect.Left + lWidth div 4 + 1, aRect.Top + lHeight div 2 + 2);
aDest.Line(aRect.Left + lWidth div 4, aRect.Top + lHeight div 2 - 1,
aRect.Left + lWidth div 4, aRect.Top + lHeight div 2 + 1);
//aDest.Colors[aRect.Left + lWidth div 4 - 3, aRect.Top + lHeight div 2] := aDest.Brush.FPColor;
end
else
begin
aDest.Line(aRect.Left + 3 * lWidth div 4 - 1, aRect.Top + lHeight div 2,
aRect.Left + 3 * lWidth div 4 + 3, aRect.Top + lHeight div 2);
aDest.Line(aRect.Left + 3 * lWidth div 4 + 2, aRect.Top + lHeight div 2 - 1,
aRect.Left + 3 * lWidth div 4 + 2, aRect.Top + lHeight div 2 + 1);
aDest.Line(aRect.Left + 3 * lWidth div 4 + 1, aRect.Top + lHeight div 2 - 2,
aRect.Left + 3 * lWidth div 4 + 1, aRect.Top + lHeight div 2 + 2);
aDest.Line(aRect.Left + 3 * lWidth div 4 + 0, aRect.Top + lHeight div 2 - 3,
aRect.Left + 3 * lWidth div 4 + 0, aRect.Top + lHeight div 2 + 3);
aDest.Line(aRect.Left + 3 * lWidth div 4 - 1, aRect.Top + lHeight div 2 - 4,
aRect.Left + 3 * lWidth div 4 - 1, aRect.Top + lHeight div 2 + 4);
//aDest.Colors[aRect.Left + 3 * lWidth div 4, aRect.Top + lHeight div 2] := aDest.Brush.FPColor;
end;
end;
procedure DrawTabHead(aDest: TFPCustomCanvas; aRect: TRect; HeadColor: TColor;
IsActive: boolean);
var
lRect: TRect;
CC: TFPColor;
begin
lRect.Bottom := aRect.Bottom;
lRect.Right := aRect.Right;
lRect.Left := aRect.Left;
lRect.Top := aRect.Top + 3;
if not IsActive then
GradientFillRect(clWhite, HeadColor, aDest, lREct)
else
begin
aDest.Brush.FPColor := TColorToFPColor(ColorToRGB(HeadColor));
aDest.Pen.FPColor := aDest.Brush.FPColor;
aDest.Rectangle(lRect);
end;
aDest.Pen.FPColor := TColorToFPColor(ColorToRGB(clWhite));
aDest.Line(lRect.Left + 2, aRect.Top + 1, lRect.Right - 2, aRect.Top + 1);
aDest.Line(lRect.Left + 1, aRect.Top + 2, lRect.Right - 1, aRect.Top + 2);
ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($009C9B91));
aDest.Line(lRect.Left, lRect.Top, lRect.Left, lRect.Bottom);
//aDest.Line(lRect.Left + 3, aRect.Top, lRect.Right - 3, aRect.Top);
aDest.Line(lRect.Left + 3, aRect.Top, lRect.Right - 2, aRect.Top);
aDest.Line(lRect.Right, lRect.Top, lRect.Right, lRect.Bottom);
if not IsActive then
aDest.Line(aRect.Left, aRect.Bottom - 1, aRect.Right, aRect.Bottom - 1);
//aDest.Line();
{ aDest.Colors[aRect.Left + 1, aRect.Top + 2] := aDest.Pen.FPColor;
aDest.Colors[aRect.Left + 2, aRect.Top + 1] := aDest.Pen.FPColor;
aDest.Colors[aRect.Right - 1, aRect.Top + 2] := aDest.Pen.FPColor;
aDest.Colors[aRect.Right - 2, aRect.Top + 1] := aDest.Pen.FPColor; }
if IsActive then
begin
aDest.Pen.FPColor := TColorToFPColor(ColorToRGB($003CC7FF));
aDest.Line(lRect.Left, aRect.Top + 2, lRect.Right, aRect.Top + 2);
aDest.Line(lRect.Left + 1, aRect.Top + 1, lRect.Right - 1, aRect.Top + 1);
aDest.Pen.FPColor := TColorToFPColor(ColorToRGB($001CA7DF));
aDest.Line(lRect.Left + 2, aRect.Top, lRect.Right - 2, aRect.Top);
CC := TColorToFPColor(ColorToRGB($001CA7DF));
aDest.Colors[aRect.Left + 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left, aRect.Top + 2] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top] := CC;
{ CC := TColorToFPColor(ColorToRGB($005CE7FF));
aDest.Colors[aRect.Left, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top + 1] := CC; }
end
else
begin
CC := TColorToFPColor(ColorToRGB($00BCBBB1));
aDest.Colors[aRect.Left + 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left, aRect.Top + 2] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top] := CC;
CC := TColorToFPColor(ColorToRGB($00DCDBD1));
aDest.Colors[aRect.Left, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top + 1] := CC;
end;
end;
procedure DrawTabHeadMask(aDest: TFPCustomCanvas; aRect: TRect;
HeadColor: TColor; IsActive: boolean);
var
lRect: TRect;
CC: TFPColor;
begin
lRect.Bottom := aRect.Bottom;
lRect.Right := aRect.Right;
lRect.Left := aRect.Left;
lRect.Top := aRect.Top + 3;
CC := TColorToFPColor(ColorToRGB(HeadColor));
aDest.Pen.FPColor := CC;
aDest.Brush.FPColor := CC;
aDest.Rectangle(lRect);
aDest.Line(lRect.Left, lRect.Top, lRect.Left, lRect.Bottom);
aDest.Line(lRect.Left + 3, aRect.Top, lRect.Right - 2, aRect.Top);
aDest.Line(lRect.Right, lRect.Top, lRect.Right, lRect.Bottom);
aDest.Line(aRect.Left, aRect.Bottom - 1, aRect.Right, aRect.Bottom - 1);
aDest.Line(lRect.Left + 1, lRect.Top - 1, lRect.Right, lRect.Top - 1);
aDest.Line(lRect.Left + 2, lRect.Top - 2, lRect.Right - 1, lRect.Top - 2);
aDest.Colors[aRect.Left + 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left, aRect.Top + 2] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top] := CC;
end;
function GetUniqueName(const Name: string; PControl: TComponent): string;
var
i: integer; TName: string;
i: integer;
TName: string;
function GetTheName: boolean;
var
@ -101,8 +253,11 @@ end;
procedure GradientFill(Clr1, Clr2: TColor; Canvas: TCanvas);
var
ColorFrom: array[0..2] of byte; ColorDiff: array[0..2] of integer;
DrawBand: TRect; I: integer; R, G, B: byte;
ColorFrom: array[0..2] of byte;
ColorDiff: array[0..2] of integer;
DrawBand: TRect;
I: integer;
R, G, B: byte;
begin
ColorFrom[0] := GetRValue(ColorToRGB(Clr1));
ColorFrom[1] := GetGValue(ColorToRGB(Clr1));
@ -126,10 +281,13 @@ begin
end;
end;
procedure GradientFillFP(Clr1, Clr2: TColor; Canvas: TFPImageCanvas; lRect: TRect);
procedure GradientFillRect(Clr1, Clr2: TColor; Canvas: TFPCustomCanvas; lRect: TRect);
var
ColorFrom: array[0..2] of byte; ColorDiff: array[0..2] of integer;
DrawBand: TRect; I: integer; R, G, B: byte;
ColorFrom: array[0..2] of byte;
ColorDiff: array[0..2] of integer;
DrawBand: TRect;
I: integer;
R, G, B: byte;
begin
ColorFrom[0] := GetRValue(ColorToRGB(Clr1));
ColorFrom[1] := GetGValue(ColorToRGB(Clr1));
@ -155,8 +313,10 @@ begin
end;
end;
procedure GradCenterFill(Canvas: TFPImageCanvas; aRect: TRect; Clr1, Clr2: TColor; rate: float);
var lRect: TRect;
procedure GradCenterFill(Canvas: TFPCustomCanvas; aRect: TRect;
Clr1, Clr2: TColor; rate: float);
var
lRect: TRect;
begin
lRect.Left := aRect.Left;
lRect.Top := aRect.Top;
@ -170,10 +330,13 @@ begin
GradFill(Canvas, lRect, Clr2, Clr1);
end;
procedure GradFill(Canvas: TFPImageCanvas; aRect: TRect; Clr1, Clr2: TColor);
procedure GradFill(Canvas: TFPCustomCanvas; aRect: TRect; Clr1, Clr2: TColor);
var
ColorFrom: array[0..2] of byte; ColorDiff: array[0..2] of integer;
I: integer; R, G, B: byte; RBand: TRect;
ColorFrom: array[0..2] of byte;
ColorDiff: array[0..2] of integer;
I: integer;
R, G, B: byte;
RBand: TRect;
begin
ColorFrom[0] := GetRValue(ColorToRGB(Clr1));
ColorFrom[1] := GetGValue(ColorToRGB(Clr1));
@ -331,7 +494,7 @@ var
begin
if (orig_bmp = nil) or (dest_bmp = nil) then
Exit;
TmpBmp:=TBitmap.Create;
TmpBmp := TBitmap.Create;
TmpBmp.PixelFormat := pf24bit;
IntfImg1 := TLazIntfImage.Create(0, 0);
IntfImg1.LoadFromBitmap(orig_bmp.Handle, orig_bmp.MaskHandle);
@ -361,14 +524,14 @@ begin
for i := 0 to 2 do
begin
// New red value
totr := totr + Row1^[cx + i].rgbtRed +
Row2^[cx + i].rgbtRed + Row3^[cx + i].rgbtRed;
totr := totr + Row1^[cx + i].rgbtRed + Row2^[cx + i].rgbtRed +
Row3^[cx + i].rgbtRed;
// New green value
totg := totg + Row1^[cx + i].rgbtGreen +
Row2^[cx + i].rgbtGreen + Row3^[cx + i].rgbtGreen;
totg := totg + Row1^[cx + i].rgbtGreen + Row2^[cx + i].rgbtGreen +
Row3^[cx + i].rgbtGreen;
// New blue value
totb := totb + Row1^[cx + i].rgbtBlue +
Row2^[cx + i].rgbtBlue + Row3^[cx + i].rgbtBlue;
totb := totb + Row1^[cx + i].rgbtBlue + Row2^[cx + i].rgbtBlue +
Row3^[cx + i].rgbtBlue;
end;
// Set output pixel colors
DestRow^[x].rgbtRed := totr div 9;