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(); } } }
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(); } } }
/// <summary> /// Function to compile the shader. /// </summary> /// <param name="includeDebugInfo">TRUE to include debug information, FALSE to exclude it.</param> /// <returns>The compiled shader byte code.</returns> private Shaders.ShaderBytecode CompileFromSource(bool includeDebugInfo) { var flags = Shaders.ShaderFlags.OptimizationLevel3; try { string parsedCode = ProcessSource(SourceCode); IsDebug = includeDebugInfo; if (IsDebug) { flags = Shaders.ShaderFlags.Debug; } if (Graphics.VideoDevice.SupportedFeatureLevel < DeviceFeatureLevel.SM5) { flags |= Shaders.ShaderFlags.EnableBackwardsCompatibility; } return(Shaders.ShaderBytecode.Compile(parsedCode, EntryPoint, GetD3DVersion(), flags, Shaders.EffectFlags.None, _shaderMacros, null)); } catch (CompilationException cex) { Errors = cex.Message; throw GorgonException.Catch(cex); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.SizeChanged" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); try { if (_bitmap == null) { return; } _formGraphics.Dispose(); _graphics.Dispose(); _bitmap.Dispose(); _bitmap = null; _graphics = null; _formGraphics = panelGraphics.CreateGraphics(); _bitmap = new Bitmap(panelGraphics.ClientSize.Width, panelGraphics.ClientSize.Height, _formGraphics); _graphics = Graphics.FromImage(_bitmap); _graphics.Clear(Color.Black); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } }
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)); } }
/// <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 { _writePath = Path.GetDirectoryName(Gorgon.Log.LogPath) + @"\Examples\FileSystem.Writing\"; // Create our virtual file system. _fileSystem = new GorgonFileSystem(); LoadText(); labelFileSystem.Text = string.Format("{0} mounted as '/'.", Program.GetResourcePath(@"FolderSystem\").Ellipses(100, true)); labelWriteLocation.Text = string.Format("{0} mounted as '/'", _writePath.Ellipses(100, true)); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); Application.Exit(); } finally { itemLoadChanged.Enabled = !string.Equals(textDisplay.Text, _originalText, StringComparison.CurrentCulture); UpdateInfo(); } }
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(); } } }
/// <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 } }
/// <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 } }
/// <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 { // Picture box. _picture = new PictureBox { Name = "pictureImage" }; // Text display. _textDisplay = new TextBox { Name = "textDisplay" }; _textFont = new Font("Consolas", 10.0f, FontStyle.Regular, GraphicsUnit.Point); _textDisplay.Font = _textFont; _instructions = new Label { Name = "labelInstructions", Text = "Double click on a file node in the tree to display it.", AutoSize = false, TextAlign = ContentAlignment.MiddleCenter, Dock = DockStyle.Fill, Font = Font }; // Add the instructions. splitFileSystem.Panel2.Controls.Add(_instructions); // Create the file system. _fileSystem = new GorgonFileSystem(); // Get the zip file provider. LoadZipFileSystemProvider(); // Mount the physical file system directory. _fileSystem.Mount(Program.GetResourcePath(@"VFSRoot\")); // Mount the zip file into a sub directory. _fileSystem.Mount(Program.GetResourcePath("VFSRoot.zip"), "/ZipFile"); // Fill the root of the tree. FillTree(null); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); Application.Exit(); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new formMain()); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex)); } }
/// <summary> /// Handles the BeforeCollapse event of the treeFileSystem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="TreeViewCancelEventArgs" /> instance containing the event data.</param> private void treeFileSystem_BeforeCollapse(object sender, TreeViewCancelEventArgs e) { var directory = e.Node.Tag as GorgonFileSystemDirectory; try { // Do not expand or collapse if (directory == _fileSystem.RootDirectory) { e.Cancel = true; } } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } }
/// <summary> /// Handles the Click event of the itemLoadChanged 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 itemLoadChanged_Click(object sender, EventArgs e) { try { CommandEnable(false); LoadText(); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } finally { CommandEnable(true); UpdateInfo(); } }
/// <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 { _formGraphics = panelGraphics.CreateGraphics(); _bitmap = new Bitmap(panelGraphics.ClientSize.Width, panelGraphics.ClientSize.Height, _formGraphics); _graphics = Graphics.FromImage(_bitmap); _graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; _graphics.Clear(Color.Black); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } }
/// <summary> /// Handles the BeforeExpand event of the treeFileSystem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="TreeViewCancelEventArgs" /> instance containing the event data.</param> private void treeFileSystem_BeforeExpand(object sender, TreeViewCancelEventArgs e) { var directory = e.Node.Tag as GorgonFileSystemDirectory; try { if (directory == null) { e.Cancel = true; return; } FillTree(directory); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } }
/// <summary> /// Function to handle an exception with this instance of the logger. /// </summary> /// <param name="ex">Exception to catch.</param> /// <param name="handler">Exception handler to call.</param> public static Exception CatchException(Exception ex, GorgonExceptionHandler handler = null) { if ((_logFile == null) || (_logFile.IsClosed)) { return(ex); } GorgonLogFile oldLogger = GorgonException.Log; try { GorgonException.Log = _logFile; return(GorgonException.Catch(ex, handler)); } finally { GorgonException.Log = oldLogger; } }
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(); } }
/// <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; } }
private string _originalText = string.Empty; // Original text. #endregion #region Properties. /// <summary> /// Handles the Click event of the buttonSave 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 buttonSave_Click(object sender, EventArgs e) { try { CommandEnable(false); buttonSave.Enabled = false; textDisplay.Enabled = false; byte[] data = Encoding.UTF8.GetBytes(textDisplay.Text); _fileSystem.WriteFile("/SomeText.txt", data); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } finally { CommandEnable(true); itemLoadChanged.Enabled = !string.Equals(textDisplay.Text, _originalText, StringComparison.CurrentCulture); UpdateInfo(); } }
/// <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 } }
/// <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 } }
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)); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data.</param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); try { if (_picture != null) { _picture.Dispose(); _picture = null; } if (_image != null) { _image.Dispose(); _image = null; } if (_textDisplay != null) { _textDisplay.Dispose(); _textDisplay = null; } if (_textFont == null) { return; } _textFont.Dispose(); _textFont = null; } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); } }
static void Main() { try { Console.Title = "Example #4 - Gorgon Plug-Ins."; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("This is an example to show how to create and use custom plug-ins."); Console.WriteLine("The plug-in interface in Gorgon is quite flexible and gives the developer"); Console.WriteLine("the ability to allow extensions to their own applications.\n"); Console.ResetColor(); var plugInFiles = GetPlugInAssemblies().ToArray(); Console.WriteLine("{0} plug-in assemblies found.", plugInFiles.Count()); if (plugInFiles.Length == 0) { return; } // Load the plug-ins into Gorgon (only take the first 9). IList <TextColorWriter> writers = new List <TextColorWriter>(); // Our text writer plug-in interfaces. foreach (var path in plugInFiles) { Gorgon.PlugIns.LoadPlugInAssembly(path); } // Get our plug-ins. // But limit to 9 entries. var plugIns = (from plugIn in Gorgon.PlugIns let textPlugIn = plugIn as TextColorPlugIn where textPlugIn != null select textPlugIn).Take(9).ToArray(); // Display a list of the available plug-ins. Console.WriteLine("\n{0} Plug-ins loaded:\n", plugIns.Length); for (int i = 0; i < plugIns.Length; i++) { // Here's where we make use of our description. Console.WriteLine("{0}. {1} ({2})", i + 1, plugIns[i].Description, plugIns[i].GetType().FullName); // Create the text writer interface and add it to the list. writers.Add(plugIns.ElementAt(i).CreateWriter()); } Console.Write("0. Quit\n\nSelect a plug-in: "); // Loop until we quit. while (true) { if (!Console.KeyAvailable) { continue; } Console.ResetColor(); // Remember our cursor coordinates. int cursorX = Console.CursorLeft; // Cursor position. int cursorY = Console.CursorTop; var keyValue = Console.ReadKey(false); if (char.IsNumber(keyValue.KeyChar)) { if (keyValue.KeyChar == '0') { break; } // Move to the next line and clear the previous line of text. Console.WriteLine(); Console.Write(new string(' ', Console.BufferWidth - 1)); Console.CursorLeft = 0; // Call our text color writer to print the text in the plug-in color. int writerIndex = keyValue.KeyChar - '0'; if ((writerIndex >= 0) && (writerIndex <= 3)) { writers[writerIndex - 1].WriteString(string.Format("You pressed #{0}.", writerIndex)); } } Console.CursorTop = cursorY; Console.CursorLeft = cursorX; } } 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, () => { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", ex.Message, ex.StackTrace); }); Console.ResetColor(); } }
private Label _instructions; // Instructions label. #endregion #region Methods. /// <summary> /// Handles the NodeMouseDoubleClick event of the treeFileSystem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="TreeNodeMouseClickEventArgs" /> instance containing the event data.</param> private void treeFileSystem_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (splitFileSystem.Panel2.Controls.Count > 0) { splitFileSystem.Panel2.Controls.RemoveAt(0); } try { if ((e.Node == null) || (!(e.Node.Tag is GorgonFileSystemFileEntry))) { splitFileSystem.Panel2.Controls.Add(_instructions); return; } _picture.Image = null; _textDisplay.Text = string.Empty; var file = (GorgonFileSystemFileEntry)e.Node.Tag; // Here we load the image from the file system. // Note that we don't care if it's from the zip file // or the folder. It's all the same to us. using (Stream fileStream = file.OpenStream(false)) { // If it's a picture, then load it. switch (file.Extension.ToLower()) { case ".jpg": case ".jpeg": case ".bmp": case ".png": if (_image != null) { _image.Dispose(); _image = null; } _image = Image.FromStream(fileStream); _picture.Image = _image; _picture.SizeMode = PictureBoxSizeMode.Zoom; // Add to control. splitFileSystem.Panel2.Controls.Add(_picture); _picture.Dock = DockStyle.Fill; break; default: // Get data in the file stream. var textData = new byte[fileStream.Length]; fileStream.Read(textData, 0, textData.Length); // Convert to a string. _textDisplay.Text = Encoding.UTF8.GetString(textData); _textDisplay.Multiline = true; _textDisplay.ReadOnly = true; _textDisplay.ScrollBars = ScrollBars.Both; _textDisplay.Dock = DockStyle.Fill; splitFileSystem.Panel2.Controls.Add(_textDisplay); break; } } } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); splitFileSystem.Panel2.Controls.Add(_instructions); } }
/// <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(); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { try { // Create a new file system. // The file system must be created first and given access to the various // data sources via the provider plug-ins. // For example, this will allow us to create a file system that can read // a RAR file, while another file system would only cater to Zip files. // By default, every file system comes with a folder file system provider // that can mount a directory from the hard drive as a VFS root. _fileSystem = new GorgonFileSystem(); Console.WriteLine("Gorgon is capable of mounting virtual file systems for file access. A virtual"); Console.WriteLine("filesystem root can be a folder on a harddrive, a zip file, or any data store"); Console.WriteLine("(assuming there's a provider for it).\n"); Console.WriteLine("In Gorgon, the types of data that can be mounted as a virtual file system is"); Console.WriteLine("managed by plug-ins called providers. By default, the file system has a folder"); Console.WriteLine("provider. This allows a folder to be mounted as the root of a virtual file\nsystem.\n"); Console.WriteLine("This example will show how to load extra providers into a file system.\n"); Console.ForegroundColor = ConsoleColor.White; // Get our file system providers. Console.WriteLine("Found {0} external file system plug-ins.\n", LoadFileSystemProviders()); // Loop through each provider and print some info. for (int i = 0; i < _fileSystem.Providers.Count; i++) { var provider = _fileSystem.Providers[i]; // Print some info about the file system provider. Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("{0}. {1}", (i + 1), provider.Name); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(" Description: {0}", provider.Description); // Gather the preferred extensions. // File system providers that use a file (like a Zip file) as its root // have a list of file extensions that are preferred. For example, the // Zip provider, expects to find *.zip files. These are merely here // for the convenience of the developer and are formatted like a common // dialog file mask so they can be easily dropped into that control. // In this case, we're going to just strip out the relevant part and // concatenate each preferred extension description into a single string. // // Note that a provider may have multiple preferred extensions. var extensionList = (from preferred in provider.PreferredExtensions select string.Format("*.{0}", preferred.Extension)).ToArray(); if (extensionList.Length > 0) { Console.WriteLine(" Preferred Extensions: {0}", string.Join(", ", extensionList)); } } Console.ResetColor(); Console.WriteLine("\nPress any key to close."); Console.ReadKey(); } 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, () => { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", ex.Message, ex.StackTrace); }); Console.ResetColor(); #if DEBUG Console.ReadKey(); #endif } }
/// <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(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Initialize(); Gorgon.Run(_form, Idle); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex)); } finally { if (_materialBuffer != null) { _materialBuffer.Dispose(); } if (_normalEarfMap != null) { _normalEarfMap.Dispose(); } if (_normalMap != null) { _normalMap.Dispose(); } if (_specEarfMap != null) { _specEarfMap.Dispose(); } if (_specMap != null) { _specMap.Dispose(); } if (_cloudMap != null) { _cloudMap.Dispose(); } if (_clouds != null) { _clouds.Dispose(); } if (_sphere != null) { _sphere.Dispose(); } if (_light != null) { _light.Dispose(); } if (_cube != null) { _cube.Dispose(); } if (_plane != null) { _plane.Dispose(); } if (_triangle != null) { _triangle.Dispose(); } if (_wvp != null) { _wvp.Dispose(); } if (_renderer2D != null) { _renderer2D.Dispose(); } if (_swapChain != null) { _swapChain.Dispose(); } if (_graphics != null) { _graphics.Dispose(); } } }
/// <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(); } }