Пример #1
0
 public static void AttachAsNextOrToDocument(this IHTMLElement e, IHTMLElement anchor)
 {
     if (anchor == null)
     {
         e.AttachToDocument();
     }
     else
     {
         anchor.insertNextSibling(e);
     }
 }
Пример #2
0
            public void Attach(int x, int y)
            {
                k6is.AttachToDocument();
                piltm.AttachToDocument();

                new k6is().ToBackground(k6is.style);
                k6is.style.backgroundRepeat = "repeat-y";

                MoveTo(x, y);


                Native.Document.onkeydown += Native.DisabledEventHandler;
                Native.Document.onkeydown += new Action <IEvent>(Document_onkeypress);
            }
		public SolitaireDocument(IHTMLElement e)
		{
			Native.Document.body.style.backgroundColor = Color.Black;

			// wpf here
			var clip = new IHTMLDiv();

			clip.style.position = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.relative;
			clip.style.SetSize(TargetCanvas.DefaultWidth, TargetCanvas.DefaultHeight);
			clip.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

			var c = new IHTMLElement(IHTMLElement.HTMLElementEnum.center, clip);

			if (e == null)
				c.AttachToDocument();
			else
				e.insertPreviousSibling(c);

			new TargetCanvas().AttachToContainer(clip);

		}
Пример #4
0
        public static void GenerateView(string[] lines)
        {
            string Status = "";

            var c = new IHTMLElement(IHTMLElement.HTMLElementEnum.center, "");
            var cursor = Native.Document.createElement("blink");
            cursor.innerText = "_";

            var index = 0;
            var index_char = 0;

            var span = new IHTMLSpan();

            var delay_delayed = false;

            Status = "creating actions";
            var Delay = default(System.Action<System.Action, int>);

            Delay = (h, due) => new Timer(

            delegate
            {

                if (delay_delayed)
                    Delay(h, due);
                else
                    h();

            }, due, 0);

            System.Func<string> CurrentLineString = () => (1 + index) + ". " + lines[index].Trim();

            var DeleteChar = default(System.Action);
            var PrintChar = default(System.Action);
            var ChooseLine = default(System.Action);

            DeleteChar =
                () =>
                {
                    index_char--;

                    span.innerText = CurrentLineString().Substring(0, index_char);

                    if (index_char == 0)
                    {
                        ChooseLine();
                    }
                    else
                    {
                        Delay(DeleteChar, 30);
                    }
                };

            PrintChar =
                () =>
                {
                    index_char++;

                    if (index_char < CurrentLineString().Length)
                    {
                        var x = 100;
                        var y = CurrentLineString()[index_char];


                        if (",. \t\n".Contains("" + y))
                            x = 200;


                        if (index_char > 1)
                            span.style.color = Color.None;

                        span.innerText = CurrentLineString().Substring(0, index_char);
                        Delay(PrintChar, x);
                    }
                    else
                    {
                        Delay(DeleteChar, 3000);
                    }
                };

            ChooseLine =
                () =>
                {
                    index = new System.Random().Next() % lines.Length;
                    index_char = 0;
                    span.innerText = "";
                    span.style.color = Color.White;

                    PrintChar();
                };

            Status = "adding to document";

            c.onmouseover +=
                delegate
                {
                    c.style.color = Color.Yellow;
                    delay_delayed = true;
                };

            c.onmouseout +=
                delegate
                {
                    c.style.color = Color.None;
                    delay_delayed = false;
                };


            c.appendChild(span, cursor);
            c.AttachToDocument();

            ChooseLine();
        }
Пример #5
0
        public static void GenerateView(string[] lines)
        {
            string Status = "";

            var c      = new IHTMLElement(IHTMLElement.HTMLElementEnum.center, "");
            var cursor = Native.Document.createElement("blink");

            cursor.innerText = "_";

            var index      = 0;
            var index_char = 0;

            var span = new IHTMLSpan();

            var delay_delayed = false;

            Status = "creating actions";
            var Delay = default(System.Action <System.Action, int>);

            Delay = (h, due) => new Timer(

                delegate
            {
                if (delay_delayed)
                {
                    Delay(h, due);
                }
                else
                {
                    h();
                }
            }, due, 0);

            System.Func <string> CurrentLineString = () => (1 + index) + ". " + lines[index].Trim();

            var DeleteChar = default(System.Action);
            var PrintChar  = default(System.Action);
            var ChooseLine = default(System.Action);

            DeleteChar =
                () =>
            {
                index_char--;

                span.innerText = CurrentLineString().Substring(0, index_char);

                if (index_char == 0)
                {
                    ChooseLine();
                }
                else
                {
                    Delay(DeleteChar, 30);
                }
            };

            PrintChar =
                () =>
            {
                index_char++;

                if (index_char < CurrentLineString().Length)
                {
                    var x = 100;
                    var y = CurrentLineString()[index_char];


                    if (",. \t\n".Contains("" + y))
                    {
                        x = 200;
                    }


                    if (index_char > 1)
                    {
                        span.style.color = Color.None;
                    }

                    span.innerText = CurrentLineString().Substring(0, index_char);
                    Delay(PrintChar, x);
                }
                else
                {
                    Delay(DeleteChar, 3000);
                }
            };

            ChooseLine =
                () =>
            {
                index            = new System.Random().Next() % lines.Length;
                index_char       = 0;
                span.innerText   = "";
                span.style.color = Color.White;

                PrintChar();
            };

            Status = "adding to document";

            c.onmouseover +=
                delegate
            {
                c.style.color = Color.Yellow;
                delay_delayed = true;
            };

            c.onmouseout +=
                delegate
            {
                c.style.color = Color.None;
                delay_delayed = false;
            };


            c.appendChild(span, cursor);
            c.AttachToDocument();

            ChooseLine();
        }
Пример #6
0
        private static void Spawn()
        {
            // this ctor creates a new div which has a text and a button element
            // on mouseover over the color text is changed
            // on pressing the button the next message in text element is displayed


            IStyleSheet.Default.AddRule("img.fx1",
                                        r =>
            {
                r.style.position = IStyle.PositionEnum.absolute;
                r.style.top      = "0";
                r.style.border   = "0";
            });


            Native.css.style.cursorImage = new HTML.Images.FromAssets.cursor01();

            //IStyleSheet.Default.AddRule("*", "cursor: url('" + new HTML.Images.FromAssets.cursor01().src + "'), auto;", 0);

            var img = new HTML.Images.FromAssets._99851426_7f408a6cc3_o_gray {
                className = "fx1"
            };

            var img_up = new HTML.Images.FromAssets.up {
                className = "fx1"
            };
            var img_up_neg = new HTML.Images.FromAssets.up_neg {
                className = "fx1"
            };
            var img_down = new HTML.Images.FromAssets.down {
                className = "fx1"
            };



            img.AttachToDocument();
            img_up.AttachToDocument();
            img_up_neg.AttachToDocument();


            var info_size = new XSize
            {
                width  = 350,
                height = 200
            };

            var info_bg = new IHTMLDiv();

            info_bg.style.SetLocation(60, 60, info_size.width, info_size.height);
            info_bg.style.Opacity = 0.2;
            info_bg.style.zIndex  = 1;
            info_bg.AttachToDocument();

            var info_borders = new IHTMLDiv();

            info_borders.style.SetLocation(60 - 4, 60 - 4, info_size.width + 8, info_size.height + 8);
            info_borders.style.Opacity = 0.2;
            info_borders.style.zIndex  = 4;
            info_borders.AttachToDocument();

            var info_drag_tween = new TweenDataDouble();

            var info_bg_useimage_cookie = new Cookie("setting1");

            var info_bg_useimage = new DynamicProperty <bool>(
                p =>
            {
                info_bg_useimage_cookie.BooleanValue = p.Value;

                if (p.Value)
                {
                    new HTML.Images.FromAssets.up_neg().ToBackground(info_borders.style);
                    new HTML.Images.FromAssets.up_neg().ToBackground(info_bg.style);
                }
                else
                {
                    info_borders.style.backgroundImage = "";
                    info_bg.style.backgroundImage      = "";
                }

                info_drag_tween.Value = 0.5;
            }
                )
            {
                Value = info_bg_useimage_cookie.BooleanValue
            };



            var info_drag = new DragHelper(info_borders);

            info_drag_tween.Value         = 0;
            info_drag_tween.ValueChanged +=
                delegate
            {
                var i = ScriptCoreLib.JavaScript.Runtime.Convert.ToInteger(255 * info_drag_tween.Value);

                if (!info_bg_useimage.Value)
                {
                    info_bg.style.backgroundColor      = Color.FromRGB(i, i, 0);
                    info_borders.style.backgroundColor = Color.FromRGB(i, i, 0);
                }
                else
                {
                    if (i < 1)
                    {
                        i = 1;
                    }

                    info_bg.style.Opacity      = i / 255;
                    info_borders.style.Opacity = i / 255 * 0.5;
                }
            };

            info_borders.style.cursor = IStyle.CursorEnum.move;

            info_borders.onmouseover +=
                delegate
            {
                if (info_drag.IsDrag)
                {
                    return;
                }

                info_drag_tween.Value = 1;
            };



            info_borders.onmouseout +=
                delegate
            {
                if (info_drag.IsDrag)
                {
                    return;
                }

                info_drag_tween.Value = 0;
            };



            var info = new IHTMLDiv();

            info.onmouseover +=
                delegate
            {
                if (info_drag.IsDrag)
                {
                    return;
                }

                info_drag_tween.Value = 0.5;
            };



            info.onmouseout +=
                delegate
            {
                if (info_drag.IsDrag)
                {
                    return;
                }

                info_drag_tween.Value = 0;
            };

            info.style.color      = Color.White;
            info.style.fontFamily = IStyle.FontFamilyEnum.Tahoma;

            Func <string, IHTMLElement> par = texty => new IHTMLElement(IHTMLElement.HTMLElementEnum.p, texty);


            Native.Document.title = "HotPolygon";

            info.innerHTML = @"<h1>HotPolygon</h1>";

            //var preview = new IHTMLImage("assets/HotPolygon/Preview.png");

            //preview.style.Float = IStyle.FloatEnum.right;
            //preview.style.margin = "1em";

            info.appendChild(
                //preview,
                par("This example demonstrates the use of custom cursors, map, area, timed animation, cookies and a custom dialog."),
                par("You can change the background of this page by hovering above the tree or one of the clouds."),
                par("And yes you can drag this dialog at the borders :)"),

                new IHTMLDiv(
                    @"
                    <ul>
                        <li>visit <a href='http://jsc.sf.net/'>jsc homepage</a></li>
                        <li>visit <a href='http://zproxy.wordpress.com/'>blog</a></li>
                    </ul>
                                ")
                );



            var info_option       = new IHTMLInput(HTMLInputTypeEnum.checkbox);
            var info_option_label = new IHTMLLabel("Alternative background", info_option);


            info.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.p, info_option, info_option_label));



            info_option.onclick += i => info_bg_useimage.Value = info_option.@checked;
            info_option.@checked = info_bg_useimage.Value;

            info.style.overflow = IStyle.OverflowEnum.auto;

            info.style.SetLocation(70, 70, info_size.width - 20, info_size.height - 20);
            info.style.zIndex = 5;
            info.AttachToDocument();

            info_drag.DragMove +=
                delegate
            {
                if (info_bg_useimage.Value)
                {
                    info_borders.style.backgroundPosition = (-(info_drag.Position.X - 4)) + "px " + (-(info_drag.Position.Y - 4)) + "px";
                    info_bg.style.backgroundPosition      = (-info_drag.Position.X) + "px " + (-info_drag.Position.Y) + "px";
                }

                info_borders.style.SetLocation(info_drag.Position.X - 4, info_drag.Position.Y - 4);
                info_bg.style.SetLocation(info_drag.Position.X, info_drag.Position.Y);
                info.style.SetLocation(info_drag.Position.X + 10, info_drag.Position.Y + 10);
            };

            info_drag.Position = new Point(60, 60);
            info_drag.Enabled  = true;

            // 416 x 100

            var img_here_src_off =
                new IHTMLImage[]
            {
                new HTML.Images.FromAssets.here0(),
                new HTML.Images.FromAssets.here1(),
                new HTML.Images.FromAssets.here2(),
                new HTML.Images.FromAssets.here3(),
                new HTML.Images.FromAssets.here4(),
                new HTML.Images.FromAssets.here5(),
            };

            var img_here_src_on =
                new IHTMLImage[]
            {
                new HTML.Images.FromAssets.here0(),
                new HTML.Images.FromAssets.here1(),
                new HTML.Images.FromAssets.here2(),
                new HTML.Images.FromAssets.here3(),
                new HTML.Images.FromAssets.here4(),
                new HTML.Images.FromAssets.here5(),
            }.Reverse().ToArray();



            var img_here = new IHTMLDiv();

            img_here.style.SetSize(416, 100);

            Action <Action, int> Wait =
                (done, time) =>
            {
                new Timer(t => done(), time, 0);
            };


            ActionParams <Action, Action> DelayFrames =
                (done, h) =>
            {
                int i = 0;

                var next = default(Action);

                next = () =>
                {
                    if (i < h.Length)
                    {
                        var v = h[i];
                        i++;

                        Wait(() => { if (v != null)
                                     {
                                         v();
                                     }
                                     next(); }, 1000 / 24);
                    }
                    else
                    {
                        Wait(done, 1000 / 24);
                    }
                };

                next();
            };


            var AnimationOn       = default(Action);
            var AnimationOff      = default(Action);
            var AnimationRandomOn = default(Action);


            AnimationOff =
                () =>
            {
                DelayFrames(
                    () =>
                {
                    img_here.style.display = IStyle.DisplayEnum.none;

                    Wait(() =>
                    {
                        AnimationRandomOn();
                    }, 5000);
                }
                    ,
                    img_here_src_off.Select <IHTMLImage, Action>(i => () => i.ToBackground(img_here.style)).ToArray()
                    );
            };

            AnimationOn =
                () =>
            {
                img_here.style.display = IStyle.DisplayEnum.block;

                DelayFrames(
                    () => Wait(AnimationOff, 3000),
                    img_here_src_on.Select <IHTMLImage, Action>(i => () => i.ToBackground(img_here.style)).ToArray()
                    );
            };

            AnimationRandomOn =
                () =>
            {
                try
                {
                    if (new System.Random().NextDouble() > 0.5)
                    {
                        img_here.SetCenteredLocation(589, 509);
                    }
                    else
                    {
                        img_here.SetCenteredLocation(686, 141);
                    }

                    Wait(AnimationOn, new System.Random().Next() % 15000);
                }
                catch
                {
                }
            };


            img_here.style.SetLocation(100, 100);
            img_here.style.zIndex = 1;

            AnimationRandomOn();


            img_here.AttachToDocument();

            img_down.AttachToDocument();

            img_up.style.Opacity     = 0;
            img_up_neg.style.Opacity = 0;

            var tw_up = new TweenDataDouble();

            tw_up.Value         = 0;
            tw_up.ValueChanged += delegate { img_up.style.Opacity = tw_up.Value; };

            var tw_up_neg = new TweenDataDouble();

            tw_up_neg.Value         = 0;
            tw_up_neg.ValueChanged += delegate { img_up_neg.style.Opacity = tw_up_neg.Value; };



            var map = new IHTMLElement(IHTMLElement.HTMLElementEnum.map);

            map.id   = "map1";
            map.name = "map1";

            var area1 = new IHTMLArea
            {
                shape  = ShapeEnum.polygon,
                coords = "477, 178, 515, 144, 557, 160, 576, 194, 614, 181, 629, 206, 648, 209, 659, 163, 719, 154, 730, 103, 845, 118, 891, 168, 949, 213, 917, 246, 931, 266, 859, 300, 787, 302, 756, 274, 721, 294, 658, 282, 615, 257, 537, 239, 492, 230, 470, 195"
            };

            area1.onmouseover += i =>
            {
                System.Console.WriteLine("over");
                tw_up_neg.Value = 1;                          /*tw_down.Value = 0.2;*/
            };
            area1.onmouseout += i =>
            {
                try
                {
                    System.Console.WriteLine("out");
                    tw_up_neg.Value = 0;                        /* tw_down.Value = 1;*/
                }
                catch
                {
                }
            };


            var area2 = new IHTMLArea
            {
                shape  = ShapeEnum.polygon,
                coords = "677, 556, 718, 551, 747, 570, 758, 594, 756, 613, 729, 625, 688, 629, 663, 604, 657, 585"
            };



            area2.onmouseover += i =>
            {
                System.Console.WriteLine("over");
                tw_up.Value = 1;                          /*tw_down.Value = 0.2;*/
            };
            area2.onmouseout += i =>
            {
                try
                {
                    System.Console.WriteLine("out");
                    tw_up.Value = 0;                        /* tw_down.Value = 1;*/
                }
                catch
                {
                }
            };

            img_down.onclick += i => System.Console.WriteLine(i.CursorPosition);

            //area1.href = "http://google.com";
            //area1.target = "_blank";

            map.appendChild(area1);
            map.appendChild(area2);

            map.AttachToDocument();


            img_down.style.zIndex = 2;
            img_down.setAttribute("useMap", "#map1");


            //img_overlay.style.backgroundColor = Color.Red;
        }
Пример #7
0
        /// <summary>
        /// Creates a new control
        /// </summary>
        /// <param name="DataElement">The hidden data element</param>
        public ImageZoomer()
        {
            var Control = new IHTMLElement(IHTMLElement.HTMLElementEnum.center);

            Control.AttachToDocument();

            Control.appendChild( new IHTMLDiv("A simple image zoomer example") );
            Control.appendChild(new IHTMLAnchor("http://valid.tjp.hu/tjpzoom/", "based on tjpZoom"));
            Control.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.p, "Use your mouse wheel to zoom!"));
            Control.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.hr));

            System.Action<string, string> Spawn =
                (src, zoom_src) =>
                {
                    var i = new IHTMLImage(src);

                    i.style.margin = "2px";

                    Control.appendChild(i);

                    // note: image should be loeaded before attaching events on it!


                    i.InvokeOnComplete(
                        (img) => MyMagnifier.CreateClickableMagnifier(i, zoom_src)
                    );
                };

            System.Action<string, string> SpawnFreezable =
                (src, zoom_src) =>
                {
                    var i = new IHTMLImage(src);

                    i.style.margin = "2px";

                    Control.appendChild(i);

                    i.InvokeOnComplete(
                        (img) => MyMagnifier.CreateFreezableMagnifier(i, zoom_src)
                    );
                };

            Control.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.p, "Click to disable or re-enable the magnifier!"));
            new[] {
                "assets/ImageZoomer/boat.jpg",
                "assets/ImageZoomer/boat2.jpg",
                "assets/ImageZoomer/tea.jpg",
                "assets/ImageZoomer/town.jpg",
            }.ForEach( src => Spawn(src, src) );

            Control.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.p, "Click to freeze the magnifier!"));

            SpawnFreezable("assets/ImageZoomer/belchite_bw.jpg", "assets/ImageZoomer/belchite.jpg");
            SpawnFreezable("assets/ImageZoomer/belchite.jpg", "assets/ImageZoomer/belchite_bw_neg.jpg");
            
        }
Пример #8
0
        public static IHTMLElement AttachToDocument(this IHTMLElement.HTMLElementEnum node)
        {
            var e = new IHTMLElement(node);

            e.AttachToDocument();
            return e;
        }
Пример #9
0
        static IHTMLElement ImportStyleSheet(string url)
        {
            Console.WriteLine("importing css at " + url);

            var s = new IHTMLElement(IHTMLElement.HTMLElementEnum.link);

            s.setAttribute("rel", "stylesheet");
            s.setAttribute("type", "text/css");
            s.setAttribute("href", url);

            s.AttachToDocument();

            return s;
        }
        public void Initialize(IHTMLElement Menu, Func<IHTMLImage, string, Type, Action<Type>, IHTMLElement> ConvertImageToControl)
        {
            var List = new IHTMLElement(IHTMLElement.HTMLElementEnum.ol).AttachTo(Menu);

            var ApplicationsWithLoadingImagesQuery =
                from t in Applications
                let assembly = t.Assembly.GetName().Name
                let preview = "assets/" + assembly + "/Preview.png"
                let image = new IHTMLImage(preview)
                orderby t.Name
                select new { t, assembly, preview, image };

            var ApplicationsWithLoadingImages = ApplicationsWithLoadingImagesQuery.ToArray();

            var LoadingMessage = new IHTMLDiv().AttachTo(Menu);

            var DoneLoading = 500.Until(
                t =>
                {
                    var count = ApplicationsWithLoadingImages.Count(i => !i.image.complete);

                    LoadingMessage.innerText = count + " images are still loading...";

                    return (count == 0 || t.Counter == 6);
                }
            );

            Func<Point> GetCenter =
                () => new Point(Native.Window.Width / 2, Native.Window.Height / 2);

            Action<Type> TypeClicked = t => { };

            DoneLoading +=
                delegate
                {
                    var query = from i in ApplicationsWithLoadingImages
                                let hasimage = i.image.complete && i.image.width > 0
                                select new { i.image, i.t, i.assembly, hasimage, i.preview }; ;

                    var WithImages =
                        from i in query
                        where i.hasimage
                        select i;


                    var WithoutImages =
                        from i in query
                        where !i.hasimage
                        select i;

                    #region WithImages
                    DoneLoading = WithImages.ForEachAtInterval(50,
                        v =>
                        {
                            LoadingMessage.innerText = v.t.Name;

                            var href = v.t.Name + ".htm";

                            var r = ConvertImageToControl(v.image, href, v.t, TypeClicked);

                            r.AttachTo(Menu);

                        }
                    );
                    #endregion

                    DoneLoading +=
                        delegate
                        {
                            LoadingMessage.Dispose();

                            var clr = new IHTMLBreak();

                            clr.style.clear = "both";
                            clr.AttachTo(Menu);

                            foreach (var v in WithoutImages)
                            {
                                new IHTMLDiv("image not found: " + v.preview).AttachTo(Menu);
                            }


                            "script".DisposeElementsByTagName();
                            "noscript".DisposeElementsByTagName();

                            
                        };

                };

            TypeClicked +=
                t =>
                {
                    Menu.Dispose();

                    try
                    {
                        Activator.CreateInstance(t);
                    }
                    catch (Exception exc)
                    {
                        Native.Window.alert("Error: " + exc.Message);

                        Menu.AttachToDocument();
                    }
                };

        }