Recent

Author Topic: TBitBtn no longer shows glyphs in transparent.  (Read 5911 times)

jamie

  • Hero Member
  • *****
  • Posts: 7772
TBitBtn no longer shows glyphs in transparent.
« on: June 04, 2024, 01:27:14 am »
I have a project that uses TBitbtn buttons and I load the Glyph with a simple image and set the transparent  true;

This no longer works, tmAuto or fixed or

Below is a sample of creating a Tbitmap, filling it with Red, and then assigning it to a Tbitbtn button, setting the transparent mode etc.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     BitBtn1: TBitBtn;
  16.     procedure FormCreate(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.    B:Tbitmap;
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. begin
  34.  
  35.  B:= TBitmap.Create;
  36.  B.SetSize(16,16);
  37.  B.Canvas.Brush.Color := clRed;
  38.  B.Canvas.FillRect(ClientRect);
  39.  BitBtn1.Glyph.Assign(B);
  40.  BitBtn1.Glyph.Transparent := true;
  41.  BitBtn1.Glyph.TransparentColor := clRed;
  42.  BitBtn1.Glyph.TransparentMode :=tmFixed;
  43.  B.Free;
  44. end;
  45.  
  46. end.
  47.  

 What should happen here is you shouldn't see any image at all, what you get is a red square.

What should happen, even in Auto Mode, is the code samples the lower left corner of the image for the transparent color value.
 This is Delphi compliant and has been that way as far as I can remember.

 In manual mode, it uses the color indicated in the TransparentColor property

 Neither work any more..

 I just upgraded to 3.4, I don't know if 3.2 worked but the last time it did work, I was using  2.04 laz on this project.

The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #1 on: June 04, 2024, 01:37:23 am »
fwiw: test with laz 2.2.4, 2.2.6, 2.3 and 3.0 all showed a red square for me. Besides newer versions of laz that is all I can test on this machine. Linux 64-bit gtk2.
« Last Edit: June 04, 2024, 01:41:33 am by TRon »
Today is tomorrow's yesterday.

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #2 on: June 04, 2024, 01:43:52 am »
Well, its broke.

I noticed it today when I decided to start cleaning up an old app with the new lazarus. had buttons all over the place non-transparent.
 
 I just did a direct draw to the screen with just the B bitmap and it too is still non-transparent.

 Something has gone wrong here.
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #3 on: June 04, 2024, 01:58:14 am »
Seems that when you set the transparent property last it works.
Today is tomorrow's yesterday.

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #4 on: June 04, 2024, 02:08:14 am »
Hmm.
That's strange.
I just noticed if you set MASK(ThatColor) it also works.

I think this needs to be looked at a little closer. This use to work before.

I just tried that, it only worked for the button define but not when I draw the image directly to the form.

if I use the B.Mask(clRed) it works.

something is wrong here.

« Last Edit: June 04, 2024, 02:13:05 am by jamie »
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #5 on: June 04, 2024, 02:34:47 am »
Ok, I've narrowed it down to this.

You have to set the TransparentColor := cl???? and it does not matter what color, any color.

and if you use  tmAuto it then finds the correct color.

If you don't set TransParent color first before others, it gets all messed up.

I know how to get around this but you shouldn't need to , this has changed.


EDIT:
  I just tried the hack back in the main application, it's a no go. I believe if I use a ImageList that does work.

 Maybe I should present a bug.

« Last Edit: June 04, 2024, 02:57:15 am by jamie »
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #6 on: June 04, 2024, 03:11:11 am »
Maybe I should present a bug.
You could but tbh, I have tried several things that you mentioned and none of them seem to work the way as described while my own examples seem to work for me (but perhaps I misunderstood your original issue)

Could you perhaps present an example with some graphics (either prepared or drawn in code) and an image of how that looks for you (so someone/I could try reproduce) ?
Today is tomorrow's yesterday.

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #7 on: June 04, 2024, 03:23:09 am »
I thought I did present and example?

It seems to be some random bug, work here but won't work there. etc.

Using a Imagelist works ok but the part where I decided to draw it myself using the transparent facilities no longer work correctly.

I'll post back a different example.
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #8 on: June 04, 2024, 03:39:14 am »
I thought I did present and example?
Yes, you did with the glyph example on the bitbtn.

And as I wrote, none of the things you mentioned seem to have any influence (at least for me) other than either setting the transparency property. And I am also unable to repeat it with directly drawing to a form. Do note that while I understand your situation that directly drawing onto component canvas is not the brightest of idea's and Lazarus provides other means especially for such cases as transparency (lazintfimg etc).

Quote
I'll post back a different example.
That would be appreciated, at least to try and see if we can produce some consistent behaviour.
Today is tomorrow's yesterday.

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #9 on: June 04, 2024, 03:45:33 am »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     BitBtn1: TBitBtn;
  16.     procedure BitBtn1Click(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.BitBtn1Click(Sender: TObject);
  33. Var
  34.   B:TBitmap;
  35. begin
  36.   B := TbitMap.Create;
  37.   B.pixelFormat := pf24bit;
  38.   B.SetSize(16,16);
  39.   b.Canvas.Brush.COlor := clRed;
  40.   B.Canvas.FillRect(B.Canvas.ClipRect);
  41.   B.Canvas.Pen.Color := clBlack;
  42.   B.Canvas.Line(0,0,15,15);
  43.   B.TransparentColor := clRed;// << I shouldn't have to do this?,Comment it out and see.
  44.   B.TransparentMode := tmAuto;// Because we are in auto mode.
  45.   B.TransParent := true;
  46.   Canvas.Draw(0,0,B);     // Test to the form.
  47.   Bitbtn1.Glyph.Assign(B);  //Looks like assignment is not assigning naturally.
  48.   B.Free;                   //Could be using DRAW thus,transparent draw instead of copy.
  49.   //In the past, Assigned copied the image to the button and you set the transparent of the image in the button if you wanted it so.
  50.   //In any case, in main app it seems to be a mess due to some randomness.
  51. end;
  52.  
  53. end.
  54.  
  55.  
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #10 on: June 04, 2024, 04:15:11 am »
Thank you jamie.

now... this is what I need to do to get it 'working'.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   B := TBitMap.Create;
  4.   B.pixelFormat := pf24bit;
  5.   B.SetSize(16,16);
  6.  
  7.   B.Canvas.Brush.Color := clRed;
  8.   B.Canvas.FillRect(B.Canvas.ClipRect);
  9.   B.Canvas.Pen.Color := clBlack;
  10.   B.Canvas.Line(0,0,15,15);
  11.  
  12. //  B.TransparentColor := clRed;//  no influence whatsoever.
  13. //  B.TransparentMode := tmAuto;// no influence whatsoever.
  14.   B.TransParent := true; // <- this is key for me
  15.  
  16. //  Canvas.Draw(0,0,B);     // Does not work at gtk2, only in onpaint event so we do that instead
  17.   Bitbtn1.Glyph.Assign(B);  //Looks like assignment is not assigning naturally.
  18. end;
  19.  
  20. procedure TForm1.FormPaint(Sender: TObject);
  21. begin
  22.   B.TransparentColor := clRed;// Not setting this results in a red square with a black line
  23. //  B.TransparentMode := tmAuto;// No influence whatsoever
  24.   B.TransParent := true; // <- this is key... even though it is already set. Not setting this results in a red square with black line.
  25.   Form1.Canvas.Draw(20,20,b);
  26. end;
  27.  
I need to scratch my head a few times in order to make sense out of that.
Today is tomorrow's yesterday.

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #11 on: June 04, 2024, 11:16:27 pm »
There is definitely a change because it worked in 2.04 but I didn't change until 3.2 and now 3.4 Lazarus

I just checked an old install of Delphi, it works exactly as expected and use to work until now for me anyways.


The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7772
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #12 on: June 05, 2024, 12:44:28 am »
I think I found the problem.

Using this code to test the drawing..
Code: Pascal  [Select][+][-]
  1. procedure TForm1.BitBtn1Click(Sender: TObject);
  2. Var
  3.   B:TBitmap;
  4. begin
  5.   B := TBitmap.Create;
  6.   B.SetSize(16,16);
  7.   B.Canvas.Brush.Color := clRed;
  8.   B.Canvas.FillRect(B.canvas.ClipRect);
  9.   B.Canvas.Line(0,0,15,15);
  10.   B.TransparentMode := tmFixed; //<< backwards.
  11.   B.Transparent := True;
  12.   Canvas.Draw(0,0,B);
  13.   B.Free;
  14. end;                                          
  15.  
  16.  

 That does exactly what it should, gets the color from the lower left.
 now looking at the code in the sources that is causing this.

Code: Pascal  [Select][+][-]
  1. procedure TRasterImage.SetTransparentMode(AValue: TTransparentMode);
  2. begin
  3.   if AValue = TransparentMode then exit;
  4.   FTransparentMode := AValue;
  5.  
  6.   if AValue = tmAuto
  7.   then TransparentColor := clDefault
  8.   else TransparentColor := RequestTransparentColor;
  9. end;                                            
  10.  
  11.  

 the RequestTransparentColor gets the color at the lower left corner as it should.
but look at the boolean operations!

 The items are backwards.
The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #13 on: June 05, 2024, 04:57:38 am »
the RequestTransparentColor gets the color at the lower left corner as it should.
but look at the boolean operations!

The items are backwards.
I don't believe they are (unless I misinterpreted what items are backwards). fwiw: I am still scratching ...  :)

The code you quote seem to not have been changed over 13 years but besides that the documentation is clear on some things.

RequestTransparentColor states:
Quote
RequestTransparentColor is a TColor function used to get the color for transparent pixels in the image. It is called when the value tmFixed is assigned to the TransparentMode property.

RequestTransparentColor examines pixels in the raw image data to get the return value for the method. It gets the color for the pixel located at the bottom-left corner of the image (x = 0, y - Height-1).

When Empty returns True (raw image data is not available), the return value is clNone.
That also implies that when that is not set to tmFixed it defaults to tmAuto and tmAuto uses clDefault as transparent color (at least that is what the source-code of TRasterimage tells).

I have a feeling that you/we would have to look at things a layer deeper or so.
« Last Edit: June 05, 2024, 05:03:39 am by TRon »
Today is tomorrow's yesterday.

dsiders

  • Hero Member
  • *****
  • Posts: 1635
Re: TBitBtn no longer shows glyphs in transparent.
« Reply #14 on: June 05, 2024, 05:09:17 am »
the RequestTransparentColor gets the color at the lower left corner as it should.
but look at the boolean operations!

The items are backwards.
I don't believe they are (unless I misinterpreted what items are backwards). fwiw: I am still scratching ...  :)

The code you quote seem to not have been changed over 13 years but besides that the documentation is clear on some things.

RequestTransparentColor states:
Quote
RequestTransparentColor is a TColor function used to get the color for transparent pixels in the image. It is called when the value tmFixed is assigned to the TransparentMode property.

RequestTransparentColor examines pixels in the raw image data to get the return value for the method. It gets the color for the pixel located at the bottom-left corner of the image (x = 0, y - Height-1).

When Empty returns True (raw image data is not available), the return value is clNone.
That also implies that when that is not set to tmFixed it defaults to tmAuto and tmAuto uses clDefault as transparent color (at least that is what the source-code of TRasterimage tells).

I have a feeling that you/we would have to look at things a layer deeper or so.

Keep in mind that the docs can be incomplete or wrong. If something looks askew, report a documentation bug.


 

TinyPortal © 2005-2018