~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/tachart/tadrawerfpvectorial.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
 *****************************************************************************
 
3
 *                                                                           *
 
4
 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
 
5
 *  for details about the copyright.                                         *
 
6
 *                                                                           *
 
7
 *  This program is distributed in the hope that it will be useful,          *
 
8
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 
9
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
 
10
 *                                                                           *
 
11
 *****************************************************************************
 
12
 
 
13
Authors: Alexander Klenin
 
14
 
 
15
}
 
16
unit TADrawerFPVectorial;
 
17
 
 
18
{$H+}
 
19
 
 
20
interface
 
21
 
 
22
uses
 
23
  Classes, FPCanvas, FPImage, FPVectorial, TAChartUtils, TADrawUtils;
 
24
 
 
25
type
 
26
 
 
27
  { TFPVectorialDrawer }
 
28
 
 
29
  TFPVectorialDrawer = class(TBasicDrawer, IChartDrawer)
 
30
  strict private
 
31
    FBoundingBox: TRect;
 
32
    FBrushColor: TFPColor;
 
33
    FBrushStyle: TFPBrushStyle;
 
34
    FCanvas: TvVectorialPage;
 
35
    FFontSize: Integer;
 
36
    FPenColor: TFPColor;
 
37
    FPenStyle: TFPPenStyle;
 
38
    FPenWidth: Integer;
 
39
 
 
40
    procedure AddLine(AX, AY: Integer);
 
41
    procedure ApplyBrush;
 
42
    procedure ApplyPen;
 
43
    function InvertY(AY: Integer): Integer; inline;
 
44
  strict protected
 
45
    function GetFontAngle: Double; override;
 
46
    procedure SetBrush(ABrush: TFPCustomBrush);
 
47
    procedure SetFont(AFont: TFPCustomFont);
 
48
    procedure SetPen(APen: TFPCustomPen);
 
49
    function SimpleTextExtent(const AText: String): TPoint; override;
 
50
    procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
 
51
  public
 
52
    constructor Create(ACanvas: TvVectorialPage);
 
53
  public
 
54
    procedure AddToFontOrientation(ADelta: Integer);
 
55
    procedure ClippingStart;
 
56
    procedure ClippingStart(const AClipRect: TRect);
 
57
    procedure ClippingStop;
 
58
    procedure DrawingBegin(const ABoundingBox: TRect); override;
 
59
    procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
 
60
    procedure FillRect(AX1, AY1, AX2, AY2: Integer);
 
61
    function GetBrushColor: TChartColor;
 
62
    procedure Line(AX1, AY1, AX2, AY2: Integer);
 
63
    procedure Line(const AP1, AP2: TPoint); overload;
 
64
    procedure LineTo(AX, AY: Integer); override;
 
65
    procedure MoveTo(AX, AY: Integer); override; overload;
 
66
    procedure Polygon(
 
67
      const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
 
68
    procedure Polyline(
 
69
      const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
 
70
    procedure PrepareSimplePen(AColor: TChartColor);
 
71
    procedure RadialPie(
 
72
      AX1, AY1, AX2, AY2: Integer;
 
73
      AStartAngle16Deg, AAngleLength16Deg: Integer);
 
74
    procedure Rectangle(const ARect: TRect);
 
75
    procedure Rectangle(AX1, AY1, AX2, AY2: Integer);
 
76
    procedure SetBrushColor(AColor: TChartColor);
 
77
    procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
 
78
    procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
 
79
  end experimental;
 
80
 
 
81
implementation
 
82
 
 
83
uses
 
84
  Math, TAGeometry;
 
85
 
 
86
{ TFPVectorialDrawer }
 
87
 
 
88
procedure TFPVectorialDrawer.AddLine(AX, AY: Integer);
 
89
begin
 
90
  FCanvas.AddLineToPath(AX, InvertY(AY));
 
91
end;
 
92
 
 
93
procedure TFPVectorialDrawer.AddToFontOrientation(ADelta: Integer);
 
94
begin
 
95
  // Not implemented.
 
96
  Unused(ADelta);
 
97
end;
 
98
 
 
99
procedure TFPVectorialDrawer.ApplyBrush;
 
100
begin
 
101
  FCanvas.SetBrushColor(FBrushColor);
 
102
  FCanvas.SetBrushStyle(FBrushStyle);
 
103
end;
 
104
 
 
105
procedure TFPVectorialDrawer.ApplyPen;
 
106
begin
 
107
  FCanvas.SetPenColor(FPenColor);
 
108
  FCanvas.SetPenStyle(FPenStyle);
 
109
  FCanvas.SetPenWidth(FPenWidth);
 
110
end;
 
111
 
 
112
procedure TFPVectorialDrawer.ClippingStart(const AClipRect: TRect);
 
113
begin
 
114
  Unused(AClipRect); // Not implemented.
 
115
end;
 
116
 
 
117
procedure TFPVectorialDrawer.ClippingStart;
 
118
begin
 
119
  // Not implemented.
 
120
end;
 
121
 
 
122
procedure TFPVectorialDrawer.ClippingStop;
 
123
begin
 
124
  // Not implemented.
 
125
end;
 
126
 
 
127
constructor TFPVectorialDrawer.Create(ACanvas: TvVectorialPage);
 
128
begin
 
129
  inherited Create;
 
130
  FCanvas := ACanvas;
 
131
end;
 
132
 
 
133
procedure TFPVectorialDrawer.DrawingBegin(const ABoundingBox: TRect);
 
134
begin
 
135
  FBoundingBox := ABoundingBox;
 
136
end;
 
137
 
 
138
procedure TFPVectorialDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
 
139
var
 
140
  cx, cy, rx, ry: Integer;
 
141
begin
 
142
  BoundingBoxToCenterAndHalfRadius(AX1, AY1, AX2, AY2, cx, cy, rx, ry);
 
143
  FCanvas.AddEllipse(cx, InvertY(cy), rx, ry, 0.0);
 
144
end;
 
145
 
 
146
procedure TFPVectorialDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);
 
147
begin
 
148
  MoveTo(AX1, AY1);
 
149
  AddLine(AX2, AY1);
 
150
  AddLine(AX2, AY2);
 
151
  AddLine(AX1, AY2);
 
152
  AddLine(AX1, AY1);
 
153
  FCanvas.SetBrushStyle(bsClear);
 
154
  FCanvas.SetPenColor(FPenColor);
 
155
  FCanvas.EndPath();
 
156
end;
 
157
 
 
158
function TFPVectorialDrawer.GetBrushColor: TChartColor;
 
159
begin
 
160
  Result := FPColorToChartColor(FBrushColor);
 
161
end;
 
162
 
 
163
function TFPVectorialDrawer.GetFontAngle: Double;
 
164
begin
 
165
  Result := 0.0;
 
166
end;
 
167
 
 
168
function TFPVectorialDrawer.InvertY(AY: Integer): Integer;
 
169
begin
 
170
  with FBoundingBox do
 
171
    Result := Bottom - Top - AY;
 
172
end;
 
173
 
 
174
procedure TFPVectorialDrawer.Line(AX1, AY1, AX2, AY2: Integer);
 
175
begin
 
176
  FCanvas.StartPath(AX1, InvertY(AY1));
 
177
  AddLine(AX2, AY2);
 
178
  FCanvas.SetPenColor(FPenColor);
 
179
  FCanvas.EndPath();
 
180
end;
 
181
 
 
182
procedure TFPVectorialDrawer.Line(const AP1, AP2: TPoint);
 
183
begin
 
184
  Line(AP1.X, AP1.Y, AP2.X, AP2.Y);
 
185
end;
 
186
 
 
187
procedure TFPVectorialDrawer.LineTo(AX, AY: Integer);
 
188
begin
 
189
  FCanvas.AddLineToPath(AX, InvertY(AY), FPenColor);
 
190
end;
 
191
 
 
192
procedure TFPVectorialDrawer.MoveTo(AX, AY: Integer);
 
193
begin
 
194
  FCanvas.EndPath();
 
195
  FCanvas.StartPath(AX, InvertY(AY));
 
196
end;
 
197
 
 
198
procedure TFPVectorialDrawer.Polygon(
 
199
  const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
 
200
var
 
201
  i: Integer;
 
202
begin
 
203
  if ANumPts <= 0 then exit;
 
204
  MoveTo(APoints[AStartIndex]);
 
205
  for i := 1 to ANumPts - 1 do
 
206
    with APoints[i + AStartIndex] do
 
207
      AddLine(X, Y);
 
208
  ApplyBrush;
 
209
  ApplyPen;
 
210
  FCanvas.EndPath();
 
211
end;
 
212
 
 
213
procedure TFPVectorialDrawer.Polyline(
 
214
  const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
 
215
var
 
216
  i: Integer;
 
217
begin
 
218
  if ANumPts <= 0 then exit;
 
219
  MoveTo(APoints[AStartIndex]);
 
220
  for i := 1 to ANumPts - 1 do
 
221
    with APoints[i + AStartIndex] do
 
222
      AddLine(X, Y);
 
223
  ApplyPen;
 
224
  FCanvas.EndPath();
 
225
end;
 
226
 
 
227
procedure TFPVectorialDrawer.PrepareSimplePen(AColor: TChartColor);
 
228
begin
 
229
  FPenColor := FChartColorToFPColorFunc(AColor);
 
230
  FPenStyle := psSolid;
 
231
  FPenWidth := 1;
 
232
end;
 
233
 
 
234
procedure TFPVectorialDrawer.RadialPie(
 
235
  AX1, AY1, AX2, AY2: Integer; AStartAngle16Deg, AAngleLength16Deg: Integer);
 
236
begin
 
237
  // Not implemented.
 
238
  Unused(AX1, AY1);
 
239
  Unused(AX2, AY2);
 
240
  Unused(AStartAngle16Deg, AAngleLength16Deg);
 
241
end;
 
242
 
 
243
procedure TFPVectorialDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer);
 
244
begin
 
245
  MoveTo(AX1, AY1);
 
246
  AddLine(AX2, AY1);
 
247
  AddLine(AX2, AY2);
 
248
  AddLine(AX1, AY2);
 
249
  AddLine(AX1, AY1);
 
250
  ApplyBrush;
 
251
  ApplyPen;
 
252
  FCanvas.EndPath();
 
253
end;
 
254
 
 
255
procedure TFPVectorialDrawer.Rectangle(const ARect: TRect);
 
256
begin
 
257
  with ARect do
 
258
    Rectangle(Left, Top, Right, Bottom);
 
259
end;
 
260
 
 
261
procedure TFPVectorialDrawer.SetBrush(ABrush: TFPCustomBrush);
 
262
begin
 
263
  FBrushColor := ABrush.FPColor;
 
264
  FBrushStyle := ABrush.Style;
 
265
end;
 
266
 
 
267
procedure TFPVectorialDrawer.SetBrushColor(AColor: TChartColor);
 
268
begin
 
269
  FBrushColor := FChartColorToFPColorFunc(AColor);
 
270
end;
 
271
 
 
272
procedure TFPVectorialDrawer.SetBrushParams(
 
273
  AStyle: TFPBrushStyle; AColor: TChartColor);
 
274
begin
 
275
  SetBrushColor(AColor);
 
276
  FBrushStyle := AStyle;
 
277
end;
 
278
 
 
279
procedure TFPVectorialDrawer.SetFont(AFont: TFPCustomFont);
 
280
begin
 
281
  FFontSize := IfThen(AFont.Size = 0, 10, AFont.Size);
 
282
end;
 
283
 
 
284
procedure TFPVectorialDrawer.SetPen(APen: TFPCustomPen);
 
285
begin
 
286
  FPenColor := APen.FPColor;
 
287
  FPenStyle := APen.Style;
 
288
  FPenWidth := APen.Width;
 
289
end;
 
290
 
 
291
procedure TFPVectorialDrawer.SetPenParams(
 
292
  AStyle: TFPPenStyle; AColor: TChartColor);
 
293
begin
 
294
  FPenStyle := AStyle;
 
295
  FPenColor := FChartColorToFPColorFunc(AColor);
 
296
end;
 
297
 
 
298
function TFPVectorialDrawer.SimpleTextExtent(const AText: String): TPoint;
 
299
begin
 
300
  Result.X := FFontSize * Length(AText) * 2 div 3;
 
301
  Result.Y := FFontSize;
 
302
end;
 
303
 
 
304
procedure TFPVectorialDrawer.SimpleTextOut(
 
305
  AX, AY: Integer; const AText: String);
 
306
begin
 
307
  // FPVectorial uses lower-left instead of upper-left corner as text start.
 
308
  FCanvas.AddText(AX, InvertY(AY) - FFontSize, 0, AText);
 
309
end;
 
310
 
 
311
end.
 
312