
Shaped Forms in OSX
Shaped Forms in OSX
I searched the forum but there were no results for this. Is it possible to get shaped forms or shaped windows on a Mac? Transparency? Thank you for any answers and of course examples too. 

Re: Shaped Forms in OSX
I found this native example on the web but have no idea how to adapt it to PB. Can it also work with other shapes or only round shapes?
http://www.cocoawithlove.com/2008/12/dr ... -os-x.html
Thank you for your help.
http://www.cocoawithlove.com/2008/12/dr ... -os-x.html
Thank you for your help.
Re: Shaped Forms in OSX
The example you mention creates a custom class.
It's too complicated.
I suggest making a PB window transparent and place an image to indicate the basic shape
It's too complicated.
I suggest making a PB window transparent and place an image to indicate the basic shape
Code: Select all
CreateImage(0, 300, 200, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
RoundBox(0, 0, 300, 200, 30, 30, RGBA(160, 160, 160, 255))
StopDrawing()
If OpenWindow(0, 0, 0, 300, 200, "PureBasic Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_Invisible)
CocoaMessage(0, WindowID(0), "setOpaque:", #NO)
CocoaMessage(0, WindowID(0), "setBackgroundColor:", CocoaMessage(0, 0, "NSColor clearColor"))
HideWindow(0, #False)
ImageGadget(0, 0, 0, 300, 200, ImageID(0))
ButtonGadget(1, 10, 10, 100, 30, "Quit")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 1
Break
EndIf
ForEver
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Shaped Forms in OSX
It works great! Thanks!wilbert wrote:The example you mention creates a custom class.
It's too complicated.
I suggest making a PB window transparent and place an image to indicate the basic shape

How can I control the form movement like Windows WM_NCHITTEST? Thanks again.
Re: Shaped Forms in OSX
Something like this ?
Here's a second example using NSBezierPath for antialiased lines
Code: Select all
EnableExplicit
Define Window0ID, Event
CreateImage(0, 300, 200, 32, #PB_Image_Transparent)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
RoundBox(0, 0, 300, 200, 30, 30, RGBA(160, 160, 160, 255))
StopDrawing()
If OpenWindow(0, 0, 0, 300, 200, "PureBasic Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_Invisible)
Window0ID = WindowID(0)
CocoaMessage(0, Window0ID, "setOpaque:", #NO)
CocoaMessage(0, Window0ID, "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID(0)))
CocoaMessage(0, Window0ID, "setMovableByWindowBackground:", #YES)
CocoaMessage(0, Window0ID, "setHasShadow:", #YES)
HideWindow(0, #False)
ButtonGadget(0, 10, 10, 100, 30, "Quit")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Break
EndIf
ForEver
EndIf
Code: Select all
EnableExplicit
Define.i ImageID, Path, Color, Window0ID, Event, Rect.NSRect
Rect\size\width = 300
Rect\size\height = 200
ImageID = CocoaMessage(0, CocoaMessage(0, 0, "NSImage alloc"), "initWithSize:@", @Rect\size)
CocoaMessage(0, ImageID, "lockFocus")
Path = CocoaMessage(0, 0, "NSBezierPath bezierPathWithOvalInRect:@", @Rect)
Color = CocoaMessage(0, 0, "NSColor windowBackgroundColor")
CocoaMessage(0, Color, "setFill")
CocoaMessage(0, Path, "fill")
CocoaMessage(0, ImageID, "unlockFocus")
If OpenWindow(0, 0, 0, 300, 200, "PureBasic Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_Invisible)
Window0ID = WindowID(0)
CocoaMessage(0, Window0ID, "setOpaque:", #NO)
CocoaMessage(0, Window0ID, "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID))
CocoaMessage(0, Window0ID, "setMovableByWindowBackground:", #YES)
CocoaMessage(0, Window0ID, "setHasShadow:", #YES)
HideWindow(0, #False)
ButtonGadget(0, 80, 80, 100, 30, "Quit")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Break
EndIf
ForEver
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Shaped Forms in OSX
WHOA! How do you do that???wilbert wrote:Something like this ?Code: Select all
EnableExplicit Define Window0ID, Event CreateImage(0, 300, 200, 32, #PB_Image_Transparent) StartDrawing(ImageOutput(0)) DrawingMode(#PB_2DDrawing_AllChannels) RoundBox(0, 0, 300, 200, 30, 30, RGBA(160, 160, 160, 255)) StopDrawing() If OpenWindow(0, 0, 0, 300, 200, "PureBasic Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_Invisible) Window0ID = WindowID(0) CocoaMessage(0, Window0ID, "setOpaque:", #NO) CocoaMessage(0, Window0ID, "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", ImageID(0))) CocoaMessage(0, Window0ID, "setMovableByWindowBackground:", #YES) CocoaMessage(0, Window0ID, "setHasShadow:", #YES) HideWindow(0, #False) ButtonGadget(0, 10, 10, 100, 30, "Quit") Repeat Event = WaitWindowEvent() If Event = #PB_Event_Gadget And EventGadget() = 0 Break EndIf ForEver EndIf
Thank you very much.
Not that I would have the first clue on how to use it, but is there a guide to all these CocoaMessages?

Re: Shaped Forms in OSX
https://developer.apple.com/library/mac ... TP40004151fromVB wrote: Not that I would have the first clue on how to use it, but is there a guide to all these CocoaMessages?
On the developer apple site you should find everything you need, be quick before they deprecate Cocoa too

"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: Shaped Forms in OSX
Thanks man.luis wrote:https://developer.apple.com/library/mac ... TP40004151fromVB wrote: Not that I would have the first clue on how to use it, but is there a guide to all these CocoaMessages?
On the developer apple site you should find everything you need, be quick before they deprecate Cocoa too
wilbert you really solved my problem. Thank you.
Re: Shaped Forms in OSX
Glad I could helpfromVB wrote:wilbert you really solved my problem. Thank you.

Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)