Page 2 of 2

Re: Transparent CanvasGadget

Posted: Thu Apr 21, 2022 11:10 am
by ZX80
Thanks, Bernd.

I'm writing a user interface that consists of a frame only. I found your code handy and easy to select a region (for making screenshot). I hope the technical part is over. You may have seen the progress in my previous topics. I was just taking a little break. And now I need to take care of interactivity. And now I want to get this over with. I just wanted to add a bit more visibility for end user (to be able to see the overlap area). So, we know how far we can scroll down the page.


added.

Thank you very much :!:
This is not exactly what I was talking about. But I can already work with this.

I see it like this:

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "Select your area", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Tool)
  SetWindowColor(0, #Blue)
  SetWindowLong_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED|#WS_EX_TOPMOST)
  SetLayeredWindowAttributes_(WindowID(0), #Blue, 0, #LWA_COLORKEY)
  
  StripHeight = 20
  StripBorder = 3
  
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
      Case #PB_Event_Repaint
        If StartDrawing(WindowOutput(0))
          Box(0, WindowHeight(0) - StripHeight - StripBorder, WindowWidth(0), StripBorder, #Red)
          StopDrawing()
        EndIf
        
    EndSelect
    
  ForEver
EndIf
Attention! Do not resize the window. I haven't added a reaction for this event yet (well, I guess I could do that). Just move it.
Thanks again.

Re: Transparent CanvasGadget

Posted: Thu Apr 21, 2022 11:29 am
by ZX80
In the simplest case like this:

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "Select your area", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Tool)
  SetWindowColor(0, #Blue)
  SetWindowLong_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED|#WS_EX_TOPMOST)
  SetLayeredWindowAttributes_(WindowID(0), #Blue, 0, #LWA_COLORKEY)
  
  StripHeight = 20
  StripBorder = 2
  
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
        
      Case #PB_Event_SizeWindow
        InvalidateRect_(WindowID(0), 0, 1)
        
      Case #PB_Event_Repaint
        If StartDrawing(WindowOutput(0))
          Box(0, WindowHeight(0) - StripHeight - StripBorder, WindowWidth(0), StripBorder, #Red)
          StopDrawing()
        EndIf
        
    EndSelect
    
  ForEver
EndIf
But I think I'll change that again to smoothly change size of the strip.

Re: Transparent CanvasGadget

Posted: Thu Apr 21, 2022 12:26 pm
by RASHAD
If I understood you correctly
Maybe
It may need more calculations for borders and so

Code: Select all

Procedure sizeCB()
  ResizeWindow(1,WindowX(0)+2, WindowY(0)+WindowHeight(0)+11, WindowWidth(0), 20)
EndProcedure

If OpenWindow(0, 0, 0, 400, 200, "Select your area", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Tool)
  SetWindowColor(0, #Blue)
  SetWindowLong_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED|#WS_EX_TOPMOST)
  SetLayeredWindowAttributes_(WindowID(0), #Blue, 0, #LWA_COLORKEY)
  
  OpenWindow(1, WindowX(0)+2, WindowY(0)+211, 400, 20, "Select your area", #PB_Window_BorderLess,WindowID(0))
  SetWindowColor(1, #Green)
  SetWindowLong_(WindowID(1), #GWL_EXSTYLE, #WS_EX_LAYERED|#WS_EX_TOPMOST)
  SetLayeredWindowAttributes_(WindowID(1), #Green, 100, #LWA_ALPHA)
  
  StripHeight = 20
  StripBorder = 2
  
  BindEvent(#PB_Event_SizeWindow,@sizeCB())
  BindEvent(#PB_Event_MoveWindow,@sizeCB())
  SetActiveWindow(0)
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End       
       
        
    EndSelect
    
  ForEver
EndIf

Re: Transparent CanvasGadget

Posted: Thu Apr 21, 2022 12:49 pm
by ZX80
Good day, master RASHAD.

YES :!: ........ YES :!: ........ YES :!:
You absolutely correctly understood the task. And you did/resolved it very cool.
I assumed that a second window would be required here.

Thank you very much :!:
Perfect/great solution :!:
Virtuoso as usual/always :!:

You once again showed me how to make a quality program :!:
My applause for you :!:

Re: [Solved] Transparent CanvasGadget

Posted: Thu Apr 21, 2022 12:59 pm
by RASHAD
You are very welcome :)

Re: [Solved] Transparent CanvasGadget

Posted: Sat Aug 24, 2024 11:15 am
by DSPread
Hello.

In my search for how to create a window with a transparent background (to overly subtitles on a video) I've I've just come across your code items SetWindowLong_(), SetLayeredWindowAttributes_(), and constants like #GWL_EXSTYLE, #WS_EX_LAYERED, #WS_EX_TOPMOST, and #LWA_COLORKEY.

Your transparency example runs OK on my Win 11 system, but I can't find any reference where these items are defined/explained, which I would like read before using them in my own program.

Could you direct me, please?

Kind regards,

David

Re: [Solved] Transparent CanvasGadget

Posted: Sat Aug 24, 2024 11:52 am
by infratec
All procedures with an underscore at the end are OS API functions.
You have to look at them at the microsoft help:

https://learn.microsoft.com/en-us/windo ... indowlonga

https://learn.microsoft.com/en-us/windo ... attributes

Also the constants are from MS.

Re: [Solved] Transparent CanvasGadget

Posted: Thu Jan 02, 2025 7:29 pm
by DSPread
After a signicant delay (previous post August 2024) I have discovered that PlayMovie automatically renders subtitle files (at least the WEBVTT one I had handy)! I cannot find any documentation, however, and I may find this behaviour unnaceptable (some text I may use will be ready-formatted with one or more specific fonts and font size and are likely to contain a shape or two). Is there a comprehensive reference document for PlayMovie that will cover this, please?

As a follow-up I was originally going to ask about adding subtitles as text or grapohics by overlaying the main material with opaque text and semi-transparent background, so that, unlike chroma keying, white text over a white image region is avoided by a partially transparent black background which reduces the image brightness. This may have already been solved but as a hardware engineer my ability to read non-obvious code is limited...

Kind regards,

David