/// <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 }; }
/// <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; } }
/// <summary> /// Paints a representation of the value of an object using the specified <see cref="T:System.Drawing.Design.PaintValueEventArgs" />. /// </summary> /// <param name="e">A <see cref="T:System.Drawing.Design.PaintValueEventArgs" /> that indicates what to paint and where to paint it.</param> public override void PaintValue(PaintValueEventArgs e) { var sourceBrush = e.Value as GorgonGlyphBrush; Brush brush = null; try { // If we haven't assigned a brush, then fall back to a solid brush. if (sourceBrush == null) { sourceBrush = new GorgonGlyphSolidBrush(); } switch (sourceBrush.BrushType) { case GlyphBrushType.Hatched: var hatchBrush = (GorgonGlyphHatchBrush)sourceBrush; brush = new HatchBrush(hatchBrush.HatchStyle, hatchBrush.ForegroundColor, hatchBrush.BackgroundColor); e.Graphics.FillRectangle(brush, e.Bounds); break; case GlyphBrushType.LinearGradient: brush = CreateLinearGradBrush(e.Bounds, sourceBrush); e.Graphics.FillRectangle(brush, e.Bounds); break; case GlyphBrushType.Texture: var textureBrush = (GorgonGlyphTextureBrush)sourceBrush; // If we can't find the image, then display the broken image icon. if (textureBrush.Texture == null) { e.Graphics.DrawImage(Resources.image_missing_16x16, e.Bounds, new Rectangle(0, 0, Resources.image_missing_16x16.Width, Resources.image_missing_16x16.Height), GraphicsUnit.Pixel); return; } // Convert to a GDI image so the property pane can display the texture. Image gdiImage = textureBrush.Texture.ToGDIImage()[0]; e.Graphics.DrawImage(gdiImage, e.Bounds, textureBrush.Texture.ToPixel(textureBrush.TextureRegion), GraphicsUnit.Pixel); gdiImage.Dispose(); break; case GlyphBrushType.Solid: var solidBrush = (GorgonGlyphSolidBrush)sourceBrush; brush = new SolidBrush(solidBrush.Color); e.Graphics.FillRectangle(brush, e.Bounds); break; default: return; } } finally { if (brush != null) { brush.Dispose(); } } }