야간 Webkit 빌드의 NetscapeCocoaPlugin 예제를 따라했으며 Cocoa Event Model을 사용하는 NPAPI 스타일 플러그인을 만들 수 있습니다.코코아 이벤트 모델 NPAPI 플러그인에서 NSView를 얻는 방법
이제 내 질문에 NPP_SetWindow 내부에서 NSView를 얻을 수 있습니다.
이 thread의 포스터, 그것은 [NSView의 focusView]을 사용 가능 말한다, 그러나 나는 이것이 나의 현재 기능은 다음과 같습니다
작동시킬 수 없었다 :
NPError NPP_SetWindow(NPP instance, NPWindow* window)
{
PluginObject *obj = instance->pdata;
obj->window = *window;
NSLog(@"Set Window called");
NSView* currentView = [NSView focusView];
[[NSColor redColor] set]; // Sets current drawing color.
NSRectFill(NSMakeRect(10, 10, 2, 20)); // Defines a rectangle and then fills it with the current drawing color.
[[NSColor colorWithCalibratedRed:0.7 green:0.9 blue:0.3 alpha:1.0] set]; // Sets a new color.
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(5, 0, 10, 10)] fill]; // Draws a circle in the new color.
[currentView setNeedsDisplay:YES];
return NPERR_NO_ERROR;
}
아, 재미! CGContextRef를 얻고 싶다면 다음과 같이 호출하면됩니다 : NP_CGContext * npContext = (NP_CGContext *) window-> window; npContext-> context? – CambridgeMike
그것은 많은 것들에 달려 있습니다. 먼저 CoreGraphics를 드로잉 모델로 선택해야합니다 (https://wiki.mozilla.org/NPAPI:Models 및 https://wiki.mozilla.org/NPAPI:CoreGraphicsDrawing). 그렇다면 아마도 효과가있는 Carbon 이벤트 모델을 협상했지만 Cocoa (https://wiki.mozilla.org/NPAPI:CocoaEventModel 참조)를 사용하는 경우 CGContextRef를 저장할 수는 없지만 이벤트 데이터는 NPAPI에서 CocoaEvent를 얻을 때마다 표시됩니다. 이러한 링크는 귀하를 시작 시키거나 새로운 질문을 공식화하는 데 도움이됩니다. – taxilian
답변 인 경우 해당 표시로하시기 바랍니다. – taxilian