1 | unit Dpi.ExtCtrls;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Controls, ExtCtrls, Dpi.Controls, Dpi.Graphics;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
55 | procedure Register;
|
---|
56 |
|
---|
57 |
|
---|
58 | implementation
|
---|
59 |
|
---|
60 | uses
|
---|
61 | Dpi.Common;
|
---|
62 |
|
---|
63 | procedure Register;
|
---|
64 | begin
|
---|
65 | RegisterComponents(DpiControlsComponentPaletteName, [TDpiPaintBox, TDpiImage]);
|
---|
66 | end;
|
---|
67 |
|
---|
68 | { TDpiPanel }
|
---|
69 |
|
---|
70 | function TDpiPanel.GetNativePanel: TPanel;
|
---|
71 | begin
|
---|
72 | if not Assigned(NativePanel) then NativePanel := TPanel.Create(nil);
|
---|
73 | Result := NativePanel;
|
---|
74 | end;
|
---|
75 |
|
---|
76 | constructor TDpiPanel.Create(TheOwner: TComponent);
|
---|
77 | begin
|
---|
78 | inherited Create(TheOwner);
|
---|
79 | end;
|
---|
80 |
|
---|
81 | destructor TDpiPanel.Destroy;
|
---|
82 | begin
|
---|
83 | FreeAndNil(NativePanel);
|
---|
84 | inherited;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | { TDpiPaintBox }
|
---|
88 |
|
---|
89 | function TDpiPaintBox.GetNativeGraphicControl: Controls.TGraphicControl;
|
---|
90 | begin
|
---|
91 | if not Assigned(NativePaintBox) then NativePaintBox := TPaintBox.Create(nil);
|
---|
92 | Result := NativePaintBox;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | constructor TDpiPaintBox.Create(TheOwner: TComponent);
|
---|
96 | begin
|
---|
97 | inherited;
|
---|
98 | Canvas := TCanvas.Create;
|
---|
99 | Canvas.NativeCanvas := NativePaintBox.Canvas;
|
---|
100 | UpdateNativeControl;
|
---|
101 | ScreenChanged;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | destructor TDpiPaintBox.Destroy;
|
---|
105 | begin
|
---|
106 | FreeAndNil(NativePaintBox);
|
---|
107 | inherited;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | { TDpiImage }
|
---|
111 |
|
---|
112 | procedure TDpiImage.SetStretch(AValue: Boolean);
|
---|
113 | begin
|
---|
114 | if FStretch = AValue then Exit;
|
---|
115 | FStretch := AValue;
|
---|
116 | NativeImage.Stretch := AValue;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TDpiImage.SetPicture(AValue: TPicture);
|
---|
120 | begin
|
---|
121 | if FDpiPicture = AValue then Exit;
|
---|
122 | FDpiPicture := AValue;
|
---|
123 | end;
|
---|
124 |
|
---|
125 | function TDpiImage.GetNativeControl: Controls.TControl;
|
---|
126 | begin
|
---|
127 | if not Assigned(NativeImage) then NativeImage := TImage.Create(nil);
|
---|
128 | Result := NativeImage;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | destructor TDpiImage.Destroy;
|
---|
132 | begin
|
---|
133 | FreeAndNil(NativeImage);
|
---|
134 | inherited Destroy;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | initialization
|
---|
138 |
|
---|
139 | RegisterClasses([TDpiImage]);
|
---|
140 |
|
---|
141 | end.
|
---|
142 |
|
---|