BTW, the background image for container gadget has also a problem when the window
is resize-able.
I wanted to set a pattern image as window background:
Code: Select all
Procedure SetWindowBackgroundPattern(win,imageID)
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
CocoaMessage(@color,0,"NSColor colorWithPatternImage:",imageID)
If color
CocoaMessage(0,WindowID(win),"setBackgroundColor:",color) ; note: pattern begins at the bottom
CocoaMessage(0,WindowID(win),"update") ; of the window (not good with
ProcedureReturn color ; resize-able windows)
EndIf
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
brush = CreatePatternBrush_(imageID)
If brush
SetClassLongPtr_(WindowID(win),#GCL_HBRBACKGROUND,brush)
InvalidateRect_(WindowID(win),0,#True)
UpdateWindow_(WindowID(win))
ProcedureReturn brush
EndIf
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
CompilerElse
CompilerError "Unknown Platform for SetWindowBackgroundImage()"
CompilerEndIf
EndProcedure
CreateImage(1,25,25,24)
If StartDrawing(ImageOutput(1))
Box(0,0,OutputWidth() ,OutputHeight() ,RGB(0,0,0))
Box(2,2,OutputWidth()-4,OutputHeight()-4,RGB(64,64,64))
StopDrawing()
EndIf
CreateImage(2,50,50,24)
If StartDrawing(ImageOutput(2))
For i = 0 To 50 Step 10
Box(0,i ,OutputWidth(),5,RGB(180,180,180))
Box(0,i+5,OutputWidth(),5,RGB(192,192,192))
Next i
StopDrawing()
EndIf
CreateImage(3,10,10,24)
If StartDrawing(ImageOutput(3))
Box(0,0,OutputWidth(),OutputHeight(),RGB(192,192,192))
Box(OutputWidth()-2,OutputHeight()-2,2,2,RGB(64,64,64))
StopDrawing()
EndIf
If OpenWindow(1,0,0,800,600,"Window Background Image",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetWindowBackgroundPattern(1,ImageID(3))
For i = 1 To 10
ButtonGadget(#PB_Any, 25, 10+i*30, 150, 25, "Button "+Str(i))
Next i
OpenWindow(2,WindowX(1)+WindowWidth(1)-100,WindowY(1)+100,200,150,"Tool Window 1",#PB_Window_Tool|#PB_Window_SizeGadget|#PB_Window_Invisible,WindowID(1))
SetWindowBackgroundPattern(2,ImageID(2))
ButtonGadget(#PB_Any,10,10,180,25,"Button")
OpenWindow(3,WindowX(1)+WindowWidth(1)-150,WindowY(1)+300,300,150,"Tool Window 2",#PB_Window_Tool|#PB_Window_SizeGadget|#PB_Window_Invisible,WindowID(1))
SetWindowBackgroundPattern(3,ImageID(1))
ButtonGadget(#PB_Any,10,10,180,25,"Button")
HideWindow(1,0)
HideWindow(2,0)
HideWindow(3,0)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Works fine with fixed size windows, but on MacOSX the background is scrolling
when you resize the window. It happens because the pattern drawing begins
at the bottom of the window.
Thought now using a container could fix this, but it doesn't. Even more weird,
the container background pattern scrolls just by resizing the window, not
the container itself!
Code: Select all
Procedure SetContainerBackgroundPattern(containerGadget,imageID)
CocoaMessage(@color,0,"NSColor colorWithPatternImage:",imageID)
If color
CocoaMessage(0,GadgetID(containerGadget),"setFillColor:",color)
ProcedureReturn color
EndIf
EndProcedure
CreateImage(1,25,25,24)
If StartDrawing(ImageOutput(1))
Box(0,0,OutputWidth() ,OutputHeight() ,RGB(0,0,0))
Box(2,2,OutputWidth()-4,OutputHeight()-4,RGB(64,64,64))
StopDrawing()
EndIf
CreateImage(2,50,50,24)
If StartDrawing(ImageOutput(2))
For i = 0 To 50 Step 10
Box(0,i ,OutputWidth(),5,RGB(180,180,180))
Box(0,i+5,OutputWidth(),5,RGB(192,192,192))
Next i
StopDrawing()
EndIf
CreateImage(3,10,10,24)
If StartDrawing(ImageOutput(3))
Box(0,0,OutputWidth(),OutputHeight(),RGB(192,192,192))
Box(OutputWidth()-2,OutputHeight()-2,2,2,RGB(64,64,64))
StopDrawing()
EndIf
If OpenWindow(1,0,0,800,600,"Window Background Image",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
c1 = ContainerGadget(#PB_Any,0,0,800,600)
SetContainerBackgroundPattern(c1,ImageID(3))
For i = 1 To 10
ButtonGadget(#PB_Any, 25, 10+i*30, 150, 25, "Button "+Str(i))
Next i
OpenWindow(2,WindowX(1)+WindowWidth(1)-100,WindowY(1)+100,200,150,"Tool Window 1",#PB_Window_Tool|#PB_Window_SizeGadget|#PB_Window_Invisible,WindowID(1))
c2 = ContainerGadget(#PB_Any,0,0,200,150)
SetContainerBackgroundPattern(c2,ImageID(2))
ButtonGadget(#PB_Any,10,10,180,25,"Button")
OpenWindow(3,WindowX(1)+WindowWidth(1)-150,WindowY(1)+300,300,150,"Tool Window 2",#PB_Window_Tool|#PB_Window_SizeGadget|#PB_Window_Invisible,WindowID(1))
c3 = ContainerGadget(#PB_Any,0,0,300,150)
SetContainerBackgroundPattern(c3,ImageID(1))
ButtonGadget(#PB_Any,10,10,180,25,"Button")
HideWindow(1,0)
HideWindow(2,0)
HideWindow(3,0)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Nice for fixed windows, but for resize-able windows this is not useable as is.