Пример #1
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == _drawEvent)
            {
                using (SKBitmap bitmap = new SKBitmap(width: args.Area.Width, height: args.Area.Height, colorType: SKColorType.Rgba8888, alphaType: SKAlphaType.Premul))
                    using (SKCanvas canvas = new SKCanvas(bitmap))
                        using (SKPaint paint = new SKPaint())
                        {
                            paint.IsAntialias = true;
                            canvas.Clear();

                            paint.Shader = SKShader.CreateRadialGradient(
                                new SKPoint(args.Area.Width / 2f, args.Area.Height / 2f),
                                Math.Max(args.Area.Width, args.Area.Height) / 10f,
                                new SKColor[] { SKColor.Parse("#77FFFFFF"), SKColor.Parse("#33FFFFFF"), SKColor.Parse("#00000000") },
                                null,
                                SKShaderTileMode.Mirror);

                            canvas.DrawRect(new SKRect(0, 0, args.Area.Width, args.Area.Height), paint);

                            var img = bitmap.ToSciterImage();
                            var gfx = SciterGraphics.Create(args.Handle);
                            gfx.BlendImage(img, args.Area.Left, args.Area.Top);

                            //return true;
                        }
            }

            return(base.OnDraw(se, args));
        }
Пример #2
0
        public bool ResetByNeedle(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            string needle = args[0].Get("");

            List <Icon> icons = new List <Icon>();

            foreach (var icon in Joiner._iconsByHash.Values)
            {
                foreach (var tag in icon.arr_tags)
                {
                    if (tag.IndexOf(needle, StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        icons.Add(icon);
                        break;
                    }
                }
            }

            SetIconList(icons);

            _bulk_pos = 0;

            result = null;
            return(true);
        }
Пример #3
0
 public void SynchronousFunction(SciterElement element, SciterValue arg1, SciterValue arg2, SciterValue arg3, SciterValue arg4, SciterValue arg5)
 {
     _logger?.LogInformation(
         "{NameOfMethod}(arg1: {Arg1}; arg2: {Arg2}; arg3: {Arg3}; arg4: {Arg4}; arg5: {Arg5}) was executed!",
         nameof(SynchronousFunction), arg1.AsInt32(), arg2.AsInt32(), arg3.AsInt32(), arg4.AsInt32(),
         arg5.AsInt32());
 }
Пример #4
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent == DrawEvent.Content)
            {
                using (var graphics = SciterGraphics.Create(args.Handle))
                {
                    graphics.SaveState()
                    .Translate(args.Area.Left, args.Area.Top)
                    .SetLineColor(SciterColor.Create(0, 255, 255, .75f))
                    .SetFillColor(SciterColor.Create(127, 78, 194, .75f))
                    .SetLineWidth(4)
                    .DrawPolygon(
                        PolygonPoint.Create(51.0f, 58.0f),
                        PolygonPoint.Create(70.0f, 28.0f),
                        PolygonPoint.Create(48.0f, 1.0f),
                        PolygonPoint.Create(15.0f, 14.0f),
                        PolygonPoint.Create(17.0f, 49.0f)
                        )
                    .DrawEllipse(200, 50, 50, 50)
                    .RestoreState();
                }

                return(true);
            }
            return(false);
        }
Пример #5
0
        public void TestSciterElement()
        {
            SciterElement el  = SciterElement.Create("div");
            SciterElement el2 = new SciterElement(el._he);

            Assert.IsTrue(el == el2);
        }
Пример #6
0
        protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result)
        {
            switch (name)
            {
            case "Host_Stats":
                Process p = Process.GetCurrentProcess();
                if (_pc == null)
                {
                    _pc = new PerformanceCounter("Process", "% Processor Time", p.ProcessName, true);
                }

                float cpu = 0;
                try
                {
                    cpu = _pc.NextValue();
                }
                catch (Exception ex)
                {
                }

                result           = new SciterValue();
                result["memory"] = new SciterValue(p.WorkingSet64);
                result["cpu"]    = new SciterValue(cpu);
                return(true);
            }

            result = null;
            return(false);
        }
Пример #7
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent != DrawEvent.Content)
            {
                return(false);
            }

            se.Attributes.TryGetValue("fill", out var fillStyle);

            using (var graphics = SciterGraphics.Create(args.Handle))
            {
                var scale = args.Area.Width < args.Area.Height ? args.Area.Width / 300.0f : args.Area.Height / 300.0f;
                se.Attributes.TryGetValue("face", out var clockFace);

                var timeInfo = DateTime.Now;

                switch (clockFace)
                {
                case "swiss":
                    DrawSwissClock(graphics, args.Area, scale, timeInfo);
                    break;

                case "circles":
                    DrawCirclesClock(graphics, args.Area, scale, timeInfo);
                    break;

                default:
                    DrawDefaultClock(graphics, args.Area, scale, timeInfo);
                    break;
                }
            }

            return(true);
        }
Пример #8
0
            protected override ScriptEventResult OnScriptCall(SciterElement element, MethodInfo method, SciterValue[] args)
            {
                var result = base.OnScriptCall(element, method, args);

                _onScriptCallCallback?.Invoke(element, method, args, result);
                return(result);
            }
Пример #9
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent != DrawEvent)
            {
                return(base.OnDraw(se, args));
            }

            //Sciter requires BGRA data, ensure you use the correct SKColorType `Bgra8888`!
            using (var bitmap = new SKBitmap(width: args.Area.Width, height: args.Area.Height, colorType: SKColorType.Bgra8888, alphaType: SKAlphaType.Premul))
                using (var canvas = new SKCanvas(bitmap))
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;

                        canvas.Clear();

                        var colorArray = new SKColor[] { SKColor.Parse("#00FEB775"), SKColor.Parse("#FEB775") };

                        paint.Shader = SKShader.CreateLinearGradient(
                            new SKPoint(args.Area.Width / 2f, 0),
                            new SKPoint(args.Area.Width / 2f, args.Area.Height),
                            colorArray,
                            null,
                            SKShaderTileMode.Clamp);

                        canvas.DrawRect(new SKRect(0, 0, args.Area.Width, args.Area.Height), paint);

                        var img = bitmap.ToSciterImage();
                        var gfx = SciterGraphics.Create(args.Handle);
                        gfx.BlendImage(img, args.Area.Left, args.Area.Top);
                        //return true;
                    }

            return(base.OnDraw(se, args));
        }
Пример #10
0
        protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result)
        {
            result = null;
            switch (name)
            {
            case "Host_DownloadFont":
                string      savefolder = args[0].Get("");
                string      family     = args[1].Get("");
                SciterValue async_cbk  = args[2];
                string      str        = async_cbk.ToString();

                Task.Run(() =>
                {
                    bool res;
                    try
                    {
                        GAPI.DownloadFont(family, savefolder);
                        res = true;
                    }
                    catch (Exception)
                    {
                        res = false;
                    }

                    App.AppHost.InvokePost(() =>
                    {
                        async_cbk.Call(new SciterValue(res));
                    });
                });

                return(true);
            }
            return(false);
        }
Пример #11
0
        public static void Rebuild()
        {
            Stopwatch sw = new Stopwatch();;

            sw.Start();

            Clear();

            if (State.g_el_frameroot.ChildrenCount == 0)
            {
                return;                // you removed the <html> element bastard
            }
            Inspecting.g_dom_count_elem = 0;
            Inspecting.g_dom_count_node = 0;

            SciterElement origin_el_root = State.g_el_frameroot[0];

            Debug.Assert(origin_el_root != null);
            origin_el_root.SetAttribute("omni", "");

            AddElement(el_tree, origin_el_root);

            sw.Stop();

            SciterValue sv = App.AppHost.EvalScript("View.omnidata.show_tree_timing");

            if (sv.Get(false))
            {
                Host._sdh.InternalOutput($"[Omni internal] DOM-tree Rebuild time: {sw.ElapsedMilliseconds}ms");
            }
        }
Пример #12
0
        public bool Host_GoPage(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            string args1 = args[0].Get("");

            result = new SciterValue(args1);
            return(true);
        }
Пример #13
0
        public bool Host_GetMsg(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            var args1 = args[0].Get("");

            result = SciterValue.FromJSONString(args1);
            return(true);
        }
Пример #14
0
        public void RecreateTagPath(uint uid, List <uint> uidstack, List <string> tagpath)
        {
            if (actual_uidstack != null &&
                actual_uidstack.Count >= uidstack.Count &&
                Enumerable.SequenceEqual(uidstack, actual_uidstack.Take(uidstack.Count)))
            {
                var r    = _se.ChildrenCount;
                var rrrr = _se.SelectAll("*");

                var el_li = _se.SelectAll("li").Single(li => li.ExpandoValue["uuid"].Get(-1) == uid);
                el_li.SetState(SciterXDom.ELEMENT_STATE_BITS.STATE_CURRENT);
            }
            else
            {
                ResetTagPath();
                actual_uidstack = uidstack;

                for (int i = 0; i < tagpath.Count; i++)
                {
                    var el_li = SciterElement.Create("li");
                    _se.Append(el_li);

                    el_li.SetHTML("<text>" + tagpath[i] + "</text>");
                    el_li.ExpandoValue["uuid"] = new SciterValue(uidstack[i]);

                    if (uidstack[i] == uid)
                    {
                        el_li.SetState(SciterXDom.ELEMENT_STATE_BITS.STATE_CURRENT);
                    }
                }

                App.AppHost.InvokePost(() => _se.Refresh());
            }
        }
Пример #15
0
        // A dynamic script call handler. Any call in TIScript to function 'view.Host_HelloWorld()' with invoke this method
        // Notice that signature of these handlers is always the same
        // (Hint: install OmniCode snippets which adds the 'ssh' snippet to C# editor so you can easily declare 'Siter Handler' methods)
        // (see: https://github.com/MISoftware/OmniCode-Snippets)
        public bool Host_HelloSciter(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            var stackFrame = new StackTrace(true).GetFrame(0);            //.GetFileName();

            result = SciterValue.Create($"<h2>Hello Sciter from C#!</h2><code>Method: {stackFrame.GetMethod().Name}<br/>File: <a href=\"{new Uri(stackFrame.GetFileName()).AbsoluteUri}\">{Path.GetFileName(stackFrame.GetFileName())}</a><br/>Line: {stackFrame.GetFileLineNumber()}<br/>Column: {stackFrame.GetFileColumnNumber()}</code>");
            return(true);
        }
Пример #16
0
        protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result)
        {
            switch (name)
            {
            case "LoadConfigs":
                result = Config.SciterValue;
                return(true);

            case "LoadShaders":
                result = ShaderRegistry.SciterValue;
                return(true);

            case "ConfigSetInteger":
                result = SetConfigValue(args[0].Get(""), args[1].Get(0));
                return(true);

            case "ConfigSetDouble":
                result = SetConfigValue(args[0].Get(""), args[1].Get(0D));
                return(true);

            case "ConfigSetBoolean":
                result = SetConfigValue(args[0].Get(""), args[1].Get(false));
                return(true);

            case "ConfigSetString":
                result = SetConfigValue(args[0].Get(""), args[1].Get(""));
                return(true);
            }

            result = null;
            return(false);
        }
Пример #17
0
        protected override bool OnDraw(SciterElement se, SciterXBehaviors.DRAW_PARAMS prms)
        {
            if (prms.cmd == SciterXBehaviors.DRAW_EVENTS.DRAW_CONTENT)
            {
                using (SciterGraphics g = new SciterGraphics(prms.gfx))
                {
                    g.StateSave();
                    g.Translate(prms.area.left, prms.area.top);

                    List <Tuple <float, float> > points = new List <Tuple <float, float> >
                    {
                        Tuple.Create(100.0f, 0.0f),
                        Tuple.Create(150.0f, 150.0f),
                        Tuple.Create(50.0f, 150.0f)
                    };

                    g.LineColor = new RGBAColor(0, 0, 255);
                    g.FillColor = new RGBAColor(255, 0, 0);
                    g.LineWidth = 5;
                    g.Polygon(points);
                    g.Ellipse(200, 50, 50, 50);

                    g.StateRestore();
                }

                return(true);
            }
            return(false);
        }
Пример #18
0
 protected override void Detached(SciterElement se)
 {
     if (_thief.IsStealing)
     {
         _thief.StopStealing();
     }
 }
Пример #19
0
        protected override bool OnFocus(SciterElement element, FocusArgs args)
        {
            Debug.WriteLine($"focus-behavior: {args.Event}");

            SciterColor color;

            switch (args.Event)
            {
            case FocusEvents.Got:
                color = SciterColor.CornflowerBlue;
                break;

            case FocusEvents.Lost:
                color = SciterColor.Crimson;
                break;

            default:
                return(base.OnFocus(element, args));
            }

            element
            .SetStyleValue("background-color", $"{color.ToShortHtmlColor()}")
            .SetHtml(SciterElement.Create("div", $"{args.Event}").Html);
            return(base.OnFocus(element, args));
        }
Пример #20
0
 public void Create_with_invalid_handle_throws_ArgumentException()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var sciterElement = new SciterElement(IntPtr.Zero);
     });
 }
Пример #21
0
        protected override bool OnDraw(SciterElement se, DrawArgs args)
        {
            if (args.DrawEvent != DrawEvent)
            {
                return(base.OnDraw(se, args));
            }

            //Sciter requires BGRA data, ensure you use the correct SKColorType `Bgra8888`!
            using (var bitmap = new SKBitmap(width: args.Area.Width, height: args.Area.Height, colorType: SKColorType.Bgra8888, alphaType: SKAlphaType.Premul))
                using (var canvas = new SKCanvas(bitmap))
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        canvas.Clear();

                        paint.Shader = SKShader.CreateRadialGradient(
                            new SKPoint(args.Area.Width / 2f, args.Area.Height / 2f),
                            30f,
                            new SKColor[] { SKColors.Black.WithAlpha(0), SKColors.Green, SKColors.Black.WithAlpha(0), SKColors.Red, SKColors.Black.WithAlpha(0), SKColors.Blue, SKColors.Black.WithAlpha(0) },
                            null,
                            SKShaderTileMode.Mirror);

                        canvas.DrawRect(new SKRect(0, 0, args.Area.Width, args.Area.Height), paint);

                        var img = bitmap.ToSciterImage();
                        var gfx = SciterGraphics.Create(args.Handle);
                        gfx.BlendImage(img, args.Area.Left, args.Area.Top);
                    }

            return(base.OnDraw(se, args));
        }
Пример #22
0
        public void Create_element_from_tag(string tag)
        {
            var element = SciterElement.Create(tag);

            Assert.IsNotNull(element);
            Assert.AreEqual(tag, element.Tag);
        }
Пример #23
0
        public void TestSciterElement()
        {
            SciterElement el  = SciterElement.Create("div");
            SciterElement el2 = SciterElement.Attach(el.Handle);

            Assert.IsTrue(el == el2);
        }
Пример #24
0
        public static void OnPostedContentChange()
        {
            in_content_change = false;

            SciterValue sv = App.AppHost.EvalScript("View.omnidata.dom_tree_disable");

            if (sv.Get(false) == false)
            {
                DOMTree.Rebuild();
            }

            if (g_el_inspected != null)
            {
                // element might have been removed, so restore selection to its closest parent from its parent stack (g_parentstack)
                SciterElement el_sel = null;
                if (g_parentstack != null)
                {
                    foreach (var item in g_parentstack)
                    {
                        IntPtr hwnd;
                        if (SciterX.API.SciterGetElementHwnd(item._he, out hwnd, true) == SciterXDom.SCDOM_RESULT.SCDOM_OK)
                        {
                            el_sel = item;
                            break;
                        }
                    }
                }
                if (el_sel != null)
                {
                    //if(el_sel==g_el_inspected)
                    //	PageElemHighlight(el_sel);// something to test out, it is anoying
                    PageElemInspect(el_sel, true);
                }
            }
        }
Пример #25
0
        protected override bool OnDraw(SciterElement se, SciterXBehaviors.DRAW_PARAMS prms)
        {
            if (_model == null)
            {
                return(false);
            }

            if (prms.cmd == SciterXBehaviors.DRAW_EVENTS.DRAW_CONTENT)
            {
                var pngExporter = new PngExporter()
                {
                    Width      = prms.area.Width,
                    Height     = prms.area.Height,
                    Background = OxyColors.Transparent
                };

                /*using(var ms = new MemoryStream())
                 * {
                 *      var bmp = pngExporter.ExportToBitmap(_model);
                 *
                 *      using(var img = new SciterImage(bmp))
                 *      {
                 *              new SciterGraphics(prms.gfx).BlendImage(img, prms.area.left, prms.area.top);
                 *      }
                 * }*/

                return(true);
            }
            return(false);
        }
Пример #26
0
        /*public bool Host_DaysToExpire(SciterElement el, SciterValue[] args, out SciterValue result)
         * {
         *      result = new SciterValue(Ion.Ion.DaysToExpire);
         *      return true;
         * }*/

        public bool Host_GenerateSVGSprite(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            string sv_outputpath = args[0].Get("");
            var    sv_icons      = args[1];

            sv_icons.Isolate();

            var xml = new SvgSpriteXML();

            foreach (var item in sv_icons.Keys)
            {
                string hash = item.Get("");
                if (!Joiner._iconsByHash.ContainsKey(hash))
                {
                    continue;
                }
                var icon = Joiner._iconsByHash[hash];
                icon.id = sv_icons[hash].Get("");
                xml.AddIcon(icon);
            }
            File.WriteAllText(sv_outputpath, xml.ToXML());

            result = null;
            return(true);
        }
Пример #27
0
        public bool LoadBulk(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            var f_CreateItem = args[0];

            foreach (Icon icon in _iconList.Skip(_bulk_pos))
            {
                if (icon.kind == EIconKind.COLLECTION && !File.Exists(icon.path))
                {
                    continue;
                }

                bool consumed = f_CreateItem.Call(icon.ToSV()).Get(true);
                if (!consumed)
                {
                    break;
                }
                else
                {
                    _bulk_pos++;
                }
            }

            result = null;
            return(true);
        }
Пример #28
0
        /*public bool Host_IsUpdateAvailable(SciterElement el, SciterValue[] args, out SciterValue result)
         * {
         *      var version = UpdateControl.IsUpdateAvailable();
         *      if(version != null)
         *              args[0].Call(new SciterValue(version));
         *      result = null;
         *      return true;
         * }*/

        public bool Host_SaveTempSVG(SciterElement el, SciterValue[] args, out SciterValue result)
        {
            string iconhash = args[0].Get("");
            bool   white    = args[1].Get(false);
            Icon   icn      = Joiner._iconsByHash[iconhash];

            string filepath;

            if (icn.kind == EIconKind.LIBRARY)
            {
                var svg    = SvgXML.FromIcon(icn);
                var factor = 75f / (float)icn.bounds.w;
                svg.Scale(factor);
                var xml = svg.ToXML(white);

                string fname = icn.arr_tags[0].Replace("/", "").Replace("\\", "");
                filepath = _tmp_dir + fname + ".svg";
                File.WriteAllText(filepath, xml);
            }
            else
            {
                filepath = icn.path;
            }

            Debug.Assert(File.Exists(filepath));
            result = new SciterValue(filepath);
            return(true);
        }
Пример #29
0
        protected override bool OnScriptCall(SciterElement se, string name, SciterValue[] args, out SciterValue result)
        {
            result = null;

            if (name == "start_device")
            {
                var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (videoDevices.Count == 0)
                {
                    result = new SciterValue(false);
                }
                else
                {
                    _videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
                    _videoSource.VideoResolution = _videoSource.VideoCapabilities.FirstOrDefault(vc => vc.FrameSize.Width == 640);
                    _videoSource.NewFrame       += NewFrameEventHandler;
                    _videoSource.Start();

                    result = new SciterValue(true);
                }

                return(true);
            }

            return(false);
        }
Пример #30
0
        protected override bool OnDataArrived(SciterElement element, SciterBehaviors.DATA_ARRIVED_PARAMS prms)
        {
            _logger?.LogTrace(
                "{NameOfMethod}(element: {Element}; prms: {Params})", nameof(OnDataArrived),
                element?.Tag, prms);

            return(base.OnDataArrived(element, prms));
        }