NPAPI drawPlugin 从 NPP 实例检索 cgContext

发布于 2024-12-09 09:21:03 字数 1979 浏览 0 评论 0原文

我尝试在基于 basic-plugin

我想在 NPCocoaEventMouseDown 上重绘插件,但我需要检索 cgContextRef

下面的方法适用于 NPCocoaEventDrawRect 但不适用于 NPCocoaEventMouseDown 因为这样我就无法使用 event->data.draw.context >。我尝试检索 cgContextRef



    CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window


但似乎不起作用。这是我的函数:



    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

Im trying to draw a png in my (NPAPI)webplugin for Mac based on basic-plugin.

I would like to redraw the plugin on a NPCocoaEventMouseDown but I'm having trouwens to retrieve the cgContextRef.

The methode below works for the NPCocoaEventDrawRect but doesn't for the NPCocoaEventMouseDown because then I can't use event->data.draw.context. I tried to retrieve the cgContextRef with



    CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window


but that didn't seem to work. Here's my function:



    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);
    }

And the function is called here:



    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;
    }

How can I retrieve the cgContextRef in a NPCocoaEventMouseDown?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

另类 2024-12-16 09:21:04

我想在 NPCocoaEventMouseDown 上重绘插件

如何在 NPCocoaEventMouseDown 中检索 cgContextRef?

这两件事你都不能做。您在鼠标按下处理程序中调用 NPN_InvalidateRect,然后等待绘制回调。

我尝试使用

检索cgContextRef

CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window

但这似乎不起作用。

因为该字段在 Cocoa 事件模型下始终为 NULL,如 Cocoa 事件规范中所述。仅在绘制调用期间明确向您提供 CGContextRef,并且仅要求它在该调用期间有效。 (如果您正在考虑缓存它以供以后使用:不要这样做。结果将是完全未定义的行为,可能无法工作,当然不能依赖它工作,并且几乎肯定会在某些时候导致崩溃在某些浏览器中。)

I would like to redraw the plugin on a NPCocoaEventMouseDown

How can I retrieve the cgContextRef in a NPCocoaEventMouseDown?

You can't do either of those things. You call NPN_InvalidateRect in your mouse-down handler, and wait to get a draw call-back.

I tried to retrieve the cgContextRef with

CGContextRef cgContext = (NP_CGContext*)currentInstance->window.window

but that didn't seem to work.

Because that field is always NULL under the Cocoa event model, as documented in the Cocoa event spec. You are explicitly only provided a CGContextRef during a paint call, and it is only required to be valid for the duration of that call. (In case you are thinking of caching it for later use: don't. The results will be totally undefined behavior, probably won't work, certainly can't be relied on to work, and will almost certainly cause crashes at some point in some browser.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文