Exemple #1
0
        public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.bezierCurveTo({1},{2},{3},{4},{5},{6});"
                    ),
                Script.GetObject(API.id),
                cp1x, cp1y, cp2x, cp2y, x, y
                );

            API.ExecuteJavaScript(script);
        }
Exemple #2
0
        public void quadraticCurveTo(double cpx, double cpy, double x, double y)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.quadraticCurveTo({1},{2},{3},{4});"
                    ),
                Script.GetObject(API.id),
                cpx, cpy, x, y
                );

            API.ExecuteJavaScript(script);
        }
Exemple #3
0
        public void lineTo(double x, double y)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.lineTo({1},{2});"
                    ),
                Script.GetObject(API.id),
                x, y
                );

            API.ExecuteJavaScript(script);
        }
Exemple #4
0
        public void setLineDash(params double[] segments)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.setLineDash({1});"
                    ),
                Script.GetObject(API.id),
                JSON.Stringify(segments)
                );

            API.ExecuteJavaScript(script);
        }
Exemple #5
0
        public void arcTo(double x, double y, double x2, double y2, double radius)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.arcTo({1},{2},{3},{4},{5});"
                    ),
                Script.GetObject(API.id),
                x, y, x2, y2, radius
                );

            API.ExecuteJavaScript(script);
        }
Exemple #6
0
        public void arc(double x, double y, double radius, double startAngle, double endAngle)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.arc({1},{2},{3},{4},{5});"
                    ),
                Script.GetObject(API.id),
                x, y, radius, startAngle, endAngle
                );

            API.ExecuteJavaScript(script);
        }
Exemple #7
0
 public Window this[int i] {
     get {
         string script = ScriptBuilder.Build(
             ScriptBuilder.Script(
                 "var w = {0};",
                 "return w[{1}];"
                 ),
             Script.GetObject(API.id), i
             );
         int id = API._ExecuteBlocking <int>(script);
         return(API.CreateObject <Window>(id));
     }
 }
Exemple #8
0
        /*
         * public void bindBuffer(GLenum target, WebGLBuffer buffer) {
         *      string script = ScriptBuilder.Build(
         *              ScriptBuilder.Script(
         *                      "{0}.bindBuffer({1},{2});"
         *              ),
         *              Script.GetObject(API.id),
         *              target,
         *              Script.GetObject(buffer.API.id)
         *      );
         *      API.ExecuteJavaScript(script);
         * }
         * //*/

        public void bufferData(GLenum target, GLsizeiptr size, GLenum usage)
        {
            // TODO: add params
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.bufferData({1},{2},{3});"
                    ),
                Script.GetObject(API.id),
                target, size, usage
                );

            API.ExecuteJavaScript(script);
        }
Exemple #9
0
        public void isPointInStroke(double x, double y)
        {
            // TODO: add parameter
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.isPointInStroke({1},{2});"
                    ),
                Script.GetObject(API.id),
                x, y
                );

            API.ExecuteJavaScript(script);
        }
Exemple #10
0
        /*
         * public void bufferSubData(GLenum target, GLuint offset, ArrayBuffer srcData) {
         *      string script = ScriptBuilder.Build(
         *              ScriptBuilder.Script(
         *                      "{0}.bufferSubData({1},{2},{3});"
         *              ),
         *              Script.GetObject(API.id),
         *              target, size, usage
         *      );
         *      API.ExecuteJavaScript(script);
         * }
         * //*/

        /*
         * public WebGLBuffer createBuffer() {
         *      string script = ScriptBuilder.Build(
         *              ScriptBuilder.Script(
         *                      "var buf = {0}.createBuffer();",
         *                      "return {1};"
         *              ),
         *              Script.GetObject(API.id),
         *              Script.AddObject("buf")
         *      );
         *      int id = API._ExecuteBlocking<int>(script);
         *      return new WebGLBuffer();
         * }
         * //*/

        /*
         * public void deleteBuffer(WebGLBuffer buffer) {
         *      string script = ScriptBuilder.Build(
         *              ScriptBuilder.Script(
         *                      "{0}.deleteBuffer({1});"
         *              ),
         *              Script.GetObject(API.id),
         *              Script.GetObject(buffer.API.id)
         *      );
         *      API.ExecuteJavaScript(script);
         * }
         * //*/

        public JsonObject getBufferParameter(GLenum target, GLenum pname)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "return {0}.getBufferParameter({1},{2});"
                    ),
                Script.GetObject(API.id),
                target, pname
                );
            object result = API._ExecuteBlocking <object>(script);

            return(new JsonObject(result));
        }
Exemple #11
0
        public void drawFocusIfNeeded(Element element)
        {
            // TODO: add path parameter
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.drawFocusIfNeeded({1});"
                    ),
                Script.GetObject(API.id),
                Script.GetObject(element.API.id)
                );

            API.ExecuteJavaScript(script);
        }
Exemple #12
0
        public void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "{0}.ellipse({1},{2},{3},{4},{5},{6},{7});"
                    ),
                Script.GetObject(API.id),
                x, y, radiusX, radiusY,
                rotation, startAngle, endAngle
                );

            API.ExecuteJavaScript(script);
        }
Exemple #13
0
        public double[] getLineDash()
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var array = {0}.getLineDash();",
                    "return {1};"
                    ),
                Script.GetObject(API.id),
                Script.AddObject("array")
                );

            object[] result = API._ExecuteBlocking <object[]>(script);
            return(Array.ConvertAll(result, value => Convert.ToDouble(value)));
        }
Exemple #14
0
        public Node removeChild(Node child)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var node = {0}.removeChild({1});",
                    "return {2};"
                    ),
                Script.GetObject(API.id),
                Script.GetObject(child.API.id),
                Script.AddObject("node")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Node>(id));
        }
Exemple #15
0
        public Node getRootNode(JsonObject options)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var node = {0}.getRootNode({1});",
                    "return {2}"
                    ),
                Script.GetObject(API.id),
                options.Stringify(),
                Script.AddObject("node")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Node>(id));
        }
Exemple #16
0
        public Node cloneNode(bool deep)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var node = {0}.cloneNode({1});",
                    "return {2};"
                    ),
                Script.GetObject(API.id),
                deep.Escape(),
                Script.AddObject("node")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Node>(id));
        }
Exemple #17
0
        public TextMetrics measureText(string text)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var metrics = {0}.measureText({1});",
                    "return {2};"
                    ),
                Script.GetObject(API.id),
                text.Escape(),
                Script.AddObject("metrics")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <TextMetrics>(id));
        }
Exemple #18
0
        public Element querySelector(string selectors)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var element = {0}.querySelector({1});",
                    "return {2}"
                    ),
                Script.GetObject(API.id),
                selectors.Escape(),
                Script.AddObject("element")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Element>(id));
        }
Exemple #19
0
        public Node replaceChild(Node newChild, Node oldChild)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var node = {0}.replaceChild({1},{2});",
                    "return {3};"
                    ),
                Script.GetObject(API.id),
                Script.GetObject(newChild.API.id),
                Script.GetObject(oldChild.API.id),
                Script.AddObject("node")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Node>(id));
        }
Exemple #20
0
        public Node insertBefore(Node newNode, Node referenceNode)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var node = {0}.insertBefore({1},{2});",
                    "return {3}"
                    ),
                Script.GetObject(API.id),
                Script.GetObject(newNode.API.id),
                Script.GetObject(referenceNode.API.id),
                Script.AddObject("node")
                );
            int id = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Node>(id));
        }
Exemple #21
0
        /// <summary>
        /// Generally, the template is just an array of options for constructing a MenuItem.
        /// <para>
        /// You can also attach other fields to the element of the template
        /// and they will become properties of the constructed menu items.
        /// </para>
        /// </summary>
        /// <param name="template"></param>
        /// <returns></returns>
        public Menu buildFromTemplate(MenuItemConstructorOptions[] template)
        {
            string param  = _CreateTemplateString(template);
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var menu = {0}.buildFromTemplate({1});",
                    "return {2};"
                    ),
                Script.GetObject(API.id),
                param,
                Script.AddObject("menu")
                );
            int result = API._ExecuteBlocking <int>(script);

            return(API.CreateObject <Menu>(result));
        }
Exemple #22
0
        /// <summary>
        /// The native type of the handle is HWND on Windows, NSView* on macOS,
        /// and Window (unsigned long) on Linux.
        /// </summary>
        /// <returns>The platform-specific handle of the window.</returns>
        public ulong getNativeWindowHandle()
        {
            string script = ScriptBuilder.Build(
                "return {0}.getNativeWindowHandle();",
                Script.GetObject(API.id)
                );
            object     result = API._ExecuteBlocking <object>(script);
            JsonObject json   = new JsonObject(result);

            object[] data  = json["data"] as object[];
            byte[]   bytes = new byte[8];
            for (int i = 0; i < data.Length; i++)
            {
                object item = data[i];
                bytes[i] = (byte)(int)item;
            }
            return(BitConverter.ToUInt64(bytes, 0));
        }
        public void testBasic()
        {
            ScriptBuilder builder = new ScriptBuilder();

            builder.ScriptLanguage = "Groovy";
            builder.ScriptText     = "print 'foo'";
            Script s1 = builder.Build();

            Assert.AreEqual("Groovy", s1.ScriptLanguage);
            Assert.AreEqual("print 'foo'", s1.ScriptText);
            builder = new ScriptBuilder();
            builder.ScriptLanguage = "Groovy";
            builder.ScriptText     = "print 'foo'";
            Script s2 = builder.Build();

            Assert.AreEqual(s1, s2);
            Assert.AreEqual(s1.GetHashCode(), s2.GetHashCode());
        }
Exemple #24
0
        public Element createElement(string tagName)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var element = {0}.createElement({1});",
                    "return {2}"
                    ),
                Script.GetObject(API.id),
                tagName.Escape(),
                Script.AddObject("element")
                );
            int id = API._ExecuteBlocking <int>(script);

            if (tagName == "canvas")
            {
                return(API.CreateObject <HTMLCanvasElement>(id));
            }
            return(API.CreateObject <Element>(id));
        }
Exemple #25
0
        public Gamepad[] getGamepads()
        {
            if (!_getGamepadsCache.ContainsKey((API as SocketronDOMAPI).webContentsId))
            {
                string script = ScriptBuilder.Build(
                    ScriptBuilder.Script(
                        "var result = [];",
                        "var array = {0}.getGamepads();",
                        "for (var item of array) {{",
                        "if (item == null) {{",
                        "result.push(0)",
                        "continue;",
                        "}}",
                        "result.push({1});",
                        "}}",
                        "return result;"
                        ),
                    Script.GetObject(API.id),
                    Script.AddObject("item")
                    );
                int cacheId = API.CacheScript(script);
                _getGamepadsCache.Add((API as SocketronDOMAPI).webContentsId, cacheId);
            }
            int cacheId2 = _getGamepadsCache[(API as SocketronDOMAPI).webContentsId];

            object[] result = API.ExecuteCachedScript <object[]>(cacheId2);
            if (result == null)
            {
                return(new Gamepad[0]);
            }
            int[]     ids      = Array.ConvertAll(result, value => Convert.ToInt32(value));
            Gamepad[] gamepads = new Gamepad[ids.Length];
            for (int i = 0; i < ids.Length; i++)
            {
                int id = ids[i];
                if (id <= 0)
                {
                    continue;
                }
                gamepads[i] = API.CreateObject <Gamepad>(id);
            }
            return(gamepads);
        }
        public void testTextNotNull()
        {
            ScriptBuilder builder = new ScriptBuilder();

            try
            {
                builder.ScriptLanguage = "Groovy";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                // OK.
            }

            // The text can be empty.
            builder = new ScriptBuilder();
            builder.ScriptLanguage = "Groovy";
            builder.ScriptText     = "";
            builder.Build();
        }
        public void testLanguageNotBlank()
        {
            try
            {
                ScriptBuilder builder = new ScriptBuilder();
                builder.ScriptText = "print 'foo'";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // OK.
            }

            try
            {
                ScriptBuilder builder = new ScriptBuilder();
                builder.ScriptText     = "print 'foo'";
                builder.ScriptLanguage = "";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // OK.
            }

            try
            {
                ScriptBuilder builder = new ScriptBuilder();
                builder.ScriptText     = "print 'foo'";
                builder.ScriptLanguage = " ";
                builder.Build();
                Assert.Fail();
            }
            catch (ArgumentException)
            {
                // OK.
            }
        }
Exemple #28
0
        /*
         * public void captureStream() {
         *      string script = ScriptBuilder.Build(
         *              ScriptBuilder.Script(
         *                      "var stream = {0}.captureStream();",
         *                      "return {1};"
         *              ),
         *              Script.GetObject(_id),
         *              Script.AddObject("stream")
         *      );
         *      int id = _ExecuteBlocking<int>(script);
         * }
         * //*/

        public RenderingContext getContext(string contextType)
        {
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var context = {0}.getContext({1});",
                    "return {2};"
                    ),
                Script.GetObject(API.id),
                contextType.Escape(),
                Script.AddObject("context")
                );
            int id = API._ExecuteBlocking <int>(script);

            if (contextType == "2d")
            {
                return(API.CreateObject <CanvasRenderingContext2D>(id));
            }
            if (contextType == "webgl")
            {
                return(API.CreateObject <WebGLRenderingContext>(id));
            }
            return(API.CreateObject <RenderingContext>(id));
        }
Exemple #29
0
        public async Task ReaderTest()
        {
            var sb = new ScriptBuilder();

            sb.AddCodeBlock("println(F0)");
            sb.AddCodeBlock("println(F[1])");
            sb.AddCodeBlock("println(F[2])");
            var(script, _) = sb.Build(CancellationToken.None);

            using var iop = new IoProxy();

            await script.RunAsync(new Global {
                Reader = new StringReader(string.Join(Environment.NewLine, new[] {
                    "1 a",
                    "a 1",
                    "2 b",
                    "b 2",
                    "3 c",
                    "c 3"
                })),
                Separator = new Regex(@"\s")
            });

            var expects = new[] {
                "1 a", "1", "a",
                "a 1", "a", "1",
                "2 b", "2", "b",
                "b 2", "b", "2",
                "3 c", "3", "c",
                "c 3", "c", "3"
            };

            foreach (var(expect, actual) in expects.Zip(iop.ReadLineFromStdOut()))
            {
                Assert.Equal(expect, actual);
            }
        }
Exemple #30
0
        private static IReadOnlyDictionary <string, string> MakeLocationDictionary(string rootPath)
        {
            var builder = new ScriptBuilder();

            var defn = builder.Build(rootPath);

            var results = new Dictionary <string, string>();

            foreach (var file in defn.ScriptReferences.Where(f => f.IsValid))
            {
                var path = Path.GetDirectoryName(file.RealSourcePath);
                var name = Path.GetFileNameWithoutExtension(file.RealSourcePath)?.ToLowerInvariant();

                if (path.NotUseful() ||
                    name.NotUseful())
                {
                    continue;
                }

                results.Add(name, path);
            }

            return(results);
        }