It is currently Sun Mar 07, 2021 9:05 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Re: Shaped Forms in OSX
PostPosted: Mon Oct 07, 2013 2:08 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3712
Location: Netherlands
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:
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

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Shaped Forms in OSX
PostPosted: Mon Oct 07, 2013 4:10 pm 
Offline
User
User

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Shaped Forms in OSX
PostPosted: Mon Oct 07, 2013 4:40 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3712
Location: Netherlands
Something like this ?
Code:
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:
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

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Shaped Forms in OSX
PostPosted: Mon Oct 07, 2013 4:54 pm 
Offline
User
User

Joined: Sun Jul 29, 2012 2:27 am
Posts: 81
wilbert wrote:
Something like this ?
Code:
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? :?


Top
 Profile  
Reply with quote  
 Post subject: Re: Shaped Forms in OSX
PostPosted: Mon Oct 07, 2013 5:27 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3698
Location: Italy
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 :)

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Shaped Forms in OSX
PostPosted: Tue Oct 08, 2013 3:36 am 
Offline
User
User

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Shaped Forms in OSX
PostPosted: Tue Oct 08, 2013 6:22 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3712
Location: Netherlands
fromVB wrote:
wilbert you really solved my problem. Thank you.

Glad I could help :wink:

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye