Shaped Forms in OSX

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Shaped Forms in OSX

Post by wilbert »

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

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)
fromVB
User
User
Posts: 81
Joined: Sun Jul 29, 2012 2:27 am

Re: Shaped Forms in OSX

Post by fromVB »

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
It works great! Thanks! :D

How can I control the form movement like Windows WM_NCHITTEST? Thanks again.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Shaped Forms in OSX

Post by wilbert »

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
Here's a second example using NSBezierPath for antialiased lines

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)
fromVB
User
User
Posts: 81
Joined: Sun Jul 29, 2012 2:27 am

Re: Shaped Forms in OSX

Post by fromVB »

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
WHOA! How do you do that???

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? :?
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Shaped Forms in OSX

Post by luis »

fromVB wrote: Not that I would have the first clue on how to use it, but is there a guide to all these CocoaMessages? :?
https://developer.apple.com/library/mac ... TP40004151

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
fromVB
User
User
Posts: 81
Joined: Sun Jul 29, 2012 2:27 am

Re: Shaped Forms in OSX

Post by fromVB »

luis wrote:
fromVB wrote: Not that I would have the first clue on how to use it, but is there a guide to all these CocoaMessages? :?
https://developer.apple.com/library/mac ... TP40004151

On the developer apple site you should find everything you need, be quick before they deprecate Cocoa too :)
Thanks man.

wilbert you really solved my problem. Thank you.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Shaped Forms in OSX

Post by wilbert »

fromVB wrote:wilbert you really solved my problem. Thank you.
Glad I could help :wink:
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply