1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| procedure TForm15.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF; const Row: Integer;
const Value: TValue; const State: TGridDrawStates);
var ARect : TRectF;
ABrush : TBrush;
ABackColor,ATextColor : TAlphaColor;
procedure DrawTriangle(Bounds : TRectF; Color : TAlphaColor;
Direction : Word=0; Stretch : Word =1);
var Points: array[0..2] of TPointF;
Demi : Single;
APath : TPath;
begin
if Stretch=1 then Demi:=Min(Column.Width,Bounds.Height)/2
else Demi:=Bounds.Height/2;
if Direction=0 then
begin
Points[0] := PointF(Bounds.Left,Bounds.Top+Bounds.Height/2-Demi);
Points[1] := PointF(Bounds.Left+Bounds.Width,Bounds.Top+(Bounds.Height/2));
Points[2] := PointF(Bounds.Left,Bounds.Top+(Bounds.Height/2)+Demi);
end
else begin
Points[0] := PointF(Bounds.Left,Bounds.Top+Bounds.Height/2);
Points[1] := PointF(Bounds.Left+Bounds.Width,Bounds.Top+(Bounds.Height/2)-Demi);
Points[2] := PointF(Bounds.Left+Bounds.Width,Bounds.Top+(Bounds.Height/2)+Demi);
end;
ABrush:=TBrush.Create(TBrushkind.Solid,Color);
APath:=TPath.Create(Self);
try
APath.Data.MoveTo(Points[0]);
APath.Data.LineTo(Points[1]);
APath.Data.LineTo(Points[2]);
APath.Data.ClosePath;
Canvas.FillPath(APath.Data,1,ABrush);
finally
FreeAndNil(ABrush);
FreeAndNil(APath);
end;
end;
function GetHeaderColors(Sender: TObject; var BackGroundColor,TextColor : TAlphaColor) : TBrush;
var Header : THeader;
HeaderItem : THeaderItem;
aFMXObj : TFMXObject;
aGradient : TGradient;
begin
Header:=THeader((Sender as TGrid).FindStyleResource('header'));
if Assigned(Header) then
begin
HeaderItem := Header.Items[1];
AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('Text');
TextColor:=TText(AFMXObj).TextSettings.FontColor;
AFMXObj:=THeaderItem(HeaderItem).FindStyleResource('background');
Result:=TRectangle(AFMXObj).Fill;
if Result.Kind=TBrushKind.Gradient
then BackGroundColor:=Result.Gradient.InterpolateColor(50)
else BackGroundColor:=Result.DefaultColor; // hypothèse non testée
end;
end;
begin
...
if Column.Name='Curseur' then
begin
ABrush:=GetHeaderColors(Sender,ABackColor,ATextColor);
ARect:=TRectF.Create(Bounds);
InflateRect(ARect,3,3);
Canvas.ClearRect(ARect,ABackColor);
Canvas.FillRect(ARect,0,0,[],1,ABrush);
if Row=cds.RecNo-1 then
DrawTriangle(Bounds,ATextColor,0,1);
end;
...
end; |
Partager