- Timestamp:
- Apr 6, 2021, 11:03:40 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r349 r353 340 340 end; 341 341 342 { TDpiPen } 343 344 TDpiPen = class 345 FWidth: Integer; 346 FNativePen: TPen; 347 FNativePenFree: Boolean; 348 private 349 function GetColor: TColor; 350 function GetStyle: TPenStyle; 351 function GetWidth: Integer; 352 procedure SetColor(AValue: TColor); 353 procedure SetNativePen(AValue: TPen); 354 procedure SetStyle(AValue: TPenStyle); 355 procedure SetWidth(AValue: Integer); 356 public 357 constructor Create; 358 destructor Destroy; override; 359 function GetNativePen: TPen; 360 property NativePen: TPen read FNativePen write SetNativePen; 361 published 362 property Color: TColor read GetColor write SetColor default clBlack; 363 property Style : TPenStyle read GetStyle write SetStyle default psSolid; 364 property Width: Integer read GetWidth write SetWidth default 1; 365 end; 366 367 { TDpiBrush } 368 369 TDpiBrush = class 370 private 371 FNativeBrush: TBrush; 372 FNativeBrushFree: Boolean; 373 function GetColor: TColor; 374 function GetStyle: TBrushStyle; 375 procedure SetColor(AValue: TColor); 376 function GetNativeBrush: TBrush; 377 procedure SetNativeBrush(AValue: TBrush); 378 procedure SetStyle(AValue: TBrushStyle); 379 public 380 constructor Create; 381 destructor Destroy; override; 382 property NativeBrush: TBrush read FNativeBrush write SetNativeBrush; 383 published 384 property Color: TColor read GetColor write SetColor default clWhite; 385 property Style: TBrushStyle read GetStyle write SetStyle default bsSolid; 386 end; 387 342 388 { TDpiCanvas } 343 389 344 390 TDpiCanvas = class 345 391 private 392 FBrush: TDpiBrush; 393 FBrushFree: Boolean; 394 FPen: TDpiPen; 395 FPenFree: Boolean; 346 396 FFont: TDpiFont; 347 397 FFontFree: Boolean; 348 398 FNativeCanvas: TCanvas; 349 399 FNativeCanvasFree: Boolean; 350 function GetBrush: TBrush;351 400 function GetHandle: HDC; 352 401 function GetHeight: Integer; 353 function GetPen: TPen;354 402 function GetPixel(X, Y: Integer): TColor; 355 403 function GetWidth: Integer; 356 procedure SetBrush(AValue: T Brush);404 procedure SetBrush(AValue: TDpiBrush); 357 405 procedure SetFont(AValue: TDpiFont); 358 406 procedure SetHandle(AValue: HDC); 359 procedure SetPen(AValue: T Pen);407 procedure SetPen(AValue: TDpiPen); 360 408 procedure SetPixel(X, Y: Integer; AValue: TColor); 361 409 procedure SetNativeCanvas(AValue: TCanvas); … … 386 434 property Height: Integer read GetHeight; 387 435 published 388 property Brush: T Brush read GetBrush write SetBrush;389 property Pen: T Pen read GetPen write SetPen;436 property Brush: TDpiBrush read FBrush write SetBrush; 437 property Pen: TDpiPen read FPen write SetPen; 390 438 property Font: TDpiFont read FFont write SetFont; 391 439 end; … … 1076 1124 function ScaleToNative(Value: Integer): Integer; 1077 1125 begin 1078 Result := Trunc(Value * DpiScreen.Dpi / 96);1126 Result := Round(Value * DpiScreen.Dpi / 96); 1079 1127 end; 1080 1128 … … 1190 1238 } 1191 1239 {$ENDIF} 1240 end; 1241 1242 { TDpiPen } 1243 1244 function TDpiPen.GetColor: TColor; 1245 begin 1246 Result := GetNativePen.Color; 1247 end; 1248 1249 function TDpiPen.GetStyle: TPenStyle; 1250 begin 1251 Result := GetNativePen.Style; 1252 end; 1253 1254 function TDpiPen.GetWidth: Integer; 1255 begin 1256 Result := FWidth; 1257 end; 1258 1259 procedure TDpiPen.SetColor(AValue: TColor); 1260 begin 1261 GetNativePen.Color := AValue; 1262 end; 1263 1264 procedure TDpiPen.SetNativePen(AValue: TPen); 1265 begin 1266 if FNativePen = AValue then Exit; 1267 if FNativePenFree then FreeAndNil(FNativePen); 1268 FNativePenFree := False; 1269 FNativePen := AValue; 1270 SetWidth(FWidth); 1271 end; 1272 1273 procedure TDpiPen.SetStyle(AValue: TPenStyle); 1274 begin 1275 GetNativePen.Style := AValue; 1276 end; 1277 1278 procedure TDpiPen.SetWidth(AValue: Integer); 1279 begin 1280 GetNativePen.Width := ScaleToNative(AValue); 1281 FWidth := AValue; 1282 end; 1283 1284 constructor TDpiPen.Create; 1285 begin 1286 FNativePen := TPen.Create; 1287 FNativePenFree := True; 1288 FWidth := 1; 1289 end; 1290 1291 destructor TDpiPen.Destroy; 1292 begin 1293 if FNativePenFree then 1294 FreeAndNil(FNativePen); 1295 inherited; 1296 end; 1297 1298 function TDpiPen.GetNativePen: TPen; 1299 begin 1300 Result := FNativePen; 1301 end; 1302 1303 { TDpiBrush } 1304 1305 function TDpiBrush.GetColor: TColor; 1306 begin 1307 Result := GetNativeBrush.Color; 1308 end; 1309 1310 function TDpiBrush.GetStyle: TBrushStyle; 1311 begin 1312 Result := GetNativeBrush.Style; 1313 end; 1314 1315 procedure TDpiBrush.SetColor(AValue: TColor); 1316 begin 1317 GetNativeBrush.Color := AValue; 1318 end; 1319 1320 function TDpiBrush.GetNativeBrush: TBrush; 1321 begin 1322 Result := FNativeBrush; 1323 end; 1324 1325 procedure TDpiBrush.SetNativeBrush(AValue: TBrush); 1326 begin 1327 if FNativeBrush = AValue then Exit; 1328 if FNativeBrushFree then FreeAndNil(FNativeBrush); 1329 FNativeBrushFree := False; 1330 FNativeBrush := AValue; 1331 end; 1332 1333 procedure TDpiBrush.SetStyle(AValue: TBrushStyle); 1334 begin 1335 GetNativeBrush.Style := AValue; 1336 end; 1337 1338 constructor TDpiBrush.Create; 1339 begin 1340 FNativeBrush := TBrush.Create; 1341 FNativeBrushFree := True; 1342 end; 1343 1344 destructor TDpiBrush.Destroy; 1345 begin 1346 if FNativeBrushFree then FreeAndNil(FNativeBrush); 1347 inherited; 1192 1348 end; 1193 1349 … … 2408 2564 Canvas := TDpiCanvas.Create; 2409 2565 Canvas.NativeCanvas := NativePaintBox.Canvas; 2410 Canvas.Font.NativeFont := NativePaintBox.Canvas.Font;2411 2566 UpdateNativeControl; 2412 2567 ScreenChanged; … … 2433 2588 { TDpiCanvas } 2434 2589 2435 function TDpiCanvas.GetBrush: TBrush;2436 begin2437 Result := GetNativeCanvas.Brush;2438 end;2439 2440 2590 function TDpiCanvas.GetHandle: HDC; 2441 2591 begin … … 2448 2598 end; 2449 2599 2450 function TDpiCanvas.GetPen: TPen;2451 begin2452 Result := GetNativeCanvas.Pen;2453 end;2454 2455 2600 function TDpiCanvas.GetPixel(X, Y: Integer): TColor; 2456 2601 begin … … 2463 2608 end; 2464 2609 2465 procedure TDpiCanvas.SetBrush(AValue: TBrush); 2466 begin 2467 GetNativeCanvas.Brush := AValue; 2610 procedure TDpiCanvas.SetBrush(AValue: TDpiBrush); 2611 begin 2612 if FBrush = AValue then Exit; 2613 if FBrushFree then FreeAndNil(FBrush); 2614 FBrushFree := False; 2615 FBrush := AValue; 2468 2616 end; 2469 2617 … … 2481 2629 end; 2482 2630 2483 procedure TDpiCanvas.SetPen(AValue: TPen); 2484 begin 2485 GetNativeCanvas.Pen := AValue; 2631 procedure TDpiCanvas.SetPen(AValue: TDpiPen); 2632 begin 2633 if FPen = AValue then Exit; 2634 if FPenFree then FreeAndNil(FPen); 2635 FPenFree := False; 2636 FPen := AValue; 2486 2637 end; 2487 2638 … … 2510 2661 if Assigned(FNativeCanvas) then begin 2511 2662 FFont.NativeFont := FNativeCanvas.Font; 2663 FBrush.NativeBrush := FNativeCanvas.Brush; 2664 FPen.NativePen := FNativeCanvas.Pen; 2512 2665 end; 2513 2666 end; … … 2600 2753 FFont := TDpiFont.Create; 2601 2754 FFontFree := True; 2755 FPen := TDpiPen.Create; 2756 FPenFree := True; 2757 FBrush := TDpiBrush.Create; 2758 FBrushFree := True; 2602 2759 end; 2603 2760 … … 2605 2762 begin 2606 2763 if FFontFree then FreeAndNil(FFont); 2764 if FBrushFree then FreeAndNil(FBrush); 2765 if FPenFree then FreeAndNil(FPen); 2607 2766 if FNativeCanvasFree then FreeAndNil(FNativeCanvasFree); 2608 2767 inherited;
Note:
See TracChangeset
for help on using the changeset viewer.