2
*****************************************************************************
3
See the file COPYING.modifiedLGPL.txt, included in this distribution,
4
for details about the license.
5
*****************************************************************************
7
Authors: Alexander Klenin
17
BGRABitmap, BGRABitmapTypes, BGRAGradients, Graphics, Types,
20
function CreateChocolateBar(
21
AColor: TBGRAPixel; ALightPos: TPoint; ARect: TRect; ABorder: Integer;
22
ARoundedCorners: Boolean; AOptions: TRectangleMapOptions): TBGRABitmap;
23
procedure DrawChocolateBar(
24
ASeries: TBarSeries; ACanvas: TCanvas; ARect: TRect; APointIndex: Integer;
26
function CreatePhong3DBar(
27
AColor: TBGRAPixel; ALightPos: TPoint; var ARect: TRect;
28
ADepth: Integer): TBGRABitmap;
29
procedure DrawPhong3DBar(
30
ASeries: TBarSeries; ACanvas: TCanvas; ARect: TRect; APointIndex: Integer);
35
TAChartUtils, TADrawUtils, TAGeometry;
37
function BarColor(ASeries: TBarSeries; APointIndex: Integer): TBGRAPixel;
40
Result := ColorToBGRA(ColorToRGB(
41
ColorDef(Source[APointIndex]^.Color, BarBrush.Color)), 255 - Transparency);
44
function CreateChocolateBar(
45
AColor: TBGRAPixel; ALightPos: TPoint; ARect: TRect; ABorder: Integer;
46
ARoundedCorners: Boolean; AOptions: TRectangleMapOptions): TBGRABitmap;
51
t := MaxPoint(ARect.BottomRight - ARect.TopLeft, Point(0, 0));
52
Result := TBGRABitmap.Create(t.X, t.Y);
53
if (t.X = 0) and (t.Y = 0) then exit;
54
if ABorder < 0 then ABorder := 0;
55
phong := TPhongShading.Create;
57
phong.AmbientFactor := 0.5;
58
phong.LightPosition := ALightPos - ARect.TopLeft;
60
Result, BoundsSize(0, 0, t), ABorder, ABorder,
61
AColor, ARoundedCorners, AOptions);
67
procedure DrawChocolateBar(
68
ASeries: TBarSeries; ACanvas: TCanvas; ARect: TRect;
69
APointIndex: Integer; ARounded: boolean);
74
border := (ARect.Right - ARect.Left) div 8;
75
ARect.Top += -border div 2 + 1;
76
ARect.Bottom += border div 2 + 1;
77
bar := CreateChocolateBar(
78
BarColor(ASeries, APointIndex),
79
Point(ASeries.ParentChart.ClientWidth div 2, 0),
80
ARect, border, ARounded, []);
83
bar.Draw(ACanvas, X, Y, false);
89
function CreatePhong3DBar(
90
AColor: TBGRAPixel; ALightPos: TPoint; var ARect: TRect;
91
ADepth: Integer): TBGRABitmap;
99
t := MaxPoint(ARect.BottomRight - ARect.TopLeft, Point(0, 0));
100
map := TBGRABitmap.Create(t.X + ADepth,t.Y + ADepth);
102
map.FillRect(0, ADepth, t.X, t.Y + ADepth, BGRAWhite, dmSet);
103
for i := 1 to ADepth do begin
104
h := MapHeightToBGRA((ADepth - i) / ADepth, 255);
105
map.SetHorizLine(i, ADepth - i, t.X - 1 + i - 1, h);
106
map.SetVertLine(t.X - 1 + i, ADepth - i, t.Y + ADepth - 1 - i, h);
108
Result := TBGRABitmap.Create(t.X + ADepth, t.Y + ADepth);
110
ARect.Right += ADepth;
111
if (Result.width = 0) or (Result.Height = 0) then exit;
112
phong := TPhongShading.Create;
114
phong.AmbientFactor := 0.5;
115
phong.LightPosition := ALightPos - ARect.TopLeft;
116
phong.Draw(Result, map, ADepth, 0, 0, AColor);
125
procedure DrawPhong3DBar(
126
ASeries: TBarSeries; ACanvas: TCanvas; ARect: TRect; APointIndex: Integer);
128
procedure DrawContour(var ABar: TBGRABitmap; var ADrawnRect: TRect);
132
marginValue, depth: integer;
135
margin := point(0, 0);
136
if ASeries.BarPen.Style = psClear then exit;
137
size := ARect.BottomRight - ARect.TopLeft;
138
if ASeries.BarPen.Width > 1 then begin
139
marginValue := (ASeries.BarPen.Width + 1) div 2;
140
margin := Point(marginValue, marginValue);
141
temp := TBGRABitmap.Create(
142
ABar.Width + 2 * margin.X, ABar.Height + 2 * margin.Y);
143
temp.PutImage(margin.X, margin.Y, ABar, dmSet);
144
BGRAReplace(ABar, temp);
145
ADrawnRect.TopLeft -= margin;
146
ADrawnRect.BottomRight += margin;
148
depth := ASeries.Depth;
149
with ABar.CanvasBGRA do begin
150
Pen.Assign(ASeries.BarPen);
151
Brush.Style := bsClear;
153
Point(margin.x + 0, margin.y + depth),
154
Point(margin.x + depth, margin.y + 0),
155
Point(margin.x + size.x - 1 + depth, margin.y + 0),
156
Point(margin.x + size.x - 1 + depth, margin.y + size.y - 1),
157
Point(margin.x + size.x - 1, margin.y + size.y - 1 + depth),
158
Point(margin.x + 0, margin.y + size.y - 1 + depth)
166
bar := CreatePhong3DBar(
167
BarColor(ASeries, APointIndex),
168
Point(ASeries.ParentChart.ClientWidth div 2, 0), ARect, ASeries.Depth);
170
DrawContour(bar, ARect);
171
with ARect.TopLeft do
172
bar.Draw(ACanvas, X, Y, false);