Exemple #1
0
        public static IDisposable TrackScreenSize(this GameRendering r, Insets insets = new Insets())
        {
            void UpdateBounds()
            {
                var cb = r.Game.Window.ClientBounds;
                var x  = insets.Left;
                var y  = insets.Top;
                var w  = Math.Max(1, cb.Width - insets.Horizontal);
                var h  = Math.Max(1, cb.Height - insets.Vertical);

                r.Bounds = new Rect(x, y, w, h);
            }

            void Handler(object o, EventArgs eventArgs) => UpdateBounds();

            var          changeGuardian = WindowSizeChangeGuardian.Install(r.Game);
            EventHandler handlerRef     = Handler;

            changeGuardian.WindowSizeChanged += handlerRef;

            // finally initialize once
            UpdateBounds();
            return(new ScreenTrackingSubscription(r, handlerRef));
        }
Exemple #2
0
 public ScreenTrackingSubscription(GameRendering gameRendering, EventHandler registeredListener)
 {
     this.gameRendering      = gameRendering ?? throw new ArgumentNullException(nameof(gameRendering));
     this.registeredListener = registeredListener ?? throw new ArgumentNullException(nameof(registeredListener));
 }