mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 22:19:18 +02:00
TAChart: Simplify painting of series pointer in TChartCombobox.
git-svn-id: trunk@59734 -
This commit is contained in:
parent
3a17f4d9bb
commit
f87a819e21
@ -26,7 +26,6 @@ type
|
|||||||
TChartComboBox = class(TCustomComboBox)
|
TChartComboBox = class(TCustomComboBox)
|
||||||
private
|
private
|
||||||
FAlignment: TAlignment;
|
FAlignment: TAlignment;
|
||||||
FBitmaps: array[TSeriesPointerStyle] of TBitmap;
|
|
||||||
FBrushBitmap: TBitmap;
|
FBrushBitmap: TBitmap;
|
||||||
FBrushColor: TColor;
|
FBrushColor: TColor;
|
||||||
FBrushStyle: TBrushStyle;
|
FBrushStyle: TBrushStyle;
|
||||||
@ -60,11 +59,11 @@ type
|
|||||||
function SymbolWidthStored: Boolean;
|
function SymbolWidthStored: Boolean;
|
||||||
protected
|
protected
|
||||||
procedure Change; override;
|
procedure Change; override;
|
||||||
procedure CreateBitmaps(AWidth, AHeight: Integer);
|
|
||||||
procedure DestroyBitmaps;
|
|
||||||
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||||
const AXProportion, AYProportion: Double); override;
|
const AXProportion, AYProportion: Double); override;
|
||||||
procedure DrawItem(AIndex: Integer; ARect: TRect; AState: TOwnerDrawState); override;
|
procedure DrawItem(AIndex: Integer; ARect: TRect; AState: TOwnerDrawState); override;
|
||||||
|
procedure DrawPointer(ACanvas: TCanvas; ARect: TRect;
|
||||||
|
AStyle: TSeriesPointerStyle; APenColor, ABrushColor: TColor);
|
||||||
function GetBrushStyle(const AIndex: Integer): TBrushStyle;
|
function GetBrushStyle(const AIndex: Integer): TBrushStyle;
|
||||||
function GetPenStyle(const AIndex: Integer): TPenStyle;
|
function GetPenStyle(const AIndex: Integer): TPenStyle;
|
||||||
function GetPenWidth(const AIndex: Integer): Integer;
|
function GetPenWidth(const AIndex: Integer): Integer;
|
||||||
@ -258,7 +257,6 @@ end;
|
|||||||
|
|
||||||
destructor TChartCombobox.Destroy;
|
destructor TChartCombobox.Destroy;
|
||||||
begin
|
begin
|
||||||
DestroyBitmaps;
|
|
||||||
FBrushBitmap.Free;
|
FBrushBitmap.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
@ -269,64 +267,6 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChartCombobox.CreateBitmaps(AWidth, AHeight: Integer);
|
|
||||||
var
|
|
||||||
ps: TSeriesPointerStyle;
|
|
||||||
chart: TChart;
|
|
||||||
id: IChartDrawer;
|
|
||||||
series: TLineSeries;
|
|
||||||
legItems: TChartLegendItems;
|
|
||||||
begin
|
|
||||||
DestroyBitmaps;
|
|
||||||
|
|
||||||
chart := TChart.Create(nil);
|
|
||||||
try
|
|
||||||
for ps in TSeriesPointerStyle do begin
|
|
||||||
FBitmaps[ps] := TBitmap.Create;
|
|
||||||
FBitmaps[ps].Transparent := true;
|
|
||||||
FBitmaps[ps].TransparentColor := RgbToColor(254,254,254);
|
|
||||||
FBitmaps[ps].SetSize(AWidth, AHeight);
|
|
||||||
FBitmaps[ps].Canvas.Brush.Color := FBitmaps[ps].TransparentColor;
|
|
||||||
FBitmaps[ps].Canvas.FillRect(0, 0, AWidth, AHeight);
|
|
||||||
|
|
||||||
series := TLineSeries.Create(chart);
|
|
||||||
try
|
|
||||||
with series do begin
|
|
||||||
Pointer.Style := ps;
|
|
||||||
Pointer.Brush.Color := FBrushColor;
|
|
||||||
Pointer.Pen.Color := FPenColor;
|
|
||||||
Pointer.HorizSize := Min(AWidth, AHeight);
|
|
||||||
Pointer.VertSize := Pointer.HorizSize;
|
|
||||||
ShowPoints := true;
|
|
||||||
LineType := ltNone;
|
|
||||||
end;
|
|
||||||
chart.AddSeries(series);
|
|
||||||
legitems := TChartLegendItems.Create;
|
|
||||||
try
|
|
||||||
series.GetSingleLegendItem(legItems);
|
|
||||||
id := TCanvasDrawer.Create(FBitmaps[ps].Canvas);
|
|
||||||
id.Pen := Chart.Legend.SymbolFrame;
|
|
||||||
legItems[0].Draw(id, Rect(0, 0, AWidth-1, AHeight-1));
|
|
||||||
finally
|
|
||||||
legitems.Free;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
series.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
chart.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartCombobox.DestroyBitmaps;
|
|
||||||
var
|
|
||||||
ps: TSeriesPointerStyle;
|
|
||||||
begin
|
|
||||||
for ps in TSeriesPointerStyle do
|
|
||||||
FreeAndNil(FBitmaps[ps]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartComboBox.DoAutoAdjustLayout(
|
procedure TChartComboBox.DoAutoAdjustLayout(
|
||||||
const AMode: TLayoutAdjustmentPolicy;
|
const AMode: TLayoutAdjustmentPolicy;
|
||||||
const AXProportion, AYProportion: Double);
|
const AXProportion, AYProportion: Double);
|
||||||
@ -354,6 +294,7 @@ var
|
|||||||
bs: TBrushStyle;
|
bs: TBrushStyle;
|
||||||
sps: TSeriesPointerStyle;
|
sps: TSeriesPointerStyle;
|
||||||
symwidth, symheight: Integer;
|
symwidth, symheight: Integer;
|
||||||
|
R: TRect;
|
||||||
begin
|
begin
|
||||||
if Assigned(OnDrawItem) then
|
if Assigned(OnDrawItem) then
|
||||||
OnDrawItem(Self, AIndex, ARect, AState)
|
OnDrawItem(Self, AIndex, ARect, AState)
|
||||||
@ -426,10 +367,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
ccmPointerStyle:
|
ccmPointerStyle:
|
||||||
begin
|
begin
|
||||||
if (FBitmaps[psCircle] = nil) or (FBitmaps[psCircle].Height <> symHeight)
|
R := Rect(MARGIN, MARGIN, MARGIN + symheight, MARGIN + symheight);
|
||||||
then CreateBitmaps(symwidth, symHeight);
|
OffsetRect(R, ARect.Left + (symWidth - symheight) div 2, ARect.Top);
|
||||||
sps := GetPointerStyle(AIndex);
|
DrawPointer(Canvas, R, GetPointerStyle(AIndex), FPenColor, FBrushColor);
|
||||||
Canvas.Draw(x1, ARect.Top + MARGIN, FBitmaps[sps]);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -448,6 +388,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartCombobox.DrawPointer(ACanvas: TCanvas; ARect: TRect;
|
||||||
|
AStyle: TSeriesPointerStyle; APenColor, ABrushColor: TColor);
|
||||||
|
var
|
||||||
|
id: IChartDrawer;
|
||||||
|
pointer: TSeriesPointer;
|
||||||
|
c: TPoint;
|
||||||
|
begin
|
||||||
|
pointer := TSeriesPointer.Create(nil);
|
||||||
|
try
|
||||||
|
pointer.Style := AStyle;
|
||||||
|
Pointer.HorizSize := (ARect.Right - ARect.Left) div 2 - 1;
|
||||||
|
Pointer.VertSize := (ARect.Bottom - ARect.Top) div 2 - 1;
|
||||||
|
Pointer.Brush.Color := ABrushColor;
|
||||||
|
Pointer.Pen.Color := APenColor;
|
||||||
|
c := Point((ARect.Left + ARect.Right) div 2, (ARect.Top + ARect.Bottom) div 2);
|
||||||
|
pointer.Draw(TCanvasDrawer.Create(ACanvas), c, ABrushColor);
|
||||||
|
finally
|
||||||
|
pointer.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TChartCombobox.GetBrushStyle(const AIndex: Integer): TBrushStyle;
|
function TChartCombobox.GetBrushStyle(const AIndex: Integer): TBrushStyle;
|
||||||
begin
|
begin
|
||||||
if AIndex < 0 then
|
if AIndex < 0 then
|
||||||
@ -629,7 +590,6 @@ procedure TChartCombobox.SetBrushColor(const AValue: TColor);
|
|||||||
begin
|
begin
|
||||||
if FBrushColor = AValue then exit;
|
if FBrushColor = AValue then exit;
|
||||||
FBrushColor := AValue;
|
FBrushColor := AValue;
|
||||||
DestroyBitmaps;
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -673,25 +633,21 @@ begin
|
|||||||
case FMode of
|
case FMode of
|
||||||
ccmBrushStyle:
|
ccmBrushStyle:
|
||||||
begin
|
begin
|
||||||
DestroyBitmaps;
|
|
||||||
PopulateBrushStyles;
|
PopulateBrushStyles;
|
||||||
SetSelectedBrushStyle(FBrushStyle);
|
SetSelectedBrushStyle(FBrushStyle);
|
||||||
end;
|
end;
|
||||||
ccmPenStyle:
|
ccmPenStyle:
|
||||||
begin
|
begin
|
||||||
DestroyBitmaps;
|
|
||||||
PopulatePenStyles;
|
PopulatePenStyles;
|
||||||
SetSelectedPenStyle(FPenStyle);
|
SetSelectedPenStyle(FPenStyle);
|
||||||
end;
|
end;
|
||||||
ccmPenWidth:
|
ccmPenWidth:
|
||||||
begin
|
begin
|
||||||
DestroyBitmaps;
|
|
||||||
PopulatePenWidths;
|
PopulatePenWidths;
|
||||||
SetSelectedPenWidth(FPenWidth);
|
SetSelectedPenWidth(FPenWidth);
|
||||||
end;
|
end;
|
||||||
ccmPointerStyle:
|
ccmPointerStyle:
|
||||||
begin
|
begin
|
||||||
DestroyBitmaps; // bitmaps will be created when painting
|
|
||||||
PopulatePointerStyles;
|
PopulatePointerStyles;
|
||||||
SetSelectedPointerStyle(FPointerStyle);
|
SetSelectedPointerStyle(FPointerStyle);
|
||||||
end;
|
end;
|
||||||
@ -739,7 +695,6 @@ procedure TChartComboBox.SetPenColor(const AValue: TColor);
|
|||||||
begin
|
begin
|
||||||
if AValue = FPenColor then exit;
|
if AValue = FPenColor then exit;
|
||||||
FPenColor := AValue;
|
FPenColor := AValue;
|
||||||
DestroyBitmaps;
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user