Esempio n. 1
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);
        }
        /// <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)
        {
  

            var n = new MyEditor();

            n.Container.AttachToDocument();

            //var a = new IHTMLAnchor(
            //    "http://sketchup.google.com/3dwarehouse/search?q=stargate",
            //    "Open 3dwarehouse in another window"
            //);
            //a.style.fontSize = "large-xx";
            //a.AttachToDocument();



            //ii.setAttribute("src", "http://sketchup.google.com/3dwarehouse/");


            IHTMLDiv Control = new IHTMLDiv();

            n.Edit1.parentNode.replaceChild(Control, n.Edit1);

            //n.Logo.src = "assets/TextEditorDemo2/Preview.png";

            //Control.AttachToDocument();


            var text = new TextEditor(Control);


            text.InnerHTML = "Drag images to this frame!<hr />";

            // IE error

            text.Height = 200;
            text.Width = 400;
            //text.InnerHTML = n.Edit1.value;

            text.IsFadeEnabled = false;

            //var i = new IHTMLImage(21, 20) { src = "assets/TextEditorDemo2/cal.png" };

            var CurrentList = new List<InternalExtensions.GoogleThreeDWarehouseImage>();

            n.ToLarge.onclick += e =>
            {
                CurrentList.ForEach(k => k.AnimationZoom = 4);
            };

            n.ToMedium.onclick += e =>
            {
                CurrentList.ForEach(k => k.AnimationZoom = 1);
            };
            n.ToSmall.onclick += e =>
            {
                CurrentList.ForEach(k => k.AnimationZoom = 0.5);
            };

            Action<string[], IHTMLButton> ToPreview =
                (data, button) =>
                {
                    var ii = new IHTMLImage(40, 30) { src = data[0] };
                    ii.style.verticalAlign = "middle";

                    var sp = new IHTMLSpan();
                    sp.style.marginLeft = "1em";
                    sp.AttachTo(button);

                    ii.AttachTo(button).ToGoogleThreeDWarehouseImage().Animate();

                };
            n.Nasa.onclick +=
                delegate
                {
                    text.InnerHTML = NasaSource.Text;

                };


            //n.Houses.onclick +=
            //    delegate
            //    {
            //        text.InnerHTML = Pages.Houses.Static.HTML;

            //    };

            n.CnC.onclick +=
                delegate
                {
                    text.InnerHTML = CnCSource.Text;

                };

            n.Ships.onclick +=
            delegate
            {
                text.InnerHTML = ShipsSource.Text;
            };

            //ToPreview(Ships..Images, n.Ships);
            //ToPreview(CnC.Static.Images, n.CnC);
            ////ToPreview(Houses.Static.Images, n.Houses);
            //ToPreview(Nasa.Static.Images, n.Nasa);


            //i.AttachToDocument();
            n.OK.onclick +=
                delegate
                {
                    n.ContainerForImages.removeChildren();
                    CurrentList.Clear();
                    //text.Document.getElementsByTagName("img").ToGoogleThreeDWarehouseImages().Animate();

                    var clones = text.Document.GetClonedImages();
                    foreach (IHTMLImage iii in clones)
                    {


                        var w = iii.AttachTo(n.ContainerForImages).ToGoogleThreeDWarehouseImage();

                        w.Animate();

                        CurrentList.Add(w);
                    }

                };
            //);

            //OK.Control.style.paddingLeft = "1em";
            //text.BottomToolbarContainer.appendChild(OK.Control);

            text.TopToolbarContainer.Hide();
            text.BottomToolbarContainer.Hide();
        }
Esempio n. 3
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);

        }
        // 20140526 roslyn friendly!
        // and broken again

        //        script: error JSC1000:
        //error:
        //  statement cannot be a load instruction(or is it a bug?)
        //  [0x000a]
        //        ldarg.0    +1 -0

        // assembly: V:\Abstractatech.JavaScript.Avatar.Application.exe
        // type: Abstractatech.JavaScript.Avatar.ApplicationImplementation+<MakeCamGrabber>d__1+<MoveNext>0600002d, Abstractatech.JavaScript.Avatar.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
        // offset: 0x000a
        //  method:Int32<06ad> call.try(<MoveNext>0600002d, <MakeCamGrabber>d__1 ByRef, System.Runtime.CompilerServices.TaskAwaiter`1[ScriptCoreLib.JavaScript.DOM.HTML.IHTMLImage] ByRef, System.Runtime.CompilerServic

        public static async void MakeCamGrabber(
            IHTMLDiv c,
            bool sizeToWindow = false,
            Action<WebCamAvatarsSheet1Row> yield = null
            )
        {
            if (sizeToWindow)
            {
                #region onresize
                Native.window.With(
                    async window =>
                    {
                        while (true)
                        {
                            c.style.transformOrigin = "0% 0%";

                            var scale =

                                Native.window.Height / (double)(480 + 96);

                            if (Native.window.Height > Native.window.Width)
                                scale = Native.window.Width / (double)(640);


                            c.style.transform = "scale("
                                + scale
                                + ")";

                            var w = (int)(scale * (640));
                            var h = (int)(scale * (480 + 96));


                            c.style.width = w + "px";
                            c.style.height = h + "px";

                            c.style.SetLocation(
                                (Native.window.Width - w) / 2,
                                (Native.window.Height - h) / 2
                            );

                            await window.async.onresize;
                        }
                    }
                );
                #endregion

            }

            c.style.backgroundColor = "black";

            #region localStorageKeys

            // or webSQL?
            var localStorageKeys = new
            {

                img640x480 = new { img = "avatar", w = 640, h = 480 },
                img96gif = new { img = "avatar", w = 96, h = 96 },

                frames = new[] {
                            new { index= 0, img = "avatar", w = 96, h = 96 },
                            new { index= 1, img = "avatar", w = 96, h = 96 },
                            new { index= 2, img = "avatar", w = 96, h = 96 },
                            new { index= 3, img = "avatar", w = 96, h = 96 },
                        }
            };
            #endregion



            //c.css.children
            c.css.children.style.SetLocation(0, 0);

            c.style.position = IStyle.PositionEnum.relative;
            c.style.width = (640) + "px";
            c.style.height = (480 + 96) + "px";






            c.css.hover.style.cursor = IStyle.CursorEnum.pointer;

            #region empty
            var css = c.css.empty.before;

            css.style.textAlign = IStyle.TextAlignEnum.center;
            css.style.display = IStyle.DisplayEnum.block;
            css.style.width = (640) + "px";
            css.style.color = "white";
            css.style.paddingTop = 300 + "px";


            c.css.hover.empty.before.style.color = "yellow";
            #endregion




            var retry = 0;
            retry:
            retry++;

            Console.WriteLine(new { retry });


            css.contentText = "either drag a picture here -or- click here to use your webcam";

            var snapshot = new CanvasRenderingContext2D(640, 480);

            var frames = new List<IHTMLImage>();

            c.css[IHTMLElement.HTMLElementEnum.img][0].style.SetLocation(96 * 0, 480);
            c.css[IHTMLElement.HTMLElementEnum.img][1].style.SetLocation(96 * 1, 480);
            c.css[IHTMLElement.HTMLElementEnum.img][2].style.SetLocation(96 * 2, 480);
            c.css[IHTMLElement.HTMLElementEnum.img][3].style.SetLocation(96 * 3, 480);
            c.css[IHTMLElement.HTMLElementEnum.img][4].style.SetLocation(96 * 4, 480);
            c.css[IHTMLElement.HTMLElementEnum.img][5].style.SetLocation(96 * 5, 480);

            var size = 400;

            #region newmask
            Action newmask = delegate
            {
                #region grid
                new IHTMLDiv
                {

                }.AttachTo(c).With(
                    async grid =>
                    {
                        grid.style.SetLocation(
                            (640 - size) / 2,
                            (480 - size) / 2,

                            size - 2,
                            size - 2
                        );

                        var s = Stopwatch.StartNew();

                        // X:\jsc.svn\examples\javascript\LINQ\LINQWebCamAvatars\LINQWebCamAvatars\Application.cs
                        // until orphanized
                        while (c.parentNode != null)
                        {
                            //await Native.window.requestAnimationFrameAsync;
                            await Native.window.async.onframe;

                            var a = (Math.Cos(s.ElapsedMilliseconds * 0.001) + 1) / 2.0;

                            grid.style.border = "1px dotted rgba(255,255,255, "
                                + (1.0 - a)
                                + ")";

                            //mask_css.style.Opacity = a;

                        }
                    }
                );
                #endregion

                #region mask
                var mask = new CanvasRenderingContext2D(640, 480 + 96);

                mask.canvas.style.zIndex = 100;

                //mask.drawImage(
                //    v, 0, 0,

                //    mask.canvas.width,
                //    mask.canvas.height
                //);

                mask.fillStyle = "rgba(0,0,0, 0.8)";
                mask.fillRect(
                       0, 0,

                       640,
                       480 + 96
                   );


                mask.clearRect(
                      (640 - size) / 2,
                        (480 - size) / 2,

                        size,
                        size
                );



                //var bytes = i.bytes;

                mask.canvas.AttachTo(c);
                #endregion


            };
            #endregion


            #region localStorage
            var base64 = Native.window.localStorage[localStorageKeys.img640x480];
            if (base64 != null)
            {
                var base64image = new IHTMLImage { src = base64 };

                await base64image;

                snapshot.drawImage(base64image, 0, 0, 640, 480);
                snapshot.canvas.AttachTo(c);


                for (int i = 0; i < 5; i++)
                {
                    var base64f = Native.window.localStorage[localStorageKeys.frames[
                        localStorageKeys.frames.Length - i - 1]];

                    if (base64f != null)
                    {
                        var newframe = new IHTMLImage { src = base64f };
                        newframe.AttachTo(c);
                        frames.Add(newframe);
                    }
                }



                newmask();

                var base64gif = Native.window.localStorage[localStorageKeys.img96gif];

                #region atgif
                Action<string> atgif =
                    gif =>
                    {
                        //Native.document.title = new { gif.Length }.ToString();

                        var newframe = new IHTMLImage { src = gif };

                        newframe.style.zIndex = 300;

                        newframe.AttachTo(c);
                        frames.Add(newframe);

                        //if (frames.Count > 5)
                        //    frames.Remove(frames[0].Orphanize());
                    };
                #endregion


                if (base64gif != null)
                    atgif(base64gif);
                else
                {
                    var bytes = frames.Select(x => x.bytes.Result).ToArray().AsEnumerable();

                    //bytes = bytes.Concat(bytes.Skip(1).Reverse().Skip(1)).ToArray().AsEnumerable();

                    // build it
                    new GIFEncoderWorker(
                         96,
                         96,
                             delay: 1000 / 10,
                         frames: bytes,
                         AtFrame:
                          async index =>
                          {
                              //Native.document.title = new { index }.ToString();
                          }


                     ).Task.ContinueWithResult(
                        gif =>
                        {
                            Native.window.localStorage[localStorageKeys.img96gif] = gif;


                            // report sizes. smaller is better if db
                            Console.WriteLine(
                                // { Avatar640x480 = 54843, Avatar96gif = 54734 } 
                                new
                                {
                                    Avatar640x480 = base64.Length,
                                    Avatar96gif = gif.Length
                                }
                            );


                            if (yield != null)
                                yield(
                                    new WebCamAvatarsSheet1Row
                                    {
                                        Avatar640x480 = base64,
                                        Avatar96frame1 = Native.window.localStorage[localStorageKeys.frames[0]],
                                        // do we want to report frames?
                                        Avatar96gif = gif
                                    }
                                );


                            atgif(gif);
                        }
                        );
                }

            }
            #endregion

            Console.WriteLine("await c.async.onclick");
            await c.async.onclick;
            Console.WriteLine("await c.async.onclick done");

            c.Clear();

            css.content = "awaiting for video";




            var v = await Native.window.navigator.async.onvideo;


            v.AttachTo(c);
            v.play();


            var mask_css = c.css[IHTMLElement.HTMLElementEnum.canvas];



            newmask();

            var z96 = new CanvasRenderingContext2D(96, 96);

            z96.canvas.AttachTo(c);
            //z96.canvas.style.backgroundColor = "gray";
            z96.canvas.style.SetLocation(96 * 5, 480);

            z96.canvas.style.zIndex = 300;


            var ok = c.async.onclick;

            #region frames



            while (!ok.IsCompleted)
            {

                z96.drawImage(
                    image: v,
                    sx: (640 - size) / 2,
                    sy: (480 - size) / 2,

                    sw: size,
                    sh: size,
                    dx: 0,
                    dy: 0,
                    dw: 96,
                    dh: 96
                );

                var newframe = new IHTMLImage { src = z96.canvas.toDataURL() };
                newframe.AttachTo(c);
                frames.Add(newframe);

                if (frames.Count > 5)
                    frames.Remove(frames[0].Orphanize());


                await (1000 / 15);
            }
            #endregion

            snapshot.drawImage(v, 0, 0, 640, 480);

            #region localStorage

            // https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement
            //Native.window.localStorage[localStorageKeys.img640x480] = 

            var firstTry = snapshot.canvas.toDataURL(

            // shall we use enum
            type: "image/jpeg"
            );
            if (firstTry.Length >= (1024 * 64))
            {
                Console.WriteLine("Reducing quality");
                firstTry = snapshot.canvas.toDataURL(

            // shall we use enum
            type: "image/jpeg",
            quality: 0.5
            );
            }

            // can we use SQL instead now?
            Native.window.localStorage[localStorageKeys.img640x480] = firstTry;



            frames.WithEachIndex(
                (k, index) =>
                {
                    Native.window.localStorage[localStorageKeys.frames[index]] = k.src;
                }
            );

            Native.window.localStorage.removeItem(localStorageKeys.img96gif);
            #endregion


            v.src = "";
            c.Clear();



            goto retry;
        }
Esempio n. 5
0
        // change: C:\util\xampplite\apache\conf\httpd.conf

        // http://localhost/jsc/FlashBrowserDocument/FlashBrowserDocument.htm

        /*
         * Alias /jsc/FlashBrowserDocument "C:\work\jsc.svn\examples\actionscript\FlashBrowserDocument\FlashBrowserDocument\bin\Release\web"
         * <Directory "C:\work\jsc.svn\examples\actionscript\FlashBrowserDocument\FlashBrowserDocument\bin\Release\web">
         *     Options Indexes FollowSymLinks ExecCGI
         *     AllowOverride All
         *     Order allow,deny
         *     Allow from all
         * </Directory>
         */

        /// <summary>
        /// Default constructor
        /// </summary>
        public FlashBrowserDocument()
        {
            ConsoleFormPackageExperience.Initialize();

            Console.WriteLine("ConsoleFormPackageExperience");

            var t = new TextField
            {
                defaultTextFormat = new TextFormat {
                    font = "Courier"
                },
                backgroundColor = 0x303030,
                textColor       = 0xffff00,
                text            = "powered by jsc",
                background      = true,
                x = 0,
                y = 0,
                alwaysShowSelection = true,
                width  = DefaultWidth,
                height = DefaultHeight
            }.AttachTo(this);

            // you should be running within the browser
            //SecurityError: Error #2060: Security sandbox violation: ExternalInterface caller file:///C:/work/jsc.svn/examples/actionscript/FlashBrowserDocument/FlashBrowserDocument/bin/Release/web/FlashBrowserDocument.swf cannot access file:///C:/work/jsc.svn/examples/actionscript/FlashBrowserDocument/FlashBrowserDocument/bin/Release/web/FlashBrowserDocument.htm.
            //    at flash.external::ExternalInterface$/_initJS()
            //    at flash.external::ExternalInterface$/addCallback()
            //    at Extensions::ExternalExtensions$/External_100668292()
            //    at DOM::ExternalContext()
            //    at DOM::ExternalContext$/ExternalAuthentication_100663321()
            //    at FlashBrowserDocument.ActionScript::FlashBrowserDocument()

            t.text = "before ExternalAuthentication";
            try
            {
                Console.WriteLine("before ExternalAuthentication");
                ExternalContext.ExternalAuthentication(
                    context =>
                {
                    Console.WriteLine("at ExternalAuthentication");
                    t.text = "after ExternalAuthentication";

                    context.Document.body.style.backgroundColor = "#afafff";
                    context.Document.body.style.color           = "#000080";

                    t.appendText("\nflash element was found within html document");

                    context.Document.title = "hello world";

                    #region hide/show flash element
                    var HideFlashButtonCounter = 0;
                    var HideFlashButton        = new IHTMLButton {
                        innerHTML = "hide flash element"
                    };

                    HideFlashButton.AttachTo(context);
                    HideFlashButton.onclick +=
                        delegate
                    {
                        if (HideFlashButtonCounter % 2 == 0)
                        {
                            t.appendText("\nflash element hidden");
                            context.Element.width     = 0;
                            context.Element.height    = 0;
                            HideFlashButton.innerHTML = "show flash element";
                        }
                        else
                        {
                            t.appendText("\nflash element shown");
                            context.Element.width     = DefaultWidth;
                            context.Element.height    = DefaultHeight;
                            HideFlashButton.innerHTML = "hide flash element";
                        }

                        HideFlashButtonCounter++;
                    };
                    #endregion

                    var Content = @"
					<hr />
					<blockqoute>
						<h1>This application was written in c# and was compiled to actionscript with <a href='http://jsc.sf.net'>jsc compiler</a>.</h1>
						<h2>Currently supported browsers:</h2>
						<ul>
							<li><img src='http://www.w3schools.com/images/compatible_firefox.gif' />Firefox</li>
							<li><img src='http://www.w3schools.com/images/compatible_chrome.gif' />Google Chrome</li>
							<li><img src='http://www.w3schools.com/images/compatible_safari.gif' />Safari</li>
							<li><img src='http://www.w3schools.com/images/compatible_opera.gif' />Opera</li>
						</ul>
					</blockqoute>
					"                    .AttachAsDiv(context);

                    var DynamicChild = new IHTMLSpan {
                        innerHTML = "hello world"
                    }.AttachTo(Content);

                    DynamicChild.style.color = "red";
                    DynamicChild.innerHTML   = "click on the image to remove it!";

                    var DynamicChildImage = new IHTMLImage
                    {
                        title = "jsc diagram",
                        src   = "http://jsc.sourceforge.net/jsc.png"
                    }.AttachTo(DynamicChild);

                    DynamicChildImage.style.backgroundColor = "white";

                    DynamicChildImage.onclick +=
                        delegate
                    {
                        Console.WriteLine("at DynamicChildImage onclick");

                        DynamicChild.removeChild(DynamicChildImage);
                        DynamicChild.innerHTML = "you have removed that image!";

                        var Undo = new IHTMLButton {
                            innerHTML = "undo"
                        }.AttachTo(DynamicChild);

                        Undo.onclick +=
                            delegate
                        {
                            DynamicChildImage.AttachTo(DynamicChild);
                            DynamicChild.removeChild(Undo);
                        };
                    };

                    DynamicChild.onclick +=
                        delegate
                    {
                        Console.WriteLine("at DynamicChild onclick");
                    };
                }
                    );
            }
            catch (Exception ex)
            {
                t.text = "error " + new { ex };
            }
        }
Esempio n. 6
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)
        {
            var n = new MyEditor();

            n.Container.AttachToDocument();

            //var a = new IHTMLAnchor(
            //    "http://sketchup.google.com/3dwarehouse/search?q=stargate",
            //    "Open 3dwarehouse in another window"
            //);
            //a.style.fontSize = "large-xx";
            //a.AttachToDocument();



            //ii.setAttribute("src", "http://sketchup.google.com/3dwarehouse/");


            IHTMLDiv Control = new IHTMLDiv();

            n.Edit1.parentNode.replaceChild(Control, n.Edit1);

            //n.Logo.src = "assets/TextEditorDemo2/Preview.png";

            //Control.AttachToDocument();


            var text = new TextEditor(Control);


            text.InnerHTML = "Drag images to this frame!<hr />";

            // IE error

            text.Height = 200;
            text.Width  = 400;
            //text.InnerHTML = n.Edit1.value;

            text.IsFadeEnabled = false;

            //var i = new IHTMLImage(21, 20) { src = "assets/TextEditorDemo2/cal.png" };

            var CurrentList = new List <InternalExtensions.GoogleThreeDWarehouseImage>();

            n.ToLarge.onclick += e =>
            {
                CurrentList.ForEach(k => k.AnimationZoom = 4);
            };

            n.ToMedium.onclick += e =>
            {
                CurrentList.ForEach(k => k.AnimationZoom = 1);
            };
            n.ToSmall.onclick += e =>
            {
                CurrentList.ForEach(k => k.AnimationZoom = 0.5);
            };

            Action <string[], IHTMLButton> ToPreview =
                (data, button) =>
            {
                var ii = new IHTMLImage(40, 30)
                {
                    src = data[0]
                };
                ii.style.verticalAlign = "middle";

                var sp = new IHTMLSpan();
                sp.style.marginLeft = "1em";
                sp.AttachTo(button);

                ii.AttachTo(button).ToGoogleThreeDWarehouseImage().Animate();
            };

            n.Nasa.onclick +=
                delegate
            {
                text.InnerHTML = NasaSource.Text;
            };


            //n.Houses.onclick +=
            //    delegate
            //    {
            //        text.InnerHTML = Pages.Houses.Static.HTML;

            //    };

            n.CnC.onclick +=
                delegate
            {
                text.InnerHTML = CnCSource.Text;
            };

            n.Ships.onclick +=
                delegate
            {
                text.InnerHTML = ShipsSource.Text;
            };

            //ToPreview(Ships..Images, n.Ships);
            //ToPreview(CnC.Static.Images, n.CnC);
            ////ToPreview(Houses.Static.Images, n.Houses);
            //ToPreview(Nasa.Static.Images, n.Nasa);


            //i.AttachToDocument();
            n.OK.onclick +=
                delegate
            {
                n.ContainerForImages.removeChildren();
                CurrentList.Clear();
                //text.Document.getElementsByTagName("img").ToGoogleThreeDWarehouseImages().Animate();

                var clones = text.Document.GetClonedImages();
                foreach (IHTMLImage iii in clones)
                {
                    var w = iii.AttachTo(n.ContainerForImages).ToGoogleThreeDWarehouseImage();

                    w.Animate();

                    CurrentList.Add(w);
                }
            };
            //);

            //OK.Control.style.paddingLeft = "1em";
            //text.BottomToolbarContainer.appendChild(OK.Control);

            text.TopToolbarContainer.Hide();
            text.BottomToolbarContainer.Hide();
        }
Esempio n. 7
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();
            // Send data from JavaScript to the server tier
            service.WebMethod2(
                @"A string from JavaScript.",
                value => value.ToDocumentTitle()
                );


            string[] Links =
            {
                "http://www.aminocom.com/products/ipstb/aminet110.html",
                "http://www.vario.tv/espace-clients/aide/variotv_AmiNET110_UserGuide_Book2.pdf"
            };



            var img = new HTML.Images.FromAssets.Amino_remote();
            //var img_bg = new IHTMLImage(Assets.Path + "/Amino-remote-bg.png");

            var reddot_array = Extensions.ToArray(0, 1, 3, 6);

            var reddot = new[]
            {
                new { index = 0, image = (IHTMLImage) new HTML.Images.FromAssets.reddot_0() },
                new { index = 1, image = (IHTMLImage) new HTML.Images.FromAssets.reddot_1() },
                new { index = 3, image = (IHTMLImage) new HTML.Images.FromAssets.reddot_3() },
                new { index = 6, image = (IHTMLImage) new HTML.Images.FromAssets.reddot_6() }
            };


            100.AtInterval(
                t1 =>
            {
                if (reddot.Any(i => !i.image.complete))
                {
                    return;
                }

                //if (!img_bg.complete)
                //    return;

                t1.Stop();


                //Native.Document.body.style.background = "url(" + img_bg.src + ") repeat-x";

                img.InvokeOnComplete(
                    delegate
                {
                    var div = new IHTMLDiv();

                    div.style.SetLocation(0, 0, img.width, img.height);
                    div.style.SetBackground(img.src, false);
                    div.AttachToDocument();

                    Action <Point> SpawnDot =
                        pos =>
                    {
                        var c = reddot.Last();
                        var x = new IHTMLImage(c.image.src);            // c.image.cloneNode();

                        x.AttachTo(div);
                        x.SetCenteredLocation(pos);

                        (1000 / 16).AtInterval(
                            t =>
                        {
                            c = reddot.Previous(y => y.index == c.index);

                            x.src = c.image.src;
                        },
                            () => c.index == reddot.First().index,
                            () => 400.AtTimeout(
                                t2 =>
                        {
                            x.Orphanize();
                        }
                                )

                            );
                    };

                    div.onclick +=
                        ev =>
                    {
                        var pos = ev.CursorPosition;

                        Console.WriteLine(pos);

                        SpawnDot(pos);
                    };

                    div.ontouchmove +=
                        ev =>
                    {
                        ev.preventDefault();


                        for (uint i = 0; i < ev.touches.length; i++)
                        {
                            var pos = new Point(ev.touches[i].clientX, ev.touches[i].clientY);

                            SpawnDot(pos);
                        }
                    };


                    var map = new[]
                    {
                        new { KeyCode = 13, Point = new Point(173, 331) },       // enter
                        new { KeyCode = 13, Point = new Point(206, 216) },       // enter

                        new { KeyCode = 38, Point = new Point(173, 304) },       // up
                        new { KeyCode = 37, Point = new Point(148, 327) },       // left
                        new { KeyCode = 39, Point = new Point(201, 331) },       // right
                        new { KeyCode = 40, Point = new Point(174, 357) },       // down

                        new { KeyCode = 33, Point = new Point(164, 431) },       // page up
                        new { KeyCode = 34, Point = new Point(187, 435) },       // page down

                        new { KeyCode = 48, Point = new Point(172, 207) },       // 0


                        new { KeyCode = 49, Point = new Point(141, 121) },       // 1
                        new { KeyCode = 50, Point = new Point(171, 120) },       // 2
                        new { KeyCode = 51, Point = new Point(206, 131) },
                        new { KeyCode = 52, Point = new Point(143, 152) },
                        new { KeyCode = 53, Point = new Point(175, 149) },
                        new { KeyCode = 54, Point = new Point(207, 158) },
                        new { KeyCode = 55, Point = new Point(141, 178) },
                        new { KeyCode = 56, Point = new Point(174, 177) },      // 8
                        new { KeyCode = 57, Point = new Point(209, 185) },      // 9

                        new { KeyCode = 8, Point = new Point(140, 204) },       // backspace


                        new { KeyCode = 8492, Point = new Point(209, 252) },        // prog up
                        new { KeyCode = 8494, Point = new Point(205, 290) },        // prog down

                        new { KeyCode = 8512, Point = new Point(147, 380) },        // red
                        new { KeyCode = 8513, Point = new Point(167, 386) },        // green
                        new { KeyCode = 8514, Point = new Point(184, 389) },        // yellow
                        new { KeyCode = 8515, Point = new Point(206, 385) },        // blue

                        new { KeyCode = 8516, Point = new Point(175, 267) },        // menu

                        new { KeyCode = 8502, Point = new Point(144, 403) },        // rewind
                        new { KeyCode = 8499, Point = new Point(164, 406) },        // play
                        new { KeyCode = 8504, Point = new Point(188, 414) },        // pause
                        new { KeyCode = 8500, Point = new Point(208, 413) },        // pause
                    };

                    ActionParam <int, int> AddKeyCodes =
                        (_old, _new) =>
                    {
                        var _2 = map.Where(i => i.KeyCode == _old).First();

                        map = map.Concat(_new.Select(KeyCode => new { KeyCode, _2.Point })).ToArray();
                    };

                    Action <int, string> AddKeyCodesString =
                        (_old, _new) =>
                    {
                        var _U = _new.ToUpper();
                        var _L = _new.ToLower();


                        for (int i = 0; i < _U.Length; i++)
                        {
                            Console.WriteLine(_old + " -> " + _U[i] + " , " + _L[i]);

                            AddKeyCodes(_old, _U[i], _L[i]);
                        }
                    };

                    var alpha = new Dictionary <char, string>
                    {
                        { '2', "abc" },
                        { '3', "def" },
                        { '4', "ghi" },
                        { '5', "jkl" },
                        { '6', "mno" },
                        { '7', "pqrs" },
                        { '8', "tuv" },
                        { '9', "wxyz" },
                    };

                    alpha.ForEach(i => AddKeyCodesString(i.Key, i.Value));


                    Native.document.onkeyup +=
                        ev =>
                    {
                        ev.preventDefault();

                        var z = map.Where(i => i.KeyCode == ev.KeyCode).ToArray();

                        if (z.Length > 0)
                        {
                            z.ForEach(i => SpawnDot(i.Point));
                        }

                        Console.WriteLine(new { ev.KeyCode });
                    };

                    map.ForEach(
                        (i, next) =>
                    {
                        SpawnDot(i.Point);

                        25.AtTimeout(
                            delegate
                        {
                            next();
                        }
                            );
                    }
                        );
                }
                    );
            }
                );
        }
        /// <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)
        {
            WebCamAvatarsSheet1Row lastPicture = null;

            new IStyle(page.ImgContainer.css + IHTMLElement.HTMLElementEnum.img)
            {
                transition = "left linear 2000ms",
                position = IStyle.PositionEnum.absolute,
                Opacity = 1
            };

            //new IStyle(Native.css[typeof(IHTMLImage)].hover)
            //{
            //    width = "100px",
            //};

           

            Action getNewPicture = async delegate
            {
                while (true)
                {
                    var pic = await this.GetLastUserImage();

                    if (lastPicture != null)
                    {
                        if (pic != null)
                        {
                            Console.WriteLine(pic.Key.ToString());
                            Console.WriteLine(lastPicture.Key.ToString());
                            if (pic.Key == lastPicture.Key)
                            {
                                page.ImgContainer.Clear();
                            }
                            else
                            {
                                IHTMLImage img = new IHTMLImage();
                                img.AttachTo(page.ImgContainer);
                                img.src = pic.Avatar96frame1;
                                img.style.left = "-150px";
                                lastPicture = pic;

                                await 500;

                                Native.window.requestAnimationFrame += delegate
                                {
                                    img.style.left = "50px";

                                };

                                await 10000;

                                Native.window.requestAnimationFrame += delegate
                                {
                                    img.style.left = "-150px";

                                };
                            }
                        }
                        else
                        {
                            page.ImgContainer.Clear();
                        }
                    }
                    else
                    {
                        IHTMLImage img = new IHTMLImage();
                        img.AttachTo(page.ImgContainer);
                        lastPicture = pic;
                        img.src = pic.Avatar96frame1;
                        img.style.left = "-150px";
                        
                        await 500;

                        Native.window.requestAnimationFrame += delegate
                        {
                            img.style.left = "50px";

                        };

                        await 10000;

                        Native.window.requestAnimationFrame += delegate
                        {
                            img.style.left = "-150px";

                        };
                    }
                    await 4000;
                }
            };
            Console.WriteLine("Start");
            //getNewPicture();

           // new IHTMLDiv { }.AttachToDocument().With(x => ApplicationImplementation.MakeCamGrabber(x, sizeToWindow: true));
           // var service = new AvatarNotificationService();
            page.ImgContainer.With(x => ApplicationImplementation.MakeimageNotification(page.ImgContainer, this));

            var button = new IHTMLButton { innerHTML = "SubmitButton" }.AttachToDocument();

            button.onclick += delegate
            {
                var overlay = new IHTMLDiv { }.AttachTo(Native.document.documentElement);
                overlay.style.position = IStyle.PositionEnum.@fixed;
                overlay.style.left = "0";
                overlay.style.top = "0";
                overlay.style.right = "0";
                overlay.style.bottom = "0";
                overlay.style.backgroundColor = "black";

                var div = new IHTMLDiv { }.AttachTo(overlay);

                var xcss = Native.document.body.css.children;

                xcss.style.display = IStyle.DisplayEnum.none;

                Abstractatech.JavaScript.Avatar.ApplicationImplementation.MakeCamGrabber(
                    div,
                    sizeToWindow: true,
                    yield:
                    y =>
                    {
                        overlay.Orphanize();
                        xcss.style.display = IStyle.DisplayEnum.empty;

                        Console.WriteLine("InsertNewPicture");

                        if (y.Avatar640x480.Length >= (1024 * 64))
                        {
                            //MessageBox.Show("Picture size too big for now");
                            return;
                        }

                        this.DiagnosticInsertNewPicture(y);

                        //var z = (__PictureBox)(object)f.pictureBox1;

                        // dow we like gif of jpg?
                        //z.InternalElement.src = y.Avatar96gif;
                        //z.InternalElement.src = y.Avatar96frame1;
                    }
                );
            };
        }
        public static async void MakeimageNotification(IHTMLDiv c, IAvatarNotificationInterface service)
        {
            WebCamAvatarsSheet1Row lastPicture = null;

            //new IStyle(page.ImgContainer.css + IHTMLElement.HTMLElementEnum.img)
            //{
            //    transition = "left linear 2000ms",
            //    position = IStyle.PositionEnum.absolute,
            //    Opacity = 1
            //};

            while (true)
            {
                var pic = await service.GetLastUserImage();

                if (lastPicture != null)
                {
                    if (pic != null)
                    {
                        Console.WriteLine(pic.Key.ToString());
                        Console.WriteLine(lastPicture.Key.ToString());
                        if (pic.Key == lastPicture.Key)
                        {
                            c.Clear();
                        }
                        else
                        {
                            IHTMLImage img = new IHTMLImage();
                            img.AttachTo(c);
                            img.src = pic.Avatar96frame1;
                            img.style.left = "-150px";
                            lastPicture = pic;

                            await 500;

                            Native.window.requestAnimationFrame += delegate
                            {
                                img.style.left = "50px";

                            };

                            await 10000;

                            Native.window.requestAnimationFrame += delegate
                            {
                                img.style.left = "-150px";

                            };
                        }
                    }
                    else
                    {
                        c.Clear();
                    }
                }
                else
                {
                    IHTMLImage img = new IHTMLImage();
                    img.AttachTo(c);
                    lastPicture = pic;
                    img.src = pic.Avatar96frame1;
                    img.style.left = "-150px";

                    await 500;

                    Native.window.requestAnimationFrame += delegate
                    {
                        img.style.left = "50px";

                    };

                    await 10000;

                    Native.window.requestAnimationFrame += delegate
                    {
                        img.style.left = "-150px";

                    };
                }
                await 4000;
            }

        }