delphitransparencyvcltimagelist

When using styles, bitmaps of imagelists on toolbars get masked in an unexpected way


Description:

I am using PNG loaded imagelists to allow transparency in my menu's and speed buttons. Also using runtime themes to allow user defind GUI experiance.

If no style is selected, a.k.a. the "Windows" style, nice masks are generated for my toolbar, and everything works as expected. However, when I activate a style (no matter which one) a very strange rendering of the masks is performed, where some buttons appear to be empty (first and prior buttons) when disabled , and some (post and cancel buttons) actually do show a minimal mask of the original image.

Research: I have created a VCL style testing app, and am prying into the VCL to find out exactly how the drawing process proceeds. My research on SO here came with this more or less related topic, but id dint really help to get around my problem.

Meanwhile I can imagine someone else has bumbed into this and can point me in the rioght direction.

The question:

I am looking for a way to have these masks displayed correctly, or auto generated (like this link) which allows the work it as expected even when using VCL styles. This could by creating masks automatically in my imagelists, or , preferably, by changing the behavior that generates masks for the styles custom drawing.

Standard style shows toolbar fine: Standard style shows toolbar fine

Using custom style, no images on buttons: using custom style, no images on buttons

Another custom style, and you will even miss the buttons Another custom style, and you will even miss the buttons

BTW: "Dont use styles" would not be the answer I am looking for.


Solution

  • Well as it turns out, there is an undocumented property Vcl.Controls.TImageList.GrayscaleFactor

    If anything but 0 is in there, the images are rendered in a gray fashion correctly when usiong styles.

    The grayscale factor itself appears to have influence on the "darkness" of the resulting disabled buttons. The default value is 0, whih produces the behavior in the question above. Grayscalefactor appears to have no effect if no runtime theme is active.

    Personally I would have liked it better if the GrayscaleFactor would be influencing the transparency also, so buttons would look more "ghosted" rather than "grayed". The gray may not work in all themes... imagine a "grey" theme :)

    Below the effect of TImageList.Grayscalefactor on the windows 10 blue theme.

    GrayScaleFactor=1 GrayScaleFactor=1

    GrayScaleFactor=128 GrayScaleFactor=128

    GrayScaleFactor=255 (maximum allowed value) GrayScaleFactor=255 (maximum allowed value)