I’d like to use the function NSDrawThreePartImage (Application Kit Functions Reference) in my MonoMac application. However, it’s not available to me.
Looking at the source for NSCell.cs, I can see it’s commented out:
//APPKIT_EXTERN void NSDrawThreePartImage(NSRect frame, NSImage *startCap, NSImage *centerFill, NSImage *endCap, BOOL vertical, NSCompositingOperation op, CGFloat alphaFraction, BOOL flipped);
I would guess this just means, it was never implemented.
I understand it’s a C API. What could be involved in manually calling this method? It looks like it could be done with a Pinvoke (Binding Objective-C Types). Can someone confirm that’s the right approach?
Secondly, I’m unfamiliar with how to go about this since the method parameters are not simply primitives. Perhaps there is a good guide for doing this, or some existing examples I can refer to ?
Thanks
Since it’s a C API, you can simply use P/Invoke to bind it.
Regarding the complex types:
NSRectbecomesRectangleF– seeNSGraphics.RectClipin monomac/src/AppKit/NSGraphics.cs for an example.NSImage *becomesIntPtr– use the constructor that takes anIntPtrto construct it its theHandleproperty to get the address.GCFloatis simply afloat.BOOLisbool(seeNSGraphics.BestDepthfor an example).intfor theNSCompositingOperationenum.So, putting the pieces together, something like this should do it:
NSDrawNinePartImageshould work in a similar way.No idea why it’s commented out, most likely it just never got implemented. There are more missing pieces. Let me know whether it works for you and I’ll add it to NSCell.cs for you.
Edit:
I just added this to NSCell.cs: https://github.com/mono/monomac/commit/7c60d5756c49331642d2348c7c83320b9ec3f549.
Thanks a lot for testing this!