2011-10-11 1 views
1

에서 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를 검색 할 수 있습니다?

답변

1

내가이 NPCocoaEventMouseDown에서 cgContextRef을 검색 할 수있는 방법 NPCocoaEventMouseDown

에 플러그인을 다시 그리기 하시겠습니까?

이러한 작업을 수행 할 수 없습니다. 마우스 다운 핸들러에서 NPN_InvalidateRect를 호출하고 드로 콜백을 기다립니다.

나는

window.window

CGContextRef cgContext = (NP_CGContext *) currentInstance->로 cgContextRef를 검색하려하지만 그건 작동하지 않았다.

이 필드는 Cocoa 이벤트 모델에 설명 된대로 Cocoa 이벤트 모델에서 항상 NULL이기 때문에이 필드는 항상 NULL입니다. 페인트 호출 중에 명시 적으로 CGContextRef 만 제공되며 해당 호출 기간 동안 만 유효해야합니다. (나중에 사용하기 위해 캐싱을 고려하고있는 경우 : 결과가 완전히 정의되지 않은 동작이거나, 작동하지 않을 것이며, 확실하게 작동하지 않을 수 있으며, 어떤 시점에서는 거의 확실하게 충돌을 일으킬 것입니다 일부 브라우저에서는.

+0

smorgan이 오인 되 었는지 궁금한 경우가 있습니다. 당신은 윈도우가없는 플러그인에서 지시를 받았을 때만 그리기위한 것이고, mac의 coregraphics는 자격이 있습니다. 오래된 Carbon 구현으로도 언제든지 그릴 수 있기를 원하지 않았습니다. 단지 조금 더 나은 결과가 나온 것입니다. FireBreath (http://firebreath.org)는 이에 대한 탁월한 추상화를 제공합니다. 당신은 mousedown 이벤트에서 NPN_InvalidateRect를 호출하여 드로우 이벤트를 요청할 수 있습니다. – taxilian

+0

smorgan과 Taxilian에게 감사드립니다. 나는 웹 플러그인을 개발하는 것에 익숙하지 않으며 때로는 참고 문헌과 문서가 완전히 명확하지 않아서이 대답이 나를 도와 준다. –

+0

새로운 질문, 어디서 어떻게 NPN_InvalidateRect를 호출 할 수 있습니까? –