How to get a global(screen, device) coordinates with CGContext?
I try to make a plugin for browsers in Mac OSX.
I got a CGContext from browser process.
So I ca开发者_JS百科n draw with it.
What I have to do is make a window for event handling someone advise me in this amazing site :)
I can make a transparent window easily but I can move that window proper position.
I know the size of window exactly but I can determine the origin of window.
Only thing I got is CGContextRef.
I tried this.
NSRect rect = [mywindow frame];
CGPoint origin;
origin.x = rect.origin.x;
origin.y = rect.origin.y;
CGPoint globalOrigin = CGContextConvertPointToDeviceSpace(cgContext, origin);
if (globalOrigin.x != origin.x || globalOrigin.y != origin.y) {
NSPoint newPoint;
newPoint.x = globalOrigin.x;
newPoint.y = globalOrigin.y;
[mywindow setFrameOrigin:newPoint];
}
But no luck. It returned the value what I gave it to
Any advice?
Thanks in advance.
The CGContext you get in an NPAPI plugin is not necessarily associated with any window, so it's impossible to map from the CGContext to a location on screen.
smorgan's answer is right.
For someone who maybe need more explanations, I will add my thinking.
I think plugin process has CGContext which doesn't have real os window. because browser process need window but plugin process just transfer drawing data to browser process, so plugin process's CGContext does NOT have location. It might be just memory buffer.
Thanks smorgan.
精彩评论