Transparent ImageGadget and canvas

Just starting out? Need help? Post your questions and find answers here.
User_Russian
Addict
Addict
Posts: 1535
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Transparent ImageGadget and canvas

Post by User_Russian »

In window ImageGadget is transparent.

Code: Select all

If OpenWindow(0, 0, 0, 520, 520, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, 1234)
  ;CanvasGadget(0, 10, 10, 500, 500, #PB_Canvas_Container)
  ImageGadget(1, 100, 100, 300, 300, 0)
  ;CloseGadgetList()
  
  CreateImage(0, 300, 300, 32, #PB_Image_Transparent)
  LoadFont(0, "Times New Roman", 20)    
  
  If StartVectorDrawing(ImageVectorOutput(0))
    
    Text$ = "Every drawing output has a default unit of measurement. The default unit is pixels " +
            "for screen or raster image outputs and points for printer or vector image outputs. " +
            "It is however possible to select a different unit of measurement for the output when " +
            "creating it with the ImageVectorOutput(), PrinterVectorOutput() or similar function."
    
    VectorFont(FontID(0), 18)
    MovePathCursor(0, 0)
    DrawVectorParagraph(Text$, 300, 300)
    StopVectorDrawing()
  EndIf
    
  SetGadgetState(1, ImageID(0))
  
  Repeat
    Event = WaitWindowEvent()   
  Until Event = #PB_Event_CloseWindow
EndIf
But if you uncomment the lines with CanvasGadget and CloseGadgetList(), in ImageGadget has a background color (no transparency).
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Transparent ImageGadget and canvas

Post by infratec »

In the german help of the CanvasGadget this is documented below the flag #PB_Canvas_Container:
Unter Windows funktioniert die Transparenz der Gadgets nicht ...
User_Russian
Addict
Addict
Posts: 1535
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Transparent ImageGadget and canvas

Post by User_Russian »

If use WinAPI, there is transparency.
That's why I think this is a bug!

Code: Select all

If OpenWindow(0, 0, 0, 520, 520, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, 1234)
  hWnd=CanvasGadget(0, 10, 10, 500, 500)
  ImageGadget(1, 100, 100, 300, 300, 0)
  DisableGadget(1, #True)
  SetParent_(GadgetID(1), hWnd)
  
  SetWindowLongPtr_(hWnd, #GWL_EXSTYLE, GetWindowLongPtr_(hWnd, #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
  
  CreateImage(0, 300, 300, 32, #PB_Image_Transparent)
  LoadFont(0, "Times New Roman", 20)    
  
  If StartVectorDrawing(ImageVectorOutput(0))
    
    Text$ = "Every drawing output has a default unit of measurement. The default unit is pixels " +
            "for screen or raster image outputs and points for printer or vector image outputs. " +
            "It is however possible to select a different unit of measurement for the output when " +
            "creating it with the ImageVectorOutput(), PrinterVectorOutput() or similar function."
    
    VectorFont(FontID(0), 18)
    MovePathCursor(0, 0)
    DrawVectorParagraph(Text$, 300, 300)
    StopVectorDrawing()
  EndIf
    
  SetGadgetState(1, ImageID(0))
  
  Repeat
    Event = WaitWindowEvent()  
    
    If Event = #PB_Event_Gadget And EventGadget() = 0 
      If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
        If StartDrawing(CanvasOutput(0))
          x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
          y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
          Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
          StopDrawing()
        EndIf
      EndIf
    EndIf 
    
  Until Event = #PB_Event_CloseWindow
EndIf
User_Russian
Addict
Addict
Posts: 1535
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Transparent ImageGadget and canvas

Post by User_Russian »

infratec wrote: Sat Jul 13, 2024 3:50 pm In the german help of the CanvasGadget this is documented below the flag #PB_Canvas_Container:
On Windows, the transparency of the gadgets does not work so the text of the following gadgets will be
displayed on an opaque background: CheckBoxGadget, FrameGadget, HyperlinkGadget, OptionGadget, TextGadget and TrackBarGadget.
CheckBoxGadget, FrameGadget and OptionGadget is transparency.

Code: Select all

If OpenWindow(0, 0, 0, 520, 520, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, 1234)

  hWnd=CanvasGadget(0, 10, 10, 500, 500)
  SetParent_(ImageGadget(1, 100, 100, 300, 300, 0), hWnd)
  DisableGadget(1, #True)
  SetParent_(CheckBoxGadget(2, 10, 10, 120, 20, "CheckBoxGadget"), hWnd)
  SetParent_(FrameGadget(3, 200, 10, 100, 100, "FrameGadget"), hWnd)
  SetParent_(HyperLinkGadget(4, 10, 30, 100, 20, "HyperlinkGadget", 1234), hWnd)
  SetParent_(OptionGadget(5, 10, 50, 100, 20, "OptionGadget"), hWnd)
  SetParent_(OptionGadget(6, 200, 50, 100, 20, "OptionGadget"), hWnd)
  SetParent_(TextGadget(7, 10, 80, 100, 20, "TextGadget"), hWnd)
  SetParent_(TrackBarGadget(8, 200, 80, 100, 20, 0, 100), hWnd)
  
  SetWindowLongPtr_(hWnd, #GWL_EXSTYLE, GetWindowLongPtr_(hWnd, #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
  
  CreateImage(0, 300, 300, 32, #PB_Image_Transparent)
  LoadFont(0, "Times New Roman", 20)    
  
  If StartVectorDrawing(ImageVectorOutput(0))
    
    Text$ = "Every drawing output has a default unit of measurement. The default unit is pixels " +
            "for screen or raster image outputs and points for printer or vector image outputs. " +
            "It is however possible to select a different unit of measurement for the output when " +
            "creating it with the ImageVectorOutput(), PrinterVectorOutput() or similar function."
    
    VectorFont(FontID(0), 18)
    MovePathCursor(0, 0)
    DrawVectorParagraph(Text$, 300, 300)
    StopVectorDrawing()
  EndIf
    
  SetGadgetState(1, ImageID(0))
  
  Repeat
    Event = WaitWindowEvent()  
    
    If Event = #PB_Event_Gadget And EventGadget() = 0 
      If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
        If StartDrawing(CanvasOutput(0))
          x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
          y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
          Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
          StopDrawing()
        EndIf
      EndIf
    EndIf 
    
  Until Event = #PB_Event_CloseWindow
EndIf
Post Reply