// save as: warp.c
// compile with: gcc -Wall -o warp warp.c -framework Carbon
#include <Carbon/Carbon.h>
OSErr CPSEnableForegroundOperation(ProcessSerialNumber *psn);
typedef struct CGPointWarp CGPointWarp;
struct CGPointWarp {
CGPoint local;
CGPoint global;
};
typedef int CGSWindowID;
typedef void *CGSConnectionID;
extern CGSConnectionID _CGSDefaultConnection(void);
extern CGSWindowID GetNativeWindowFromWindowRef(WindowRef);
extern CGError CGSSetWindowWarp(CGSConnectionID, CGSWindowID, int w, int h,
CGPointWarp mesh[h][w]);
#define W 2
#define H 5
int main() {
ProcessSerialNumber psn;
WindowRef w;
Rect r = { 100, 100, 300, 350 };
CGPointWarp mesh[H][W] = {
{ {{0, 0},{100,100}}, {{250, 0},{350,100}} },
{ {{0, 50},{100,150}}, {{250, 50},{330,150}} },
{ {{0,100},{120,200}}, {{250,100},{320,200}} },
{ {{0,150},{ 90,250}}, {{250,150},{360,250}} },
{ {{0,200},{100,300}}, {{250,200},{350,300}} },
};
#if 1 /* omit this if using XCode */
GetCurrentProcess(&psn);
CPSEnableForegroundOperation(&psn);
SetFrontProcess(&psn);
#endif
CreateNewWindow(kDocumentWindowClass, kWindowMetalAttribute
| kWindowCompositingAttribute
| kWindowStandardHandlerAttribute
| kWindowLiveResizeAttribute
| kWindowStandardDocumentAttributes, &r, &w);
ShowWindow(w);
CGSSetWindowWarp(_CGSDefaultConnection(),
GetNativeWindowFromWindowRef(w), W, H, mesh);
RunApplicationEventLoop();
return 0;
}