PaintPlugin::~PaintPlugin() { gPathI.deletePath(m_touchPath); gPaintI.deletePaint(m_paintSurface); gPaintI.deletePaint(m_paintButton); setContext(NULL); destroySurface(); }
AudioPlugin::~AudioPlugin() { gPaintI.deletePaint(m_paintTrack); gPaintI.deletePaint(m_paintRect); gPaintI.deletePaint(m_paintText); gPaintI.deletePaint(m_paintTrackProgress); gPaintI.deletePaint(m_paintActiveRect); if(m_soundPlay->track) gSoundI.deleteTrack(m_soundPlay->track); delete m_soundPlay; }
void BackgroundPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) { // get the plugin's dimensions according to the DOM PluginObject *obj = (PluginObject*) inst()->pdata; const int W = obj->window->width; const int H = obj->window->height; // compute the current zoom level const float zoomFactorW = static_cast<float>(surfaceWidth) / W; const float zoomFactorH = static_cast<float>(surfaceHeight) / H; // check to make sure the zoom level is uniform if (zoomFactorW + .01 < zoomFactorH && zoomFactorW - .01 > zoomFactorH) gLogI.log(kError_ANPLogType, " ------ %p zoom is out of sync (%f,%f)", inst(), zoomFactorW, zoomFactorH); // scale the variables based on the zoom level const int fontSize = (int)(zoomFactorW * 16); const int leftMargin = (int)(zoomFactorW * 10); // lock the surface ANPBitmap bitmap; JNIEnv* env = NULL; if (!m_surface || gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK || !gSurfaceI.lock(env, m_surface, &bitmap, NULL)) { gLogI.log(kError_ANPLogType, " ------ %p unable to lock the plugin", inst()); return; } // create a canvas ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); gCanvasI.drawColor(canvas, 0xFFFFFFFF); ANPPaint* paint = gPaintI.newPaint(); gPaintI.setFlags(paint, gPaintI.getFlags(paint) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(paint, 0xFFFF0000); gPaintI.setTextSize(paint, fontSize); ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(paint, tf); gTypefaceI.unref(tf); ANPFontMetrics fm; gPaintI.getFontMetrics(paint, &fm); gPaintI.setColor(paint, 0xFF0000FF); const char c[] = "This is a background plugin."; gCanvasI.drawText(canvas, c, sizeof(c)-1, leftMargin, -fm.fTop, paint); // clean up variables and unlock the surface gPaintI.deletePaint(paint); gCanvasI.deleteCanvas(canvas); gSurfaceI.unlock(env, m_surface); }
void FormPlugin::drawText(ANPCanvas* canvas, TextInput textInput) { // get font metrics ANPFontMetrics fontMetrics; gPaintI.getFontMetrics(m_paintText, &fontMetrics); gCanvasI.drawText(canvas, textInput.text, textInput.charPtr, textInput.rect.left + 5, textInput.rect.bottom - fontMetrics.fBottom, m_paintText); }
PaintPlugin::PaintPlugin(NPP inst) : SurfaceSubPlugin(inst) { m_isTouchActive = false; m_isTouchCurrentInput = true; m_activePaintColor = s_redColor; memset(&m_drawingSurface, 0, sizeof(m_drawingSurface)); memset(&m_inputToggle, 0, sizeof(m_inputToggle)); memset(&m_colorToggle, 0, sizeof(m_colorToggle)); memset(&m_fullScreenToggle, 0, sizeof(m_fullScreenToggle)); memset(&m_clearSurface, 0, sizeof(m_clearSurface)); // initialize the drawing surface m_surface = NULL; // initialize the path m_touchPath = gPathI.newPath(); if(!m_touchPath) gLogI.log(kError_ANPLogType, "----%p Unable to create the touch path", inst); // initialize the paint colors m_paintSurface = gPaintI.newPaint(); gPaintI.setFlags(m_paintSurface, gPaintI.getFlags(m_paintSurface) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintSurface, 0xFFC0C0C0); gPaintI.setTextSize(m_paintSurface, 18); m_paintButton = gPaintI.newPaint(); gPaintI.setFlags(m_paintButton, gPaintI.getFlags(m_paintButton) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintButton, 0xFFA8A8A8); // initialize the typeface (set the colors) ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(m_paintSurface, tf); gTypefaceI.unref(tf); //register for touch events ANPEventFlags flags = kTouch_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
NavigationPlugin::NavigationPlugin(NPP inst) : SubPlugin(inst) { m_hasFocus = false; m_activeNav = NULL; m_paintDisabled = gPaintI.newPaint(); gPaintI.setFlags(m_paintDisabled, gPaintI.getFlags(m_paintDisabled) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintDisabled, 0xFFFFFFFF); m_paintActive = gPaintI.newPaint(); gPaintI.setFlags(m_paintActive, gPaintI.getFlags(m_paintActive) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintActive, 0xFFFFFF00); //register for key events ANPEventFlags flags = kKey_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
void PaintPlugin::paintTouch() { //TODO do not paint outside the drawing surface //create the paint color ANPPaint* strokePaint = gPaintI.newPaint(); gPaintI.setFlags(strokePaint, gPaintI.getFlags(strokePaint) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(strokePaint, m_activePaintColor); gPaintI.setStyle(strokePaint, kStroke_ANPPaintStyle); gPaintI.setStrokeWidth(strokePaint, 6.0); gPaintI.setStrokeCap(strokePaint, kRound_ANPPaintCap); gPaintI.setStrokeJoin(strokePaint, kRound_ANPPaintJoin); // handle the complex "touch" paint (draw a line) ANPRectF bounds; gPathI.getBounds(m_touchPath, &bounds); // get a canvas that is only locked around the point and draw the path ANPCanvas* canvas = getCanvas(&bounds); gCanvasI.drawPath(canvas, m_touchPath, strokePaint); // clean up releaseCanvas(canvas); gPaintI.deletePaint(strokePaint); }
void FormPlugin::drawPassword(ANPCanvas* canvas, TextInput passwordInput) { // get font metrics ANPFontMetrics fontMetrics; gPaintI.getFontMetrics(m_paintText, &fontMetrics); // comput the circle dimensions and initial location float initialX = passwordInput.rect.left + 5; float ovalBottom = passwordInput.rect.bottom - 2; float ovalTop = ovalBottom - (fontMetrics.fBottom - fontMetrics.fTop); float ovalWidth = ovalBottom - ovalTop; float ovalSpacing = 3; // draw circles instead of the actual text for (uint32_t x = 0; x < passwordInput.charPtr; x++) { ANPRectF oval; oval.left = initialX + ((ovalWidth + ovalSpacing) * (float) x); oval.right = oval.left + ovalWidth; oval.top = ovalTop; oval.bottom = ovalBottom; gCanvasI.drawOval(canvas, &oval, m_paintText); } }
void PaintPlugin::paintMouse(int x, int y) { //TODO do not paint outside the drawing surface //create the paint color ANPPaint* fillPaint = gPaintI.newPaint(); gPaintI.setFlags(fillPaint, gPaintI.getFlags(fillPaint) | kAntiAlias_ANPPaintFlag); gPaintI.setStyle(fillPaint, kFill_ANPPaintStyle); gPaintI.setColor(fillPaint, m_activePaintColor); // handle the simple "mouse" paint (draw a point) ANPRectF point; point.left = (float) x-3; point.top = (float) y-3; point.right = (float) x+3; point.bottom = (float) y+3; // get a canvas that is only locked around the point and draw it ANPCanvas* canvas = getCanvas(&point); gCanvasI.drawOval(canvas, &point, fillPaint); // clean up releaseCanvas(canvas); gPaintI.deletePaint(fillPaint); }
AudioPlugin::AudioPlugin(NPP inst) : SubPlugin(inst) { const char path[] = "/sdcard/sample.raw"; // open a file stream FILE* f = fopen(path, "r"); gLogI.log(inst, kDebug_ANPLogType, "--- path %s FILE %p", path, f); // setup our private audio struct's default values m_soundPlay = new SoundPlay; m_soundPlay->instance = inst; m_soundPlay->progress = 0; m_soundPlay->fileSize = 0; m_soundPlay->file = f; m_soundPlay->track = NULL; // create the audio track if (f) { m_soundPlay->track = gSoundI.newTrack(44100, kPCM16Bit_ANPSampleFormat, 2, audioCallback, m_soundPlay); if (!m_soundPlay->track) { fclose(f); m_soundPlay->file = NULL; } } // get the audio file's size int fileDescriptor = open(path, O_RDONLY); struct stat fileStatus; if(fileDescriptor <= 0) { gLogI.log(inst, kError_ANPLogType, "fopen error"); } else if (fstat(fileDescriptor, &fileStatus) != 0) { gLogI.log(inst, kDebug_ANPLogType, "File Size: %d", fileStatus.st_size); m_soundPlay->fileSize = fileStatus.st_size; } else { gLogI.log(inst, kError_ANPLogType, "fstat error"); } // configure the UI elements m_activeTouch = false; memset(&m_trackRect, 0, sizeof(m_trackRect)); memset(&m_playRect, 0, sizeof(m_playRect)); memset(&m_pauseRect, 0, sizeof(m_pauseRect)); memset(&m_stopRect, 0, sizeof(m_stopRect)); m_paintTrack = gPaintI.newPaint(); gPaintI.setFlags(m_paintTrack, gPaintI.getFlags(m_paintTrack) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintTrack, 0xFFC0C0C0); m_paintRect = gPaintI.newPaint(); gPaintI.setFlags(m_paintRect, gPaintI.getFlags(m_paintRect) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintRect, 0xFFA8A8A8); m_paintText = gPaintI.newPaint(); gPaintI.setFlags(m_paintText, gPaintI.getFlags(m_paintText) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintText, 0xFF2F4F4F); gPaintI.setTextSize(m_paintText, 18); m_paintTrackProgress = gPaintI.newPaint(); gPaintI.setFlags(m_paintTrackProgress, gPaintI.getFlags(m_paintTrackProgress) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintTrackProgress, 0xFF545454); m_paintActiveRect = gPaintI.newPaint(); gPaintI.setFlags(m_paintActiveRect, gPaintI.getFlags(m_paintActiveRect) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintActiveRect, 0xFF545454); ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(m_paintText, tf); gTypefaceI.unref(tf); //register for touch events ANPEventFlags flags = kTouch_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(inst, kError_ANPLogType, "Error selecting input events."); } }
void AudioPlugin::draw(ANPCanvas* canvas) { NPP instance = this->inst(); PluginObject *obj = (PluginObject*) instance->pdata; gLogI.log(instance, kError_ANPLogType, "Drawing"); const float trackHeight = 30; const float buttonWidth = 60; const float buttonHeight = 30; const int W = obj->window->width; const int H = obj->window->height; // color the plugin canvas gCanvasI.drawColor(canvas, 0xFFCDCDCD); // get font metrics ANPFontMetrics fontMetrics; gPaintI.getFontMetrics(m_paintText, &fontMetrics); // draw the track box (1 px from the edge) m_trackRect.left = 1; m_trackRect.top = 1; m_trackRect.right = W - 2; m_trackRect.bottom = 1 + trackHeight; gCanvasI.drawRect(canvas, &m_trackRect, m_paintTrack); // draw the progress bar if (m_soundPlay->progress > 0) { // TODO need to draw progress bar to cover the proper percentage of the track bar gCanvasI.drawRect(canvas, &m_trackRect, m_paintTrackProgress); } // draw the play box (under track box) m_playRect.left = m_trackRect.left + 5; m_playRect.top = m_trackRect.bottom + 10; m_playRect.right = m_playRect.left + buttonWidth; m_playRect.bottom = m_playRect.top + buttonHeight; gCanvasI.drawRect(canvas, &m_playRect, getPaint(&m_playRect)); // draw the play box (under track box) const char playText[] = "Play"; gCanvasI.drawText(canvas, playText, sizeof(playText)-1, m_playRect.left + 5, m_playRect.top - fontMetrics.fTop, m_paintText); // draw the pause box (under track box) m_pauseRect.left = m_playRect.right + 20; m_pauseRect.top = m_trackRect.bottom + 10; m_pauseRect.right = m_pauseRect.left + buttonWidth; m_pauseRect.bottom = m_pauseRect.top + buttonHeight; gCanvasI.drawRect(canvas, &m_pauseRect, getPaint(&m_pauseRect)); // draw the text in the pause box const char pauseText[] = "Pause"; gCanvasI.drawText(canvas, pauseText, sizeof(pauseText)-1, m_pauseRect.left + 5, m_pauseRect.top - fontMetrics.fTop, m_paintText); // draw the stop box (under track box) m_stopRect.left = m_pauseRect.right + 20; m_stopRect.top = m_trackRect.bottom + 10; m_stopRect.right = m_stopRect.left + buttonWidth; m_stopRect.bottom = m_stopRect.top + buttonHeight; gCanvasI.drawRect(canvas, &m_stopRect, getPaint(&m_stopRect)); // draw the text in the pause box const char stopText[] = "Stop"; gCanvasI.drawText(canvas, stopText, sizeof(stopText)-1, m_stopRect.left + 5, m_stopRect.top - fontMetrics.fTop, m_paintText); }
FormPlugin::FormPlugin(NPP inst) : SubPlugin(inst) { m_hasFocus = false; m_activeInput = NULL; memset(&m_usernameInput, 0, sizeof(m_usernameInput)); memset(&m_passwordInput, 0, sizeof(m_passwordInput)); m_usernameInput.text[0] = '\0'; m_usernameInput.charPtr = 0; m_passwordInput.text[0] = '\0'; m_passwordInput.charPtr = 0; m_paintInput = gPaintI.newPaint(); gPaintI.setFlags(m_paintInput, gPaintI.getFlags(m_paintInput) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintInput, 0xFFFFFFFF); m_paintActive = gPaintI.newPaint(); gPaintI.setFlags(m_paintActive, gPaintI.getFlags(m_paintActive) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintActive, 0xFFFFFF00); m_paintText = gPaintI.newPaint(); gPaintI.setFlags(m_paintText, gPaintI.getFlags(m_paintText) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintText, 0xFF000000); gPaintI.setTextSize(m_paintText, 18); ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(m_paintText, tf); gTypefaceI.unref(tf); //register for key and visibleRect events ANPEventFlags flags = kKey_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
FormPlugin::~FormPlugin() { gPaintI.deletePaint(m_paintInput); gPaintI.deletePaint(m_paintActive); gPaintI.deletePaint(m_paintText); }
NavigationPlugin::~NavigationPlugin() { gPaintI.deletePaint(m_paintDisabled); gPaintI.deletePaint(m_paintActive); }
void PaintPlugin::drawCleanPlugin(ANPCanvas* canvas) { NPP instance = this->inst(); PluginObject *obj = (PluginObject*) instance->pdata; // if no canvas get a locked canvas if (!canvas) canvas = getCanvas(); if (!canvas) return; const float buttonWidth = 60; const float buttonHeight = 30; const int W = obj->window->width; const int H = obj->window->height; // color the plugin canvas gCanvasI.drawColor(canvas, 0xFFCDCDCD); // get font metrics ANPFontMetrics fontMetrics; gPaintI.getFontMetrics(m_paintSurface, &fontMetrics); // draw the input toggle button m_inputToggle.left = 5; m_inputToggle.top = H - buttonHeight - 5; m_inputToggle.right = m_inputToggle.left + buttonWidth; m_inputToggle.bottom = m_inputToggle.top + buttonHeight; gCanvasI.drawRect(canvas, &m_inputToggle, m_paintButton); const char* inputText = m_isTouchCurrentInput ? "Touch" : "Mouse"; gCanvasI.drawText(canvas, inputText, strlen(inputText), m_inputToggle.left + 5, m_inputToggle.top - fontMetrics.fTop, m_paintSurface); // draw the color selector button m_colorToggle.left = (W/3) - (buttonWidth/2); m_colorToggle.top = H - buttonHeight - 5; m_colorToggle.right = m_colorToggle.left + buttonWidth; m_colorToggle.bottom = m_colorToggle.top + buttonHeight; gCanvasI.drawRect(canvas, &m_colorToggle, m_paintButton); const char* colorText = getColorText(); gCanvasI.drawText(canvas, colorText, strlen(colorText), m_colorToggle.left + 5, m_colorToggle.top - fontMetrics.fTop, m_paintSurface); // draw the full-screen toggle button m_fullScreenToggle.left = ((W*2)/3) - (buttonWidth/2); m_fullScreenToggle.top = H - buttonHeight - 5; m_fullScreenToggle.right = m_fullScreenToggle.left + buttonWidth; m_fullScreenToggle.bottom = m_fullScreenToggle.top + buttonHeight; gCanvasI.drawRect(canvas, &m_fullScreenToggle, m_paintButton); const char* fullScreenText = "Full"; gCanvasI.drawText(canvas, fullScreenText, strlen(fullScreenText), m_fullScreenToggle.left + 5, m_fullScreenToggle.top - fontMetrics.fTop, m_paintSurface); // draw the clear canvas button m_clearSurface.left = W - buttonWidth - 5; m_clearSurface.top = H - buttonHeight - 5; m_clearSurface.right = m_clearSurface.left + buttonWidth; m_clearSurface.bottom = m_clearSurface.top + buttonHeight; gCanvasI.drawRect(canvas, &m_clearSurface, m_paintButton); const char* clearText = "Clear"; gCanvasI.drawText(canvas, clearText, strlen(clearText), m_clearSurface.left + 5, m_clearSurface.top - fontMetrics.fTop, m_paintSurface); // draw the drawing surface box (5 px from the edge) m_drawingSurface.left = 5; m_drawingSurface.top = 5; m_drawingSurface.right = W - 5; m_drawingSurface.bottom = m_colorToggle.top - 5; gCanvasI.drawRect(canvas, &m_drawingSurface, m_paintSurface); // release the canvas releaseCanvas(canvas); }