Changeset 535 for DpiControls
- Timestamp:
- May 27, 2019, 12:06:17 AM (6 years ago)
- Location:
- DpiControls
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
DpiControls/Demo/DpiComponentsDemo.lpi
r534 r535 15 15 <Icon Value="0"/> 16 16 </General> 17 <BuildModes Count="1"> 18 <Item1 Name="Default" Default="True"/> 17 <BuildModes Count="2"> 18 <Item1 Name="Debug" Default="True"/> 19 <Item2 Name="Release"> 20 <CompilerOptions> 21 <Version Value="11"/> 22 <Target> 23 <Filename Value="DpiComponentsDemo"/> 24 </Target> 25 <SearchPaths> 26 <IncludeFiles Value="$(ProjOutDir)"/> 27 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-${BuildMode}"/> 28 </SearchPaths> 29 <Parsing> 30 <SyntaxOptions> 31 <CStyleOperator Value="False"/> 32 <AllowLabel Value="False"/> 33 <CPPInline Value="False"/> 34 </SyntaxOptions> 35 </Parsing> 36 <CodeGeneration> 37 <Optimizations> 38 <OptimizationLevel Value="3"/> 39 </Optimizations> 40 </CodeGeneration> 41 <Linking> 42 <Debugging> 43 <GenerateDebugInfo Value="False"/> 44 </Debugging> 45 <Options> 46 <Win32> 47 <GraphicApplication Value="True"/> 48 </Win32> 49 </Options> 50 </Linking> 51 <Other> 52 <CompilerMessages> 53 <IgnoredMessages idx5024="True"/> 54 </CompilerMessages> 55 </Other> 56 </CompilerOptions> 57 </Item2> 19 58 </BuildModes> 20 59 <PublishOptions> … … 64 103 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)-${BuildMode}"/> 65 104 </SearchPaths> 105 <Parsing> 106 <SyntaxOptions> 107 <CStyleOperator Value="False"/> 108 <IncludeAssertionCode Value="True"/> 109 <AllowLabel Value="False"/> 110 <CPPInline Value="False"/> 111 </SyntaxOptions> 112 </Parsing> 113 <CodeGeneration> 114 <Checks> 115 <IOChecks Value="True"/> 116 <RangeChecks Value="True"/> 117 <OverflowChecks Value="True"/> 118 <StackChecks Value="True"/> 119 </Checks> 120 <VerifyObjMethodCallValidity Value="True"/> 121 </CodeGeneration> 66 122 <Linking> 123 <Debugging> 124 <UseHeaptrc Value="True"/> 125 </Debugging> 67 126 <Options> 68 127 <Win32> … … 71 130 </Options> 72 131 </Linking> 132 <Other> 133 <CompilerMessages> 134 <IgnoredMessages idx5024="True"/> 135 </CompilerMessages> 136 </Other> 73 137 </CompilerOptions> 74 138 <Debugging> -
DpiControls/Demo/UDpiFormMain.lfm
r534 r535 5 5 Height = 0 6 6 Visible = True 7 Enabled = True 8 ShowHint = False 9 BorderStyle = Controls 7 10 OnCreate = DpiFormMainCreate 8 object Dpi Button1: TDpiButton9 Top = 1 2810 Left = 811 Width = 1 5012 Height = 4011 object DpiPaintBox1: TDpiPaintBox 12 Top = 161 13 Left = 124 14 Width = 100 15 Height = 100 13 16 Visible = True 14 Caption = 'Test' 15 OnClick = DpiButton1Click 17 Enabled = True 18 ShowHint = False 19 OnPaint = DpiPaintBox1Paint 20 left = 88 21 top = 248 16 22 end 17 23 end -
DpiControls/Demo/UDpiFormMain.pas
r534 r535 6 6 7 7 uses 8 Classes, SysUtils, UDpiControls, Dialogs ;8 Classes, SysUtils, UDpiControls, Dialogs, Graphics; 9 9 10 10 type … … 13 13 14 14 TDpiFormMain = class(TDpiForm) 15 Dpi Button1: TDpiButton;15 DpiPaintBox1: TDpiPaintBox; 16 16 procedure DpiButton1Click(Sender: TObject); 17 17 procedure DpiFormMainCreate(Sender: TObject); 18 procedure DpiPaintBox1Paint(Sender: TObject); 18 19 private 19 20 20 public 21 21 … … 33 33 procedure TDpiFormMain.DpiFormMainCreate(Sender: TObject); 34 34 var 35 DpiButton: TDpiButton; 36 DpiImage: TDpiImage; 35 Button: TDpiButton; 36 Image: TDpiImage; 37 ListBox: TDpiListBox; 38 I: Integer; 39 PaintBox: TDpiPaintBox; 37 40 begin 38 DpiButton := TDpiButton.Create(DpiFormMain); 39 DpiButton.Parent := Self; 40 DpiButton.SetBounds(10, 10, 100, 30); 41 DpiButton.Caption := 'Click me'; 42 DpiButton.Visible := True; 43 DpiButton1.Parent := Self; 41 Button := TDpiButton.Create(DpiFormMain); 42 Button.Parent := Self; 43 Button.SetBounds(10, 10, 100, 30); 44 Button.Caption := 'Click me'; 45 Button.Visible := True; 44 46 45 DpiImage := TDpiImage.Create(DpiFormMain); 46 DpiImage.Parent := Self; 47 DpiImage.SetBounds(150, 10, 100, 100); 48 DpiImage.Visible := True; 49 DpiImage.Stretch := True; 50 DpiImage.VclImage.Picture.LoadFromFile('dance.jpg'); 47 Image := TDpiImage.Create(DpiFormMain); 48 Image.Parent := Self; 49 Image.SetBounds(150, 10, 100, 100); 50 Image.Visible := True; 51 Image.Stretch := True; 52 Image.VclImage.Picture.LoadFromFile('dance.jpg'); 53 //Image.Picture.LoadFromFile('dance.jpg'); 54 55 ListBox := TDpiListBox.Create(DpiFormMain); 56 for I := 0 to 10 do 57 ListBox.VclListBox.Items.Add('Item ' + IntToStr(I)); 58 ListBox.Parent := Self; 59 ListBox.SetBounds(250, 10, 100, 100); 60 ListBox.Visible := True; 61 62 DpiPaintBox1.BoundsRect := Rect(0, 0, 100, 100); 63 DpiPaintBox1.VclPaintBox.Parent := VclForm; 64 DpiPaintBox1.Repaint; 65 end; 66 67 procedure TDpiFormMain.DpiPaintBox1Paint(Sender: TObject); 68 begin 69 with DpiPaintBox1.Canvas do begin 70 Brush.Color := clWhite; 71 Brush.Style := bsSolid; 72 FillRect(Rect(0, 0, 100, 100)); 73 Caption := IntToStr(Width); 74 Pen.Color := clGreen; 75 Pen.Style := psSolid; 76 MoveTo(0, 0); 77 LineTo(100, 100); 78 Font.Color := clRed; 79 TextOut(40, 10, 'Scaled text'); 80 end; 51 81 end; 52 82 -
DpiControls/Demo/UFormMain.lfm
r534 r535 38 38 TabOrder = 1 39 39 end 40 object Timer1: TTimer 41 Interval = 100 42 OnTimer = Timer1Timer 43 left = 256 44 top = 40 45 end 40 46 end -
DpiControls/Demo/UFormMain.pas
r534 r535 16 16 ButtonNewDpiForm: TButton; 17 17 Label1: TLabel; 18 Timer1: TTimer; 18 19 TrackBar1: TTrackBar; 19 20 procedure ButtonNewDpiFormClick(Sender: TObject); 20 21 procedure FormShow(Sender: TObject); 22 procedure Timer1Timer(Sender: TObject); 21 23 procedure TrackBar1Change(Sender: TObject); 22 24 private 23 25 24 26 public 25 27 Redraw: Boolean; 26 28 end; 27 29 … … 42 44 end; 43 45 46 procedure TFormMain.Timer1Timer(Sender: TObject); 47 begin 48 Redraw := False; 49 DpiScreen.Dpi := TrackBar1.Position; 50 end; 51 44 52 procedure TFormMain.ButtonNewDpiFormClick(Sender: TObject); 45 53 var … … 55 63 procedure TFormMain.TrackBar1Change(Sender: TObject); 56 64 begin 57 DpiScreen.Dpi := TrackBar1.Position;65 Redraw := True; 58 66 end; 59 67 -
DpiControls/UDpiControls.pas
r534 r535 7 7 uses 8 8 Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf, ProjectIntf, 9 Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls ;9 Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls, LCLType; 10 10 11 11 type … … 26 26 FOnChange: TNotifyEvent; 27 27 FSize: Integer; 28 function GetColor: TColor; 29 function GetName: string; 30 function GetPixelsPerInch: Integer; 31 function GetStyle: TFontStyles; 32 procedure SetColor(AValue: TColor); 33 procedure SetName(AValue: string); 28 34 procedure SetOnChange(AValue: TNotifyEvent); 35 procedure SetPixelsPerInch(AValue: Integer); 29 36 procedure SetSize(AValue: Integer); 30 37 procedure DoChange; 38 procedure SetStyle(AValue: TFontStyles); 31 39 protected 32 40 procedure ScreenChanged; … … 35 43 constructor Create; 36 44 destructor Destroy; override; 45 procedure Assign(Source: TDpiFont); 37 46 published 47 property Color: TColor read GetColor write SetColor; 48 property Name: string read GetName write SetName; 49 property Style: TFontStyles read GetStyle write SetStyle; 38 50 property Size: Integer read FSize write SetSize; 51 property PixelsPerInch: Integer read GetPixelsPerInch write SetPixelsPerInch; 39 52 property OnChange: TNotifyEvent read FOnChange write SetOnChange; 40 53 end; … … 52 65 FOnResize: TNotifyEvent; 53 66 FTop: Integer; 54 FVisible: Boolean;55 67 FWidth: Integer; 56 68 FParent: TDpiWinControl; 69 function GetBoundsRect: TRect; 70 function GetClientHeight: Integer; 71 function GetClientWidth: Integer; 72 function GetEnabled: Boolean; 73 function GetOnClick: TNotifyEvent; 74 function GetShowHint: Boolean; 75 function GetVisible: Boolean; 76 procedure SetBoundsRect(AValue: TRect); 77 procedure SetEnabled(AValue: Boolean); 57 78 procedure SetFont(AValue: TDpiFont); 58 79 procedure SetOnChangeBounds(AValue: TNotifyEvent); 80 procedure SetOnClick(AValue: TNotifyEvent); 59 81 procedure SetOnResize(AValue: TNotifyEvent); 82 procedure SetShowHint(AValue: Boolean); 60 83 procedure VclFormResize(Sender: TObject); 61 84 procedure VclChangeBounds(Sender: TObject); … … 75 98 function GetVclControl: TControl; virtual; 76 99 procedure UpdateVclControl; virtual; 100 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; 101 X, Y: Integer); virtual; 102 procedure MouseUp(Button: TMouseButton; Shift: TShiftState; 103 X, Y: Integer); virtual; 104 procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual; 77 105 public 78 106 procedure ScreenChanged; virtual; … … 80 108 procedure Show; 81 109 procedure Hide; 110 procedure Invalidate; 111 procedure Repaint; 82 112 constructor Create(TheOwner: TComponent); override; 83 113 destructor Destroy; override; 84 114 property Parent: TDpiWinControl read FParent write SetParent; 115 property BoundsRect: TRect read GetBoundsRect write SetBoundsRect; 116 property ClientWidth: Integer read GetClientWidth; 117 property ClientHeight: Integer read GetClientHeight; 85 118 published 86 119 property Top: Integer read FTop write SetTop; … … 88 121 property Width: Integer read FWidth write SetWidth; 89 122 property Height: Integer read FHeight write SetHeight; 90 property Visible: Boolean read FVisible write SetVisible;123 property Visible: Boolean read GetVisible write SetVisible; 91 124 property Caption: string read GetCaption write SetCaption; 125 property Enabled: Boolean read GetEnabled write SetEnabled; 126 property ShowHint: Boolean read GetShowHint write SetShowHint; 92 127 property Font: TDpiFont read FFont write SetFont; 93 128 property OnResize: TNotifyEvent read FOnResize write SetOnResize; 94 129 property OnChangeBounds: TNotifyEvent read FOnChangeBounds write SetOnChangeBounds; 130 property OnClick: TNotifyEvent read GetOnClick write SetOnClick; 95 131 end; 96 132 97 133 TDpiControls = specialize TFPGObjectList<TDpiControl>; 98 134 135 { TDpiCanvas } 136 137 TDpiCanvas = class 138 private 139 FFont: TDpiFont; 140 function GetBrush: TBrush; 141 function GetHandle: HDC; 142 function GetHeight: Integer; 143 function GetPen: TPen; 144 function GetPixel(X, Y: Integer): TColor; 145 function GetWidth: Integer; 146 procedure SetBrush(AValue: TBrush); 147 procedure SetFont(AValue: TDpiFont); 148 procedure SetHandle(AValue: HDC); 149 procedure SetPen(AValue: TPen); 150 procedure SetPixel(X, Y: Integer; AValue: TColor); 151 public 152 VclCanvas: TCanvas; 153 procedure FrameRect(Rect: TRect); 154 function TextWidth(Text: string): Integer; 155 function TextHeight(Text: string): Integer; 156 procedure TextOut(X, Y: Integer; Text: string); 157 procedure MoveTo(X, Y: Integer); 158 procedure LineTo(X, Y: Integer); 159 procedure FillRect(ARect: TRect); 160 procedure FillRect(X1, Y1, X2, Y2: Integer); 161 constructor Create; 162 destructor Destroy; override; 163 property Handle: HDC read GetHandle write SetHandle; 164 property Pixels[X, Y: Integer]: TColor read GetPixel write SetPixel; 165 property Width: Integer read GetWidth; 166 property Height: Integer read GetHeight; 167 published 168 property Brush: TBrush read GetBrush write SetBrush; 169 property Pen: TPen read GetPen write SetPen; 170 property Font: TDpiFont read FFont write SetFont; 171 end; 172 173 { TDpiGraphicControl } 174 175 TDpiGraphicControl = class(TDpiControl) 176 private 177 FCanvas: TDpiCanvas; 178 procedure SetCanvas(AValue: TDpiCanvas); 179 protected 180 procedure Paint; virtual; 181 public 182 constructor Create(TheOwner: TComponent); override; 183 destructor Destroy; override; 184 published 185 property Canvas: TDpiCanvas read FCanvas write SetCanvas; 186 end; 187 99 188 { TDpiWinControl } 100 189 101 190 TDpiWinControl = class(TDpiControl) 102 191 private 192 function GetHandle: HWND; 193 procedure SetHandle(AValue: HWND); 103 194 protected 104 195 function GetVclWinControl: TWinControl; virtual; … … 106 197 Controls: TDpiControls; 107 198 procedure ScreenChanged; override; 199 function ControlCount: Integer; 108 200 constructor Create(TheOwner: TComponent); override; 109 201 destructor Destroy; override; 202 property Handle: HWND read GetHandle write SetHandle; 110 203 published 111 204 end; … … 115 208 TDpiForm = class(TDpiWinControl) 116 209 private 210 function GetBorderStyle: TBorderStyle; 211 function GetCanvas: TDpiCanvas; 117 212 function GetOnCreate: TNotifyEvent; 118 213 function GetOnDestroy: TNotifyEvent; 119 214 function GetOnHide: TNotifyEvent; 120 215 function GetOnShow: TNotifyEvent; 216 procedure SetBorderStyle(AValue: TBorderStyle); 121 217 procedure SetOnCreate(AValue: TNotifyEvent); 122 218 procedure SetOnDestroy(AValue: TNotifyEvent); … … 130 226 public 131 227 VclForm: TForm; 228 property Canvas: TDpiCanvas read GetCanvas; 132 229 constructor Create(TheOwner: TComponent); override; 133 230 destructor Destroy; override; 134 231 published 232 property BorderStyle: TBorderStyle read GetBorderStyle write SetBorderStyle; 135 233 property OnShow: TNotifyEvent read GetOnShow write SetOnShow; 136 234 property OnHide: TNotifyEvent read GetOnHide write SetOnHide; … … 145 243 TDpiButton = class(TDpiControl) 146 244 private 147 FOnClick: TNotifyEvent;148 procedure SetOnClick(AValue: TNotifyEvent);149 245 protected 150 246 function GetVclControl: TControl; override; 151 247 public 152 248 VclButton: TButton; 153 constructor Create(TheOwner: TComponent); override;154 249 destructor Destroy; override; 155 250 published 156 property OnClick: TNotifyEvent read FOnClick write SetOnClick; 251 end; 252 253 { TDpiListBox } 254 255 TDpiListBox = class(TDpiControl) 256 private 257 protected 258 function GetVclControl: TControl; override; 259 public 260 VclListBox: TListBox; 261 destructor Destroy; override; 262 end; 263 264 { TDpiBitmap } 265 266 TDpiBitmap = class 267 private 268 FCanvas: TDpiCanvas; 269 published 270 property Canvas: TDpiCanvas read FCanvas; 271 end; 272 273 { TDpiPicture } 274 275 TDpiPicture = class(TPersistent) 276 private 277 FBitmap: TDpiBitmap; 278 procedure SetBitmap(AValue: TDpiBitmap); 279 published 280 procedure LoadFromFile(FileName: string); 281 property Bitmpa: TDpiBitmap read FBitmap write SetBitmap; 157 282 end; 158 283 … … 161 286 TDpiImage = class(TDpiControl) 162 287 private 288 FDpiPicture: TDpiPicture; 163 289 FStretch: Boolean; 290 procedure SetPicture(AValue: TDpiPicture); 164 291 procedure SetStretch(AValue: Boolean); 165 292 protected … … 167 294 VclImage: TImage; 168 295 function GetVclControl: TControl; override; 296 destructor Destroy; override; 297 published 298 property Stretch: Boolean read FStretch write SetStretch; 299 property Picture: TDpiPicture read FDpiPicture write SetPicture; 300 end; 301 302 { TDpiPaintBox } 303 304 TDpiPaintBox = class(TDpiGraphicControl) 305 private 306 function GetOnPaint: TNotifyEvent; 307 procedure SetOnPaint(AValue: TNotifyEvent); 308 public 309 VclPaintBox: TPaintBox; 310 function GetVclControl: TControl; override; 169 311 constructor Create(TheOwner: TComponent); override; 170 312 destructor Destroy; override; 171 313 published 172 property Stretch: Boolean read FStretch write SetStretch;314 property OnPaint: TNotifyEvent read GetOnPaint write SetOnPaint; 173 315 end; 174 316 … … 210 352 DpiFormFileDesc := TDpiFormFileDesc.Create; 211 353 RegisterProjectFileDescriptor(DpiFormFileDesc); 212 RegisterComponents('DpiControls', [TDpiButton, TDpiImage ]);354 RegisterComponents('DpiControls', [TDpiButton, TDpiImage, TDpiPaintBox, TDpiListBox]); 213 355 end; 214 356 … … 221 363 begin 222 364 Result := Round(Value * 96 / DpiScreen.Dpi); 365 end; 366 367 function ScaleRectToVcl(Value: TRect): TRect; 368 begin 369 Result.Left := ScaleToVcl(Value.Left); 370 Result.Top := ScaleToVcl(Value.Top); 371 Result.Right := ScaleToVcl(Value.Right); 372 Result.Bottom := ScaleToVcl(Value.Bottom); 373 end; 374 375 function ScaleRectFromVcl(Value: TRect): TRect; 376 begin 377 Result.Left := ScaleFromVcl(Value.Left); 378 Result.Top := ScaleFromVcl(Value.Top); 379 Result.Right := ScaleFromVcl(Value.Right); 380 Result.Bottom := ScaleFromVcl(Value.Bottom); 381 end; 382 383 { TDpiListBox } 384 385 function TDpiListBox.GetVclControl: TControl; 386 begin 387 if not Assigned(VclListBox) then VclListBox := TListBox.Create(nil); 388 Result := VclListBox; 389 end; 390 391 destructor TDpiListBox.Destroy; 392 begin 393 FreeAndNil(VclListBox); 394 inherited Destroy; 395 end; 396 397 { TDpiPaintBox } 398 399 function TDpiPaintBox.GetOnPaint: TNotifyEvent; 400 begin 401 Result := VclPaintBox.OnPaint; 402 end; 403 404 procedure TDpiPaintBox.SetOnPaint(AValue: TNotifyEvent); 405 begin 406 VclPaintBox.OnPaint := AValue; 407 end; 408 409 function TDpiPaintBox.GetVclControl: TControl; 410 begin 411 if not Assigned(VclPaintBox) then VclPaintBox := TPaintBox.Create(nil); 412 Result := VclPaintBox; 413 end; 414 415 constructor TDpiPaintBox.Create(TheOwner: TComponent); 416 begin 417 inherited; 418 Canvas := TDpiCanvas.Create; 419 Canvas.VclCanvas := VclPaintBox.Canvas; 420 Canvas.Font.VclFont := VclPaintBox.Canvas.Font; 421 UpdateVclControl; 422 ScreenChanged; 423 end; 424 425 destructor TDpiPaintBox.Destroy; 426 begin 427 FreeAndNil(VclPaintBox); 428 inherited; 429 end; 430 431 { TDpiPicture } 432 433 procedure TDpiPicture.SetBitmap(AValue: TDpiBitmap); 434 begin 435 if FBitmap = AValue then Exit; 436 FBitmap := AValue; 437 end; 438 439 procedure TDpiPicture.LoadFromFile(FileName: string); 440 begin 441 end; 442 443 444 { TDpiCanvas } 445 446 function TDpiCanvas.GetBrush: TBrush; 447 begin 448 Result := VclCanvas.Brush; 449 end; 450 451 function TDpiCanvas.GetHandle: HDC; 452 begin 453 Result := VclCanvas.Handle; 454 end; 455 456 function TDpiCanvas.GetHeight: Integer; 457 begin 458 Result := ScaleFromVcl(VclCanvas.Height); 459 end; 460 461 function TDpiCanvas.GetPen: TPen; 462 begin 463 Result := VclCanvas.Pen; 464 end; 465 466 function TDpiCanvas.GetPixel(X, Y: Integer): TColor; 467 begin 468 Result := VclCanvas.Pixels[ScaleToVcl(X), ScaleToVcl(Y)]; 469 end; 470 471 function TDpiCanvas.GetWidth: Integer; 472 begin 473 Result := ScaleFromVcl(VclCanvas.Width); 474 end; 475 476 procedure TDpiCanvas.SetBrush(AValue: TBrush); 477 begin 478 VclCanvas.Brush := AValue; 479 end; 480 481 procedure TDpiCanvas.SetFont(AValue: TDpiFont); 482 begin 483 if FFont = AValue then Exit; 484 FFont := AValue; 485 end; 486 487 procedure TDpiCanvas.SetHandle(AValue: HDC); 488 begin 489 VclCanvas.Handle := AValue; 490 end; 491 492 procedure TDpiCanvas.SetPen(AValue: TPen); 493 begin 494 VclCanvas.Pen := AValue; 495 end; 496 497 procedure TDpiCanvas.SetPixel(X, Y: Integer; AValue: TColor); 498 begin 499 VclCanvas.Pixels[ScaleToVcl(X), ScaleToVcl(Y)] := AValue; 500 end; 501 502 procedure TDpiCanvas.FrameRect(Rect: TRect); 503 begin 504 VclCanvas.FrameRect(ScaleRectToVcl(Rect)); 505 end; 506 507 function TDpiCanvas.TextWidth(Text: string): Integer; 508 begin 509 Result := ScaleFromVcl(VclCanvas.TextWidth(Text)); 510 end; 511 512 function TDpiCanvas.TextHeight(Text: string): Integer; 513 begin 514 Result := ScaleFromVcl(VclCanvas.TextHeight(Text)); 515 end; 516 517 procedure TDpiCanvas.TextOut(X, Y: Integer; Text: string); 518 begin 519 VclCanvas.TextOut(ScaleToVcl(X), ScaleToVcl(Y), Text); 520 end; 521 522 procedure TDpiCanvas.MoveTo(X, Y: Integer); 523 begin 524 VclCanvas.MoveTo(ScaleToVcl(X), ScaleToVcl(Y)); 525 end; 526 527 procedure TDpiCanvas.LineTo(X, Y: Integer); 528 begin 529 VclCanvas.LineTo(ScaleToVcl(X), ScaleToVcl(Y)); 530 end; 531 532 procedure TDpiCanvas.FillRect(ARect: TRect); 533 begin 534 VclCanvas.FillRect(ScaleRectToVcl(ARect)); 535 end; 536 537 procedure TDpiCanvas.FillRect(X1, Y1, X2, Y2: Integer); 538 begin 539 VclCanvas.FillRect(ScaleToVcl(X1), ScaleToVcl(Y1), ScaleToVcl(X2), ScaleToVcl(Y2)); 540 end; 541 542 constructor TDpiCanvas.Create; 543 begin 544 FFont := TDpiFont.Create; 545 end; 546 547 destructor TDpiCanvas.Destroy; 548 begin 549 FreeAndNil(FFont); 550 inherited; 551 end; 552 553 { TDpiGraphicControl } 554 555 procedure TDpiGraphicControl.SetCanvas(AValue: TDpiCanvas); 556 begin 557 if FCanvas = AValue then Exit; 558 FCanvas := AValue; 559 end; 560 561 procedure TDpiGraphicControl.Paint; 562 begin 563 end; 564 565 constructor TDpiGraphicControl.Create(TheOwner: TComponent); 566 begin 567 inherited; 568 FCanvas := TDpiCanvas.Create; 569 end; 570 571 destructor TDpiGraphicControl.Destroy; 572 begin 573 FreeAndNil(FCanvas); 574 inherited; 223 575 end; 224 576 … … 233 585 end; 234 586 587 procedure TDpiImage.SetPicture(AValue: TDpiPicture); 588 begin 589 if FDpiPicture = AValue then Exit; 590 FDpiPicture := AValue; 591 end; 592 235 593 function TDpiImage.GetVclControl: TControl; 236 594 begin 595 if not Assigned(VclImage) then VclImage := TImage.Create(nil); 237 596 Result := VclImage; 238 end;239 240 constructor TDpiImage.Create(TheOwner: TComponent);241 begin242 inherited;243 VclImage := TImage.Create(nil);244 597 end; 245 598 … … 264 617 end; 265 618 619 procedure TDpiFont.SetStyle(AValue: TFontStyles); 620 begin 621 VclFont.Style := AValue; 622 end; 623 266 624 procedure TDpiFont.ScreenChanged; 267 625 begin … … 275 633 end; 276 634 635 procedure TDpiFont.SetPixelsPerInch(AValue: Integer); 636 begin 637 VclFont.PixelsPerInch := PixelsPerInch; 638 end; 639 640 function TDpiFont.GetName: string; 641 begin 642 Result := VclFont.Name; 643 end; 644 645 function TDpiFont.GetColor: TColor; 646 begin 647 Result := VclFont.Color; 648 end; 649 650 function TDpiFont.GetPixelsPerInch: Integer; 651 begin 652 Result := VclFont.PixelsPerInch; 653 end; 654 655 function TDpiFont.GetStyle: TFontStyles; 656 begin 657 Result := VclFont.Style; 658 end; 659 660 procedure TDpiFont.SetColor(AValue: TColor); 661 begin 662 VclFont.Color := AValue; 663 end; 664 665 procedure TDpiFont.SetName(AValue: string); 666 begin 667 VclFont.Name := AValue; 668 end; 669 277 670 constructor TDpiFont.Create; 278 671 begin 279 VclFont := TFont.Create;280 672 Size := 8; 281 673 end; … … 283 675 destructor TDpiFont.Destroy; 284 676 begin 285 FreeAndNil(VclFont);286 677 inherited Destroy; 287 678 end; 288 679 680 procedure TDpiFont.Assign(Source: TDpiFont); 681 begin 682 VclFont.Assign(Source.VclFont); 683 Size := Source.Size; 684 FOnChange := Source.FOnChange; 685 end; 686 289 687 { TDpiWinControl } 688 689 function TDpiWinControl.GetHandle: HWND; 690 begin 691 Result := GetVclWinControl.Handle; 692 end; 693 694 procedure TDpiWinControl.SetHandle(AValue: HWND); 695 begin 696 GetVclWinControl.Handle := AValue; 697 end; 290 698 291 699 function TDpiWinControl.GetVclWinControl: TWinControl; … … 303 711 end; 304 712 713 function TDpiWinControl.ControlCount: Integer; 714 begin 715 Result := Controls.Count; 716 end; 717 305 718 constructor TDpiWinControl.Create(TheOwner: TComponent); 306 719 begin 307 inherited;308 720 Controls := TDpiControls.Create; 309 721 Controls.FreeObjects := False; 722 inherited; 310 723 end; 311 724 … … 361 774 { TDpiButton } 362 775 363 procedure TDpiButton.SetOnClick(AValue: TNotifyEvent);364 begin365 if FOnClick = AValue then Exit;366 FOnClick := AValue;367 VclButton.OnClick := AValue;368 end;369 370 776 function TDpiButton.GetVclControl: TControl; 371 777 begin 778 if not Assigned(VclButton) then VclButton := TButton.Create(nil); 372 779 Result := VclButton; 373 end;374 375 constructor TDpiButton.Create(TheOwner: TComponent);376 begin377 inherited;378 VclButton := TButton.Create(nil);379 ScreenChanged;380 780 end; 381 781 … … 397 797 procedure TDpiControl.SetVisible(AValue: Boolean); 398 798 begin 399 if FVisible = AValue then Exit;400 FVisible := AValue;401 799 GetVclControl.Visible := AValue; 402 800 end; … … 418 816 GetVclControl.OnResize := @VclFormResize; 419 817 GetVclControl.OnChangeBounds := @VclChangeBounds; 818 end; 819 820 procedure TDpiControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, 821 Y: Integer); 822 begin 823 // TODO 824 end; 825 826 procedure TDpiControl.MouseUp(Button: TMouseButton; Shift: TShiftState; X, 827 Y: Integer); 828 begin 829 // TODO 830 end; 831 832 procedure TDpiControl.MouseMove(Shift: TShiftState; X, Y: Integer); 833 begin 834 // TODO 420 835 end; 421 836 … … 445 860 end; 446 861 862 procedure TDpiControl.Invalidate; 863 begin 864 GetVclControl.Invalidate; 865 end; 866 867 procedure TDpiControl.Repaint; 868 begin 869 GetVclControl.Repaint; 870 end; 871 447 872 constructor TDpiControl.Create(TheOwner: TComponent); 448 873 begin … … 450 875 FFont := TDpiFont.Create; 451 876 FFont.OnChange := @FontChanged; 877 if Assigned(TheOwner) and (TheOwner is TDpiWinControl) then 878 Parent := TDpiWinControl(TheOwner); 879 GetVclControl; 880 UpdateVclControl; 881 ScreenChanged; 452 882 end; 453 883 … … 492 922 end; 493 923 924 function TDpiControl.GetBoundsRect: TRect; 925 begin 926 Result.Left := Left; 927 Result.Top := Top; 928 Result.Right := Left + Width; 929 Result.Bottom := Top + Height; 930 end; 931 932 function TDpiControl.GetClientHeight: Integer; 933 begin 934 Result := ScaleFromVcl(GetVclControl.ClientHeight); 935 end; 936 937 function TDpiControl.GetClientWidth: Integer; 938 begin 939 Result := ScaleFromVcl(GetVclControl.ClientWidth); 940 end; 941 942 function TDpiControl.GetEnabled: Boolean; 943 begin 944 Result := GetVclControl.Enabled; 945 end; 946 947 function TDpiControl.GetOnClick: TNotifyEvent; 948 begin 949 Result := GetVclControl.OnClick; 950 end; 951 952 function TDpiControl.GetShowHint: Boolean; 953 begin 954 Result := GetVclControl.ShowHint; 955 end; 956 957 function TDpiControl.GetVisible: Boolean; 958 begin 959 Result := GetVclControl.Visible; 960 end; 961 962 procedure TDpiControl.SetBoundsRect(AValue: TRect); 963 begin 964 SetBounds(AValue.Left, AValue.Top, AValue.Right - AValue.Left, AValue.Bottom - AValue.Top); 965 end; 966 967 procedure TDpiControl.SetEnabled(AValue: Boolean); 968 begin 969 GetVclControl.Enabled := AValue; 970 end; 971 494 972 procedure TDpiControl.SetOnChangeBounds(AValue: TNotifyEvent); 495 973 begin … … 498 976 end; 499 977 978 procedure TDpiControl.SetOnClick(AValue: TNotifyEvent); 979 begin 980 GetVclControl.OnClick := AValue; 981 end; 982 500 983 procedure TDpiControl.SetOnResize(AValue: TNotifyEvent); 501 984 begin … … 504 987 end; 505 988 989 procedure TDpiControl.SetShowHint(AValue: Boolean); 990 begin 991 GetVclControl.ShowHint := AValue; 992 end; 993 506 994 procedure TDpiControl.VclFormResize(Sender: TObject); 507 995 begin 508 SetBounds(ScaleFromVcl(GetVclControl.Left), ScaleFromVcl(GetVclControl.Top), 509 ScaleFromVcl(GetVclControl.Width), ScaleFromVcl(GetVclControl.Height)); 996 BoundsRect := ScaleRectFromVcl(GetVclControl.BoundsRect); 510 997 DoFormResize; 511 998 end; … … 513 1000 procedure TDpiControl.VclChangeBounds(Sender: TObject); 514 1001 begin 515 SetBounds(ScaleFromVcl(GetVclControl.Left), ScaleFromVcl(GetVclControl.Top), 516 ScaleFromVcl(GetVclControl.Width), ScaleFromVcl(GetVclControl.Height)); 1002 BoundsRect := ScaleRectFromVcl(GetVclControl.BoundsRect); 517 1003 DoChangeBounds; 518 1004 end; … … 540 1026 procedure TDpiControl.UpdateBounds; 541 1027 begin 542 GetVclControl. SetBounds(ScaleToVcl(Left), ScaleToVcl(Top), ScaleToVcl(Width), ScaleToVcl(Height));1028 GetVclControl.BoundsRect := ScaleRectToVcl(BoundsRect); 543 1029 end; 544 1030 … … 578 1064 { TDpiForm } 579 1065 1066 function TDpiForm.GetBorderStyle: TBorderStyle; 1067 begin 1068 Result := VclForm.BorderStyle; 1069 end; 1070 1071 function TDpiForm.GetCanvas: TDpiCanvas; 1072 begin 1073 Result := Canvas; 1074 end; 1075 580 1076 function TDpiForm.GetOnCreate: TNotifyEvent; 581 1077 begin … … 596 1092 begin 597 1093 Result := VclForm.OnShow; 1094 end; 1095 1096 procedure TDpiForm.SetBorderStyle(AValue: TBorderStyle); 1097 begin 1098 VclForm.BorderStyle := AValue; 598 1099 end; 599 1100 … … 642 1143 function TDpiForm.GetVclControl: TControl; 643 1144 begin 644 Result := VclForm;1145 Result := GetVclWinControl; 645 1146 end; 646 1147 647 1148 function TDpiForm.GetVclWinControl: TWinControl; 648 1149 begin 1150 if not Assigned(VclForm) then VclForm := TForm.Create(nil); 649 1151 Result := VclForm; 650 1152 end; … … 654 1156 begin 655 1157 inherited; 656 VclForm := TForm.Create(nil);657 ScreenChanged;658 1158 DebugLn(['TDpiForm.Create ', DbgSName(TheOwner)]); 659 1159 GlobalNameSpace.BeginWrite; … … 668 1168 GlobalNameSpace.EndWrite; 669 1169 end; 1170 ScreenChanged; 670 1171 UpdateVclControl; 671 1172 DoOnCreate;
Note:
See TracChangeset
for help on using the changeset viewer.