Changeset 463 for branches/highdpi/Packages/Common/ScaleDPI.pas
- Timestamp:
- Nov 29, 2023, 2:35:44 PM (12 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/Common/ScaleDPI.pas
r462 r463 1 unit UScaleDPI;1 unit ScaleDPI; 2 2 3 3 { See: http://wiki.lazarus.freepascal.org/High_DPI } 4 4 5 {$mode delphi}{$H+}6 7 5 interface 8 6 9 7 uses 10 UDpiControls, Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, StdCtrls,11 Contnrs;8 UDpiControls, Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, 9 Generics.Collections; 12 10 13 11 type 12 TControlDimensions = class; 14 13 15 14 { TControlDimension } … … 18 17 BoundsRect: TRect; 19 18 FontHeight: Integer; 20 Controls: T ObjectList; // TList<TControlDimension>19 Controls: TControlDimensions; 21 20 // Class specifics 22 21 ButtonSize: TPoint; // TToolBar … … 26 25 constructor Create; 27 26 destructor Destroy; override; 27 end; 28 29 TControlDimensions = class(TObjectList<TControlDimension>) 28 30 end; 29 31 … … 73 75 constructor TControlDimension.Create; 74 76 begin 75 Controls := T ObjectList.Create;77 Controls := TControlDimensions.Create; 76 78 end; 77 79 … … 79 81 begin 80 82 FreeAndNil(Controls); 81 inherited Destroy;83 inherited; 82 84 end; 83 85 … … 212 214 TempBmp: TDpiBitmap; 213 215 Temp: array of TDpiBitmap; 214 NewWidth, NewHeight: integer; 216 NewWidth: Integer; 217 NewHeight: Integer; 215 218 I: Integer; 216 219 begin 217 220 ImgList.BeginUpdate; 218 NewWidth := ScaleX(ImgList.Width, FromDPI.X); 219 NewHeight := ScaleY(ImgList.Height, FromDPI.Y); 220 221 SetLength(Temp, ImgList.Count); 222 for I := 0 to ImgList.Count - 1 do 223 begin 224 TempBmp := TDpiBitmap.Create; 225 TempBmp.PixelFormat := pf32bit; 226 ImgList.GetBitmap(I, TempBmp); 227 Temp[I] := TDpiBitmap.Create; 228 Temp[I].SetSize(NewWidth, NewHeight); 229 Temp[I].PixelFormat := pf32bit; 230 Temp[I].TransparentColor := TempBmp.TransparentColor; 231 //Temp[I].TransparentMode := TempBmp.TransparentMode; 232 Temp[I].Transparent := True; 233 Temp[I].Canvas.Brush.Style := bsSolid; 234 Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor; 235 Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height); 236 237 if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue; 238 Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp); 239 TempBmp.Free; 240 end; 241 242 ImgList.Clear; 243 ImgList.Width := NewWidth; 244 ImgList.Height := NewHeight; 245 246 for I := 0 to High(Temp) do 247 begin 248 ImgList.Add(Temp[I], nil); 249 Temp[i].Free; 250 end; 251 ImgList.EndUpdate; 221 try 222 NewWidth := ScaleX(ImgList.Width, FromDPI.X); 223 NewHeight := ScaleY(ImgList.Height, FromDPI.Y); 224 225 Temp := nil; 226 SetLength(Temp, ImgList.Count); 227 for I := 0 to ImgList.Count - 1 do 228 begin 229 TempBmp := TDpiBitmap.Create; 230 try 231 TempBmp.PixelFormat := pf32bit; 232 ImgList.GetBitmap(I, TempBmp); 233 Temp[I] := TDpiBitmap.Create; 234 Temp[I].SetSize(NewWidth, NewHeight); 235 {$IFDEF UNIX} 236 Temp[I].PixelFormat := pf24bit; 237 {$ELSE} 238 Temp[I].PixelFormat := pf32bit; 239 {$ENDIF} 240 Temp[I].TransparentColor := TempBmp.TransparentColor; 241 //Temp[I].TransparentMode := TempBmp.TransparentMode; 242 Temp[I].Transparent := True; 243 Temp[I].Canvas.Brush.Style := bsSolid; 244 Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor; 245 Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height); 246 247 if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue; 248 Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp); 249 finally 250 TempBmp.Free; 251 end; 252 end; 253 254 ImgList.Clear; 255 ImgList.Width := NewWidth; 256 ImgList.Height := NewHeight; 257 258 for I := 0 to High(Temp) do 259 begin 260 ImgList.Add(Temp[I], nil); 261 Temp[i].Free; 262 end; 263 finally 264 ImgList.EndUpdate; 265 end; 252 266 end; 253 267 … … 303 317 304 318 //if Control is TMemo then Exit; 305 //if Control is T DpiForm then319 //if Control is TForm then 306 320 // Control.DisableAutoSizing; 307 321 with Control do begin … … 327 341 with TDpiCoolBar(Control) do begin 328 342 BeginUpdate; 329 for I := 0 to Bands.Count - 1 do 330 with Bands[I] do begin 331 MinWidth := ScaleX(MinWidth, FromDPI.X); 332 MinHeight := ScaleY(MinHeight, FromDPI.Y); 333 // Workaround to bad band width auto sizing 334 //Width := ScaleX(Width, FromDPI.X); 335 Width := ScaleX(Control.Width + 28, FromDPI.X); 336 //Control.Invalidate; 343 try 344 for I := 0 to Bands.Count - 1 do 345 with Bands[I] do begin 346 MinWidth := ScaleX(MinWidth, FromDPI.X); 347 MinHeight := ScaleY(MinHeight, FromDPI.Y); 348 // Workaround to bad band width auto sizing 349 //Width := ScaleX(Width, FromDPI.X); 350 Width := ScaleX(Control.Width + 28, FromDPI.X); 351 //Control.Invalidate; 352 end; 353 // Workaround for bad autosizing of coolbar 354 if AutoSize then begin 355 AutoSize := False; 356 Height := ScaleY(Height, FromDPI.Y); 357 AutoSize := True; 337 358 end; 338 // Workaround for bad autosizing of coolbar 339 if AutoSize then begin 340 AutoSize := False; 341 Height := ScaleY(Height, FromDPI.Y); 342 AutoSize := True; 343 end; 344 EndUpdate; 359 finally 360 EndUpdate; 361 end; 345 362 end; 346 363 … … 353 370 end; 354 371 355 //if Control is T DpiForm then372 //if Control is TForm then 356 373 // Control.EnableAutoSizing; 357 374 end;
Note:
See TracChangeset
for help on using the changeset viewer.