Example #1
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();
        }
Example #2
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();
        }