Exemplo n.º 1
0
        /// <summary>
        /// Sets up the <see cref="Form"/>.
        /// Call <see cref="ToWindowed"/> or <see cref="ToFullscreen"/> and <see cref="Run"/> afterwards.
        /// </summary>
        /// <param name="name">The name of the application for the title bar</param>
        /// <param name="icon">The icon of the application for the title bar</param>
        /// <param name="background">A background image for the window while loading</param>
        /// <param name="stretch">Stretch <paramref name="background"/> to fit the screen? (<c>false</c> will center it instead)</param>
        protected GameBase(string name, Icon icon = null, Image background = null, bool stretch = false)
        {
            // Setup render-target form
            Form = new GameForm
            {
                Text            = name, Icon = icon,
                BackgroundImage = background, BackgroundImageLayout = stretch ? ImageLayout.Stretch : ImageLayout.Center, BackColor = Color.Black,
                MinimumSize     = new Size(800, 600), Size = new Size(800, 600), MaximizeBox = false
            };

            // Setup event hooks
            Form.Shown   += Form_Shown;
            Form.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                // Ctrl + Shift + Alt + D = Debug console
                if (e.Control && e.Alt && e.Shift && e.KeyCode == Keys.D)
                {
                    Debug();
                }
            };

            // Start tracking input
            KeyboardInputProvider = new KeyboardInputProvider(Form);
            MouseInputProvider    = new MouseInputProvider(Form);
            TouchInputProvider    = new TouchInputProvider(Form);
        }
Exemplo n.º 2
0
        //--------------------//

        #region Setup
        /// <summary>
        /// Initializes the <see cref="OmegaEngine.Engine"/> for rendering on this <see cref="Panel"/>.
        /// </summary>
        /// <returns>The newly initialized <see cref="Engine"/>.</returns>
        /// <exception cref="NotSupportedException">The graphics card does not meet the engine's minimum requirements.</exception>
        /// <exception cref="Direct3D9NotFoundException">Throw if required DirectX version is missing.</exception>
        /// <exception cref="Direct3DX9NotFoundException">Throw if required DirectX version is missing.</exception>
        /// <exception cref="Direct3D9Exception">internal errors occurred while intiliazing the graphics card.</exception>
        /// <exception cref="SlimDX.DirectSound.DirectSoundException">internal errors occurred while intiliazing the sound card.</exception>
        /// <remarks>Calling this multiple times will always return the same <see cref="OmegaEngine.Engine"/> instance.</remarks>
        public Engine Setup()
        {
            if (Engine == null)
            {
                Engine = new Engine(this, new EngineConfig {
                    TargetSize = ClientSize
                });
                KeyboardInputProvider = new KeyboardInputProvider(this);
                MouseInputProvider    = new MouseInputProvider(this);
                TouchInputProvider    = new TouchInputProvider(this);
            }

            return(Engine);
        }
Exemplo n.º 3
0
        //--------------------//

        #region Dispose
        protected override void Dispose(bool disposing)
        {
            try
            {
                _renderTimer.Dispose();

                Engine?.Dispose();
                TouchInputProvider?.Dispose();
                MouseInputProvider?.Dispose();
                KeyboardInputProvider?.Dispose();
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Calls <see cref="InputProvider.RemoveReceiver"/> for all default <see cref="InputProvider"/>s.
 /// </summary>
 /// <param name="receiver">The object to no longer receive the commands.</param>
 public void RemoveInputReceiver(IInputReceiver receiver)
 {
     KeyboardInputProvider.RemoveReceiver(receiver);
     MouseInputProvider.RemoveReceiver(receiver);
     TouchInputProvider.RemoveReceiver(receiver);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Calls <see cref="InputProvider.AddReceiver"/> for all default <see cref="InputProvider"/>s.
 /// </summary>
 /// <param name="receiver">The object to receive the commands.</param>
 public void AddInputReceiver(IInputReceiver receiver)
 {
     KeyboardInputProvider.AddReceiver(receiver);
     MouseInputProvider.AddReceiver(receiver);
     TouchInputProvider.AddReceiver(receiver);
 }