Thanks for the screenshots, I now understand better the request.
So ObjectTheme is something other than Gnozal's Pureform+Purecolor.
I don't know how it is made by Gnozal but based on netmaestro's second code here
Here's a sample for Static Gadget Transparent Background, to improve.
But apart from writing the background image in hard, I don't know how to retrieve it easily depending on whether it's done with:
ImageGadget+DisableGadget or with GCL_HBRBACKGROUND message or if the parent is a drawn Canvas Container...
Code: Select all
; Static Gadget Transparent Background sample
; Based on NetMaestro's second code here: https://www.purebasic.fr/english/viewtopic.php?p=488045#p488045
EnableExplicit
Enumeration Window
#MainWindow
EndEnumeration
Enumeration Gadgets
#Btn : #Check : #Frame : #Img_Backgound : #Opt_1 : #Opt_2 : #Txt
EndEnumeration
Enumeration Images
#Image_Background
EndEnumeration
Enumeration Fonts
#Font_Broadway_12_B
EndEnumeration
Structure GadgetImages
Image.i
PressedImage.i
Width.i
Height.i
EndStructure
Structure GadgetBrush
IDGadget.i
X.i
Y.i
Width.i
Height.i
BackgroundBrush.i
EndStructure
UsePNGImageDecoder()
CatchImage(#Image_Background, ?Image_Background)
LoadFont(#Font_Broadway_12_B, "Broadway", 12, #PB_Font_Bold)
Declare GetGadgetBackgroundBrush(IDGadget)
Declare WinCallback(hWnd, uMsg, wParam, lParam)
Declare ResizeGadgetImage(Gadget, OriginalImage, OriginalPressedImage = #PB_Ignore)
Declare Resize_MainWindow()
Declare Open_MainWindow(X = 0, Y = 0, Width = 420, Height = 280)
Procedure GetGadgetBackgroundBrush(IDGadget)
Protected Gadget = GetDlgCtrlID_(IDGadget), X = GadgetX(Gadget), Y = GadgetY(Gadget), Width = GadgetWidth(Gadget), Height = GadgetHeight(Gadget)
Protected CopyImage, GrabImage
Static OldBrush.GadgetBrush
If IDGadget <> OldBrush\IDGadget Or X <> OldBrush\X Or Y <> OldBrush\Y Or Width <> OldBrush\Width Or Height <> OldBrush\Height
OldBrush\IDGadget = IDGadget : OldBrush\X = X : OldBrush\Y = Y : OldBrush\Width = Width : OldBrush\Height = Height
If OldBrush\BackgroundBrush
DeleteObject_(OldBrush\BackgroundBrush)
EndIf
If IsImage(#Image_Background) And Width And Height
SetWindowTheme_(IDGadget, "", "")
CopyImage = CopyImage(#Image_Background, #PB_Any)
ResizeImage(CopyImage, DesktopScaledX(GadgetWidth(#Img_Backgound)), DesktopScaledY(GadgetHeight(#Img_Backgound)))
GrabImage = GrabImage(CopyImage, #PB_Any, DesktopScaledX(X), DesktopScaledY(Y), DesktopScaledX(Width), DesktopScaledY(Height))
FreeImage(CopyImage)
OldBrush\BackgroundBrush = CreatePatternBrush_(ImageID(GrabImage))
FreeImage(GrabImage)
Else
OldBrush\BackgroundBrush = GetStockObject_(#NULL_BRUSH)
EndIf
EndIf
ProcedureReturn OldBrush\BackgroundBrush
EndProcedure
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_CTLCOLORSTATIC ; CheckBoxGadget, FrameGadget, OptionGadget, TextGadget, TrackBarGadget
SetTextColor_(wParam, #Cyan)
SetBkMode_(wparam, #TRANSPARENT)
ProcedureReturn GetGadgetBackgroundBrush(lparam)
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure ResizeGadgetImage(Gadget, OriginalImage, OriginalPressedImage = #PB_Ignore)
Protected Image, Width, Height
Static NewMap GadgetImage.GadgetImages()
If IsGadget(Gadget) And IsImage(OriginalImage)
Width = DesktopScaledX(GadgetWidth(Gadget)) : Height = DesktopScaledY(GadgetHeight(Gadget))
If Width > 0 And Height > 0
If GadgetImage(Str(Gadget))\Width <> Width Or GadgetImage(Str(Gadget))\Height <> Height
GadgetImage()\Width = Width : GadgetImage()\Height = Height
Image = CopyImage(OriginalImage, #PB_Any)
If Image
ResizeImage(Image, Width, Height)
Select GadgetType(Gadget)
Case #PB_GadgetType_ButtonImage
SetGadgetAttribute(Gadget, #PB_Button_Image, ImageID(Image))
Case #PB_GadgetType_Image
SetGadgetState(Gadget, ImageID(Image))
EndSelect
If GadgetImage()\Image And IsImage(GadgetImage()\Image)
FreeImage(GadgetImage()\Image)
EndIf
GadgetImage()\Image = Image
EndIf
If GadgetType(Gadget) = #PB_GadgetType_ButtonImage And IsImage(OriginalPressedImage)
Image = CopyImage(OriginalPressedImage, #PB_Any)
If Image
ResizeImage(Image, Width, Height)
SetGadgetAttribute(Gadget, #PB_Button_PressedImage, ImageID(Image))
If GadgetImage()\PressedImage And IsImage(GadgetImage()\PressedImage)
FreeImage(GadgetImage()\PressedImage)
EndIf
GadgetImage()\PressedImage = Image
EndIf
EndIf
EndIf ; If GadgetImage(Str(Gadget))\Width <> Width Or GadgetImage(Str(Gadget))\Height <> Height
EndIf ; If Width > 0 And Height > 0
EndIf ; If IsGadget(Gadget) And IsImage(OriginalImage)
EndProcedure
Procedure Resize_MainWindow()
Protected MainWindow_WidthIni = 420, MainWindow_HeightIni = 280
Protected ScaleX.f, ScaleY.f
ScaleX = WindowWidth(#MainWindow) / MainWindow_WidthIni : ScaleY = WindowHeight(#MainWindow) / MainWindow_HeightIni
ResizeGadget(#Check, ScaleX * 20, ScaleY * 20, ScaleX * 160, ScaleY * 22)
ResizeGadget(#Frame, ScaleX * 20, ScaleY * 60, ScaleX * 360, ScaleY * 70)
ResizeGadget(#Opt_1, ScaleX * 30, ScaleY * 90, ScaleX * 160, ScaleY * 22)
ResizeGadget(#Opt_2, ScaleX * 210, ScaleY * 90, ScaleX * 160, ScaleY * 22)
ResizeGadget(#Txt, ScaleX * 20, ScaleY * 150, ScaleX * 160, ScaleY * 22)
ResizeGadget(#Btn, ScaleX * 20, ScaleY * 200, ScaleX * 380, ScaleY * 50)
ResizeGadget(#Img_Backgound, 0, 0, WindowWidth(#MainWindow), WindowHeight(#MainWindow))
ResizeGadgetImage(#Img_Backgound, #Image_Background)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows : RedrawWindow_(WindowID(#MainWindow), #Null, #Null, #RDW_INVALIDATE | #RDW_ERASE | #RDW_ALLCHILDREN | #RDW_UPDATENOW) : CompilerEndIf
EndProcedure
Procedure Open_MainWindow(X = 0, Y = 0, Width = 420, Height = 280)
If OpenWindow(#MainWindow, X, Y, Width, Height, "Title", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
SetGadgetFont(#PB_Default, FontID(#Font_Broadway_12_B))
;Protected BrushWindowBackground = CreatePatternBrush_(ImageID(#Image_Background)) : SetClassLongPtr_(WindowID(#MainWindow), #GCL_HBRBACKGROUND, BrushWindowBackground)
ImageGadget(#Img_Backgound, 0, 0, 420, 280, ImageID(#Image_Background)) : DisableGadget(#Img_Backgound, #True)
CheckBoxGadget(#Check, 20, 20, 160, 22, "CheckBox")
FrameGadget(#Frame, 20, 60, 360, 70, "Frame")
OptionGadget(#Opt_1, 30, 90, 160, 22, "Option_1")
OptionGadget(#Opt_2, 210, 90, 160, 22, "Option_2")
TextGadget(#Txt, 20, 150, 160, 22, "Text_blablabla")
ButtonGadget(#Btn, 20, 200, 380, 50, "Button")
SetWindowCallback(@WinCallback(), #MainWindow)
BindEvent(#PB_Event_SizeWindow, @Resize_MainWindow(), #MainWindow)
PostEvent(#PB_Event_SizeWindow, #MainWindow, 0)
ProcedureReturn #True
EndIf
EndProcedure
If Open_MainWindow()
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
DataSection
Image_Background: : IncludeBinary #PB_Compiler_Home + "Examples\3D\Data\Water\Foam.png"
EndDataSection