Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MultimediaJoystick"/> class.
 /// </summary>
 /// <param name="owner">The input factory that owns this device.</param>
 /// <param name="joystickID">The ID of the joystick.</param>
 /// <param name="name">The name of the joystick.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the owner parameter is NULL (or Nothing in VB.NET).</exception>
 internal MultimediaJoystick(GorgonInputFactory owner, int joystickID, string name)
     : base(owner, name)
 {
     AllowExclusiveMode = false;
     _joystickID        = joystickID;
     Gorgon.Log.Print("Windows multimedia joystick device ID 0x{0} interface created.", LoggingLevel.Verbose, joystickID.FormatHex());
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContentPanel"/> class.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="input">Input interface to use.</param>
        public ContentPanel(ContentObject content, GorgonInputFactory input = null)
            : this()
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            Content = content;
            UpdateCaption();
            RawInput = input;
        }
Esempio n. 3
0
        /// <summary>
        /// Function to return the raw input object from the editor.
        /// </summary>
        /// <returns>The raw input interface from the editor.</returns>
        protected GorgonInputFactory GetRawInput()
        {
            if (_input != null)
            {
                return(_input);
            }

            if (!Gorgon.PlugIns.Contains(GorgonRawInputTypeName))
            {
                return(null);
            }

            _input = GorgonInputFactory.CreateInputFactory(GorgonRawInputTypeName);

            return(_input);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XInputController"/> class.
        /// </summary>
        /// <param name="owner">The input factory that owns this device.</param>
        /// <param name="joystickID">The ID of the joystick.</param>
        /// <param name="name">The name of the joystick.</param>
        /// <param name="controller">Controller instance to bind to this joystick.</param>
        internal XInputController(GorgonInputFactory owner, int joystickID, string name, XI.Controller controller)
            : base(owner, name)
        {
            AllowExclusiveMode = false;

            _controller   = controller;
            _controllerID = joystickID;
            if (controller.IsConnected)
            {
                IsConnected = true;

#if DEBUG
                XI.Capabilities caps = controller.GetCapabilities(XI.DeviceQueryType.Any);
                Gorgon.Log.Print("XInput XBOX 360 controller device {0} interface created (ID:{1}).", LoggingLevel.Simple, caps.SubType.ToString(), joystickID);
#endif
            }
            else
            {
                Gorgon.Log.Print("Disconnected XInput XBOX 360 controller device #{0} interface created.", LoggingLevel.Simple, joystickID);
                IsConnected = false;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Function to initialize the application.
        /// </summary>
        private static void Initialize()
        {
            _form = new FormMain();

            _graphics  = new GorgonGraphics();
            _swapChain = _graphics.Output.CreateSwapChain("Swap",
                                                          new GorgonSwapChainSettings
            {
                Window             = _form,
                IsWindowed         = true,
                DepthStencilFormat = BufferFormat.D24_UIntNormal_S8_UInt,
                Format             = BufferFormat.R8G8B8A8_UIntNormal
            });

            _renderer2D = _graphics.Output.Create2DRenderer(_swapChain);

            _font = _graphics.Fonts.CreateFont("AppFont",
                                               new GorgonFontSettings
            {
                FontFamilyName   = "Calibri",
                FontStyle        = FontStyle.Bold,
                FontHeightMode   = FontHeightMode.Pixels,
                AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                OutlineSize      = 1,
                OutlineColor1    = Color.Black,
                Size             = 16.0f
            });

            _vertexShader       = _graphics.Shaders.CreateShader <GorgonVertexShader>("VertexShader", "PrimVS", Resources.Shaders);
            _pixelShader        = _graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "PrimPS", Resources.Shaders);
            _bumpShader         = _graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "PrimPSBump", Resources.Shaders);
            _waterShader        = _graphics.Shaders.CreateShader <GorgonPixelShader>("PixelShader", "PrimPSWaterBump", Resources.Shaders);
            _normalVertexShader = _graphics.Shaders.CreateShader <GorgonVertexShader>("NormalVertexShader", "NormalVS", Resources.Shaders);
            _normalPixelShader  = _graphics.Shaders.CreateShader <GorgonPixelShader>("NormalPixelShader", "NormalPS", Resources.Shaders);
            _vertexLayout       = _graphics.Input.CreateInputLayout("Vertex3D", typeof(Vertex3D), _vertexShader);
            _normalVertexLayout = _graphics.Input.CreateInputLayout("NormalVertex",
                                                                    new[]
            {
                new GorgonInputElement("SV_POSITION",
                                       BufferFormat.R32G32B32A32_Float,
                                       0,
                                       0,
                                       0,
                                       false,
                                       0),
            },
                                                                    _normalVertexShader);

            _graphics.Shaders.VertexShader.Current = _vertexShader;
            _graphics.Shaders.PixelShader.Current  = _pixelShader;
            _graphics.Input.Layout        = _vertexLayout;
            _graphics.Input.PrimitiveType = PrimitiveType.TriangleList;

            _texture       = _graphics.Textures.CreateTexture <GorgonTexture2D>("UVTexture", Resources.UV);
            _earf          = _graphics.Textures.CreateTexture <GorgonTexture2D>("Earf", Resources.earthmap1k);
            _normalMap     = _graphics.Textures.FromMemory <GorgonTexture2D>("RainNRM", Resources.Rain_Height_NRM, new GorgonCodecDDS());
            _normalEarfMap = _graphics.Textures.FromMemory <GorgonTexture2D>("EarfNRM", Resources.earthbump1k_NRM, new GorgonCodecDDS());
            _specMap       = _graphics.Textures.FromMemory <GorgonTexture2D>("RainSPC", Resources.Rain_Height_SPEC, new GorgonCodecDDS());
            _specEarfMap   = _graphics.Textures.CreateTexture <GorgonTexture2D>("EarfSPC", Resources.earthspec1k);
            _cloudMap      = _graphics.Textures.CreateTexture <GorgonTexture2D>("EarfClouds", Resources.earthcloudmap);
            _gorgNrm       = _graphics.Textures.CreateTexture <GorgonTexture2D>("EarfClouds", Resources.normalmap);

            var depth = new GorgonDepthStencilStates
            {
                DepthComparison     = ComparisonOperator.LessEqual,
                IsDepthEnabled      = true,
                IsDepthWriteEnabled = true
            };

            _graphics.Output.DepthStencilState.States = depth;
            _graphics.Output.SetRenderTarget(_swapChain, _swapChain.DepthStencilBuffer);
            _graphics.Rasterizer.States = GorgonRasterizerStates.CullBackFace;
            _graphics.Rasterizer.SetViewport(new GorgonViewport(0, 0, _form.ClientSize.Width, _form.ClientSize.Height, 0, 1.0f));
            _graphics.Shaders.PixelShader.TextureSamplers[0] = GorgonTextureSamplerStates.LinearFilter;

            _wvp = new WorldViewProjection(_graphics);
            _wvp.UpdateProjection(75.0f, _form.ClientSize.Width, _form.ClientSize.Height);

            // When we resize, update the projection and viewport to match our client size.
            _form.Resize += (sender, args) =>
            {
                _graphics.Rasterizer.SetViewport(new GorgonViewport(0, 0, _form.ClientSize.Width, _form.ClientSize.Height, 0, 1.0f));
                _wvp.UpdateProjection(75.0f, _form.ClientSize.Width, _form.ClientSize.Height);
            };

            var     fnU = new Vector3(0.5f, 1.0f, 0);
            var     fnV = new Vector3(1.0f, 1.0f, 0);
            Vector3 faceNormal;

            Vector3.Cross(ref fnU, ref fnV, out faceNormal);
            faceNormal.Normalize();

            _triangle = new Triangle(_graphics, new Vertex3D
            {
                Position = new Vector4(-12.5f, -1.5f, 12.5f, 1),
                Normal   = faceNormal,
                UV       = new Vector2(0, 1.0f)
            }, new Vertex3D
            {
                Position = new Vector4(0, 24.5f, 12.5f, 1),
                Normal   = faceNormal,
                UV       = new Vector2(0.5f, 0.0f)
            }, new Vertex3D
            {
                Position = new Vector4(12.5f, -1.5f, 12.5f, 1),
                Normal   = faceNormal,
                UV       = new Vector2(1.0f, 1.0f)
            })
            {
                Texture  = _texture,
                Position = new Vector3(0, 0, 1.0f)
            };

            _plane = new Plane(_graphics, new Vector2(25.0f, 25.0f), new RectangleF(0, 0, 1.0f, 1.0f), new Vector3(90, 0, 0), 32, 32)
            {
                Position = new Vector3(0, -1.5f, 1.0f),
                Texture  = _texture
            };

            _cube = new Cube(_graphics, new Vector3(1, 1, 1), new RectangleF(0, 0, 1.0f, 1.0f), new Vector3(45.0f, 0, 0), 1, 1)
            {
                Position = new Vector3(0, 0, 1.5f),
                Texture  = _texture
            };

            _sphere = new Sphere(_graphics, 1.0f, new RectangleF(0.0f, 0.0f, 1.0f, 1.0f), Vector3.Zero, 64, 64)
            {
                Position = new Vector3(-2.0f, 1.0f, 0.75f),
                Texture  = _earf
            };

            _clouds = new Sphere(_graphics, 5.175f, new RectangleF(0.0f, 0.0f, 1.0f, 1.0f), Vector3.Zero, 16, 16)
            {
                Position = new Vector3(10, 2, 9.5f),
                Texture  = _cloudMap
            };

            _icoSphere = new IcoSphere(_graphics, 5.0f, new RectangleF(0, 0, 1, 1), Vector3.Zero, 3)
            {
                Rotation = new Vector3(0, -45.0f, 0),
                Position = new Vector3(10, 2, 9.5f),
                Texture  = _earf
            };

            _graphics.Shaders.PixelShader.TextureSamplers[0] = new GorgonTextureSamplerStates
            {
                TextureFilter        = TextureFilter.Linear,
                HorizontalAddressing = TextureAddressing.Wrap,
                VerticalAddressing   = TextureAddressing.Wrap,
                DepthAddressing      = TextureAddressing.Wrap,
                ComparisonFunction   = ComparisonOperator.Always
            };
            _graphics.Shaders.PixelShader.TextureSamplers[2] = new GorgonTextureSamplerStates
            {
                TextureFilter        = TextureFilter.Linear,
                HorizontalAddressing = TextureAddressing.Wrap,
                VerticalAddressing   = TextureAddressing.Wrap,
                DepthAddressing      = TextureAddressing.Wrap,
                ComparisonFunction   = ComparisonOperator.Always
            };

            _graphics.Shaders.PixelShader.TextureSamplers[1] = new GorgonTextureSamplerStates
            {
                TextureFilter        = TextureFilter.Linear,
                HorizontalAddressing = TextureAddressing.Wrap,
                VerticalAddressing   = TextureAddressing.Wrap,
                DepthAddressing      = TextureAddressing.Wrap,
                ComparisonFunction   = ComparisonOperator.Always
            };

            _material = new Material
            {
                UVOffset      = Vector2.Zero,
                SpecularPower = 1.0f
            };

            _materialBuffer = _graphics.Buffers.CreateConstantBuffer("uvOffset", ref _material, BufferUsage.Default);

            _graphics.Shaders.PixelShader.ConstantBuffers[2] = _materialBuffer;

            _light = new Light(_graphics);
            var lightPosition = new Vector3(1.0f, 1.0f, -1.0f);

            _light.UpdateLightPosition(ref lightPosition, 0);
            GorgonColor color = GorgonColor.White;

            _light.UpdateSpecular(ref color, 256.0f, 0);

            lightPosition = new Vector3(-5.0f, 5.0f, 8.0f);
            _light.UpdateLightPosition(ref lightPosition, 1);
            color = Color.Yellow;
            _light.UpdateColor(ref color, 1);
            _light.UpdateSpecular(ref color, 2048.0f, 1);
            _light.UpdateAttenuation(10.0f, 1);

            lightPosition = new Vector3(5.0f, 3.0f, 10.0f);
            _light.UpdateLightPosition(ref lightPosition, 2);
            color = Color.Red;
            _light.UpdateColor(ref color, 2);
            _light.UpdateAttenuation(16.0f, 2);

            var eye    = Vector3.Zero;
            var lookAt = Vector3.UnitZ;
            var up     = Vector3.UnitY;

            _wvp.UpdateViewMatrix(ref eye, ref lookAt, ref up);

            _cameraRotation = Vector2.Zero;

            Gorgon.PlugIns.LoadPlugInAssembly(Application.StartupPath + @"\Gorgon.Input.Raw.dll");

            _input    = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonRawPlugIn");
            _keyboard = _input.CreateKeyboard(_form);
            _mouse    = _input.CreatePointingDevice(_form);

            _keyboard.KeyDown += (sender, args) =>
            {
                if (args.Key == KeyboardKeys.L)
                {
                    _lock = !_lock;
                }
            };

            _mouse.PointingDeviceDown      += Mouse_Down;
            _mouse.PointingDeviceUp        += Mouse_Up;
            _mouse.PointingDeviceWheelMove += (sender, args) =>
            {
                if (args.WheelDelta < 0)
                {
                    _sensitivity -= 0.05f;

                    if (_sensitivity < 0.05f)
                    {
                        _sensitivity = 0.05f;
                    }
                }
                else if (args.WheelDelta > 0)
                {
                    _sensitivity += 0.05f;

                    if (_sensitivity > 2.0f)
                    {
                        _sensitivity = 2.0f;
                    }
                }
            };
            _mouse.PointingDeviceMove += (sender, args) =>
            {
                if (!_mouse.Exclusive)
                {
                    return;
                }

                var delta = args.RelativePosition;
                _cameraRotation.Y      += delta.Y * _sensitivity;                                        //((360.0f * 0.002f) * delta.Y.Sign());
                _cameraRotation.X      += delta.X * _sensitivity;                                        //((360.0f * 0.002f) * delta.X.Sign());
                _mouseStart             = _mouse.Position;
                _mouse.RelativePosition = PointF.Empty;
            };
        }
Esempio n. 6
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                // Set our default cursor.
                _currentCursor = Resources.hand_icon;

                // Load our raw input plug-in assembly.
                Gorgon.PlugIns.LoadPlugInAssembly(Program.PlugInPath + "Gorgon.Input.Raw.DLL");

                // Create our input factory.
                _factory = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonRawPlugIn");

                // Get our device info.
                // This function is called when the factory is created.
                // However, I'm calling it here just to show that it exists.
                _factory.EnumerateDevices();

                // Validate, even though it's highly unlikely we'll run into these.
                if (_factory.PointingDevices.Count == 0)
                {
                    GorgonDialogs.ErrorBox(this, "There were no mice detected on this computer.  The application requires a mouse.");
                    Gorgon.Quit();
                }

                if (_factory.KeyboardDevices.Count == 0)
                {
                    GorgonDialogs.ErrorBox(this, "There were no keyboards detected on this computer.  The application requires a keyboard.");
                    Gorgon.Quit();
                }

                // Get our input devices.
                CreateMouse();
                CreateKeyboard();
                CreateJoystick();

                // When the display area changes size, update the spray effect
                // and limit the mouse.
                panelDisplay.Resize += panelDisplay_Resize;

                // Set the initial range of the mouse cursor.
                _mouse.PositionRange = Rectangle.Round(panelDisplay.ClientRectangle);

                // Set up our spray object.
                _spray  = new Spray(panelDisplay.ClientSize);
                _cursor = new MouseCursor(panelDisplay)
                {
                    Hotspot = new Point(-16, -3)
                };

                // Set up our idle method.
                Gorgon.ApplicationIdleLoopMethod = Idle;
            }
            catch (Exception ex)
            {
                // We do this here instead of just calling the dialog because this
                // function will send the exception to the Gorgon log file.
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex));
                Gorgon.Quit();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                // Load the XInput plug-in assembly.
                Gorgon.PlugIns.LoadPlugInAssembly(Program.PlugInPath + "Gorgon.Input.XInput.dll");

                // Create our factory.
                _factory = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonXInputPlugIn");

                // Ensure that we have and XBox controller to work with.
                if (_factory.JoystickDevices.Count == 0)
                {
                    GorgonDialogs.ErrorBox(this, "No XBox controllers were found on this system.\nThis example requires an XBox controller.");
                    Gorgon.Quit();
                    return;
                }

                // Enumerate the active joysticks.  We'll only take 3 of the 4 available xbox controllers.
                _joystick      = new GorgonJoystick[3];
                _stickPosition = new PointF[_joystick.Count];
                _sprayStates   = new SprayCan[_joystick.Count];

                for (int i = 0; i < _joystick.Count; i++)
                {
                    var joystick = _factory.CreateJoystick(this, _factory.JoystickDevices[i].Name);

                    // Set a dead zone on the joystick.
                    // A dead zone will stop input from the joystick until it reaches the outside
                    // of the specified coordinates.
                    joystick.DeadZone.X          = new GorgonRange(joystick.Capabilities.XAxisRange.Minimum / 4, joystick.Capabilities.XAxisRange.Maximum / 4);
                    joystick.DeadZone.Y          = new GorgonRange(joystick.Capabilities.YAxisRange.Minimum / 4, joystick.Capabilities.YAxisRange.Maximum / 4);
                    joystick.DeadZone.SecondaryX = new GorgonRange(joystick.Capabilities.XAxisRange.Minimum / 128, joystick.Capabilities.XAxisRange.Maximum / 128);
                    joystick.DeadZone.SecondaryY = new GorgonRange(joystick.Capabilities.YAxisRange.Minimum / 128, joystick.Capabilities.YAxisRange.Maximum / 128);

                    _joystick[i] = joystick;

                    // Start at a random spot.
                    _stickPosition[i] = new Point(GorgonRandom.RandomInt32(64, panelDisplay.ClientSize.Width - 64), GorgonRandom.RandomInt32(64, panelDisplay.ClientSize.Height - 64));

                    // Turn off spray for all controllers.
                    _sprayStates[i] = new SprayCan(joystick, i);
                }

                // Check for connected controllers.
                while (!_joystick.Any(item => item.IsConnected))
                {
                    if (MessageBox.Show(this,
                                        "There are no XBox controllers connected.\nPlease plug in an XBox controller and click OK.",
                                        "No Controllers", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.Cancel)
                    {
                        continue;
                    }

                    Gorgon.Quit();
                    return;
                }

                // Get the graphics interface for our panel.
                _surface = new DrawingSurface(panelDisplay);

                // Set up our idle loop.
                Gorgon.ApplicationIdleLoopMethod += Idle;
            }
            catch (Exception ex)
            {
                // We do this here instead of just calling the dialog because this
                // function will send the exception to the Gorgon log file.
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex));
                Gorgon.Quit();
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WinFormsPointingDevice"/> class.
 /// </summary>
 /// <param name="owner">The control that owns this device.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the owner parameter is NULL (or Nothing in VB.NET).</exception>
 internal WinFormsPointingDevice(GorgonInputFactory owner)
     : base(owner, "Win Forms Mouse")
 {
     AllowExclusiveMode = false;
     Gorgon.Log.Print("Windows forms input pointing device interface created.", LoggingLevel.Verbose);
 }
Esempio n. 9
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load"></see> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                // Load the plug-in assembly.
                Gorgon.PlugIns.LoadPlugInAssembly(Program.PlugInPath + "Gorgon.Input.Raw.DLL");

                // Create the factory.
                _input = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonRawPlugIn");

                // Create mouse, keyboard and joystick interfaces.
                _keyboard     = _input.CreateKeyboard(this);
                _mouse        = _input.CreatePointingDevice(this);
                _joystickList = new GorgonJoystick[_input.JoystickDevices.Count];

                // Create each joystick interface.
                for (int i = 0; i < _joystickList.Length; i++)
                {
                    _joystickList[i] = _input.CreateJoystick(this, _input.JoystickDevices[i].Name);
                }

                // Create the graphics interface.
                _graphics = new GorgonGraphics();
                _screen   = _graphics.Output.CreateSwapChain("Screen", new GorgonSwapChainSettings
                {
                    Size       = Settings.Default.Resolution,
                    Format     = BufferFormat.R8G8B8A8_UIntNormal,
                    IsWindowed = Settings.Default.IsWindowed
                });

                // For the backup image. Used to make it as large as the monitor that we're on.
                Screen currentScreen = Screen.FromHandle(Handle);

                // Relocate the window to the center of the screen.
                Location = new Point(currentScreen.Bounds.Left + (currentScreen.WorkingArea.Width / 2) - ClientSize.Width / 2,
                                     currentScreen.Bounds.Top + (currentScreen.WorkingArea.Height / 2) - ClientSize.Height / 2);


                // Create the 2D renderer.
                _2D = _graphics.Output.Create2DRenderer(_screen);

                // Create the text font.
                _font = _graphics.Fonts.CreateFont("Arial_9pt", new GorgonFontSettings
                {
                    FontFamilyName   = "Arial",
                    FontStyle        = FontStyle.Bold,
                    AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                    FontHeightMode   = FontHeightMode.Points,
                    Size             = 9.0f
                });

                // Enable the mouse.
                Cursor                          = Cursors.Cross;
                _mouse.Enabled                  = true;
                _mouse.Exclusive                = false;
                _mouse.PointingDeviceDown      += MouseInput;
                _mouse.PointingDeviceMove      += MouseInput;
                _mouse.PointingDeviceWheelMove += _mouse_PointingDeviceWheelMove;

                // Enable the keyboard.
                _keyboard.Enabled   = true;
                _keyboard.Exclusive = false;
                _keyboard.KeyDown  += _keyboard_KeyDown;

                // Create text sprite.
                _messageSprite       = _2D.Renderables.CreateText("Message", _font, "Using mouse and keyboard.");
                _messageSprite.Color = Color.Black;

                // Create a back buffer.
                _backBuffer = _graphics.Output.CreateRenderTarget("BackBuffer", new GorgonRenderTarget2DSettings
                {
                    Width  = _screen.Settings.Width,
                    Height = _screen.Settings.Height,
                    Format = BufferFormat.R8G8B8A8_UIntNormal
                });
                _backBuffer.Clear(Color.White);

                var settings = new GorgonTexture2DSettings
                {
                    Width  = currentScreen.Bounds.Width,
                    Height = currentScreen.Bounds.Height,
                    Format = BufferFormat.R8G8B8A8_UIntNormal,
                    Usage  = BufferUsage.Staging
                };

                // Clear our backup image to white to match our primary screen.
                _backupImage = _graphics.Textures.CreateTexture("Backup", settings);
                using (var textureData = _backupImage.Lock(BufferLockFlags.Write))
                {
                    textureData.Data.Fill(0xFF);
                }

                // Set the mouse range and position.
                Cursor.Position = PointToScreen(new Point(Settings.Default.Resolution.Width / 2, Settings.Default.Resolution.Height / 2));
                _mouse.SetPosition(Settings.Default.Resolution.Width / 2, Settings.Default.Resolution.Height / 2);
                _mouse.SetPositionRange(0, 0, Settings.Default.Resolution.Width, Settings.Default.Resolution.Height);

                // Set gorgon events.
                _screen.AfterStateTransition += (sender, args) =>
                {
                    OnResizeEnd(EventArgs.Empty);

                    // Reposition after a state change.
                    if (!args.IsWindowed)
                    {
                        return;
                    }

                    Screen monitor = Screen.FromHandle(Handle);
                    Location = new Point(monitor.Bounds.Left + (monitor.WorkingArea.Width / 2) - args.Width / 2,
                                         monitor.Bounds.Top + (monitor.WorkingArea.Height / 2) - args.Height / 2);
                    Cursor.Position = PointToScreen(Point.Round(_mouse.Position));
                };
                Gorgon.ApplicationIdleLoopMethod = Gorgon_Idle;
            }
            catch (Exception ex)
            {
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex));
                Gorgon.Quit();
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WinFormsKeyboard"/> class.
 /// </summary>
 /// <param name="owner">The control that owns this device.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the owner parameter is NULL (or Nothing in VB.NET).</exception>
 internal WinFormsKeyboard(GorgonInputFactory owner)
     : base(owner, "Win Forms Input Keyboard")
 {
     AllowExclusiveMode = false;
     Gorgon.Log.Print("Win Forms input keyboard interface created.", LoggingLevel.Verbose);
 }
Esempio n. 11
0
        /// <summary>
        /// Function to load in the input plug-ins.
        /// </summary>
        /// <returns>A list of input plug-ins.</returns>
        static IList <Tuple <GorgonInputPlugIn, GorgonInputFactory> > GetInputPlugIns()
        {
            IList <Tuple <GorgonInputPlugIn, GorgonInputFactory> > result = new Tuple <GorgonInputPlugIn, GorgonInputFactory>[] { };            // A list of input factories and the plug-ins that created them.

            // Get the files from the plug-in directory.
            // The plug-in directory can be changed in the configuration file
            // to point at wherever you'd like.  If a {0} place holder is
            // in the path, it will be replaced with whatever the build
            // configuration is set to (i.e. DEBUG or RELEASE).
            var files = Directory.GetFiles(PlugInPath, "*.dll");

            if (files.Length == 0)
            {
                return(result);
            }

            // Find our plug-ins in the DLLs.
            foreach (var file in files)
            {
                // Get the assembly name.
                // This is the preferred method of loading a plug-in assembly.
                // It keeps us from going into DLL hell because it'll contain
                // version information, public key info, etc...
                // We wrap this in this exception handler because if a DLL is
                // a native DLL, then it'll throw an exception.  And since
                // we can't load native DLLs as our plug-in, then we should
                // skip it.
                AssemblyName name;
                try
                {
                    name = AssemblyName.GetAssemblyName(file);
                }
                catch (BadImageFormatException)
                {
                    // This happens if we try and load a DLL that's not a .NET assembly.
                    continue;
                }

                // Skip any assemblies that aren't a plug-in assembly.
                if (!Gorgon.PlugIns.IsPlugInAssembly(name))
                {
                    continue;
                }

                // Load the assembly DLL.
                // This will not only load the assembly DLL into the application
                // domain (if it's not already loaded), but will also enumerate
                // the plug-in types.  If there are none, an exception will be
                // thrown.  This is why we do a check with IsPlugInAssembly before
                // we load the assembly.
                Gorgon.PlugIns.LoadPlugInAssembly(name);

                // Now try to retrieve our input plug-ins.
                // Retrieve the list of plug-ins from the assembly.  Once we have
                // the list we look for any plug-ins that are GorgonInputPlugIn
                // types and retrieve their type information.
                var inputPlugIns = Gorgon.PlugIns.EnumeratePlugIns(name)
                                   .Where(item => item is GorgonInputPlugIn)
                                   .Select(item => item.GetType()).ToArray();

                // If we have input plug-ins, and we haven't initialized our list, then do so now.
                if ((result.Count == 0) && (inputPlugIns.Length > 0))
                {
                    result = new List <Tuple <GorgonInputPlugIn, GorgonInputFactory> >();
                }

                // Add each input factory and plug-in to our list.
                foreach (var inputPlugIn in inputPlugIns)
                {
                    // Here we actually create the input factory from the plug-in
                    // by passing the input plug-in type.
                    var factory = GorgonInputFactory.CreateInputFactory(inputPlugIn);

                    if (factory != null)
                    {
                        result.Add(new Tuple <GorgonInputPlugIn, GorgonInputFactory>(
                                       (GorgonInputPlugIn)Gorgon.PlugIns[inputPlugIn.FullName],
                                       factory));
                    }
                }
            }

            return(result);
        }