How can I flip coordinate of cocoa

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

How can I flip coordinate of cocoa

Post 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?
macOS Catalina 10.15.7
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: How can I flip coordinate of cocoa

Post 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...

I am to provide the public with beneficial shocks.
Alfred Hitshock
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How can I flip coordinate of cocoa

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: How can I flip coordinate of cocoa

Post by Wolfram »

wilbert wrote:Do you only want to flip the y coordinate or both x and y ?
I need to flip Y only
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How can I flip coordinate of cocoa

Post 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 ?
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: How can I flip coordinate of cocoa

Post 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!
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How can I flip coordinate of cocoa

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: How can I flip coordinate of cocoa

Post by Wolfram »

wilbert wrote: Where does it say it is deprecated ?
In my 10.7 DocSet.
Maybe they recant it.
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How can I flip coordinate of cocoa

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply