Paste number 2717: CGSSetWindowWarp example

Index of paste annotations: 1

Paste number 2717: CGSSetWindowWarp example
Pasted by: xmath
When:4 years, 9 months ago
Share:Tweet this! | http://paste.lisp.org/+23H
Channel:#macdev
Paste contents:
Raw Source | XML | Display As
// 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;
}

Annotations for this paste:

Annotation number 1: Have a Makefile...
Pasted by: rw-rw-rw-
When:3 years, 2 weeks ago
Share:Tweet this! | http://paste.lisp.org/+23H#1
Paste contents:
Raw Source | Display As
TARGET=warp
INCLUDES=
OBJS=$(TARGET).o
LDFLAGS=-framework Carbon

$(TARGET): $(OBJS)
        gcc -o $(TARGET) $? $(LDFLAGS)

$(OBJS): Makefile $(INCLUDES)

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.