コード例 #1
0
ファイル: Samples.cpp プロジェクト: afrog33k/canvasplusplus
void Sample9(CanvasPlus::Canvas& canvas)
{
    Context2D& ctx = canvas.getContext("2d");
    CanvasGradient lingrad = ctx.createLinearGradient(0, 10 + 130, 0, 10);
    lingrad.addColorStop(0, "rgb(255,0,0)");
    lingrad.addColorStop(1, "rgb(255,255,255)");
    ctx.fillStyle = lingrad;
    ctx.fillRect(10, 10, 130, 130);
}
コード例 #2
0
static v8::Handle<v8::Value> addColorStopCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.CanvasGradient.addColorStop");
    CanvasGradient* imp = V8CanvasGradient::toNative(args.Holder());
    ExceptionCode ec = 0;
    {
    EXCEPTION_BLOCK(float, offset, static_cast<float>(MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined)->NumberValue()));
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, color, MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined));
    imp->addColorStop(offset, color, ec);
    if (UNLIKELY(ec))
        goto fail;
    return v8::Handle<v8::Value>();
    }
    fail:
    V8Proxy::setDOMException(ec);
    return v8::Handle<v8::Value>();
}
コード例 #3
0
ファイル: JSCanvasGradient.cpp プロジェクト: Xertz/EAWebKit
EncodedJSValue JSC_HOST_CALL jsCanvasGradientPrototypeFunctionAddColorStop(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSCanvasGradient::s_info))
        return throwVMTypeError(exec);
    JSCanvasGradient* castedThis = static_cast<JSCanvasGradient*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSCanvasGradient::s_info);
    CanvasGradient* imp = static_cast<CanvasGradient*>(castedThis->impl());
    ExceptionCode ec = 0;
    float offset(exec->argument(0).toFloat(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    const String& color(ustringToString(exec->argument(1).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->addColorStop(offset, color, ec);
    setDOMException(exec, ec);
    return JSValue::encode(jsUndefined());
}
コード例 #4
0
ファイル: Samples.cpp プロジェクト: afrog33k/canvasplusplus
void Sample11(CanvasPlus::Canvas& canvas)
{
    Context2D& ctx = canvas.getContext("2d");
    bool ispressed =  false;
    bool isfocused = true;
    CanvasGradient lingrad = ctx.createLinearGradient(0, 10 + 130, 0, 10);
    
    if (ispressed)
    {
        lingrad.addColorStop(0, "rgb(245,245,245)");
        lingrad.addColorStop(1, "rgb(220,220,220)");
    }
    else
    {
        lingrad.addColorStop(1, "rgb(220,220,220)");
        lingrad.addColorStop(0, "rgb(245,245,245)");
    }
    
    ctx.fillStyle = lingrad;
    ctx.fillRect(10, 10, 130, 130);
    
    if (isfocused)
    {
        ctx.strokeStyle = "rgb(74,144,254)";
    }
    else
    {
        ctx.strokeStyle = "rgb(198,198,198)";
    }
    
    ctx.strokeRect(10, 10, 130, 130);
    ctx.fillStyle = "rgb(0,0,0)";
    ctx.textAlign = "center";
    ctx.textBaseline = "middle";
    ctx.fillText(L"Button", (10 + 10 + 130) / 2, (10 + 10 + 130) / 2);
}