예제 #1
0
        static public void FadeOut(IHTMLElement target, int waittime, int fadetime)
        {
            target.style.Opacity = 1;

            new Timer(
                delegate
            {
                Timer a = null;

                a = new Timer(
                    delegate
                {
                    target.style.Opacity = 1 - (a.Counter / a.TimeToLive);

                    if (a.Counter == a.TimeToLive)
                    {
                        target.Hide();
                    }
                }
                    );


                a.StartInterval(fadetime / 25, 25);
            }
                ).StartTimeout(waittime);
        }
예제 #2
0
        /// <summary>
        /// fades an element and provides async callback
        /// </summary>
        /// <param name="target"></param>
        /// <param name="waittime"></param>
        /// <param name="fadetime"></param>
        /// <param name="done"></param>
        static public void Fade(IHTMLElement target, int waittime, int fadetime, System.Action done)
        {
            // if IE
            target.style.height = target.clientHeight + "px";

            new Timer(
                delegate
            {
                Timer a = null;

                a = new Timer(
                    delegate
                {
                    target.style.Opacity = 1 - (a.Counter / a.TimeToLive);

                    if (a.Counter == a.TimeToLive)
                    {
                        if (done != null)
                        {
                            done();
                        }
                    }
                }
                    );


                a.StartInterval(fadetime / 25, 25);
            }
                ).StartTimeout(waittime);
        }
예제 #3
0
        static public void FadeOut(IHTMLElement target, int waittime, int fadetime)
        {
            target.style.Opacity = 1;

            new Timer(
                delegate
                {
                    Timer a = null;

                    a = new Timer(
                        delegate
                        {

                            target.style.Opacity = 1 - (a.Counter / a.TimeToLive);

                            if (a.Counter == a.TimeToLive)
                            {
                                target.Hide();

                            }

                        }
                    );


                    a.StartInterval(fadetime / 25, 25);
                }
            ).StartTimeout(waittime);
        }
예제 #4
0
        static public void FadeAndRemove(IHTMLElement target, int waittime, int fadetime, params IHTMLElement[] cotargets)
        {
            // if IE
            target.style.height = target.clientHeight + "px";

            new Timer(
                delegate
            {
                Timer a = null;

                a = new Timer(
                    delegate
                {
                    target.style.Opacity = 1 - (a.Counter / a.TimeToLive);

                    if (a.Counter == a.TimeToLive)
                    {
                        target.Orphanize();

                        foreach (IHTMLElement z in cotargets)
                        {
                            z.Orphanize();
                        }
                    }
                }
                    );


                a.StartInterval(fadetime / 25, 25);
            }
                ).StartTimeout(waittime);
        }
예제 #5
0
		static public void FadeIn(this IHTMLElement target, int waittime, int fadetime, Action done)
		{
			// if IE
			target.style.height = target.clientHeight + "px";

			target.style.Opacity = 0;

			waittime.AtDelay(
				delegate
				{
					Timer a = null;

					a = new Timer(
						delegate
						{

							target.style.Opacity = (a.Counter / a.TimeToLive);

							if (a.Counter == a.TimeToLive)
							{
								target.style.Opacity = 1;

								if (done != null)
									done();

							}

						}
						);


					a.StartInterval(fadetime / 25, 25);
				}
			);
		}
예제 #6
0
        public static Timer Interval(System.Action <Timer> e, int i)
        {
            Timer t = new Timer();

            t.Tick += e;
            t.StartInterval(i);

            return(t);
        }
예제 #7
0
        public static void Trigger(this Func<bool> condition, Action done, int interval)
        {
            Timer t = null;

            t = new Timer(
                delegate
                {
                    if (!condition())
                    {
                        t.Stop();

                        done();
                    }
                }
            );

            t.StartInterval(interval);
        }
예제 #8
0
		static public void FadeOut(this IHTMLElement target, int waittime, int fadetime, Action done)
		{
			waittime.AtDelay(
				delegate
				{
					if (null == target)
					{
						done();
						return;
					}

					Timer a = null;

					a = new Timer(
						delegate
						{

							var Opacity = 1.0 - (a.Counter / a.TimeToLive);

							//Native.Document.title = "" + Opacity;

							target.style.Opacity = Opacity;

							if (a.Counter == a.TimeToLive)
							{
								target.style.Opacity = 0;

								if (done != null)
									done();

							}

						}
						);


					a.StartInterval(fadetime / 25, 25);
				}
			);
		}
예제 #9
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            DiagnosticsConsole.ApplicationContent.BindKeyboardToDiagnosticsConsole();

            FormStyler.AtFormCreated =
                s =>
            {
                FormStyler.LikeVisualStudioMetro(s);

                s.TargetOuterBorder.style.borderColor = ScriptCoreLib.JavaScript.Runtime.JSColor.FromRGB(0, 127, 0);
                s.Caption.style.backgroundColor       = ScriptCoreLib.JavaScript.Runtime.JSColor.FromRGB(0, 127, 0);
                s.TargetOuterBorder.style.boxShadow   = "rgba(0, 127, 0, 0.3) 0px 0px 6px 3px";
            };

            //FormStyler.AtFormCreated = FormStyler.LikeWindows3;

            var SidebarIdleWidth = 32;

            var f = new Form {
                Text = "Sidebar"
            };

            GrayScaleRule.InitializeGrayScaleFor("CLRForm");
            f.GetHTMLTarget().className = "CLRForm";


            #region WhileDragging


            Action WhileDragging = null;

            WhileDragging = delegate
            {
                if (f.Left == 0)
                {
                    f.GetHTMLTarget().className = "CLRForm_nohover";
                    f.Text = "Sidebar (docked)";
                }
                else if (f.Capture)
                {
                    f.GetHTMLTarget().className = "";
                    f.Text = "Sidebar (dragging)";
                }
                else
                {
                    f.GetHTMLTarget().className = "CLRForm";
                    f.Text = "Sidebar";
                }
                Native.window.requestAnimationFrame += WhileDragging;
            };
            Native.window.requestAnimationFrame += WhileDragging;
            #endregion


            var c = new Sidebar {
                Dock = DockStyle.Fill
            }.AttachTo(f);

            f.Show();

            Action <int> SetLeftSidebarWidth  =
                w =>
            {
                page.SidebarContainer.style.width = w + "px";
                page.DocumentContent.style.left   = w + "px";
            };

            Action <int> SetRightSidebarWidth =
                w =>
            {
                page.RightSidebarContainer.style.width = w + "px";
                page.DocumentContent.style.right       = w + "px";
            };

            #region LocationChanged
            var LocationChangedDisabled       = false;
            f.LocationChanged +=
                delegate
            {
                if (LocationChangedDisabled)
                {
                    return;
                }

                if (f.Left == 0)
                {
                    return;
                }

                if (f.Right == Native.window.Width)
                {
                    return;
                }

                SetLeftSidebarWidth(SidebarIdleWidth);
                SetRightSidebarWidth(SidebarIdleWidth);

                if (f.Left < SidebarIdleWidth && c.checkBox1.Checked)
                {
                    page.SidebarContainer.style.backgroundColor = JSColor.Blue;
                }
                else
                {
                    page.SidebarContainer.style.backgroundColor = JSColor.Gray;
                }

                if (f.Right > Native.window.Width - SidebarIdleWidth && c.checkBox2.Checked)
                {
                    page.RightSidebarContainer.style.backgroundColor = JSColor.Blue;
                }
                else
                {
                    page.RightSidebarContainer.style.backgroundColor = JSColor.Gray;
                }
            };
            #endregion



            #region Capture
            var tt = new ScriptCoreLib.JavaScript.Runtime.Timer();

            Action AtCapture = null;

            tt.Tick +=
                delegate
            {
                if (LocationChangedDisabled)
                {
                    return;
                }

                if (f.Left == 0)
                {
                    return;
                }

                if (f.Right == Native.window.Width)
                {
                    return;
                }

                if (f.Capture)
                {
                    if (AtCapture != null)
                    {
                        AtCapture();
                    }

                    return;
                }


                if (f.Left < SidebarIdleWidth)
                {
                    if (c.checkBox1.Checked)
                    {
                        var fs = f.Size;

                        SetLeftSidebarWidth(f.ClientSize.Width);
                        f.MoveTo(0, 0);
                        f.SizeTo(f.ClientSize.Width, page.SidebarContainer.clientHeight);
                        f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                        f.MaximumSize = new System.Drawing.Size(Native.window.Width - page.RightSidebarContainer.clientWidth, Native.window.Height);


                        var             done     = false;
                        Action <IEvent> onresize =
                            delegate
                        {
                            if (done)
                            {
                                return;
                            }
                            f.SizeTo(f.ClientSize.Width, page.SidebarContainer.clientHeight);
                            f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                            f.MaximumSize = new System.Drawing.Size(Native.window.Width - page.RightSidebarContainer.clientWidth, Native.window.Height);
                        };

                        Native.window.onresize += onresize;

                        AtCapture = delegate
                        {
                            done = true;

                            AtCapture     = null;
                            f.MinimumSize = new System.Drawing.Size(100, 100);
                            f.SizeTo(fs.Width, fs.Height);
                        };
                    }
                }
                else if (f.Right > (Native.window.Width - SidebarIdleWidth))
                {
                    if (c.checkBox2.Checked)
                    {
                        var fs = f.Size;

                        SetRightSidebarWidth(f.ClientSize.Width);
                        f.MoveTo(page.RightSidebarContainer.offsetLeft, 0);
                        f.SizeTo(f.ClientSize.Width, page.RightSidebarContainer.clientHeight);
                        f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                        f.MaximumSize = new System.Drawing.Size(Native.window.Width, Native.window.Height);

                        var             done     = false;
                        Action <IEvent> onresize =
                            delegate
                        {
                            if (done)
                            {
                                return;
                            }

                            f.MoveTo(page.RightSidebarContainer.offsetLeft, 0);
                            f.SizeTo(f.ClientSize.Width, page.RightSidebarContainer.clientHeight);
                            f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                            f.MaximumSize = new System.Drawing.Size(Native.window.Width, Native.window.Height);
                        };

                        Native.window.onresize += onresize;


                        AtCapture = delegate
                        {
                            done          = true;
                            AtCapture     = null;
                            f.MinimumSize = new System.Drawing.Size(100, 100);
                            f.SizeTo(fs.Width, fs.Height);
                        };
                    }
                }
            };
            tt.StartInterval(100);
            #endregion

            SetLeftSidebarWidth(SidebarIdleWidth);
            SetRightSidebarWidth(SidebarIdleWidth);

            #region SizeChanged
            var PrevRight = 0;

            f.SizeChanged +=
                delegate
            {
                if (LocationChangedDisabled)
                {
                    return;
                }

                if (f.Left == 0)
                {
                    SetLeftSidebarWidth(f.Width);
                }
                else
                {
                    //if (f.Left == page.RightSidebarContainer.offsetLeft)
                    //{
                    //    LocationChangedDisabled = true;
                    //    f.Left = Native.Window.Width - f.Width;
                    //    SetRightSidebarWidth(f.Width);
                    //    LocationChangedDisabled = false;
                    //}
                }

                PrevRight = f.Right;
            };
            #endregion

            #region AtButton1
            Action AtButton1 =
                delegate
            {
                c.button1.Enabled = false;
                c.button2.Enabled = true;

                var cl = f.Location;
                var cs = f.ClientSize;


                var cc = f.GetHTMLTarget();

                var IsLeft = f.Left < (Native.window.Width - f.Width) / 2;

                if (IsLeft)
                {
                    f.MoveTo(0, 0);
                }
                else
                {
                    f.MoveTo(page.RightSidebarContainer.offsetLeft, 0);
                }

                f.FormBorderStyle = FormBorderStyle.None;

                Native.window.requestAnimationFrame +=
                    delegate
                {
                    f.Height = Native.window.Height;
                };

                c.button2.Click +=
                    delegate
                {
                    if (cc == null)
                    {
                        return;
                    }

                    c.button1.Enabled = true;
                    c.button2.Enabled = false;

                    cc.AttachToDocument();


                    cc = null;

                    f.ClientSize = cs;
                    f.Location   = cl;

                    //if (c.checkBox1.Checked)
                    f.FormBorderStyle = FormBorderStyle.Sizable;

                    SetLeftSidebarWidth(SidebarIdleWidth);
                };

                cc.AttachTo(page.SidebarContainer);
            };
            #endregion

            #region button1
            c.button1.Click +=
                delegate
            {
                AtButton1();
            };
            #endregion

            c.button2.Enabled = false;

            c.button3.Click +=
                delegate
            {
                c.checkBox1.Enabled = false;
                c.checkBox2.Enabled = false;
                c.button3.Enabled   = false;

                //f.PopupInsteadOfClosing(
                //    HandleFormClosing: true
                //);
            };

            f.FormClosing +=
                (ss, ee) =>
            {
                if (c.button3.Enabled)
                {
                    // not yet popup mode
                    ee.Cancel = true;
                    if (c.button1.Enabled)
                    {
                        AtButton1();
                    }
                }
            };

            //f.FormClosed +=
            //    delegate
            //    {
            //        Native.Document.body.Clear();

            //        Native.Window.close();
            //    };


            @"Hello world".ToDocumentTitle();
            // Send data from JavaScript to the server tier
            //service.WebMethod2(
            //    @"A string from JavaScript.",
            //    value => value.ToDocumentTitle()
            //);


            //#region snippet http://my.jsc-solutions.net/#TestPackageAsApplication

            //new IHTMLAnchor { "drag me to my.jsc-solutions.net" }.AttachToDocument().With(
            //    dragme =>
            //    {
            //        dragme.style.position = IStyle.PositionEnum.@fixed;
            //        dragme.style.left = "1em";
            //        dragme.style.bottom = "1em";

            //        dragme.AllowToDragAsApplicationPackage();
            //    }
            //);

            //#endregion
        }
        public MineSweeperPanel(int ButtonsX = 15, int ButtonsY = 16, double Mines = 0.2, Assets MyAssets = null)
        {
            if (MyAssets == null)
                MyAssets = Assets.Default;

            Control.style.position = IStyle.PositionEnum.relative;
            Control.style.backgroundColor = Color.FromGray(192);

            MineField = new MineSweeperControl(ButtonsX, ButtonsY, Mines, MyAssets);

            ControlWidth = MineField.Width + 20;
            ControlHeight = MineField.Height + 50;
            Control.style.SetSize(ControlWidth, ControlHeight);

            MineField.Control.AttachTo(Control).style.SetLocation(10, 40);


            var face = new Button(FaceSize, FaceSize);

            face.Source = MyAssets.face_ok;
            face.MouseDownSource = MyAssets.face_ok_down;

            var timer = new RedNumberDisplay(3, 0, MyAssets);


            var actualtimer = new Timer(
                t =>
                {
                    timer.Value = t.Counter;
                }
            );

            MineField.Bang += () =>
            {
                face.Source = MyAssets.face_dead;
                actualtimer.Stop();
            };

            MineField.LookingForMines += () => face.Source = MyAssets.face_scared;
            MineField.DoneLookingForMines += () => face.Source = MyAssets.face_ok;



            face.Click +=
                () =>
                {
                    face.Source = MyAssets.face_ok;

                    actualtimer.Stop();
                    timer.Value = 0;

                    MineField.Reset();
                };

            MineField.AllMinesFound +=
                delegate
                {


                    face.Source = MyAssets.face_cool;
                    actualtimer.Stop();

                    MineField.Alive = false;
                    MineField.DisableButtons();
                };

            face.Control.AttachTo(Control);
            face.Control.style.SetLocation(10 + (MineField.Width - FaceSize) / 2, 6);


            var minecounter = new RedNumberDisplay(3, MineField.MinesTotal, MyAssets);

            minecounter.Control.AttachTo(Control);
            minecounter.Control.style.SetLocation(10, 6);

            timer.Control.AttachTo(Control);
            timer.Control.style.SetLocation(10 + MineField.Width - timer.Width, 6);

            MineField.MinesFoundChanged += () => minecounter.Value = MineField.MinesTotal - MineField.MinesFound;

            MineField.Control.style.border = "1px inset gray";
            minecounter.Control.style.border = "1px inset gray";
            timer.Control.style.border = "1px inset gray";
            this.Control.style.border = "1px outset gray";


            MineField.DoneLookingForMines += () =>
                {
                    if (!actualtimer.IsAlive)
                        actualtimer.StartInterval(1000);
                };

        }
예제 #11
0
        private void Setup(System.Action done)
        {
            t = new Timer();

            var text = new IHTMLInput(HTMLInputTypeEnum.text);

            text.className = "TalkToOthers";

            text.AttachToDocument();

            text.onkeypress += delegate(IEvent x)
            {
                if (x.IsReturn)
                {
                    this.CurrentSession.IServer_TalkToOthers(text.value);
                    this.DisplayNotification(text.value, Color.Blue);

                    text.value = "";
                }
            };

            text.style.zIndex = 1000;

            //Native.Document.body.DisableContextMenu();

            //CreateRotatingTank(96 + 48 * 7, 96 + 48 * 1, t, "tree_1", 383, 392);
            //CreateRotatingTank(96 + 48 * 1, 96 + 48 * 2, t, "tank_1", 308, 339);

            int u = 7;
            System.Action idone = null;

            System.Action<System.Action> adone = delegate(System.Action x)
            {
                if (x != null)
                    idone += x;
                u--;

                if (u == 0)
                {
                    if (idone != null)
                    {
                        idone();
                        idone = null;
                    }

                    //done();

                    //t.StartInterval(100);
                }
            };

            done();
            t.StartInterval(100);

            UnitCache.Of("harvester_1", 71, 71 + 31, 48, 48,
                delegate(UnitCache c)
                {
                    adone(delegate
                    {
                        for (int i = 1; i < 10; i++)
                        {
                            Unit.Of(c, 32 * 7, 24 * i, t, 5);
                        }
                    });
                }
            );


            building_1 = UnitCache.Of("building_1", 365, 365 + 17, 72, 72,
                delegate(UnitCache c)
                {

                    adone(delegate
                    {
                        for (int i = 1; i < 5; i++)
                        {
                            var xu = Unit.Of(c, 32 * 14, 72 * i, t, 2);

                            System.Action To3 = null;
                            System.Action To4 = null;
                            System.Action To1r = null;
                            System.Action To1 = null;

                            To3 = delegate
                            {

                                xu.Cache = building_3;
                                xu.WhenDone = To4;

                            };


                            To1r = delegate
                            {
                                xu.ReverseAnimation = true;
                                xu.Cache = building_1;
                                xu.WhenDone = To1;

                            };

                            To1 = delegate
                           {
                               xu.ReverseAnimation = false;
                               xu.Cache = building_1;
                               xu.WhenDone = To3;

                           };


                            To4 = delegate
                               {
                                   xu.Cache = building_4;
                                   xu.WhenDone = To1r;

                               };

                            xu.WhenDone = To3;
                        }
                    });
                }
            );

            UnitCache.Of("building_2", 1252, 1252 + 15, 48, 48,
                delegate(UnitCache c)
                {
                    adone(delegate
                    {
                        for (int i = 1; i < 10; i++)
                        {
                            Unit.Of(c, 32 * 17, 48 * i, t, 6);

                        }
                    });
                }
            );

            building_4 = UnitCache.Of("building_4", 405, 405 + 17, 72, 72, uc => adone(null));

            building_3 = UnitCache.Of("building_3", 393, 393 + 11, 72, 72, uc => adone(null));

            UnitCache.Of("tank_2", 308, 308 + 31, 24, 24,
               delegate(UnitCache c)
               {
                   adone(delegate
                   {
                       for (int i = 1; i < 10; i++)
                       {
                           Unit.Of(c, 32 * 3, 24 * i, t, 3);
                       }
                   });
               }
            );

            explosion_1 = UnitCache.Of("explosion_1", 990, 1015, 78, 121,
               delegate(UnitCache c)
               {
                   adone(delegate
                   {


                       Native.Document.body.onclick +=
                           delegate(IEvent ev)
                           {
                               int cx = ev.CursorX;
                               int cy = ev.CursorY;

                               UserCreateExplosion(cx, cy);
                           };
                   });
               }
            );

            new IHTMLImage("fx/building/power.png").InvokeOnComplete(
                delegate(IHTMLImage img)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        SpawnAnimation(img, 50 + 48 * i, 200, 48, 72, 0, 23, t);

                    }


                }
            );


            new IHTMLImage("fx/building/cy.png").InvokeOnComplete(
                delegate(IHTMLImage img)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        SpawnAnimation(img, 50 + 72 * i, 300, 72, 72, 0, 34, t);

                    }


                }
            );

            new IHTMLImage("fx/building/barrack.png").InvokeOnComplete(
                    delegate(IHTMLImage img)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            SpawnAnimation(img, 280 + 48 * i, 300, 48, 72, 0, 46, t);

                        }


                    }
                );


            new IHTMLImage("fx/vehicle/veh_cy.png").InvokeOnComplete(
                delegate(IHTMLImage img)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        SpawnAnimation(img, 50 + 48 * i, 400, 48, 48, 0, 31, t);
                    }

                }
            );

            //.InvokeOnComplete(
            //    delegate(IHTMLImage img)
            //    {
            //        this.Explosion = img;

            //        for (int i = 0; i < 3; i++)
            //        {
            //            SpawnAnimation(img, 250 + 48 * i, 200, 78, 121, 0, 25, t);
            //        }

            //    }
            //);
        }
예제 #12
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            DiagnosticsConsole.ApplicationContent.BindKeyboardToDiagnosticsConsole();

            FormStyler.AtFormCreated =
                  s =>
                  {

                      FormStyler.LikeVisualStudioMetro(s);

                      s.TargetOuterBorder.style.borderColor = ScriptCoreLib.JavaScript.Runtime.JSColor.FromRGB(0, 127, 0);
                      s.Caption.style.backgroundColor = ScriptCoreLib.JavaScript.Runtime.JSColor.FromRGB(0, 127, 0);
                      s.TargetOuterBorder.style.boxShadow = "rgba(0, 127, 0, 0.3) 0px 0px 6px 3px";
                  };

            //FormStyler.AtFormCreated = FormStyler.LikeWindows3;

            var SidebarIdleWidth = 32;

            var f = new Form { Text = "Sidebar" };

            GrayScaleRule.InitializeGrayScaleFor("CLRForm");
            f.GetHTMLTarget().className = "CLRForm";


            #region WhileDragging


            Action WhileDragging = null;

            WhileDragging = delegate
            {
                if (f.Left == 0)
                {
                    f.GetHTMLTarget().className = "CLRForm_nohover";
                    f.Text = "Sidebar (docked)";
                }
                else if (f.Capture)
                {
                    f.GetHTMLTarget().className = "";
                    f.Text = "Sidebar (dragging)";
                }
                else
                {
                    f.GetHTMLTarget().className = "CLRForm";
                    f.Text = "Sidebar";

                }
                Native.window.requestAnimationFrame += WhileDragging;
            };
            Native.window.requestAnimationFrame += WhileDragging;
            #endregion


            var c = new Sidebar { Dock = DockStyle.Fill }.AttachTo(f);

            f.Show();

            Action<int> SetLeftSidebarWidth =
                 w =>
                 {
                     page.SidebarContainer.style.width = w + "px";
                     page.DocumentContent.style.left = w + "px";
                 };

            Action<int> SetRightSidebarWidth =
               w =>
               {
                   page.RightSidebarContainer.style.width = w + "px";
                   page.DocumentContent.style.right = w + "px";
               };

            #region LocationChanged
            var LocationChangedDisabled = false;
            f.LocationChanged +=
                delegate
                {
                    if (LocationChangedDisabled)
                        return;

                    if (f.Left == 0)
                        return;

                    if (f.Right == Native.window.Width)
                        return;

                    SetLeftSidebarWidth(SidebarIdleWidth);
                    SetRightSidebarWidth(SidebarIdleWidth);

                    if (f.Left < SidebarIdleWidth && c.checkBox1.Checked)
                        page.SidebarContainer.style.backgroundColor = JSColor.Blue;
                    else
                        page.SidebarContainer.style.backgroundColor = JSColor.Gray;

                    if (f.Right > Native.window.Width - SidebarIdleWidth && c.checkBox2.Checked)
                        page.RightSidebarContainer.style.backgroundColor = JSColor.Blue;
                    else
                        page.RightSidebarContainer.style.backgroundColor = JSColor.Gray;
                };
            #endregion



            #region Capture
            var tt = new ScriptCoreLib.JavaScript.Runtime.Timer();

            Action AtCapture = null;

            tt.Tick +=
                delegate
                {
                    if (LocationChangedDisabled)
                        return;

                    if (f.Left == 0)
                        return;

                    if (f.Right == Native.window.Width)
                        return;

                    if (f.Capture)
                    {
                        if (AtCapture != null)
                            AtCapture();

                        return;
                    }


                    if (f.Left < SidebarIdleWidth)
                    {
                        if (c.checkBox1.Checked)
                        {
                            var fs = f.Size;

                            SetLeftSidebarWidth(f.ClientSize.Width);
                            f.MoveTo(0, 0);
                            f.SizeTo(f.ClientSize.Width, page.SidebarContainer.clientHeight);
                            f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                            f.MaximumSize = new System.Drawing.Size(Native.window.Width - page.RightSidebarContainer.clientWidth, Native.window.Height);


                            var done = false;
                            Action<IEvent> onresize =
                                delegate
                                {
                                    if (done)
                                        return;
                                    f.SizeTo(f.ClientSize.Width, page.SidebarContainer.clientHeight);
                                    f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                                    f.MaximumSize = new System.Drawing.Size(Native.window.Width - page.RightSidebarContainer.clientWidth, Native.window.Height);


                                };

                            Native.window.onresize += onresize;

                            AtCapture = delegate
                            {
                                done = true;

                                AtCapture = null;
                                f.MinimumSize = new System.Drawing.Size(100, 100);
                                f.SizeTo(fs.Width, fs.Height);
                            };
                        }
                    }
                    else if (f.Right > (Native.window.Width - SidebarIdleWidth))
                    {
                        if (c.checkBox2.Checked)
                        {

                            var fs = f.Size;

                            SetRightSidebarWidth(f.ClientSize.Width);
                            f.MoveTo(page.RightSidebarContainer.offsetLeft, 0);
                            f.SizeTo(f.ClientSize.Width, page.RightSidebarContainer.clientHeight);
                            f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                            f.MaximumSize = new System.Drawing.Size(Native.window.Width, Native.window.Height);

                            var done = false;
                            Action<IEvent> onresize =
                                delegate
                                {
                                    if (done)
                                        return;

                                    f.MoveTo(page.RightSidebarContainer.offsetLeft, 0);
                                    f.SizeTo(f.ClientSize.Width, page.RightSidebarContainer.clientHeight);
                                    f.MinimumSize = new System.Drawing.Size(SidebarIdleWidth, Native.window.Height);
                                    f.MaximumSize = new System.Drawing.Size(Native.window.Width, Native.window.Height);
                                };

                            Native.window.onresize += onresize;


                            AtCapture = delegate
                            {
                                done = true;
                                AtCapture = null;
                                f.MinimumSize = new System.Drawing.Size(100, 100);
                                f.SizeTo(fs.Width, fs.Height);
                            };
                        }
                    }
                };
            tt.StartInterval(100);
            #endregion

            SetLeftSidebarWidth(SidebarIdleWidth);
            SetRightSidebarWidth(SidebarIdleWidth);

            #region SizeChanged
            var PrevRight = 0;

            f.SizeChanged +=
                delegate
                {
                    if (LocationChangedDisabled)
                        return;

                    if (f.Left == 0)
                    {
                        SetLeftSidebarWidth(f.Width);
                    }
                    else
                    {
                        //if (f.Left == page.RightSidebarContainer.offsetLeft)
                        //{
                        //    LocationChangedDisabled = true;
                        //    f.Left = Native.Window.Width - f.Width;
                        //    SetRightSidebarWidth(f.Width);
                        //    LocationChangedDisabled = false;
                        //}
                    }

                    PrevRight = f.Right;
                };
            #endregion

            #region AtButton1
            Action AtButton1 =
                delegate
                {
                    c.button1.Enabled = false;
                    c.button2.Enabled = true;

                    var cl = f.Location;
                    var cs = f.ClientSize;


                    var cc = f.GetHTMLTarget();

                    var IsLeft = f.Left < (Native.window.Width - f.Width) / 2;

                    if (IsLeft)
                    {
                        f.MoveTo(0, 0);
                    }
                    else
                    {
                        f.MoveTo(page.RightSidebarContainer.offsetLeft, 0);
                    }

                    f.FormBorderStyle = FormBorderStyle.None;

                    Native.window.requestAnimationFrame +=
                        delegate
                        {
                            f.Height = Native.window.Height;
                        };

                    c.button2.Click +=
                          delegate
                          {
                              if (cc == null)
                                  return;

                              c.button1.Enabled = true;
                              c.button2.Enabled = false;

                              cc.AttachToDocument();


                              cc = null;

                              f.ClientSize = cs;
                              f.Location = cl;

                              //if (c.checkBox1.Checked)
                              f.FormBorderStyle = FormBorderStyle.Sizable;

                              SetLeftSidebarWidth(SidebarIdleWidth);
                          };

                    cc.AttachTo(page.SidebarContainer);
                };
            #endregion

            #region button1
            c.button1.Click +=
                delegate
                {
                    AtButton1();
                };
            #endregion

            c.button2.Enabled = false;

            c.button3.Click +=
                delegate
                {
                    c.checkBox1.Enabled = false;
                    c.checkBox2.Enabled = false;
                    c.button3.Enabled = false;

                    //f.PopupInsteadOfClosing(
                    //    HandleFormClosing: true
                    //);
                };

            f.FormClosing +=
                (ss, ee) =>
                {
                    if (c.button3.Enabled)
                    {
                        // not yet popup mode
                        ee.Cancel = true;
                        if (c.button1.Enabled)
                            AtButton1();

                    }

                };

            //f.FormClosed +=
            //    delegate
            //    {
            //        Native.Document.body.Clear();

            //        Native.Window.close();
            //    };


            @"Hello world".ToDocumentTitle();
            // Send data from JavaScript to the server tier
            //service.WebMethod2(
            //    @"A string from JavaScript.",
            //    value => value.ToDocumentTitle()
            //);


            //#region snippet http://my.jsc-solutions.net/#TestPackageAsApplication

            //new IHTMLAnchor { "drag me to my.jsc-solutions.net" }.AttachToDocument().With(
            //    dragme =>
            //    {
            //        dragme.style.position = IStyle.PositionEnum.@fixed;
            //        dragme.style.left = "1em";
            //        dragme.style.bottom = "1em";

            //        dragme.AllowToDragAsApplicationPackage();
            //    }
            //);

            //#endregion

        }
예제 #13
0
		static public void FadeIn(this IHTMLElement target, int waittime, int fadetime, Action done)
		{
			// if IE
			var c = target.clientHeight;

			if (c < 20)
				c = 20;

			target.style.height = c + "px";

			target.style.Opacity = 0;
			target.style.display = ScriptCoreLib.JavaScript.DOM.IStyle.DisplayEnum.empty;

			waittime.AtDelay(
				delegate
				{
					Timer a = null;

					a = new Timer(
						delegate
						{

							target.style.Opacity = (a.Counter / a.TimeToLive);

							if (a.Counter == a.TimeToLive)
							{
								target.style.Opacity = 1;

								if (done != null)
									done();

							}

						}
						);


					a.StartInterval(fadetime / 25, 25);
				}
			);
		}
예제 #14
0
        public static Timer Interval(System.Action<Timer> e, int i)
        {
            Timer t = new Timer();

            t.Tick += e;
            t.StartInterval(i);

            return t;
        }
예제 #15
0
        public ApplicationContent(
            IApp page = null,
            IApplicationWebServiceX service = null)
        {
            // need absolute path when docked..
            page.style1.href = page.style1.href;

            // first order of business.
            // enable drop zone.
            var dz = new DropZone();


            dz.Container.AttachToDocument();
            dz.Container.Hide();

            var StayAlertTimer = default(Timer);
            var DoRefresh = default(Action);

            #region StayAlert
            Action<string> StayAlert =
                transaction_id =>
                {
                    StayAlertTimer = new Timer(
                        delegate
                        {
                            service.GetTransactionKeyAsync(
                                id =>
                                {
                                    if (id == transaction_id)
                                        return;

                                    // shot down during flight?
                                    if (!StayAlertTimer.IsAlive)
                                        return;

                                    Console.WriteLine("StayAlert " + new { id, transaction_id });

                                    DoRefresh();
                                }
                            );
                        }
                    );

                    StayAlertTimer.StartInterval(5000);
                };
            #endregion


            DoRefresh =
                delegate
                {
                    if (StayAlertTimer != null)
                        StayAlertTimer.Stop();

                    page.output.Clear();

                    new FileLoading().Container.AttachTo(page.output);

                    service.EnumerateFilesAsync(
                        y:
                        (
                            long ContentKey,
                            string ContentValue,
                            string ContentType,
                            long ContentBytesLength
                        ) =>
                        {
                            var e = new FileEntry();

                            #region ContentValue
                            e.ContentValue.value = ContentValue.TakeUntilLastIfAny(".");
                            e.ContentValue.onchange +=
                                delegate
                                {
                                    var ext = ContentValue.SkipUntilLastOrEmpty(".");

                                    if (ext != "")
                                        ext = "." + ext;

                                    ContentValue = e.ContentValue.value + ext;


                                    Console.WriteLine("before update!");

                                    service.UpdateAsync(
                                        ContentKey,
                                        ContentValue,
                                        // null does not really work?
                                        delegate
                                        {
                                            Console.WriteLine("update done!");
                                        }
                                    );

                                    e.open.href = Native.Document.location.href.TakeUntilLastIfAny("/") + "/io/" + ContentKey + "/" + ContentValue;
                                };
                            e.open.href = Native.Document.location.href.TakeUntilLastIfAny("/") + "/io/" + ContentKey + "/" + ContentValue;
                            e.open.target = Target;

                            #endregion

                            e.ContentType.innerText = ContentBytesLength + " bytes " + ContentType;


                            #region Delete
                            e.Delete.WhenClicked(
                                delegate
                                {
                                    //e.ContentValue.style.textDecoration = ""

                                    if (StayAlertTimer != null)
                                        StayAlertTimer.Stop();

                                    e.Container.style.backgroundColor = "red";

                                    service.DeleteAsync(
                                        ContentKey,
                                        delegate
                                        {

                                            DoRefresh();
                                        }
                                    );
                                }
                            );
                            #endregion


                            e.Container.AttachTo(page.output);



                            Console.WriteLine(
                                new { ContentKey, ContentValue, ContentType, ContentBytesLength }
                            );

                        },

                        done: transaction_id =>
                        {
                            Console.WriteLine(new { transaction_id });
                            new FileLoadingDone().Container.AttachTo(page.output);

                            StayAlert(transaction_id);
                        }
                    );
                };

            #region ondrop

            var TimerHide = new Timer(
                delegate
                {
                    dz.Container.Hide();
                }
            );

            Action<DragEvent> ondragover =
                evt =>
                {
                    //Console.WriteLine("ondragover");


                    evt.stopPropagation();
                    evt.preventDefault();

                    // ondragover { type = Files }

                    //foreach (var type in evt.dataTransfer.types)
                    //{
                    //    Console.WriteLine("ondragover " + new { type });
                    //}


                    if (evt.dataTransfer.types.Contains("Files"))
                    {


                        evt.dataTransfer.dropEffect = "copy"; // Explicitly show this is a copy.

                        dz.Container.Show();
                        TimerHide.Stop();
                    }

                    //}

                    //Console.WriteLine(" Native.Document.body.ondragover");
                };

            Native.Document.body.ondragover += ondragover;
            dz.Container.ondragover += ondragover;

            //dz.Container.ondragstart +=
            //    evt =>
            //    {
            //        Console.WriteLine("ondragstart");


            //        evt.stopPropagation();
            //        evt.preventDefault();
            //    };

            dz.Container.ondragleave +=
                 evt =>
                 {
                     //Console.WriteLine("ondragleave");

                     //Console.WriteLine(" dz.Container.ondragleave");

                     evt.stopPropagation();
                     evt.preventDefault();

                     TimerHide.StartTimeout(90);
                 };

            dz.Container.ondrop +=
                evt =>
                {
                    //Console.WriteLine("ondrop");

                    TimerHide.StartTimeout(90);

                    evt.stopPropagation();
                    evt.stopImmediatePropagation();

                    evt.preventDefault();

                    // can we use a webClient yet?
                    var xhr = new IXMLHttpRequest();

                    // does not work for chrome?
                    //xhr.setRequestHeader("WebServiceMethod", "FileStorageUpload");

                    // which server?
                    xhr.open(ScriptCoreLib.Shared.HTTPMethodEnum.POST, "/FileStorageUpload");

                    // http://stackoverflow.com/questions/13870853/how-to-upload-files-in-web-workers-when-formdata-is-not-defined

                    //var c = new WebClient();

                    ////c.UploadData(
                    //c.UploadProgressChanged +=
                    //    (sender, args) =>
                    //    {

                    //    };

                    //c.UploadFileAsync(



                    #region send
                    var d = new FormData();

                    evt.dataTransfer.files.AsEnumerable().WithEachIndex(
                        (f, index) =>
                        {
                            d.append("file" + index, f, f.name);
                        }
                    );

                    xhr.InvokeOnComplete(
                        delegate
                        {
                            Console.WriteLine("upload complete!");

                            DoRefresh();
                        }
                    );

                    var upload = new Uploading();

                    upload.Container.AttachTo(page.output);
                    // http://www.matlus.com/html5-file-upload-with-progress/
                    xhr.upload.onprogress +=
                        e =>
                        {
                            var p = (int)(e.loaded * 100 / e.total) + "%";

                            upload.status = p;

                            Console.WriteLine("upload.onprogress " + new { e.total, e.loaded });
                        };

                    xhr.send(d);
                    #endregion


                    if (StayAlertTimer != null)
                        StayAlertTimer.Stop();



                };
            #endregion




            DoRefresh();
        }
        /// <summary>
        /// Creates a new control
        /// </summary>
        /// <param name="DataElement">The hidden data element</param>
        public SimpleFilmstrip()
        {
            IHTMLDiv Control = new IHTMLDiv();

            Control.style.position = IStyle.PositionEnum.absolute;

            new filmstrip().ToBackground(Control, false);

            //Control.style.background = "url(assets/SimpleFilmstrip/filmstrip.png) no-repeat";
            Control.style.height = "600px";
            Control.style.width = "326px";

            var index = 0;

            var t_icount = default(int);
            var t_interval = default(int);
            var t_iwidth = default(int);
            var t_iheight = default(int);
            var t_feed = default(string);

            var Restart = default(Action);

            var feed = new IHTMLInput(HTMLInputTypeEnum.text,

                new veh_cy().src
                );

            var iwidth = new IHTMLInput(HTMLInputTypeEnum.text, "48");
            var iheight = new IHTMLInput(HTMLInputTypeEnum.text, "48");
            var icount = new IHTMLInput(HTMLInputTypeEnum.text, "32");
            var interval = new IHTMLInput(HTMLInputTypeEnum.text, "50");
            var fps = new IHTMLInput(HTMLInputTypeEnum.text, "24");


            feed.onchange += delegate { Restart(); };
            iwidth.onchange += delegate { Restart(); };
            iheight.onchange += delegate { Restart(); };

            interval.onchange += delegate
            {
                int v = int.Parse(interval.value);

                if (v == 0)
                    return;

                fps.value = "" + (1000 / v);


                Restart();
            };

            icount.onchange += delegate { Restart(); };

            fps.onchange += delegate
            {
                int v = int.Parse(fps.value);

                if (v == 0)
                    return;

                interval.value = "" + (1000 / v);

                Restart();
            };


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

            fieldset.style.width = "30em";

            fieldset.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.legend, "Properties"));

            Func<string, IHTMLElement, IHTMLDiv> AsLabel =
                (string text, IHTMLElement control) =>
                {
                    var label = new IHTMLLabel(text, control);

                    control.style.position = IStyle.PositionEnum.absolute;
                    control.style.left = "8em";

                    return new IHTMLDiv(label, control);
                };

            fieldset.appendChild(AsLabel("feed:", feed));
            fieldset.appendChild(AsLabel("width:", iwidth));
            fieldset.appendChild(AsLabel("height:", iheight));
            fieldset.appendChild(AsLabel("count:", icount));
            fieldset.appendChild(AsLabel("interval:", interval));
            fieldset.appendChild(AsLabel("fps:", fps));


            fieldset.style.position = IStyle.PositionEnum.absolute;
            fieldset.style.top = "320px";

            var image = new IHTMLDiv();




            image.style.position = IStyle.PositionEnum.absolute;
            image.style.top = "52px";
            image.style.left = "32px";


            var t = new Timer();

            t.Tick += delegate
            {

                image.style.backgroundPosition = "-" + (index * t_iwidth) + "px 0px";


                index = (index + 1) % t_icount;
            };

            Restart =
                delegate
                {
                    t_icount = int.Parse(icount.value);
                    t_interval = int.Parse(interval.value);
                    t_iwidth = int.Parse(iwidth.value);
                    t_iheight = int.Parse(iheight.value);
                    t_feed = feed.value;

                    image.style.background = "url(" + t_feed + ") no-repeat";

                    image.style.width = t_iwidth + "px";
                    image.style.height = t_iheight + "px";

                    t.StartInterval(t_interval);
                };

            Restart();

            Control.appendChild(image, fieldset);

            Control.AttachToDocument();

        }
예제 #17
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            #region IsRightScreen || IsLeftScreen
            var IsRightScreen = Native.Document.location.hash == "#/RightScreen";
            var IsLeftScreen = Native.Document.location.hash == "#/LeftScreen";

            if (IsRightScreen || IsLeftScreen)
            {
                if (IsRightScreen)
                {
                    "Right Screen".ToDocumentTitle();
                }

                if (IsLeftScreen)
                {
                    "Left Screen".ToDocumentTitle();
                }

                Native.Document.body.Clear();

                var a = new CSSTransform3DFPSBlueprint.HTML.Pages.App();

                a.Container.AttachToDocument();


                var hud = new IHTMLDiv().AttachToDocument();

                hud.style.position = IStyle.PositionEnum.absolute;
                hud.style.left = "0px";
                hud.style.top = "0px";
                hud.style.right = "0px";
                //hud.style.height = "2em";
                hud.style.zIndex = 1000;
                hud.style.backgroundColor = "rgba(0, 0, 0, 0.5)";
                hud.style.color = JSColor.White;

                var c = new IHTMLCenter { innerText = Native.Document.location.hash }.AttachTo(hud);

                new CSSTransform3DFPSBlueprint.Application().Initialize(a,
                   x =>
                   {
                       // we know that we are packaging this sub page 
                       // in our web app
                       x.floorplan.deskCube22.LeftWallSource = "/__Templates";
                       x.floorplan.deskCube22.LeftWallSourceAutoLoad = true;


                       var w = CSSTransform3DFPSBlueprint.Application.window;


                       var du = true;
                       var qx = new delta();
                       var qy = new delta();
                       var qz = new delta();
                       var qp = new delta();

                       x.AfterKeystateChange +=
                        delegate
                        {
                            var data = new XElement("keyState",
                                new XAttribute("w", "" + w.keyState.forward),
                                new XAttribute("s", "" + w.keyState.backward),
                                new XAttribute("a", "" + w.keyState.strafeleft),
                                new XAttribute("d", "" + w.keyState.straferight)
                            );

                            Native.Window.opener.With(
                                parent =>
                                {
                                    //c.innerText = data.ToString();

                                    parent.postMessage(data.ToString());
                                }
                            );

                        };

                       x.AfterCameraRotationChange +=
                           delegate
                           {
                               var data = new XElement("viewport.camera.rotation",
                                   new XAttribute("x", "" + w.viewport.camera.rotation.x),
                                   new XAttribute("y", "" + w.viewport.camera.rotation.y),
                                   new XAttribute("z", "" + w.viewport.camera.rotation.z)
                               );

                               Native.Window.opener.With(
                                   parent =>
                                   {
                                       //c.innerText = data.ToString();

                                       parent.postMessage(data.ToString());
                                   }
                               );

                           };

                       Func<string, bool> bool_Parse =
                           xx =>
                           {
                               return xx.ToLower() == "true";
                           };

                       Native.Window.onmessage +=
                            e =>
                            {
                                var data = XElement.Parse("" + e.data);

                                #region shared.perspective
                                if (data.Name.LocalName == "shared.perspective")
                                {
                                    w.viewport.node.style.width = "200%";

                                    if (IsRightScreen)
                                    {
                                        w.viewport.node.style.marginLeft = "-100%";

                                    }


                                    CSSTransform3DFPSBlueprint.Application.window.viewport.node.style.marginTop = "-25%";
                                    w.viewport.node.style.height = "150%";






                                    //if (IsRightScreen)
                                    //{
                                    //}
                                }
                                #endregion

                                var hasupdate = true;

                                if (data.Name.LocalName == "keyState")
                                {
                                    w.keyState.forward = bool_Parse(data.Attribute("w").Value);
                                    w.keyState.backward = bool_Parse(data.Attribute("s").Value);
                                    w.keyState.strafeleft = bool_Parse(data.Attribute("a").Value);
                                    w.keyState.straferight = bool_Parse(data.Attribute("d").Value);


                                }


                                if (data.Name.LocalName == "viewport.camera.rotation")
                                {
                                    new
                                    {
                                        x = int.Parse(data.Attribute("x").Value),
                                        y = int.Parse(data.Attribute("y").Value),
                                        z = int.Parse(data.Attribute("z").Value)
                                    }.With(
                                        r =>
                                        {
                                            w.viewport.camera.rotation.x = r.x;
                                            w.viewport.camera.rotation.y = r.y;
                                            w.viewport.camera.rotation.z = r.z;

                                        }
                                    );
                                }

                                if (data.Name.LocalName == "ChangeRotationBy")
                                {
                                    new
                                    {
                                        x = int.Parse(data.Attribute("x").Value),
                                        y = int.Parse(data.Attribute("y").Value),
                                    }.With(
                                        r =>
                                        {
                                            w.viewport.camera.rotation.x -= r.y;
                                            w.viewport.camera.rotation.z += r.x;

                                        }
                                    );
                                }


                                if (data.Name.LocalName == "range")
                                {
                                    qx.newvalue = int.Parse(data.Attribute("x").Value);
                                    qy.newvalue = int.Parse(data.Attribute("y").Value);
                                    qz.newvalue = int.Parse(data.Attribute("z").Value);
                                    var s = int.Parse(data.Attribute("s").Value) / 50.0;

                                    s *= s;
                                    s *= s;

                                    qp.newvalue = int.Parse(data.Attribute("p").Value);

                                    if (du)
                                    {
                                        qx.oldvalue = qx.newvalue;
                                        qy.oldvalue = qy.newvalue;
                                        qz.oldvalue = qz.newvalue;
                                        qp.oldvalue = qp.newvalue;
                                        du = false;
                                    }
                                    else
                                    {
                                        hasupdate = false;

                                        if (qx.newvalue != qx.oldvalue)
                                        {
                                            qx.dx = qx.newvalue - qx.oldvalue;
                                            qx.oldvalue = qx.newvalue;
                                            w.viewport.camera.rotation.x -= qx.dx * 0.2 * s;
                                            hasupdate = true;
                                        }

                                        if (qy.newvalue != qy.oldvalue)
                                        {
                                            qy.dx = qy.newvalue - qy.oldvalue;
                                            qy.oldvalue = qy.newvalue;

                                            var newy = w.viewport.camera.rotation.y - qy.dx * 0.1 * s;

                                            //Console.WriteLine(
                                            //     new
                                            //     {
                                            //         w.viewport.camera.rotation.y,
                                            //         newy
                                            //     }
                                            //);

                                            // { y = 0.09999999999999937, newy = -6.38378239159465e-16 }
                                            //-6.38378239159465e-16
                                            // small values cause an anomaly?
                                            if (Math.Abs(newy) < 0.05)
                                                w.viewport.camera.rotation.y = 0;
                                            else
                                                w.viewport.camera.rotation.y = newy;
                                            hasupdate = true;
                                        }

                                        if (qz.newvalue != qz.oldvalue)
                                        {
                                            qz.dx = qz.newvalue - qz.oldvalue;
                                            qz.oldvalue = qz.newvalue;
                                            w.viewport.camera.rotation.z -= qz.dx * 0.5 * s;
                                            hasupdate = true;
                                        }


                                        if (qp.newvalue != qp.oldvalue)
                                        {
                                            //qz.dx = qz.newvalue - qz.oldvalue;
                                            qp.oldvalue = qp.newvalue;
                                            w.viewport.node.style.perspective = "" + (500 + qp.newvalue * 4 * s);
                                            hasupdate = true;
                                        }
                                    }



                                }

                                //c.innerText = new { data, dx, newvalue, oldvalue }.ToString();

                                if (hasupdate)
                                    c.innerText = data.ToString();


                                //oldvalue = newvalue;
                                //w.viewport.camera.rotation.x -= e.movementY / 2;

                            };
                   }
               );




                return;
            }
            #endregion

            Action range_onchange = delegate
            {
            };

            #region bind
            Action<IHTMLButton, string, Action<IWindow, XElement>> bind =
                (btn, hash, yield) =>
                {
                    btn.onclick +=
                        delegate
                        {
                            btn.disabled = true;

                            var w = Native.Window.open(
                                hash,
                                "_blank",
                                400,
                                300,
                                false
                            );

                            w.focus();

                            w.onload +=
                                delegate
                                {
                                    Action onchange =
                                        delegate
                                        {


                                            //                       JellyworldExperiment.DualView.Application+<>c__DisplayClassc+<>c__DisplayClass14+<>c__DisplayClass16+<>c__DisplayClass18
                                            //script: error JSC1000: Method: <.ctor>b__7, Type: JellyworldExperiment.DualView.Application+<>c__DisplayClassc+<>c__DisplayClass14+<>c__DisplayClass16+<>c__DisplayClass18; emmiting failed : System.ArgumentNullException: Value cannot be null.
                                            //   at jsc.ILFlowStackItem.InlineLogic(   )
                                            //   at  .    .    ( ?   ,    , ILInstruction , ILFlowStackItem )
                                            //   at  .    .    ( ?   ,    , ILInstruction , ILFlowStackItem )
                                            //   at  . ?  .    (   , ILInstruction , ILFlowStackItem[] , Int32 , MethodBase )

                                            var xml = new XElement("range",
                                              new XAttribute("x", page.range_x.value),
                                              new XAttribute("y", page.range_y.value),
                                              new XAttribute("z", page.range_z.value),
                                              new XAttribute("s", page.range_s.value),
                                              new XAttribute("p", page.range_p.value)
                                          );

                                            w.postMessage(xml.ToString());

                                        };

                                    onchange();

                                    page.range_x.onchange +=
                                        delegate
                                        {
                                            onchange();
                                        };
                                    page.range_y.onchange +=
                                        delegate
                                        {
                                            onchange();
                                        };
                                    page.range_z.onchange +=
                                        delegate
                                        {
                                            onchange();
                                        };
                                    page.range_s.onchange +=
                                     delegate
                                     {
                                         onchange();
                                     };

                                    page.range_p.onchange +=
                                        delegate
                                        {
                                            onchange();
                                        };

                                    range_onchange += onchange;

                                    Native.Window.onmessage +=
                                         e =>
                                         {
                                             if (e.source != w)
                                                 return;

                                             var data = XElement.Parse("" + e.data);

                                             yield(w, data);

                                         };

                                    yield(w, null);
                                };
                        };


                };
            #endregion

            #region do bind
            var wLeftScreen = default(IWindow);
            var wRightScreen = default(IWindow);

            bind(page._LeftScreen, "#/LeftScreen",
                (w, data) =>
                {
                    if (wLeftScreen == null)
                    {
                        wLeftScreen = w;

                        w.onbeforeunload +=
                            delegate
                            {
                                page._LeftScreen.innerText = "closed";
                            };

                        Native.Window.onbeforeunload +=
                            delegate
                            {
                                wLeftScreen.close();
                            };
                    }


                    if (data != null)
                    {
                        page._LeftScreen.innerText = data.ToString();

                        if (wRightScreen != null)
                        {
                            wRightScreen.postMessage(data.ToString());
                        }
                    }
                }
            );

            bind(page._RightScreen, "#/RightScreen",
                (w, data) =>
                {
                    if (wRightScreen == null)
                    {
                        wRightScreen = w;

                        w.onbeforeunload +=
                             delegate
                             {
                                 page._RightScreen.innerText = "closed";
                             };


                        Native.Window.onbeforeunload +=
                            delegate
                            {
                                wRightScreen.close();
                            };
                    }

                    if (data != null)
                    {
                        page._RightScreen.innerText = data.ToString();


                        if (wLeftScreen != null)
                        {
                            wLeftScreen.postMessage(data.ToString());
                        }
                    }
                }
            );
            #endregion

            page._SharedPerspective.onclick +=
                delegate
                {
                    var data = new XElement("shared.perspective", "dummy");

                    if (wLeftScreen != null)
                        wLeftScreen.postMessage(data.ToString());

                    if (wRightScreen != null)
                        wRightScreen.postMessage(data.ToString());


                };

            forward = false;
            backward = false;
            strafeleft = false;
            straferight = false;

            this.AfterKeystateChange =
                delegate
                {
                    var data = new XElement("keyState",
                           new XAttribute("w", "" + forward),
                           new XAttribute("s", "" + backward),
                           new XAttribute("a", "" + strafeleft),
                           new XAttribute("d", "" + straferight)
                       );

                    Console.WriteLine("AfterKeystateChange: " + data);

                    if (wLeftScreen != null)
                        wLeftScreen.postMessage(data.ToString());

                    if (wRightScreen != null)
                        wRightScreen.postMessage(data.ToString());

                };

            ChangeRotationBy =
                (x, y) =>
                {
                    var data = new XElement("ChangeRotationBy",
                        new XAttribute("x", "" + x),
                        new XAttribute("y", "" + y)
                    );

                    Console.WriteLine("AfterKeystateChange: " + data);

                    if (wLeftScreen != null)
                        wLeftScreen.postMessage(data.ToString());

                    if (wRightScreen != null)
                        wRightScreen.postMessage(data.ToString());
                };

            #region onkeydown
            Native.Document.body.onkeydown += e =>
            {
                //Console.WriteLine(new { e.KeyCode });

                if (e.KeyCode == (int)Keys.W)
                    forward = true;
                if (e.KeyCode == (int)Keys.S)
                    backward = true;
                if (e.KeyCode == (int)Keys.A)
                    strafeleft = true;
                if (e.KeyCode == (int)Keys.D)
                    straferight = true;

                if (AfterKeystateChange != null)
                    AfterKeystateChange();
            };

            Native.Document.body.onkeyup += e =>
            {
                if (e.KeyCode == (int)Keys.W)
                    forward = false;
                if (e.KeyCode == (int)Keys.S)
                    backward = false;

                if (e.KeyCode == (int)Keys.A)
                    strafeleft = false;
                if (e.KeyCode == (int)Keys.D)
                    straferight = false;

                if (AfterKeystateChange != null)
                    AfterKeystateChange();
            };
            #endregion

            #region FaceDetectedAt

            var attimer = false;
            ScriptCoreLib.JavaScript.Runtime.Timer t = null;

            FaceDetectedAt =
                (Left, Top, Width, Height) =>
                {
                    page.SimulateFace.disabled = true;

                    var f = new { Left, Top, Width, Height };


                    if (t != null)
                        t.Stop();

                    t = new ScriptCoreLib.JavaScript.Runtime.Timer(
                        delegate
                        {
                            attimer = true;
                            FaceDetectedAt(Left, Top, Width, Height);
                        }
                    );

                    t.StartInterval(1000 / 100);

                    page.range_x.value = "" + (100 - Math.Max(0, (100 * f.Top / (Native.Window.Height - f.Height))).Min(100));

                    //Console.WriteLine(new { f, page.range_x.value });

                    var range_y_old = int.Parse(page.range_y.value);
                    var range_z_old = int.Parse(page.range_z.value);
                    var range_z_new =
                        (int)(100.0 * f.Left / (Native.Window.Width - f.Width)).Max(0).Min(100);

                    page.range_z.value = "" + range_z_new;

                    if (range_z_old == range_z_new)
                    {
                        if (attimer)
                        {
                            attimer = false;

                            if (range_y_old != 50)
                            {
                                if (range_y_old > 50)
                                    page.range_y.value = "" + (int)(range_y_old - 1);
                                else
                                    page.range_y.value = "" + (int)(range_y_old + 1);
                            }
                        }
                    }
                    else
                    {
                        //var range_y_new = (Math.Sign(range_z_old - range_z_new) * 4 + range_y_old).Min(100).Max(0);

                        //page.range_y.value = "" + range_y_new;
                    }


                    range_onchange();
                };
            #endregion


            Native.Document.body.onmousedown +=
                e =>
                {
                    if (e.Element != page.AskForDragPermission)
                        if (e.Element != Native.Document.body)
                        {
                            return;
                        }

                    e.preventDefault();

                    Native.Document.body.requestPointerLock();
                };

            Native.Document.body.onmousemove +=
                e =>
                {
                    if (Native.Document.pointerLockElement != Native.Document.body)
                        return;


                    this.ChangeRotationBy(
                        e.movementX,
                        e.movementY
                    );

                };

            Native.Document.body.onmouseup +=
               e =>
               {
                   if (Native.Document.pointerLockElement != Native.Document.body)
                       return;

                   Native.Document.exitPointerLock();
               };


            page.SimulateFace.onclick +=
                delegate
                {
                    page.SimulateFace.disabled = true;

                    new Form { Text = "Simulated Face Detection" }.With(
                        f =>
                        {
                            f.LocationChanged +=
                                delegate
                                {
                                    FaceDetectedAt(f.Left, f.Top, f.Width, f.Height);
                                };

                            f.SizeChanged +=
                                delegate
                                {
                                    FaceDetectedAt(f.Left, f.Top, f.Width, f.Height);
                                };

                        }
                    ).Show();


                };
        }
예제 #18
0
        static public void FadeAndRemove(IHTMLElement target, int waittime, int fadetime, params IHTMLElement[] cotargets)
        {
            // if IE
            target.style.height = target.clientHeight + "px";

            new Timer(
                delegate
                {
                    Timer a = null;

                    a = new Timer(
                        delegate
                        {

                            target.style.Opacity = 1 - (a.Counter / a.TimeToLive);

                            if (a.Counter == a.TimeToLive)
                            {

                                target.Orphanize();

                                foreach (IHTMLElement z in cotargets)
                                    z.Orphanize();

                                
                                
                            }

                        }
                        );


                    a.StartInterval(fadetime / 25, 25);
                }
            ).StartTimeout(waittime);
        }
예제 #19
0
        /// <summary>
        /// fades an element and provides async callback
        /// </summary>
        /// <param name="target"></param>
        /// <param name="waittime"></param>
        /// <param name="fadetime"></param>
        /// <param name="done"></param>
        static public void Fade(IHTMLElement target, int waittime, int fadetime, System.Action done)
        {
            // if IE
            target.style.height = target.clientHeight + "px";

            new Timer(
                delegate
                {
                    Timer a = null;

                    a = new Timer(
                        delegate
                        {

                            target.style.Opacity = 1 - (a.Counter / a.TimeToLive);

                            if (a.Counter == a.TimeToLive)
                            {
                                if (done != null)
                                    done();

                            }

                        }
                        );


                    a.StartInterval(fadetime / 25, 25);
                }
            ).StartTimeout(waittime);
        }
예제 #20
0
        /// <summary>
        /// Creates a new control
        /// </summary>
        /// <param name="DataElement">The hidden data element</param>
        public LightsOut2(IHTMLElement DataElement)
        {

            // based on http://www.cjcraft.com/Blog/PermaLink,guid,5c35b1f1-dc66-4d85-ac04-22fc97503d4a.aspx

            // what happens in beta2 when the anonymous types are immutable? :)


            var usersettings = new  { x = 5, y = 5, tile = new  { w = 64, h = 64, cold = 0.8 } };

    
            var a = new Array2D<IHTMLDiv>(usersettings.x, usersettings.y);
            var m = a.ToBooleanArray();



            var r = new System.Random();

            m.ForEach(
                (x, y) =>
                {
                    m[x, y] = r.NextDouble() > 0.5;
                }
            );


            var canvas = new IHTMLDiv();

            canvas.className = "canvas";

            var canvas_size = new __Type1 { x = ((a.XLength + 1) * usersettings.tile.w), y = ((a.YLength + 1) * usersettings.tile.h) };

            canvas.style.position = IStyle.PositionEnum.relative;
            canvas.style.border = "2px solid black";
            canvas.style.width = canvas_size.x + "px";
            canvas.style.height = canvas_size.y + "px";

            var canvas_bg = new IHTMLDiv();
            //var canvas_bg_tween = new TweenDataDouble();

            //canvas_bg_tween.Value = 1;
            //canvas_bg_tween.ValueChanged += delegate { canvas_bg.style.Opacity = canvas_bg_tween.Value; };

            new HTML.Images.FromAssets.background().ToBackground(canvas_bg.style);
            //canvas_bg.style.backgroundImage = Assets.Default.Background.StyleSheetURL;
            canvas_bg.style.SetLocation(0, 0, canvas_size.x * 2, canvas_size.y);

            canvas.appendChild(canvas_bg);


            IStyleSheet.Default.AddRule(".info").style
                .Aggregate(s =>
                               {
                                   s.backgroundColor = Color.Black;
                                   s.color = Color.White;
                                   s.padding = "2em";
                                   s.fontFamily = IStyle.FontFamilyEnum.Tahoma;
                                   s.Float = IStyle.FloatEnum.right;
                               })
                ;

            IStyleSheet.Default.AddRule(".canvas").style
                .Aggregate(s => s.overflow = IStyle.OverflowEnum.hidden)
                .Aggregate(s => s.backgroundColor = Color.Black)
                ;

            IStyleSheet.Default.AddRule(".on").style
                .Aggregate(s =>
                    
                        new HTML.Images.FromAssets.vistaLogoOn().ToBackground(s)
                    
                   )
                //.Aggregate(s => s.Opacity = 0.8)
                ;

            IStyleSheet.Default.AddRule(".off").style
                .Aggregate(s => 
                    
                        new HTML.Images.FromAssets.vistaLogoOff().ToBackground(s)
                    
                  )
                //.Aggregate(s => s.Opacity = 0.5)
                ;




            Action<int, int> UpdateColor =
                (x, y) =>
                {
                    var n = a[x, y];

                    if (m[x, y])
                    {
                        n.className = "on";
                    }
                    else
                    {
                        n.className = "off";
                    }

                };

            Action<int, int> ToggleDirect =
                (x, y) =>
                {
                    var n = a[x, y];

                    if (n == null)
                        return;

                    m[x, y] = !m[x, y];
                    UpdateColor(x, y);
                };

            Action<int, int> Toggle =
                (x, y) =>
                {
                    //Console.WriteLine("click at: " + new { x, y } + " = " + m[x, y]);

                    var f = ToggleDirect.WithOffset(x, y);

                    f(-1, 0);
                    f(0, -1);
                    f(0, 0);
                    f(0, 1);
                    f(1, 0);
                };


            var info_stats_clicks = new IHTMLDiv();
            var info_stats_clicks_count = 0;
            var info_stats_off = new IHTMLDiv();
            var info_stats_on = new IHTMLDiv();

            Action info_stats_update =
                () =>
                {
                    info_stats_clicks.innerHTML = info_stats_clicks_count + " clicks made so far";
                    info_stats_on.innerHTML = m.Count(i => i) + " blocks are on";
                    info_stats_off.innerHTML = m.Count(i => !i) + " blocks are off";

                };

            var info_stats = new IHTMLDiv(info_stats_clicks, info_stats_off, info_stats_on);
            info_stats.className = "info";


            a.ForEach(
                (x, y) =>
                {
                    var n = new IHTMLDiv();

                    n.style.left = (x * usersettings.tile.w + usersettings.tile.w / 2) + "px";
                    n.style.top = (y * usersettings.tile.h + usersettings.tile.h / 2) + "px";
                    n.style.width = usersettings.tile.w + "px";
                    n.style.height = usersettings.tile.h + "px";
                    n.style.position = IStyle.PositionEnum.absolute;
                    n.style.overflow = IStyle.OverflowEnum.hidden;

                    //n.style.border = "1px solid black";
                    n.style.cursor = IStyle.CursorEnum.pointer;

                    canvas.appendChild(n);

                    var tween = new TweenDataDouble();


                    tween.ValueChanged += () => n.style.Opacity = tween.Value;
                    tween.Value = usersettings.tile.cold;

                    n.style.Opacity = tween.Value;

                    n.onmouseover += delegate
                    {
                        tween.Value = 1;
                        //canvas_bg_tween.Value = 0.5;
                    };

                    n.onmouseout += delegate
                    {
                        tween.Value = usersettings.tile.cold;
                        //canvas_bg_tween.Value = 1;
                    };

                    n.onclick += delegate
                    {
                        info_stats_clicks_count++;

                        Toggle(x, y);


                        info_stats_update();
                    };


                    a[x, y] = n;

                    UpdateColor(x, y);

                }
            );

            var ani = new Timer(t =>
                               canvas_bg.style.left = -(int)System.Math.Floor((double)((IDate.Now.getTime() / 75) % canvas_size.x)) + "px");




            var info = new IHTMLDiv();

            var info_header_text = "Lights out 2";

            Native.Document.title = info_header_text;

            info.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.h1, info_header_text));

            info.appendChild(new IHTMLAnchor("http://www.cjcraft.com/Blog/PermaLink,guid,5c35b1f1-dc66-4d85-ac04-22fc97503d4a.aspx", "based on SilverlightsOut"));
            info.appendChild(new IHTMLBreak());
            info.appendChild(new IHTMLAnchor("http://www.cjcraft.com/Blog/CommentView,guid,5c35b1f1-dc66-4d85-ac04-22fc97503d4a.aspx", "cjcraft blog post"));

            info.appendChild(new IHTMLElement(IHTMLElement.HTMLElementEnum.p,
                @"Lights out is a one player puzzle that is played on a 5 by 5 grid of squares in which every square has two states: on and off. The game starts off with all squares off, where the goal is to turn on every square. By selecting a square, all the surrounding squares' (up, down, left, right) state is turned toggled. For example, on a 3 by 3 grid of squares with all squares off, if the center one is selected, it will turn 'on' the 4 up, down, left, right squares from it."));

            info.appendChild(new IHTMLDiv("Mozilla based browsers seem to suffer in performance while animating contents under semitransparent elements."));

            info.appendChild(new IHTMLButton("Animate background").Aggregate(btn => btn.onclick += delegate { ani.StartInterval(50); }));
            info.appendChild(new IHTMLButton("Freeze background").Aggregate(btn => btn.onclick += delegate { ani.Stop(); }));
            info.appendChild(info_stats);
            info.appendChild(canvas);

            info_stats_update();

            DataElement.insertNextSibling(info);

        }
예제 #21
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            var random = new Random();
            device_id = random.Next();

            #region con
            var con = new ConsoleForm();

            con.InitializeConsoleFormWriter();
            con.StartPosition = FormStartPosition.Manual;
            con.Show();

            // make it slim
            con.Height = 100;

            // TopMost
            con.GetHTMLTarget().style.zIndex = 20002;
            con.Opacity = 0.9;




            Action Toggle =
                delegate
                {
                    if (con.WindowState == FormWindowState.Minimized)
                    {
                        con.WindowState = FormWindowState.Normal;

                    }
                    else
                    {
                        con.WindowState = FormWindowState.Minimized;


                    }

                    // put the console far right bottom
                    con.MoveTo(
                        Native.window.Width - con.Width,
                        Native.window.Height - con.Height
                    );

                };

            Action<int> AtKeyCode =
               KeyCode =>
               {
                   Console.WriteLine(
                       new { KeyCode }

                   );



                   // US
                   if (KeyCode == 222)
                   {
                       Toggle();
                   }
                   // EE
                   if (KeyCode == 192)
                   {
                       Toggle();
                   }
               };


#if onorientationchange
            Native.window.onorientationchange +=
                e =>
                {
                    Toggle();
                };
#endif

            Native.document.onkeyup +=
                e =>
                {
                    AtKeyCode(e.KeyCode);

                };

            Toggle();
            #endregion

            Console.WriteLine("console ready for " + new { id = device_id });

            var x = 0;
            var y = 0;

            #region Virtual Screen
            FormStyler.AtFormCreated = LikeDesktop;
            var fs = new Form { };

            //fs.FormBorderStyle = FormBorderStyle.None;

            fs.BackColor = Color.FromArgb(0, 148, 155);
            fs.Width = Native.screen.width / 4;
            fs.Height = Native.screen.height / 4;
            fs.Show();
            fs.Opacity = 0.5;

            FormStyler.AtFormCreated = LikeVirtualScreen;
            var fvs = new Form { Text = "Virtual Screen" };
            fvs.BackColor = Color.Transparent;
            FormStyler.AtFormCreated = FormStyler.LikeWindowsClassic;
            fvs.Width = Native.screen.width / 4;
            fvs.Height = Native.screen.height / 4;
            fvs.Show();
            fvs.Owner = fs;

            var fw = new Form { };

            fw.Width = Native.window.Width / 4;
            fw.Height = Native.window.Height / 4;
            fw.Show();
            fw.Owner = fvs;
            fw.Opacity = 0.8;

            KeepOwnedFormsLinkedToOwnerLocation(fs);
            KeepOwnedFormsLinkedToOwnerLocation(fvs);
            KeepOwnedFormsLinkedToOwnerLocation(fw);
            #endregion


            // doesnt work yet?
            //fw.SizeGripStyle = SizeGripStyle.Hide;

            var svg = new ISVGSVGElement().AttachTo(page.content);
            svg.style.SetLocation(0, 0);

            var vsvg = new ISVGSVGElement().AttachTo(fvs.GetHTMLTarget());
            vsvg.style.SetLocation(0, 0);

            #region VirtualScreenUpdate
            Action VirtualScreenUpdate = delegate
            {
                if (fs.Capture)
                    return;

                // dragging it?
                if (fvs.Capture)
                    return;

                var max_right = fvs.OwnedForms.Max(k => k.Right);
                var min_left = fvs.OwnedForms.Min(k => k.Left);

                var max_bottom = fvs.OwnedForms.Max(k => k.Bottom);
                var min_top = fvs.OwnedForms.Min(k => k.Top);

                DisableKeepOwnedFormsLinkedToOwnerLocation = true;

                fvs.Left = min_left;
                fvs.Top = min_top;
                fvs.Width = max_right - min_left;
                fvs.Height = max_bottom - min_top;

                page.content.style.SetLocation(
                    (min_left - fw.Left) * 4,
                    (min_top - fw.Top) * 4,
                    (max_right - min_left) * 4,
                    (max_bottom - min_top) * 4
                );



                DisableKeepOwnedFormsLinkedToOwnerLocation = false;

            };
            #endregion


            fw.LocationChanged +=
                delegate
                {
                    VirtualScreenUpdate();
                };

            #region AtResize
            Action AtResize = delegate
            {
                // screen can change, but only once, when window is moved to the other monitor?
                fs.Text = "Screen " + new { Native.screen.width, Native.screen.height };
                fs.Width = Native.screen.width / 4;
                fs.Height = Native.screen.height / 4;

                fw.Text = " " + new { Native.window.Width, Native.window.Height
#if onorientationchange                    
                    , Native.window.orientation 
#endif
                };
                fw.Width = Native.window.Width / 4;
                fw.Height = Native.window.Height / 4;

                VirtualScreenUpdate();
            };



            Native.window.onresize +=
                delegate
                {
                    AtResize();
                };

            Native.window.onfocus +=
                delegate
                {
                    AtResize();
                };

            Native.window.onblur +=
                delegate
                {
                    AtResize();
                };

            new ScriptCoreLib.JavaScript.Runtime.Timer(
                delegate
                {
                    AtResize();
                }
            ).StartInterval(1000 / 2);
            #endregion


            // what is attaching what?
            // what about await
            var svgcursor1ghost = new cursor1().AttachTo(page.content).ToSVG();

            var svgcursor1 = new cursor1().AttachTo(page.content).ToSVG();

            svgcursor1.fill += svgcursor1ghost.fill;

            var vcursor = new cursor1().AttachTo(fvs.GetHTMLTarget()).ToSVG();

            var Shadows = new List<Form>();

            Func<Form, Form> CreateShadow =
                _fw =>
                {
                    FormStyler.AtFormCreated = LikeVirtualWindow;
                    var fwshadow = new Form();
                    Shadows.Add(fwshadow);

                    fwshadow.BackColor = Color.Transparent;
                    FormStyler.AtFormCreated = FormStyler.LikeWindowsClassic;
                    fwshadow.Width = Native.screen.width / 4;
                    fwshadow.Height = Native.screen.height / 4;
                    fwshadow.Show();


                    Action fwshadow_update = delegate
                    {

                        fwshadow.MoveTo(_fw.Left, _fw.Top);
                        fwshadow.SizeTo(_fw.Width, _fw.Height);
                    };

                    _fw.LocationChanged +=
                        delegate
                        {
                            fwshadow_update();
                        };

                    _fw.SizeChanged +=
                        delegate
                        {
                            fwshadow_update();

                        };

                    fwshadow_update();

                    _fw.BringToFront();

                    return fwshadow;
                };

            Shadows.Add(CreateShadow(fw));

            bool canexit = false;
            bool canenter = true;

            Action at_exit_MultiMouseMode = delegate
            {
                //Console.WriteLine("at_exit_MultiMouseMode");
            };

            Action at_enter_MultiMouseMode = delegate
            {

                //Console.WriteLine("at_enter_MultiMouseMode");
            };

            Action<IEvent.MouseButtonEnum> at_mousedown = button =>
            {

                //Console.WriteLine("at_enter_mousedown: " + button);
            };


            Action at_mouseup = delegate
            {

                //Console.WriteLine("at_enter_mouseup");
            };




            var path = new ISVGPathElement().AttachTo(svg);
            path.setAttribute("style", "stroke: black; stroke-width: 4; fill: none;");

            var path_d = "";



            var vpath = new ISVGPathElement().AttachTo(vsvg);
            vpath.setAttribute("style", "stroke: black; stroke-width: 1; fill: none;");

            var vpath_d = "";

            bool internal_ismousedown = false;

            Action<IEvent.MouseButtonEnum> internal_mousedown = button =>
            {
                internal_ismousedown = true;

                path = new ISVGPathElement().AttachTo(svg);

                if (button == IEvent.MouseButtonEnum.Left)
                    path.setAttribute("style", "stroke: black; stroke-width: 4; fill: none;");
                else
                    path.setAttribute("style", "stroke: rgb(0, 108, 115); stroke-width: 32; fill: none;");

                path_d = "";


                vpath = new ISVGPathElement().AttachTo(vsvg);

                if (button == IEvent.MouseButtonEnum.Left)
                    vpath.setAttribute("style", "stroke: black; stroke-width: 1; fill: none;");
                else
                    vpath.setAttribute("style", "stroke: rgb(0, 108, 115); stroke-width: 8; fill: none;");

                vpath_d = "";

                svgcursor1.fill(0, 0, 255);
                vcursor.fill(0, 0, 255);

                //path.d = "    M100,50  L10,10   L200,200   ";
                path_d += " M" + x + "," + y;
                path.d = path_d;

                vpath_d += " M" + (x / 4) + "," + (y / 4);
                vpath.d = vpath_d;
            };

            Action<IEvent.MouseButtonEnum> mousedown = button =>
            {
                at_mousedown(button);
                internal_mousedown(button);
            };

            Action internal_mouseup = delegate
            {
                internal_ismousedown = false;





                svgcursor1.fill(0, 255, 0);
                vcursor.fill(0, 255, 0);
            };

            Action mouseup = delegate
            {
                at_mouseup();
                internal_mouseup();
            };



            #region exit_MultiMouseMode
            Action internal_exit_MultiMouseMode = delegate
            {
                svgcursor1.fill(0, 0, 0);
                vcursor.fill(0, 0, 0);

                con.Opacity = 0.9;
                page.content.style.Opacity = 0.3;
                page.content.style.zIndex = 0;

                page.content.style.backgroundColor = "rgba(0, 148, 155, 1)";
                Native.Document.body.style.backgroundColor = "black";

                page.content.style.With(
                    (dynamic s) =>
                    {
                        s.webkitFilter = "blur(3px)";
                    }
                );

                page.info.style.With(
                    (dynamic s) =>
                    {
                        s.webkitFilter = "";
                    }
                );

                Shadows.WithEach(
                   f =>
                       f.GetHTMLTarget().style.With(
                           (dynamic s) =>
                           {
                               s.webkitFilter = "";
                           }
                       )
                 );


                fs.FormsByOwnership().WithEach(
                 f =>
                     f.GetHTMLTarget().style.With(
                         (dynamic s) =>
                         {
                             s.webkitFilter = "";

                         }
                     )
            );


                fvs.OwnedForms.WithEach(
                    k =>
                    {
                        k.GetHTMLTarget().style.display = IStyle.DisplayEnum.block;
                    }
                );




            };

            Action exit_MultiMouseMode = delegate
            {
                if (!canexit)
                    return;

                canexit = false;
                canenter = true;

                at_exit_MultiMouseMode();
                internal_exit_MultiMouseMode();
            };
            #endregion

            #region enter_MultiMouseMode
            Action internal_enter_MultiMouseMode = delegate
            {
                svgcursor1.fill(255, 0, 0);
                vcursor.fill(255, 0, 0);
                con.Opacity = 0.5;

                page.content.style.Opacity = 1.0;
                page.content.style.backgroundColor = "";
                Native.Document.body.style.backgroundColor = "rgba(0, 148, 155, 1)";

                page.content.style.zIndex = 20000;
                con.GetHTMLTarget().style.zIndex = 20002;
                page.content.style.With(
                    (dynamic s) =>
                    {
                        s.webkitFilter = "";
                    }
                );

                page.info.style.With(
                    (dynamic s) =>
                    {
                        s.webkitFilter = "blur(3px)";
                    }
                );


                fvs.OwnedForms.WithEach(
                     k =>
                     {
                         k.GetHTMLTarget().style.display = IStyle.DisplayEnum.none;
                     }
                 );

                Shadows.WithEach(
                  f =>
                      f.GetHTMLTarget().style.With(
                          (dynamic s) =>
                          {
                              s.webkitFilter = "blur(3px)";
                          }
                      )
                );


                fs.FormsByOwnership().WithEach(
                    f =>
                        f.GetHTMLTarget().style.With(
                            (dynamic s) =>
                            {
                                s.webkitFilter = "blur(3px)";
                            }
                        )
                );
            };

            Action enter_MultiMouseMode = delegate
            {
                if (!canenter)
                    return;

                canexit = true;
                canenter = false;

                at_enter_MultiMouseMode();
                internal_enter_MultiMouseMode();
            };
            #endregion





            #region onmousemove



            Native.Document.body.onmouseup +=
              e =>
              {
                  if (Native.Document.pointerLockElement == Native.Document.body)
                  {
                      mouseup();
                      return;
                  }
              };

            Native.Document.body.onmousedown +=
                e =>
                {
                    if (Native.Document.pointerLockElement == Native.Document.body)
                    {
                        mousedown(e.MouseButton);
                        return;
                    }

                    Console.WriteLine("requesting MultiMouse mode!");

                    x = e.CursorX;
                    y = e.CursorY;
                    e.preventDefault();
                    Native.Document.body.requestPointerLock();

                };

            Action<int, int> at_set_cursor_position = delegate { };


            var pxx = 0;
            var pyy = 0;

            var ghost_busy = false;

            Action<int, int> internal_set_cursor_position =
                 (xx, yy) =>
                 {
                     // already set to that exact location!
                     if (pxx == xx)
                         if (pyy == yy)
                             return;


                     pxx = xx;
                     pyy = yy;

                     vcursor.Element.style.SetSize(
                           cursor1.ImageDefaultWidth / 4,
                           cursor1.ImageDefaultHeight / 4
                       );

                     vcursor.Element.style.SetLocation(
                           (xx - 14) / 4,
                           (yy - (64 - 56)) / 4
                       );


                     svgcursor1.Element.style.SetLocation(

                         xx - 14,

                         // inscaope/svg Y is upside down!
                         yy - (64 - 56)

                     );

                     if (!ghost_busy)
                     {
                         ghost_busy = true;

                         svgcursor1ghost.Element.style.Opacity = 0.2;
                         svgcursor1ghost.Element.style.With(
                                (dynamic s) => s.webkitTransition = "all 0.5s linear"
                         );

                         svgcursor1ghost.Element.style.SetLocation(

                            pxx - 14,

                            // inscaope/svg Y is upside down!
                            pyy - (64 - 56)

                        );

                         new ScriptCoreLib.JavaScript.Runtime.Timer(
                             delegate
                             {
                                 svgcursor1ghost.Element.style.SetLocation(

                                    pxx - 14,

                                    // inscaope/svg Y is upside down!
                                    pyy - (64 - 56)

                                );

                                 ghost_busy = false;
                             }
                         ).StartTimeout(500);
                     }


                     // if this window will be activated next time we can continue where we were
                     // told to..
                     x = xx;
                     y = yy;

                     if (internal_ismousedown)
                     {
                         path_d += " L" + x + "," + y;
                         path.d = path_d;

                         vpath_d += " L" + (x / 4) + "," + (y / 4);
                         vpath.d = vpath_d;
                     }

                 };

            Action<int, int> set_cursor_position =
                (xx, yy) =>
                {
                    at_set_cursor_position(xx, yy);
                    internal_set_cursor_position(xx, yy);
                };

            Native.Document.body.onmousemove +=
                e =>
                {
                    if (Native.Document.pointerLockElement == Native.Document.body)
                    {
                        enter_MultiMouseMode();

                        x += e.movementX;
                        y += e.movementY;

                        // clip it
                        // fullscreen behaves differently?
                        x = x.Min(fvs.Width * 4).Max(0);
                        y = y.Min(fvs.Height * 4).Max(0);

                        set_cursor_position(x, y);
                    }
                    else
                    {
                        exit_MultiMouseMode();
                    }

                };
            #endregion

            internal_exit_MultiMouseMode();
            internal_set_cursor_position(0, 0);

            Native.document.body.ontouchstart +=
                 e =>
                 {
                     e.preventDefault();
                     e.stopPropagation();

                     e.touches[0].With(
                         touch =>
                         {
                             // how do we enter?
                             enter_MultiMouseMode();
                             // exit by broswer history move?

                             set_cursor_position(touch.clientX, touch.clientY);

                             // ipad has 11 touchpoints. multiply that with the number of devices/
                             // for now we support 1 pointer per session :)

                             if (e.touches.length == 1)
                                 mousedown(IEvent.MouseButtonEnum.Left);
                             else
                                 mousedown(IEvent.MouseButtonEnum.Right);

                         }
                     );
                 };

            Native.document.body.ontouchend +=
               e =>
               {

                   e.preventDefault();
                   e.stopPropagation();



                   // ipad has 11 touchpoints. multiply that with the number of devices/
                   // for now we support 1 pointer per session :)

                   if (e.touches.length == 0)
                       mouseup();
                   else
                       mousedown(IEvent.MouseButtonEnum.Left);

               };

            Native.document.body.ontouchmove +=
                 e =>
                 {
                     e.preventDefault();
                     e.stopPropagation();


                     e.touches[0].With(
                         touch =>
                         {
                             set_cursor_position(touch.clientX, touch.clientY);
                         }
                     );
                 };



            #region onmessage

            bool disable_bind_reconfigure = false;


            Action<int, int> internal_reconfigure =
                delegate { };

            Action<MessageEvent, XElement> internal_onmessage =
                (e, xml) =>
                {
                    device_onmessage(0, xml);
                };

            Native.window.onmessage +=
                e =>
                {
                    // who sent this? :P
                    var source = (string)e.data;
                    //var now = DateTime.Now;
                    //Console.WriteLine(now + " " + source);


                    var xml = XElement.Parse(source);




                    internal_onmessage(e, xml);
                };

            var friendly_devices = new
            {
                source_device_id = 0,
                f = default(Form),
                children = new
                {
                    child_id = 0,
                    fc = default(Form)
                }.ToEmptyList()
            }.ToEmptyList();

            #region device_onmessage
            this.device_onmessage =
                (source_device_id, xml) =>
                {
                    // mothership to local network?
                    // source_device_id = 0 means it came from one of our virtual screens?

                    if (xml.Name.LocalName == "at_mousedown")
                    {
                        int button = int.Parse(xml.Attribute("button").Value);
                        internal_mousedown((IEvent.MouseButtonEnum)button);
                    }

                    if (xml.Name.LocalName == "at_mouseup")
                    {
                        internal_mouseup();
                    }

                    if (xml.Name.LocalName == "at_enter_MultiMouseMode")
                    {
                        internal_enter_MultiMouseMode();
                    }

                    if (xml.Name.LocalName == "at_exit_MultiMouseMode")
                    {
                        internal_exit_MultiMouseMode();
                    }

                    if (xml.Name.LocalName == "at_set_cursor_position")
                    {
                        int xx = int.Parse(xml.Attribute("x").Value);
                        int yy = int.Parse(xml.Attribute("y").Value);

                        internal_set_cursor_position(xx, yy);
                    }


                };
            #endregion

            var ListOfChildren = new { child_id = 0, fc = default(Form) }.ToEmptyList();

            // when is this called?
            this.device_bind =
                (mothership_postXElement) =>
                {
                    // we might now be able to invoke the server, and via that any other device
                    Console.WriteLine("device_bind");

                    #region at_enter_MultiMouseMode
                    at_enter_MultiMouseMode +=
                        delegate
                        {
                            var xml = new XElement("at_enter_MultiMouseMode");

                            mothership_postXElement(xml);
                        };
                    #endregion

                    #region at_exit_MultiMouseMode
                    at_exit_MultiMouseMode +=
                        delegate
                        {
                            mothership_postXElement(new XElement("at_exit_MultiMouseMode"));
                        };
                    #endregion

                    #region at_mousedown
                    at_mousedown +=
                      button =>
                      {
                          mothership_postXElement(new XElement("at_mousedown", new XAttribute("button", "" + (int)button)));
                      };
                    #endregion

                    #region at_mouseup
                    at_mouseup +=
                     delegate
                     {
                         mothership_postXElement(new XElement("at_mouseup"));
                     };
                    #endregion

                    #region at_set_cursor_position
                    at_set_cursor_position +=
                       (xx, yy) =>
                       {

                           var xml = new XElement("at_set_cursor_position",
                               // int not yet supported?
                                   new XAttribute("x", "" + xx),
                                   new XAttribute("y", "" + yy)
                               );

                           mothership_postXElement(
                               xml
                           );



                       };
                    #endregion

                    // now we can reply..
                    this.device_onmessage +=
                       (source_device_id, xml) =>
                       {
                           #region at_virtualwindowsync_reconfigure
                           if (source_device_id != 0)
                               if (xml.Name.LocalName == "at_virtualwindowsync_reconfigure")
                               {
                                   int __device_id = int.Parse(xml.Attribute("device_id").Value);

                                   if (__device_id == device_id)
                                   {
                                       // are we being reconfigured?

                                       friendly_devices.Where(k => k.source_device_id == source_device_id).WithEach(
                                           q =>
                                           {
                                               int dx = int.Parse(xml.Attribute("dx").Value);
                                               int dy = int.Parse(xml.Attribute("dy").Value);
                                               disable_bind_reconfigure = true;

                                               q.f.MoveTo(
                                                   fw.Left - dx,
                                                   fw.Top - dy
                                               );
                                               disable_bind_reconfigure = false;

                                           }
                                       );
                                   }
                               }
                           #endregion

                           #region at_virtualwindowsync
                           if (source_device_id != 0)
                               if (xml.Name.LocalName == "at_virtualwindowsync")
                               {
                                   Console.WriteLine("got at_virtualwindowsync");

                                   // do we know this device?
                                   var q = friendly_devices.FirstOrDefault(k => k.source_device_id == source_device_id);

                                   int w = int.Parse(xml.Attribute("w").Value);
                                   int h = int.Parse(xml.Attribute("h").Value);

                                   Action reposition = delegate { };

                                   if (q == null)
                                   {
                                       var fc = new Form { Text = new { source_device_id }.ToString() };

                                       q = new { source_device_id, f = fc, children = new { child_id = 0, fc = default(Form) }.ToEmptyList() };

                                       friendly_devices.Add(q);

                                       q.f.StartPosition = FormStartPosition.Manual;
                                       q.f.Show();
                                       // show should respect opacity?
                                       q.f.Opacity = 0.3;


                                       // where to put it?
                                       // left or right?

                                       var max_right = fvs.OwnedForms.Max(k => k.Right);
                                       var min_left = fvs.OwnedForms.Min(k => k.Left);

                                       if (source_device_id < device_id)
                                           q.f.Left = min_left - w;
                                       else
                                           q.f.Left = max_right;

                                       q.f.Top = fw.Top;
                                       q.f.Owner = fvs;

                                       var fcShadow = CreateShadow(q.f);
                                       Shadows.Add(fcShadow);

                                       #region from now on if we move any of our screens
                                       // in relation to this source_device_id we have to notify it

                                       Action SendDelta = delegate
                                       {
                                           var pdx = fc.Left - fw.Left;
                                           var pdy = fc.Top - fw.Top;

                                           mothership_postXElement(
                                             new XElement("at_virtualwindowsync_reconfigure",
                                                 new XAttribute("device_id", "" + source_device_id),
                                                 new XAttribute("dx", "" + pdx),
                                                 new XAttribute("dy", "" + pdy)
                                             )
                                           );
                                       };

                                       fw.LocationChanged +=
                                           delegate
                                           {
                                               if (disable_bind_reconfigure)
                                                   return;

                                               SendDelta();
                                           };

                                       fc.LocationChanged +=
                                           delegate
                                           {
                                               if (disable_bind_reconfigure)
                                                   return;


                                               SendDelta();
                                           };


                                       #endregion


                                   }

                                   // thanks for letting us know that you changed your size...
                                   q.f.Width = w;
                                   q.f.Height = h;


                                   xml.Elements("child").WithEach(
                                       cxml =>
                                       {
                                           // any new children?
                                           int child_id = int.Parse(cxml.Attribute("child_id").Value);

                                           int pdx = int.Parse(cxml.Attribute("pdx").Value);
                                           int pdy = int.Parse(cxml.Attribute("pdy").Value);

                                           int cw = int.Parse(cxml.Attribute("w").Value);
                                           int ch = int.Parse(cxml.Attribute("h").Value);

                                           var cq = q.children.FirstOrDefault(k => k.child_id == child_id);

                                           if (cq == null)
                                           {
                                               var fc = new Form { Text = new { source_device_id, child_id }.ToString() };

                                               cq = new { child_id, fc };

                                               q.children.Add(cq);

                                               cq.fc.StartPosition = FormStartPosition.Manual;
                                               cq.fc.Show();
                                               // show should respect opacity?
                                               cq.fc.Opacity = 0.2;

                                               // if this child needs to be between then add it
                                               // before reposition

                                               cq.fc.Owner = fvs;

                                               var fcShadow = CreateShadow(cq.fc);
                                               Shadows.Add(fcShadow);

                                           }


                                           cq.fc.Left = q.f.Left + pdx;
                                           cq.fc.Top = q.f.Top + pdy;

                                           // thanks for letting us know that you changed your size...
                                           cq.fc.Width = cw;
                                           cq.fc.Height = ch;
                                       }
                                   );

                               }
                           #endregion

                       };

                    // lets tell the world about virtual screens owned by us.
                    // lets start by advertising our size.

                    #region at_virtualwindowsync
                    var t = new ScriptCoreLib.JavaScript.Runtime.Timer(
                        delegate
                        {
                            // do we know whats the dx to other windows?
                            var xml = new XElement("at_virtualwindowsync",
                                // int not yet supported?
                                new XAttribute("w", "" + fw.Width),
                                new XAttribute("h", "" + fw.Height)


                            );

                            #region what about children?
                            ListOfChildren.WithEach(
                                c =>
                                {
                                    var pdx = c.fc.Left - fw.Left;
                                    var pdy = c.fc.Top - fw.Top;

                                    xml.Add(

                                        new XElement("child",
                                            new XAttribute("child_id", "" + c.child_id),
                                        // int not yet supported?
                                            new XAttribute("pdx", "" + pdx),
                                            new XAttribute("pdy", "" + pdy),
                                            new XAttribute("w", "" + c.fc.Width),
                                            new XAttribute("h", "" + c.fc.Height)
                                        )

                                    );
                                }
                            );
                            #endregion


                            mothership_postXElement(
                              xml
                            );

                            Console.WriteLine("sent at_virtualwindowsync");

                        }
                    );

                    t.StartInterval(5000);
                    #endregion

                };

            Action<IWindow, Form> bind =
                (w, fc) =>
                {
                    this.device_bind(w.postXElement);

                    internal_onmessage +=
                        (e, xml) =>
                        {
                            if (xml.Name.LocalName == "reconfigure")
                            {
                                // how do we know this reconfigrue event is for us?

                                if (e.source == w)
                                {
                                    disable_bind_reconfigure = true;

                                    int dx = int.Parse(xml.Attribute("dx").Value);
                                    int dy = int.Parse(xml.Attribute("dy").Value);

                                    //Console.WriteLine("reconfigure " + new { dx, dy, fw.Left });

                                    //fw.Left += dx;
                                    //fw.Top += dy;


                                    fc.MoveTo(
                                        fw.Left - dx,
                                        fw.Top - dy
                                    );

                                    disable_bind_reconfigure = false;
                                }
                            }
                        };

                    Action SendDelta = delegate
                    {
                        var pdx = fc.Left - fw.Left;
                        var pdy = fc.Top - fw.Top;

                        w.postXElement(
                          new XElement("reconfigure",
                              new XAttribute("dx", "" + pdx),
                              new XAttribute("dy", "" + pdy)
                          )
                        );
                    };

                    fw.LocationChanged +=
                        delegate
                        {
                            if (disable_bind_reconfigure)
                                return;

                            SendDelta();
                        };

                    fc.LocationChanged +=
                        delegate
                        {
                            if (disable_bind_reconfigure)
                                return;


                            SendDelta();
                        };
                };
            #endregion


            #region opener
            Native.window.opener.With(
                w =>
                {
                    // disable features
                    page.info.Hide();

                    Console.WriteLine("we have opener: " + w.document.location.href);

                    var fc = new Form { Text = "opener" };

                    fc.Owner = fvs;

                    Action cAtResize = delegate
                    {
                        fc.Text = "Opener " + new { w.Width, w.Height };
                        fc.Width = w.Width / 4;
                        fc.Height = w.Height / 4;
                    };

                    w.onresize += delegate
                    {
                        cAtResize();
                    };

                    var ct = new ScriptCoreLib.JavaScript.Runtime.Timer(
                       delegate
                       {
                           cAtResize();
                       }
                    );

                    ct.StartInterval(1000 / 15);

                    cAtResize();

                    fc.StartPosition = FormStartPosition.Manual;
                    fc.Show();
                    fc.Opacity = 0.7;
                    fc.BackColor = Color.Transparent;

                    var fcShadow = CreateShadow(fc);
                    Shadows.Add(fcShadow);



                    Native.window.requestAnimationFrame +=
                        delegate
                        {
                            // ScriptCoreLib Windows Forms has a few bugs:P
                            fc.MoveTo(fw.Left - fc.Width, fw.Top);

                            bind(w, fc);
                        };

                }
            );
            #endregion

            #region make info clickable

            page.info.onmousedown +=
             e =>
             {
                 if (internal_ismousedown)
                     return;

                 e.stopPropagation();
             };

            page.info.ontouchstart +=
              e =>
              {
                  if (internal_ismousedown)
                      return;


                  e.stopPropagation();
              };

            page.info.ontouchmove +=
          e =>
          {
              if (internal_ismousedown)
                  return;


              e.stopPropagation();
          };

            page.info.ontouchend +=
     e =>
     {
         if (internal_ismousedown)
             return;

         e.stopPropagation();
     };
            #endregion

            #region OpenChildSession



            page.OpenChildSession.onclick +=
                e =>
                {
                    e.preventDefault();

                    Console.WriteLine("open child session...");

                    Native.window.open(
                        Native.Document.location.href,
                        "_blank", 400, 400, true).With(
                        w =>
                        {
                            w.onload +=
                                delegate
                                {
                                    if (w.document.location.href == "about:blank")
                                        return;

                                    Console.WriteLine("child onload " + w.document.location.href);

                                    var fc = new Form { Text = "child" };



                                    Action cAtResize = delegate
                                    {
                                        fc.Text = "Child " + new { w.Width, w.Height };
                                        fc.Width = w.Width / 4;
                                        fc.Height = w.Height / 4;

                                        VirtualScreenUpdate();
                                    };

                                    w.onresize += delegate
                                    {
                                        cAtResize();

                                    };

                                    var ct = new ScriptCoreLib.JavaScript.Runtime.Timer(
                                       delegate
                                       {
                                           cAtResize();
                                       }
                                    );

                                    ct.StartInterval(1000 / 2);

                                    //cAtResize();

                                    fc.StartPosition = FormStartPosition.Manual;
                                    fc.Show();
                                    fc.Opacity = 0.5;
                                    // first child could be a monitor to our right
                                    fc.MoveTo(fw.Right, fw.Top);
                                    fc.Owner = fvs;
                                    fc.BackColor = Color.Transparent;

                                    fc.Width = 400 / 4;
                                    fc.Height = 400 / 4;

                                    VirtualScreenUpdate();



                                    fc.LocationChanged +=
                                        delegate
                                        {
                                            VirtualScreenUpdate();

                                        };

                                    var fcShadow = CreateShadow(fc);
                                    Shadows.Add(fcShadow);

                                    var token = new { child_id = random.Next(), fc };

                                    ListOfChildren.Add(token);

                                    #region FormClosing
                                    w.onbeforeunload +=
                                        delegate
                                        {
                                            if (fc == null)
                                                return;

                                            w = null;

                                            ct.Stop();
                                            fc.Close();
                                            fc = null;
                                        };

                                    Native.window.onbeforeunload +=
                                        delegate
                                        {
                                            if (w == null)
                                                return;

                                            w.close();
                                            w = null;
                                        };

                                    fc.FormClosing +=
                                        delegate
                                        {

                                            if (w == null)
                                                return;

                                            ListOfChildren.Remove(token);
                                            Shadows.Remove(fcShadow);

                                            fc = null;

                                            w.close();
                                            w = null;
                                        };
                                    #endregion



                                    bind(w, fc);


                                };
                        }
                    );
                };
            #endregion





            Native.document.documentElement.style.overflow = IStyle.OverflowEnum.hidden;
        }
        public ApplicationWebServiceWithReplay()
        {
            var sync = new Timer(
                delegate
                {
                    // in every 500ms we get to do stuff.

                    if (CurrentPending == null)
                    {
                        // there is nothing pending just yet.
                        // do we have work?

                        if (actions.Count > 0)
                        {
                            var next = actions.Peek();

                            // alright, we know what to do
                            // start our timeout

                            var timeout = new Stopwatch();

                            timeout.Start();

                            CurrentPending = timeout;

                            Console.WriteLine("start task " + new { actions.Count });


                            // .net does not need this?
                            if (!ServicePending.IsRunning)
                                ServicePending.Start();


                            if (AtPendingActions != null)
                                AtPendingActions(actions.Count);

                            next(
                                delegate
                                {
                                    if (CurrentPending == timeout)
                                    {
                                        // we have been expecting you..

                                        Console.WriteLine("task complete " + new { timeout.ElapsedMilliseconds, actions.Count });

                                        CurrentPending = null;
                                        actions.Dequeue();

                                        if (actions.Count == 0)
                                        {
                                            ServicePending = new Stopwatch();
                                            //ServicePending.Reset();
                                        }

                                        if (AtPendingActions != null)
                                            AtPendingActions(actions.Count);

                                    }
                                }
                            );
                        }

                    }
                    else
                    {
                        // there is something pending

                        // lag 4000 and we will need to retry
                        if (CurrentPending.ElapsedMilliseconds > 4000)
                        {
                            Console.WriteLine("task abort  " + new { actions.Count });
                            CurrentPending = null;



                        }

                        if (AtPendingActions != null)
                            AtPendingActions(actions.Count);
                    }


                }
            );

            sync.StartInterval(500);
        }
        public ClientToServerBase()
        {
            PollTimer = new Timer();
            PollTimer.StartInterval(500);
            PollTimer.Tick +=
                delegate
                {
                    if (PollCount > MaxConcurrentPolls)
                    {
                        Console.WriteLine(MaxConcurrentPolls + " polls already in progress....");
                        return;
                    }

                    var data = MarkPending();

                    // Console.WriteLine("polling.... sending: " + data.Length);

                    var t = new ClientTansport<Message[]>("");


                    // t.IsVerbose = true;

                    t.BeforeSend += delegate
                    {
                        t.Data = data;
                        t.Descriptor.Description = this.ClientName;

                        PollCount++;
                    };

                    t.Complete += delegate
                    {
                        PollCount--;

                        if (t.Request.IsNoContent)
                        {
                            return;
                        }

                        if (t.Request.IsOffline)
                        {

                            Console.WriteLine("server seems to be offline");

                            this.PollTimer.Stop();

                            return;
                        }

                        if (t.Request.IsOK)
                        {
                            foreach (Message v in t.Data)
                            {
                                if (v.ToServerMessageId > 0)
                                {
                                    RemoveToServerPending(v);
                                }
                                else if (v.ToClientMessageId > 0)
                                {
                                    AsyncInvoke(v);
                                }
                            }

                            t.Data = null;
                        }
                        else
                        {
                            Console.WriteLine("unknown status: " + t.Request.status);
                        }


                    };

                    t.Send();
                };
        }