Page 1 of 1

How can I flip coordinate of cocoa

Posted: Mon Nov 13, 2017 9:02 pm
by Wolfram
Hi,

is there a way to flip the coordinate on a cocoa window, to have the start point in the upper right corner instead of lower corner?

Re: How can I flip coordinate of cocoa

Posted: Mon Nov 13, 2017 9:42 pm
by fsw
Never tried it, but as far as I know you have to change the origin of the window's view with setBoundsOrigin.
However, if you place ui children based from the new 0,0 location they will be invisible if you use positive numbers.
This is because they are placed in the quadrant that is outside the window.
Bottom line: all ui children need to be placed with negative coordinates in order to be visible.

Hope I'm not too far off with my assumption...

Re: How can I flip coordinate of cocoa

Posted: Tue Nov 14, 2017 7:39 am
by wilbert
Do you only want to flip the y coordinate or both x and y ?

To do both, you could rotate things

Code: Select all

If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
    ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
    ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
    ButtonGadget(3, 10,100, 200, 60, "Multiline Button  (longer text gets automatically wrapped)", #PB_Button_MultiLine)
    ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
    
    ContentView = CocoaMessage(0, WindowID(0), "contentView")
    
    Rotation.CGFloat = 180
    CocoaMessage(0, ContentView, "setBoundsRotation:@", @Rotation)
    
    Origin.CGPoint\x = WindowWidth(0)
    Origin\y = WindowHeight(0)
    CocoaMessage(0, ContentView, "setBoundsOrigin:@", @Origin)    
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Re: How can I flip coordinate of cocoa

Posted: Tue Nov 14, 2017 9:38 pm
by Wolfram
wilbert wrote:Do you only want to flip the y coordinate or both x and y ?
I need to flip Y only

Re: How can I flip coordinate of cocoa

Posted: Wed Nov 15, 2017 7:30 am
by wilbert
The NSView class has a method named isFlipped
You can overwrite this method and return #True .
Is that what you are looking for ?

Re: How can I flip coordinate of cocoa

Posted: Wed Nov 15, 2017 10:43 am
by Wolfram
wilbert wrote:The NSView class has a method named isFlipped
You can overwrite this method and return #True .
Is that what you are looking for ?
Hi Wilbert,

isFliped is Deprecated since 10.6 maybe drawInRect:fromRect:operation:fraction:respectFlipped:hints: is the better way.
I will try it in a few days.

Thanks!

Re: How can I flip coordinate of cocoa

Posted: Wed Nov 15, 2017 10:55 am
by wilbert
Wolfram wrote:isFliped is Deprecated since 10.6
Where does it say it is deprecated ?
The Apple docs don't seem to mention that :?
https://developer.apple.com/documentati ... -isflipped

Re: How can I flip coordinate of cocoa

Posted: Wed Nov 15, 2017 4:34 pm
by Wolfram
wilbert wrote: Where does it say it is deprecated ?
In my 10.7 DocSet.
Maybe they recant it.

Re: How can I flip coordinate of cocoa

Posted: Wed Nov 15, 2017 4:52 pm
by wilbert
Wolfram wrote:
wilbert wrote: Where does it say it is deprecated ?
In my 10.7 DocSet.
Maybe they recant it.
Are you sure you didn’t look at NSImage instead of NSView ?
For NSImage isFlipped is marked deprecated.