示例#1
0
        // this works under .NET debugger :)

        public static void ConnectToSession(this ApplicationCanvas that, IEnumerable<ApplicationCanvas> others)
        {
            that.AtNotifyBuildRocket +=
                (x, y) =>
                {
                    others.WithEach(k => k.NotifyBuildRocket(x, y));
                };

            that.AtNotifyVisualizeTouch +=
               (x, y) =>
               {
                   others.WithEach(k => k.NotifyVisualizeTouch(x, y));
               };
        }
示例#2
0
        public ApplicationSprite()
        {
            this.InvokeWhenStageIsReady(
                delegate
            {
                this.stage.align     = StageAlign.TOP_LEFT;
                this.stage.scaleMode = StageScaleMode.NO_SCALE;

                var fullscreen = new ScriptCoreLib.ActionScript.flash.ui.ContextMenuItem("Go fullscreen!");

                fullscreen.menuItemSelect +=
                    delegate
                {
                    this.stage.SetFullscreen(true);
                };

#if FcontextMenu
                this.contextMenu = new ScriptCoreLib.ActionScript.flash.ui.ContextMenu
                {
                    customItems = new[] { fullscreen }
                };
#endif


                var c = new ApplicationCanvas();
                c.AttachToContainer(this);


                this.stage.resize +=
                    e =>
                {
                    c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
                };

                c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
            }
                );
        }
示例#3
0
        public static void Main(string[] args)
        {
            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple).AssemblyQualifiedName
            //);


            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple<,>).AssemblyQualifiedName
            //);

            //Debugger.Break();

#if DEBUG
            var Spawn = default(Action<Action<Window>>);
            var Session = new List<ApplicationCanvas>();

            Spawn = WindowCreated =>
                {
                    var c = new ApplicationCanvas();

                    Session.Add(c);

                    c.ConnectToSession(Session.Except(new[] { c }));

                    

                    var w = c.ToWindow();

                    w.Title += " | F2 - Spawn, F11 - Fullscreen";

                    w.Closing +=
                        delegate
                        {
                            Session.Remove(c);
                        };

                    w.KeyUp +=
                        (s, e) =>
                        {
                            if (e.Key == Key.F2)
                                Spawn(k => k.Show());
                        };

                    w.KeyDown +=
                        (s, e) =>
                        {

                            if (e.Key == Key.Escape || e.Key == Key.F11)
                                if (w.WindowState == WindowState.Maximized)
                                {
                                    w.WindowState = WindowState.Normal;
                                    return;
                                }

                            if (e.Key == Key.F11)
                                if (w.WindowState == WindowState.Normal)
                                {
                                    w.WindowStyle = WindowStyle.None;
                                    w.WindowState = WindowState.Maximized;
                                    return;
                                }
                        };

                    w.StateChanged +=
                        (s, e) =>
                        {
                            w.WindowStyle = w.WindowState == WindowState.Maximized ? WindowStyle.None : WindowStyle.SingleBorderWindow;
                        };


                    w.Loaded +=
                        delegate
                        {
                            w.SizeToContent = SizeToContent.Manual;
                            w.Focus();
                        };

                    w.SizeChanged +=
                        (s, e) =>
                        {
                            if (e.PreviousSize.Width == 0)
                                return;

                            // Content dictates its size. Yet when we resize the window we want the content to know it has more room.
                            // http://stackoverflow.com/questions/1081580/how-to-set-wpf-windows-startup-clientsize
                            var horizontalBorderHeight = SystemParameters.ResizeFrameHorizontalBorderHeight;
                            var verticalBorderWidth = SystemParameters.ResizeFrameVerticalBorderWidth;
                            var captionHeight = SystemParameters.CaptionHeight;

                            var Width = e.NewSize.Width;

                            var Height = e.NewSize.Height;


                            Width -= 2 * verticalBorderWidth;
                            Height -= 2 * horizontalBorderHeight;


                            if (w.WindowStyle != WindowStyle.None)
                            {
                                Height -= captionHeight;
                            }

                            c.SizeTo(Width, Height);

                        };

                    if (WindowCreated != null)
                        WindowCreated(w);
                };

            Spawn(w => w.ShowDialog());
#else

            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
#endif
        }
示例#4
0
        public ApplicationSprite()
        {
            this.InvokeWhenStageIsReady(
                delegate
                {
                    this.stage.align = StageAlign.TOP_LEFT;
                    this.stage.scaleMode = StageScaleMode.NO_SCALE;

                    var fullscreen = new ScriptCoreLib.ActionScript.flash.ui.ContextMenuItem("Go fullscreen!");

                    fullscreen.menuItemSelect +=
                        delegate
                        {
                            this.stage.SetFullscreen(true);
                        };

#if FcontextMenu
                    this.contextMenu = new ScriptCoreLib.ActionScript.flash.ui.ContextMenu
                    {
                        customItems = new[] { fullscreen }
                    };
#endif


                    var c = new ApplicationCanvas();
                    c.AttachToContainer(this);


                    this.stage.resize +=
                        e =>
                        {

                            c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
                        };

                    c.SizeTo(this.stage.stageWidth, this.stage.stageHeight);
                }
            );
        }
示例#5
0
        public static void Main(string[] args)
        {
            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple).AssemblyQualifiedName
            //);


            //System.Diagnostics.Debug.WriteLine(
            //    typeof(Tuple<,>).AssemblyQualifiedName
            //);

            //Debugger.Break();

#if DEBUG
            var Spawn   = default(Action <Action <Window> >);
            var Session = new List <ApplicationCanvas>();

            Spawn = WindowCreated =>
            {
                var c = new ApplicationCanvas();

                Session.Add(c);

                c.ConnectToSession(Session.Except(new[] { c }));



                var w = c.ToWindow();

                w.Title += " | F2 - Spawn, F11 - Fullscreen";

                w.Closing +=
                    delegate
                {
                    Session.Remove(c);
                };

                w.KeyUp +=
                    (s, e) =>
                {
                    if (e.Key == Key.F2)
                    {
                        Spawn(k => k.Show());
                    }
                };

                w.KeyDown +=
                    (s, e) =>
                {
                    if (e.Key == Key.Escape || e.Key == Key.F11)
                    {
                        if (w.WindowState == WindowState.Maximized)
                        {
                            w.WindowState = WindowState.Normal;
                            return;
                        }
                    }

                    if (e.Key == Key.F11)
                    {
                        if (w.WindowState == WindowState.Normal)
                        {
                            w.WindowStyle = WindowStyle.None;
                            w.WindowState = WindowState.Maximized;
                            return;
                        }
                    }
                };

                w.StateChanged +=
                    (s, e) =>
                {
                    w.WindowStyle = w.WindowState == WindowState.Maximized ? WindowStyle.None : WindowStyle.SingleBorderWindow;
                };


                w.Loaded +=
                    delegate
                {
                    w.SizeToContent = SizeToContent.Manual;
                    w.Focus();
                };

                w.SizeChanged +=
                    (s, e) =>
                {
                    if (e.PreviousSize.Width == 0)
                    {
                        return;
                    }

                    // Content dictates its size. Yet when we resize the window we want the content to know it has more room.
                    // http://stackoverflow.com/questions/1081580/how-to-set-wpf-windows-startup-clientsize
                    var horizontalBorderHeight = SystemParameters.ResizeFrameHorizontalBorderHeight;
                    var verticalBorderWidth    = SystemParameters.ResizeFrameVerticalBorderWidth;
                    var captionHeight          = SystemParameters.CaptionHeight;

                    var Width = e.NewSize.Width;

                    var Height = e.NewSize.Height;


                    Width  -= 2 * verticalBorderWidth;
                    Height -= 2 * horizontalBorderHeight;


                    if (w.WindowStyle != WindowStyle.None)
                    {
                        Height -= captionHeight;
                    }

                    c.SizeTo(Width, Height);
                };

                if (WindowCreated != null)
                {
                    WindowCreated(w);
                }
            };

            Spawn(w => w.ShowDialog());
#else
            RewriteToUltraApplication.AsProgram.Launch(typeof(Application));
#endif
        }
 public static void ConnectToSession(this ApplicationCanvas that, ConnectToSessionVariation variation = ConnectToSessionVariation.Other)
 {
 }
        public static void ConnectToSession(this ApplicationCanvas that, ConnectToSessionVariation variation = ConnectToSessionVariation.Flash)
        {
            var nc = new NetConnection();

            var connected = false;

            Action <string> RaiseMessage =
                x =>
            {
                that.About.Text = x + Environment.NewLine + that.About.Text;
            };

            Action <string> PostMessage =
                message =>
            {
                RaiseMessage("drop: " + message);
            };

            #region AtNotifyBuildRocket
            that.AtNotifyBuildRocket +=
                (x, y) =>
            {
                XElement BuildRocket = new DoubleVector2
                {
                    X = x,
                    Y = y
                };

                PostMessage(
                    new XElement("Updates",
                                 new XElement("BuildRocket", BuildRocket)
                                 ).ToString()
                    );
            };
            #endregion


            #region AtNotifyVisualizeTouch
            that.AtNotifyVisualizeTouch +=
                (x, y) =>
            {
                XElement VisualizeTouch = new DoubleVector2
                {
                    X = x,
                    Y = y
                };

                PostMessage(
                    new XElement("Updates",
                                 new XElement("VisualizeTouch", VisualizeTouch)
                                 ).ToString()
                    );
            };
            #endregion


            nc.netStatus +=
                e =>
            {
                // http://stackoverflow.com/questions/10683595/cant-receive-netgroup-events

                RaiseMessage("nc.netStatus: " + e.info.code);


                if (e.info.code == "NetGroup.Connect.Success")
                {
                    connected = true;
                    RaiseMessage("connected");
                    return;
                }

                if (e.info.code == "NetConnection.Connect.Success")
                {
                    // http://kafkaris.com/blog/2011/04/03/local-peer-to-peer-communication-in-as3-with-rtmfp/
                    // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/GroupSpecifier.html

                    var groupspec = new GroupSpecifier("goo");
                    groupspec.postingEnabled = true;
                    groupspec.routingEnabled = true;

                    // // Necessary to multicast over a NetStream.
                    groupspec.multicastEnabled = true;

                    // // Must be enabled for LAN peer discovery to work
                    groupspec.ipMulticastMemberUpdatesEnabled = true;

                    // http://help.adobe.com/en_US/flashmediaserver/ssaslr/WS486834a3d4bc74a45ce7a7ac126f44d8a30-8000.html
                    //groupspec.addIPMulticastAddress("225.225.0.1:30303");


                    // // Multicast address over which to exchange peer discovery.
                    groupspec.addIPMulticastAddress("224.0.0.255:30000");


                    // Specify minimum GroupSpec version (FMS 4.5.2/Flash Player 11.5)
                    groupspec.minGroupspecVersion = 2;

                    var group = new NetGroup(
                        nc,
                        groupspec.groupspecWithAuthorizations()
                        //groupspec.groupspecWithoutAuthorizations()
                        );

                    // http://stackoverflow.com/questions/10206097/netstream-send-not-working-with-netgroup-in-rtmfp

                    PostMessage =
                        message =>
                    {
                        if (connected)
                        {
                            RaiseMessage("write: " + new { message.Length });
                            //RaiseMessage("write: " + message);

                            group.post(message);
                        }
                        else
                        {
                            //RaiseMessage("skip: " + message);
                        }
                    };

                    //AtPostMessage += PostMessage;

                    group.netStatus +=
                        g =>
                    {
                        if (g.info.code == "NetGroup.Posting.Notify")
                        {
                            // Type Coercion failed: cannot convert Object@60b6cb9 to LANMulticast_Components_MySprite1__f__AnonymousType0_1_33554444.

                            var source = (string)g.info.message;

                            RaiseMessage("group.netStatus: " + new { g.info.code, source });


                            //Console.WriteLine("source: " + source);

                            var xml = XElement.Parse(source);

                            xml.Elements().Where(k => k.Name.LocalName == "BuildRocket").Elements().WithEach(
                                ksource =>
                            {
                                //Console.WriteLine("BuildRocket: " + ksource);

                                DoubleVector2 k = ksource;

                                that.NotifyBuildRocket(k.X, k.Y);
                            }
                                );

                            xml.Elements().Where(k => k.Name.LocalName == "VisualizeTouch").Elements().WithEach(
                                ksource =>
                            {
                                //Console.WriteLine("VisualizeTouch: " + ksource);

                                DoubleVector2 k = ksource;

                                that.NotifyVisualizeTouch(k.X, k.Y);
                            }
                                );

                            return;
                        }

                        RaiseMessage("group.netStatus: " + g.info.code);
                    };

                    return;
                }
            };


            // X:\jsc.svn\examples\actionscript\FlashStratusDemo\FlashStratusDemo\ActionScript\OrcasFlashApplication.cs
            nc.connect("rtmfp:");
        }