TSpeedButton with TAction - Auto-generated disabled image only considers black

First of all, I already know that during implementation TSpeedButton, when you assign it Glyph, if you have no more than one glyph, it NumGlyphsshould be 1, and when it is disabled, it will automatically use the same image to automatically generate a disabled version of the glyph.

However, in my situation, I assign an action to this speed button. TActionManagerhas both Imagesand DisabledImagespointing to the same TImageList. I also tested without any DisabledImagesassigned at all, and also to create a copy of the images using a completely black mask and assigning it using DisabledImages.

The symbol shows only thin (based on the image configured for the action) when it is on. But when it is disabled, only black colors in the images will be used for disabled images. Everything that has any color except pure black, even slightly black, is completely ignored and does not turn on when rendering a disabled image.

Here is a comparison between the test enabled image and the automatically generated disabled image. The image is only a 16x16 bitmap with some vertical lines. Starting from the far right, a completely black line, and then slightly lighter lines to her left.

Comparison of actions on and off

As you can see, when disconnected, it takes into account only the black line. The next line is a little lighter than black.

Glyph , , . , , . .

TSpeedButton ( TAction), () , ?

. TBitBtn, - , Glyph.


u44169002.pas

unit u44169002;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, System.ImageList,
  Vcl.ImgList, System.Actions, Vcl.ActnList, Vcl.PlatformDefaultStyleActnCtrls, Vcl.ActnMan, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Actions: TActionManager;
    actTest: TAction;
    ImageList: TImageList;
    SpeedButton1: TSpeedButton;
    BitBtn1: TBitBtn;
    procedure actTestExecute(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.actTestExecute(Sender: TObject);
begin
  Self.actTest.Enabled:= False;
end;

end.

u44169002.dfm

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 231
  ClientWidth = 405
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object SpeedButton1: TSpeedButton
    Left = 24
    Top = 24
    Width = 105
    Height = 33
    Action = actTest
    Flat = True
  end
  object BitBtn1: TBitBtn
    Left = 160
    Top = 24
    Width = 105
    Height = 33
    Action = actTest
    Caption = 'Test Action'
    TabOrder = 0
  end
  object Actions: TActionManager
    DisabledImages = ImageList
    Images = ImageList
    Left = 24
    Top = 128
    StyleName = 'Platform Default'
    object actTest: TAction
      Caption = 'Test Action'
      Hint = 'This is just a test action'
      ImageIndex = 0
      OnExecute = actTestExecute
    end
  end
  object ImageList: TImageList
    Left = 24
    Top = 72
    Bitmap = {
      494C010101000800440010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
      0000000000003600000028000000400000001000000001002000000000000010
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000082828200000000006B6B6B000000
      0000555555000000000041414100000000002D2D2D00000000001D1D1D000000
      00000C0C0C000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000424D3E000000000000003E000000
      2800000040000000100000000100010000000000800000000000000000000000
      000000000000000000000000FFFFFF00FFFF0000000000005555000000000000
      5555000000000000555500000000000055550000000000005555000000000000
      5555000000000000555500000000000055550000000000005555000000000000
      5555000000000000555500000000000055550000000000005555000000000000
      5555000000000000FFFF00000000000000000000000000000000000000000000
      000000000000}
  end
end

, :

Test bitmap


, Vcl.Buttons TButtonGlyph.CreateButtonGlyph :

{ Create a disabled version }
with MonoBmp do
begin
  Assign(FOriginal);
  HandleType := bmDDB;
  Canvas.Brush.Color := clBlack;
  Width := IWidth;
  if Monochrome then
  begin
    Canvas.Font.Color := clWhite;
    Monochrome := False;
    Canvas.Brush.Color := clWhite;
  end;
  Monochrome := True;
end;
with TmpImage.Canvas do
begin
  Brush.Color := clBtnFace;
  FillRect(IRect);
  Brush.Color := clBtnHighlight;
  SetTextColor(Handle, clBlack);
  SetBkColor(Handle, clWhite);
  BitBlt(Handle, 1, 1, IWidth, IHeight,
    MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
  Brush.Color := clBtnShadow;
  SetTextColor(Handle, clBlack);
  SetBkColor(Handle, clWhite);
  BitBlt(Handle, 0, 0, IWidth, IHeight,
    MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
end;
+6

All Articles