Page 1 of 1

Shaped Forms in OSX

Posted: Mon Oct 07, 2013 5:08 am
by fromVB
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. :D

Re: Shaped Forms in OSX

Posted: Mon Oct 07, 2013 1:26 pm
by fromVB
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.

Re: Shaped Forms in OSX

Posted: Mon Oct 07, 2013 2:08 pm
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

Re: Shaped Forms in OSX

Posted: Mon Oct 07, 2013 4:10 pm
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.

Re: Shaped Forms in OSX

Posted: Mon Oct 07, 2013 4:40 pm
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

Re: Shaped Forms in OSX

Posted: Mon Oct 07, 2013 4:54 pm
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? :?

Re: Shaped Forms in OSX

Posted: Mon Oct 07, 2013 5:27 pm
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 :)

Re: Shaped Forms in OSX

Posted: Tue Oct 08, 2013 3:36 am
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.

Re: Shaped Forms in OSX

Posted: Tue Oct 08, 2013 6:22 am
by wilbert
fromVB wrote:wilbert you really solved my problem. Thank you.
Glad I could help :wink: