예제 #1
0
        internal WinFormsGameWindow(WinFormsGamePlatform platform)
        {
            _platform = platform;
            Game      = platform.Game;

            _form            = new WinFormsGameForm(this);
            _form.ClientSize = new Size(GraphicsDeviceManager.DefaultBackBufferWidth, GraphicsDeviceManager.DefaultBackBufferHeight);

            SetIcon();
            Title = Utilities.AssemblyHelper.GetDefaultWindowTitle();

            _form.MaximizeBox     = false;
            _form.FormBorderStyle = FormBorderStyle.FixedSingle;
            _form.StartPosition   = FormStartPosition.CenterScreen;

            // Capture mouse events.
            _form.MouseWheel += OnMouseScroll;
            _form.MouseEnter += OnMouseEnter;
            _form.MouseLeave += OnMouseLeave;

            // Use RawInput to capture key events.
            Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, DeviceFlags.None);
            Device.KeyboardInput += OnRawKeyEvent;

            _form.Activated         += OnActivated;
            _form.Deactivate        += OnDeactivate;
            _form.ClientSizeChanged += OnClientSizeChanged;

            _form.KeyPress += OnKeyPress;

            RegisterToAllWindows();
        }
예제 #2
0
 void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_form != null)
         {
             UnregisterFromAllWindows();
             _form.Dispose();
             _form = null;
         }
     }
 }
        internal WinFormsGameWindow(WinFormsGamePlatform platform)
        {
            _platform = platform;
            Game      = platform.Game;

            _form = new WinFormsGameForm();

            // When running unit tests this can return null.
            var assembly = Assembly.GetEntryAssembly();

            if (assembly != null)
            {
                _form.Icon = Icon.ExtractAssociatedIcon(assembly.Location);
            }

            _form.MaximizeBox     = false;
            _form.FormBorderStyle = FormBorderStyle.FixedSingle;
            _form.StartPosition   = FormStartPosition.CenterScreen;

            // Capture mouse events.
            _form.MouseDown  += OnMouseState;
            _form.MouseMove  += OnMouseState;
            _form.MouseUp    += OnMouseState;
            _form.MouseWheel += OnMouseState;
            _form.MouseEnter += OnMouseEnter;
            _form.MouseLeave += OnMouseLeave;

            // Use RawInput to capture key events.
            Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, DeviceFlags.None);
            Device.KeyboardInput += OnRawKeyEvent;

            _form.Activated         += OnActivated;
            _form.Deactivate        += OnDeactivate;
            _form.ClientSizeChanged += OnClientSizeChanged;

            _form.KeyPress += OnKeyPress;
        }