Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6681097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:33:05+00:00 2026-05-26T04:33:05+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:33:06+00:00Added an answer on May 26, 2026 at 4:33 am

    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.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a vertical scrollbar for my G15 applet, but am having
I am trying to draw a transparent (alpha) PNG image using CxImage, but it
I'm trying to figure out how to draw a color map like this: http://www.ritsplasman.com/images/colormap.png
Working in Visual Studio 2008. I'm trying to draw on a PNG image and
I'm trying to draw some simples lines with the iPhone/Touch SDK. I'd like to
I am trying to draw a series of rectangles using OpenGL but some of
I'm trying to redraw a GtkDrawingArea using the gtk_widget_queue_draw function, but the widget is
Trying to use pil for creating grid-like layout from images. But that code only
I am trying to draw an image from .png resource file. I have tried
I'm trying to draw a transparent.png image over a TV signal (so blending before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.