Example #1
0
void DependencyArrow::draw(const Cairo::RefPtr<Cairo::Context>& context) const
{
    // the way to compute the (tcx, tcy) single control point of the
    // quadratic
    double dX = mControlPoint.getX() - mOrigin->getX();
    double dY = mControlPoint.getY() - mOrigin->getY();
    double d1 = std::sqrt(dX * dX + dY * dY);
    double d = d1;

    dX = mDestination->getX() - mControlPoint.getX();
    dY = mDestination->getY() - mControlPoint.getY();
    d += std::sqrt(dX * dX + dY * dY);
    double t = d1/d;

    double t1 = 1.0 - t;
    double tSq = t * t;
    double denom = 2.0 * t * t1;

    double tcx = (mControlPoint.getX() - t1 * t1 * mOrigin->getX() -
        tSq * mDestination->getX()) / denom;
    double tcy = (mControlPoint.getY() - t1 * t1 * mOrigin->getY() -
        tSq * mDestination->getY()) / denom;

    // from the single point of the quadratic to the both of the cubic
    double tcxq1 = mOrigin->getX() + 2. * (tcx - mOrigin->getX()) / 3.;
    double tcyq1 = mOrigin->getY() + 2. * (tcy - mOrigin->getY()) / 3.;
    double tcxq2 = mDestination->getX() +
        2. * (tcx - mDestination->getX()) / 3.;
    double tcyq2 = mDestination->getY() +
        2. * (tcy - mDestination->getY()) / 3.;

    // and now to draw,
    std::valarray< double > dashes(2);
    double angle = atan2 (mDestination->getY() - tcyq2,
        mDestination->getX() - tcxq2) + M_PI;
    double x1 = mDestination->getX() + 9 * std::cos(angle - 0.35);
    double y1 = mDestination->getY() + 9 * std::sin(angle - 0.35);
    double x2 = mDestination->getX() + 9 * std::cos(angle + 0.35);
    double y2 = mDestination->getY() + 9 * std::sin(angle + 0.35);
    dashes[0] = 8.0;
    dashes[1] = 3.0;

    context->save();
    context->set_line_width(1);
    context->move_to(mDestination->getX(), mDestination->getY());
    context->line_to(x1,y1);
    context->line_to(x2,y2);
    context->line_to(mDestination->getX(), mDestination->getY());
    context->fill();

    context->set_dash(dashes,0.);
    context->move_to(mOrigin->getX(), mOrigin->getY());
    context->curve_to(tcxq1, tcyq1, tcxq2, tcyq2, mDestination->getX(),
        mDestination->getY());
    context->stroke();
    context->restore();
}
Example #2
0
Gura_ImplementMethod(wx_Pen, SetDashes)
{
	Signal &sig = env.GetSignal();
	Object_wx_Pen *pThis = Object_wx_Pen::GetObjectThis(arg);
	if (pThis->IsInvalid(sig)) return Value::Nil;
	CArrayOfDash dashes(arg.GetList(0));
	pThis->GetEntity()->SetDashes(dashes.Count(), dashes.Data());
	return Value::Nil;
}
Example #3
0
static bool
setDash_func(JSContext *context,
             unsigned   argc,
             JS::Value *vp)
{
    GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
    guint i;
    cairo_t *cr = priv ? priv->cr : NULL;
    JS::RootedObject dashes(context);
    double offset;
    guint len;

    if (!gjs_parse_call_args(context, "setDash", argv, "of",
                             "dashes", &dashes,
                             "offset", &offset))
        return false;

    if (!JS_IsArrayObject(context, dashes)) {
        gjs_throw(context, "dashes must be an array");
        return false;
    }

    if (!JS_GetArrayLength(context, dashes, &len)) {
        gjs_throw(context, "Can't get length of dashes");
        return false;
    }

    std::vector<double> dashes_c;
    dashes_c.reserve(len);
    JS::RootedValue elem(context);
    for (i = 0; i < len; ++i) {
        double b;

        elem.setUndefined();
        if (!JS_GetElement(context, dashes, i, &elem)) {
            return false;
        }
        if (elem.isUndefined())
            continue;

        if (!JS::ToNumber(context, elem, &b))
            return false;
        if (b <= 0) {
            gjs_throw(context, "Dash value must be positive");
            return false;
        }

        dashes_c.push_back(b);
    }

    cairo_set_dash(cr, &dashes_c[0], dashes_c.size(), offset);
    argv.rval().setUndefined();
    return true;
}
Example #4
0
void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr)
{
    cairo_set_antialias(dstCr, cairo_get_antialias(srcCr));

    size_t dashCount = cairo_get_dash_count(srcCr);
    Vector<double> dashes(dashCount);

    double offset;
    cairo_get_dash(srcCr, dashes.data(), &offset);
    cairo_set_dash(dstCr, dashes.data(), dashCount, offset);
    cairo_set_line_cap(dstCr, cairo_get_line_cap(srcCr));
    cairo_set_line_join(dstCr, cairo_get_line_join(srcCr));
    cairo_set_line_width(dstCr, cairo_get_line_width(srcCr));
    cairo_set_miter_limit(dstCr, cairo_get_miter_limit(srcCr));
    cairo_set_fill_rule(dstCr, cairo_get_fill_rule(srcCr));
}
Example #5
0
void CurveEditPart::drawControlLine(Cairo::RefPtr<Cairo::Context> context, const Point& start_point, const Point& end_point)
{
    context->begin_new_path();
    context->move_to (start_point.getX(), start_point.getY());
    context->line_to (end_point.getX(), end_point.getY());

    context->set_source_rgba (1, 0, 0, 0.5);

    std::vector< double > dashes(2);
    dashes[0] = 2.0;
    dashes[1] = 2.0;

    context->set_dash (dashes, 0.0);

    context->set_line_width (1.0);

    context->stroke();
}
void FrequencyGraph( Cairo::RefPtr<Cairo::Context> cr, bool active, float x, float y, float xS, float yS, EqualizerState state)
{
    cr->set_line_cap( Cairo::LINE_CAP_ROUND );
    cr->set_line_join( Cairo::LINE_JOIN_ROUND);

    int xSize = xS;
    int ySize = yS;

    // works but a bit simple
    cr -> move_to( x        , y         );
    cr -> line_to( x + xSize, y         );
    cr -> line_to( x + xSize, y + ySize );
    cr -> line_to( x        , y + ySize );
    cr -> close_path();

    // Draw outline shape
    cr -> set_source_rgb (0.1,0.1,0.1);
    cr -> fill();

    // draw "frequency guides"
    std::valarray< double > dashes(2);
    dashes[0] = 2.0;
    dashes[1] = 2.0;
    cr->set_dash (dashes, 0.0);
    cr->set_line_width(1.0);
    cr->set_source_rgb (0.4,0.4,0.4);
    for ( int i = 0; i < 4; i++ )
    {
        cr->move_to( x + ((xSize / 4.f)*i), y );
        cr->line_to( x + ((xSize / 4.f)*i), y + ySize );
    }
    for ( int i = 0; i < 4; i++ )
    {
        cr->move_to( x       , y + ((ySize / 4.f)*i) );
        cr->line_to( x +xSize, y + ((ySize / 4.f)*i) );
    }
    cr->stroke();
    cr->unset_dash();

    // set colour based on active or not
    if ( active )
        setColour(cr, COLOUR_BLUE_1, 0.2 );
    else
        setColour(cr, COLOUR_GREY_1, 0.2 );

    int tmpX = x;
    int tmpY = y;

    // precalculate some variables
    float oldGainPix = (ySize / 60.f) * (state.gain[0] - 0.5 ) * 40;
    float oldXLoc = 0;
    float qPix = ((xSize * 0.2) / 3.f );
    //float oldCutoff = 0;

    // move to bottom left, draw line to middle left
    cr->move_to( tmpX, tmpY + ySize         );
    cr->line_to( tmpX, tmpY + (ySize * 0.5) - oldGainPix );


    for ( int i = 0; i < 4; i++ )
    {
        //float cutoff = state.cutoffFreq[i] / 20000;


        float gainPix = (ySize / 60.f) * (state.gain[i] - 0.5 ) * 40;

        float xLoc = xSize * 0.2 * (i+1);

        //std::cout << "I: " << i << "  GainPix: " << gainPix << "  tmpY - gainPix" << tmpY - gainPix << std::endl;


        cr->curve_to( tmpX + oldXLoc + qPix, tmpY + (ySize * 0.5) - oldGainPix ,// control point 1
                      tmpX + xLoc - qPix   , tmpY + (ySize * 0.5) - gainPix ,   // control point 2
                      tmpX + xLoc          , tmpY + (ySize * 0.5) - gainPix );  // end of curve

        // update variables for next iter
        oldGainPix = gainPix;
        oldXLoc = xLoc;
        //oldCutoff = cutoff;
    }

    // last bit of curve to the right edge
    cr->curve_to( tmpX + oldXLoc + qPix, tmpY + (ySize * 0.5) - oldGainPix,   // control point 1
                  tmpX + xSize   - qPix, tmpY + (ySize * 0.5) - oldGainPix,   // control point 2
                  tmpX + xSize         , tmpY + (ySize * 0.5) - oldGainPix);  // end of curve


    cr->line_to( tmpX + xSize , tmpY + ySize );
    cr->close_path();
    cr->fill_preserve();

    cr->set_line_width(2.5);
    if ( active )
        setColour(cr, COLOUR_BLUE_1 );
    else
        setColour(cr, COLOUR_GREY_1 );
    cr->stroke();

    // outline
    cr->rectangle( x, y , xS, yS );
    cr->set_line_width(3);
    if ( active )
        setColour(cr, COLOUR_GREY_2 );
    else
        setColour(cr, COLOUR_GREY_3 );
    cr->stroke();

    //std::cout << "LupppWidget::FrequencyGraph() called!" << std::endl;
}