예제 #1
0
            public XRectangle()
            {
                var aelement = new IHTMLDiv();



                // WPF: Rectangle, Image or Label
                var acontent = new IHTMLDiv();

                acontent.style.backgroundColor = "#ff0000";

                this.Rotor = new IHTMLDiv();

                //this.Rotor.style.backgroundColor = "#ffd0d0";

                this.Rotor.style.border = "1px solid black";

                //this.Rotor.style.paddingRight = "10px";

                this.Rotor.AttachTo(aelement);

                acontent.AttachTo(this.Rotor);

                aelement.AttachToDocument();

                Element = aelement;
                Content = acontent;
            }
예제 #2
0
        private static IHTMLDiv SpawnDiv(Dictionary <string, IHTMLImage> Images, bool b)
        {
            var div1 = new IHTMLDiv();
            var div2 = new IHTMLDiv();


            var img1 = (IHTMLImage)Images["room 001, obj 005 (296,32)"].cloneNode(false);
            var img2 = (IHTMLImage)Images["room 002, obj 002 (0,24)"].cloneNode(false);
            var img3 = (IHTMLImage)Images["room 002, obj 002 (0,24)"].cloneNode(false);

            div2.AttachTo(div1);
            div2.style.position = IStyle.PositionEnum.relative;
            div2.style.SetSize(100, 100);
            div2.style.border = "1px solid red";

            if (b)
            {
                div2.onfocus += ev => div2.blur();
            }

            img1.style.SetLocation(4, 4);
            img1.AttachTo(div2);

            img2.style.SetLocation(33, 4);
            img2.AttachTo(div2);
            img2.onfocus += ev => img2.blur();

            img3.style.SetLocation(66, 4);
            img3.AttachTo(div2);
            img3.onfocus += ev => ev.preventDefault();

            return(div1);
        }
예제 #3
0
        public Apple AttachTo(IHTMLDiv canvas)
        {
            MoveToLocation();
            Control.AttachTo(canvas);

            return(this);
        }
예제 #4
0
        public RedNumberDisplay(int Digits, int value, Assets MyAssets)
        {
            this.MyAssets = MyAssets;
            this.Digits   = Digits;

            this.Control.style.SetSize(Width, Height);
            this.Control.style.backgroundColor = Color.Black;
            this.Control.style.position        = IStyle.PositionEnum.relative;

            DigitControls = Enumerable.Range(0, Digits).Select(
                i =>
            {
                var d = new IHTMLDiv();

                d.style.SetLocation(i * DigitX, 0, DigitX, DigitY);
                d.style.SetBackground(MyAssets.red_numbers[0]);

                d.AttachTo(this.Control);

                return(d);
            }
                ).ToArray();


            this.Value = value;
        }
예제 #5
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(IDefaultPage page)
        {
            @"Hello world".ToDocumentTitle();
            // Send data from JavaScript to the server tier
            service.getExternalStoragePublicDirectory(
                "",
                root =>
            {
                Action <string, IHTMLElement> listFiles = null;

                listFiles =
                    (xroot, xcontainer) =>
                {
                    if (!xroot.EndsWith("/"))
                    {
                        xroot += "/";
                    }

                    new IHTMLPre {
                        innerText = xroot
                    }.AttachTo(xcontainer);

                    service.listFiles(xroot,
                                      f =>
                    {
                        var ch = new IHTMLDiv();

                        ch.style.marginLeft = "1em";


                        new IHTMLButton {
                            innerText = f
                        }.AttachTo(xcontainer).With(
                            btn =>
                        {
                            btn.style.display = IStyle.DisplayEnum.block;

                            btn.onclick +=
                                delegate
                            {
                                if (f.EndsWith("/"))
                                {
                                    listFiles(xroot + f, ch);
                                }
                            };
                        }
                            );

                        ch.AttachTo(xcontainer);
                    }
                                      );
                };


                listFiles(root, Native.Document.body);
            }
                );
        }
        public static void ExposedFunctions_AddData1(Data1 e)
        {
            if (e == null)
            {
                new IHTMLDiv {
                    innerText = "yay, no data..."
                }.AttachTo(instructions);
                return;
            }

            Func <string> GetString = () => new { e.text, e.index }.ToString();

            // this function can now be used by external API
            e.GetString = IFunction.OfDelegate(GetString);

            var div = new IHTMLDiv
            {
                // using a real anonymous type, we get a nice key value string for display
                innerText = GetString()
            };

            #region attach events
            if (e.onclick != null)
            {
                div.style.cursor = IStyle.CursorEnum.pointer;
                div.onclick     +=
                    delegate
                {
                    e.onclick.apply(e, div);
                };
            }

            if (e.onmouseover != null)
            {
                div.style.cursor = IStyle.CursorEnum.pointer;
                div.onmouseover +=
                    delegate
                {
                    e.onmouseover.apply(e, div);
                };
            }

            if (e.onmouseout != null)
            {
                div.style.cursor = IStyle.CursorEnum.pointer;
                div.onmouseout  +=
                    delegate
                {
                    e.onmouseout.apply(e, div);
                };
            }
            #endregion

            div.AttachTo(instructions);
        }
예제 #7
0
        void Spawn(DudeAnimationInfo LoadedCharacter, Scene.Document LoadedScene)
        {
            var ViewSize = new Size {
                Width = 640, Height = 480
            };

            var Container = new IHTMLDiv();

            Container.AttachToDocument();
            Container.style.SetSize(ViewSize.Width, ViewSize.Height + 22);
            Container.KeepInCenter();

            //Container.MakeCSSShaderCrumple();

            var Wallpaper = new IHTMLDiv().AttachTo(Container);

            Wallpaper.style.SetSize(ViewSize.Width, ViewSize.Height + 22);


            new power().ToBackground(Wallpaper.style);
            Wallpaper.style.position           = IStyle.PositionEnum.absolute;
            Wallpaper.style.backgroundRepeat   = "no-repeat";
            Wallpaper.style.backgroundPosition = "center center";



            var Margin     = 48;
            var MarginSafe = 72;



            var CurrentFrame = LoadedScene.Frames.Randomize().First();
            //var CurrentFrame = LoadedScene.Frames.Single(f => f.Name == "C");

            var Room = new IHTMLDiv();



            Room.style.border = "1px solid #00ff00";
            Room.style.SetSize(ViewSize.Width, ViewSize.Height);
            Room.style.position = IStyle.PositionEnum.absolute;
            Room.style.overflow = IStyle.OverflowEnum.hidden;

            Room.AttachTo(Container);
            Room.style.SetLocation(0, 22);

            //Room.AttachToDocument();
            //Room.KeepInCenter();



            var tween = Room.ToOpacityTween();

            Action HideRoom = () => tween.Value = 1;
            Action ShowRoom = () => tween.Value = 0;

            HideRoom();

            //var GroundOverlay2 = new IHTMLDiv();

            //GroundOverlay2.style.backgroundColor = Color.Blue;
            ////GroundOverlay.style.Opacity = 0;

            //GroundOverlay2.style.position = IStyle.PositionEnum.absolute;
            //GroundOverlay2.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height);
            //GroundOverlay2.AttachTo(Room);

            var LostInTime_Images = new ImpAdventures.HTML.Pages.LostInTimeImages().Images;

            var BackgroundImage = new IHTMLImage();

            LostInTime_Images.FirstOrDefault(
                k => k.src.SkipUntilLastIfAny("/") == CurrentFrame.Image.Source.SkipUntilLastIfAny("/")
                ).With(
                ImageSource =>
            {
                Console.WriteLine(ImageSource.src);
                BackgroundImage.src = ImageSource.src;
            }
                );

            BackgroundImage.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height);
            BackgroundImage.alt = "BackgroundImage";
            BackgroundImage.AttachTo(Room);

            //GroundOverlay2.style.backgroundImage = "url(" + CurrentFrame.Image.Source + ")";
            //BackgroundImage.InvokeOnComplete(
            //    delegate
            //    {
            //        //BackgroundImage.style.backgroundColor = Color.Red;
            //        //BackgroundImage.style.SetLocation(0,0, ViewSize.Width, ViewSize.Height);
            //        BackgroundImage.AttachTo(GroundOverlay2);
            //    }
            //);


            var GroundOverlay = new IHTMLDiv();

            GroundOverlay.style.backgroundColor = Color.Blue;
            GroundOverlay.style.Opacity         = 0;
            GroundOverlay.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height);
            GroundOverlay.AttachTo(Room);

            var Ground = new IHTMLDiv();

            Ground.style.SetLocation(0, 0, ViewSize.Width, ViewSize.Height);
            Ground.AttachTo(Room);



            var AnimateRoomChange = default(Action <Action>);

            #region TryToChangeRooms
            Func <TryToChangeRoomsArgs, bool> TryToChangeRooms =
                e =>
            {
                if (e == null)
                {
                    return(false);
                }

                if (e.NextRoomSelector == null)
                {
                    throw new ArgumentNullException("NextRoomSelector");
                }

                var next = LoadedScene.Frames.SingleOrDefault(e.NextRoomSelector);

                var r = next != null;

                if (r)
                {
                    AnimateRoomChange(
                        delegate
                    {
                        CurrentFrame = next;

                        Console.WriteLine("AnimateRoomChange");

                        LostInTime_Images.FirstOrDefault(
                            k => k.src.SkipUntilLastIfAny("/") == CurrentFrame.Image.Source.SkipUntilLastIfAny("/")
                            ).With(
                            ImageSource =>
                        {
                            Console.WriteLine(ImageSource.src);
                            BackgroundImage.src = ImageSource.src;
                        }
                            );

                        //GroundOverlay2.style.backgroundImage = "url(" + CurrentFrame.Image.Source + ")";
                        //BackgroundImage.src = CurrentFrame.Image.Source;

                        e.ReadyToTeleport();
                    }
                        );
                }


                return(r);
            };
            #endregion


            var dude = CreateDude(LoadedCharacter);

            dude.Control.AttachTo(Ground);

            #region Doors
            var Doors = new[]
            {
                new TryToChangeRoomsArgs
                {
                    Condition        = () => dude.CurrentLocation.X > ViewSize.Width - Margin,
                    NextRoomSelector = f => f.Name == CurrentFrame.Right,
                    ReadyToTeleport  = delegate
                    {
                        dude.TeleportTo(-MarginSafe, dude.CurrentLocation.Y);
                        dude.LookAt(new Point(MarginSafe, (int)dude.CurrentLocation.Y));
                    }
                },
                new TryToChangeRoomsArgs
                {
                    Condition        = () => dude.CurrentLocation.X < Margin,
                    NextRoomSelector = f => f.Name == CurrentFrame.Left,
                    ReadyToTeleport  = delegate
                    {
                        dude.TeleportTo(ViewSize.Width + MarginSafe, dude.CurrentLocation.Y);
                        dude.LookAt(new Point(ViewSize.Width - MarginSafe, (int)dude.CurrentLocation.Y));
                    }
                },
                new TryToChangeRoomsArgs
                {
                    Condition        = () => dude.CurrentLocation.Y < Margin,
                    NextRoomSelector = f => f.Name == CurrentFrame.Top,
                    ReadyToTeleport  = delegate
                    {
                        dude.TeleportTo(dude.CurrentLocation.X, ViewSize.Height + MarginSafe);
                        dude.LookAt(new Point((int)dude.CurrentLocation.X, ViewSize.Height - MarginSafe));
                    }
                },
                new TryToChangeRoomsArgs
                {
                    Condition        = () => dude.CurrentLocation.Y > ViewSize.Height - Margin,
                    NextRoomSelector = f => f.Name == CurrentFrame.Bottom,
                    ReadyToTeleport  = delegate
                    {
                        dude.TeleportTo(dude.CurrentLocation.X, -Margin);
                        dude.LookAt(new Point((int)dude.CurrentLocation.X, MarginSafe));
                    }
                }
            };
            #endregion

            Console.WriteLine(new { Doors = Doors.Length });

            Doors.WithEachIndex(
                (x, index) =>
            {
                Console.WriteLine(new { index, x });
                Console.WriteLine(new { index, x.Condition });
            }
                );


            var ChangeRoom = new ChangeRoom {
                autobuffer = true
            };
            var Talk = new Talk {
                autobuffer = true
            };
            var Argh_RChannel = new Argh_RChannel {
                autobuffer = true
            };
            var Argh_LChannel = new Argh_LChannel {
                autobuffer = true
            };
            var Argh_Disabled         = false;
            var Argh_VolumeMultiplier = 1.0;

            #region Argh_Stereo
            Action <double, double> Argh_Stereo =
                (volume, balance) =>
            {
                if (Argh_Disabled)
                {
                    return;
                }

                Argh_RChannel.AttachToDocument();
                Argh_LChannel.AttachToDocument();

                Argh_RChannel.volume = Argh_VolumeMultiplier * volume * balance;
                Argh_LChannel.volume = Argh_VolumeMultiplier * volume * (1 - balance);

                Argh_RChannel.play();
                Argh_LChannel.play();

                Argh_RChannel = new Argh_RChannel {
                    autobuffer = true
                };
                Argh_LChannel = new Argh_LChannel {
                    autobuffer = true
                };

                Argh_Disabled          = true;
                Argh_VolumeMultiplier /= 2;

                new Timer(t => Argh_Disabled         = false).StartTimeout(800);
                new Timer(t => Argh_VolumeMultiplier = 1).StartTimeout(5000);
            };
            #endregion

            #region PrintText
            Action <string, Action> PrintText =
                (text, done) =>
            {
                Talk.AttachToDocument();
                Talk.load();
                Talk.volume = Math.Min(1, dude.Zoom.DynamicZoom / 4);
                Talk.play();
                Talk = new Talk {
                    autobuffer = true
                };

                text.Length.Range().AsyncForEach(
                    i =>
                {
                    Wallpaper.innerText = text.Left(i + 1);

                    var c = text[i];

                    if (LoadedScene.SlowText.Contains("" + c))
                    {
                        return(100.Random());
                    }

                    return(50.Random());
                }, done
                    );
            };
            #endregion

            Action <string, Action> PrintRandomText =
                (text, done) => PrintText(text.Split(LoadedScene.TextDelimiter).Randomize().First(), done);



            dude.DoneWalking +=
                delegate
            {
                // compiler bug: cannot invoke Action<func, action> delegate ?

                System.Console.WriteLine("done walking in " + CurrentFrame.Name + " at " + dude.CurrentLocation);

                var xFirstOrDefault = Doors.FirstOrDefault(d => d.Condition());

                System.Console.WriteLine("done walking in " + new { xFirstOrDefault });

                // Doors null?
                if (TryToChangeRooms(xFirstOrDefault))
                {
                    return;
                }


                if (CurrentFrame.Items != null)
                {
                    var item = CurrentFrame.Items.Where(
                        i => new Point(i.X.ToInt32(), i.Y.ToInt32()).GetRange(dude.CurrentLocation) < i.R.ToInt32()
                        ).FirstOrDefault();

                    if (item != null)
                    {
                        dude.IsSelected = false;
                        dude.LookDown();

                        PrintRandomText(item.Text,
                                        delegate
                        {
                            dude.WalkingOnce +=
                                delegate
                            {
                                Wallpaper.innerText = "";
                            };

                            dude.IsSelected = true;
                        }
                                        );
                    }
                }
            };

            #region AnimateRoomChange
            AnimateRoomChange =
                ReadyToTeleport =>
            {
                var Step1 = default(System.Action);
                var Step2 = default(System.Action);
                var Step3 = default(Action);

                Step1 =
                    delegate
                {
                    tween.Done -= Step1;

                    ReadyToTeleport();

                    tween.Done += Step2;

                    ShowRoom();
                };

                Step2 =
                    delegate
                {
                    tween.Done -= Step2;

                    dude.DoneWalking += Step3;

                    dude.IsWalking = true;
                };

                Step3 =
                    delegate
                {
                    dude.DoneWalking -= Step3;

                    dude.IsSelected = true;
                };

                dude.IsSelected = false;

                tween.Done += Step1;
                // go left
                HideRoom();

                // http://stackoverflow.com/questions/3009888/autoplay-audio-files-on-an-ipad-with-html5
                ChangeRoom.AttachToDocument();
                ChangeRoom.load();
                ChangeRoom.volume = 0.2;
                ChangeRoom.play();
                ChangeRoom = new ChangeRoom();
            };
            #endregion

            var pointer_x = 0;
            var pointer_y = 0;

            #region onmousemove
            Container.onmousemove +=
                ev =>
            {
                if (Native.Document.pointerLockElement == Container)
                {
                    if (dude.IsSelected)
                    {
                        var volume  = Math.Min(1, dude.Zoom.DynamicZoom / 4);
                        var balance = dude.CurrentLocation.X / ViewSize.Width;

                        pointer_x += ev.movementX;
                        pointer_y += ev.movementY;

                        pointer_x = Math.Min(ViewSize.Width - 0, Math.Max(0, pointer_x));
                        pointer_y = Math.Min(ViewSize.Height - 0, Math.Max(0, pointer_y));

                        var OffsetPosition = new Point(pointer_x, pointer_y

                                                       );

                        Console.WriteLine(OffsetPosition);

                        Argh_Stereo(volume, balance);
                        dude.WalkTo(OffsetPosition);
                    }
                }
            };
            #endregion

            #region ontouchstart
            Container.ontouchstart +=
                ev =>
            {
                ev.PreventDefault();

                System.Console.WriteLine(ev.CursorPosition);

                if (dude.IsSelected)
                {
                    var volume  = Math.Min(1, dude.Zoom.DynamicZoom / 4);
                    var balance = dude.CurrentLocation.X / ViewSize.Width;

                    var ev_OffsetPosition = new Point(
                        ev.touches[0].clientX - Container.Bounds.Left,
                        ev.touches[0].clientY - Container.Bounds.Top
                        );

                    Argh_Stereo(volume, balance);
                    dude.WalkTo(ev_OffsetPosition);
                }
            };
            #endregion

            #region onclick
            Container.onclick +=
                ev =>
            {
                ev.PreventDefault();

                if (ev.MouseButton == IEvent.MouseButtonEnum.Middle)
                {
                    if (Native.Document.pointerLockElement == Container)
                    {
                        Native.Document.exitPointerLock();
                        return;
                    }

                    pointer_x = (int)dude.CurrentLocation.X;
                    pointer_y = (int)dude.CurrentLocation.Y;

                    //Container.requestFullscreen();
                    Container.requestPointerLock();
                    return;
                }

                if (ev.Element != Ground)
                {
                    return;
                }

                System.Console.WriteLine(ev.CursorPosition);

                if (dude.IsSelected)
                {
                    var volume  = Math.Min(1, dude.Zoom.DynamicZoom / 4);
                    var balance = dude.CurrentLocation.X / ViewSize.Width;

                    Argh_Stereo(volume, balance);
                    dude.WalkTo(ev.OffsetPosition);
                }
            };
            #endregion



            //GroundOverlay.onclick +=
            //    ev =>
            //    {
            //        if (ev.Element != GroundOverlay)
            //            return;

            //        System.Console.WriteLine(ev.CursorPosition);

            //        if (dude.IsSelected)
            //        {
            //            new Argh().play();

            //            dude.WalkTo(ev.OffsetPosition);
            //        }
            //    };


            dude.TeleportTo(ViewSize.Width / 2, (ViewSize.Height - MarginSafe) / 2);
            dude.LookDown();

            ShowRoom();

            dude.DoneWalkingOnce +=
                delegate
            {
                PrintRandomText(
                    LoadedScene.IntroText,
                    delegate
                {
                    dude.WalkingOnce +=
                        delegate
                    {
                        Wallpaper.innerText = "";
                    };

                    dude.IsSelected = true;
                }
                    );
            };

            dude.WalkToArc(MarginSafe, dude.Direction);
        }
예제 #8
0
        /// <summary>
        /// Creates a new control
        /// </summary>
        public TextScreenSaver(Qoutes.DocumentList list = null)
        {
            if (list == null)
            {
                list = DefaultData;
            }

            var type = typeof(TextScreenSaver);

            var name = type.Name;

            Console.WriteLine("type: " + name);

            //try
            //{
            //    //IStyleSheet.Default.AddRule("*", "cursor: url('assets/TextScreenSaver/images/cursor.cur'), auto;", 0);

            //IStyleSheet.Default.AddRule("html",
            //    r =>
            //    {
            //        r.style.overflow = IStyle.OverflowEnum.hidden;
            //    }
            //);
            //}
            //catch (Exception exc)
            //{
            //    //new IHTMLElement(IHTMLElement.HTMLElementEnum.div, "error: " + exc.Message.Replace(",", ", ")).AttachToDocument().style.width = "80em";
            //}

            Action <Qoutes.DocumentRef, Action <Qoutes.Document> > PrepareDocument =
                (doc, done) =>
            {
                if (doc.Document == null)
                {
                    Native.Document.title = "loading...";

                    //Console.WriteLine("loading: " + doc.Source);

                    doc.Source.DownloadToXML <Qoutes.Document>(Qoutes.Settings.KnownTypes,
                                                               newdoc =>
                    {
                        doc.Document = newdoc;
                        done(newdoc);
                    }
                                                               );
                }
                else
                {
                    done(doc.Document);
                }
            };


            var current = list.Documents.Random();

            var abort = default(Action);
            var kbd   = new KeyboardEvents();

            var reset = default(Action);

            kbd.left +=
                ev =>
            {
                kbd.Enabled = false;
                ev.PreventDefault();

                if (abort != null)
                {
                    abort();
                }
                current = list.Documents.Previous(i => i == current);
                reset();
            };

            kbd.right +=
                ev =>
            {
                kbd.Enabled = false;
                ev.PreventDefault();

                if (abort != null)
                {
                    abort();
                }

                current = list.Documents.Next(i => i == current);
                reset();
            };

            Native.Document.onkeydown += kbd;


            reset =
                () =>
                PrepareDocument(current,
                                doc =>
            {
                Native.Document.title = doc.Topic.Trim();

                var body = Native.Document.body;

                body.style.overflow   = IStyle.OverflowEnum.hidden;
                body.style.width      = "100%";
                body.style.height     = "100%";
                body.style.fontFamily = IStyle.FontFamilyEnum.Verdana;
                //body.style.backgroundImage = "url(assets/TextScreenSaver/powered_by_jsc.png)";
                body.style.backgroundRepeat = "no-repeat";


                //("BackgroundColor: " + doc.Style.BackgroundColor).ToConsole();
                //("Color: " + doc.Style.Color).ToConsole();

                doc.Style.ApplyTo(body.style);



                var lines = doc.Lines();

                var timer_handler = new Action <Timer>(delegate { });
                var timer_ref     = 100.AsTimer(timer_handler);

                var vectors = new List <IHTMLDiv>();

                var abort_me = default(Action);

                abort_me =
                    delegate
                {
                    abort -= abort_me;

                    Console.WriteLine("aborting...");

                    timer_ref.Stop();

                    vectors.ForEach(v => v.Orphanize());

                    abort_me = null;
                };

                abort += abort_me;

                Action <Action> SpawnVector =
                    done =>
                {
                    // we have been aborted
                    if (abort_me == null)
                    {
                        return;
                    }

                    var z = 0.5d.Random() + 0.5d;

                    var v = new IHTMLDiv {
                        innerText = lines.Random()
                    };

                    v.style.whiteSpace = IStyle.WhiteSpaceEnum.nowrap;

                    vectors.Add(v);

                    Action ApplyZ =
                        () =>
                    {
                        v.style.fontSize = (z * 3) + "em";
                        v.style.Opacity  = z;
                        v.style.zIndex   = (z * 1000).Floor();
                    };


                    ApplyZ();

                    var x = 100d;
                    var y = 80.Random();

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

                    Action UpdatePosition =
                        () =>
                    {
                        v.style.left = x + "%";
                        v.style.top  = y + "%";
                    };

                    UpdatePosition();

                    v.AttachTo(body);


                    var handler = default(Action <Timer>);


                    Action DisposeThisVector =
                        delegate
                    {
                        timer_handler -= handler;
                        v.FadeOut();

                        done();
                    };

                    v.ondblclick +=
                        ev =>
                    {
                        DisposeThisVector();
                    };

                    var IsHover = false;

                    v.onmousedown +=
                        ev =>
                    {
                        ev.PreventDefault();
                    };

                    v.onmouseover +=
                        delegate
                    {
                        v.style.color = doc.Style.HoverColor;
                        IsHover       = true;
                    };

                    v.onmouseout +=
                        delegate
                    {
                        v.style.color = Color.None;
                        IsHover       = false;
                    };

                    v.onmousewheel +=
                        ev =>
                    {
                        z = (z + 0.02 * ev.WheelDirection).Max(0.5).Min(1.0);

                        ApplyZ();
                    };

                    var drag = new DragHelper(v);

                    drag.Enabled   = true;
                    drag.DragMove +=
                        delegate
                    {
                        var w = Native.window.Width;
                        var h = Native.window.Height;


                        x = (drag.Position.X * 100 / w);
                        y = (drag.Position.Y * 100 / h);

                        UpdatePosition();

                        // v.style.SetLocation(drag.Position.X, drag.Position.Y);
                    };

                    handler =
                        timer =>
                    {
                        if (drag.IsDrag)
                        {
                            return;
                        }

                        if (IsHover)
                        {
                            return;
                        }


                        x -= 0.4 * z;

                        UpdatePosition();

                        drag.Position = new Point(v.offsetLeft, v.offsetTop);

                        if (v.GetOffsetRight() < 0)
                        {
                            DisposeThisVector();
                        }
                    };

                    timer_handler += handler;
                };

                var SpawnNextVector = SpawnVector.AsCyclic();


                var SpawnRandom = default(Action <int, int, Action>);

                SpawnRandom =
                    (counter, max, h) =>
                {
                    max.Random().Delayed(
                        () =>
                    {
                        h();

                        counter--;

                        if (counter > 0)
                        {
                            SpawnRandom(counter, max, h);
                        }
                    }
                        );
                };


                SpawnRandom(doc.Count.ToInt32(), 3000, SpawnNextVector);

                kbd.Enabled = true;
            }
                                );

            reset();
        }
예제 #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)
        {
            #region serviceworker
            if (Native.serviceworker != null)
            {
                // since chrome does not yet tell us who the clients
                //are we need to collect the intel in user code?

                var clients = new { e = default(MessageEvent), edata = default(ClientData) }.AsEmptyListWithEvents();

                Native.serviceworker.onmessage += e =>
                {
                    var edata = (ClientData)e.data;

                    // if the data identity is already know, then its an update
                    // we will ignore current ports and reuse previous ones.

                    var known = clients.Source.FirstOrDefault(x => x.edata.identity == edata.identity);
                    if (known != null)
                    {
                        if (known.edata.window_screenLeft == edata.window_screenLeft)
                        {
                            if (known.edata.window_screenTop == edata.window_screenTop)
                            {
                                if (known.edata.closed == edata.closed)
                                {
                                    // discard as nop
                                    return;
                                }
                            }
                        }

                        Console.WriteLine(
                            "serviceworker.onmessage update " + new
                        {
                            edata.window_screenLeft,
                            edata.window_screenTop
                        }
                            );

                        known.edata.closed            = edata.closed;
                        known.edata.window_screenLeft = edata.window_screenLeft;
                        known.edata.window_screenTop  = edata.window_screenTop;
                        known.edata.window_Width      = edata.window_Width;
                        known.edata.window_Height     = edata.window_Height;

                        // data updated
                        // let everybody know

                        clients.Source.WithEach(
                            x =>
                        {
                            // let each know of this specific data item, not about their own data
                            x.e.postMessage(known.edata);
                        }
                            );


                        return;
                    }


                    // how could the as operator know if object is of a type
                    //var edata = e.data as ClientData;

                    // 48686ms serviceworker.onmessage {{ source = null, data = [object Object] }}

                    // tab is telling us something.

                    Console.WriteLine(
                        "serviceworker.onmessage " + new
                    {
                        edata.screen_width,
                        edata.screen_height
                    }
                        );

                    //e.postMessage("got it! " + new
                    //{
                    //    edata.screen_width,
                    //    edata.screen_height
                    //}
                    //);

                    // echo back what the tab told us
                    e.postMessage(edata);

                    // late to the party?
                    // let the newby know about the others.

                    clients.Source.WithEach(
                        n =>
                    {
                        e.postMessage(n.edata);
                    }
                        );

                    clients.Source.Add(new { e, edata });

                    clients.Added +=
                        (n, nindex) =>
                    {
                        Console.WriteLine(
                            "serviceworker.onmessage  clients.Added " + new
                        {
                            nindex
                        }
                            );


                        // report that somebody joined?
                        e.postMessage(n.edata);
                    };
                };

                return;
            }
            #endregion



            // this does not work within shadow root, due to css use?
            //FormStyler.AtFormCreated = FormStylerLikeChrome.LikeChrome;

            // wont see it on black background
            //FormStyler.AtFormCreated = FormStylerLikeFloat.LikeFloat;

            new IHTMLAnchor {
                href = "chrome://serviceworker-internals", innerText = "chrome://serviceworker-internals"
            }.AttachToDocument();
            new IHTMLPre {
                "Opens the DevTools window for ServiceWorker on start for debugging."
            }.AttachToDocument();

            new IHTMLBreak {
            }.AttachToDocument();

            #region register
            if (Native.window.navigator.serviceWorker.controller == null)
            {
                Native.css.style.borderTop = "1em solid red";

                // we need to register!

                new { }.With(async delegate
                {
                    var sw = Stopwatch.StartNew();

                    new IHTMLPre {
                        "service register!"
                    }.AttachToDocument();

                    // should jsc do this automatically?
                    // how many test cases should be made to understand it?
                    var activated = await Native.window.navigator.serviceWorker.activate();


                    new IHTMLPre {
                        "service activated! " + new { sw.ElapsedMilliseconds }
                    }.AttachToDocument();

                    Native.css.style.borderTop = "1em solid yellow";

                    new IHTMLButton {
                        "reload to become controlled client "
                    }.AttachToDocument().onclick +=
                        delegate
                    {
                        // is this something jsc app should do automatically?
                        Native.document.location.reload();
                    };
                }
                             );



                return;
            }
            else
            {
                Native.css.style.borderTop = "1em solid green";

                new IHTMLPre {
                    "service as controller!"
                }.AttachToDocument();
            }
            #endregion



            // we need to get roslyn compiler to work for scriptcorelib windows forms.

            // dual 4k is to be the max for visualization?
            // shall we use templates to bring the point across?


            // based on
            // X:\jsc.svn\examples\javascript\Test\TestServiceWorkerFetchHTML\TestServiceWorkerFetchHTML\Application.cs
            // X:\jsc.svn\examples\javascript\Test\TestIScreen\TestIScreen\Application.cs
            // X:\jsc.svn\examples\javascript\test\TestServiceWorkerVisualizedScreens\TestServiceWorkerVisualizedScreens\Application.cs
            // X:\jsc.svn\examples\javascript\Test\TestServiceWorkerScreens\TestServiceWorkerScreens\Application.cs

            // jsc, how do the templates work again, i forgot?

            //Native.tem

            //Native.shadow

            var desktop = new IHTMLDiv();

            new IStyle(desktop)
            {
                backgroundColor = "black",


                // need to glue it
                position = IStyle.PositionEnum.absolute,
                top      = "0px",
                right    = "0px",
                bottom   = "0px",
                left     = "0px",

                // no scrollbars. thanks
                // how will this work for android multiscreeners?
                overflow = IStyle.OverflowEnum.hidden
            };

            //__Form.

            //Native.shadow = desktop;

            desktop.AttachTo(Native.shadow);
            //Native.shadow

            // actully the offset and scale.
            // screen0 as background should be there as another element.


            var offsetandscale = new IHTMLDiv();

            new IStyle(offsetandscale)
            {
                // the viewport info?

                //backgroundColor = "darkcyan",
                backgroundColor = "gray",


                // need to glue it
                position = IStyle.PositionEnum.absolute,


                // both screens should be able to fit here
                top  = "100px",
                left = "100px",

                width  = "600px",
                height = "600px",


                transformOrigin = "0% 0%",
                transform       = "scale(0.3)"
            };

            offsetandscale.AttachTo(desktop);

            var screen0 = new IHTMLDiv();

            new IStyle(screen0)
            {
                // the viewport info?

                backgroundColor = "darkcyan",


                // need to glue it
                position = IStyle.PositionEnum.absolute,


                // both screens should be able to fit here
                top  = "0px",
                left = "0px",

                width  = "600px",
                height = "600px",
            };

            screen0.AttachTo(offsetandscale);


            // why would it be a good idea to maximize?
            //new Form().AttachFormTo(desktop);


            //namespace ScriptCoreLib.JavaScript.Extensions
            //
            // where are they defined?
            //new Form().AttachControlTo(desktop);



            var data = new ClientData
            {
                identity = new Random().Next(),


                screen_width  = Native.screen.width,
                screen_height = Native.screen.height,

                //Native.window.aspect,

                window_Width  = Native.window.Width,
                window_Height = Native.window.Height,

                // where is this window on current screen?
                //(Native.window as dynamic).offsetLeft,
                //(Native.window as dynamic).offsetTop,

                window_screenLeft = (Native.window as dynamic).screenLeft,
                window_screenTop  = (Native.window as dynamic).screenTop,

                // if we were to update, mutate this object,
                // how would we distribute the knowledge?
                // with sync events?
            };


            var f = new Form
            {
                // frame0
                Text = new { data.window_screenLeft, data.window_screenTop }.ToString(),

                Left = data.window_screenLeft,
                Top  = data.window_screenTop
            };

            f.GetHTMLTarget().AttachTo(offsetandscale);

            var fcontent = new IHTMLContent {
                select = "body"
            };
            fcontent.AttachTo(f.GetHTMLTargetContainer());

            f.Show();


            #region Toggle
            Action Toggle =
                delegate
            {
                if (desktop.parentNode == null)
                {
                    // show setup mode again
                    Native.shadow.replaceChild(
                        desktop, Native.shadow.firstChild
                        );
                }
                else
                {
                    // remove the screen setup mode
                    desktop.Orphanize();
                    new IHTMLContent {
                    }.AttachTo(Native.shadow);
                }
            };

            Native.document.onkeyup +=
                e =>
            {
                // US
                if (e.KeyCode == 222)
                {
                    Toggle();
                }
                // EE
                if (e.KeyCode == 192)
                {
                    Toggle();
                }
            };
            #endregion


            var lookup = new Dictionary <int, Form> {
                { data.identity, f }
            };



            new IHTMLPre {
                "lets tell the service, we have opened a new tab. "
            }.AttachToDocument();

            #region postMessage
            Native.window.navigator.serviceWorker.controller.postMessage(
                data,

                // data updated o the other side.
                // lets decode.
                m =>
            {
                var mdata = (ClientData)m.data;


                if (!lookup.ContainsKey(mdata.identity))
                {
                    var ff = new Form {
                        Text = new { mdata.identity }.ToString()
                    };

                    ff.GetHTMLTarget().AttachTo(offsetandscale);
                    ff.Show();
                    ff.Opacity = 0.5;

                    lookup[mdata.identity] = ff;
                }

                {
                    var ff = lookup[mdata.identity];

                    ff.Left = mdata.window_screenLeft;
                    ff.Top  = mdata.window_screenTop;

                    ff.Width  = mdata.window_Width;
                    ff.Height = mdata.window_Height;

                    if (mdata.closed)
                    {
                        ff.Close();
                    }
                }
            }
                );
            #endregion



            // keep it up to date

            #region onframe
            Native.window.onframe +=
                delegate
            {
                if (data.closed)
                {
                    return;
                }



                data.screen_width  = Native.screen.width;
                data.screen_height = Native.screen.height;

                //Native.window.aspect,

                data.window_Width  = Native.window.Width;
                data.window_Height = Native.window.Height;

                // where is this window on current screen?
                //(Native.window as dynamic).offsetLeft,
                //(Native.window as dynamic).offsetTop,

                data.window_screenLeft = (Native.window as dynamic).screenLeft;
                data.window_screenTop  = (Native.window as dynamic).screenTop;



                // keep it in center

                offsetandscale.style.transform = "scale(" + ((data.window_Width * 0.5) / (data.screen_width + 200)) + ")";



                offsetandscale.style.left = (data.window_Width / 2) + "px";
                //offsetandscale.style.top = (Native.window.Height / 2) + "px";

                // assume our monitors are side by side?
                offsetandscale.style.top = (data.window_Height / 4) + "px";

                #region screen0
                // what happens if we move to the other monitor?
                screen0.style.SetSize(
                    data.screen_width,
                    data.screen_height
                    );

                if (data.window_screenLeft < -(data.window_Width / 2))
                {
                    // assume we are on the other monitor to the left?
                    // we do not know the actual offset until we go fullscreen.

                    screen0.style.SetLocation(
                        -data.screen_width,
                        0
                        );
                }
                else
                {
                    screen0.style.SetLocation(
                        0,
                        0
                        );
                }
                #endregion


                //f.Text = new { data.window_screenLeft, data.window_screenTop }.ToString();

                //f.Left = data.window_screenLeft;
                //f.Top = data.window_screenTop;

                //f.Width = data.window_Width;
                //f.Height = data.window_Height;



                // resend data
                Native.window.navigator.serviceWorker.controller.postMessage(data);
            };
            #endregion


            Native.window.onbeforeunload +=
                //Native.window.onunload +=
                delegate
            {
                // move out of view to signify being closed?
                data.closed = true;


                // resend data
                Native.window.navigator.serviceWorker.controller.postMessage(data);
            };
        }
예제 #10
0
        private static IHTMLDiv AddNamespace(IHTMLDiv parent, IHTMLDiv NextNamespaceOrDefault, string Namespace, Action <string> UpdateLocation)
        {
            var div = new IHTMLDiv();

            if (NextNamespaceOrDefault == null)
            {
                div.AttachTo(parent);
            }
            else
            {
                NextNamespaceOrDefault.insertPreviousSibling(div);
            }

            div.style.marginTop  = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = new Namespace().AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight   = "0.5em";

            if (Namespace == "")
            {
                Namespace = "<Module>";
            }

            var s = new IHTMLAnchor {
                innerText = Namespace
            }.AttachTo(div);


            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color          = JSColor.System.WindowText;

            Action onclick = delegate
            {
            };

            s.onclick +=
                e =>
            {
                e.PreventDefault();

                s.focus();

                UpdateLocation(Namespace);

                onclick();
            };

            s.onfocus +=
                delegate
            {
                s.style.backgroundColor = JSColor.System.Highlight;
                s.style.color           = JSColor.System.HighlightText;
            };

            s.onblur +=
                delegate
            {
                s.style.backgroundColor = JSColor.None;
                s.style.color           = JSColor.System.WindowText;
            };

            var children = new IHTMLDiv().AttachTo(div);

            children.style.paddingLeft = "1em";
            children.Hide();


            var NextClickHide = default(Action);
            var NextClickShow = default(Action);

            NextClickHide =
                delegate
            {
                children.Hide();

                onclick = NextClickShow;
            };

            NextClickShow =
                delegate
            {
                children.Show();

                onclick = NextClickHide;
            };


            onclick = NextClickShow;

            return(children);
        }
예제 #11
0
        public void Initialize()
        {
            Native.Document.body.style.padding = "0";
            Native.Document.body.style.margin  = "0";

            var Images       = new Dictionary <string, IHTMLImage>();
            var ImagesLoaded = default(Action);
            Func <string, IHTMLImage> CloneImage = name => (IHTMLImage)Images[name].cloneNode(false);

            var Zoom = Data.Zoom.ToDouble();

            var ControlSize = new ZoomedPoint
            {
                Z = Zoom,
                X = Data.ControlSize.Xint,
                Y = Data.ControlSize.Yint
            };

            Control.style.SetSize(ControlSize.ZoomedXint, ControlSize.ZoomedYint);
            Control.style.backgroundColor = Data.BackgroundColor;
            Control.style.color           = Data.TextColor;
            Control.AttachAsNextOrToDocument(null);
            Control.style.position = IStyle.PositionEnum.relative;

            Action LoadImages =
                delegate
            {
                Data.Sprites.ForEach(
                    i =>
                {
                    Images[i.Value] = i.ImageValue;
                }
                    );

                ImagesLoaded();
            };

            ImagesLoaded =
                delegate
            {
                var ClientRectPos = new ZoomedPoint
                {
                    Z = Zoom,
                    X = Data.ClientRect.From.Xint,
                    Y = Data.ClientRect.From.Yint
                };

                var ClientRectSize = new ZoomedPoint
                {
                    Z = Zoom,
                    X = Data.ClientRect.Size.Xint,
                    Y = Data.ClientRect.Size.Yint
                };

                var ContentLayer = new IHTMLDiv();

                ContentLayer.style.backgroundColor = Data.ClientRectColor;
                ContentLayer.style.overflow        = IStyle.OverflowEnum.hidden;

                ContentLayer.style.SetLocation(
                    ClientRectPos.ZoomedXint,
                    ClientRectPos.ZoomedYint,
                    ClientRectSize.ZoomedXint,
                    ClientRectSize.ZoomedYint
                    );
                ContentLayer.AttachTo(Control);


                //var r1 = CloneImage("room 001").AttachTo(ContentLayer);

                //r1.style.SetLocation(0, 0, ClientRectSize.ZoomedXint, ClientRectSize.ZoomedYint);

                Func <string, IHTMLImage> CreateRoomImage =
                    name =>
                {
                    var r2 = CloneImage(name);

                    r2.AttachTo(ContentLayer);

                    var r2_Zoom = new ZoomedPoint
                    {
                        Z = Zoom,
                        X = Images[name].width,
                        Y = Images[name].height
                    };

                    r2.Hide();
                    r2.style.SetLocation(0, 0, r2_Zoom.ZoomedXint, r2_Zoom.ZoomedYint);

                    return(r2);
                };

                var KnownRooms = new List <IHTMLImage>();

                KnownRooms.AddRange(
                    new []
                {
                    CreateRoomImage("room 001"),
                    CreateRoomImage("room 002"),
                    CreateRoomImage("room 024"),
                    CreateRoomImage("room 031"),
                    CreateRoomImage("room 032"),
                }
                    );

                var CurrentRoom = KnownRooms.Random();

                CurrentRoom.Show();

                Action <double> SetClipTo =
                    percentage =>
                {
                    var x = (ClientRectSize.ZoomedX * percentage / 2).ToInt32();
                    var y = (ClientRectSize.ZoomedY * percentage / 2).ToInt32();

                    var clip = new CSSClip
                    {
                        Left   = x,
                        Top    = y,
                        Right  = (ClientRectSize.ZoomedX - x).ToInt32(),
                        Bottom = (ClientRectSize.ZoomedY - y).ToInt32()
                    };

                    Console.WriteLine(percentage + " clip: " + clip);

                    ContentLayer.style.clip = clip;
                };

                //ContentLayer.style.clip = "rect(15px auto auto 15px)";

                //var timer = new ScriptCoreLib.JavaScript.Runtime.Timer(
                //    delegate
                //    {
                //        var p = (Math.Sin(DateTime.Now.Ticks) + 1) / 2;

                //        Console.WriteLine("p: " + p);
                //        SetClipTo(p);
                //    }
                //    , 0, 200);

                //var pc = 50;
                //var px = 200;

                //Action<double> pChange = i => { px += (i * pc).ToInt32(); timer.StartInterval(px); };

                Action <Action, Action> FadeOut =
                    (Starting, Stopping) =>
                    new LinearTimeTween
                {
                    Length    = 300,
                    Starting  = Starting,
                    Stopping  = Stopping,
                    Changed   = t => SetClipTo(t),
                    Percision = 20
                }.Start();

                Action <Action, Action> FadeIn =
                    (Starting, Stopping) =>
                    new LinearTimeTween
                {
                    Length    = 300,
                    Starting  = Starting,
                    Stopping  = Stopping,
                    Changed   = t => SetClipTo(1d - t),
                    Percision = 20
                }.Start();

                var kbd = new KeyboardEvents {
                    Enabled = true
                };

                kbd.left += ev =>
                            FadeOut(
                    () => kbd.Enabled = false,
                    () =>
                {
                    CurrentRoom.Hide();
                    CurrentRoom = KnownRooms.Previous(i => CurrentRoom == i);
                    CurrentRoom.Show();

                    //r1.Hide();
                    //r2.Show();

                    FadeIn(null, () => kbd.Enabled = true);
                }
                    );

                kbd.right += ev =>
                             FadeOut(
                    () => kbd.Enabled = false,
                    () =>
                {
                    CurrentRoom.Hide();
                    CurrentRoom = KnownRooms.Next(i => CurrentRoom == i);
                    CurrentRoom.Show();

                    FadeIn(null, () => kbd.Enabled = true);
                }
                    );


                Native.Document.onkeydown += kbd;

                Native.Document.onmousedown +=
                    ev =>
                    FadeOut(
                        () => kbd.Enabled = false,
                        () =>
                {
                    CurrentRoom.Hide();
                    CurrentRoom = KnownRooms.Next(i => CurrentRoom == i);
                    CurrentRoom.Show();

                    FadeIn(null, () => kbd.Enabled = true);
                }
                        );

                /*
                 * var div1 = SpawnDiv(Images, false);
                 *
                 * div1.style.backgroundColor = Color.Yellow;
                 * div1.AttachTo(ClientRect);
                 * div1.style.SetLocation(4, 4, 100, 100);
                 *
                 * var div2 = SpawnDiv(Images, true);
                 *
                 * div2.style.backgroundColor = Color.Gray;
                 * div2.AttachTo(ClientRect);
                 * div2.style.SetLocation(100, 4, 100, 100);
                 *
                 */
            };

            LoadImages();
        }
예제 #12
0
        // vNext should be semi 3D - http://www.freeworldgroup.com/games/3dworm/index.html

        public Game()
        {
            //typeof(ConsoleWorm).ToWindowText();

            var canvas = new IHTMLDiv();

            canvas.style.overflow = IStyle.OverflowEnum.hidden;
            canvas.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);
            canvas.style.backgroundColor = Color.Black;
            canvas.AttachToDocument();
            //canvas.style.position = IStyle.PositionEnum.relative;


            new HTML.Images.FromAssets.avatar14683_21().InvokeOnComplete(
                scull =>
            {
                new global::ConsoleWorm.HTML.Audio.FromAssets.applause().play();

                var zoom = 24;

                Func <int> RoomWidth  = () => (Native.window.Width / zoom).ToInt32();
                Func <int> RoomHeight = () => ((Native.window.Height /*- scull.height - 16*/) / zoom).ToInt32();

                var score  = 0;
                var status = new IHTMLDiv("0$");
                var isdead = false;
                var paused = true;


                status.style.color      = Color.Green;
                status.style.fontFamily = IStyle.FontFamilyEnum.Consolas;


                scull.AttachTo(canvas);
                scull.style.SetLocation(
                    8,
                    Native.window.Height - scull.height - 8);


                status.AttachTo(canvas);
                status.style.SetLocation(
                    8 + scull.width + 8,
                    Native.window.Height - scull.height
                    );
                Native.window.onresize +=
                    delegate
                {
                    canvas.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);
                    scull.style.SetLocation(
                        8,
                        Native.window.Height - scull.height - 8);
                    status.style.SetLocation(
                        8 + scull.width + 8,
                        Native.window.Height - scull.height
                        );
                };



                Func <Point> GetRandomLocation =
                    () => new Point(
                        (RoomWidth() - 1).Random(),
                        (RoomHeight() - 1).Random()
                        );

                var game_colors = new
                {
                    worm = new
                    {
                        active   = Color.FromRGB(0, 0xff, 0),
                        inactive = Color.FromRGB(0, 0x7F, 0),
                        excited  = Color.FromRGB(0xff, 0xff, 0),
                    }
                };

                Func <Point, Point> Wrapper =
                    p => new Point((p.X + RoomWidth()) % RoomWidth(), (p.Y + RoomHeight()) % RoomHeight());


                Func <Apple> CreateApple =
                    () => new Apple
                {
                    GetRandomLocation = GetRandomLocation,
                    GetZoom           = () => zoom,
                    Wrapper           = Wrapper
                }.MoveToRandomLocation();


                var apples = new List <Apple>
                {
                };

                10.Times(() =>
                         apples.Add(
                             CreateApple()
                             )
                         );

                apples.ForEach(a => a.AttachTo(canvas));



                var worm = new Worm
                {
                    Wrapper  = Wrapper,
                    Location = new Point(4, 8),
                    GetZoom  = () => zoom,
                    Canvas   = canvas,
                    Vector   = new Point(0, 1),
                    Color    = game_colors.worm.active
                }
                .Grow()
                .GrowToVector()
                .GrowToVector();



                Action <int> AddScore = x =>
                {
                    score += x;

                    if (isdead)
                    {
                        status.innerText = score + "$ - Game Over - Enter to continue";
                    }
                    else if (paused)
                    {
                        status.innerText = score + "$ - Paused - Zoom: " + zoom;
                    }
                    else
                    {
                        status.innerText = score + "$";
                    }

                    worm.Color         = game_colors.worm.excited;
                    status.style.color = JSColor.Yellow;
                };


                100.AtInterval(
                    t =>
                {
                    if (paused)
                    {
                        // slowdown
                        if (t.Counter % 4 == 0)
                        {
                            if (worm.Color == game_colors.worm.active)
                            {
                                worm.Color         = game_colors.worm.inactive;
                                status.style.color = game_colors.worm.inactive;
                            }
                            else
                            {
                                worm.Color         = game_colors.worm.active;
                                status.style.color = game_colors.worm.active;
                            }
                        }

                        return;
                    }

                    if (worm.Parts.Any(i => i.Location.IsEqual(worm.NextLocation)))
                    {
                        paused = true;
                        isdead = true;

                        AddScore(0);
                        new global::ConsoleWorm.HTML.Audio.FromAssets.buzzer().play();

                        return;
                    }

                    worm.Color         = game_colors.worm.active;
                    status.style.color = Color.Green;
                    worm.GrowToVector();

                    // did we find an apple?
                    var a = apples.Where(i => i.Location.IsEqual(worm.Location)).ToArray();

                    if (a.Length > 0)
                    {
                        foreach (var v in a)
                        {
                            v.MoveToRandomLocation();
                        }

                        new global::ConsoleWorm.HTML.Audio.FromAssets.tick().play();

                        AddScore(1);
                    }
                    else
                    {
                        worm.Shrink();
                    }
                }
                    );

                var map = new[]
                {
                    new { KeyCode = 38, Point = new Point(0, -1) },                               // up
                    new { KeyCode = 37, Point = new Point(-1, 0) },                               // left
                    new { KeyCode = 39, Point = new Point(1, 0) },                                // right
                    new { KeyCode = 40, Point = new Point(0, 1) },                                // down,

                    new { KeyCode = (int)System.Windows.Forms.Keys.W, Point = new Point(0, -1) }, // up
                    new { KeyCode = (int)System.Windows.Forms.Keys.A, Point = new Point(-1, 0) }, // left
                    new { KeyCode = (int)System.Windows.Forms.Keys.D, Point = new Point(1, 0) },  // right
                    new { KeyCode = (int)System.Windows.Forms.Keys.S, Point = new Point(0, 1) },  // down
                };

                Func <IEvent, bool> IsPauseKey =
                    ev => ev.IsKeyCode("pP") || ev.KeyCode == 8504;

                var PreviousKeyCode = 40;

                Native.Document.body.onselectstart +=
                    ev =>
                {
                    ev.PreventDefault();
                    ev.StopPropagation();
                };


                Action <IEvent> AtClick =
                    ev =>
                {
                    ev.PreventDefault();
                    ev.StopPropagation();
                    var KeyCode = PreviousKeyCode;

                    if (ev.CursorX < Native.window.Width / 2)
                    {
                        if (KeyCode == 38)
                        {
                            KeyCode = 37;
                        }
                        else if (KeyCode == 37)
                        {
                            KeyCode = 40;
                        }
                        else if (KeyCode == 40)
                        {
                            KeyCode = 39;
                        }
                        else if (KeyCode == 39)
                        {
                            KeyCode = 38;
                        }
                        // turn left
                    }
                    else
                    {
                        if (KeyCode == 38)
                        {
                            KeyCode = 39;
                        }
                        else if (KeyCode == 37)
                        {
                            KeyCode = 38;
                        }
                        else if (KeyCode == 40)
                        {
                            KeyCode = 37;
                        }
                        else if (KeyCode == 39)
                        {
                            KeyCode = 40;
                        }


                        // turn right
                    }


                    if (isdead)
                    {
                        while (worm.Parts.Count > 2)
                        {
                            worm.Shrink();
                        }

                        paused = false;
                        isdead = false;
                        AddScore(-score);
                        new global::ConsoleWorm.HTML.Audio.FromAssets.reveal().play();
                        return;
                    }


                    if (paused)
                    {
                        paused = !paused;

                        if (!paused)
                        {
                            worm.Color         = game_colors.worm.active;
                            status.style.color = game_colors.worm.active;
                        }

                        canvas.requestFullscreen();

                        AddScore(0);
                        new global::ConsoleWorm.HTML.Audio.FromAssets.reveal().play();

                        return;
                    }

                    if (!paused)
                    {
                        var v = map.SingleOrDefault(i => i.KeyCode == KeyCode);

                        if (v != null)
                        {
                            ev.PreventDefault();


                            if ((worm.Vector + v.Point).IsZero())
                            {
                                return;
                            }

                            PreviousKeyCode = v.KeyCode;
                            worm.Vector     = v.Point;
                        }
                    }
                };

                Native.Document.body.onclick += AtClick;


                #region onkeyup
                Native.Document.onkeyup +=
                    ev =>
                {
                    if (isdead)
                    {
                        if (ev.IsReturn)
                        {
                            while (worm.Parts.Count > 2)
                            {
                                worm.Shrink();
                            }

                            paused = false;
                            isdead = false;
                            AddScore(-score);
                            new global::ConsoleWorm.HTML.Audio.FromAssets.reveal().play();
                        }
                    }

                    if (!paused)
                    {
                        var v = map.SingleOrDefault(i => i.KeyCode == ev.KeyCode);

                        if (v != null)
                        {
                            ev.PreventDefault();


                            if ((worm.Vector + v.Point).IsZero())
                            {
                                return;
                            }

                            worm.Vector = v.Point;
                        }

                        if (ev.IsReturn)
                        {
                            apples.Add(
                                CreateApple().AttachTo(canvas)
                                );
                        }
                        else
                        if (ev.KeyCode == 33)
                        {
                            zoom--;
                            zoom = zoom.Max(8);

                            apples.ForEach(a => a.MoveToLocation());
                            worm.Parts.ForEach(p => p.MoveToLocation());
                        }
                        else if (ev.KeyCode == 34)
                        {
                            zoom++;
                            zoom = zoom.Min(64);
                            apples.ForEach(a => a.MoveToLocation());
                            worm.Parts.ForEach(p => p.MoveToLocation());
                        }
                    }

                    if (!isdead)
                    {
                        if (IsPauseKey(ev))
                        {
                            paused = !paused;

                            if (!paused)
                            {
                                worm.Color         = game_colors.worm.active;
                                status.style.color = game_colors.worm.active;
                            }

                            AddScore(0);
                        }
                    }
                };
                #endregion
            }
                );
        }
        private void RenderWriteHistory(Dictionary <SolutionFileTextFragment, Color> Lookup, SolutionFile f, IHTMLElement Container)
        {
            Func <SolutionFileTextFragment, Color> LookupOrDefault =
                ff =>
            {
                if (this.Colors.ContainsKey(ff))
                {
                    return(this.Colors[ff]);
                }

                return(this.Colors[SolutionFileTextFragment.None]);
            };

            var Content = new IHTMLDiv().AttachTo(Container);


            Content.style.position = IStyle.PositionEnum.relative;

            var ViewBackground = new IHTMLDiv().AttachTo(Content);

            ViewBackground.style.position     = IStyle.PositionEnum.absolute;
            ViewBackground.style.left         = "0px";
            ViewBackground.style.top          = "0px";
            ViewBackground.style.width        = "4em";
            ViewBackground.style.borderRight  = "1px dotted gray";
            ViewBackground.style.paddingRight = "0.5em";

            var ViewTrap = new IHTMLDiv().AttachTo(Content);

            ViewTrap.style.position = IStyle.PositionEnum.absolute;
            ViewTrap.style.left     = "0px";
            ViewTrap.style.top      = "0px";
            ViewTrap.style.right    = "0px";
            ViewTrap.style.bottom   = "0px";
            //ViewTrap.style.backgroundColor = Color.White;

            var ViewTrapContainer = new IHTMLDiv().AttachTo(ViewTrap);

            ViewTrapContainer.style.cursor      = IStyle.CursorEnum.text;
            ViewTrapContainer.style.position    = IStyle.PositionEnum.relative;
            ViewTrapContainer.style.paddingLeft = "5em";

            var View = new IHTMLDiv().AttachTo(ViewTrapContainer);



            var ContentHeightDummy = new IHTMLDiv().AttachTo(Content);

            var RegionStack  = new Stack <List <Action <bool> > >();
            var RegionGlobal = new List <Action <bool> >();

            RegionStack.Push(RegionGlobal);

            var Lines = new List <IHTMLDiv>();

            var CurrentLineDirty   = false;
            var CurrentLine        = default(IHTMLDiv);
            var CurrentLineContent = default(IHTMLDiv);

            Action NextLine = delegate
            {
                CurrentLineDirty = false;

                var c  = new IHTMLDiv();
                var cc = new IHTMLDiv();
                var cb = new IHTMLDiv();

                CurrentLine        = c.AttachTo(View);
                CurrentLineContent = cc.AttachTo(c);

                var CurrentRegion = RegionStack.Peek();

                RegionStack.WithEach(
                    k =>
                {
                    k.Add(
                        IsActive =>
                    {
                        // should we react when in a global region
                        if (k == RegionGlobal)
                        {
                            return;
                        }

                        if (IsActive)
                        {
                            cc.style.backgroundColor = Color.FromGray(0xf9);
                            cb.style.backgroundColor = Color.FromGray(0xf9);
                        }
                        else
                        {
                            cc.style.backgroundColor = Color.None;
                            cb.style.backgroundColor = Color.None;
                        }
                    }
                        );
                }
                    );

                CurrentLine.onmouseover +=
                    delegate
                {
                    CurrentRegion.Invoke(true);
                    cc.style.backgroundColor = Color.FromGray(0xf0);
                    cb.style.backgroundColor = Color.FromGray(0xf0);
                };

                CurrentLine.onmouseout +=
                    delegate
                {
                    CurrentRegion.Invoke(false);
                    cc.style.backgroundColor = Color.None;
                    cb.style.backgroundColor = Color.None;
                };


                Lines.Add(CurrentLine);
                //CurrentLineContent.style.marginLeft = "5em";

                var BCurrentLine = cb.AttachTo(ViewBackground);

                BCurrentLine.style.textAlign = IStyle.TextAlignEnum.right;

                var span = new IHTMLCode {
                    innerText = "" + Lines.Count
                };
                span.style.color = Lookup[SolutionFileTextFragment.Type];
                span.AttachTo(BCurrentLine);

                //Content.style.height = Lines.Count + "em";

                new IHTMLDiv {
                    new IHTMLCode {
                        innerText = Environment.NewLine
                    }
                }.AttachTo(ContentHeightDummy);
            };



            foreach (var item in f.WriteHistory.ToArray())
            {
                if (item is SolutionFileWriteArguments.BeginRegion)
                {
                    RegionStack.Push(new List <Action <bool> >());
                }

                if (item is SolutionFileWriteArguments.EndRegion)
                {
                    RegionStack.Pop();
                }

                if (CurrentLine == null)
                {
                    NextLine();
                }



                var innerText = item.Text;
                innerText = innerText.TakeUntilLastIfAny(Environment.NewLine);

                if (!string.IsNullOrEmpty(innerText))
                {
                    var span = new IHTMLCode {
                        innerText = innerText
                    };

                    if (item.Fragment == SolutionFileTextFragment.Indent)
                    {
                        span.style.width   = "2em";
                        span.style.display = IStyle.DisplayEnum.inline_block;

                        if (CurrentLineDirty)
                        {
                            span.style.borderLeft = "1px dotted #afafaf";
                        }
                    }


                    span.style.color = LookupOrDefault(item.Fragment);

                    CurrentLineDirty = true;
                    span.AttachTo(CurrentLineContent);

                    if (item.Tag != null)
                    {
                        span.style.cursor = ScriptCoreLib.JavaScript.DOM.IStyle.CursorEnum.pointer;
                        span.onmouseover +=
                            delegate
                        {
                            span.style.textDecoration = "underline";
                        };

                        span.onmouseout +=
                            delegate
                        {
                            span.style.textDecoration = "";
                        };



                        var Type = item.Tag as SolutionProjectLanguageType;
                        if (Type != null)
                        {
                            span.title = Type.FullName;
                        }

                        var Method = item.Tag as SolutionProjectLanguageMethod;
                        if (Method != null)
                        {
                            span.title = Method.Name;
                        }


                        var Uri = item.Tag as Uri;
                        if (Uri != null)
                        {
                            var a = new IHTMLAnchor();
                            a.style.color = LookupOrDefault(item.Fragment);

                            a.href   = Uri.ToString();
                            a.target = "_blank";
                            a.Add(span);
                            a.AttachTo(CurrentLineContent);

                            a.onclick +=
                                e =>
                            {
                                // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201511/20151103
                                e.preventDefault();

                                if (LinkCommentClick != null)
                                {
                                    LinkCommentClick(Uri);
                                }
                            };
                        }
                    }
                }

                if (item.Text.EndsWith(Environment.NewLine))
                {
                    if (!CurrentLineDirty)
                    {
                        var span = new IHTMLCode {
                            innerText = " "
                        };
                        span.AttachTo(CurrentLineContent);
                    }

                    CurrentLine = null;
                }
            }
        }
예제 #14
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(IDefault page = null)
        {
            // used by
            // X:\jsc.svn\examples\javascript\WebGL\WebGLGoldDropletTransactions\WebGLGoldDropletTransactions\Application.cs


            if (DisableBackground)
            {
                // nop
            }
            else
            {
                //page.body.style.backgroundColor = "#4584b4";

                container.style.backgroundColor = "#4584b4";
            }

            // Bg gradient

            //var canvas = new IHTMLCanvas();
            //canvas.width = 32;
            //canvas.height = Native.Window.Height;

            //var context = (CanvasRenderingContext2D)canvas.getContext("2d");

            //var gradient = context.createLinearGradient(0, 0, 0, canvas.height);
            //gradient.addColorStop(0f, "#1e4877");
            //gradient.addColorStop(0.5f, "#4584b4");

            //context.fillStyle = gradient;
            //context.fillRect(0, 0, canvas.width, canvas.height);


            // Clouds

            //var , , renderer, sky, mesh, , material,
            //, h, color, colors = [], sprite, size, x, y, z;

            var mouseX     = 0f;
            var start_time = new IDate().getTime();

            Console.WriteLine(new { Native.window.Width, Native.window.Height });

            var windowHalfX = Native.window.Width / 2;
            var windowHalfY = Native.window.Height / 2;

            Console.WriteLine(new { DefaultMouseY });

            var mouseY = (float)((Native.window.Height * DefaultMouseY - windowHalfY) * 0.15);

            //Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

            if (page == null)
            {
                container.AttachToDocument();
            }
            else
            {
                container.AttachTo(page.body);
            }

            container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);
            //container.style.background = "url(" + canvas.toDataURL("image/png") + ")";

            #region Dispose
            var IsDisposed = false;

            Dispose = delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                IsDisposed = true;

                container.Orphanize();
            };
            #endregion



            var camera = new THREE.PerspectiveCamera(30, Native.window.aspect, 1, 3000);
            camera.position.z = 6000;

            var scene = new THREE.Scene();

            var geometry = new THREE.Geometry();

            //var texture = THREE.ImageUtils.loadTexture(new HTML.Images.FromAssets.cloud10().src);
            var texture = THREE.ImageUtils.loadTexture(CloudTexture);

            texture.magFilter = THREE.LinearMipMapLinearFilter;
            texture.minFilter = THREE.LinearMipMapLinearFilter;

            // FogColor
            //var fog = new THREE.Fog(0x4584b4, -100, 3000);
            var fog = new THREE.Fog(FogColor, -100, 3000);


            // what about sprites?
            var material = new THREE.ShaderMaterial(

                new
            {
                uniforms = new
                {
                    map      = new { type = "t", value = texture },
                    fogColor = new { type = "c", value = fog.color },
                    fogNear  = new { type = "f", value = fog.near },
                    fogFar   = new { type = "f", value = fog.far },
                },

                vertexShader   = new GeometryVertexShader().ToString(),
                fragmentShader = new GeometryFragmentShader().ToString(),
                depthWrite     = false,
                depthTest      = false,
                transparent    = true
            }
                );

            var          r           = new Random();
            Func <float> Math_random = () => (float)r.NextDouble();

            var plane = new THREE.Mesh(new THREE.PlaneGeometry(64, 64));

            for (var i = 0; i < 8000; i++)
            {
                plane.position.x = Math_random() * 1000 - 500;
                plane.position.y = -Math_random() * Math_random() * 200 - 15;
                plane.position.z = i;
                plane.rotation.z = (f)(Math_random() * Math.PI);
                plane.scale.x    = Math_random() * Math_random() * 1.5f + 0.5f;
                plane.scale.y    = plane.scale.x;

                THREE.GeometryUtils.merge(geometry, plane);
            }

            var mesh = new THREE.Mesh(geometry, material);
            scene.add(mesh);

            mesh            = new THREE.Mesh(geometry, material);
            mesh.position.z = -8000;
            scene.add(mesh);

            var renderer = new THREE.WebGLRenderer(new { antialias = false });
            renderer.setSize(Native.window.Width, Native.window.Height);
            container.appendChild(renderer.domElement);

            container.style.SetLocation(0, 0, Native.window.Width, Native.window.Height);

            #region onresize
            Native.window.onresize +=
                delegate
            {
                container.style.SetSize(Native.window.Width, Native.window.Height);

                camera.aspect = Native.window.aspect;
                camera.updateProjectionMatrix();

                renderer.setSize(Native.window.Width, Native.window.Height);
            };
            #endregion



            #region animate

            Native.window.onframe += delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                var position = ((new IDate().getTime() - start_time) * 0.03) % 8000;


                camera.position.x += (float)((mouseX - camera.position.x) * 0.01);
                camera.position.y += (float)((-mouseY - camera.position.y) * 0.01);

                camera.position.z = (f)(-position + 8000);



                renderer.render(scene, camera);
            };

            #endregion

            Native.document.onmousemove +=
                e =>
            {
                mouseX = (float)((e.CursorX - windowHalfX) * 0.25);
                mouseY = (float)((e.CursorY - windowHalfY) * 0.15);
            };



            //var ze = new ZeProperties();

            //ze.Show();


            //ze.Add(() => renderer);
            ////ze.Add(() => controls);
            //ze.Add(() => scene);
        }
        public MatrixTransformBExample()
        {
            var x = 400;
            var y = 200;
            var w = 200;
            var h = 200;

            var ro_matrix = new IHTMLDiv();

            ro_matrix.style.backgroundColor = "#8080ff";
            ro_matrix.style.SetLocation(x, y);
            ro_matrix.AttachToDocument();
            //ro_matrix.style.paddingLeft = w + "px";
            //ro_matrix.style.paddingTop = h + "px";
            var ro_matric_content = new IHTMLDiv();

            ro_matric_content.style.backgroundColor = "#0000ff";
            ro_matric_content.style.SetSize(w, h);
            ro_matric_content.AttachTo(ro_matrix);


            var r_matrix = new IHTMLDiv();

            r_matrix.style.backgroundColor = "#80ff80";
            r_matrix.style.SetLocation(x, y);
            r_matrix.AttachToDocument();

            //r_matrix.style.paddingLeft = w + "px";
            //r_matrix.style.paddingTop = h + "px";
            var r_matric_content = new IHTMLDiv();

            r_matric_content.style.backgroundColor = "#00ff00";
            r_matric_content.style.SetSize(w, h);
            r_matric_content.AttachTo(r_matrix);


            #region blue rotation
            var jo = new IHTMLDiv();

            jo.style.background = "blue";
            jo.style.SetLocation(x - w / 2 - 4, y - h / 2 - 1, 8, 2);

            jo.AttachToDocument();

            var joh = new IHTMLDiv();

            joh.style.background = "blue";
            joh.style.SetLocation(x - w / 2 - 1, y - h / 2 - 4, 2, 8);

            joh.AttachToDocument();

            jo.BlinkAt(400);
            joh.BlinkAt(400);
            #endregion

            #region black origin
            var zo = new IHTMLDiv();

            zo.style.background = "black";
            zo.style.SetLocation(x - 4, y - 1, 8, 2);

            zo.AttachToDocument();

            var zoh = new IHTMLDiv();

            zoh.style.background = "black";
            zoh.style.SetLocation(x - 1, y - 4, 2, 8);

            zoh.AttachToDocument();
            #endregion



            var ro = new IHTMLDiv();

            ro.style.background = "red";
            ro.style.SetLocation(x, y, w, h);
            ro.style.Opacity = 0.3;
            ro.AttachToDocument();



            var info = new IHTMLSpan {
                innerText = "MatrixTransform"
            };


            info.style.SetLocation(x, y + h, w, h);

            info.AttachToDocument();

            var at = new IHTMLDiv();

            at.style.background = "yellow";
            at.style.SetLocation(x - w / 2, y - h / 2, w * 2, h * 2);
            at.style.Opacity = 0.5;
            at.AttachToDocument();



            var r = new IHTMLDiv();

            r.style.background = "black";
            r.style.SetLocation(x, y, w, h);
            r.style.Opacity = 0.3;

            r.AttachToDocument();
            r.style.cursor = IStyle.CursorEnum.pointer;

            #region blue origin
            var o = new IHTMLDiv();

            o.style.background = "blue";
            o.style.SetLocation(x + w / 2 - 4, y + h / 2 - 1, 8, 2);

            o.AttachToDocument();

            var oh = new IHTMLDiv();

            oh.style.background = "blue";
            oh.style.SetLocation(x + w / 2 - 1, y + h / 2 - 4, 2, 8);

            oh.AttachToDocument();
            #endregion



            #region black rotation
            var jzo = new IHTMLDiv();

            jzo.style.background = "black";
            jzo.style.SetLocation(x - w / 2 - 4, y - h / 2 - 1, 8, 2);

            jzo.AttachToDocument();

            var jzoh = new IHTMLDiv();

            jzoh.style.background = "black";
            jzoh.style.SetLocation(x - w / 2 - 1, y - h / 2 - 4, 2, 8);

            jzoh.AttachToDocument();


            jzo.BlinkAt(400);
            jzoh.BlinkAt(400);
            #endregion


            var m = new MatrixModifiers();

            var InteractiveSetOrigin_x = 0;
            var InteractiveSetOrigin_y = 0;

            var InteractiveSetRotation_x = 0;
            var InteractiveSetRotation_y = 0;


            Action <int, int> InteractiveSetRotation = null;

            Action <int, int> SetPadding =
                (ox, oy) =>
            {
                // -0 ... -w

                ox += w / 2;
                oy += h / 2;

                info.innerText = "padding x: " + ox + " y:" + oy;

                if (ox > 0)
                {
                    ro_matrix.style.paddingLeft  = ox * 2 + "px";
                    ro_matrix.style.paddingRight = 0 + "px";
                }
                else
                {
                    ro_matrix.style.paddingLeft  = 0 + "px";
                    ro_matrix.style.paddingRight = ox * -2 + "px";
                }

                if (oy > 0)
                {
                    ro_matrix.style.paddingTop    = oy * 2 + "px";
                    ro_matrix.style.paddingBottom = 0 + "px";
                }
                else
                {
                    ro_matrix.style.paddingTop    = 0 + "px";
                    ro_matrix.style.paddingBottom = oy * -2 + "px";
                }



                if (ox > 0)
                {
                    r_matrix.style.paddingLeft  = ox * 2 + "px";
                    r_matrix.style.paddingRight = 0 + "px";
                }
                else
                {
                    r_matrix.style.paddingLeft  = 0 + "px";
                    r_matrix.style.paddingRight = ox * -2 + "px";
                }

                if (oy > 0)
                {
                    r_matrix.style.paddingTop    = oy * 2 + "px";
                    r_matrix.style.paddingBottom = 0 + "px";
                }
                else
                {
                    r_matrix.style.paddingTop    = 0 + "px";
                    r_matrix.style.paddingBottom = oy * -2 + "px";
                }
            };

            m.Visual1.CheckedChanged +=
                delegate
            {
                r_matrix.Show(m.Visual1.Checked);
            };

            m.Visual2.CheckedChanged +=
                delegate
            {
                ro_matrix.Show(m.Visual2.Checked);
            };

            m.Debug1.CheckedChanged +=
                delegate
            {
                if (m.Debug1.Checked)
                {
                    ro_matrix.style.backgroundColor = "#8080ff";
                    r_matrix.style.backgroundColor  = "#80ff80";

                    return;
                }

                ro_matrix.style.backgroundColor = "";
                r_matrix.style.backgroundColor  = "";
            };

            Action <int, int> InteractiveSetOrigin =
                (ox, oy) =>
            {
                var dx = InteractiveSetOrigin_x - ox;
                var dy = InteractiveSetOrigin_y - oy;

                InteractiveSetOrigin_x = ox;
                InteractiveSetOrigin_y = oy;

                SetPadding(ox, oy);

                m.TranslateX.Text = "" + ox;
                m.TranslateY.Text = "" + oy;

                ro.style.SetLocation(x + ox, y + oy, w, h);
                ro_matrix.style.SetLocation(x + ox, y + oy /*, w, h*/);
                o.style.SetLocation(x - ox - 4, y - oy - 1, 8, 2);
                oh.style.SetLocation(x - ox - 1, y - oy - 4, 2, 8);

                InteractiveSetRotation(InteractiveSetRotation_x + dx, InteractiveSetRotation_y + dy);
            };

            InteractiveSetRotation =
                (ox, oy) =>
            {
                InteractiveSetRotation_x = ox;
                InteractiveSetRotation_y = oy;

                var ax = x - w / 2 + ox;
                var ay = y - h / 2 + oy;

                var bx = x - InteractiveSetOrigin_x;
                var by = y - InteractiveSetOrigin_y;

                var dx = ax - bx;
                var dy = ay - by;

                var rotation         = Extensions.GetRotation(dx, dy);
                var rotation_degrees = rotation.RadiansToDegrees();

                var costheta = Math.Cos(rotation);
                var sintheta = Math.Sin(rotation);

                var M11 = costheta;
                var M12 = -sintheta;
                var M21 = sintheta;
                var M22 = costheta;

                m.M11.Text = "" + M11;
                m.M12.Text = "" + M12;
                m.M21.Text = "" + M21;
                m.M22.Text = "" + M22;

                info.innerText = "rotation: " + rotation_degrees + "° x: " + InteractiveSetOrigin_x + " y:" + InteractiveSetOrigin_y;
                //Native.Document.title = new { ax, bx, dx, rotation_degrees }.ToString();

                joh.style.SetLocation(ax - 1, y - h / 2 + oy - 4, 2, 8);
                jo.style.SetLocation(x - w / 2 + ox - 4, ay - 1, 8, 2);

                jzoh.style.SetLocation(x + InteractiveSetOrigin_x - w / 2 + ox - 1, y + InteractiveSetOrigin_y - h / 2 + oy - 4, 2, 8);
                jzo.style.SetLocation(x + InteractiveSetOrigin_x - w / 2 + ox - 4, y + InteractiveSetOrigin_y - h / 2 + oy - 1, 8, 2);

                var mm = new[]
                {
                    M11, M21,
                    M12, M22,

                    0, 0
                    //0.838670551776886,0.5446390509605408,-0.5446390509605408,0.838670551776886,0,0
                };

                var code = @"
			q.style.filter = ""progid:DXImageTransform.Microsoft.Matrix(M11='"" + m[0] + ""',M12='"" + m[2] + ""',M21='"" + m[1] + ""', M22='"" + m[3] + ""', sizingmethod='auto expand');"";
	
			q.style.MozTransform = ""matrix("" + m[0] + "","" + m[1] + "","" + m[2] + "","" + m[3] + "","" + m[4] + "","" + m[5] + "")"";
			
			q.style.WebkitTransform = ""matrix("" + m[0] + "","" + m[1] + "","" + m[2] + "","" + m[3] + "","" + m[4] + "","" + m[5] + "")"";
				"                ;

                new IFunction("q", "m", code).apply(null, r_matrix, mm);
                new IFunction("q", "m", code).apply(null, ro_matrix, mm);


                var r_matrix_adj_x = (r_matrix.clientWidth - r_matrix.offsetWidth) / 2;
                var r_matrix_adj_y = (r_matrix.clientHeight - r_matrix.offsetHeight) / 2;

                var ro_matrix_adj_x = (ro_matrix.clientWidth - ro_matrix.offsetWidth) / 2;
                var ro_matrix_adj_y = (ro_matrix.clientHeight - ro_matrix.offsetHeight) / 2;



                r_matrix.style.SetLocation(x + r_matrix_adj_x, y + r_matrix_adj_y /*, w, h*/);
                ro_matrix.style.SetLocation(x + InteractiveSetOrigin_x + ro_matrix_adj_x, y + InteractiveSetOrigin_y + ro_matrix_adj_y /*, w, h*/);
            };



            #region bind InteractiveSetRotation
            at.onclick +=
                e =>
            {
                InteractiveSetRotation(e.OffsetX, e.OffsetY);
            };

            at.onmousemove +=
                e =>
            {
                InteractiveSetRotation(e.OffsetX, e.OffsetY);
            };

            at.onmouseover +=
                delegate
            {
                info.innerText = "Click to set rotation";
            };

            InteractiveSetRotation(0, 0);
            #endregion

            #region bind InteractiveSetOrigin
            m.ButtonClear.Click +=
                delegate
            {
                InteractiveSetOrigin(0, 0);
            };

            r.onclick +=
                e =>
            {
                // 0 0 is top left

                InteractiveSetOrigin(-e.OffsetX, -e.OffsetY);
            };

            r.onmouseover +=
                delegate
            {
                if (m.Debug1.Checked)
                {
                    info.innerText = "Click to set padding";
                    return;
                }
                info.innerText = "Click to set origin";
            };


            #endregion

            //InteractiveSetOrigin(0, 0);
            InteractiveSetOrigin(-w / 2, -h / 2);

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

            m.BackColor = System.Drawing.Color.White;

            f.Controls.Add(m);
            f.ClientSize = m.Size;

            f.GetHTMLTarget().AttachToDocument();
        }
        public static IHTMLDiv ConvertToImageReflection(ReflectionSetup rs)
        {
            var Control = new IHTMLDiv();

            Control.style.SetLocation(rs.Position.X, rs.Position.Y, +rs.Size.X, +rs.Size.Y);

            rs.Image.style.SetLocation(0, 0, rs.Size.X, rs.Size.Y);
            rs.Image.AttachTo(Control);

            #region drag

            if (rs.Drag)
            {
                rs.Image.onmousedown += Native.DisabledEventHandler;
                rs.Image.style.cursor = ScriptCoreLib.JavaScript.DOM.IStyle.CursorEnum.move;

                var drag = new DragHelper(rs.Image);

                drag.Enabled   = true;
                drag.Position  = rs.Position;
                drag.DragMove +=
                    delegate
                {
                    Control.style.SetLocation(drag.Position.X, drag.Position.Y);
                };
            }

            #endregion

            #region GetRect
            Func <int, int, int, int, string> GetRect =
                (left, top, width, height) =>
            {
                // rect (top, right, bottom, left)
                var x = string.Format("rect({0}px, {1}px, {2}px, {3}px)", top, width + left, height + top, left);
                return(x);
            };
            #endregion


            #region CopyLineY
            Action <ReflectionFrameInfo> CopyLineY =
                i =>
            {
                var clone = (IHTMLImage)rs.Image.cloneNode(true);

                clone.style.SetLocation(0, i.Offset + i.To, rs.Size.X, i.Size);
                clone.style.clip    = GetRect(0, i.From, rs.Size.X, 1);
                clone.style.Opacity = i.Opacity;
                clone.AttachTo(i.Owner);
            };
            #endregion



            #region y
            var YMax = (rs.Size.Y * rs.ReflectionZoom).ToInt32();

            if (rs.Bottom >= 0)
            {
                var _bottom = new IHTMLDiv();
                _bottom.style.SetLocation(0, rs.Size.Y - 1 + rs.Bottom, rs.Size.X, YMax);
                _bottom.AttachTo(Control);
                _bottom.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int y = 0; y < YMax; y++)
                {
                    CopyLineY(
                        new ReflectionFrameInfo
                    {
                        From    = y,
                        To      = YMax - y * 2,
                        Opacity = y / YMax,
                        Size    = YMax,
                        Offset  = 0,
                        Owner   = _bottom
                    }
                        );
                }
            }

            if (rs.Top >= 0)
            {
                var _top = new IHTMLDiv();
                _top.style.SetLocation(0, -YMax - rs.Top, rs.Size.X, YMax);
                _top.AttachTo(Control);
                _top.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;


                for (int y = 0; y < YMax; y++)
                {
                    CopyLineY(
                        new ReflectionFrameInfo
                    {
                        From    = y,
                        To      = YMax - y * 2,
                        Opacity = (1 - (y / (YMax))),
                        Size    = YMax,
                        Offset  = 0,
                        Owner   = _top
                    }
                        );
                }
            }
            #endregion

            var XMax = (rs.Size.X * rs.ReflectionZoom).ToInt32();



            #region CopyLineX
            Action <ReflectionFrameInfo> CopyLineX =
                i =>
            {
                var clone = (IHTMLImage)rs.Image.cloneNode(true);

                clone.style.SetLocation(i.Offset + i.To, 0, i.Size, rs.Size.Y);
                clone.style.clip    = GetRect(i.From, 0, 1, rs.Size.Y);
                clone.style.Opacity = i.Opacity;


                clone.AttachTo(i.Owner);
            };
            #endregion

            #region x

            if (rs.Right >= 0)
            {
                var _right = new IHTMLDiv();
                _right.style.SetLocation(rs.Size.X - 1 + rs.Right, 0, XMax, rs.Size.Y);
                _right.AttachTo(Control);
                _right.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int x = 0; x < XMax; x++)
                {
                    CopyLineX(
                        new ReflectionFrameInfo
                    {
                        From    = x,
                        To      = XMax - x * 2,
                        Opacity = (x / (XMax)),
                        Size    = XMax,
                        Offset  = 0,
                        Owner   = _right
                    }
                        );
                }
            }

            if (rs.Left >= 0)
            {
                var _left = new IHTMLDiv();
                _left.style.SetLocation(-XMax - rs.Left, 0, XMax, rs.Size.Y);
                _left.AttachTo(Control);
                _left.style.overflow = ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden;

                for (int x = 0; x < XMax; x++)
                {
                    CopyLineX(
                        new ReflectionFrameInfo
                    {
                        From    = x,
                        To      = XMax - x * 2,
                        Opacity = (1 - (x / (XMax))),
                        Size    = XMax,
                        Offset  = 0,
                        Owner   = _left
                    }
                        );
                }
            }
            #endregion

            return(Control);
        }
예제 #17
0
        public HorizontalSplitBase(Arguments args)
        {
            this.Split     = args.Split;
            this.SplitArea = args.SplitArea;

            var hs     = args.Split;
            var hsArea = args.SplitArea;

            var hsa = args.SplitImage;

            this.SplitImageContainer = new IHTMLDiv();
            SplitImageContainer.AttachTo(hs.Splitter);
            SplitImageContainer.style.position  = ScriptCoreLib.JavaScript.DOM.IStyle.PositionEnum.absolute;
            SplitImageContainer.style.left      = "1px";
            SplitImageContainer.style.top       = "50%";
            SplitImageContainer.style.marginTop = (-args.SplitImageHeight / 2) + "px";

            hsa.AttachTo(SplitImageContainer);


            hsArea.Abort.style.Opacity = 0.05;


            var    dragmode       = false;
            Action ReleaseCapture = delegate { };

            hsArea.Target.onmousedown +=
                ee =>
            {
                ReleaseCapture = hsArea.Target.CaptureMouse();

                hsArea.Target.style.backgroundColor = SelectionColor;
                dragmode = true;

                ee.PreventDefault();
                hsArea.Abort.style.Opacity = SelectionBackgroundOpacity;
            };

            hsArea.PageContainer.onmousemove +=
                ee =>
            {
                var OffsetX = ee.GetOffsetX(hsArea.PageContainer);


                if (!dragmode)
                {
                    return;
                }

                var p = System.Convert.ToInt32(OffsetX * 100 / hsArea.PageContainer.offsetWidth);

                if (p < Convert.ToInt32(Minimum * 100))
                {
                    p = Convert.ToInt32(Minimum * 100);
                }
                if (p > Convert.ToInt32(Maximum * 100))
                {
                    p = Convert.ToInt32(Maximum * 100);
                }

                hsArea.Target.style.left = p + "%";
            };

            InternalSetValue =
                p =>
            {
                if (p < Convert.ToInt32(Minimum * 100))
                {
                    p = Convert.ToInt32(Minimum * 100);
                }
                if (p > Convert.ToInt32(Maximum * 100))
                {
                    p = Convert.ToInt32(Maximum * 100);
                }

                hsArea.Target.style.left = p + "%";
                hs.Right.style.left      = p + "%";
                hs.Right.style.width     = (100 - p) + "%";
                hs.Left.style.width      = p + "%";
            };

            hsArea.PageContainer.onmouseup +=
                ee =>
            {
                if (!dragmode)
                {
                    return;
                }

                ReleaseCapture();

                var OffsetX = ee.GetOffsetX(hsArea.PageContainer);

                dragmode = false;
                var p = System.Convert.ToInt32(OffsetX * 100 / hsArea.PageContainer.offsetWidth);

                Value = p * 0.01;

                hsArea.Abort.style.Opacity          = 0;
                hsArea.Target.style.backgroundColor = ScriptCoreLib.JavaScript.Runtime.JSColor.None;
            };

            hsArea.Abort.onmousemove +=
                ee =>
            {
                if (dragmode)
                {
                    return;
                }

                hsArea.Target.style.backgroundColor = ScriptCoreLib.JavaScript.Runtime.JSColor.None;
                hsArea.PageContainer.Orphanize();
            };

            hs.Splitter.onmouseover +=
                delegate
            {
                hsArea.Abort.style.Opacity = 0.05;

                hsArea.PageContainer.AttachTo(hs.ContentContainer);
            };
        }
예제 #18
0
        public __SplitContainer()
        {
            //InternalElement.style.backgroundColor = "red";

            this.Panel1 = new SplitterPanel(this);
            this.Panel2 = new SplitterPanel(this);

            this.Controls.Add(this.Panel1);
            this.Controls.Add(this.Panel2);



            var TheSplitter = new IHTMLDiv {
            };

            TheSplitter.css.hover.style.backgroundColor  = "blue";
            TheSplitter.css.active.style.backgroundColor = "blue";

            TheSplitter.style.cursor = DOM.IStyle.CursorEnum.move;


            TheSplitter.AttachTo(
                InternalElement
                );

            this.SplitterDistance = 200;



            var h = new DragHelper(TheSplitter);

            h.Enabled = true;
            //h.Position.X = this.SplitterDistance;

            h.DragMove +=
                delegate
            {
                //this.SplitterDistance = h.Position.X;

                if (this.InternalOrientation == global::System.Windows.Forms.Orientation.Horizontal)
                {
                    TheSplitter.style.SetLocation(0, h.Position.Y);
                }
                else
                {
                    TheSplitter.style.SetLocation(h.Position.X, 0);
                }
            };

            // X:\jsc.svn\examples\javascript\forms\FormsSplitter\FormsSplitter\ApplicationControl.cs



            TheSplitter.style.position = DOM.IStyle.PositionEnum.absolute;


            Action AtUpdate = delegate
            {
                __Panel p1 = this.Panel1;
                __Panel p2 = this.Panel2;


                if (this.InternalOrientation == global::System.Windows.Forms.Orientation.Horizontal)
                {
                    h.Position.Y = this.SplitterDistance;



                    p1.InternalElement.style.position = DOM.IStyle.PositionEnum.absolute;
                    p1.InternalElement.style.left     = "0px";
                    p1.InternalElement.style.top      = "0px";
                    p1.InternalElement.style.width    = "";
                    p1.InternalElement.style.bottom   = "";
                    p1.InternalElement.style.right    = "0px";
                    p1.InternalElement.style.height   = (this.SplitterDistance - 4) + "px";



                    p2.InternalElement.style.position = DOM.IStyle.PositionEnum.absolute;
                    p2.InternalElement.style.left     = "0px";
                    p2.InternalElement.style.top      = (this.SplitterDistance + 4) + "px";
                    p2.InternalElement.style.width    = "";
                    p2.InternalElement.style.bottom   = "0px";
                    p2.InternalElement.style.right    = "0px";
                    p2.InternalElement.style.height   = "";



                    TheSplitter.style.left   = "0px";
                    TheSplitter.style.top    = (this.SplitterDistance - 4) + "px";
                    TheSplitter.style.right  = "0px";
                    TheSplitter.style.height = "8px";


                    TheSplitter.style.width  = "";
                    TheSplitter.style.bottom = "";
                }
                else
                {
                    h.Position.X = this.SplitterDistance;

                    // dock left?


                    p1.InternalElement.style.position = DOM.IStyle.PositionEnum.absolute;
                    p1.InternalElement.style.left     = "0px";
                    p1.InternalElement.style.top      = "0px";
                    p1.InternalElement.style.width    = (this.SplitterDistance - 4) + "px";
                    p1.InternalElement.style.bottom   = "0px";
                    p1.InternalElement.style.right    = "";
                    p1.InternalElement.style.height   = "";



                    p2.InternalElement.style.position = DOM.IStyle.PositionEnum.absolute;
                    p2.InternalElement.style.left     = (this.SplitterDistance + 4) + "px";
                    p2.InternalElement.style.top      = "0px";
                    p2.InternalElement.style.width    = "";
                    p2.InternalElement.style.bottom   = "0px";
                    p2.InternalElement.style.right    = "0px";
                    p2.InternalElement.style.height   = "";


                    TheSplitter.style.left   = (this.SplitterDistance - 4) + "px";
                    TheSplitter.style.top    = "0px";
                    TheSplitter.style.width  = "8px";
                    TheSplitter.style.bottom = "0px";

                    TheSplitter.style.right  = "";
                    TheSplitter.style.height = "";
                }


                p1.InternalClientSizeChanged0();
                p2.InternalClientSizeChanged0();
            };


            h.DragStop +=
                delegate
            {
                if (this.InternalOrientation == global::System.Windows.Forms.Orientation.Horizontal)
                {
                    this.SplitterDistance = h.Position.Y;
                }
                else
                {
                    this.SplitterDistance = h.Position.X;
                }

                //AtUpdate();
            };



            this.InternalSplitterDistanceChanged +=
                delegate
            {
                AtUpdate();
            };

            this.InternalOrientationChanged +=
                delegate
            {
                Console.WriteLine(
                    "InternalOrientationChanged " + new
                {
                    this.Name,
                    this.Orientation
                }
                    );

                AtUpdate();
            };

            this.SizeChanged +=
                delegate
            {
                //Console.WriteLine("__SplitContainer SizeChanged");


                AtUpdate();
            };


            AtUpdate();
        }
예제 #19
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(IDefault page)
        {
            @"Hello world".ToDocumentTitle();

            var output = new IHTMLTextArea().AttachToDocument();

            var gexf = new XElement("gexf");

            gexf.Add(
                new XElement("meta",
                             new XElement("creator", "jsc"),
                             new XElement("description", "NASDAQSNA")
                             )
                );

            var graph = new XElement("graph",
                                     new XAttribute("mode", "static"),
                                     new XAttribute("defaultedgetype", "directed")
                                     );

            gexf.Add(graph);

            var nodes = new XElement("nodes");

            graph.Add(nodes);

            var edges = new XElement("edges");

            graph.Add(edges);

            output.value    = gexf.ToString();
            output.onfocus +=
                delegate
            {
                output.value = gexf.ToString();
            };
            output.onmouseover +=
                delegate
            {
                output.value = gexf.ToString();
            };

            var NumericNodeIdLookup = new List <string>();

            Func <string, int> GetNumericNodeId =
                k =>
            {
                if (!NumericNodeIdLookup.Contains(k))
                {
                    NumericNodeIdLookup.Add(k);
                }


                return(NumericNodeIdLookup.IndexOf(k));
            };

            #region AddRelatedCompanies
            Func <IHTMLDiv, string, Action, Task> AddRelatedCompanies = null;

            AddRelatedCompanies =
                (c, qid, done) =>
            {
                var nqid = GetNumericNodeId(qid).ToString();
                var cc   = new IHTMLDiv();

                cc.style.marginLeft = "2em";



                var service = new ApplicationWebService
                {
                    qid   = qid,
                    yield = (id, CompanyName, Price) =>
                    {
                        var nid = GetNumericNodeId(id).ToString();

                        if (nodes.Elements().Any(k => k.Attribute("id").Name.LocalName == nid))
                        {
                        }
                        else
                        {
                            nodes.Add(
                                new XElement("node",
                                             new XAttribute("id", nid),
                                             new XAttribute("label", CompanyName)
                                             )
                                );
                        }



                        var btn = new IHTMLButton
                        {
                            innerText = id + " " + CompanyName + " " + Price
                        };

                        btn.style.display = IStyle.DisplayEnum.block;

                        if (qid == id)
                        {
                            btn.disabled = true;

                            if (c == null)
                            {
                                btn.AttachToDocument();
                                cc.AttachToDocument();
                            }
                            else
                            {
                                //btn.AttachTo(c);
                                cc.AttachTo(c);
                            }

                            if (done != null)
                            {
                                done();
                            }
                        }
                        else
                        {
                            edges.Add(
                                new XElement("edge",
                                             new XAttribute("source", nqid),
                                             new XAttribute("target", nid)
                                             )
                                );

                            btn.AttachTo(cc);

                            var ccc = new IHTMLDiv();

                            ccc.AttachTo(cc);

                            int cx = 0;

                            ccc.ToggleVisible();



                            btn.WhenClicked(
                                async delegate
                            {
                                if (cx == 0)
                                {
                                    btn.style.color = JSColor.Red;

                                    await AddRelatedCompanies(ccc, id,
                                                              delegate
                                    {
                                        btn.style.color = JSColor.Blue;
                                    }
                                                              );
                                }


                                cx++;

                                ccc.ToggleVisible();
                            }
                                );
                        }
                    }
                };



                return(service.GetRelatedCompanies());
            };
            #endregion

            AddRelatedCompanies(null, "NASDAQ:FB", null);
            AddRelatedCompanies(null, "NASDAQ:GOOG", null);
        }
예제 #20
0
        void InitializeCanvasSelection()
        {
            var u = this.Layers.User;

            var selection = new IHTMLDiv();

            selection.style.border = "1px solid #ffffff";
            //selection.style.overflow = IStyle.OverflowEnum.hidden;


            var selection_start = Point.Zero;
            var selection_end   = Point.Zero;
            var selection_rect  = new Rectangle();

            #region UpdateSelection
            System.Action UpdateSelection =
                delegate
            {
                var size = selection_end - selection_start;

                if (size.X < 0)
                {
                    selection_rect.Left  = selection_start.X + size.X;
                    selection_rect.Width = -size.X;
                }
                else
                {
                    selection_rect.Left  = selection_start.X;
                    selection_rect.Width = size.X;
                }

                if (size.Y < 0)
                {
                    selection_rect.Top    = selection_start.Y + size.Y;
                    selection_rect.Height = -size.Y;
                }
                else
                {
                    selection_rect.Top    = selection_start.Y;
                    selection_rect.Height = size.Y;
                }


                if (ShowSelectionRectangle)
                {
                    if (IsSelectionMinimumSize(selection_rect))
                    {
                        selection.style.display = IStyle.DisplayEnum.none;
                    }
                    else
                    {
                        selection.style.display = IStyle.DisplayEnum.block;
                        selection.style.SetLocation(selection_rect);
                    }
                }

                if (SelectionPreview != null)
                {
                    SelectionPreview(selection_rect);
                }

                if (SelectionPointsPreview != null)
                {
                    SelectionPointsPreview(selection_start, selection_end);
                }
            };
            #endregion

            Action ReleaseCapture = null;



            var aa = default(Point);
            var bb = default(Point);

            var disablemouse = false;

            #region ontouchmove
            u.ontouchstart +=
                e =>
            {
                disablemouse = true;

                // one finger to pan around
                if (e.touches.length == 2)
                {
                    //Console.WriteLine("ontouchstart");
                    e.preventDefault();
                    selection.style.border = "1px solid white";

                    _InSelectionMode = true;

                    if (ShowSelectionRectangle)
                    {
                        selection.AttachTo(this.Layers.CanvasInfo);
                    }

                    //this.Layers.CanvasInfo.appendChild(selection);

                    aa = new Point(
                        // selection_start
                        Math.Min(
                            e.touches[0].screenX,
                            e.touches[1].screenX
                            ),
                        Math.Min(
                            e.touches[0].screenY,
                            e.touches[1].screenY
                            )
                        );

                    bb = new Point(
                        // selection_start
                        Math.Max(
                            e.touches[0].screenX,
                            e.touches[1].screenX
                            ),
                        Math.Max(
                            e.touches[0].screenY,
                            e.touches[1].screenY
                            )
                        );
                }
            };

            u.ontouchmove +=
                e =>
            {
                if (e.touches.length == 2)
                {
                    if (_InSelectionMode)
                    {
                        selection.style.border = "1px solid green";
                        //Console.WriteLine("ontouchmove");

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

                        var a = new Point(
                            // selection_start
                            Math.Min(
                                e.touches[0].screenX,
                                Math.Min(e.touches[1].screenX, aa.X)
                                ),
                            Math.Min(
                                e.touches[0].screenY,
                                Math.Min(e.touches[1].screenY, aa.Y)
                                )
                            );

                        var b = new Point(
                            // selection_start
                            Math.Max(
                                e.touches[0].screenX,
                                Math.Max(e.touches[1].screenX, aa.X)
                                ),
                            Math.Max(
                                e.touches[0].screenY,
                                Math.Max(e.touches[1].screenY, bb.Y)
                                )
                            );


                        selection_start = a - this.CurrentCanvasPosition;
                        selection_end   = b - this.CurrentCanvasPosition;


                        UpdateSelection();
                    }
                }
            };

            u.ontouchend +=
                e =>
            {
                if (_InSelectionMode)
                {
                    _InSelectionMode = false;

                    selection.style.border = "1px solid yellow";
                    //Console.WriteLine("ontouchend");

                    Native.window.requestAnimationFrame +=
                        delegate
                    {
                        // !!! workaround for webview.
                        selection.style.SetLocation(0, 0, 0, 0);
                        //selection.Orphanize();

                        Console.WriteLine("ontouchend done?");
                    };



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


            #endregion



            #region mouse
            u.onmousedown +=
                e =>
            {
                if (disablemouse)
                {
                    return;
                }

                if (e.MouseButton == IEvent.MouseButtonEnum.Left)
                {
                    _InSelectionMode = true;

                    if (ShowSelectionRectangle)
                    {
                        this.Layers.CanvasInfo.appendChild(selection);
                    }

                    selection_start = e.OffsetPosition - this.CurrentCanvasPosition;
                    selection_end   = selection_start;

                    UpdateSelection();

                    Console.WriteLine("CaptureMouse");
                    e.preventDefault();
                    e.stopPropagation();
                    ReleaseCapture = u.CaptureMouse();
                }
            };



            u.onmousemove +=
                delegate(IEvent e)
            {
                if (disablemouse)
                {
                    return;
                }


                if (_InSelectionMode)
                {
                    selection_end = e.OffsetPosition - this.CurrentCanvasPosition;

                    e.preventDefault();
                    e.stopPropagation();
                    UpdateSelection();
                }
            };

            u.onmouseup +=
                delegate(IEvent e)
            {
                if (disablemouse)
                {
                    return;
                }


                if (_InSelectionMode)
                {
                    if (e.MouseButton == IEvent.MouseButtonEnum.Left)
                    {
                        _InSelectionMode = false;
                        e.preventDefault();
                        e.stopPropagation();

                        if (IsSelectionMinimumSize(selection_rect))
                        {
                            var p = new Point(selection_end.X, selection_end.Y);

                            if (SelectionClick != null)
                            {
                                SelectionClick(p, e);
                            }
                        }
                        else
                        {
                            var r = new Rectangle
                            {
                                Left   = selection_rect.Left,
                                Top    = selection_rect.Top,
                                Width  = selection_rect.Width,
                                Height = selection_rect.Height,
                            };

                            if (ApplySelection != null)
                            {
                                ApplySelection(r, e);
                            }

                            if (ApplyPointsSelection != null)
                            {
                                ApplyPointsSelection(selection_start, selection_end, e);
                            }
                        }

                        if (ShowSelectionRectangle)
                        {
                            this.Layers.CanvasInfo.removeChild(selection);
                        }

                        if (ReleaseCapture != null)
                        {
                            Console.WriteLine("ReleaseCapture");
                            ReleaseCapture();
                            ReleaseCapture = null;
                        }
                    }
                }
            };
            #endregion


            //u.onmouseout +=
            //    delegate
            //    {
            //        if (_InSelectionMode)
            //        {
            //            _InSelectionMode = false;

            //            if (ShowSelectionRectangle)
            //                this.Layers.CanvasInfo.removeChild(selection);

            //            if (ReleaseCapture != null)
            //            {
            //                Console.WriteLine("ReleaseCapture");
            //                ReleaseCapture();
            //                ReleaseCapture = null;
            //            }
            //        }
            //    };
        }
예제 #21
0
        public SectionConcept(T Target, IHTMLImage TreeExpand, IHTMLImage TreeCollapse)
        {
            this.Target = Target;

            Content = new IHTMLDiv
            {
                Target.Content.childNodes
            };

            Header = new IHTMLSpan
            {
                Target.Header.childNodes
            };

            var Icon = new IHTMLSpan
            {
                TreeExpand,
                TreeCollapse
            };

            Icon.style.marginRight = "1em";

            Icon.AttachTo(Target.Header);
            Header.AttachTo(Target.Header);

            Content.AttachTo(Target.Content);

            Target.Header.style.cursor = ScriptCoreLib.JavaScript.DOM.IStyle.CursorEnum.pointer;



            TreeExpand.Hide();



            Action onclick = delegate { };

            Target.Header.onclick +=
                delegate
            {
                onclick();
            };


            this.NextClickHide =
                delegate
            {
                InternalIsExpanded = false;

                Target.Content.Hide();
                TreeExpand.Show();
                TreeCollapse.Hide();

                onclick = NextClickShow;
            };

            this.NextClickShow =
                delegate
            {
                InternalIsExpanded = true;

                Target.Content.Show();
                TreeExpand.Hide();
                TreeCollapse.Show();

                onclick = NextClickHide;
            };


            onclick = NextClickHide;
        }
예제 #22
0
        private static void CreateRotor(double _angle, IHTMLElement _container)
        {
            var shadow = new IHTMLDiv();

            shadow.style.position        = IStyle.PositionEnum.absolute;
            shadow.style.left            = "0px";
            shadow.style.top             = "0px";
            shadow.style.width           = "600px";
            shadow.style.height          = "400px";
            shadow.style.backgroundColor = "black";
            shadow.style.Opacity         = 0.3;
            shadow.AttachTo(_container);

            var borders = new IHTMLDiv();

            borders.style.position = IStyle.PositionEnum.absolute;
            borders.style.left     = "0px";
            borders.style.top      = "0px";
            //borders.style.width = "400px";
            //borders.style.height = "300px";
            borders.style.border  = "4px solid black";
            borders.style.Opacity = 0.1;
            borders.AttachTo(_container);

            var a = new IHTMLDiv();

            // we can specify rotation origin within red area!

            a.style.backgroundColor = "red";

            a.style.marginTop   = "-200px";
            a.style.marginLeft  = "-300px";
            a.style.paddingLeft = "300px";
            a.style.paddingTop  = "200px";

            var c = new IHTMLDiv();

            var z = new IHTMLButton("hi");


            z.AttachTo(c);
            c.AttachTo(a);

            //a.style.width = "300px";
            //a.style.height = "200px";

            c.style.width  = "300px";
            c.style.height = "200px";
            //c.style.position = IStyle.PositionEnum.relative;
            //c.style.SetLocation(0, 0);
            //c.style.clip = "rect(0px,60px,200px,0px)";

            c.appendChild("hello world");
            c.appendChild(new IHTMLButton("click me"));

            var xx = new IHTMLButton("xx");

            xx.style.SetLocation(32, 32);

            c.appendChild(xx);
            c.appendChild("hello world");

            new IHTMLDiv
            {
                innerText =
                    @"As it seems we can use apng files but 
we cannot have absolute children. This means we will be able to support
non container objects."
            }.AttachTo(c);


            c.style.SetBackground("assets/MatrixTransformExample/bg.png", true);

            var t = new IHTMLDiv();

            c.appendChild(t);

            //a.style.width = "400px";
            //a.style.height = "300px";



            var angle = _angle;

            ApplyRotation2(a, angle, 1, 200, 0);

            new Timer(
                delegate
            {
                t.innerHTML = "" + angle;
                angle      -= 2;
                ApplyRotation2(a, angle, 1, 200, 0);

                borders.style.SetSize(a.offsetWidth, a.offsetHeight);

                borders.style.SetLocation((a.clientWidth - a.offsetWidth) / 2, (a.clientHeight - a.offsetHeight) / 2);
                a.style.SetLocation((a.clientWidth - a.offsetWidth) / 2, (a.clientHeight - a.offsetHeight) / 2);
            }
                , 0, 250
                );


            a.AttachTo(_container);
        }
예제 #23
0
        public void __Application(IApplicationLoader app)
        {
            //app.LoadingAnimation.FadeOut();

            var DefaultTitle = "jsc solutions";


            Native.Document.title = DefaultTitle;

            StringActionAction GetTitleFromServer = new UltraWebService().GetTitleFromServer;



            GetTitleFromServer(
                n => Native.Document.title = n
                );

            var MyPagesBackground = new IHTMLDiv
            {
            };

            MyPagesBackground.style.overflow = IStyle.OverflowEnum.hidden;
            MyPagesBackground.style.position = IStyle.PositionEnum.absolute;
            MyPagesBackground.style.width    = "100%";
            MyPagesBackground.style.height   = "100%";
            MyPagesBackground.AttachToDocument();

            var MyPages = new IHTMLDiv
            {
            };

            MyPages.style.overflow = IStyle.OverflowEnum.auto;
            MyPages.style.position = IStyle.PositionEnum.absolute;
            MyPages.style.width    = "100%";
            MyPages.style.height   = "100%";
            MyPages.AttachToDocument();

            var MyPagesInternal = new IHTMLDiv();

            MyPagesInternal.style.margin = "4em";
            MyPagesInternal.AttachTo(MyPages);

            // http://www.google.com/support/forum/p/Google+Analytics/thread?tid=486a963e463df665&hl=en
            var gapathname = Native.Document.location.pathname;
            var gasearch   = Native.Document.location.search;
            var gahash     = Native.Window.escape(Native.Document.location.hash);
            var gapageview = gapathname + gasearch + gahash;

            var hash = Native.Document.location.hash;

            Action <string> Analytics = delegate { };

            #region logo
            {
                var IsStudio = Native.Document.location.hash.StartsWith("#/studio");

                if (Native.Document.location.host.StartsWith("studio."))
                {
                    IsStudio = true;
                }

                if (IsStudio)
                {
                    new StudioView(AddSaveButton).Content.AttachToDocument();
                }
                else if (Native.Document.location.hash.StartsWith("#/docs"))
                {
                    var view = new DocumentationCompilationViewer();

                    view.TouchTypeSelected +=
                        type =>
                    {
                        Native.Document.location.hash = "#/docs/" + type.FullName;

                        Analytics("#/docs/" + type.FullName);
                    };
                }
                else if (Native.Document.location.hash.StartsWith("#/warehouse"))
                {
                    new UltraWebService().ThreeDWarehouse(
                        y =>
                    {
                        Func <string, IHTMLAnchor> Build =
                            mid =>
                        {
                            var a = new IHTMLAnchor {
                                href = "http://sketchup.google.com/3dwarehouse/details?ct=hppm&mid=" + mid
                            }.AttachTo(MyPagesInternal);
                            var img = new IHTMLImage {
                                src = "http://sketchup.google.com/3dwarehouse/download?rtyp=st&ctyp=other&mid=" + mid
                            }.AttachTo(a);

                            return(a);
                        };

                        var imgs = Enumerable.ToArray(
                            from k in y.Elements()
                            select Build(k.Value)

                            );
                    }
                        );
                }

                else if (Native.Document.location.hash == "#/source")
                {
                    var sln = new TreeNode(() => new VistaTreeNodePage());

                    sln.Text       = "Solution";
                    sln.IsExpanded = true;

                    Action <TreeNode> AddReferences =
                        p =>
                    {
                        var r = p.Add("References", new References());

                        r.Add("System", new Assembly());
                        r.Add("System.Core", new Assembly());
                        r.Add("ScriptCoreLib", new Assembly());
                        r.Add("ScriptCoreLib.Ultra", new Assembly());
                        r.Add("ScriptCoreLib.Ultra.Library", new Assembly());
                        r.Add("ScriptCoreLib.Ultra.Controls", new Assembly());
                        r.Add("ScriptCoreLibJava", new Assembly());
                        r.Add("jsc.meta", new Assembly());
                    };

                    Action <TreeNode> AddUltraSource =
                        p =>
                    {
                        var my = p.Add("My.UltraSource");
                        my.Add("Default.htm", new HTMLDocument());
                        my.Add("jsc.png", new ImageFile());
                    };

                    {
                        var p = sln.Add("Visual C# Project", new VisualCSharpProject());


                        AddReferences(p);
                        AddUltraSource(p);



                        p.Add("Application.cs", new VisualCSharpCode());
                        p.Add("WebService.cs", new VisualCSharpCode());
                        p.Add("Program.cs", new VisualCSharpCode());
                    }

                    {
                        var p = sln.Add("Visual Basic Project", new VisualBasicProject());

                        AddReferences(p);
                        AddUltraSource(p);

                        p.Add("Application.vb", new VisualBasicCode());
                        p.Add("WebService.vb", new VisualBasicCode());
                        p.Add("Program.vb", new VisualBasicCode());
                    }


                    {
                        var p = sln.Add("Visual F# Project", new VisualFSharpProject());

                        AddReferences(p);
                        AddUltraSource(p);


                        p.Add("Application.fs", new VisualFSharpCode());
                        p.Add("WebService.fs", new VisualFSharpCode());
                        p.Add("Program.fs", new VisualFSharpCode());
                    }

                    sln.Container.style.Float = IStyle.FloatEnum.right;
                    sln.Container.AttachTo(MyPagesInternal);

                    new SourceEditorHeader().Container.AttachTo(MyPagesInternal);

                    //new IHTMLElement(IHTMLElement.HTMLElementEnum.h1, "Create your own Ultra Application project template").AttachTo(MyPagesInternal);

                    var n = new TextEditor(MyPagesInternal);

                    n.Width  = 600;
                    n.Height = 400;

                    //n.InnerHTML = "<p>Create your own <b>Ultra Application</b> Project Template</p>";


                    new DefaultPage1().Container.AttachTo(n.Document.body);

                    var m1 = new SimpleCodeView();

                    m1.Container.AttachTo(MyPagesInternal);
                    //m1.SelectType.onchange +=
                    //    delegate
                    //    {
                    //        m1.TypeName.innerText = m1.SelectType.value;
                    //    };

                    //m1.RunJavaScript.onclick +=
                    //    delegate
                    //    {
                    //        m1.RunJavaScript.style.color = JSColor.Blue;

                    //        try
                    //        {
                    //            Native.Window.eval(m1.Code1.value);

                    //            1000.AtDelay(
                    //                delegate
                    //                {
                    //                    m1.RunJavaScript.style.color = JSColor.None;
                    //                }
                    //            );
                    //        }
                    //        catch
                    //        {
                    //            m1.RunJavaScript.style.color = JSColor.Red;

                    //            1000.AtDelay(
                    //                delegate
                    //                {
                    //                    m1.RunJavaScript.style.color = JSColor.None;
                    //                }
                    //            );
                    //        }
                    //    };
                    new Compilation().GetArchives().SelectMany(k => k.GetAssemblies()).First(k => k.Name == "ScriptCoreLib").WhenReady(
                        ScriptCoreLib =>
                    {
                        // we do not have reflection in place for native wrappers :/

                        m1.SelectEvent.Clear();

                        var Element = ScriptCoreLib.GetTypes().Single(k => k.FullName == "ScriptCoreLib.JavaScript.DOM.HTML.IHTMLElement");
                        //var Element = ScriptCoreLib.GetTypes().Single(k => k.HTMLElement == "ScriptCoreLib.JavaScript.DOM.HTML.IHTMLElement");

                        Action <CompilationEvent> Add =
                            SourceEvent =>
                        {
                            m1.SelectEvent.Add(
                                new IHTMLOption {
                                innerText = SourceEvent.Name
                            }
                                );
                        };

                        Element.GetEvents().ForEach(Add);
                    }
                        );


                    m1.SelectEvent.onchange +=
                        delegate
                    {
                        m1.EventName.innerText = m1.SelectEvent.value;
                    };
                }
                else if (Native.Document.location.hash == "#/UltraApplicationWithAssets")
                {
                    new UltraApplicationWithAssets().Container.AttachToDocument();
                }
                else
                if (Native.Document.location.hash == "#/audio")
                {
                    Action AtTimer = delegate { };

                    (1000 / 15).AtInterval(
                        tt =>
                    {
                        AtTimer();
                    }
                        );

                    new SoundCloudBackground().Container.AttachTo(MyPagesBackground);
                    new SoundCloudHeader().Container.AttachTo(MyPagesInternal);

                    var page = 1;

                    var Tracks = new IHTMLDiv().AttachTo(MyPagesInternal);
                    Tracks.style.margin = "1em";

                    var More = new SoundCloudMore();

                    var AudioLinks = default(AudioLink);

                    var LoadCurrentPage = default(Action);

                    LoadCurrentPage = delegate
                    {
                        var loading = new SoundCloudLoading();

                        loading.Container.AttachTo(Tracks);


                        new UltraWebService().SoundCloudTracksDownload(
                            System.Convert.ToString(page),
                            ee =>
                        {
                            if (loading != null)
                            {
                                loading.Container.Orphanize();
                                loading = null;
                            }

                            var t = new SoundCloudTrack();

                            t.Content.ApplyToggleConcept(t.HideContent, t.ShowContent).Hide();

                            t.Title.innerHTML = ee.trackName;
                            t.Waveform.src    = ee.waveformUrl;

                            t.Audio.src        = ee.streamUrl;
                            t.Audio.autobuffer = true;


                            AudioLinks = new AudioLink
                            {
                                Audio = t.Audio,
                                Prev  = AudioLinks
                            };

                            var _AudioLinks = AudioLinks;

                            if (AudioLinks.Prev != null)
                            {
                                AudioLinks.Prev.Next = AudioLinks;
                            }
                            else
                            {
                                // we are the first  :)
                                t.Audio.play();
                            }

                            t.MoreButton.onclick +=
                                delegate
                            {
                                t.Audio.pause();

                                if (_AudioLinks.Next != null)
                                {
                                    _AudioLinks.Next.Audio.currentTime = 0;
                                    _AudioLinks.Next.Audio.play();

                                    if (_AudioLinks.Next.Next == null)
                                    {
                                        page++;
                                        LoadCurrentPage();
                                    }
                                }
                            };

                            t.Audio.onended +=
                                delegate
                            {
                                if (_AudioLinks.Next != null)
                                {
                                    _AudioLinks.Next.Audio.currentTime = 0;
                                    _AudioLinks.Next.Audio.play();

                                    if (_AudioLinks.Next.Next == null)
                                    {
                                        page++;
                                        LoadCurrentPage();
                                    }
                                }
                            };

                            t.Identity.innerText = ee.uid;

                            t.Play.onclick  += eee => { eee.PreventDefault(); t.Audio.play(); };
                            t.Pause.onclick += eee => { eee.PreventDefault(); t.Audio.pause(); };

                            t.Title.style.cursor = IStyle.CursorEnum.pointer;
                            t.Title.onclick     += eee =>
                            {
                                eee.PreventDefault();

                                var playing = true;

                                if (t.Audio.paused)
                                {
                                    playing = false;
                                }

                                if (t.Audio.ended)
                                {
                                    playing = false;
                                }

                                if (!playing)
                                {
                                    t.Audio.play();
                                }
                                else
                                {
                                    t.Audio.pause();
                                }
                            };

                            DoubleAction SetProgress1 = p =>
                            {
                                t.Gradient3.style.width = System.Convert.ToInt32(800 * p) + "px";
                                t.Gradient4.style.width = System.Convert.ToInt32(800 * p) + "px";
                            };

                            t.Gradient5.style.Opacity = 0.4;
                            t.Gradient6.style.Opacity = 0.4;

                            DoubleAction SetProgress2 = p =>
                            {
                                t.Gradient5.style.width = System.Convert.ToInt32(800 * p) + "px";
                                t.Gradient6.style.width = System.Convert.ToInt32(800 * p) + "px";
                            };

                            AtTimer +=
                                delegate
                            {
                                if (t.Audio.duration == 0)
                                {
                                    t.Play.Hide();
                                    t.Pause.Hide();
                                    return;
                                }
                                else
                                {
                                    var playing = true;

                                    if (t.Audio.paused)
                                    {
                                        playing = false;
                                    }

                                    if (t.Audio.ended)
                                    {
                                        playing = false;
                                    }

                                    if (!playing)
                                    {
                                        t.Title.style.color = Color.None;
                                    }
                                    else
                                    {
                                        t.Title.style.color = Color.Blue;
                                    }

                                    t.Play.Show(!playing);
                                    t.Pause.Show(playing);
                                }

                                var p = t.Audio.currentTime / t.Audio.duration;
                                SetProgress1(p);
                            };

                            t.Waveform.onmouseout +=
                                delegate
                            {
                                SetProgress2(0);
                            };

                            t.Waveform.onmousemove +=
                                eee =>
                            {
                                SetProgress2(eee.OffsetX / 800.0);
                            };

                            t.Waveform.onclick +=
                                eee =>
                            {
                                t.Audio.currentTime = t.Audio.duration * (eee.OffsetX / 800.0);
                                t.Audio.play();
                            };

                            t.Waveform.style.cursor = IStyle.CursorEnum.pointer;

                            SetProgress1(0);
                            SetProgress2(0);

                            t.Container.AttachTo(Tracks);
                        }
                            );


                        10000.AtDelay(
                            delegate
                        {
                            More.MoreButton.FadeIn(0, 1000, null);
                        }
                            );
                    };


                    More.MoreButton.Hide();
                    More.Container.AttachTo(MyPagesInternal);

                    More.MoreButton.onclick += eee =>
                    {
                        eee.PreventDefault();
                        More.MoreButton.FadeOut(1, 300,
                                                delegate
                        {
                            page++;
                            LoadCurrentPage();
                        }
                                                );
                    };

                    LoadCurrentPage();
                }
                else
                {
                    //new PromotionWebApplication1.HTML.Audio.FromAssets.Track1 { controls = true }.AttachToDocument();
                    //new PromotionWebApplication1.HTML.Audio.FromWeb.Track1 { controls = true, autobuffer = true }.AttachToDocument();

                    var IsAvalonJavaScript   = hash == "#/avalon.js";
                    var IsAvalonActionScript = hash == "#/avalon.as";
                    var IsAvalon             = IsAvalonActionScript || IsAvalonJavaScript;

                    //if (IsAvalon)
                    //{

                    //{
                    //    var ccc = new IHTMLDiv();

                    //    ccc.style.position = IStyle.PositionEnum.absolute;
                    //    ccc.style.left = "15%";
                    //    ccc.style.right = "15%";
                    //    ccc.style.top = "15%";


                    //    var Now = DateTime.Now;

                    //    var CountDown = new CountDownGadgetConcept(CountDownGadget.Create)
                    //    {
                    //        ShowOnlyDays = true,
                    //        Event = new DateTime(2010, 5, 24, 23, 59, 50),

                    //    };

                    //    CountDown.Element.GadgetContainer.style.color = "#808080";
                    //    CountDown.Element.GadgetContainer.style.textShadow = "#E0E0E0 1px 1px 1px";


                    //    CountDown.Element.GadgetContainer.AttachTo(ccc);
                    //    CountDown.Element.GadgetContainer.FadeIn(3000, 2000, null);

                    //    ccc.AttachToDocument();
                    //}

                    {
                        var ccc = new IHTMLDiv();

                        ccc.style.position   = IStyle.PositionEnum.absolute;
                        ccc.style.left       = "50%";
                        ccc.style.top        = "50%";
                        ccc.style.marginLeft = (-JSCSolutionsNETCarouselCanvas.DefaultWidth / 2) + "px";
                        ccc.style.marginTop  = (-JSCSolutionsNETCarouselCanvas.DefaultHeight / 2) + "px";

                        ccc.style.SetSize(JSCSolutionsNETCarouselCanvas.DefaultWidth, JSCSolutionsNETCarouselCanvas.DefaultHeight);

                        ccc.AttachToDocument();

                        if (IsAvalonActionScript)
                        {
                            var alof = new UltraSprite();
                            alof.ToTransparentSprite();
                            alof.AttachSpriteTo(ccc);
                        }
                        else
                        {
                            var alo = new JSCSolutionsNETCarouselCanvas();
                            alo.Container.AttachToContainer(ccc);

                            alo.AtLogoClick +=
                                delegate
                            {
                                //Native.Window.open("http://sourceforge.net/projects/jsc/", "_blank");
                                Native.Window.open("/download", "_blank");
                            };
                        }
                    }
                    //}
                    //else
                    //{
                    //    var cc = new HTML.Pages.FromAssets.Controls.Named.CenteredLogo_Kamma();

                    //    cc.Container.AttachToDocument();

                    //    // see: http://en.wikipedia.org/wiki/Perl_control_structures
                    //    // "Unless" == "if not"  ;)

                    //    IsMicrosoftInternetExplorer.YetIfNotThen(cc.TheLogoImage.BeginPulseAnimation).ButIfSoThen(cc.TheLogoImage.HideNowButShowAtDelay);
                    //}

                    var aa = new About();
                    aa.Service.innerText = gapageview;
                    aa.Container.AttachToDocument();
                }
            }
            #endregion


            Analytics =
                __hash =>
            {
                var __gahash     = Native.Window.escape(__hash);
                var __gapageview = gapathname + gasearch + __gahash;


                "UA-13087448-1".ToGoogleAnalyticsTracker(
                    pageTracker =>
                {
                    pageTracker._setDomainName(".jsc-solutions.net");
                    pageTracker._trackPageview(__gapageview);
                }
                    );
            };

            Analytics(Native.Document.location.hash);
        }