Example #1
0
        // Our rectangle has to match that of the containing view, if we want to be able
        // to properly get all the mouse events.
        public KeyboardResponder(
            EnterTextDelegate enterText,
            JustPressedKeyDelegate justPressedKey,
            MonoMacGameView gameView)
            : base(gameView.Window.ContentView.Frame)
        {
            EnterText = enterText;
            JustPressedKey = justPressedKey;
            GameView = gameView;

            // We authorize the parent's view to automatically change our width and height in case
            // of a window resize.
            AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
            // We need to ˝display˝ ourselves if we want to get any mouse events.
            GameView.Window.ContentView.AddSubview(this);
            // Just in case...
            GameView.Window.ContentView.AutoresizesSubviews = true;
            GameView.AutoresizesSubviews = true;

            // For all the events we don't care about, the GameView will get them. There might not
            // be that many though, as we should cover all the bases there, but one never knows.
            NextResponder = GameView;
            // We force ourselves to be the first responder to be called, and we will never resign
            // that duty. That will enable us to get all of the key events, but will also prevent
            // the GameView to get the mouse events. We'll have to forward them.
            GameView.Window.MakeFirstResponder(this);
        }
Example #2
0
 // We need to de-reference the GameView so that the pool can collect it properly.
 protected override void Dispose(bool dispose)
 {
     if (dispose)
         GameView = null;
 }