Page 1 of 1

Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 1:57 pm
by HwyStar
I understand how to create a transparent window. Is there a way for us to set a TextGadget() to also have transparency too? Just text with no background?

Ignore the arrow in the image below.

My goal is to display a HUD display window over MSFS 2020 with pertinent flight information data like a Real-life airplane does.

Image

Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 2:32 pm
by HwyStar
Code to use to "be tweaked" by a pro:

Code: Select all

Enumeration
  #WIN
  #RALT
  #TORQUE
  #IAS
  #FONT
EndEnumeration

Procedure ShowWin()
If OpenWindow(#WIN, 0, 0, 400, 200, "Transparent Window",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
  SetWindowColor(#WIN,#Blue)
  SetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
  SetLayeredWindowAttributes_(WindowID(#WIN),#Blue,0,#LWA_COLORKEY)

  If LoadFont(#Font, "Segoe UI", 11)
    SetGadgetFont(#PB_Default, FontID(#Font)) 
  EndIf
  TextGadget(#RALT,    10, 10,100, 20, "RALT: 2,050")
  TextGadget(#TORQUE,  10,100,100, 20, "THQ%: 95%")
  TextGadget(#IAS,    290, 10,100, 20, "IAS%: 95kt",#PB_Text_Right)
  SetGadgetColor(#RALT,  #PB_Gadget_FrontColor,$14DE1F)
  SetGadgetColor(#TORQUE,#PB_Gadget_FrontColor,$14DE1F)
  SetGadgetColor(#IAS,   #PB_Gadget_FrontColor,$14DE1F)
EndIf

EndProcedure

ShowWin()
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_CloseWindow 
    Quit = 1
  EndIf

Until Quit = 1


Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 2:44 pm
by fluent
Not a pro by any means but give this a try:

Code: Select all

Enumeration
  #WIN
  #RALT
  #TORQUE
  #IAS
  #FONT
EndEnumeration

Procedure ShowWin()
  If OpenWindow(#WIN, 0, 0, 400, 200, "Transparent Window",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    SetWindowColor(#WIN,#Blue)
    SetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
    SetLayeredWindowAttributes_(WindowID(#WIN),#Blue,0,#LWA_COLORKEY)
    
    If LoadFont(#Font, "Segoe UI", 11)
      SetGadgetFont(#PB_Default, FontID(#Font)) 
    EndIf
    TextGadget(#RALT,    10, 10,100, 20, "RALT: 2,050")
    TextGadget(#TORQUE,  10,100,100, 20, "THQ%: 95%")
    TextGadget(#IAS,    300, 10,100, 20, "IAS%: 95kt")
    SetGadgetColor(#RALT,  #PB_Gadget_FrontColor,$14DE1F)
    SetGadgetColor(#RALT,  #PB_Gadget_BackColor,#Blue)
    SetGadgetColor(#TORQUE,#PB_Gadget_FrontColor,$14DE1F)
    SetGadgetColor(#TORQUE,  #PB_Gadget_BackColor,#Blue)
    SetGadgetColor(#IAS,   #PB_Gadget_FrontColor,$14DE1F)
    SetGadgetColor(#IAS,  #PB_Gadget_BackColor,#Blue)
  EndIf
  
EndProcedure

SystemParametersInfo_(#SPI_SETFONTSMOOTHING,0,0,0)   ;  turns off font smoothing

ShowWin()
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_CloseWindow 
    Quit = 1
  EndIf
  
Until Quit = 1




Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 2:48 pm
by HwyStar
You... My Man... Are brillant!

Thanks for the quick reply, Mate!

Done deal.

Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 3:23 pm
by Saki
The disadvantage here, however, is again the loss of the edge smoothing of the fonts.

Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 3:45 pm
by RASHAD
Hi
Don't play with system parameters
It's very bad practice

Code: Select all

Enumeration
  #WIN
  #RALT
  #TORQUE
  #IAS
  #FONT
EndEnumeration

Procedure ShowWin()
  If OpenWindow(#WIN, 0, 0, 400, 200, "Transparent Window",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    SetWindowColor(#WIN,$f0f0f0)
    SetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
    SetLayeredWindowAttributes_(WindowID(#WIN),$f0f0f0,0,#LWA_COLORKEY)
    
    If LoadFont(#Font, "Segoe UI", 12,#PB_Font_HighQuality)
      SetGadgetFont(#PB_Default, FontID(#Font)) 
    EndIf
    TextGadget(#RALT,    10, 10,100, 20, "RALT: 2,050")
    TextGadget(#TORQUE,  10,100,100, 20, "THQ%: 95%")
    TextGadget(#IAS,    290, 10,100, 20, "IAS%: 95kt",#PB_Text_Right)
    SetGadgetColor(#RALT,  #PB_Gadget_FrontColor,$00ff00)
    SetGadgetColor(#RALT,  #PB_Gadget_BackColor,$f0f0f0)
    SetGadgetColor(#TORQUE,#PB_Gadget_FrontColor,$00ff00)
    SetGadgetColor(#TORQUE,  #PB_Gadget_BackColor,$f0f0f0)
    SetGadgetColor(#IAS,   #PB_Gadget_FrontColor,$00ff00)
    SetGadgetColor(#IAS,  #PB_Gadget_BackColor,$f0f0f0)
  EndIf
  
EndProcedure

ShowWin()
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_CloseWindow 
    Quit = 1
  EndIf
  
Until Quit = 1


Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 3:53 pm
by HwyStar
I am so stoked to do my next project! I will be revisiting an older post I made about SimConnect, using PB calls. I will need help with the SimConnect prototypes since it is over my old, thick, head. I will present my questions one prototype call at a time. There are a total of five prototypes that I will need to understand. I have made a successful PB connection with SimConnect, I just need to now get the data I need.

PB Hud display (top-most window code)

Code: Select all

Enumeration
  #WIN
  #RALT
  #TORQUE
  #IAS
  #FONT
  #EXIT
EndEnumeration

Procedure ShowWin()
  SystemParametersInfo_(#SPI_SETFONTSMOOTHING,0,0,0)   ;  turns off font smoothing

  If OpenWindow(#WIN, 0, 0, 1000, 450, "Daher TBM-930",  #PB_Window_BorderLess | #PB_Window_ScreenCentered)
    SetWindowPos_(WindowID(#WIN), #HWND_TOPMOST, 0, 0, 0, 0,#SWP_NOACTIVATE | #SWP_NOMOVE | #SWP_NOSIZE)  
    SetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE,  GetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)

    SetWindowColor(#WIN,#Blue)
    SetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
    SetLayeredWindowAttributes_(WindowID(#WIN),#Blue,0,#LWA_COLORKEY)
    
    If LoadFont(#Font, "Segoe UI Bold", 11)
      SetGadgetFont(#PB_Default, FontID(#Font)) 
    EndIf
    ButtonGadget(#EXIT,     WindowWidth(#WIN) - 20,0,20,20,"X")
    TextGadget(#RALT,       10, 25,100, 20, "RALT: 25 ft")
    TextGadget(#IAS,        (WindowWidth(#WIN) / 2) - 50, 25,100, 20, "IAS%: 0kt")
    TextGadget(#TORQUE,     WindowWidth(#WIN) - 100, 25,100, 20, "THQ%: 5%")

    SetGadgetColor(#RALT,   #PB_Gadget_FrontColor,$1D8D23)
    SetGadgetColor(#RALT,   #PB_Gadget_BackColor,#Blue)
    SetGadgetColor(#TORQUE, #PB_Gadget_FrontColor,$1D8D23)
    SetGadgetColor(#TORQUE, #PB_Gadget_BackColor,#Blue)
    SetGadgetColor(#IAS,    #PB_Gadget_FrontColor,$1D8D23)
    SetGadgetColor(#IAS,    #PB_Gadget_BackColor,#Blue)
  EndIf
  
EndProcedure

ShowWin()

Repeat
  Event = WaitWindowEvent()
  Select Event
  Case #PB_Event_CloseWindow 
    Quit = #True

  Case #PB_Event_Gadget
     Select EventGadget()
     Case #EXIT
       Quit = #True
     EndSelect
  EndSelect
Until Quit = #True
Here is a screen print of that code above in action:
https://drive.google.com/file/d/1By5Jq7 ... sp=sharing

Sweet! :)

Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 3:56 pm
by HwyStar
Saki wrote: Sat Apr 17, 2021 3:23 pm The disadvantage here, however, is again the loss of the edge smoothing of the fonts.
Very true, Saki. But, on my 4K monitor, as you can see, the font is really not that bad. The font displayed is really no worse than a real-life HUD displays'.

I am satisfied with the results. Have a look at the screenprint I just posted.

Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 4:38 pm
by HwyStar
RASHAD wrote: Sat Apr 17, 2021 3:45 pm Hi
Don't play with system parameters
It's very bad practice
I just saw your reply, Rashad.

So that I understand, since I do very much respect your opinion, what am I doing wrong; and can this affect the overall health of the OS while this is running? Windows only, since MSFS 2020 only runs on windows.

Re: Transparent background of a TextGadget() over a transparent window?

Posted: Sat Apr 17, 2021 4:52 pm
by RASHAD
Hi HwyStar
If your project is for you only so there is no any problem
But if somebody else will use it after quit he will discover that all the running application has a problem he can't solve
Next is a working snippet see if it will suit you
At the end you should have what you asked for :)

Code: Select all

Enumeration
  #WIN
  #RALT
  #TORQUE
  #IAS
  #FONT
EndEnumeration

Procedure ShowWin()
  If OpenWindow(#WIN, 0, 0, 400, 200, "Transparent Window",#PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    SetWindowColor(#WIN,$00ef00)
    SetWindowLong_(WindowID(#WIN), #GWL_EXSTYLE, #WS_EX_LAYERED | #WS_EX_TOPMOST)
    SetLayeredWindowAttributes_(WindowID(#WIN),$00ef00,0,#LWA_COLORKEY)
    
    If LoadFont(#Font, "Segoe UI", 12,#PB_Font_HighQuality)
      SetGadgetFont(#PB_Default, FontID(#Font)) 
    EndIf
    TextGadget(#RALT,    10, 10,100, 20, "RALT: 2,050")
    TextGadget(#TORQUE,  10,100,100, 20, "THQ%: 95%")
    TextGadget(#IAS,    290, 10,100, 20, "IAS%: 95kt",#PB_Text_Right)
    SetGadgetColor(#RALT,  #PB_Gadget_FrontColor,$00ff00)
    SetGadgetColor(#RALT,  #PB_Gadget_BackColor,$00ef00)
    SetGadgetColor(#TORQUE,#PB_Gadget_FrontColor,$00ff00)
    SetGadgetColor(#TORQUE,  #PB_Gadget_BackColor,$00ef00)
    SetGadgetColor(#IAS,   #PB_Gadget_FrontColor,$00ff00)
    SetGadgetColor(#IAS,  #PB_Gadget_BackColor,$00ef00)
  EndIf
  
EndProcedure

ShowWin()
Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_CloseWindow 
    Quit = 1
  EndIf
  
Until Quit = 1