Example #1
0
        /// <summary>
        /// Function to load the text into the file system.
        /// </summary>
        private void LoadText()
        {
            _fileSystem.Clear();
            _fileSystem.Mount(Program.GetResourcePath(@"FolderSystem\"));

            // Load the original before we mount the write directory.
            byte[] textData = _fileSystem.ReadFile("/SomeText.txt");
            _originalText = Encoding.UTF8.GetString(textData);

            // Set the write location to the users app data folder.
            _fileSystem.WriteLocation = _writePath;

            // Load the modified version.
            textData = _fileSystem.ReadFile("/SomeText.txt");
            string modifiedText = Encoding.UTF8.GetString(textData);

            textDisplay.Text = string.Equals(modifiedText, _originalText) ? _originalText : modifiedText;
        }
Example #2
0
        /// <summary>
        /// Function called to initialize the application.
        /// </summary>
        private void Initialize()
        {
            // Resize and center the screen.
            var screen = Screen.FromHandle(Handle);

            ClientSize = Settings.Default.Resolution;
            Location   = new Point(screen.Bounds.Left + screen.WorkingArea.Width / 2 - ClientSize.Width / 2, screen.Bounds.Top + screen.WorkingArea.Height / 2 - ClientSize.Height / 2);

            // Initialize our graphics.
            _graphics = new GorgonGraphics();
            _2D       = _graphics.Output.Create2DRenderer(this, ClientSize.Width, ClientSize.Height, BufferFormat.R8G8B8A8_UIntNormal, Settings.Default.IsWindowed);

            // Show the logo because I'm insecure.
            _2D.IsLogoVisible = true;

            // Create fonts.
            _textFont = _graphics.Fonts.CreateFont("GiGi_24pt", new GorgonFontSettings
            {
                FontFamilyName   = "GiGi",
                AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                Size             = 24.0f,
                FontHeightMode   = FontHeightMode.Points,
                TextureSize      = new Size(512, 256)
            });

            // Use the form font for this one.
            _helpFont = _graphics.Fonts.CreateFont("FormFont", new GorgonFontSettings
            {
                FontFamilyName   = Font.FontFamily.Name,
                FontStyle        = FontStyle.Bold,
                AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                Size             = Font.Size,
                FontHeightMode   = FontHeightMode.Points
            });

            // Create our file system and mount the resources.
            _fileSystem = new GorgonFileSystem();
            _fileSystem.Mount(Program.GetResourcePath(@"FolderSystem\"));

            // Get the sprite image.
            _spriteImage = _graphics.Textures.FromMemory <GorgonTexture2D>("0_HardVacuum", _fileSystem.ReadFile("/Images/0_HardVacuum.png"), new GorgonCodecPNG());

            // Get the sprites.
            // The sprites in the file system are from version 1.0 of Gorgon.
            // This version is backwards compatible and can load any version
            // of the sprites produced by older versions of Gorgon.
            _sprites    = new GorgonSprite[3];
            _sprites[0] = _2D.Renderables.FromMemory <GorgonSprite>("Base", _fileSystem.ReadFile("/Sprites/base.gorSprite"));
            _sprites[1] = _2D.Renderables.FromMemory <GorgonSprite>("Mother", _fileSystem.ReadFile("/Sprites/Mother.gorSprite"));
            _sprites[2] = _2D.Renderables.FromMemory <GorgonSprite>("Mother2c", _fileSystem.ReadFile("/Sprites/Mother2c.gorSprite"));

            // Get poetry.
            _textPosition    = new Vector2(0, ClientSize.Height + _textFont.LineHeight);
            _poetry          = _2D.Renderables.CreateText("Poetry", _textFont, Encoding.UTF8.GetString(_fileSystem.ReadFile("/SomeText.txt")), Color.Black);
            _poetry.Position = _textPosition;

            // Set up help text.
            _helpText          = _2D.Renderables.CreateText("Help", _helpFont, "F1 - Show/hide this help text.\nS - Show frame statistics.\nESC - Exit.", Color.Blue);
            _helpText.Position = new Vector2(3, 3);

            // Set the initial blur value.
            // We set a small render target for the blur, this will help
            // speed up the effect.
            _2D.Effects.GaussianBlur.BlurAmount            = 13.0f;
            _2D.Effects.GaussianBlur.BlurRenderTargetsSize = new Size(128, 128);
            _2D.Effects.GaussianBlur.RenderScene           = pass =>
            {
                // Draw the sprite at the upper left corner instead of
                // centered.  Otherwise it'll be centered in the blur
                // render target and will be clipped.
                _sprites[2].Anchor   = Vector2.Zero;
                _sprites[2].Position = Vector2.Zero;
                // Scale to the size of the blur target.
                _sprites[2].Scale = new Vector2(1.0f, _2D.Effects.GaussianBlur.BlurRenderTargetsSize.Height / _sprites[2].Size.Y);
                // Adjust the texture size to avoid bleed when blurring.
                // Bleed means that other portions of the texture get pulled
                // in to the texture because of bi-linear filtering (and the
                // blur operates in a similar manner, and therefore unwanted
                // pixels get pulled in as well).
                // See http://tape-worm.net/?page_id=277 for more info.
                _sprites[2].TextureSize = new Vector2(125.0f / _spriteImage.Settings.Width, _sprites[2].TextureSize.Y);

                _sprites[2].Draw();

                // Reset.
                _sprites[2].TextureSize = new Vector2(128.0f / _spriteImage.Settings.Width, _sprites[2].TextureSize.Y);
            };

            Gorgon.ApplicationIdleLoopMethod = Idle;
        }