procedure TMain.PresetTreeAfterItemPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; const ItemRect: TRect);
var
Level: Cardinal;
IsSelected: Boolean;
IsFocused: Boolean;
IsFocusedNode: Boolean;
IsExpanded: Boolean;
procedure DrawBackground(Canvas: TCanvas; Selected, Focused: Boolean);
begin
if Focused or Selected then
begin
Canvas.Pen.Color := PresetTree.Colors.FocusedSelectionColor;
Canvas.Brush.Color := PresetTree.Colors.FocusedSelectionColor;
end
else
begin
Canvas.Pen.Color := PresetTree.Colors.UnfocusedColor;
Canvas.Brush.Color := PresetTree.Colors.UnfocusedColor;
end;
Canvas.FillRect(1, 1, 16, 16);
end;
procedure EraseCategoryOutline(TargetCanvas: TCanvas; Selected, Focused: Boolean);
begin
if Focused or Selected then
begin
TargetCanvas.Pen.Color := PresetTree.Colors.FocusedSelectionColor;
TargetCanvas.Frame(0, 0, 200, 18);
end;
end;
procedure ErasePresetNameOutline(TargetCanvas: TCanvas; Selected, FocusedNode: Boolean);
begin
if FocusedNode then
begin
TargetCanvas.Pen.Color := PresetTree.Colors.FocusedSelectionColor;
TargetCanvas.Frame(0, 0, 200, 18);
end;
end;
procedure DrawArrow(Canvas: TCanvas; Expanded, Selected, Focused: Boolean);
var
Points: array[0..2] of TPoint;
ArrowColor: TColor;
begin
// Set colors
if Focused or Selected then
ArrowColor := PresetTree.Colors.SelectionTextColor
else
ArrowColor := PresetTree.Colors.TreeLineColor;
Canvas.Pen.Color := ArrowColor;
Canvas.Brush.Color := ArrowColor;
// Do the actual drawing
if Expanded then
begin
// Down arrow
Points[0] := Point(6, 5);
Points[1] := Point(14, 5);
Points[2] := Point(10, 11);
end
else
begin
// Right arrow
Points[0] := Point(6, 4);
Points[1] := Point(12, 8);
Points[2] := Point(6, 12);
end;
Canvas.Polygon(Points);
end;
begin
Level := PresetTree.GetNodeLevel(Node);
if Level = 0 then
begin
// Set state flags
IsSelected := PresetTree.Selected[Node] and PresetTree.Focused;
IsFocused := (Node = PresetTree.FocusedNode) and PresetTree.Focused;
IsExpanded := PresetTree.Expanded[Node];
// Call the drawing nested procedures
DrawBackground(TargetCanvas, IsSelected, IsFocused);
DrawArrow(TargetCanvas, IsExpanded, IsSelected, IsFocused);
EraseCategoryOutline(TargetCanvas, IsSelected, IsFocused);
end;
if Level = 1 then
begin
IsSelected := PresetTree.Selected[Node] and PresetTree.Focused;
IsFocusedNode := Node = PresetTree.FocusedNode;
ErasePresetNameOutline(TargetCanvas, IsSelected, IsFocusedNode);
end;
end;