OS X and Fullscreen?

Okay, lets have a little crash course then…

Looking at the API for NSCursor, there are a couple of methods under the heading “Initalizing a new cursor”. I’ll pick the easier to the two to get started.

Now at the very beginning is “-”, this indicates to us that this function is a ‘instance’ function (if it has a “+” it’s a class function or a shared method in Xojo terms), so we need to create an instance of NSCursor object first. A NSObject is just a pointer to some memory somewhere, and this can easily be done in Xojo.

So to create a NSObject (as this function doesn’t create one for us), we’ll have to allocate a block of memory and declare it’s type to be NSCursor.

[code] const AppKit = “AppKit.framework”
const NSCursor = “NSCursor”

// – Create a NSCursor object.
declare function NSClassFromString lib AppKit (aClassName as CFStringRef) as Ptr
declare function alloc lib AppKit selector “alloc” (classRef as Ptr) as Ptr

Dim newCursor as Ptr = alloc( NSClassFromString( NSCursor ) )[/code]

Now we have an allocated block of memory we can use as a NSCursor. Let’s take another look at the method. With C, it declares it’s return type first. Here you can see ID, which in Xojo terms is also just a pointer, this will be our initialized NSCursor. Then after ‘initWithImage:’ it declares a NSImage (which you can use MacOSLib, MBS or Retina Kit for), then the last parameter is ‘hotSpot’ which is a NSPoint. NSPoint is simple a data structure. Lets add it to our project. Add a structure and name is NSPoint, then add X as single and Y as single to the structure.

Below I’ve set up the variables I want to pass to the method (I’m using the Retina Kit to get a NSImage).

[code] Dim cursorPoint as NSPoint
cursorPoint.x = 3
cursorPoint.y = 3 // Please note that with Objective-C, it’s bottom-up, not top-down like Xojo.

Dim image as HIDPiPicture = HIDPIPicture.imageNamed( NSImageName.TrashEmpty )[/code]

Now we’ll write our function.

declare function initWithImage lib AppKit selector "initWithImage:hotSpot:" ( NSCursorRef as Ptr, newImage as Ptr, aPoint as NSPoint ) as Ptr newCursor = initWithImage( newCursor, image.NSImageRef, cursorPoint )

If you run it now, nothing will happen, but it shouldn’t crash (which is a very good sign!). We need to add the function to make it the current cursor. Which is [quote]- (void)set[/quote]Looking at the code, you can see it’s an instance function, the first item (void) means it returns nothing, so it’s a subroutine.

// - (void)set declare sub set lib AppKit selector "set" ( NSCursorRef as Ptr ) set( newCursor )

The complete code listing is as follows.

[code] const AppKit = “AppKit.framework”
const NSCursor = “NSCursor”

// – Create a NSCursor object.
declare function NSClassFromString lib AppKit (aClassName as CFStringRef) as Ptr
declare function alloc lib AppKit selector “alloc” (classRef as Ptr) as Ptr

Dim newCursor as Ptr = alloc( NSClassFromString( NSCursor ) )

Dim cursorPoint as NSPoint
cursorPoint.x = 3
cursorPoint.y = 3 // Please note that with Objective-C, it’s bottom-up, not top-down like Xojo.

Dim image as HIDPiPicture = HIDPIPicture.imageNamed( NSImageName.TrashEmpty )

// - (id)initWithImage:(NSImage *)newImage hotSpot:(NSPoint)aPoint
declare function initWithImage lib AppKit selector “initWithImage:hotSpot:” ( NSCursorRef as Ptr, newImage as Ptr, aPoint as NSPoint ) as Ptr
newCursor = initWithImage( newCursor, image.NSImageRef, cursorPoint )

// - (void)set
declare sub set lib AppKit selector “set” ( NSCursorRef as Ptr )
set( newCursor )[/code]
If I put this code in a push button (with the structure and the Retina Kit loaded), I end up with replacing my cursor with the full trashcan. Which is not actually that helpful to me!

Sam, how can I thank you enough for your patient teaching. Now I have to digest all that precious tutoring :slight_smile: