File: cairo-linear-gradient.cpp

package info (click to toggle)
gjs 1.87.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,128 kB
  • sloc: cpp: 38,390; javascript: 31,939; ansic: 15,994; sh: 1,743; python: 791; xml: 137; makefile: 40
file content (49 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2010 litl, LLC.

#include <config.h>

#include <cairo.h>

#include <js/PropertyDescriptor.h>  // for JSPROP_READONLY
#include <js/PropertySpec.h>
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <jsapi.h>  // for JS_NewObjectWithGivenProto
#include <jspubtd.h>  // for JSProtoKey

#include "gjs/jsapi-util-args.h"
#include "modules/cairo-private.h"

namespace JS {
class CallArgs;
}

JSObject* CairoLinearGradient::new_proto(JSContext* cx, JSProtoKey) {
    JS::RootedObject parent_proto(cx, CairoGradient::prototype(cx));
    return JS_NewObjectWithGivenProto(cx, nullptr, parent_proto);
}

cairo_pattern_t* CairoLinearGradient::constructor_impl(
    JSContext* cx, const JS::CallArgs& args) {
    double x0, y0, x1, y1;
    if (!gjs_parse_call_args(cx, "LinearGradient", args, "ffff", "x0", &x0,
                             "y0", &y0, "x1", &x1, "y1", &y1))
        return nullptr;

    cairo_pattern_t* pattern = cairo_pattern_create_linear(x0, y0, x1, y1);

    if (!gjs_cairo_check_status(cx, cairo_pattern_status(pattern), "pattern"))
        return nullptr;

    return pattern;
}

const JSPropertySpec CairoLinearGradient::proto_props[] = {
    JS_STRING_SYM_PS(toStringTag, "LinearGradient", JSPROP_READONLY),
    JS_PS_END};

const JSFunctionSpec CairoLinearGradient::proto_funcs[] = {
    // getLinearPoints
    JS_FS_END};