Ejemplo n.º 1
0
void FormPlugin::draw(ANPCanvas* canvas) {
    NPP instance = this->inst();
    PluginObject *obj = (PluginObject*) instance->pdata;

    const float inputWidth = 60;
    const float inputHeight = 30;
    const int W = obj->window->width;
    const int H = obj->window->height;

    // color the plugin canvas
    gCanvasI.drawColor(canvas, (m_hasFocus) ? 0xFFCDCDCD : 0xFF545454);

    // draw the username box (5 px from the top edge)
    m_usernameInput.rect.left = 5;
    m_usernameInput.rect.top = 5;
    m_usernameInput.rect.right = W - 5;
    m_usernameInput.rect.bottom = m_usernameInput.rect.top + inputHeight;
    gCanvasI.drawRect(canvas, &m_usernameInput.rect, getPaint(&m_usernameInput));
    drawText(canvas, m_usernameInput);

    // draw the password box (5 px from the bottom edge)
    m_passwordInput.rect.left = 5;
    m_passwordInput.rect.top = H - (inputHeight + 5);
    m_passwordInput.rect.right = W - 5;
    m_passwordInput.rect.bottom = m_passwordInput.rect.top + inputHeight;
    gCanvasI.drawRect(canvas, &m_passwordInput.rect, getPaint(&m_passwordInput));
    drawPassword(canvas, m_passwordInput);

    //invalidate the canvas
    //inval(instance);
}
Ejemplo n.º 2
0
ANPCanvas* PaintPlugin::getCanvas(ANPRectI* dirtyRect) {

    ANPBitmap bitmap;
    JNIEnv* env = NULL;
    if (!m_surface || gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK ||
        !gSurfaceI.lock(env, m_surface, &bitmap, dirtyRect)) {
            return NULL;
        }

    ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);

    // clip the canvas to the dirty rect b/c the surface is only required to
    // copy a minimum of the dirty rect and may copy more. The clipped canvas
    // however will never write to pixels outside of the clipped area.
    if (dirtyRect) {
        ANPRectF clipR;
        clipR.left = dirtyRect->left;
        clipR.top = dirtyRect->top;
        clipR.right = dirtyRect->right;
        clipR.bottom = dirtyRect->bottom;
        gCanvasI.clipRect(canvas, &clipR);
    }

    return canvas;
}
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 AudioPlugin::drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip) {
    ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap);

    ANPRectF clipR;
    clipR.left = clip.left;
    clipR.top = clip.top;
    clipR.right = clip.right;
    clipR.bottom = clip.bottom;
    gCanvasI.clipRect(canvas, &clipR);

    draw(canvas);
    gCanvasI.deleteCanvas(canvas);
}
Ejemplo n.º 5
0
void PaintPlugin::releaseCanvas(ANPCanvas* canvas) {
    JNIEnv* env = NULL;
    if (m_surface && gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) {
        gSurfaceI.unlock(env, m_surface);
    }
    gCanvasI.deleteCanvas(canvas);
}
Ejemplo n.º 6
0
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);
}
void NavigationPlugin::draw(ANPCanvas* canvas) {
    NPP instance = this->inst();
    PluginObject *obj = (PluginObject*) instance->pdata;

    const int W = obj->window->width;
    const int H = obj->window->height;
    const int Wm = W/2;
    const int Hm = H/2;

    // color the plugin canvas
    gCanvasI.drawColor(canvas, (m_hasFocus) ? 0xFFCDCDCD : 0xFF545454);

    // draw the nav up box (5 px from the top edge)
    m_navUp.left = Wm - 15;
    m_navUp.top = 5;
    m_navUp.right = m_navUp.left + 30;
    m_navUp.bottom = m_navUp.top + 30;
    gCanvasI.drawRect(canvas, &m_navUp, getPaint(&m_navUp));

    // draw the nav down box (5 px from the bottom edge)
    m_navDown.left = Wm - 15;
    m_navDown.top = H - (30 + 5);
    m_navDown.right = m_navDown.left + 30;
    m_navDown.bottom = m_navDown.top + 30;
    gCanvasI.drawRect(canvas, &m_navDown, getPaint(&m_navDown));

    // draw the nav left box (5 px from the left edge)
    m_navLeft.left = 5;
    m_navLeft.top = Hm - 15;
    m_navLeft.right = m_navLeft.left + 30;
    m_navLeft.bottom = m_navLeft.top + 30;
    gCanvasI.drawRect(canvas, &m_navLeft, getPaint(&m_navLeft));

    // draw the nav right box (5 px from the right edge)
    m_navRight.left = W - (30 + 5);
    m_navRight.top = Hm - 15;
    m_navRight.right = m_navRight.left + 30;
    m_navRight.bottom = m_navRight.top + 30;
    gCanvasI.drawRect(canvas, &m_navRight, getPaint(&m_navRight));

    // draw the nav center box
    m_navCenter.left = Wm - 15;
    m_navCenter.top = Hm - 15;
    m_navCenter.right = m_navCenter.left + 30;
    m_navCenter.bottom = m_navCenter.top + 30;
    gCanvasI.drawRect(canvas, &m_navCenter, getPaint(&m_navCenter));

    gLogI.log(kDebug_ANPLogType, "----%p Drawing Plugin", inst());
}
Ejemplo n.º 8
0
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);
    }
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 10
0
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);
}
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);
}
Ejemplo n.º 12
0
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);
}