TImageList High DPI support
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
Here is a concept for a DPI-aware TImageList
Changes in TCustomImageList:
1.) Create overload(s) for Draw that accept a PPI value.
2.) Create a function "ReferenceForPPI(const aPPI: Integer): TWSCustomImageListReference" that returns the native image list handle for a PPI value (analog to Reference property).
3.) Create function "WidthForPPI(const aPPI: Integer): Integer" and HeightForPPI that return image width/height for a PPI value.
4.) Obviously you need a container that stores images in ImageIndex/PPI pairs. (Eg. a list[PPI] of list[ImageIndex] or the other way round or whatsoever - it doesn't matter if it is fast enough.)
Changes in TImageList:
5.) Design-time: the image list editor has to accept different image sizes for one ImageIndex.
6.) Run-time: if a resolution/PPI is needed but isn't available, all images have to be scaled from an available size.
Changes in controls:
7.) All controls that use TCustomImageList have to use the new PPI-aware Draw methods or PPI-aware ReferenceForPPI.
E.g. in lcl\interfaces\win32\win32pagecontrol.inc TWin32WSCustomTabControl.CreateHandle you need
SendMessage(Result, TCM_SETIMAGELIST, 0, TCustomTabControl(AWinControl).Images.ReferenceForPPI(AWinControl.Font.PixelsPerInch)._Handle);
instead of
SendMessage(Result, TCM_SETIMAGELIST, 0, TCustomTabControl(AWinControl).Images.Reference._Handle);
E.g. in TToolButton.Paint you need:
ImgList.Draw(Canvas, IconPos.X, IconPos.Y, ImgIndex, Font.PixelsPerInch, ImgEffect);
and
IconSize := Point(ImgList.WidthForPPI(Font.PixelsPerInch), ImgList.HeightForPPI(Font.PixelsPerInch));
For backwards compatibilty, TCustomImageList must introduce the Scaled property with which you can disable PPI scaling. In this case PPI value will just be ignored and the default images will always be returned.
Mantis conversion info:
- Mantis ID: 32967
- Monitored by: » @FTurtle (FTurtle), » AntonK (Anton Kavalenka)
- Target version: 1.10