Recent

Author Topic: How to make form background transparent in Linux  (Read 1244 times)

eldred

  • Newbie
  • Posts: 5
How to make form background transparent in Linux
« on: May 09, 2020, 07:23:37 pm »
Hello everyone, may I ask if it is possible to make background of a borderless form transparent in Linux, so I can use alphablended png image as a background while retaining opacity of all controls on the form?

All solutions I found are windows-specific, and TForm.SetShape method wont work for me, as it doesn't allow for semitransparency

Second question: I also having trouble drawing my png image directly on the form's canvas (via loading png from resources). Drawing same image on a TImage component works fine like this:
Code: Pascal  [Select][+][-]
  1. MyTImageObject.Picture.LoadFromResourceName(hInstance, resnameString);
  2.  

But when I use
Code: Pascal  [Select][+][-]
  1. var img:TBitmap;
  2. img:=TBitmap.Create;
  3. img.LoadFromResourceName(hInstance, resnameString);
  4.  
I get an exception (EResNotFound), also get it when loading resource into TResourceStream first.

And when I use
Code: Pascal  [Select][+][-]
  1. var img:TPortableNetworkGraphic;
  2. img:=TPortableNetworkGraphic.Create;
  3. img.LoadFromResourceName(hInstance, resnameString);
  4.  
program runs, but nothing is drawn on Form.Canvas.Draw(0,0,img) call

Am I correct to assume that even If I manage to put my image on form canvas, opaque form background will still be seen?

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: How to make form background transparent in Linux
« Reply #1 on: May 09, 2020, 07:34:43 pm »
First I don't think reading a PNG into a TBiTMAP directly is going to work but I could be wrong there.. TPicture on the other hand knows how to handle this because it converts...

 Have you tried doing Bitmap.Canvas.changed prior to painting to the screen ?

 Also unless the gt or gk has a layered window mode I don't think you'll get what you are looking for when it comes to the form...

 In Linux things like this is a little different because how graphics is processed.

The only true wisdom is knowing you know nothing

eldred

  • Newbie
  • Posts: 5
Re: How to make form background transparent in Linux
« Reply #2 on: May 09, 2020, 09:23:20 pm »
Thank you for your response. Canvas.Changed has no effect on above behaviour.

Code: Pascal  [Select][+][-]
  1. var img:TPortableNetworkGraphic;
  2. img:=TPortableNetworkGraphic.Create;
  3. img.LoadFromResourceName(hInstance, resnameString);
  4. MyTImageObject.Picture.Assign(img);
  5.  
Works fine so I am missing a step of properly converting my TPortableNetworkGraphic object for output to Canvas.

But actual problem remains the form. Is it really impossible to do for linux? Transparent forms seem like one of the common design decisions today.
« Last Edit: May 09, 2020, 09:27:25 pm by eldred »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to make form background transparent in Linux
« Reply #3 on: May 09, 2020, 09:41:45 pm »
Hi!

The canvas of your MyTImageObject can be accessed with

MyTImageObject.Picture.PNG.Canvas

With Linux/gtk there is yet no solution for transpareny of a Form.

There is one hardrock workaround:

* Hide all applications on the desktop
* Take a screenshot of the whole desktop
* With the Form parameters top, left, width and height you can copy a recangle from the
screenshot to the Form.

Winni

eldred

  • Newbie
  • Posts: 5
Re: How to make form background transparent in Linux
« Reply #4 on: May 09, 2020, 09:57:10 pm »
I spoke of form's Canvas.
TImage works fine via direct loading of a png resource

But without proper forms, I guess I will have to abandon Lazarus for good unfortunately.

How do I mark a topic closed/solved?

 

TinyPortal © 2005-2018