示例#1
0
文件: Program.cs 项目: tmp7701/Gorgon
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                // Initialize the application.
                Initialize();

                // Now begin running the application idle loop.
                Gorgon.Run(_mainForm, Idle);
            }
            catch (Exception ex)
            {
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex));
            }
            finally
            {
                if (Graphics != null)
                {
                    Graphics.Dispose();
                }
            }
        }
示例#2
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);

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Set up the graphics interface.
                _graphics = new GorgonGraphics();

                // Create our 2D renderer to display the image.
                _2D = _graphics.Output.Create2DRenderer(this, 1280, 800);

                // Center the window on the screen.
                Screen currentMonitor = Screen.FromControl(this);
                Location = new Point(currentMonitor.WorkingArea.Left + (currentMonitor.WorkingArea.Width / 2 - Width / 2),
                                     currentMonitor.WorkingArea.Top + (currentMonitor.WorkingArea.Height / 2 - Height / 2));

                // Load our base texture.
                _image = _graphics.Textures.FromMemory <GorgonTexture2D>("SourceTexture",
                                                                         Resources.SourceTexture,
                                                                         new GorgonCodecDDS());


                // Load the custom codec.
                if (!LoadCodec())
                {
                    GorgonDialogs.ErrorBox(this, "Unable to load the useless image codec plug-in.");
                    Gorgon.Quit();
                    return;
                }

                // Convert the image to our custom codec.
                ConvertImage();

                // Set up our idle time processing.
                Gorgon.ApplicationIdleLoopMethod = () =>
                {
                    _2D.Clear(Color.White);

                    // Draw to the window.
                    Draw();

                    // Render with a vsync interval of 2 (typically 30 FPS).
                    // We're not making an action game here.
                    _2D.Render(2);
                    return(true);
                };
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(this, ex);
                Gorgon.Quit();
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
示例#3
0
        private void SetupGorgon()
        {
            Gorgon.Initialize(true, false);
            Gorgon.SetMode(this);
            //Gorgon.AllowBackgroundRendering = true;
            //Gorgon.Screen.BackgroundColor = Color.FromArgb(50, 50, 50);

            //Gorgon.CurrentClippingViewport = new Viewport(0, 20, Gorgon.Screen.Width, Gorgon.Screen.Height - 20);
            //PreciseTimer preciseTimer = new PreciseTimer();
            //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66);
            Gorgon.Idle += new FrameEventHandler(Gorgon_Idle);
            Gorgon.FrameStatsVisible = true;
            Gorgon.DeviceReset      += MainWindowResizeEnd;

            bouncesprite = new Sprite("flyingball", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"flyingball.png"));
            //bouncesprite.SetScale(3, 3);

            baseTarget       = new RenderImage("baseTarget", 32, 32, ImageBufferFormats.BufferRGB888A8);
            baseTargetSprite = new Sprite("baseTargetSprite", baseTarget);

            screenTarget = new RenderImage("screenTarget", Gorgon.CurrentClippingViewport.Width, Gorgon.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8);

            bounceysprites = new BounceySprite[10];
            for (int i = 0; i < 10; i++)
            {
                bounceysprites[i] = new BounceySprite(bouncesprite, new Vector2D(random.Next(0, Gorgon.CurrentClippingViewport.Width), random.Next(0, Gorgon.CurrentClippingViewport.Height)),
                                                      new Vector2D((float)random.Next(-100000, 100000) / 100000, (float)random.Next(-100000, 100000) / 100000)
                                                      , this);
            }
        }
示例#4
0
文件: Text.cs 项目: tmp7701/Gorgon
        public void TestText()
        {
            _form.Show();
            _form.ClientSize = new Size(1280, 800);
            _form.Location   = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - 640, Screen.PrimaryScreen.WorkingArea.Height / 2 - 400);
            _form.BringToFront();
            _form.WindowState = FormWindowState.Minimized;
            _form.WindowState = FormWindowState.Normal;

            GorgonText text = _renderer.Renderables.CreateText("Test",
                                                               _graphics.Fonts.DefaultFont,
                                                               "The quick brown fox jumps over the lazy dog.\n1234567890 !@#$%^&*() ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz");

            Gorgon.Run(_form, () =>
            {
                _renderer.Clear(Color.Black);

                text.Draw();

                _renderer.Render();

                return(true);
            });

            Assert.IsTrue(_form.TestResult == DialogResult.Yes);
        }
示例#5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Gorgon.Run(new Form1());
        }
示例#6
0
        /// <summary>
        /// Function to bind the device to a window.
        /// </summary>
        /// <param name="boundWindow">Window to bind with.</param>
        /// <remarks>Passing NULL (Nothing in VB.Net) to <paramref name="boundWindow"/> will use the <see cref="GorgonLibrary.Gorgon.ApplicationForm">main Gorgon Application Form</see>.  If there is no Form bound with the application, then an exception will be thrown.</remarks>
        /// <exception cref="System.ArgumentException">Thrown when the boundWindow parameter and the Gorgon.ApplicationForm property are both NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the top level form cannot be determined.</para>
        /// </exception>
        public void Bind(Control boundWindow)
        {
            if (BoundControl != null)
            {
                UnbindWindow();
                BoundControl      = null;
                BoundTopLevelForm = null;
            }

            if (boundWindow == null)
            {
                if (Gorgon.ApplicationForm == null)
                {
                    throw new ArgumentException(Resources.GORINP_NO_WINDOW_TO_BIND, "boundWindow");
                }

                boundWindow = Gorgon.ApplicationForm;
            }

            Gorgon.Log.Print("Binding input device object {1} to window 0x{0}.", LoggingLevel.Intermediate, boundWindow.Handle.FormatHex(), GetType().Name);

            BoundControl      = boundWindow;
            BoundTopLevelForm = Gorgon.GetTopLevelForm(BoundControl);

            if (BoundTopLevelForm == null)
            {
                throw new ArgumentException(Resources.GORINP_NO_WINDOW_TO_BIND, "boundWindow");
            }

            BoundTopLevelForm.Activated  += BoundForm_Activated;
            BoundTopLevelForm.Deactivate += BoundForm_Deactivate;
            BoundControl.LostFocus       += BoundWindow_LostFocus;
            BoundControl.GotFocus        += BoundWindow_GotFocus;
        }
示例#7
0
文件: Program.cs 项目: tmp7701/Gorgon
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                Initialize();
                Gorgon.Run(_mainForm, Idle);
            }
            catch (Exception ex)
            {
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex));
            }
            finally
            {
                if (_wvpBufferStream != null)
                {
                    _wvpBufferStream.Dispose();
                }

                if (Graphics != null)
                {
                    Graphics.Dispose();
                }
            }
        }
示例#8
0
文件: Program.cs 项目: tmp7701/Gorgon
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Initialize our example.
                Initialize();

                // Start it running.
                Gorgon.Run(_formMain, Idle);
            }
            catch (Exception ex)
            {
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex));
            }
            finally
            {
                // Perform clean up.
                if (_renderer != null)
                {
                    _renderer.Dispose();
                }

                if (_graphics != null)
                {
                    _graphics.Dispose();
                }
            }
        }
示例#9
0
文件: Program.cs 项目: tmp7701/Gorgon
		static void Main()
		{
			try
			{
				Application.EnableVisualStyles();
				Application.SetCompatibleTextRenderingDefault(false);

				_form = new formMain
				    {
				        ClientSize = new Size(640, 480)
				    };

			    // Get the initial time.
				_lastTime = GorgonTiming.MillisecondsSinceStart;

				// Run the application with an idle loop.
				//
				// The form will still control the life time of the application (i.e. the close button will end the application). 
				// However, you may specify only the idle method and use that to control the application life time, similar to 
				// standard windows application in C++.
				// Other overloads allow using only the form and assigning the idle method at another time (if at all), or setting
				// up an application context object to manage the life time of the application (with or without an idle loop 
				// method).
				Gorgon.Run(_form, Idle);
			}
			catch (Exception ex)
			{
				// Catch all exceptions here.  If we had logging for the application enabled, then this 
				// would record the exception in the log.
				GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex));
			}
		}
示例#10
0
        /// <summary>
        /// Initializes the <see cref="GorgonGraphics"/> class.
        /// </summary>
        /// <param name="device">Video device to use.</param>
        /// <param name="featureLevel">The maximum feature level to support for the devices enumerated.</param>
        /// <exception cref="System.ArgumentException">Thrown when the <paramref name="featureLevel"/> parameter is invalid.</exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when Gorgon could not find any video devices that are Shader Model 5, or the down level interfaces (Shader Model 4, and lesser).
        /// <para>-or-</para>
        /// <para>Thrown if the operating system version is not supported.  Gorgon Graphics requires at least Windows Vista Service Pack 2 or higher.</para>
        /// </exception>
        /// <remarks>
        /// The <paramref name="device"/> parameter is the video device that should be used with Gorgon.  If the user passes NULL (Nothing in VB.Net), then the primary device will be used.
        /// To determine the devices on the system, check the <see cref="GorgonLibrary.Graphics.GorgonVideoDeviceEnumerator">GorgonVideoDeviceEnumerator</see> class.  The primary device will be the first device in this collection.
        /// <para>The user may pass in a feature level to the featureLevel parameter to limit the feature levels available.  Note that the feature levels imply all feature levels up until the feature level passed in, for example, passing <c>DeviceFeatureLevel.SM4</c> will only allow functionality
        /// for both Shader Model 4, and Shader Model 2/3 capable video devices, while DeviceFeatureLevel.SM4_1 will include Shader Model 4 with a 4.1 profile and Shader model 2/3 video devices.</para>
        /// <para>If a feature level is not supported by the hardware, then Gorgon will not use that feature level.  That is, passing a SM5 feature level with a SM4 card will only use a SM4 feature level.  If the user omits the feature level (in one of the constructor
        /// overloads), then Gorgon will use the best available feature level for the video device being used.</para>
        /// </remarks>
        public GorgonGraphics(GorgonVideoDevice device, DeviceFeatureLevel featureLevel)
        {
            ResetFullscreenOnFocus = true;
            ImmediateContext       = this;

            if (featureLevel == DeviceFeatureLevel.Unsupported)
            {
                throw new ArgumentException(Resources.GORGFX_FEATURE_LEVEL_UNKNOWN);
            }

            if (GorgonComputerInfo.OperatingSystemVersion.Major < 6)
            {
                throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_INVALID_OS);
            }

            Gorgon.Log.Print("Gorgon Graphics initializing...", LoggingLevel.Simple);

            // Track our objects.
            _trackedObjects = new GorgonDisposableObjectCollection();

#if DEBUG
            if (!SharpDX.Configuration.EnableObjectTracking)
            {
                SharpDX.Configuration.EnableObjectTracking = true;
            }
#else
            SharpDX.Configuration.EnableObjectTracking = false;
#endif

            if (device == null)
            {
                if (GorgonVideoDeviceEnumerator.VideoDevices.Count == 0)
                {
                    GorgonVideoDeviceEnumerator.Enumerate(false, false);
                }

                // Use the first device in the list.
                device = GorgonVideoDeviceEnumerator.VideoDevices[0];
            }

            VideoDevice = device;

            var D3DDeviceData = VideoDevice.GetDevice(VideoDevice.VideoDeviceType, featureLevel);

            // Create the DXGI factory for the video device.
            GIFactory = D3DDeviceData.Item1;
            Adapter   = D3DDeviceData.Item2;
            D3DDevice = D3DDeviceData.Item3;

            Context = D3DDevice.ImmediateContext;
            Context.ClearState();
            VideoDevice.Graphics = ImmediateContext;

            CreateStates();

            Gorgon.AddTrackedObject(this);

            Gorgon.Log.Print("Gorgon Graphics initialized.", LoggingLevel.Simple);
        }
示例#11
0
 /// <summary>
 /// Handles the FormClosing event of the MainForm control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Forms.FormClosingEventArgs"/> instance containing the event data.</param>
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!DesignMode)
     {
         // Perform clean up.
         Gorgon.Terminate();
     }
 }
示例#12
0
        /// <summary>
        /// Handles the ParentChanged event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void Window_ParentChanged(object sender, EventArgs e)
        {
            try
            {
                // If the actual control has changed parents, update the top level control.
                if (sender == Settings.Window)
                {
                    var newTopLevelParent = Gorgon.GetTopLevelControl(Settings.Window);

                    if (newTopLevelParent != _topLevelControl)
                    {
                        _topLevelControl.ParentChanged -= Window_ParentChanged;

                        // If we're not at the top of the chain, then find out which window is and set it up
                        // to handle changes to its hierarchy.
                        if (newTopLevelParent != Settings.Window)
                        {
                            _topLevelControl = newTopLevelParent;
                            _topLevelControl.ParentChanged += Window_ParentChanged;
                        }
                    }
                }

                if (_parentForm != null)
                {
                    _parentForm.ResizeBegin -= _parentForm_ResizeBegin;
                    _parentForm.ResizeEnd   -= _parentForm_ResizeEnd;
                }

                _parentForm = Gorgon.GetTopLevelForm(Settings.Window);

                if (_parentForm == null)
                {
                    return;
                }

                _parentForm.ResizeBegin += _parentForm_ResizeBegin;
                _parentForm.ResizeEnd   += _parentForm_ResizeEnd;
            }
            catch (Exception ex)
            {
#if DEBUG
                GorgonException.Catch(ex,
                                      () =>
                                      GorgonDialogs.ErrorBox(_parentForm,
                                                             string.Format(Resources.GORGFX_CATASTROPHIC_ERROR, Gorgon.Log.LogPath),
                                                             null,
                                                             ex));

                // If we fail in here, then we have a terminal error in Gorgon, don't risk further corruption.
                Gorgon.Quit();
#else
                GorgonException.Catch(ex);
#endif
            }
        }
示例#13
0
        /// <summary>
        /// Handles the Resize event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Window_Resize(object sender, EventArgs e)
        {
            // If we're in a manual resize operation, then don't call this method just yet.
            if (_isInResize)
            {
                return;
            }

            // Attempt to get the parent form if we don't have one yet.
            if (_parentForm == null)
            {
                _parentForm              = Gorgon.GetTopLevelForm(Settings.Window);
                _parentForm.ResizeBegin += _parentForm_ResizeBegin;
                _parentForm.ResizeEnd   += _parentForm_ResizeEnd;
            }

            if ((!AutoResize) || ((_parentForm != null) && (_parentForm.WindowState == FormWindowState.Minimized)))
            {
                return;
            }

            // Only do this if the size has changed, if we're just restoring the window, then don't bother.
            if (((GISwapChain == null)) || (Settings.Window.ClientSize.Width <= 0) || (Settings.Window.ClientSize.Height <= 0))
            {
                return;
            }

            try
            {
                // Resize the video mode.
                Settings.VideoMode = new GorgonVideoMode(Settings.Window.ClientSize.Width,
                                                         Settings.Window.ClientSize.Height,
                                                         Settings.VideoMode.Format,
                                                         Settings.VideoMode.RefreshRateNumerator,
                                                         Settings.VideoMode.RefreshRateDenominator);
                ResizeBuffers();
            }
            catch (Exception ex)
            {
#if DEBUG
                GorgonException.Catch(ex,
                                      () =>
                                      GorgonDialogs.ErrorBox(_parentForm,
                                                             string.Format(Resources.GORGFX_CATASTROPHIC_ERROR, Gorgon.Log.LogPath),
                                                             null,
                                                             ex));

                // If we fail in here, then we have a terminal error in Gorgon, don't risk further corruption.
                Gorgon.Quit();
#else
                // Log the exception.
                GorgonException.Catch(ex);
#endif
            }
        }
示例#14
0
        /// <summary>
        /// Function to run the test.
        /// </summary>
        /// <returns>The test result for manual testing.</returns>
        public DialogResult Run()
        {
            _form.WindowState = FormWindowState.Minimized;
            _form.Show();
            _form.WindowState = FormWindowState.Normal;

            //_form.TopMost = true;

            Gorgon.Run(_form, Idle);

            return(_form.TestResult);
        }
示例#15
0
        /// <summary>
        /// Function to initialize the scratch files area.
        /// </summary>
        private void InitializeScratchArea()
        {
            ScratchArea.ScratchPath = Program.Settings.ScratchPath;

            EditorLogging.Print("Creating scratch area at \"{0}\"", LoggingLevel.Verbose, ScratchArea.ScratchPath);

            _splash.UpdateVersion(Resources.GOREDIT_TEXT_CREATING_SCRATCH);

            // Ensure that we're not being clever and trying to mess up our system.
            if (ScratchArea.CanAccessScratch(Program.Settings.ScratchPath) == ScratchAccessibility.SystemArea)
            {
                GorgonDialogs.ErrorBox(null, Resources.GOREDIT_ERR_CANNOT_USESYS_SCRATCH);
            }
            else
            {
                // Destroy previous scratch area files if possible.
                // Do not do this when we have it set to a system area, this will keep us from
                // destroying anything critical.
                ScratchArea.CleanOldScratchAreas();
            }

            // Ensure we can actually access the scratch area.
            while (ScratchArea.CanAccessScratch(Program.Settings.ScratchPath) != ScratchAccessibility.Accessible)
            {
                EditorLogging.Print("Could not access scratch area at \"{0}\"", LoggingLevel.Verbose, Program.Settings.ScratchPath);

                if (ScratchArea.SetScratchLocation() == ScratchAccessibility.Canceled)
                {
                    // Exit the application if we cancel.
                    MainForm.Dispose();
                    Gorgon.Quit();
                    return;
                }

                EditorLogging.Print("Setting scratch area to \"{0}\".", LoggingLevel.Verbose, Program.Settings.ScratchPath);

                // Update with the new scratch path.
                Program.Settings.Save();
            }

            ScratchArea.InitializeScratch();

            // Get only the providers that are not disabled.
            var plugIns = from plugIn in Gorgon.PlugIns
                          where plugIn is GorgonFileSystemProviderPlugIn &&
                          PlugIns.UserDisabledPlugIns.All(name => !string.Equals(name, plugIn.Name, StringComparison.OrdinalIgnoreCase))
                          select plugIn;

            foreach (GorgonPlugIn plugIn in plugIns)
            {
                ScratchArea.ScratchFiles.Providers.LoadProvider(plugIn.Name);
            }
        }
示例#16
0
文件: Program.cs 项目: tmp7701/Gorgon
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Settings.Load();

                Gorgon.PlugIns.AssemblyResolver = (appDomain, e) => appDomain.GetAssemblies()
                                                  .FirstOrDefault(assembly => assembly.FullName == e.Name);

                Gorgon.Run(new AppContext());
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(null, ex);
            }
            finally
            {
                Gorgon.PlugIns.AssemblyResolver = null;

                ContentManagement.UnloadCurrentContent();

                // Clean up the plug-ins.
                foreach (var plugInItem in PlugIns.ContentPlugIns)
                {
                    plugInItem.Value.Dispose();
                }

                foreach (var plugInItem in PlugIns.WriterPlugIns)
                {
                    plugInItem.Value.Dispose();
                }

                // Shut down the graphics interface.
                if (ContentObject.Graphics != null)
                {
                    ContentObject.Graphics.Dispose();
                    ContentObject.Graphics = null;
                }

                // Clean up temporary files in scratch area.
                if (Settings != null)
                {
                    ScratchArea.DestroyScratchArea();
                }

                EditorLogging.Close();
            }
        }
示例#17
0
        /// <summary>
        /// Initializes the display control.
        /// </summary>
        public void InitDisplay()
        {
            if (!DesignMode)
            {
                // Initialize the library.
                Gorgon.Initialize();

                // Display the logo and frame stats.
                Gorgon.LogoVisible              = false;
                Gorgon.FrameStatsVisible        = false;
                Gorgon.AllowBackgroundRendering = true;

                // Set the video mode to match the form client area.
                Gorgon.SetMode(this);

                // Assign rendering event handler.
                Gorgon.Idle += new FrameEventHandler(Screen_OnFrameBegin);

                // Set the clear color to something ugly.
                Gorgon.Screen.BackgroundColor = Color.FromArgb(0, 0, 0);

                //Init Configuration and resource manager.
                MainForm.InitializeResourceManager();

                /*
                 * _particleImage = GorgonLibrary.Graphics.Image.FromFile("star1.png");
                 * _particleSprite = new Sprite("particlesprite", _particleImage);
                 * _particleSprite.Axis = new Vector2(_particleSprite.Width/2, _particleSprite.Height/2);*/
                _particleSprite = ResourceManager.GetSprite("star1");
                var settings = ParticleConfigurator.ParticleSettings;
                _particleSystem                         = new ParticleSystem(_particleSprite, new Vector2(0, 0));
                settings.ColorRange                     = new SS14.Shared.Utility.Range <Color>(Color.Blue, Color.Black);
                settings.EmitterPosition                = new PointF(Gorgon.Screen.Width / 2, Gorgon.Screen.Height / 2);
                settings.EmissionRadiusRange            = new PointF(10, 170);
                settings.EmitRate                       = 40;
                settings.Velocity                       = new Vector2(0, -20);
                settings.Acceleration                   = new Vector2(0, -30);
                settings.RadialAcceleration             = 10;
                settings.TangentialAccelerationVariance = 0.2f;
                settings.TangentialVelocityVariance     = 1;
                settings.RadialVelocityVariance         = 1;
                //_particleSystem.TangentialAcceleration = 5;
                settings.Lifetime             = 3;
                _particleSystem.Emit          = true;
                settings.SpinVelocityVariance = 2;

                // Begin execution.
                Gorgon.Go();
            }
        }
示例#18
0
文件: Program.cs 项目: tmp7701/Gorgon
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Gorgon.Run(new FormMain());
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(null, ex);
            }
        }
示例#19
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    Gorgon.RemoveTrackedObject(this);

                    // Destroy any outstanding device instances.
                    DestroyDevices();
                }
            }

            _disposed = true;
        }
示例#20
0
        private void SetupGorgon()
        {
            Gorgon.Initialize(true, false);
            Gorgon.SetMode(this);
            //Gorgon.AllowBackgroundRendering = true;
            //Gorgon.Screen.BackgroundColor = Color.FromArgb(50, 50, 50);

            //Gorgon.CurrentClippingViewport = new Viewport(0, 20, Gorgon.Screen.Width, Gorgon.Screen.Height - 20);
            //PreciseTimer preciseTimer = new PreciseTimer();
            //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66);
            Gorgon.Idle += new FrameEventHandler(Gorgon_Idle);
            Gorgon.FrameStatsVisible = true;

            bouncesprite = new Sprite("bouncey", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Items.png"), new Vector2D(0, 0), new Vector2D(22, 20));
            bouncesprite.SetScale(3, 3);
            decalsprite = new Sprite("decal", GorgonLibrary.Graphics.Image.FromFile(mediadir + @"\textures\0_Decals.png"), new Vector2D(56, 0), new Vector2D(103, 29));
            decalsprite.SetScale(1, 1);
            decalShader = FXShader.FromFile(mediadir + @"\shaders\decalshader.fx", ShaderCompileOptions.Debug);
            decalShader.Parameters["tex1"].SetValue(decalsprite.Image);

            baseTarget       = new RenderImage("baseTarget", 32, 32, ImageBufferFormats.BufferRGB888A8);
            baseTargetSprite = new Sprite("baseTargetSprite", baseTarget);

            bounceysprites = new BounceySprite[10];
            for (int i = 0; i < 10; i++)
            {
                bounceysprites[i] = new BounceySprite(bouncesprite, new Vector2D(random.Next(0, Gorgon.Screen.Width), random.Next(0, Gorgon.Screen.Height)),
                                                      new Vector2D((float)random.Next(-100000, 100000) / 100000, (float)random.Next(-100000, 100000) / 100000),
                                                      decalsprite, new Vector2D(random.Next(-10, 15), random.Next(-10, 15)), decalShader, this);
            }


            //Calculate decal texcoord offsets

            /*Vector2D decalBToffset = new Vector2D(10,5);
             * float BTXDTL_x = decalBToffset.X / bouncesprite.Image.Width;
             * float BTXDTL_y = decalBToffset.Y / bouncesprite.Image.Height;
             * float BTXDBR_x = (decalBToffset.X + decalsprite.Width)/bouncesprite.Image.Width;
             * float BTXDBR_y = (decalBToffset.Y + decalsprite.Height)/bouncesprite.Image.Height;
             * float CFx = (float)decalsprite.Image.Width/(float)bouncesprite.Image.Width;
             * float CFy = (float)decalsprite.Image.Height / (float)bouncesprite.Image.Height;
             * float DOtc_xtl = (float)decalsprite.ImageOffset.X / (float)decalsprite.Image.Width;
             * float DOtc_ytl = (float)decalsprite.ImageOffset.Y / (float)decalsprite.Image.Height;
             *
             * Vector4D decalParms1 = new Vector4D(BTXDTL_x, BTXDTL_y, BTXDBR_x, BTXDBR_y);
             * Vector4D decalParms2 = new Vector4D(CFx, CFy, DOtc_xtl, DOtc_ytl);*/
        }
示例#21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonSwapChain"/> class.
        /// </summary>
        /// <param name="graphics">Graphics interface that owns this swap chain.</param>
        /// <param name="name">The name of the swap chain.</param>
        /// <param name="settings">Settings for the swap chain.</param>
        internal GorgonSwapChain(GorgonGraphics graphics, string name, GorgonSwapChainSettings settings)
            : base(name)
        {
            Graphics = graphics;
            Settings = settings;

            // Get the parent form for our window.
            _parentForm      = Gorgon.GetTopLevelForm(settings.Window);
            _topLevelControl = Gorgon.GetTopLevelControl(settings.Window);
            settings.Window.ParentChanged += Window_ParentChanged;

            if (_topLevelControl != settings.Window)
            {
                _topLevelControl.ParentChanged += Window_ParentChanged;
            }

            AutoResize = true;
        }
示例#22
0
        private void MainWindowLoad(object sender, EventArgs e)
        {
            _configurationManager = IoCManager.Resolve <IConfigurationManager>();

            SetupGorgon();
            SetupInput();

            IoCManager.Resolve <IResourceManager>().LoadBaseResources();
            IoCManager.Resolve <IResourceManager>().LoadLocalResources();

            Gorgon.Go();

            _networkManager       = IoCManager.Resolve <INetworkManager>();
            _netGrapher           = IoCManager.Resolve <INetworkGrapher>();
            _stateManager         = IoCManager.Resolve <IStateManager>();
            _userInterfaceManager = IoCManager.Resolve <IUserInterfaceManager>();

            _stateManager.RequestStateChange <MainScreen>();
        }
示例#23
0
文件: Program.cs 项目: tmp7701/Gorgon
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Initialize();

                Gorgon.Run(_form, Idle);
            }
            catch (Exception ex)
            {
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex));
            }
            finally
            {
                CleanUp();
            }
        }
示例#24
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
            {
                Cursor = Cursors.WaitCursor;

                // Initialize.
                Initialize();
            }
            catch (Exception ex)
            {
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex));
                Gorgon.Quit();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
示例#25
0
        /// <summary>
        /// Handles the Deactivate event of the _parentForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void _parentForm_Deactivate(object sender, EventArgs e)
        {
            try
            {
                if ((GISwapChain == null) || (!Graphics.ResetFullscreenOnFocus))
                {
                    return;
                }

                Graphics.GetFullScreenSwapChains();

                // Reset the video mode to windowed.
                // Note:  For some reason, this is different than it was on SlimDX.  I never had to do this before, but with
                // SharpDX I now have to handle the transition from full screen to windowed manually.
                if (!GISwapChain.IsFullScreen)
                {
                    return;
                }

                GISwapChain.SetFullscreenState(false, null);
                Settings.IsWindowed = true;
                ((Form)Settings.Window).WindowState = FormWindowState.Minimized;
            }
            catch (Exception ex)
            {
#if DEBUG
                GorgonException.Catch(ex,
                                      () =>
                                      GorgonDialogs.ErrorBox(_parentForm,
                                                             string.Format(Resources.GORGFX_CATASTROPHIC_ERROR, Gorgon.Log.LogPath),
                                                             null,
                                                             ex));

                // If we fail in here, then we have a terminal error in Gorgon, don't risk further corruption.
                Gorgon.Quit();
#else
                GorgonException.Catch(ex);
#endif
            }
        }
示例#26
0
        private void SetupGorgon()
        {
            uint displayWidth  = _configurationManager.GetDisplayWidth();
            uint displayHeight = _configurationManager.GetDisplayHeight();
            bool fullscreen    = _configurationManager.GetFullscreen();
            var  refresh       = (int)_configurationManager.GetDisplayRefresh();

            Size = new Size((int)displayWidth, (int)displayHeight);

            //TODO. Find first compatible videomode and set it if no configuration is present. Else the client might crash due to invalid videomodes on the first start.

            Gorgon.Initialize(true, false);
            //Gorgon.SetMode(this);
            Gorgon.SetMode(this, (int)displayWidth, (int)displayHeight, BackBufferFormats.BufferRGB888, !fullscreen,
                           false, false, refresh);
            Gorgon.AllowBackgroundRendering = true;
            Gorgon.Screen.BackgroundColor   = Color.FromArgb(50, 50, 50);
            Gorgon.CurrentClippingViewport  = new Viewport(0, 0, Gorgon.Screen.Width, Gorgon.Screen.Height);
            Gorgon.DeviceReset += MainWindowResizeEnd;
            //Gorgon.MinimumFrameTime = PreciseTimer.FpsToMilliseconds(66);
            Gorgon.Idle += GorgonIdle;
        }
示例#27
0
        /// <summary>
        /// Handles the Activated event of the _parentForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void _parentForm_Activated(object sender, EventArgs e)
        {
            try
            {
                if ((GISwapChain == null) || (!Graphics.ResetFullscreenOnFocus))
                {
                    return;
                }

                Graphics.GetFullScreenSwapChains();

                if (GISwapChain.IsFullScreen)
                {
                    return;
                }

                ((Form)Settings.Window).WindowState = FormWindowState.Normal;
                // Get the current video output.
                GISwapChain.SetFullscreenState(true, null);
                Settings.IsWindowed = false;
            }
            catch (Exception ex)
            {
#if DEBUG
                GorgonException.Catch(ex,
                                      () =>
                                      GorgonDialogs.ErrorBox(_parentForm,
                                                             string.Format(Resources.GORGFX_CATASTROPHIC_ERROR, Gorgon.Log.LogPath),
                                                             null,
                                                             ex));

                // If we fail in here, then we have a terminal error in Gorgon, don't risk further corruption.
                Gorgon.Quit();
#else
                GorgonException.Catch(ex);
#endif
            }
        }
示例#28
0
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Get the initial time.
                _lastTime = GorgonTiming.MillisecondsSinceStart;

                // Run the application context with an idle loop.
                //
                // Here we specify that we want to run an application context and an idle loop.  The idle loop
                // will kick in after the main form displays.
                Gorgon.Run(new Context(), Idle);
            }
            catch (Exception ex)
            {
                // Catch all exceptions here.  If we had logging for the application enabled, then this
                // would record the exception in the log.
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex));
            }
        }
示例#29
0
        /// <summary>
        /// Handles the Load event of the MainForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                // Initialize the library.
                Gorgon.Initialize();

                // Display the logo and frame stats.
                Gorgon.LogoVisible       = false;
                Gorgon.FrameStatsVisible = false;

                // Set the video mode to match the form client area.
                Gorgon.SetMode(this);

                // Assign rendering event handler.
                Gorgon.Idle += new FrameEventHandler(Screen_OnFrameBegin);

                // Set the clear color to something ugly.
                Gorgon.Screen.BackgroundColor = Color.FromArgb(250, 245, 220);

                LoadFont();

                txtspr = new TextSprite("txtspr", "Test", font, Color.Black);

                txtspr.SetPosition(1.0f, 1.0f);
                TextStatus();

                RunMeasureLineTests();
                // Begin execution.
                Gorgon.Go();
            }
            catch (Exception ex)
            {
                UI.ErrorBox(this, "An unhandled error occured during execution, the program will now close.", ex.Message + "\n\n" + ex.StackTrace);
                Application.Exit();
            }
        }
示例#30
0
        public void TestEllipse()
        {
            _form.Show();
            _form.ClientSize = new Size(1280, 800);
            _form.Location   = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - 640, Screen.PrimaryScreen.WorkingArea.Height / 2 - 400);
            _form.BringToFront();
            _form.WindowState = FormWindowState.Minimized;
            _form.WindowState = FormWindowState.Normal;

            GorgonEllipse ellipse = _renderer.Renderables.CreateEllipse("Test",
                                                                        new Vector2(320, 400),
                                                                        new Vector2(100, 100),
                                                                        Color.Blue,
                                                                        true,
                                                                        32);

            Gorgon.Run(_form, () =>
            {
                _renderer.Clear(Color.Black);

                ellipse.Color    = Color.Blue;
                ellipse.IsFilled = true;
                ellipse.Position = new Vector2(480, 400);
                ellipse.Draw();

                ellipse.Color    = Color.Green;
                ellipse.IsFilled = false;
                ellipse.Position = new Vector2(800, 400);
                ellipse.Draw();

                _renderer.Render();

                return(true);
            });

            Assert.IsTrue(_form.TestResult == DialogResult.Yes);
        }