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

Just starting out? Need help? Post your questions and find answers here.
User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

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

Post 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
User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

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

Post 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

fluent
User
User
Posts: 68
Joined: Sun Jan 24, 2021 10:57 am

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

Post 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



User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

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

Post by HwyStar »

You... My Man... Are brillant!

Thanks for the quick reply, Mate!

Done deal.
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

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

Post by Saki »

The disadvantage here, however, is again the loss of the edge smoothing of the fonts.
地球上の平和
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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

Egypt my love
User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

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

Post 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! :)
User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

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

Post 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.
User avatar
HwyStar
Enthusiast
Enthusiast
Posts: 101
Joined: Mon Apr 05, 2010 7:13 pm
Location: Reno, Nevada

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

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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

Egypt my love
Post Reply