에서 cgContext를 가져옵니다. basic-plugin을 기반으로 Mac 용 NPPI 웹 플러그인에 PNG를 그리려고합니다.NPAPI drawPlugin NPP 인스턴스
NPCocoaEventMouseDown
에 플러그인을 다시 그리기를 원하지만 cgContextRef
을 검색하고 있습니다.
아래의 방법은 NPCocoaEventDrawRect
에서 작동하지만 NPCocoaEventMouseDown
에서는 그렇지 않습니다. event->data.draw.context
을 사용할 수 없기 때문입니다. 나는
CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window
으로 cgContextRef
을 검색하려고 시도했지만 작동하지 않는 것 같습니다. 여기 제 기능입니다 :
void drawPlugin(NPP instance, NPCocoaEvent* event)
{
char* path = "/shot.png";
if(!instance || !event)
return;
PluginInstance* currentInstance = (PluginInstance*)(instance->pdata);
//CGContextRef cgContext = event->data.draw.context; //works with DrawRect
CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window;
if (!cgContext) {
return;
}
float windowWidth = currentInstance->window.width;
float windowHeight = currentInstance->window.height;
CGContextSaveGState(cgContext);
//.....
CGContextRestoreGState(cgContext);
}
는 그리고 기능은 여기에 호출됩니다
int16_t NPP_HandleEvent(NPP instance, void* event)
{
NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
if (cocoaEvent && (cocoaEvent->type == NPCocoaEventDrawRect)) {
return 1;
}
if(cocoaEvent)
{
switch (cocoaEvent->type) {
case NPCocoaEventDrawRect:
drawPlugin(instance, (NPCocoaEvent*)event);
break;
case NPCocoaEventMouseDown:
drawPlugin(instance, (NPCocoaEvent*)event);
break;
default:
break;
}
return 1;
}
return 0;
}
가 어떻게이 NPCocoaEventMouseDown
에서 cgContextRef
를 검색 할 수 있습니다?
smorgan이 오인 되 었는지 궁금한 경우가 있습니다. 당신은 윈도우가없는 플러그인에서 지시를 받았을 때만 그리기위한 것이고, mac의 coregraphics는 자격이 있습니다. 오래된 Carbon 구현으로도 언제든지 그릴 수 있기를 원하지 않았습니다. 단지 조금 더 나은 결과가 나온 것입니다. FireBreath (http://firebreath.org)는 이에 대한 탁월한 추상화를 제공합니다. 당신은 mousedown 이벤트에서 NPN_InvalidateRect를 호출하여 드로우 이벤트를 요청할 수 있습니다. – taxilian
smorgan과 Taxilian에게 감사드립니다. 나는 웹 플러그인을 개발하는 것에 익숙하지 않으며 때로는 참고 문헌과 문서가 완전히 명확하지 않아서이 대답이 나를 도와 준다. –
새로운 질문, 어디서 어떻게 NPN_InvalidateRect를 호출 할 수 있습니까? –