Recent

Author Topic: form transparency  (Read 2474 times)

toby

  • Sr. Member
  • ****
  • Posts: 270
form transparency
« on: September 20, 2023, 07:36:26 pm »
is it possible to have a transparent window in lazarus so it looks like there is just text on the screen?

all i found was this

https://forum.lazarus.freepascal.org/index.php?topic=15565.0
i have been able to do it with a c++ with snprintf and want simple text

xforms and fpgui don't seem to be able to do it?

-

Lulu

  • Sr. Member
  • ****
  • Posts: 265
Re: form transparency
« Reply #1 on: September 20, 2023, 09:22:32 pm »
Hi, in the object inspector, select the form, and set property AlphaBlend to TRUE and AlphaBlendValue to any value  from 0(transparent) to 255(opaque).
According to the restriction view, it don't work only on GTK1.
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: form transparency
« Reply #2 on: September 20, 2023, 10:31:30 pm »
A mini correction (or bug?), an AlphaBlend value of 0 would be same like closing a form, at least that happen on my Windows machine.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: form transparency
« Reply #3 on: September 20, 2023, 10:59:58 pm »
There is a way to do it and have text show normally.

I covered this way back at some point on how to make a window transparent but all items drawn on it will should normally.

This alllows for those that like having things like running video and overlay the image with text, which I think is the case here.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: form transparency
« Reply #4 on: September 20, 2023, 11:12:20 pm »
at a look at this, windows only I guess.

The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: form transparency
« Reply #5 on: September 21, 2023, 12:20:44 am »
at a look at this, windows only I guess.
To keep it 32/64 bit compatible it should be
Code: Pascal  [Select][+][-]
  1. SetWindowLongPtr(Self.Handle, GWL_EXSTYLE, GetWindowLongPtr(Self.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
But I assume that your way would break the window.
This is how I've done in past:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   Self.Color := clSilver;
  6.   SetWindowLongPtr(Self.Handle, GWL_EXSTYLE, GetWindowLongPtr(Self.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
  7.   SetLayeredWindowAttributes(Self.Handle, clSilver, 0, LWA_COLORKEY);
  8.   for i := 0 to Pred(ComponentCount) do
  9.     begin
  10.       if Components[i].ClassType = TLabel then
  11.         TLabel(Components[i]).Font.Color := clWhite;
  12.       if Components[i].ClassType = TPanel then
  13.         TPanel(Components[i]).Font.Color := clWhite;
  14.     end;
  15. end;
And you should be aware that this not just make the window color transparent, it makes the transparent area click-thru.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: form transparency
« Reply #6 on: September 21, 2023, 12:52:14 am »
i'm on linux with lazarus-2.2.6
and using constructor to make forms

the https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tcustomform.alphablendvalue.html
has it with tcustomform

if i use the alphablend and alphablendvalue
txplugins = class(tform)
it doesn't work

and if i use
txplugins = class(tcustomform)
i get no errors but running the program shows nothing
even with alphablendvalue := 255;
« Last Edit: September 21, 2023, 12:53:57 am by toby »

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: form transparency
« Reply #7 on: September 22, 2023, 12:11:24 am »
the alphablen doesn't even work in on my windows - wrong hardware or ?

jamie what is your code suppose to be doing?
just a labelclick to change the label caption? nothing else in windows

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: form transparency
« Reply #8 on: September 22, 2023, 03:19:50 am »

this is what works on windows in the form

color := clwhite;
setwindowlongptr(self.handle, gwl_exstyle,getwindowlongptr(self.handle, gwl_exstyle) or ws_ex_layered);
setlayeredwindowattributes(self.handle, clwhite, 0, lwa_colorkey);

i guess there is nothing comparable for linux

balazsszekely

  • Guest
Re: form transparency
« Reply #9 on: September 22, 2023, 08:17:28 am »
Quote
author=toby link=topic=64677.msg492061#msg492061 date=1695345590
i guess there is nothing comparable for linux
The attached project works both on windows and linux, you can move/close/minimize the form.

PS: Tested on windows and linux(gt2 and qt5), with lazarus main and fpc 3.2.2.

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: form transparency
« Reply #10 on: September 22, 2023, 07:05:16 pm »
GetMem
very very nice indeed - thanks for sure

i am replacing a c++ fluxbox/xtdesktop/sysmon plugin - that writes directly to the screent with snprintf
i have been slogging with the c++ code and don't like doing it - now i can easily do it with fpc - your code was very clear and clean also - took no effect to get my fpc sysmon code working

your code works perfectly on linux compiled directly with fpc-3.3.1 with lazarus-2.2.6 installed
and works perfectly with wine64-8.16 compiled directly with ppcrossx64-3.3.1 with lazarus-2.2.6

as an aside
it is nice not having to use wine64 with the
color := clwhite;
setwindowlongptr(self.handle, gwl_exstyle,getwindowlongptr(self.handle, gwl_exstyle) or ws_ex_layered);
setlayeredwindowattributes(self.handle, clwhite, 0, lwa_colorkey);

wine64 code is a real resource hog

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: form transparency
« Reply #11 on: September 23, 2023, 02:47:26 am »
GetMem

am i correct that you can't use other objects with this? like a tlabel?

balazsszekely

  • Guest
Re: form transparency
« Reply #12 on: September 23, 2023, 08:05:18 am »
GetMem

am i correct that you can't use other objects with this? like a tlabel?
Yes. You can use any control you like or if you want a simple text on the screen(as in your original post), just create a png/bmp with the text.

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: form transparency
« Reply #13 on: September 23, 2023, 03:26:44 pm »
I didn't look at Getmem example which most likely involves the BGR components, but the example I supplied allows you to click through the window, so all mouse and actions get reported to the window beneath but allows you to draw ontop of the window without effecting the actual window below.


Have a good day.
The only true wisdom is knowing you know nothing

toby

  • Sr. Member
  • ****
  • Posts: 270
Re: form transparency
« Reply #14 on: September 23, 2023, 09:08:40 pm »
thank you Fred vs

i tried compiling the  mseide-msegui/apps/demo

it compiles 120 of it's units with no problem but gives this range check error when run

An unhandled exception occurred at $0000000000538D5A:
ERangeError: Range check error
  $0000000000538D5A
  $00000000005C91AC
  $00000000005C9299
  $000000000041C8AE

isn't there a way to have the place it occurs printed out?  -gl isn't enough

do you know what the demo.prj file is?

what do you recomment compiling ?

---







 

TinyPortal © 2005-2018