source: trunk/Packages/DpiControls/Dpi.ExtCtrls.pas

Last change on this file was 468, checked in by chronos, 8 months ago
  • Added: High DPI support integrated into trunk branch. It can be enabled by adding DPI define to compiler parameters for main project and packages.
File size: 2.7 KB
Line 
1unit Dpi.ExtCtrls;
2
3interface
4
5uses
6 Classes, SysUtils, Controls, ExtCtrls, Dpi.Controls, Dpi.Graphics;
7
8type
9 TTimer = ExtCtrls.TTimer;
10
11 { TDpiPanel }
12
13 TDpiPanel = class(TWinControl)
14 private
15 NativePanel: TPanel;
16 public
17 function GetNativePanel: TPanel;
18 constructor Create(TheOwner: TComponent); override;
19 destructor Destroy; override;
20 end;
21
22 { TDpiPaintBox }
23
24 TDpiPaintBox = class(TGraphicControl)
25 public
26 NativePaintBox: TPaintBox;
27 function GetNativeGraphicControl: Controls.TGraphicControl; override;
28 constructor Create(TheOwner: TComponent); override;
29 destructor Destroy; override;
30 published
31 property OnPaint;
32 property Visible;
33 end;
34
35 { TDpiImage }
36
37 TDpiImage = class(TControl)
38 private
39 FDpiPicture: TPicture;
40 FStretch: Boolean;
41 procedure SetPicture(AValue: TPicture);
42 procedure SetStretch(AValue: Boolean);
43 protected
44 public
45 NativeImage: TImage;
46 function GetNativeControl: Controls.TControl; override;
47 destructor Destroy; override;
48 published
49 property Stretch: Boolean read FStretch write SetStretch;
50 property Picture: TPicture read FDpiPicture write SetPicture;
51 property Visible;
52 end;
53
54
55procedure Register;
56
57
58implementation
59
60uses
61 Dpi.Common;
62
63procedure Register;
64begin
65 RegisterComponents(DpiControlsComponentPaletteName, [TDpiPaintBox, TDpiImage]);
66end;
67
68{ TDpiPanel }
69
70function TDpiPanel.GetNativePanel: TPanel;
71begin
72 if not Assigned(NativePanel) then NativePanel := TPanel.Create(nil);
73 Result := NativePanel;
74end;
75
76constructor TDpiPanel.Create(TheOwner: TComponent);
77begin
78 inherited Create(TheOwner);
79end;
80
81destructor TDpiPanel.Destroy;
82begin
83 FreeAndNil(NativePanel);
84 inherited;
85end;
86
87{ TDpiPaintBox }
88
89function TDpiPaintBox.GetNativeGraphicControl: Controls.TGraphicControl;
90begin
91 if not Assigned(NativePaintBox) then NativePaintBox := TPaintBox.Create(nil);
92 Result := NativePaintBox;
93end;
94
95constructor TDpiPaintBox.Create(TheOwner: TComponent);
96begin
97 inherited;
98 Canvas := TCanvas.Create;
99 Canvas.NativeCanvas := NativePaintBox.Canvas;
100 UpdateNativeControl;
101 ScreenChanged;
102end;
103
104destructor TDpiPaintBox.Destroy;
105begin
106 FreeAndNil(NativePaintBox);
107 inherited;
108end;
109
110{ TDpiImage }
111
112procedure TDpiImage.SetStretch(AValue: Boolean);
113begin
114 if FStretch = AValue then Exit;
115 FStretch := AValue;
116 NativeImage.Stretch := AValue;
117end;
118
119procedure TDpiImage.SetPicture(AValue: TPicture);
120begin
121 if FDpiPicture = AValue then Exit;
122 FDpiPicture := AValue;
123end;
124
125function TDpiImage.GetNativeControl: Controls.TControl;
126begin
127 if not Assigned(NativeImage) then NativeImage := TImage.Create(nil);
128 Result := NativeImage;
129end;
130
131destructor TDpiImage.Destroy;
132begin
133 FreeAndNil(NativeImage);
134 inherited Destroy;
135end;
136
137initialization
138
139RegisterClasses([TDpiImage]);
140
141end.
142
Note: See TracBrowser for help on using the repository browser.