Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormBrushEditor"/> class.
 /// </summary>
 /// <param name="fontContent">The current font content interface.</param>
 public FormBrushEditor(GorgonFontContent fontContent)
     : this()
 {
     _currentContent = fontContent;
     _previousIdle   = Gorgon.ApplicationIdleLoopMethod;
     Gorgon.ApplicationIdleLoopMethod = null;
     Gorgon.AllowBackground           = true;            // Enable background rendering because the application will appear to have lost focus when this dialog is present.
     SolidBrush    = new GorgonGlyphSolidBrush();
     GradientBrush = new GorgonGlyphLinearGradientBrush
     {
         StartColor = GorgonColor.Black,
         EndColor   = GorgonColor.White
     };
     PatternBrush = new GorgonGlyphHatchBrush
     {
         ForegroundColor = GorgonColor.Black,
         BackgroundColor = GorgonColor.White,
         HatchStyle      = HatchStyle.BackwardDiagonal
     };
 }
Пример #2
0
        /// <summary>
        /// Function to generate the Gorgon bitmap fonts.
        /// </summary>
        /// <param name="fontFamilies">The list of TrueType font families to use.</param>
        /// <param name="window">The window that contains the loading message.</param>
        private static void GenerateGorgonFonts(IReadOnlyList <Drawing.FontFamily> fontFamilies, FormMain window)
        {
            // Pick a font to use with outlines.
            int fontWithOutlineIndex = GorgonRandom.RandomInt32(1, 5);

            _glowIndex = GorgonRandom.RandomInt32(fontWithOutlineIndex + 1, fontWithOutlineIndex + 5);
            int fontWithGradient = GorgonRandom.RandomInt32(_glowIndex + 1, _glowIndex + 5);
            int fontWithTexture  = GorgonRandom.RandomInt32(fontWithGradient + 1, fontWithGradient + 5).Min(_fontFamilies.Count - 1);

            var pngCodec = new GorgonCodecPng();

            using (IGorgonImage texture = pngCodec.LoadFromFile(Path.Combine(GorgonExample.GetResourcePath(@"Textures\Fonts\").FullName, "Gradient.png")))
            {
                for (int i = 0; i < _fontFamilies.Count; ++i)
                {
                    string fontFamily = _fontFamilies[i];

                    // Use this to determine if the font is avaiable.
                    if (fontFamilies.All(item => !string.Equals(item.Name, fontFamily, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        // Can't locate this one, move on...
                        continue;
                    }

                    bool isExternal =
                        Drawing.FontFamily.Families.All(item => !string.Equals(item.Name, fontFamily, StringComparison.InvariantCultureIgnoreCase));
                    string           fontName;
                    int              outlineSize   = 0;
                    GorgonColor      outlineColor1 = GorgonColor.BlackTransparent;
                    GorgonColor      outlineColor2 = GorgonColor.BlackTransparent;
                    GorgonGlyphBrush brush         = null;

                    if (i == fontWithOutlineIndex)
                    {
                        fontName      = $"{fontFamily} 32px Outlined{(isExternal ? " External TTF" : string.Empty)}";
                        outlineColor1 = GorgonColor.Black;
                        outlineColor2 = GorgonColor.Black;
                        outlineSize   = 3;
                    }
                    else if (i == _glowIndex)
                    {
                        fontName      = $"{fontFamily} 32px Outline as Glow{(isExternal ? " External TTF" : string.Empty)}";
                        outlineColor1 = new GorgonColor(GorgonColor.YellowPure, 1.0f);
                        outlineColor2 = new GorgonColor(GorgonColor.DarkRed, 0.0f);
                        outlineSize   = 16;
                    }
                    else if (i == fontWithGradient)
                    {
                        fontName = $"{fontFamily} 32px Gradient{(isExternal ? " External TTF" : string.Empty)}";
                        brush    = new GorgonGlyphLinearGradientBrush
                        {
                            StartColor = GorgonColor.White,
                            EndColor   = GorgonColor.Black,
                            Angle      = 45.0f
                        };
                    }
                    else if (i == fontWithTexture)
                    {
                        fontName = $"{fontFamily} 32px Textured{(isExternal ? " External TTF" : string.Empty)}";
                        brush    = new GorgonGlyphTextureBrush(texture);
                    }
                    else
                    {
                        fontName = $"{fontFamily} 32px{(isExternal ? " External TTF" : string.Empty)}";
                    }

                    window.UpdateStatus($"Generating Font: {fontFamily}".Ellipses(50));

                    var fontInfo = new GorgonFontInfo(fontFamily,
                                                      30.25f,
                                                      name:
                                                      fontName)
                    {
                        AntiAliasingMode         = FontAntiAliasMode.AntiAlias,
                        OutlineSize              = outlineSize,
                        OutlineColor1            = outlineColor1,
                        OutlineColor2            = outlineColor2,
                        UsePremultipliedTextures = false,
                        Brush = brush
                    };

                    _font.Add(_fontFactory.GetFont(fontInfo));

                    // Texture brushes have to be disposed when we're done with them.
                    var disposableBrush = brush as IDisposable;
                    disposableBrush?.Dispose();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Function to initialize the example application.
        /// </summary>
        private static void Initialize()
        {
            var pathBrush = new GorgonGlyphPathGradientBrush
            {
                SurroundColors =
                {
                    Color.Red,
                    Color.Green,
                    Color.Blue,
                    Color.Yellow
                },
                CenterColor = Color.White,
                Points      =
                {
                    new Vector2(0,   8),
                    new Vector2(8,   0),
                    new Vector2(16,  8),
                    new Vector2(8,  16),
                },
                CenterPoint   = new Vector2(8, 8),
                Interpolation =
                {
                    new GorgonGlyphBrushInterpolator(0,    Color.Purple),
                    new GorgonGlyphBrushInterpolator(0.5f, Color.Cyan),
                    new GorgonGlyphBrushInterpolator(1.0f, Color.Firebrick)
                },
                WrapMode = WrapMode.TileFlipXY
            };

            var linBrush = new GorgonGlyphLinearGradientBrush
            {
                Angle      = 45.0f,
                StartColor = Color.Purple,
                EndColor   = Color.Yellow
            };

            var hatchBrush = new GorgonGlyphHatchBrush
            {
                HatchStyle      = HatchStyle.Percent50,
                ForegroundColor = Color.Purple,
                BackgroundColor = Color.Yellow
            };

            _formMain = new formMain();

            // Create our graphics object(s).
            _graphics = new GorgonGraphics();

            var textBrush = new GorgonGlyphTextureBrush(_graphics.Textures.FromFile <GorgonTexture2D>("Stars",
                                                                                                      GetResourcePath(@"Images\Stars-12.jpg"),
                                                                                                      new GorgonCodecJPEG()))
            {
                TextureRegion = new RectangleF(0.0f, 0.0f, 0.5f, 0.5f),
                WrapMode      = WrapMode.Tile
            };


            _renderer = _graphics.Output.Create2DRenderer(_formMain,
                                                          Settings.Default.ScreenResolution.Width,
                                                          Settings.Default.ScreenResolution.Height,
                                                          BufferFormat.Unknown,
                                                          !Settings.Default.FullScreen);

            Screen activeMonitor = Screen.FromControl(_formMain);

            // Center the window on the screen.
            _formMain.Location = new Point(activeMonitor.WorkingArea.Width / 2 - _formMain.Width / 2, activeMonitor.WorkingArea.Height / 2 - _formMain.Height / 2);

            _specialGlyphTexture = _graphics.Textures.FromFile <GorgonTexture2D>("StyledT", GetResourcePath(@"Fonts\StylizedT.png"),
                                                                                 new GorgonCodecPNG());

            _font = _graphics.Fonts.CreateFont("TestFont",
                                               new GorgonFontSettings
            {
                AntiAliasingMode = FontAntiAliasMode.AntiAlias,
                FontFamilyName   = "Times New Roman",
                FontStyle        = FontStyle.Bold,
                Size             = 24.0f,
                Brush            = textBrush,
                Glyphs           =
                {
                    new GorgonGlyph('T', _specialGlyphTexture, new Rectangle(11, 14, 111, 97), new Point(-3, -8), 97)
                }
            });

            // TODO: This is for testing font capabilities.
            _renderer.Drawing.BlendingMode = BlendingMode.Modulate;

            _font.Save(@"d:\unpak\fontTest.gorFont");

            _font.Dispose();

            textBrush.Texture.Dispose();

            _font = _graphics.Fonts.FromFile("TestFont", @"d:\unpak\fontTest.gorFont");
        }
Пример #4
0
        /// <summary>
        /// Handles the Click event of the buttonOK 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 buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                switch (BrushType)
                {
                case GlyphBrushType.Solid:
                    SolidBrush = new GorgonGlyphSolidBrush
                    {
                        Color = colorSolidBrush.SelectedColor
                    };
                    break;

                case GlyphBrushType.Texture:
                    GorgonTexture2D newTexture = panelTextureEditor.Texture.Graphics.Textures.CreateTexture(panelTextureEditor.Texture.Name,
                                                                                                            panelTextureEditor.Texture.Settings);

                    newTexture.Copy(panelTextureEditor.Texture);

                    TextureBrush = new GorgonGlyphTextureBrush(newTexture)
                    {
                        WrapMode      = panelTextureEditor.WrapMode,
                        TextureRegion = panelTextureEditor.TextureRegion
                    };

                    panelTextureEditor.Texture = null;
                    break;

                case GlyphBrushType.Hatched:
                    PatternBrush = new GorgonGlyphHatchBrush
                    {
                        ForegroundColor = panelHatchEditor.HatchForegroundColor,
                        BackgroundColor = panelHatchEditor.HatchBackgroundColor,
                        HatchStyle      = panelHatchEditor.HatchStyle
                    };
                    break;

                case GlyphBrushType.LinearGradient:
                    GradientBrush = new GorgonGlyphLinearGradientBrush
                    {
                        Angle           = panelGradEditor.Angle,
                        ScaleAngle      = panelGradEditor.ScaleAngle,
                        GammaCorrection = panelGradEditor.UseGammaCorrection
                    };

                    IEnumerable <GorgonGlyphBrushInterpolator> interpolators = panelGradEditor.GetInterpolators();

                    GradientBrush.Interpolation.Clear();

                    foreach (GorgonGlyphBrushInterpolator interpolator in interpolators)
                    {
                        GradientBrush.Interpolation.Add(interpolator);
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(this, ex);
                DialogResult = DialogResult.None;
            }
        }