1 | unit Dpi.Graphics;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Math, Graphics, LCLType, GraphType, Types;
|
---|
7 |
|
---|
8 | const
|
---|
9 | clBlack = TColor($000000);
|
---|
10 | clWhite = TColor($ffffff);
|
---|
11 |
|
---|
12 | type
|
---|
13 | TColor = Graphics.TColor;
|
---|
14 | TPixelFormat = Graphics.TPixelFormat;
|
---|
15 | TFontStyle = Graphics.TFontStyle;
|
---|
16 |
|
---|
17 | { TFont }
|
---|
18 |
|
---|
19 | TFont = class(TPersistent)
|
---|
20 | private
|
---|
21 | FNativeFont: Graphics.TFont;
|
---|
22 | FNativeFontFree: Boolean;
|
---|
23 | FOnChange: TNotifyEvent;
|
---|
24 | FSize: Integer;
|
---|
25 | FHeight: Integer;
|
---|
26 | FPixelsPerInch: Integer;
|
---|
27 | FColor: TColor;
|
---|
28 | function GetCharSet: TFontCharSet;
|
---|
29 | function GetColor: TColor;
|
---|
30 | function GetHeight: Integer;
|
---|
31 | function GetName: string;
|
---|
32 | function GetPixelsPerInch: Integer;
|
---|
33 | function GetSize: Integer;
|
---|
34 | function GetStyle: TFontStyles;
|
---|
35 | function IsNameStored: Boolean;
|
---|
36 | procedure SetCharSet(AValue: TFontCharSet);
|
---|
37 | procedure SetColor(AValue: TColor);
|
---|
38 | procedure SetHeight(AValue: Integer);
|
---|
39 | procedure SetName(AValue: string);
|
---|
40 | procedure SetNativeFont(AValue: Graphics.TFont);
|
---|
41 | procedure SetPixelsPerInch(AValue: Integer);
|
---|
42 | procedure SetSize(AValue: Integer);
|
---|
43 | procedure DoChange;
|
---|
44 | procedure SetStyle(AValue: TFontStyles);
|
---|
45 | procedure UpdateFont;
|
---|
46 | protected
|
---|
47 | function GetNativeFont: Graphics.TFont; virtual;
|
---|
48 | public
|
---|
49 | procedure ScreenChanged;
|
---|
50 | property NativeFont: Graphics.TFont read FNativeFont write SetNativeFont;
|
---|
51 | constructor Create;
|
---|
52 | destructor Destroy; override;
|
---|
53 | procedure Assign(Source: TPersistent); override;
|
---|
54 | procedure GetTextSize(Text: string; var w, h: Integer);
|
---|
55 | function GetTextHeight(Text: string): Integer;
|
---|
56 | function GetTextWidth(Text: string): Integer;
|
---|
57 | published
|
---|
58 | property CharSet: TFontCharSet read GetCharSet write SetCharSet default DEFAULT_CHARSET;
|
---|
59 | property Color: TColor read GetColor write SetColor;
|
---|
60 | property Name: string read GetName write SetName stored IsNameStored;
|
---|
61 | property Style: TFontStyles read GetStyle write SetStyle default [];
|
---|
62 | property Size: Integer read GetSize write SetSize stored false;
|
---|
63 | property PixelsPerInch: Integer read GetPixelsPerInch write SetPixelsPerInch;
|
---|
64 | property Height: Integer read GetHeight write SetHeight default 0;
|
---|
65 | property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
---|
66 | end;
|
---|
67 |
|
---|
68 | { TPen }
|
---|
69 |
|
---|
70 | TPen = class
|
---|
71 | FWidth: Integer;
|
---|
72 | FNativePen: Graphics.TPen;
|
---|
73 | FNativePenFree: Boolean;
|
---|
74 | private
|
---|
75 | function GetColor: TColor;
|
---|
76 | function GetStyle: TPenStyle;
|
---|
77 | function GetWidth: Integer;
|
---|
78 | procedure SetColor(AValue: TColor);
|
---|
79 | procedure SetNativePen(AValue: Graphics.TPen);
|
---|
80 | procedure SetStyle(AValue: TPenStyle);
|
---|
81 | procedure SetWidth(AValue: Integer);
|
---|
82 | public
|
---|
83 | constructor Create;
|
---|
84 | destructor Destroy; override;
|
---|
85 | function GetNativePen: Graphics.TPen;
|
---|
86 | procedure Assign(Source: TPen);
|
---|
87 | property NativePen: Graphics.TPen read FNativePen write SetNativePen;
|
---|
88 | published
|
---|
89 | property Color: TColor read GetColor write SetColor default clBlack;
|
---|
90 | property Style : TPenStyle read GetStyle write SetStyle default psSolid;
|
---|
91 | property Width: Integer read GetWidth write SetWidth default 1;
|
---|
92 | end;
|
---|
93 |
|
---|
94 | TBrushStyle = Graphics.TBrushStyle;
|
---|
95 | TPenStyle = Graphics.TPenStyle;
|
---|
96 |
|
---|
97 | { TBrush }
|
---|
98 |
|
---|
99 | TBrush = class
|
---|
100 | private
|
---|
101 | FNativeBrush: Graphics.TBrush;
|
---|
102 | FNativeBrushFree: Boolean;
|
---|
103 | function GetColor: TColor;
|
---|
104 | function GetStyle: TBrushStyle;
|
---|
105 | procedure SetColor(AValue: TColor);
|
---|
106 | function GetNativeBrush: Graphics.TBrush;
|
---|
107 | procedure SetNativeBrush(AValue: Graphics.TBrush);
|
---|
108 | procedure SetStyle(AValue: TBrushStyle);
|
---|
109 | public
|
---|
110 | constructor Create;
|
---|
111 | destructor Destroy; override;
|
---|
112 | procedure Assign(Source: TBrush);
|
---|
113 | property NativeBrush: Graphics.TBrush read FNativeBrush write SetNativeBrush;
|
---|
114 | published
|
---|
115 | property Color: TColor read GetColor write SetColor default clWhite;
|
---|
116 | property Style: TBrushStyle read GetStyle write SetStyle default bsSolid;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | TGraphic = class;
|
---|
120 |
|
---|
121 | { TCanvas }
|
---|
122 |
|
---|
123 | TCanvas = class
|
---|
124 | private
|
---|
125 | FBrush: TBrush;
|
---|
126 | FBrushFree: Boolean;
|
---|
127 | FPen: TPen;
|
---|
128 | FPenFree: Boolean;
|
---|
129 | FFont: TFont;
|
---|
130 | FFontFree: Boolean;
|
---|
131 | FNativeCanvas: Graphics.TCanvas;
|
---|
132 | FNativeCanvasFree: Boolean;
|
---|
133 | function GetHandle: HDC;
|
---|
134 | function GetPixel(X, Y: Integer): TColor;
|
---|
135 | function GetTextStyle: TTextStyle;
|
---|
136 | procedure SetBrush(AValue: TBrush);
|
---|
137 | procedure SetFont(AValue: TFont);
|
---|
138 | procedure SetHandle(AValue: HDC);
|
---|
139 | procedure SetPen(AValue: TPen);
|
---|
140 | procedure SetPixel(X, Y: Integer; AValue: TColor);
|
---|
141 | procedure SetNativeCanvas(AValue: Graphics.TCanvas);
|
---|
142 | procedure SetTextStyle(AValue: TTextStyle);
|
---|
143 | protected
|
---|
144 | procedure DoLine(X1, Y1, X2, Y2: Integer); virtual;
|
---|
145 | procedure DoTextOut(X, Y: Integer; Text: string); virtual;
|
---|
146 | procedure DoRectangle(const Bounds: TRect); virtual;
|
---|
147 | procedure DoRectangleFill(const Bounds: TRect); virtual;
|
---|
148 | procedure DoPolygon(const Points: array of TPoint); virtual;
|
---|
149 | procedure CreateHandle; virtual;
|
---|
150 | procedure DoEllipse(const Bounds: TRect); virtual;
|
---|
151 | procedure DoMoveTo(X, Y: Integer); virtual;
|
---|
152 | procedure DoLineTo(X, Y: Integer); virtual;
|
---|
153 | procedure DoPolyline(const Points: array of TPoint); virtual;
|
---|
154 | procedure DoPolyBezier(Points: PPoint; NumPts: Integer;
|
---|
155 | Filled: Boolean = False; Continuous: Boolean = False); virtual;
|
---|
156 | procedure SetHeight(AValue: Integer); virtual;
|
---|
157 | procedure SetWidth(AValue: Integer); virtual;
|
---|
158 | function GetWidth: Integer; virtual;
|
---|
159 | function GetHeight: Integer; virtual;
|
---|
160 | function GetNativeCanvas: Graphics.TCanvas; virtual;
|
---|
161 | public
|
---|
162 | property NativeCanvas: Graphics.TCanvas read FNativeCanvas write SetNativeCanvas;
|
---|
163 | procedure RoundRect(const Rect: TRect; RX, RY: Integer); overload;
|
---|
164 | procedure RoundRect(X1, Y1, X2, Y2: Integer; RX,RY: Integer); overload; virtual;
|
---|
165 | procedure Polygon(const Points: array of TPoint; Winding: Boolean;
|
---|
166 | StartIndex: Integer = 0; NumPts: Integer = -1); overload;
|
---|
167 | procedure Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean = False); virtual; overload;
|
---|
168 | procedure Polygon(const Points: array of TPoint); overload;
|
---|
169 | procedure PolyBezier(const Points: array of TPoint;
|
---|
170 | Filled: Boolean = False; Continuous: boolean = True); overload;
|
---|
171 | procedure PolyBezier(Points: PPoint; NumPts: Integer;
|
---|
172 | Filled: Boolean = False; Continuous: Boolean = True); virtual; overload;
|
---|
173 | procedure Polyline(const Points: array of TPoint); overload;
|
---|
174 | procedure Polyline(Points: PPoint; NumPts: Integer); virtual; overload;
|
---|
175 | procedure Ellipse(x1, y1, x2, y2: Integer); virtual; overload;
|
---|
176 | procedure Ellipse(const ARect: TRect); virtual; overload;
|
---|
177 | // procedure StretchDraw(const DestRect: TRect; SrcGraphic: Graphics.TGraphic); virtual; overload;
|
---|
178 | procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); virtual; overload;
|
---|
179 | procedure Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2,
|
---|
180 | StartX, StartY, EndX, EndY: Integer); virtual;
|
---|
181 | procedure FrameRect(Rect: TRect);
|
---|
182 | procedure Rectangle(X1, Y1, X2, Y2: Integer); overload;
|
---|
183 | procedure Rectangle(const ARect: TRect); overload;
|
---|
184 | function TextWidth(const Text: string): Integer;
|
---|
185 | function TextHeight(const Text: string): Integer;
|
---|
186 | function TextExtent(const Text: string): TSize; virtual;
|
---|
187 | procedure TextOut(X, Y: Integer; const Text: string); virtual;
|
---|
188 | procedure TextRect(ARect: TRect; X, Y: Integer; Text: string); overload;
|
---|
189 | procedure TextRect(ARect: TRect; X, Y: integer; const Text: string;
|
---|
190 | const Style: TTextStyle); overload;
|
---|
191 | procedure MoveTo(X, Y: Integer);
|
---|
192 | procedure LineTo(X, Y: Integer);
|
---|
193 | procedure Line(const p1, p2: TPoint);
|
---|
194 | procedure FillRect(const ARect: TRect); virtual; overload;
|
---|
195 | procedure FillRect(X1, Y1, X2, Y2: Integer); overload;
|
---|
196 | procedure Draw(X, Y: Integer; Source: TGraphic);
|
---|
197 | procedure CopyRect(Dest: TRect; SrcCanvas: TCanvas; Source: TRect);
|
---|
198 | constructor Create;
|
---|
199 | destructor Destroy; override;
|
---|
200 | property Handle: HDC read GetHandle write SetHandle;
|
---|
201 | property Pixels[X, Y: Integer]: TColor read GetPixel write SetPixel;
|
---|
202 | property Width: Integer read GetWidth;
|
---|
203 | property Height: Integer read GetHeight;
|
---|
204 | property TextStyle: TTextStyle read GetTextStyle write SetTextStyle;
|
---|
205 | published
|
---|
206 | property Brush: TBrush read FBrush write SetBrush;
|
---|
207 | property Pen: TPen read FPen write SetPen;
|
---|
208 | property Font: TFont read FFont write SetFont;
|
---|
209 | end;
|
---|
210 |
|
---|
211 | { TGraphic }
|
---|
212 |
|
---|
213 | TGraphic = class(TPersistent)
|
---|
214 | protected
|
---|
215 | FDpi: Integer;
|
---|
216 | function GetNativeGraphic: Graphics.TGraphic; virtual;
|
---|
217 | function GetWidth: Integer; virtual; abstract;
|
---|
218 | function GetHeight: Integer; virtual; abstract;
|
---|
219 | procedure SetWidth(Value: Integer); virtual; abstract;
|
---|
220 | procedure SetHeight(Value: Integer); virtual; abstract;
|
---|
221 | procedure ScreenChanged; virtual;
|
---|
222 | procedure SetDpi(AValue: Integer); virtual;
|
---|
223 | function GetDpi: Integer; virtual;
|
---|
224 | public
|
---|
225 | NativeGraphicClass: TGraphicClass;
|
---|
226 | constructor Create; virtual;
|
---|
227 | procedure LoadFromFile(const Filename: string); virtual;
|
---|
228 | procedure SaveToFile(const Filename: string); virtual;
|
---|
229 | property Width: Integer read GetWidth write SetWidth;
|
---|
230 | property Height: Integer read GetHeight write SetHeight;
|
---|
231 | property Dpi: Integer read GetDpi write SetDpi;
|
---|
232 | end;
|
---|
233 |
|
---|
234 | { TRasterImage }
|
---|
235 |
|
---|
236 | TRasterImage = class(TGraphic)
|
---|
237 | private
|
---|
238 | FCanvas: TCanvas;
|
---|
239 | function GetCanvas: TCanvas;
|
---|
240 | function GetRawImage: TRawImage;
|
---|
241 | protected
|
---|
242 | function GetHeight: Integer; override;
|
---|
243 | function GetWidth: Integer; override;
|
---|
244 | function GetPixelFormat: TPixelFormat; virtual; abstract;
|
---|
245 | procedure SetWidth(Value: Integer); override;
|
---|
246 | procedure SetHeight(Value: Integer); override;
|
---|
247 | procedure SetSize(AWidth, AHeight: Integer); virtual; abstract;
|
---|
248 | procedure SetPixelFormat(AValue: TPixelFormat); virtual; abstract;
|
---|
249 | function GetNativeGraphic: Graphics.TGraphic; override;
|
---|
250 | function GetNativeRasterImage: Graphics.TRasterImage; virtual;
|
---|
251 | procedure SetNativeRasterImage(CustomBitmap: Graphics.TRasterImage); virtual; abstract;
|
---|
252 | public
|
---|
253 | constructor Create; override;
|
---|
254 | destructor Destroy; override;
|
---|
255 | procedure BeginUpdate(ACanvasOnly: Boolean = False);
|
---|
256 | procedure EndUpdate(AStreamIsValid: Boolean = False);
|
---|
257 | property Canvas: TCanvas read GetCanvas;
|
---|
258 | property RawImage: TRawImage read GetRawImage;
|
---|
259 | property PixelFormat: TPixelFormat read GetPixelFormat write SetPixelFormat;
|
---|
260 | end;
|
---|
261 |
|
---|
262 | { TCustomBitmap }
|
---|
263 |
|
---|
264 | TCustomBitmap = class(TRasterImage)
|
---|
265 | private
|
---|
266 | FWidth: Integer;
|
---|
267 | FHeight: Integer;
|
---|
268 | protected
|
---|
269 | function GetHeight: Integer; override;
|
---|
270 | function GetWidth: Integer; override;
|
---|
271 | function GetPixelFormat: TPixelFormat; override;
|
---|
272 | procedure SetPixelFormat(AValue: TPixelFormat); override;
|
---|
273 | function GetNativeCustomBitmap: Graphics.TCustomBitmap; virtual;
|
---|
274 | function GetNativeRasterImage: Graphics.TRasterImage; override;
|
---|
275 | procedure SetNativeRasterImage(RasterImage: Graphics.TRasterImage); override;
|
---|
276 | procedure SetNativeCustomBitmap(CustomBitmap: Graphics.TCustomBitmap); virtual; abstract;
|
---|
277 | procedure ScreenChanged; override;
|
---|
278 | public
|
---|
279 | procedure Assign(Source: TPersistent); override;
|
---|
280 | procedure SetSize(AWidth, AHeight: Integer); override;
|
---|
281 | end;
|
---|
282 |
|
---|
283 | { TBitmap }
|
---|
284 |
|
---|
285 | TBitmap = class(TCustomBitmap)
|
---|
286 | private
|
---|
287 | function GetScanLine(Row: Integer): Pointer;
|
---|
288 | function GetTransparent: Boolean;
|
---|
289 | function GetTransparentColor: TColor;
|
---|
290 | procedure SetTransparent(AValue: Boolean);
|
---|
291 | procedure SetTransparentColor(AValue: TColor);
|
---|
292 | protected
|
---|
293 | function GetNativeBitmap: Graphics.TBitmap; virtual;
|
---|
294 | function GetNativeCustomBitmap: Graphics.TCustomBitmap; override;
|
---|
295 | procedure SetNativeBitmap(ANativeBitmap: Graphics.TBitmap); virtual;
|
---|
296 | procedure SetNativeCustomBitmap(CustomBitmap: Graphics.TCustomBitmap); override;
|
---|
297 | public
|
---|
298 | NativeBitmap: Graphics.TBitmap;
|
---|
299 | constructor Create; override;
|
---|
300 | destructor Destroy; override;
|
---|
301 | property ScanLine[Row: Integer]: Pointer read GetScanLine;
|
---|
302 | published
|
---|
303 | property TransparentColor: TColor read GetTransparentColor
|
---|
304 | write SetTransparentColor default clDefault;
|
---|
305 | property Transparent: Boolean read GetTransparent write SetTransparent default False;
|
---|
306 | end;
|
---|
307 |
|
---|
308 | { TJpegImage }
|
---|
309 |
|
---|
310 | TJpegImage = class(TCustomBitmap)
|
---|
311 | protected
|
---|
312 | function GetNativeCustomBitmap: Graphics.TCustomBitmap; override;
|
---|
313 | function GetNativeJpeg: Graphics.TJPEGImage; virtual;
|
---|
314 | procedure SetNativeCustomBitmap(CustomBitmap: Graphics.TCustomBitmap); override;
|
---|
315 | procedure SetNativeJpeg(Jpeg: Graphics.TJPEGImage); virtual;
|
---|
316 | public
|
---|
317 | NativeJpeg: Graphics.TJPEGImage;
|
---|
318 | constructor Create; override;
|
---|
319 | destructor Destroy; override;
|
---|
320 | end;
|
---|
321 |
|
---|
322 | { TPortableNetworkGraphic }
|
---|
323 |
|
---|
324 | TPortableNetworkGraphic = class(TCustomBitmap)
|
---|
325 | protected
|
---|
326 | function GetNativeCustomBitmap: Graphics.TCustomBitmap; override;
|
---|
327 | function GetNativePng: Graphics.TPortableNetworkGraphic; virtual;
|
---|
328 | procedure SetNativeCustomBitmap(CustomBitmap: Graphics.TCustomBitmap); override;
|
---|
329 | procedure SetNativePng(Png: Graphics.TPortableNetworkGraphic); virtual;
|
---|
330 | public
|
---|
331 | NativePng: Graphics.TPortableNetworkGraphic;
|
---|
332 | constructor Create; override;
|
---|
333 | destructor Destroy; override;
|
---|
334 | end;
|
---|
335 |
|
---|
336 | { TPicture }
|
---|
337 |
|
---|
338 | TPicture = class(TPersistent)
|
---|
339 | private
|
---|
340 | FBitmap: TBitmap;
|
---|
341 | procedure SetBitmap(AValue: TBitmap);
|
---|
342 | published
|
---|
343 | procedure LoadFromFile(FileName: string);
|
---|
344 | property Bitmap: TBitmap read FBitmap write SetBitmap;
|
---|
345 | end;
|
---|
346 |
|
---|
347 | { TScreenInfo }
|
---|
348 |
|
---|
349 | TScreenInfo = record
|
---|
350 | private
|
---|
351 | FDpi: Integer;
|
---|
352 | procedure SetDpi(AValue: Integer);
|
---|
353 | public
|
---|
354 | ToNative: Double;
|
---|
355 | FromNative: Double;
|
---|
356 | LookupToNative: array[-10000..10000] of Integer; // Should be sufficient for 8K screens
|
---|
357 | LookupFromNative: array[-10000..10000] of Integer; // Should be sufficient for 8K screens
|
---|
358 | property Dpi: Integer read FDpi write SetDpi;
|
---|
359 | end;
|
---|
360 |
|
---|
361 | var
|
---|
362 | ScreenInfo: TScreenInfo;
|
---|
363 |
|
---|
364 |
|
---|
365 | implementation
|
---|
366 |
|
---|
367 | uses
|
---|
368 | Dpi.Common, NativePixelPointer;
|
---|
369 |
|
---|
370 | { TCustomBitmap }
|
---|
371 |
|
---|
372 | function TCustomBitmap.GetHeight: Integer;
|
---|
373 | begin
|
---|
374 | Result := FHeight;
|
---|
375 | end;
|
---|
376 |
|
---|
377 | function TCustomBitmap.GetWidth: Integer;
|
---|
378 | begin
|
---|
379 | Result := FWidth;
|
---|
380 | end;
|
---|
381 |
|
---|
382 | function TCustomBitmap.GetPixelFormat: TPixelFormat;
|
---|
383 | begin
|
---|
384 | Result := GetNativeCustomBitmap.PixelFormat;
|
---|
385 | end;
|
---|
386 |
|
---|
387 | procedure TCustomBitmap.SetPixelFormat(AValue: TPixelFormat);
|
---|
388 | begin
|
---|
389 | GetNativeCustomBitmap.PixelFormat := AValue;
|
---|
390 | end;
|
---|
391 |
|
---|
392 | function TCustomBitmap.GetNativeCustomBitmap: Graphics.TCustomBitmap;
|
---|
393 | begin
|
---|
394 | Result := nil;
|
---|
395 | end;
|
---|
396 |
|
---|
397 | function TCustomBitmap.GetNativeRasterImage: Graphics.TRasterImage;
|
---|
398 | begin
|
---|
399 | Result := GetNativeCustomBitmap;
|
---|
400 | end;
|
---|
401 |
|
---|
402 | procedure TCustomBitmap.SetNativeRasterImage(RasterImage: Graphics.TRasterImage
|
---|
403 | );
|
---|
404 | begin
|
---|
405 | SetNativeCustomBitmap(Graphics.TCustomBitmap(RasterImage));
|
---|
406 | end;
|
---|
407 |
|
---|
408 | procedure TCustomBitmap.ScreenChanged;
|
---|
409 | var
|
---|
410 | Bitmap: Graphics.TCustomBitmap;
|
---|
411 | NewWidth: Integer;
|
---|
412 | NewHeight: Integer;
|
---|
413 | begin
|
---|
414 | NewWidth := ScaleToNative(Width);
|
---|
415 | NewHeight := ScaleToNative(Height);
|
---|
416 | if Assigned(GetNativeCustomBitmap) and ((NewWidth <> GetNativeCustomBitmap.Width) or
|
---|
417 | (NewHeight <> GetNativeCustomBitmap.Height)) then begin
|
---|
418 | // Rescale bitmap to new size
|
---|
419 | if NativeGraphicClass = Graphics.TBitmap then
|
---|
420 | Bitmap := Graphics.TBitmap.Create
|
---|
421 | else if NativeGraphicClass = Graphics.TPortableNetworkGraphic then
|
---|
422 | Bitmap := Graphics.TPortableNetworkGraphic.Create
|
---|
423 | else if NativeGraphicClass = Graphics.TJPEGImage then
|
---|
424 | Bitmap := Graphics.TJPEGImage.Create
|
---|
425 | else raise Exception.Create('Unsupported image class');
|
---|
426 | Bitmap.SetSize(NewWidth, NewHeight);
|
---|
427 | Bitmap.PixelFormat := GetNativeCustomBitmap.PixelFormat;
|
---|
428 | Bitmap.Canvas.StretchDraw(Bounds(0, 0, NewWidth, NewHeight), GetNativeCustomBitmap);
|
---|
429 | GetNativeCustomBitmap.Free;
|
---|
430 | SetNativeCustomBitmap(Bitmap);
|
---|
431 | Canvas.NativeCanvas := GetNativeCustomBitmap.Canvas;
|
---|
432 | end;
|
---|
433 | end;
|
---|
434 |
|
---|
435 | procedure TCustomBitmap.Assign(Source: TPersistent);
|
---|
436 | begin
|
---|
437 | if Source is TCustomBitmap then begin
|
---|
438 | GetNativeCustomBitmap.Assign(TCustomBitmap(Source).GetNativeCustomBitmap);
|
---|
439 | FWidth := TCustomBitmap(Source).FWidth;
|
---|
440 | FHeight := TCustomBitmap(Source).FHeight
|
---|
441 | end else inherited;
|
---|
442 | end;
|
---|
443 |
|
---|
444 | procedure TCustomBitmap.SetSize(AWidth, AHeight: Integer);
|
---|
445 | begin
|
---|
446 | FWidth := AWidth;
|
---|
447 | FHeight := AHeight;
|
---|
448 | GetNativeCustomBitmap.SetSize(ScaleToNative(AWidth), ScaleToNative(AHeight));
|
---|
449 | end;
|
---|
450 |
|
---|
451 | { TFont }
|
---|
452 |
|
---|
453 | procedure TFont.SetSize(AValue: Integer);
|
---|
454 | begin
|
---|
455 | if FSize = AValue then Exit;
|
---|
456 | FSize := AValue;
|
---|
457 | FHeight := -MulDiv(FSize, FPixelsPerInch, 72);
|
---|
458 | UpdateFont;
|
---|
459 | DoChange;
|
---|
460 | end;
|
---|
461 |
|
---|
462 | procedure TFont.DoChange;
|
---|
463 | begin
|
---|
464 | if Assigned(FOnChange) then FOnChange(Self);
|
---|
465 | end;
|
---|
466 |
|
---|
467 | procedure TFont.SetStyle(AValue: TFontStyles);
|
---|
468 | begin
|
---|
469 | GetNativeFont.Style := AValue;
|
---|
470 | end;
|
---|
471 |
|
---|
472 | procedure TFont.UpdateFont;
|
---|
473 | begin
|
---|
474 | if Assigned(GetNativeFont) then begin
|
---|
475 | GetNativeFont.PixelsPerInch := FPixelsPerInch;
|
---|
476 | GetNativeFont.Size := FSize;
|
---|
477 | end;
|
---|
478 | end;
|
---|
479 |
|
---|
480 | procedure TFont.ScreenChanged;
|
---|
481 | begin
|
---|
482 | DoChange;
|
---|
483 | end;
|
---|
484 |
|
---|
485 | function TFont.GetNativeFont: Graphics.TFont;
|
---|
486 | begin
|
---|
487 | Result := NativeFont;
|
---|
488 | end;
|
---|
489 |
|
---|
490 | procedure TFont.SetPixelsPerInch(AValue: Integer);
|
---|
491 | begin
|
---|
492 | FPixelsPerInch := PixelsPerInch;
|
---|
493 | FHeight := -MulDiv(FSize, FPixelsPerInch, 72);
|
---|
494 | UpdateFont;
|
---|
495 | end;
|
---|
496 |
|
---|
497 | function TFont.GetName: string;
|
---|
498 | begin
|
---|
499 | Result := GetNativeFont.Name;
|
---|
500 | end;
|
---|
501 |
|
---|
502 | function TFont.GetColor: TColor;
|
---|
503 | begin
|
---|
504 | Result := FColor;
|
---|
505 | end;
|
---|
506 |
|
---|
507 | function TFont.GetCharSet: TFontCharSet;
|
---|
508 | begin
|
---|
509 | Result := GetNativeFont.CharSet;
|
---|
510 | end;
|
---|
511 |
|
---|
512 | function TFont.GetHeight: Integer;
|
---|
513 | begin
|
---|
514 | Result := GetNativeFont.Height;
|
---|
515 | end;
|
---|
516 |
|
---|
517 | function TFont.GetPixelsPerInch: Integer;
|
---|
518 | begin
|
---|
519 | Result := FPixelsPerInch;
|
---|
520 | end;
|
---|
521 |
|
---|
522 | function TFont.GetSize: Integer;
|
---|
523 | begin
|
---|
524 | Result := FSize;
|
---|
525 | end;
|
---|
526 |
|
---|
527 | function TFont.GetStyle: TFontStyles;
|
---|
528 | begin
|
---|
529 | Result := GetNativeFont.Style;
|
---|
530 | end;
|
---|
531 |
|
---|
532 | function TFont.IsNameStored: Boolean;
|
---|
533 | begin
|
---|
534 | Result := GetNativeFont.Name <> 'default';
|
---|
535 | end;
|
---|
536 |
|
---|
537 | procedure TFont.SetCharSet(AValue: TFontCharSet);
|
---|
538 | begin
|
---|
539 | GetNativeFont.CharSet := AValue;
|
---|
540 | end;
|
---|
541 |
|
---|
542 | procedure TFont.SetColor(AValue: TColor);
|
---|
543 | begin
|
---|
544 | if FColor = AValue then Exit;
|
---|
545 | FColor := AValue;
|
---|
546 | GetNativeFont.Color := AValue;
|
---|
547 | end;
|
---|
548 |
|
---|
549 | procedure TFont.SetHeight(AValue: Integer);
|
---|
550 | begin
|
---|
551 | FHeight := AValue;
|
---|
552 | FSize := MulDiv(-FHeight, 72, FPixelsPerInch);
|
---|
553 | UpdateFont;
|
---|
554 | end;
|
---|
555 |
|
---|
556 | procedure TFont.SetName(AValue: string);
|
---|
557 | begin
|
---|
558 | GetNativeFont.Name := AValue;
|
---|
559 | end;
|
---|
560 |
|
---|
561 | procedure TFont.SetNativeFont(AValue: Graphics.TFont);
|
---|
562 | begin
|
---|
563 | if FNativeFont = AValue then Exit;
|
---|
564 | if FNativeFontFree then FreeAndNil(FNativeFont);
|
---|
565 | FNativeFontFree := False;
|
---|
566 | FNativeFont := AValue;
|
---|
567 | end;
|
---|
568 |
|
---|
569 | constructor TFont.Create;
|
---|
570 | begin
|
---|
571 | FNativeFont := Graphics.TFont.Create;
|
---|
572 | FNativeFontFree := True;
|
---|
573 | FPixelsPerInch := ScreenInfo.Dpi;
|
---|
574 | Size := 8;
|
---|
575 | Color := clDefault;
|
---|
576 | end;
|
---|
577 |
|
---|
578 | destructor TFont.Destroy;
|
---|
579 | begin
|
---|
580 | if FNativeFontFree then
|
---|
581 | FreeAndNil(FNativeFont);
|
---|
582 | inherited;
|
---|
583 | end;
|
---|
584 |
|
---|
585 | procedure TFont.Assign(Source: TPersistent);
|
---|
586 | begin
|
---|
587 | if Source is TFont then begin
|
---|
588 | GetNativeFont.Assign((Source as TFont).GetNativeFont);
|
---|
589 | Size := (Source as TFont).Size;
|
---|
590 | Height := (Source as TFont).Height;
|
---|
591 | PixelsPerInch := (Source as TFont).PixelsPerInch;
|
---|
592 | FOnChange := (Source as TFont).FOnChange;
|
---|
593 | Color := (Source as TFont).Color;
|
---|
594 | end;
|
---|
595 | end;
|
---|
596 |
|
---|
597 | procedure TFont.GetTextSize(Text: string; var w, h: Integer);
|
---|
598 | begin
|
---|
599 | W := GetTextWidth(Text);
|
---|
600 | H := GetTextHeight(Text);
|
---|
601 | end;
|
---|
602 |
|
---|
603 | function TFont.GetTextHeight(Text: string): Integer;
|
---|
604 | begin
|
---|
605 | Result := ScaleFromNative(GetNativeFont.GetTextHeight(Text));
|
---|
606 | end;
|
---|
607 |
|
---|
608 | function TFont.GetTextWidth(Text: string): Integer;
|
---|
609 | begin
|
---|
610 | Result := ScaleFromNative(GetNativeFont.GetTextWidth(Text));
|
---|
611 | end;
|
---|
612 |
|
---|
613 | { TRasterImage }
|
---|
614 |
|
---|
615 | function TRasterImage.GetCanvas: TCanvas;
|
---|
616 | begin
|
---|
617 | Result := FCanvas;
|
---|
618 | end;
|
---|
619 |
|
---|
620 | function TRasterImage.GetRawImage: TRawImage;
|
---|
621 | begin
|
---|
622 | Result := GetNativeRasterImage.RawImage;
|
---|
623 | end;
|
---|
624 |
|
---|
625 | function TRasterImage.GetHeight: Integer;
|
---|
626 | begin
|
---|
627 | Result := ScaleFromNative(GetNativeRasterImage.Height);
|
---|
628 | end;
|
---|
629 |
|
---|
630 | function TRasterImage.GetWidth: Integer;
|
---|
631 | begin
|
---|
632 | Result := ScaleFromNative(GetNativeRasterImage.Width);
|
---|
633 | end;
|
---|
634 |
|
---|
635 | procedure TRasterImage.SetWidth(Value: Integer);
|
---|
636 | begin
|
---|
637 | SetSize(Value, Height);
|
---|
638 | end;
|
---|
639 |
|
---|
640 | procedure TRasterImage.SetHeight(Value: Integer);
|
---|
641 | begin
|
---|
642 | SetSize(Width, Value);
|
---|
643 | end;
|
---|
644 |
|
---|
645 | function TRasterImage.GetNativeRasterImage: Graphics.TRasterImage;
|
---|
646 | begin
|
---|
647 | Result := nil;
|
---|
648 | end;
|
---|
649 |
|
---|
650 | constructor TRasterImage.Create;
|
---|
651 | begin
|
---|
652 | inherited;
|
---|
653 | FCanvas := TCanvas.Create;
|
---|
654 | FCanvas.NativeCanvas := GetNativeRasterImage.Canvas;
|
---|
655 | end;
|
---|
656 |
|
---|
657 | destructor TRasterImage.Destroy;
|
---|
658 | begin
|
---|
659 | FreeAndNil(FCanvas);
|
---|
660 | inherited;
|
---|
661 | end;
|
---|
662 |
|
---|
663 | procedure TRasterImage.BeginUpdate(ACanvasOnly: Boolean);
|
---|
664 | begin
|
---|
665 | GetNativeRasterImage.BeginUpdate(ACanvasOnly);
|
---|
666 | end;
|
---|
667 |
|
---|
668 | procedure TRasterImage.EndUpdate(AStreamIsValid: Boolean);
|
---|
669 | begin
|
---|
670 | GetNativeRasterImage.EndUpdate(AStreamIsValid);
|
---|
671 | end;
|
---|
672 |
|
---|
673 | function TRasterImage.GetNativeGraphic: Graphics.TGraphic;
|
---|
674 | begin
|
---|
675 | Result := GetNativeRasterImage;
|
---|
676 | end;
|
---|
677 |
|
---|
678 | { TGraphic }
|
---|
679 |
|
---|
680 | function TGraphic.GetNativeGraphic: Graphics.TGraphic;
|
---|
681 | begin
|
---|
682 | Result := nil;
|
---|
683 | end;
|
---|
684 |
|
---|
685 | procedure TGraphic.ScreenChanged;
|
---|
686 | begin
|
---|
687 | end;
|
---|
688 |
|
---|
689 | procedure TGraphic.SetDpi(AValue: Integer);
|
---|
690 | begin
|
---|
691 | FDpi := AValue;
|
---|
692 | ScreenChanged;
|
---|
693 | end;
|
---|
694 |
|
---|
695 | function TGraphic.GetDpi: Integer;
|
---|
696 | begin
|
---|
697 | Result := FDpi;
|
---|
698 | end;
|
---|
699 |
|
---|
700 | constructor TGraphic.Create;
|
---|
701 | begin
|
---|
702 | Dpi := ScreenInfo.Dpi;
|
---|
703 | end;
|
---|
704 |
|
---|
705 | procedure StretchDrawBitmap(Src: Graphics.TRasterImage; Dst: Graphics.TCustomBitmap);
|
---|
706 | var
|
---|
707 | SrcPtr: TPixelPointer;
|
---|
708 | DstPtr: TPixelPointer;
|
---|
709 | XX, YY: Integer;
|
---|
710 | DstPixelX, DstPixelY: Integer;
|
---|
711 | DstPixelWidth, DstPixelHeight: Integer;
|
---|
712 | begin
|
---|
713 | Dst.BeginUpdate;
|
---|
714 | SrcPtr := TPixelPointer.Create(Src, 0, 0);
|
---|
715 | DstPtr := TPixelPointer.Create(Dst, 0, 0);
|
---|
716 | for YY := 0 to Src.Height - 1 do begin
|
---|
717 | DstPixelHeight := ScaleToNative(YY + 1) - ScaleToNative(YY);
|
---|
718 | for DstPixelY := 0 to DstPixelHeight - 1 do begin
|
---|
719 | for XX := 0 to Src.Width - 1 do begin
|
---|
720 | DstPixelWidth := ScaleToNative(XX + 1) - ScaleToNative(XX);
|
---|
721 | for DstPixelX := 0 to DstPixelWidth - 1 do begin
|
---|
722 | DstPtr.PixelRGB := SrcPtr.PixelRGB;
|
---|
723 | DstPtr.NextPixel;
|
---|
724 | end;
|
---|
725 | SrcPtr.NextPixel;
|
---|
726 | end;
|
---|
727 | DstPtr.NextLine;
|
---|
728 | SrcPtr.SetX(0);
|
---|
729 | end;
|
---|
730 | SrcPtr.NextLine;
|
---|
731 | end;
|
---|
732 | Dst.EndUpdate;
|
---|
733 | end;
|
---|
734 |
|
---|
735 | procedure TGraphic.LoadFromFile(const Filename: string);
|
---|
736 | var
|
---|
737 | Bitmap: Graphics.TGraphic;
|
---|
738 | begin
|
---|
739 | Bitmap := NativeGraphicClass.Create;
|
---|
740 | try
|
---|
741 | Bitmap.LoadFromFile(FileName);
|
---|
742 | if Self is TRasterImage then begin
|
---|
743 | TRasterImage(Self).SetSize(Bitmap.Width, Bitmap.Height);
|
---|
744 | end else begin
|
---|
745 | Width := Bitmap.Width;
|
---|
746 | Height := Bitmap.Height;
|
---|
747 | end;
|
---|
748 | if Self is TCustomBitmap then begin
|
---|
749 | StretchDrawBitmap(Graphics.TRasterImage(Bitmap),
|
---|
750 | Graphics.TCustomBitmap(GetNativeGraphic));
|
---|
751 | //Graphics.TBitmap(GetNativeGraphic).Canvas.StretchDraw(Bounds(0, 0,
|
---|
752 | //Graphics.TBitmap(GetNativeGraphic).Width, TBitmap(GetNativeGraphic).Height), Bitmap);
|
---|
753 | end else raise Exception.Create('Unsupported class ' + Self.ClassName);
|
---|
754 | finally
|
---|
755 | FreeAndNil(Bitmap);
|
---|
756 | end;
|
---|
757 | end;
|
---|
758 |
|
---|
759 | procedure TGraphic.SaveToFile(const Filename: string);
|
---|
760 | var
|
---|
761 | Bitmap: Graphics.TGraphic;
|
---|
762 | begin
|
---|
763 | Bitmap := NativeGraphicClass.Create;
|
---|
764 | try
|
---|
765 | Bitmap.Width := Width;
|
---|
766 | Bitmap.Height := Height;
|
---|
767 | if Self is TBitmap then begin
|
---|
768 | if Bitmap is Graphics.TRasterImage then
|
---|
769 | (Bitmap as Graphics.TRasterImage).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width,
|
---|
770 | Bitmap.Height), Graphics.TBitmap(GetNativeGraphic))
|
---|
771 | else raise Exception.Create('Expected TRasterImage but got ' + Bitmap.ClassName);
|
---|
772 | end else raise Exception.Create('Unsupported class ' + Self.ClassName);
|
---|
773 | Bitmap.SaveToFile(FileName);
|
---|
774 | finally
|
---|
775 | FreeAndNil(Bitmap);
|
---|
776 | end;
|
---|
777 | end;
|
---|
778 |
|
---|
779 | { TBitmap }
|
---|
780 |
|
---|
781 | function TBitmap.GetScanLine(Row: Integer): Pointer;
|
---|
782 | begin
|
---|
783 | Result := GetNativeBitmap.ScanLine[Row];
|
---|
784 | end;
|
---|
785 |
|
---|
786 | function TBitmap.GetTransparent: Boolean;
|
---|
787 | begin
|
---|
788 | Result := GetNativeBitmap.Transparent;
|
---|
789 | end;
|
---|
790 |
|
---|
791 | function TBitmap.GetTransparentColor: TColor;
|
---|
792 | begin
|
---|
793 | Result := GetNativeBitmap.TransparentColor;
|
---|
794 | end;
|
---|
795 |
|
---|
796 | procedure TBitmap.SetTransparent(AValue: Boolean);
|
---|
797 | begin
|
---|
798 | GetNativeBitmap.Transparent := AValue;
|
---|
799 | end;
|
---|
800 |
|
---|
801 | procedure TBitmap.SetTransparentColor(AValue: TColor);
|
---|
802 | begin
|
---|
803 | GetNativeBitmap.TransparentColor := AValue;
|
---|
804 | end;
|
---|
805 |
|
---|
806 | function TBitmap.GetNativeBitmap: Graphics.TBitmap;
|
---|
807 | begin
|
---|
808 | Result := NativeBitmap;
|
---|
809 | end;
|
---|
810 |
|
---|
811 | function TBitmap.GetNativeCustomBitmap: Graphics.TCustomBitmap;
|
---|
812 | begin
|
---|
813 | Result := GetNativeBitmap;
|
---|
814 | end;
|
---|
815 |
|
---|
816 | procedure TBitmap.SetNativeBitmap(ANativeBitmap: Graphics.TBitmap);
|
---|
817 | begin
|
---|
818 | NativeBitmap := ANativeBitmap;
|
---|
819 | end;
|
---|
820 |
|
---|
821 | procedure TBitmap.SetNativeCustomBitmap(CustomBitmap: Graphics.TCustomBitmap);
|
---|
822 | begin
|
---|
823 | SetNativeBitmap(Graphics.TBitmap(CustomBitmap));
|
---|
824 | end;
|
---|
825 |
|
---|
826 | constructor TBitmap.Create;
|
---|
827 | begin
|
---|
828 | NativeGraphicClass := Graphics.TBitmap;
|
---|
829 | NativeBitmap := Graphics.TBitmap.Create;
|
---|
830 | inherited;
|
---|
831 | end;
|
---|
832 |
|
---|
833 | destructor TBitmap.Destroy;
|
---|
834 | begin
|
---|
835 | FreeAndNil(FCanvas);
|
---|
836 | FreeAndNil(NativeBitmap);
|
---|
837 | inherited;
|
---|
838 | end;
|
---|
839 |
|
---|
840 | { TPen }
|
---|
841 |
|
---|
842 | function TPen.GetColor: TColor;
|
---|
843 | begin
|
---|
844 | Result := GetNativePen.Color;
|
---|
845 | end;
|
---|
846 |
|
---|
847 | function TPen.GetStyle: TPenStyle;
|
---|
848 | begin
|
---|
849 | Result := GetNativePen.Style;
|
---|
850 | end;
|
---|
851 |
|
---|
852 | function TPen.GetWidth: Integer;
|
---|
853 | begin
|
---|
854 | Result := FWidth;
|
---|
855 | end;
|
---|
856 |
|
---|
857 | procedure TPen.SetColor(AValue: TColor);
|
---|
858 | begin
|
---|
859 | GetNativePen.Color := AValue;
|
---|
860 | end;
|
---|
861 |
|
---|
862 | procedure TPen.SetNativePen(AValue: Graphics.TPen);
|
---|
863 | begin
|
---|
864 | if FNativePen = AValue then Exit;
|
---|
865 | if FNativePenFree then FreeAndNil(FNativePen);
|
---|
866 | FNativePenFree := False;
|
---|
867 | FNativePen := AValue;
|
---|
868 | SetWidth(FWidth);
|
---|
869 | end;
|
---|
870 |
|
---|
871 | procedure TPen.SetStyle(AValue: TPenStyle);
|
---|
872 | begin
|
---|
873 | GetNativePen.Style := AValue;
|
---|
874 | end;
|
---|
875 |
|
---|
876 | procedure TPen.SetWidth(AValue: Integer);
|
---|
877 | begin
|
---|
878 | GetNativePen.Width := ScaleToNative(AValue);
|
---|
879 | FWidth := AValue;
|
---|
880 | end;
|
---|
881 |
|
---|
882 | constructor TPen.Create;
|
---|
883 | begin
|
---|
884 | FNativePen := Graphics.TPen.Create;
|
---|
885 | FNativePenFree := True;
|
---|
886 | FWidth := 1;
|
---|
887 | end;
|
---|
888 |
|
---|
889 | destructor TPen.Destroy;
|
---|
890 | begin
|
---|
891 | if FNativePenFree then
|
---|
892 | FreeAndNil(FNativePen);
|
---|
893 | inherited;
|
---|
894 | end;
|
---|
895 |
|
---|
896 | function TPen.GetNativePen: Graphics.TPen;
|
---|
897 | begin
|
---|
898 | Result := FNativePen;
|
---|
899 | end;
|
---|
900 |
|
---|
901 | procedure TPen.Assign(Source: TPen);
|
---|
902 | begin
|
---|
903 | FWidth := Source.FWidth;
|
---|
904 | GetNativePen.Assign(Source.GetNativePen);
|
---|
905 | end;
|
---|
906 |
|
---|
907 | { TBrush }
|
---|
908 |
|
---|
909 | function TBrush.GetColor: TColor;
|
---|
910 | begin
|
---|
911 | Result := GetNativeBrush.Color;
|
---|
912 | end;
|
---|
913 |
|
---|
914 | function TBrush.GetStyle: TBrushStyle;
|
---|
915 | begin
|
---|
916 | Result := GetNativeBrush.Style;
|
---|
917 | end;
|
---|
918 |
|
---|
919 | procedure TBrush.SetColor(AValue: TColor);
|
---|
920 | begin
|
---|
921 | GetNativeBrush.Color := AValue;
|
---|
922 | end;
|
---|
923 |
|
---|
924 | function TBrush.GetNativeBrush: Graphics.TBrush;
|
---|
925 | begin
|
---|
926 | Result := FNativeBrush;
|
---|
927 | end;
|
---|
928 |
|
---|
929 | procedure TBrush.SetNativeBrush(AValue: Graphics.TBrush);
|
---|
930 | begin
|
---|
931 | if FNativeBrush = AValue then Exit;
|
---|
932 | if FNativeBrushFree then FreeAndNil(FNativeBrush);
|
---|
933 | FNativeBrushFree := False;
|
---|
934 | FNativeBrush := AValue;
|
---|
935 | end;
|
---|
936 |
|
---|
937 | procedure TBrush.SetStyle(AValue: TBrushStyle);
|
---|
938 | begin
|
---|
939 | GetNativeBrush.Style := AValue;
|
---|
940 | end;
|
---|
941 |
|
---|
942 | constructor TBrush.Create;
|
---|
943 | begin
|
---|
944 | FNativeBrush := Graphics.TBrush.Create;
|
---|
945 | FNativeBrushFree := True;
|
---|
946 | end;
|
---|
947 |
|
---|
948 | destructor TBrush.Destroy;
|
---|
949 | begin
|
---|
950 | if FNativeBrushFree then FreeAndNil(FNativeBrush);
|
---|
951 | inherited;
|
---|
952 | end;
|
---|
953 |
|
---|
954 | procedure TBrush.Assign(Source: TBrush);
|
---|
955 | begin
|
---|
956 | GetNativeBrush.Assign(Source.GetNativeBrush);
|
---|
957 | end;
|
---|
958 |
|
---|
959 | { TCanvas }
|
---|
960 |
|
---|
961 | function TCanvas.GetHandle: HDC;
|
---|
962 | begin
|
---|
963 | Result := GetNativeCanvas.Handle;
|
---|
964 | end;
|
---|
965 |
|
---|
966 | function TCanvas.GetHeight: Integer;
|
---|
967 | begin
|
---|
968 | Result := ScaleFromNative(GetNativeCanvas.Height);
|
---|
969 | end;
|
---|
970 |
|
---|
971 | function TCanvas.GetPixel(X, Y: Integer): TColor;
|
---|
972 | begin
|
---|
973 | Result := GetNativeCanvas.Pixels[ScaleToNative(X), ScaleToNative(Y)];
|
---|
974 | end;
|
---|
975 |
|
---|
976 | function TCanvas.GetTextStyle: TTextStyle;
|
---|
977 | begin
|
---|
978 | Result := GetNativeCanvas.TextStyle;
|
---|
979 | end;
|
---|
980 |
|
---|
981 | function TCanvas.GetWidth: Integer;
|
---|
982 | begin
|
---|
983 | Result := ScaleFromNative(GetNativeCanvas.Width);
|
---|
984 | end;
|
---|
985 |
|
---|
986 | procedure TCanvas.SetBrush(AValue: TBrush);
|
---|
987 | begin
|
---|
988 | if FBrush = AValue then Exit;
|
---|
989 | if FBrushFree then FreeAndNil(FBrush);
|
---|
990 | FBrushFree := False;
|
---|
991 | FBrush := AValue;
|
---|
992 | end;
|
---|
993 |
|
---|
994 | procedure TCanvas.SetFont(AValue: TFont);
|
---|
995 | begin
|
---|
996 | if FFont = AValue then Exit;
|
---|
997 | if FFontFree then FreeAndNil(FFont);
|
---|
998 | FFontFree := False;
|
---|
999 | FFont := AValue;
|
---|
1000 | end;
|
---|
1001 |
|
---|
1002 | procedure TCanvas.SetHandle(AValue: HDC);
|
---|
1003 | begin
|
---|
1004 | GetNativeCanvas.Handle := AValue;
|
---|
1005 | end;
|
---|
1006 |
|
---|
1007 | procedure TCanvas.SetHeight(AValue: Integer);
|
---|
1008 | begin
|
---|
1009 | GetNativeCanvas.Height;
|
---|
1010 | end;
|
---|
1011 |
|
---|
1012 | procedure TCanvas.SetWidth(AValue: Integer);
|
---|
1013 | begin
|
---|
1014 |
|
---|
1015 | end;
|
---|
1016 |
|
---|
1017 | procedure TCanvas.SetPen(AValue: TPen);
|
---|
1018 | begin
|
---|
1019 | if FPen = AValue then Exit;
|
---|
1020 | if FPenFree then FreeAndNil(FPen);
|
---|
1021 | FPenFree := False;
|
---|
1022 | FPen := AValue;
|
---|
1023 | end;
|
---|
1024 |
|
---|
1025 | procedure TCanvas.SetPixel(X, Y: Integer; AValue: TColor);
|
---|
1026 | var
|
---|
1027 | BrushStyle: TBrushStyle;
|
---|
1028 | BrushColor: TColor;
|
---|
1029 | begin
|
---|
1030 | { BrushStyle := GetNativeCanvas.Brush.Style;
|
---|
1031 | BrushColor := GetNativeCanvas.Brush.Color;
|
---|
1032 | GetNativeCanvas.Brush.Color := AValue;
|
---|
1033 | GetNativeCanvas.Brush.Style := bsClear;
|
---|
1034 | GetNativeCanvas.FillRect(ScaleToNative(X), ScaleToNative(Y), ScaleToNative(X + 1) - 1, ScaleToNative(Y + 1) - 1);
|
---|
1035 | GetNativeCanvas.Brush.Style := BrushStyle;
|
---|
1036 | GetNativeCanvas.Brush.Color := BrushColor;
|
---|
1037 | }
|
---|
1038 | GetNativeCanvas.Pixels[ScaleToNative(X), ScaleToNative(Y)] := AValue;
|
---|
1039 | end;
|
---|
1040 |
|
---|
1041 | procedure TCanvas.SetNativeCanvas(AValue: Graphics.TCanvas);
|
---|
1042 | begin
|
---|
1043 | if FNativeCanvas = AValue then Exit;
|
---|
1044 | if FNativeCanvasFree then FreeAndNil(FNativeCanvas);
|
---|
1045 | FNativeCanvasFree := False;
|
---|
1046 | FNativeCanvas := AValue;
|
---|
1047 | if Assigned(FNativeCanvas) then begin
|
---|
1048 | FFont.NativeFont := FNativeCanvas.Font;
|
---|
1049 | FBrush.NativeBrush := FNativeCanvas.Brush;
|
---|
1050 | FPen.NativePen := FNativeCanvas.Pen;
|
---|
1051 | end;
|
---|
1052 | end;
|
---|
1053 |
|
---|
1054 | procedure TCanvas.SetTextStyle(AValue: TTextStyle);
|
---|
1055 | begin
|
---|
1056 | GetNativeCanvas.TextStyle := AValue;
|
---|
1057 | end;
|
---|
1058 |
|
---|
1059 | procedure TCanvas.DoLine(X1, Y1, X2, Y2: Integer);
|
---|
1060 | begin
|
---|
1061 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1062 | end;
|
---|
1063 |
|
---|
1064 | procedure TCanvas.DoTextOut(X, Y: Integer; Text: string);
|
---|
1065 | begin
|
---|
1066 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1067 | end;
|
---|
1068 |
|
---|
1069 | procedure TCanvas.DoRectangle(const Bounds: TRect);
|
---|
1070 | begin
|
---|
1071 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1072 | end;
|
---|
1073 |
|
---|
1074 | procedure TCanvas.DoRectangleFill(const Bounds: TRect);
|
---|
1075 | begin
|
---|
1076 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1077 | end;
|
---|
1078 |
|
---|
1079 | procedure TCanvas.DoPolygon(const Points: array of TPoint);
|
---|
1080 | begin
|
---|
1081 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1082 | end;
|
---|
1083 |
|
---|
1084 | procedure TCanvas.CreateHandle;
|
---|
1085 | begin
|
---|
1086 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1087 | end;
|
---|
1088 |
|
---|
1089 | procedure TCanvas.DoEllipse(const Bounds: TRect);
|
---|
1090 | begin
|
---|
1091 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1092 | end;
|
---|
1093 |
|
---|
1094 | procedure TCanvas.DoMoveTo(X, Y: Integer);
|
---|
1095 | begin
|
---|
1096 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1097 | end;
|
---|
1098 |
|
---|
1099 | procedure TCanvas.DoLineTo(X, Y: Integer);
|
---|
1100 | begin
|
---|
1101 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1102 | end;
|
---|
1103 |
|
---|
1104 | procedure TCanvas.DoPolyline(const Points: array of TPoint);
|
---|
1105 | begin
|
---|
1106 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1107 | end;
|
---|
1108 |
|
---|
1109 | procedure TCanvas.DoPolyBezier(Points: PPoint; NumPts: Integer;
|
---|
1110 | Filled: Boolean; Continuous: Boolean);
|
---|
1111 | begin
|
---|
1112 | raise ENotImplemented.Create(SNotImplemented);
|
---|
1113 | end;
|
---|
1114 |
|
---|
1115 | function TCanvas.GetNativeCanvas: Graphics.TCanvas;
|
---|
1116 | begin
|
---|
1117 | Result := NativeCanvas;
|
---|
1118 | end;
|
---|
1119 |
|
---|
1120 | procedure TCanvas.RoundRect(const Rect: TRect; RX, RY: Integer);
|
---|
1121 | begin
|
---|
1122 | GetNativeCanvas.RoundRect(Rect, RX, RY);
|
---|
1123 | end;
|
---|
1124 |
|
---|
1125 | procedure TCanvas.RoundRect(X1, Y1, X2, Y2: Integer; RX, RY: Integer);
|
---|
1126 | begin
|
---|
1127 | GetNativeCanvas.RoundRect(X1, Y1, X2, Y2, RX, RY);
|
---|
1128 | end;
|
---|
1129 |
|
---|
1130 | procedure TCanvas.Polygon(const Points: array of TPoint; Winding: Boolean;
|
---|
1131 | StartIndex: Integer; NumPts: Integer);
|
---|
1132 | begin
|
---|
1133 | GetNativeCanvas.Polygon(Points, Winding, StartIndex, NumPts);
|
---|
1134 | end;
|
---|
1135 |
|
---|
1136 | procedure TCanvas.Polygon(Points: PPoint; NumPts: Integer; Winding: Boolean);
|
---|
1137 | begin
|
---|
1138 | GetNativeCanvas.Polygon(Points, NumPts, Winding);
|
---|
1139 | end;
|
---|
1140 |
|
---|
1141 | procedure TCanvas.Polygon(const Points: array of TPoint);
|
---|
1142 | begin
|
---|
1143 | GetNativeCanvas.Polygon(Points);
|
---|
1144 | end;
|
---|
1145 |
|
---|
1146 | procedure TCanvas.PolyBezier(const Points: array of TPoint; Filled: Boolean;
|
---|
1147 | Continuous: boolean);
|
---|
1148 | begin
|
---|
1149 | GetNativeCanvas.Polyline(Points);
|
---|
1150 | end;
|
---|
1151 |
|
---|
1152 | procedure TCanvas.PolyBezier(Points: PPoint; NumPts: Integer;
|
---|
1153 | Filled: Boolean; Continuous: Boolean);
|
---|
1154 | begin
|
---|
1155 | GetNativeCanvas.PolyBezier(Points, NumPts, Filled, Continuous);
|
---|
1156 | end;
|
---|
1157 |
|
---|
1158 | procedure TCanvas.Polyline(const Points: array of TPoint);
|
---|
1159 | begin
|
---|
1160 | GetNativeCanvas.Polyline(Points);
|
---|
1161 | end;
|
---|
1162 |
|
---|
1163 | procedure TCanvas.Polyline(Points: PPoint; NumPts: Integer);
|
---|
1164 | begin
|
---|
1165 | GetNativeCanvas.Polyline(Points, NumPts);
|
---|
1166 | end;
|
---|
1167 |
|
---|
1168 | procedure TCanvas.Ellipse(x1, y1, x2, y2: Integer);
|
---|
1169 | begin
|
---|
1170 | GetNativeCanvas.Ellipse(X1, Y1, X2, Y2);
|
---|
1171 | end;
|
---|
1172 |
|
---|
1173 | procedure TCanvas.Ellipse(const ARect: TRect);
|
---|
1174 | begin
|
---|
1175 | Ellipse(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
|
---|
1176 | end;
|
---|
1177 |
|
---|
1178 | {procedure TCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: Graphics.TGraphic);
|
---|
1179 | begin
|
---|
1180 | GetNativeCanvas.StretchDraw(DestRect, SrcGraphic);
|
---|
1181 | end;
|
---|
1182 | }
|
---|
1183 | procedure TCanvas.Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2, StartX,
|
---|
1184 | StartY, EndX, EndY: Integer);
|
---|
1185 | begin
|
---|
1186 | GetNativeCanvas.Pie(EllipseX1, EllipseY1, EllipseX2, EllipseY2, StartX, StartY,
|
---|
1187 | EndX, EndY);
|
---|
1188 | end;
|
---|
1189 |
|
---|
1190 | procedure TCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic
|
---|
1191 | );
|
---|
1192 | begin
|
---|
1193 | GetNativeCanvas.StretchDraw(ScaleRectToNative(DestRect), SrcGraphic.GetNativeGraphic);
|
---|
1194 | end;
|
---|
1195 |
|
---|
1196 | procedure TCanvas.FrameRect(Rect: TRect);
|
---|
1197 | begin
|
---|
1198 | GetNativeCanvas.FrameRect(ScaleRectToNative(Rect));
|
---|
1199 | end;
|
---|
1200 |
|
---|
1201 | procedure TCanvas.Rectangle(X1, Y1, X2, Y2: Integer);
|
---|
1202 | begin
|
---|
1203 | GetNativeCanvas.Rectangle(ScaleToNative(X1), ScaleToNative(Y1), ScaleToNative(X2), ScaleToNative(Y2));
|
---|
1204 | end;
|
---|
1205 |
|
---|
1206 | procedure TCanvas.Rectangle(const ARect: TRect);
|
---|
1207 | begin
|
---|
1208 | Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
|
---|
1209 | end;
|
---|
1210 |
|
---|
1211 | function TCanvas.TextWidth(const Text: string): Integer;
|
---|
1212 | begin
|
---|
1213 | Result := ScaleFromNative(GetNativeCanvas.TextWidth(Text));
|
---|
1214 | end;
|
---|
1215 |
|
---|
1216 | function TCanvas.TextHeight(const Text: string): Integer;
|
---|
1217 | begin
|
---|
1218 | Result := ScaleFromNative(GetNativeCanvas.TextHeight(Text));
|
---|
1219 | end;
|
---|
1220 |
|
---|
1221 | function TCanvas.TextExtent(const Text: string): TSize;
|
---|
1222 | begin
|
---|
1223 | Result := ScaleSizeFromNative(GetNativeCanvas.TextExtent(Text));
|
---|
1224 | end;
|
---|
1225 |
|
---|
1226 | procedure TCanvas.TextOut(X, Y: Integer; const Text: string);
|
---|
1227 | begin
|
---|
1228 | GetNativeCanvas.TextOut(ScaleToNative(X), ScaleToNative(Y), Text);
|
---|
1229 | end;
|
---|
1230 |
|
---|
1231 | procedure TCanvas.TextRect(ARect: TRect; X, Y: Integer; Text: string);
|
---|
1232 | begin
|
---|
1233 | GetNativeCanvas.TextRect(ScaleRectToNative(ARect), ScaleToNative(X),
|
---|
1234 | ScaleToNative(Y), Text);
|
---|
1235 | end;
|
---|
1236 |
|
---|
1237 | procedure TCanvas.TextRect(ARect: TRect; X, Y: integer; const Text: string;
|
---|
1238 | const Style: TTextStyle);
|
---|
1239 | begin
|
---|
1240 | GetNativeCanvas.TextRect(ScaleRectToNative(ARect), ScaleToNative(X),
|
---|
1241 | ScaleToNative(Y), Text, TextStyle);
|
---|
1242 | end;
|
---|
1243 |
|
---|
1244 | procedure TCanvas.MoveTo(X, Y: Integer);
|
---|
1245 | begin
|
---|
1246 | GetNativeCanvas.MoveTo(ScaleToNative(X), ScaleToNative(Y));
|
---|
1247 | end;
|
---|
1248 |
|
---|
1249 | procedure TCanvas.LineTo(X, Y: Integer);
|
---|
1250 | begin
|
---|
1251 | GetNativeCanvas.LineTo(ScaleToNative(X), ScaleToNative(Y));
|
---|
1252 | end;
|
---|
1253 |
|
---|
1254 | procedure TCanvas.Line(const p1, p2: TPoint);
|
---|
1255 | begin
|
---|
1256 | GetNativeCanvas.Line(P1, P2);
|
---|
1257 | end;
|
---|
1258 |
|
---|
1259 | procedure TCanvas.FillRect(const ARect: TRect);
|
---|
1260 | begin
|
---|
1261 | GetNativeCanvas.FillRect(ScaleRectToNative(ARect));
|
---|
1262 | end;
|
---|
1263 |
|
---|
1264 | procedure TCanvas.FillRect(X1, Y1, X2, Y2: Integer);
|
---|
1265 | begin
|
---|
1266 | GetNativeCanvas.FillRect(ScaleToNative(X1), ScaleToNative(Y1), ScaleToNative(X2), ScaleToNative(Y2));
|
---|
1267 | end;
|
---|
1268 |
|
---|
1269 | procedure TCanvas.Draw(X, Y: Integer; Source: TGraphic);
|
---|
1270 | begin
|
---|
1271 | GetNativeCanvas.Draw(ScaleToNative(X), ScaleToNative(Y), Source.GetNativeGraphic);
|
---|
1272 | end;
|
---|
1273 |
|
---|
1274 | procedure TCanvas.CopyRect(Dest: TRect; SrcCanvas: TCanvas;
|
---|
1275 | Source: TRect);
|
---|
1276 | begin
|
---|
1277 | GetNativeCanvas.CopyRect(Dest, SrcCanvas.NativeCanvas, ScaleRectToNative(Source));
|
---|
1278 | end;
|
---|
1279 |
|
---|
1280 | constructor TCanvas.Create;
|
---|
1281 | begin
|
---|
1282 | FNativeCanvas := nil;
|
---|
1283 | FFont := TFont.Create;
|
---|
1284 | FFontFree := True;
|
---|
1285 | FPen := TPen.Create;
|
---|
1286 | FPenFree := True;
|
---|
1287 | FBrush := TBrush.Create;
|
---|
1288 | FBrushFree := True;
|
---|
1289 | end;
|
---|
1290 |
|
---|
1291 | destructor TCanvas.Destroy;
|
---|
1292 | begin
|
---|
1293 | if FFontFree then FreeAndNil(FFont);
|
---|
1294 | if FBrushFree then FreeAndNil(FBrush);
|
---|
1295 | if FPenFree then FreeAndNil(FPen);
|
---|
1296 | if FNativeCanvasFree then FreeAndNil(FNativeCanvasFree);
|
---|
1297 | inherited;
|
---|
1298 | end;
|
---|
1299 |
|
---|
1300 | { TJpegImage }
|
---|
1301 |
|
---|
1302 | function TJpegImage.GetNativeCustomBitmap: Graphics.TCustomBitmap;
|
---|
1303 | begin
|
---|
1304 | Result := GetNativeJpeg;
|
---|
1305 | end;
|
---|
1306 |
|
---|
1307 | function TJpegImage.GetNativeJpeg: Graphics.TJPEGImage;
|
---|
1308 | begin
|
---|
1309 | Result := NativeJpeg;
|
---|
1310 | end;
|
---|
1311 |
|
---|
1312 | procedure TJpegImage.SetNativeCustomBitmap(CustomBitmap: Graphics.TCustomBitmap
|
---|
1313 | );
|
---|
1314 | begin
|
---|
1315 | SetNativeJpeg(Graphics.TJpegImage(CustomBitmap));
|
---|
1316 | end;
|
---|
1317 |
|
---|
1318 | procedure TJpegImage.SetNativeJpeg(Jpeg: Graphics.TJPEGImage);
|
---|
1319 | begin
|
---|
1320 | NativeJpeg := Jpeg;
|
---|
1321 | end;
|
---|
1322 |
|
---|
1323 | constructor TJpegImage.Create;
|
---|
1324 | begin
|
---|
1325 | NativeJpeg := Graphics.TJPEGImage.Create;
|
---|
1326 | NativeGraphicClass := Graphics.TJPEGImage;
|
---|
1327 | inherited;
|
---|
1328 | end;
|
---|
1329 |
|
---|
1330 | destructor TJpegImage.Destroy;
|
---|
1331 | begin
|
---|
1332 | FreeAndNil(NativeJpeg);
|
---|
1333 | inherited;
|
---|
1334 | end;
|
---|
1335 |
|
---|
1336 | { TPicture }
|
---|
1337 |
|
---|
1338 | procedure TPicture.SetBitmap(AValue: TBitmap);
|
---|
1339 | begin
|
---|
1340 | if FBitmap = AValue then Exit;
|
---|
1341 | FBitmap := AValue;
|
---|
1342 | end;
|
---|
1343 |
|
---|
1344 | procedure TPicture.LoadFromFile(FileName: string);
|
---|
1345 | begin
|
---|
1346 | end;
|
---|
1347 |
|
---|
1348 | { TScreenInfo }
|
---|
1349 |
|
---|
1350 | procedure TScreenInfo.SetDpi(AValue: Integer);
|
---|
1351 | var
|
---|
1352 | I: Integer;
|
---|
1353 | begin
|
---|
1354 | if FDpi = AValue then Exit;
|
---|
1355 | FDpi := AValue;
|
---|
1356 |
|
---|
1357 | // Precalculate scaling coefficients
|
---|
1358 | ToNative := ScreenInfo.Dpi / 96;
|
---|
1359 | for I := Low(LookupToNative) to High(LookupToNative) do
|
---|
1360 | LookupToNative[I] := Ceil(I * ToNative);
|
---|
1361 | FromNative := 96 / ScreenInfo.Dpi;
|
---|
1362 | for I := Low(LookupFromNative) to High(LookupFromNative) do
|
---|
1363 | LookupFromNative[I] := Floor(I * FromNative);
|
---|
1364 | end;
|
---|
1365 |
|
---|
1366 | { TPortableNetworkGraphic }
|
---|
1367 |
|
---|
1368 | function TPortableNetworkGraphic.GetNativeCustomBitmap: Graphics.TCustomBitmap;
|
---|
1369 | begin
|
---|
1370 | Result := GetNativePng;
|
---|
1371 | end;
|
---|
1372 |
|
---|
1373 | function TPortableNetworkGraphic.GetNativePng: Graphics.TPortableNetworkGraphic;
|
---|
1374 | begin
|
---|
1375 | Result := NativePng;
|
---|
1376 | end;
|
---|
1377 |
|
---|
1378 | procedure TPortableNetworkGraphic.SetNativeCustomBitmap(
|
---|
1379 | CustomBitmap: Graphics.TCustomBitmap);
|
---|
1380 | begin
|
---|
1381 | SetNativePng(Graphics.TPortableNetworkGraphic(CustomBitmap));
|
---|
1382 | end;
|
---|
1383 |
|
---|
1384 | procedure TPortableNetworkGraphic.SetNativePng(
|
---|
1385 | Png: Graphics.TPortableNetworkGraphic);
|
---|
1386 | begin
|
---|
1387 | NativePng := Png;
|
---|
1388 | end;
|
---|
1389 |
|
---|
1390 | constructor TPortableNetworkGraphic.Create;
|
---|
1391 | begin
|
---|
1392 | NativePng := Graphics.TPortableNetworkGraphic.Create;
|
---|
1393 | NativeGraphicClass := Graphics.TPortableNetworkGraphic;
|
---|
1394 | inherited;
|
---|
1395 | end;
|
---|
1396 |
|
---|
1397 | destructor TPortableNetworkGraphic.Destroy;
|
---|
1398 | begin
|
---|
1399 | Canvas.NativeCanvas := nil;
|
---|
1400 | FreeAndNil(NativePng);
|
---|
1401 | inherited;
|
---|
1402 | end;
|
---|
1403 |
|
---|
1404 | end.
|
---|
1405 |
|
---|