First of all, I already know that when you are implementing a TSpeedButton
, when you assign its Glyph
, if you do not have more than one glyph, then NumGlyphs
should be 1
, and when it's disabled, it will automatically use the same image to auto-generate a disabled version of the glyph.
However, in my situation, I am assigning an action to this speed button. The TActionManager
has both the Images
and DisabledImages
pointed to the very same TImageList
. I've also tested without any DisabledImages
assigned at all, as well as creating a copy of the images using an all-black mask, and assigning that via the DisabledImages
.
The glyph shows just fine (based on the image set up on the action) when it's enabled. But when it's disabled, only pure black colors in the images will be used for disabled images. Anything which has any sort of color besides pure black, even slightly off-black, is completely ignored, and not included when rendering the disabled image.
Here's a comparison between a test enabled image and the auto-generated disabled image. The image is just a 16x16 bitmap with some vertical lines. Starting from the far right, a completely black line, followed by slightly lighter lines to the left of it.
As you can see, when disabled, it only considers the completely black line. The next line over is only very slightly lighter than complete black.
I cannot assign the Glyph
property myself, because it will be overwritten by the action which is assigned to it. I also cannot set up the two-glyph-wide images on the image list either, because these images are widely used in many other places which have no concept of multiple glyphs. I also do not want to use all-black for my images.
How do I get a disabled TSpeedButton
(as result of disabled TAction
) to show a disabled (grayed out) image when it has an action assigned to it?
NOTE: The same happens with the TBitBtn
, or otherwise any control which relies on a 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
For the sake of example, here's the test bitmap I used:
In fact, in the Vcl.Buttons
unit, in the function TButtonGlyph.CreateButtonGlyph
, the following code seems to explicitly consider only the black areas:
{ 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;
Flat
turned on. I still see nothing when disabled. – Finicking$000000
. – FinickingDisabled
image list, using all-black versions of every glyph I have in the main list. And that means a different version for each size, as well. What a pain. – FinickingTImageList.DoDraw
. This might help (or even a duplicate): #6003518 and this: #3117521 – DifferentDisabled
image list to the action manager makes no difference. It still seems to base its disabled version off of the main image, ignoring my disabled image list. @Different While that may be the right solution, both of those links are very different. They are talking about "ugly" disabled images in the main menu (which is actually what I want). I'm talking about a button glyph auto-created by an action only using black. So no, not a duplicate. – FinickingTImageList.DoDraw
like kobik suggests. – FinickingTBitBtn
, or anything with a glyph. I don't see what loading images in the.dfm
or not would be of any difference regarding my problem. It persists either way. – FinickingTButtonGlyph
is not exposed in the interface, thus cannot be overridden. AndTImageList.DoDraw
has a parameterEnabled
which even when I override it and explicitly passTrue
all the time, it still draws nothing. Internally, I make the same call toImageList_DrawEx
for disabled as for enabled, but theEnabled
always comes true anyway, it never even comesFalse
in my debugging. So I have no idea how I can override this drawing. – FinickingOnClick
event handler which calls the action. This way, I can assign the glyphs myself. On top of that, it also means that I need to manually enable/disable the buttons whenever the action's enabled state changes. – Finicking