Changeset 131 for trunk/Packages/Common/UScaleDPI.pas
- Timestamp:
- Mar 18, 2022, 1:37:03 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UScaleDPI.pas
r122 r131 8 8 9 9 uses 10 Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, StdCtrls, 11 Contnrs; 10 Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, fgl; 12 11 13 12 type 13 TControlDimensions = class; 14 14 15 15 { TControlDimension } … … 18 18 BoundsRect: TRect; 19 19 FontHeight: Integer; 20 Controls: T ObjectList; // TList<TControlDimension>20 Controls: TControlDimensions; 21 21 // Class specifics 22 22 ButtonSize: TPoint; // TToolBar … … 26 26 constructor Create; 27 27 destructor Destroy; override; 28 end; 29 30 TControlDimensions = class(TFPGObjectList<TControlDimension>) 28 31 end; 29 32 … … 73 76 constructor TControlDimension.Create; 74 77 begin 75 Controls := T ObjectList.Create;78 Controls := TControlDimensions.Create; 76 79 end; 77 80 … … 79 82 begin 80 83 FreeAndNil(Controls); 81 inherited Destroy;84 inherited; 82 85 end; 83 86 … … 212 215 TempBmp: TBitmap; 213 216 Temp: array of TBitmap; 214 NewWidth, NewHeight: integer; 217 NewWidth: Integer; 218 NewHeight: Integer; 215 219 I: Integer; 216 220 begin 217 221 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 := TBitmap.Create; 225 TempBmp.PixelFormat := pf32bit; 226 ImgList.GetBitmap(I, TempBmp); 227 Temp[I] := TBitmap.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; 222 try 223 NewWidth := ScaleX(ImgList.Width, FromDPI.X); 224 NewHeight := ScaleY(ImgList.Height, FromDPI.Y); 225 226 Temp := nil; 227 SetLength(Temp, ImgList.Count); 228 for I := 0 to ImgList.Count - 1 do 229 begin 230 TempBmp := TBitmap.Create; 231 try 232 TempBmp.PixelFormat := pf32bit; 233 ImgList.GetBitmap(I, TempBmp); 234 Temp[I] := TBitmap.Create; 235 Temp[I].SetSize(NewWidth, NewHeight); 236 {$IFDEF UNIX} 237 Temp[I].PixelFormat := pf24bit; 238 {$ELSE} 239 Temp[I].PixelFormat := pf32bit; 240 {$ENDIF} 241 Temp[I].TransparentColor := TempBmp.TransparentColor; 242 //Temp[I].TransparentMode := TempBmp.TransparentMode; 243 Temp[I].Transparent := True; 244 Temp[I].Canvas.Brush.Style := bsSolid; 245 Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor; 246 Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height); 247 248 if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue; 249 Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp); 250 finally 251 TempBmp.Free; 252 end; 253 end; 254 255 ImgList.Clear; 256 ImgList.Width := NewWidth; 257 ImgList.Height := NewHeight; 258 259 for I := 0 to High(Temp) do 260 begin 261 ImgList.Add(Temp[I], nil); 262 Temp[i].Free; 263 end; 264 finally 265 ImgList.EndUpdate; 266 end; 252 267 end; 253 268 … … 289 304 //OldAutoSize: Boolean; 290 305 begin 306 //if not (Control is TCustomPage) then 307 // Resize childs first 308 if Control is TWinControl then begin 309 WinControl := TWinControl(Control); 310 if WinControl.ControlCount > 0 then begin 311 for I := 0 to WinControl.ControlCount - 1 do begin 312 if WinControl.Controls[I] is TControl then begin 313 ScaleControl(WinControl.Controls[I], FromDPI); 314 end; 315 end; 316 end; 317 end; 318 291 319 //if Control is TMemo then Exit; 292 320 //if Control is TForm then … … 314 342 with TCoolBar(Control) do begin 315 343 BeginUpdate; 316 for I := 0 to Bands.Count - 1 do 317 with Bands[I] do begin 318 MinWidth := ScaleX(MinWidth, FromDPI.X); 319 MinHeight := ScaleY(MinHeight, FromDPI.Y); 320 // Workaround to bad band width auto sizing 321 //Width := ScaleX(Width, FromDPI.X); 322 Width := ScaleX(Control.Width + 28, FromDPI.X); 323 //Control.Invalidate; 344 try 345 for I := 0 to Bands.Count - 1 do 346 with Bands[I] do begin 347 MinWidth := ScaleX(MinWidth, FromDPI.X); 348 MinHeight := ScaleY(MinHeight, FromDPI.Y); 349 // Workaround to bad band width auto sizing 350 //Width := ScaleX(Width, FromDPI.X); 351 Width := ScaleX(Control.Width + 28, FromDPI.X); 352 //Control.Invalidate; 353 end; 354 // Workaround for bad autosizing of coolbar 355 if AutoSize then begin 356 AutoSize := False; 357 Height := ScaleY(Height, FromDPI.Y); 358 AutoSize := True; 324 359 end; 325 // Workaround for bad autosizing of coolbar 326 if AutoSize then begin 327 AutoSize := False; 328 Height := ScaleY(Height, FromDPI.Y); 329 AutoSize := True; 330 end; 331 EndUpdate; 360 finally 361 EndUpdate; 362 end; 332 363 end; 333 364 … … 340 371 end; 341 372 342 //if not (Control is TCustomPage) then343 if Control is TWinControl then begin344 WinControl := TWinControl(Control);345 if WinControl.ControlCount > 0 then begin346 for I := 0 to WinControl.ControlCount - 1 do begin347 if WinControl.Controls[I] is TControl then begin348 ScaleControl(WinControl.Controls[I], FromDPI);349 end;350 end;351 end;352 end;353 373 //if Control is TForm then 354 374 // Control.EnableAutoSizing;
Note:
See TracChangeset
for help on using the changeset viewer.