/src/ToolConfigStrip.cs
C# | 2979 lines | 2335 code | 419 blank | 225 comment | 220 complexity | b71bda30139507e48234f6a58848dd64 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /////////////////////////////////////////////////////////////////////////////////
- // Paint.NET //
- // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
- // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
- // See src/Resources/Files/License.txt for full licensing and attribution //
- // details. //
- // . //
- /////////////////////////////////////////////////////////////////////////////////
-
- using System.Linq;
- using PaintDotNet.Base;
- using PaintDotNet.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Threading;
- using System.Windows.Forms;
-
- namespace PaintDotNet
- {
- // TODO: for 4.0, refactor into smaller ToolConfigStrip "Sections"
- // better yet, use IndirectUI
- internal class ToolConfigStrip
- : ToolStripEx,
- IBrushConfig,
- IShapeTypeConfig,
- IPenConfig,
- IAntiAliasingConfig,
- IAlphaBlendingConfig,
- ITextConfig,
- IToleranceConfig,
- IColorPickerConfig,
- IGradientConfig,
- IResamplingConfig,
- ISelectionCombineModeConfig,
- IFloodModeConfig,
- ISelectionDrawModeConfig
- {
- private ToolBarConfigItems _toolBarConfigItems = ToolBarConfigItems.None;
-
- private readonly EnumLocalizer _hatchStyleNames = EnumLocalizer.Create(typeof(HatchStyle));
- private readonly string _solidBrushText;
- private readonly ImageResource _shapeOutlineImage = PdnResources.GetImageResource("Icons.ShapeOutlineIcon.png");
- private readonly ImageResource _shapeInteriorImage = PdnResources.GetImageResource("Icons.ShapeInteriorIcon.png");
- private readonly ImageResource _shapeBothImage = PdnResources.GetImageResource("Icons.ShapeBothIcon.png");
-
- private ToolStripSeparator _brushSeparator;
- private ToolStripLabel _brushStyleLabel;
- private ToolStripComboBox _brushStyleComboBox;
-
- private ToolStripSeparator _shapeSeparator;
- private ToolStripSplitButton _shapeButton;
-
- private ToolStripSeparator _penSeparator;
- private ToolStripLabel _penSizeLabel;
- private ToolStripButton _penSizeDecButton;
- private ToolStripComboBox _penSizeComboBox;
- private ToolStripButton _penSizeIncButton;
- private ToolStripLabel _penStyleLabel;
- private ToolStripSplitButton _penStartCapSplitButton; // Tag property is used to store chosen LineCap value
- private ToolStripSplitButton _penDashStyleSplitButton; // Tag property is used to store chosen DashStyle value
- private ToolStripSplitButton _penEndCapSplitButton; // Tag property is used to store chosen LineCap value
-
- private readonly EnumLocalizer _lineCapLocalizer = EnumLocalizer.Create(typeof(LineCap2));
- private readonly EnumLocalizer _dashStyleLocalizer = EnumLocalizer.Create(typeof(DashStyle));
-
- private ToolStripSeparator _blendingSeparator;
- private ToolStripSplitButton _alphaBlendingSplitButton;
- private bool _alphaBlendingEnabled = true;
- private readonly ImageResource _alphaBlendingEnabledImage;
- private readonly ImageResource _alphaBlendingOverwriteImage;
-
- private ToolStripSplitButton _antiAliasingSplitButton;
- private bool _antiAliasingEnabled = true;
- private readonly ImageResource _antiAliasingEnabledImage;
- private readonly ImageResource _antiAliasingDisabledImage;
-
- private readonly EnumLocalizer _resamplingAlgorithmNames = EnumLocalizer.Create(typeof(ResamplingAlgorithm));
- private ToolStripSeparator _resamplingSeparator;
- private ToolStripLabel _resamplingLabel;
- private ToolStripComboBox _resamplingComboBox;
-
- private readonly EnumLocalizer _colorPickerBehaviorNames = EnumLocalizer.Create(typeof(ColorPickerClickBehavior));
- private ToolStripSeparator _colorPickerSeparator;
- private ToolStripLabel _colorPickerLabel;
- private ToolStripComboBox _colorPickerComboBox;
-
- private ToolStripSeparator _toleranceSeparator;
- private ToolStripLabel _toleranceLabel;
- private ToolStripControlHost _toleranceSliderStrip;
- private ToleranceSliderControl _toleranceSlider;
-
- private readonly LineCap2[] _lineCaps =
- new[]
- {
- LineCap2.Flat,
- LineCap2.Arrow,
- LineCap2.ArrowFilled,
- LineCap2.Rounded
- };
-
- private readonly DashStyle[] _dashStyles =
- new[]
- {
- DashStyle.Solid,
- DashStyle.Dash,
- DashStyle.DashDot,
- DashStyle.DashDotDot,
- DashStyle.Dot
- };
-
- private const float MinPenSize = 1.0f;
- private const float MaxPenSize = 500.0f;
- private readonly int[] _brushSizes =
- new[]
- {
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 20, 25, 30,
- 35, 40, 45, 50, 55, 60, 65, 70,
- 75, 80, 85, 90, 95, 100, 125,
- 150, 175, 200, 225, 250, 275, 300,
- 325, 350, 375, 400, 425, 450, 475,
- 500
- };
- private ShapeDrawType _shapeDrawType;
-
- private readonly EnumLocalizer _gradientTypeNames = EnumLocalizer.Create(typeof(GradientType));
- private GradientInfo _gradientInfo = new GradientInfo(GradientType.LinearClamped, false);
- private ToolStripSeparator _gradientSeparator1;
- private ToolStripButton _gradientLinearClampedButton;
- private ToolStripButton _gradientLinearReflectedButton;
- private ToolStripButton _gradientLinearDiamondButton;
- private ToolStripButton _gradientRadialButton;
- private ToolStripButton _gradientConicalButton;
- private ToolStripSeparator _gradientSeparator2;
- private ToolStripSplitButton _gradientChannelsSplitButton;
- private readonly ImageResource _gradientAllColorChannelsImage;
- private readonly ImageResource _gradientAlphaChannelOnlyImage;
-
- private readonly EnumLocalizer _fontSmoothingLocalizer = EnumLocalizer.Create(typeof(FontSmoothing));
- private const int MaxFontSize = 2000;
- private const int MinFontSize = 1;
- private const int InitialFontSize = 12;
-
- private readonly FontFamily _arialFontFamily;
- private FontStyle _fontStyle;
- private TextAlignment _alignment;
- private float _oldSizeValue;
- private readonly Brush _highlightBrush;
- private readonly Brush _highlightTextBrush;
- private readonly Brush _windowBrush;
- private readonly Brush _windowTextBrush;
- private readonly Font _arialFontBase;
- private const string ArialName = "Arial";
-
- private static readonly ManualResetEvent StaticFontNamesPopulatedEvent = new ManualResetEvent(false);
- private static List<string> _staticFontNames;
- private bool _fontsComboBoxPopulated;
-
- private ToolStripSeparator _fontSeparator;
- private ToolStripLabel _fontLabel;
- private ToolStripComboBox _fontFamilyComboBox;
- private ToolStripComboBox _fontSizeComboBox;
- private ToolStripComboBox _fontSmoothingComboBox;
- private ToolStripSeparator _fontStyleSeparator;
- private ToolStripButton _fontBoldButton;
- private ToolStripButton _fontItalicsButton;
- private ToolStripButton _fontUnderlineButton;
- private ToolStripSeparator _fontAlignSeparator;
- private ToolStripButton _fontAlignLeftButton;
- private ToolStripButton _fontAlignCenterButton;
- private ToolStripButton _fontAlignRightButton;
-
- private readonly int[] _defaultFontSizes =
- new[]
- {
- 8, 9, 10, 11, 12, 14, 16, 18, 20,
- 22, 24, 26, 28, 36, 48, 72, 84, 96,
- 108, 144, 192, 216, 288
- };
-
- private ToolStripSeparator _selectionCombineModeSeparator;
- private ToolStripLabel _selectionCombineModeLabel;
- private ToolStripSplitButton _selectionCombineModeSplitButton;
-
- private ToolStripSeparator _floodModeSeparator;
- private ToolStripLabel _floodModeLabel;
- private ToolStripSplitButton _floodModeSplitButton;
-
- private SelectionDrawModeInfo _selectionDrawModeInfo;
- private ToolStripSeparator _selectionDrawModeSeparator;
- private ToolStripLabel _selectionDrawModeModeLabel;
- private ToolStripSplitButton _selectionDrawModeSplitButton;
- private ToolStripLabel _selectionDrawModeWidthLabel;
- private ToolStripTextBox _selectionDrawModeWidthTextBox;
- private ToolStripButton _selectionDrawModeSwapButton;
- private ToolStripLabel _selectionDrawModeHeightLabel;
- private ToolStripTextBox _selectionDrawModeHeightTextBox;
- private UnitsComboBoxStrip _selectionDrawModeUnits;
-
- public event EventHandler SelectionDrawModeUnitsChanging;
- protected void OnSelectionDrawModeUnitsChanging()
- {
- if (SelectionDrawModeUnitsChanging != null)
- {
- SelectionDrawModeUnitsChanging(this, EventArgs.Empty);
- }
- }
-
- public event EventHandler SelectionDrawModeUnitsChanged;
- protected void OnSelectionDrawModeUnitsChanged()
- {
- if (SelectionDrawModeUnitsChanged != null)
- {
- SelectionDrawModeUnitsChanged(this, EventArgs.Empty);
- }
- }
-
- public void LoadFromAppEnvironment(AppEnvironment appEnvironment)
- {
- AlphaBlending = appEnvironment.AlphaBlending;
- AntiAliasing = appEnvironment.AntiAliasing;
- BrushInfo = appEnvironment.BrushInfo;
- ColorPickerClickBehavior = appEnvironment.ColorPickerClickBehavior;
- GradientInfo = appEnvironment.GradientInfo;
- PenInfo = appEnvironment.PenInfo;
- ResamplingAlgorithm = appEnvironment.ResamplingAlgorithm;
- ShapeDrawType = appEnvironment.ShapeDrawType;
- FontInfo = appEnvironment.FontInfo;
- FontSmoothing = appEnvironment.FontSmoothing;
- FontAlignment = appEnvironment.TextAlignment;
- Tolerance = appEnvironment.Tolerance;
- SelectionCombineMode = appEnvironment.SelectionCombineMode;
- FloodMode = appEnvironment.FloodMode;
- SelectionDrawModeInfo = appEnvironment.SelectionDrawModeInfo;
- }
-
- public event EventHandler BrushInfoChanged;
- protected virtual void OnBrushChanged()
- {
- if (BrushInfoChanged != null)
- {
- BrushInfoChanged(this, EventArgs.Empty);
- }
- }
-
- public BrushInfo BrushInfo
- {
- get
- {
- if (_brushStyleComboBox.SelectedItem.ToString() == _solidBrushText)
- {
- return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
- }
-
- if (_brushStyleComboBox.SelectedIndex == -1)
- {
- return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
- }
- return new BrushInfo(
- BrushType.Hatch,
- (HatchStyle)_hatchStyleNames.LocalizedNameToEnumValue(_brushStyleComboBox.SelectedItem.ToString()));
- }
-
- set {
- _brushStyleComboBox.SelectedItem = value.BrushType == BrushType.Solid ? _solidBrushText : _hatchStyleNames.EnumValueToLocalizedName(value.HatchStyle);
- }
- }
-
- public event EventHandler GradientInfoChanged;
-
- protected virtual void OnGradientInfoChanged()
- {
- if (GradientInfoChanged != null)
- {
- GradientInfoChanged(this, EventArgs.Empty);
- }
- }
-
- public void PerformGradientInfoChanged()
- {
- OnGradientInfoChanged();
- }
-
- public GradientInfo GradientInfo
- {
- get
- {
- return _gradientInfo;
- }
-
- set
- {
- if (value == null)
- {
- throw new ArgumentNullException();
- }
-
- _gradientInfo = value;
- OnGradientInfoChanged();
- SyncGradientInfo();
- }
- }
-
- private void SyncGradientInfo()
- {
- _gradientConicalButton.Checked = false;
- _gradientRadialButton.Checked = false;
- _gradientLinearClampedButton.Checked = false;
- _gradientLinearReflectedButton.Checked = false;
- _gradientLinearDiamondButton.Checked = false;
-
- switch (_gradientInfo.GradientType)
- {
- case GradientType.Conical:
- _gradientConicalButton.Checked = true;
- break;
-
- case GradientType.LinearClamped:
- _gradientLinearClampedButton.Checked = true;
- break;
-
- case GradientType.LinearReflected:
- _gradientLinearReflectedButton.Checked = true;
- break;
-
- case GradientType.LinearDiamond:
- _gradientLinearDiamondButton.Checked = true;
- break;
-
- case GradientType.Radial:
- _gradientRadialButton.Checked = true;
- break;
-
- default:
- throw new InvalidEnumArgumentException();
- }
-
- _gradientChannelsSplitButton.Image = _gradientInfo.AlphaOnly ? _gradientAlphaChannelOnlyImage.Reference : _gradientAllColorChannelsImage.Reference;
- }
-
- private void ShapeButtonDropDownOpening(object sender, EventArgs e)
- {
- var outlineMI = new ToolStripMenuItem
- {
- Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.OutlineButton.ToolTipText"),
- Image = _shapeOutlineImage.Reference,
- Tag = ShapeDrawType.Outline
- };
- outlineMI.Click += ShapeMIClick;
-
- var interiorMI = new ToolStripMenuItem
- {
- Text =
- PdnResources.GetString("ShapeDrawTypeConfigWidget.InteriorButton.ToolTipText"),
- Image = _shapeInteriorImage.Reference,
- Tag = ShapeDrawType.Interior
- };
- interiorMI.Click += ShapeMIClick;
-
- var bothMI = new ToolStripMenuItem
- {
- Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.BothButton.ToolTipText"),
- Image = _shapeBothImage.Reference,
- Tag = ShapeDrawType.Both
- };
- bothMI.Click += ShapeMIClick;
-
- switch (_shapeDrawType)
- {
- case ShapeDrawType.Outline:
- outlineMI.Checked = true;
- break;
-
- case ShapeDrawType.Interior:
- interiorMI.Checked = true;
- break;
-
- case ShapeDrawType.Both:
- bothMI.Checked = true;
- break;
-
- default:
- throw new InvalidEnumArgumentException();
- }
-
- _shapeButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- outlineMI,
- interiorMI,
- bothMI
- });
- }
-
- private void ShapeMIClick(object sender, EventArgs e)
- {
- var sdt = (ShapeDrawType)((ToolStripMenuItem)sender).Tag;
- Tracing.LogFeature("ToolConfigStrip(" + sdt + ")");
- ShapeDrawType = sdt;
- }
-
- public ToolConfigStrip()
- {
- SuspendLayout();
- InitializeComponent();
-
- _solidBrushText = PdnResources.GetString("BrushConfigWidget.SolidBrush.Text"); // "Solid Brush"
- _brushStyleComboBox.Items.Add(_solidBrushText);
- string[] styleNames = _hatchStyleNames.GetLocalizedNames();
- Array.Sort(styleNames);
-
- foreach (string styleName in styleNames)
- {
- _brushStyleComboBox.Items.Add(styleName);
- }
-
- _brushStyleComboBox.SelectedIndex = 0;
-
- _brushStyleLabel.Text = PdnResources.GetString("BrushConfigWidget.FillStyleLabel.Text");
-
- _shapeDrawType = ShapeDrawType.Outline;
- _shapeButton.Image = _shapeOutlineImage.Reference;
-
- _penSizeLabel.Text = PdnResources.GetString("PenConfigWidget.BrushWidthLabel");
-
- _penSizeComboBox.ComboBox.SuspendLayout();
-
- for (int i = 0; i < _brushSizes.Length; ++i)
- {
- _penSizeComboBox.Items.Add(_brushSizes[i].ToString());
- }
-
- _penSizeComboBox.ComboBox.ResumeLayout(false);
- _penSizeComboBox.SelectedIndex = 1; // default to brush size of 2
-
- _penSizeDecButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeDecButton.ToolTipText");
- _penSizeDecButton.Image = PdnResources.GetImageResource("Icons.MinusButtonIcon.png").Reference;
- _penSizeIncButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeIncButton.ToolTipText");
- _penSizeIncButton.Image = PdnResources.GetImageResource("Icons.PlusButtonIcon.png").Reference;
- _penStyleLabel.Text = PdnResources.GetString("ToolConfigStrip.PenStyleLabel.Text");
- _penStartCapSplitButton.Tag = PenInfo.DefaultLineCap;
- _penStartCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, true).Reference;
- _penStartCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenStartCapSplitButton.ToolTipText");
- _penDashStyleSplitButton.Tag = PenInfo.DefaultDashStyle;
- _penDashStyleSplitButton.Image = GetDashStyleImage(PenInfo.DefaultDashStyle);
- _penDashStyleSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenDashStyleSplitButton.ToolTipText");
- _penEndCapSplitButton.Tag = PenInfo.DefaultLineCap;
- _penEndCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, false).Reference;
- _penEndCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenEndCapSplitButton.ToolTipText");
-
- _gradientLinearClampedButton.ToolTipText = _gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearClamped);
- _gradientLinearClampedButton.Image = PdnResources.GetImageResource("Icons.LinearClampedGradientIcon.png").Reference;
- _gradientLinearReflectedButton.ToolTipText = _gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearReflected);
- _gradientLinearReflectedButton.Image = PdnResources.GetImageResource("Icons.LinearReflectedGradientIcon.png").Reference;
- _gradientLinearDiamondButton.ToolTipText = _gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearDiamond);
- _gradientLinearDiamondButton.Image = PdnResources.GetImageResource("Icons.LinearDiamondGradientIcon.png").Reference;
- _gradientRadialButton.ToolTipText = _gradientTypeNames.EnumValueToLocalizedName(GradientType.Radial);
- _gradientRadialButton.Image = PdnResources.GetImageResource("Icons.RadialGradientIcon.png").Reference;
- _gradientConicalButton.ToolTipText = _gradientTypeNames.EnumValueToLocalizedName(GradientType.Conical);
- _gradientConicalButton.Image = PdnResources.GetImageResource("Icons.ConicalGradientIcon.png").Reference;
-
- _gradientAllColorChannelsImage = PdnResources.GetImageResource("Icons.AllColorChannelsIcon.png");
- _gradientAlphaChannelOnlyImage = PdnResources.GetImageResource("Icons.AlphaChannelOnlyIcon.png");
- _gradientChannelsSplitButton.Image = _gradientAllColorChannelsImage.Reference;
-
- _antiAliasingEnabledImage = PdnResources.GetImageResource("Icons.AntiAliasingEnabledIcon.png");
- _antiAliasingDisabledImage = PdnResources.GetImageResource("Icons.AntiAliasingDisabledIcon.png");
- _antiAliasingSplitButton.Image = _antiAliasingEnabledImage.Reference;
-
- _alphaBlendingEnabledImage = PdnResources.GetImageResource("Icons.BlendingEnabledIcon.png");
- _alphaBlendingOverwriteImage = PdnResources.GetImageResource("Icons.BlendingOverwriteIcon.png");
- _alphaBlendingSplitButton.Image = _alphaBlendingEnabledImage.Reference;
-
- _penSizeComboBox.Size = new Size(UI.ScaleWidth(_penSizeComboBox.Width), _penSizeComboBox.Height);
- _brushStyleComboBox.Size = new Size(UI.ScaleWidth(_brushStyleComboBox.Width), _brushStyleComboBox.Height);
- _brushStyleComboBox.DropDownWidth = UI.ScaleWidth(_brushStyleComboBox.DropDownWidth);
- _brushStyleComboBox.DropDownHeight = UI.ScaleHeight(_brushStyleComboBox.DropDownHeight);
-
- _toleranceLabel.Text = PdnResources.GetString("ToleranceConfig.ToleranceLabel.Text");
- _toleranceSlider.Tolerance = 0.5f;
-
- if (_fontSizeComboBox.ComboBox != null) _fontSizeComboBox.ComboBox.SuspendLayout();
- for (int i = 0; i < _defaultFontSizes.Length; ++i)
- {
- _fontSizeComboBox.Items.Add(_defaultFontSizes[i].ToString());
- }
- if (_fontSizeComboBox.ComboBox != null) _fontSizeComboBox.ComboBox.ResumeLayout(false);
-
- _fontSmoothingComboBox.Items.AddRange(
- new object[]
- {
- _fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Smooth),
- _fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Sharp)
- });
-
- _fontSmoothingComboBox.SelectedIndex = 0;
-
- _fontLabel.Text = PdnResources.GetString("TextConfigWidget.FontLabel.Text");
-
- try
- {
- _arialFontFamily = new FontFamily(ArialName);
- }
-
- catch (Exception)
- {
- _arialFontFamily = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
- }
-
- try
- {
- _arialFontBase = new Font(_arialFontFamily, InitialFontSize, FontStyle.Regular);
- }
-
- catch (Exception)
- {
- _arialFontBase = new Font(FontFamily.GenericSansSerif, InitialFontSize, FontStyle.Regular);
- }
-
- _fontFamilyComboBox.ComboBox.DropDownHeight = 600;
-
- _alignment = TextAlignment.Left;
- _fontAlignLeftButton.Checked = true;
- _oldSizeValue = InitialFontSize;
-
- _highlightBrush = new SolidBrush(SystemColors.Highlight);
- _highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
- _windowBrush = new SolidBrush(SystemColors.Window);
- _windowTextBrush = new SolidBrush(SystemColors.WindowText);
-
- // These buttons need a color key to maintain consistency with v2.5 language packs
- _fontBoldButton.ImageTransparentColor = Utility.TransparentKey;
- _fontItalicsButton.ImageTransparentColor = Utility.TransparentKey;
- _fontUnderlineButton.ImageTransparentColor = Utility.TransparentKey;
-
- _fontBoldButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontBoldIcon");
- _fontItalicsButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontItalicIcon");
- _fontUnderlineButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontUnderlineIcon");
-
- _fontAlignLeftButton.Image = PdnResources.GetImageResource("Icons.TextAlignLeftIcon.png").Reference;
- _fontAlignCenterButton.Image = PdnResources.GetImageResource("Icons.TextAlignCenterIcon.png").Reference;
- _fontAlignRightButton.Image = PdnResources.GetImageResource("Icons.TextAlignRightIcon.png").Reference;
-
- _fontBoldButton.ToolTipText = PdnResources.GetString("TextConfigWidget.BoldButton.ToolTipText");
- _fontItalicsButton.ToolTipText = PdnResources.GetString("TextConfigWidget.ItalicButton.ToolTipText");
- _fontUnderlineButton.ToolTipText = PdnResources.GetString("TextConfigWidget.UnderlineButton.ToolTipText");
- _fontAlignLeftButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignLeftButton.ToolTipText");
- _fontAlignCenterButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignCenterButton.ToolTipText");
- _fontAlignRightButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignRightButton.ToolTipText");
-
- _fontFamilyComboBox.Size = new Size(UI.ScaleWidth(_fontFamilyComboBox.Width), _fontFamilyComboBox.Height);
- _fontFamilyComboBox.DropDownWidth = UI.ScaleWidth(_fontFamilyComboBox.DropDownWidth);
- _fontSizeComboBox.Size = new Size(UI.ScaleWidth(_fontSizeComboBox.Width), _fontSizeComboBox.Height);
-
- _fontSmoothingComboBox.Size = new Size(UI.ScaleWidth(_fontSmoothingComboBox.Width), _fontSmoothingComboBox.Height);
- _fontSmoothingComboBox.DropDownWidth = UI.ScaleWidth(_fontSmoothingComboBox.DropDownWidth);
-
- _resamplingLabel.Text = PdnResources.GetString("ToolConfigStrip.ResamplingLabel.Text");
- _resamplingComboBox.BeginUpdate();
- _resamplingComboBox.Items.Add(_resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.Bilinear));
- _resamplingComboBox.Items.Add(_resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.NearestNeighbor));
- _resamplingComboBox.EndUpdate();
- _resamplingComboBox.SelectedIndex = 0; // bilinear
-
- _resamplingComboBox.Size = new Size(UI.ScaleWidth(_resamplingComboBox.Width), _resamplingComboBox.Height);
- _resamplingComboBox.DropDownWidth = UI.ScaleWidth(_resamplingComboBox.DropDownWidth);
-
- _colorPickerLabel.Text = PdnResources.GetString("ToolConfigStrip.ColorPickerLabel.Text");
- string[] colorPickerBehaviorNames = _colorPickerBehaviorNames.GetLocalizedNames();
-
- // Make sure these items are sorted to be in the order specified by the enumeration
- Array.Sort(
- colorPickerBehaviorNames,
- delegate(string lhs, string rhs)
- {
- var lhsE = (ColorPickerClickBehavior)_colorPickerBehaviorNames.LocalizedNameToEnumValue(lhs);
- var rhsE = (ColorPickerClickBehavior)_colorPickerBehaviorNames.LocalizedNameToEnumValue(rhs);
-
- if ((int)lhsE < (int)rhsE)
- {
- return -1;
- }
- return (int) lhsE > (int) rhsE ? +1 : 0;
- });
-
- _colorPickerComboBox.Items.AddRange(colorPickerBehaviorNames);
- _colorPickerComboBox.SelectedIndex = 0;
-
- _colorPickerComboBox.Size = new Size(UI.ScaleWidth(_colorPickerComboBox.Width), _colorPickerComboBox.Height);
- _colorPickerComboBox.DropDownWidth = UI.ScaleWidth(_colorPickerComboBox.DropDownWidth);
-
- _toleranceSlider.Size = UI.ScaleSize(_toleranceSlider.Size);
-
- _selectionCombineModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionCombineModeLabel.Text");
-
- _floodModeLabel.Text = PdnResources.GetString("ToolConfigStrip.FloodModeLabel.Text");
-
- _selectionDrawModeModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeLabel.Text");
- _selectionDrawModeWidthLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeWidthLabel.Text");
- _selectionDrawModeHeightLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeHeightLabel.Text");
- _selectionDrawModeSwapButton.Image = PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSwapButton.png").Reference;
-
- _selectionDrawModeWidthTextBox.Size = new Size(UI.ScaleWidth(_selectionDrawModeWidthTextBox.Width), _selectionDrawModeWidthTextBox.Height);
- _selectionDrawModeHeightTextBox.Size = new Size(UI.ScaleWidth(_selectionDrawModeHeightTextBox.Width), _selectionDrawModeHeightTextBox.Height);
- _selectionDrawModeUnits.Size = new Size(UI.ScaleWidth(_selectionDrawModeUnits.Width), _selectionDrawModeUnits.Height);
-
- ToolBarConfigItems = ToolBarConfigItems.None;
- ResumeLayout(false);
- }
-
- private void AsyncInitFontNames()
- {
- if (!IsHandleCreated)
- {
- CreateControl();
- }
-
- if (_fontFamilyComboBox.ComboBox != null)
- if (!_fontFamilyComboBox.ComboBox.IsHandleCreated)
- {
- _fontFamilyComboBox.ComboBox.CreateControl();
- }
-
- if (_staticFontNames == null)
- {
- ThreadPool.QueueUserWorkItem(PopulateFontsBackgroundThread, null);
- }
- }
-
- protected override void OnHandleCreated(EventArgs e)
- {
- if ((_toolBarConfigItems & ToolBarConfigItems.Text) == ToolBarConfigItems.Text)
- {
- AsyncInitFontNames();
- }
-
- base.OnHandleCreated(e);
- }
-
- private void InitializeComponent()
- {
- _brushSeparator = new ToolStripSeparator();
- _brushStyleLabel = new ToolStripLabel();
- _brushStyleComboBox = new ToolStripComboBox();
-
- _shapeSeparator = new ToolStripSeparator();
- _shapeButton = new ToolStripSplitButton();
-
- _gradientSeparator1 = new ToolStripSeparator();
- _gradientLinearClampedButton = new ToolStripButton();
- _gradientLinearReflectedButton = new ToolStripButton();
- _gradientLinearDiamondButton = new ToolStripButton();
- _gradientRadialButton = new ToolStripButton();
- _gradientConicalButton = new ToolStripButton();
- _gradientSeparator2 = new ToolStripSeparator();
- _gradientChannelsSplitButton = new ToolStripSplitButton();
-
- _penSeparator = new ToolStripSeparator();
- _penSizeLabel = new ToolStripLabel();
- _penSizeDecButton = new ToolStripButton();
- _penSizeComboBox = new ToolStripComboBox();
- _penSizeIncButton = new ToolStripButton();
- _penStyleLabel = new ToolStripLabel();
- _penStartCapSplitButton = new ToolStripSplitButton();
- _penDashStyleSplitButton = new ToolStripSplitButton();
- _penEndCapSplitButton = new ToolStripSplitButton();
-
- _blendingSeparator = new ToolStripSeparator();
- _antiAliasingSplitButton = new ToolStripSplitButton();
- _alphaBlendingSplitButton = new ToolStripSplitButton();
-
- _toleranceSeparator = new ToolStripSeparator();
- _toleranceLabel = new ToolStripLabel();
- _toleranceSlider = new ToleranceSliderControl();
- _toleranceSliderStrip = new ToolStripControlHost(_toleranceSlider);
-
- _fontSeparator = new ToolStripSeparator();
- _fontLabel = new ToolStripLabel();
- _fontFamilyComboBox = new ToolStripComboBox();
- _fontSizeComboBox = new ToolStripComboBox();
- _fontSmoothingComboBox = new ToolStripComboBox();
- _fontStyleSeparator = new ToolStripSeparator();
- _fontBoldButton = new ToolStripButton();
- _fontItalicsButton = new ToolStripButton();
- _fontUnderlineButton = new ToolStripButton();
- _fontAlignSeparator = new ToolStripSeparator();
- _fontAlignLeftButton = new ToolStripButton();
- _fontAlignCenterButton = new ToolStripButton();
- _fontAlignRightButton = new ToolStripButton();
-
- _resamplingSeparator = new ToolStripSeparator();
- _resamplingLabel = new ToolStripLabel();
- _resamplingComboBox = new ToolStripComboBox();
-
- _colorPickerSeparator = new ToolStripSeparator();
- _colorPickerLabel = new ToolStripLabel();
- _colorPickerComboBox = new ToolStripComboBox();
-
- _selectionCombineModeSeparator = new ToolStripSeparator();
- _selectionCombineModeLabel = new ToolStripLabel();
- _selectionCombineModeSplitButton = new ToolStripSplitButton();
-
- _floodModeSeparator = new ToolStripSeparator();
- _floodModeLabel = new ToolStripLabel();
- _floodModeSplitButton = new ToolStripSplitButton();
-
- _selectionDrawModeSeparator = new ToolStripSeparator();
- _selectionDrawModeModeLabel = new ToolStripLabel();
- _selectionDrawModeSplitButton = new ToolStripSplitButton();
- _selectionDrawModeWidthLabel = new ToolStripLabel();
- _selectionDrawModeWidthTextBox = new ToolStripTextBox {TextBox = {Width = 50}};
- _selectionDrawModeSwapButton = new ToolStripButton();
- _selectionDrawModeHeightLabel = new ToolStripLabel();
- _selectionDrawModeHeightTextBox = new ToolStripTextBox {TextBox = {Width = 50}};
- _selectionDrawModeUnits = new UnitsComboBoxStrip();
-
- SuspendLayout();
- //
- // brushStyleLabel
- //
- _brushStyleLabel.Name = "fillStyleLabel";
- //
- // brushStyleComboBox
- //
- _brushStyleComboBox.Name = "styleComboBox";
- _brushStyleComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- _brushStyleComboBox.DropDownWidth = 234;
- _brushStyleComboBox.AutoSize = true;
- //
- // brushStyleComboBox.ComboBox
- //
- if (_brushStyleComboBox.ComboBox != null)
- {
- _brushStyleComboBox.ComboBox.DrawMode = DrawMode.OwnerDrawVariable;
- _brushStyleComboBox.ComboBox.MeasureItem += ComboBoxStyleMeasureItem;
- _brushStyleComboBox.ComboBox.SelectedValueChanged += ComboBoxStyleSelectedValueChanged;
- _brushStyleComboBox.ComboBox.DrawItem += ComboBoxStyleDrawItem;
- }
- //
- // shapeButton
- //
- _shapeButton.Name = "shapeButton";
- _shapeButton.DropDownOpening += ShapeButtonDropDownOpening;
-
- _shapeButton.DropDownClosed +=
- (sender, e) => _shapeButton.DropDownItems.Clear();
-
- _shapeButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(shapeButton)");
-
- switch (ShapeDrawType)
- {
- case ShapeDrawType.Outline:
- ShapeDrawType = ShapeDrawType.Interior;
- break;
-
- case ShapeDrawType.Interior:
- ShapeDrawType = ShapeDrawType.Both;
- break;
-
- case ShapeDrawType.Both:
- ShapeDrawType = ShapeDrawType.Outline;
- break;
-
- default:
- throw new InvalidEnumArgumentException();
- }
- };
- //
- // gradientSeparator
- //
- _gradientSeparator1.Name = "gradientSeparator";
- //
- // gradientLinearClampedButton
- //
- _gradientLinearClampedButton.Name = "gradientLinearClampedButton";
- _gradientLinearClampedButton.Click += GradientTypeButtonClicked;
- _gradientLinearClampedButton.Tag = GradientType.LinearClamped;
- //
- // gradientLinearReflectedButton
- //
- _gradientLinearReflectedButton.Name = "gradientLinearReflectedButton";
- _gradientLinearReflectedButton.Click += GradientTypeButtonClicked;
- _gradientLinearReflectedButton.Tag = GradientType.LinearReflected;
- //
- // gradientLinearDiamondButton
- //
- _gradientLinearDiamondButton.Name = "gradientLinearDiamondButton";
- _gradientLinearDiamondButton.Click += GradientTypeButtonClicked;
- _gradientLinearDiamondButton.Tag = GradientType.LinearDiamond;
- //
- // gradientRadialButton
- //
- _gradientRadialButton.Name = "gradientRadialButton";
- _gradientRadialButton.Click += GradientTypeButtonClicked;
- _gradientRadialButton.Tag = GradientType.Radial;
- //
- // gradientConicalButton
- //
- _gradientConicalButton.Name = "gradientConicalButton";
- _gradientConicalButton.Click += GradientTypeButtonClicked;
- _gradientConicalButton.Tag = GradientType.Conical;
- //
- // gradientSeparator2
- //
- _gradientSeparator2.Name = "gradientSeparator2";
- //
- // gradientChannelsSplitButton
- //
- _gradientChannelsSplitButton.Name = "gradientChannelsSplitButton";
- _gradientChannelsSplitButton.DropDownOpening += GradientChannelsSplitButtonDropDownOpening;
- _gradientChannelsSplitButton.DropDownClosed +=
- (sender, e) => _gradientChannelsSplitButton.DropDownItems.Clear();
- _gradientChannelsSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(gradientChannelsSplitButton)");
- GradientInfo = new GradientInfo(GradientInfo.GradientType, !GradientInfo.AlphaOnly);
- };
- //
- // penSeparator
- //
- _penSeparator.Name = "penSeparator";
- //
- // penSizeLabel
- //
- _penSizeLabel.Name = "brushSizeLabel";
- //
- // penSizeDecButton
- //
- _penSizeDecButton.Name = "penSizeDecButton";
- _penSizeDecButton.Click +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(penSizeDecButton)");
-
- float amount = -1.0f;
-
- if ((ModifierKeys & Keys.Control) != 0)
- {
- amount *= 5.0f;
- }
-
- AddToPenSize(amount);
- };
- //
- // penSizeComboBox
- //
- _penSizeComboBox.Name = "penSizeComboBox";
- _penSizeComboBox.Validating += BrushSizeComboBoxValidating;
- _penSizeComboBox.TextChanged += SizeComboBoxTextChanged;
- _penSizeComboBox.AutoSize = false;
- _penSizeComboBox.Width = 44;
- //
- // penSizeIncButton
- //
- _penSizeIncButton.Name = "penSizeIncButton";
- _penSizeIncButton.Click +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(penSizeIncButton)");
-
- float amount = 1.0f;
-
- if ((ModifierKeys & Keys.Control) != 0)
- {
- amount *= 5.0f;
- }
-
- AddToPenSize(amount);
- };
- //
- // penStartCapLabel
- //
- _penStyleLabel.Name = "penStartCapLabel";
- //
- // penStartCapSplitButton
- //
- _penStartCapSplitButton.Name = "penStartCapSplitButton";
- _penStartCapSplitButton.DropDownOpening += PenCapSplitButtonDropDownOpening;
- _penStartCapSplitButton.DropDownClosed +=
- (sender, e) => _penStartCapSplitButton.DropDownItems.Clear();
- _penStartCapSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(penStartCapSplitButton)");
- CyclePenStartCap();
- };
- //
- // penDashStyleSplitButton
- //
- _penDashStyleSplitButton.Name = "penDashStyleSplitButton";
- _penDashStyleSplitButton.ImageScaling = ToolStripItemImageScaling.None;
- _penDashStyleSplitButton.DropDownOpening += PenDashStyleButtonDropDownOpening;
- _penDashStyleSplitButton.DropDownClosed +=
- (sender, e) => _penDashStyleSplitButton.DropDownItems.Clear();
- _penDashStyleSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(penDashStyleSplitButton)");
- CyclePenDashStyle();
- };
- //
- // penEndCapSplitButton
- //
- _penEndCapSplitButton.Name = "penEndCapSplitButton";
- _penEndCapSplitButton.DropDownOpening += PenCapSplitButtonDropDownOpening;
- _penEndCapSplitButton.DropDownClosed +=
- (sender, e) => _penEndCapSplitButton.DropDownItems.Clear();
- _penEndCapSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(penEndCapSplitButton)");
- CyclePenEndCap();
- };
- //
- // antiAliasingSplitButton
- //
- _antiAliasingSplitButton.Name = "antiAliasingSplitButton";
- _antiAliasingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- _antiAliasingSplitButton.DropDownOpening += AntiAliasingSplitButtonDropDownOpening;
- _antiAliasingSplitButton.DropDownClosed +=
- (sender, e) => _antiAliasingSplitButton.DropDownItems.Clear();
- _antiAliasingSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(antiAliasingSplitButton)");
- AntiAliasing = !AntiAliasing;
- };
- //
- // alphaBlendingSplitButton
- //
- _alphaBlendingSplitButton.Name = "alphaBlendingSplitButton";
- _alphaBlendingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- _alphaBlendingSplitButton.DropDownOpening += AlphaBlendingSplitButtonDropDownOpening;
- _alphaBlendingSplitButton.DropDownClosed +=
- (sender, e) => _alphaBlendingSplitButton.DropDownItems.Clear();
- _alphaBlendingSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(alphaBlendingSplitButton)");
- AlphaBlending = !AlphaBlending;
- };
- //
- // toleranceLabel
- //
- _toleranceLabel.Name = "toleranceLabel";
- //
- // toleranceSlider
- //
- _toleranceSlider.Name = "_toleranceSlider";
- _toleranceSlider.ToleranceChanged += ToleranceSliderToleranceChanged;
- _toleranceSlider.Size = new Size(150, 16);
- //
- // toleranceSliderStrip
- //
- _toleranceSliderStrip.Name = "toleranceSliderStrip";
- _toleranceSliderStrip.AutoSize = false;
- //
- // fontLabel
- //
- _fontLabel.Name = "fontLabel";
- //
- // fontFamilyComboBox
- //
- _fontFamilyComboBox.Name = "fontComboBox";
- _fontFamilyComboBox.DropDownWidth = 240;
- _fontFamilyComboBox.MaxDropDownItems = 12;
- _fontFamilyComboBox.Sorted = true;
- _fontFamilyComboBox.GotFocus += FontFamilyComboBoxGotFocus;
- _fontFamilyComboBox.Items.Add(ArialName);
- _fontFamilyComboBox.SelectedItem = ArialName;
- _fontFamilyComboBox.SelectedIndexChanged += FontFamilyComboBoxSelectedIndexChanged;
- _fontFamilyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- //
- // fontFamilyComboBox.ComboBox
- //
- if (_fontFamilyComboBox.ComboBox != null)
- {
- _fontFamilyComboBox.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
- _fontFamilyComboBox.ComboBox.MeasureItem += FontFamilyComboBoxMeasureItem;
- _fontFamilyComboBox.ComboBox.DrawItem += FontFamilyComboBoxDrawItem;
- }
- //
- // fontSizeComboBox
- //
- _fontSizeComboBox.Name = "fontSizeComboBox";
- _fontSizeComboBox.AutoSize = false;
- _fontSizeComboBox.TextChanged += FontSizeComboBoxTextChanged;
- _fontSizeComboBox.Validating += FontSizeComboBoxValidating;
- _fontSizeComboBox.Text = InitialFontSize.ToString();
- _fontSizeComboBox.Width = 44;
- //
- // fontSmoothingComboBox
- //
- _fontSmoothingComboBox.Name = "smoothingComboBOx";
- _fontSmoothingComboBox.AutoSize = false;
- _fontSmoothingComboBox.Sorted = false;
- _fontSmoothingComboBox.Width = 70;
- _fontSmoothingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- _fontSmoothingComboBox.SelectedIndexChanged += SmoothingComboBoxSelectedIndexChanged;
- //
- // fontBoldButton
- //
- _fontBoldButton.Name = "boldButton";
- //
- // fontItalicsButton
- //
- _fontItalicsButton.Name = "italicsButton";
- //
- // fontUnderlineButton
- //
- _fontUnderlineButton.Name = "underlineButton";
- //
- // fontAlignLeftButton
- //
- _fontAlignLeftButton.Name = "alignLeftButton";
- //
- // fontAlignCenterButton
- //
- _fontAlignCenterButton.Name = "alignCenterButton";
- //
- // fontAlignRightButton
- //
- _fontAlignRightButton.Name = "alignRightButton";
- //
- // resamplingSeparator
- //
- _resamplingSeparator.Name = "resamplingSeparator";
- //
- // resamplingLabel
- //
- _resamplingLabel.Name = "resamplingLabel";
- //
- // resamplingComboBox
- //
- _resamplingComboBox.Name = "resamplingComboBox";
- _resamplingComboBox.AutoSize = true;
- _resamplingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- _resamplingComboBox.Sorted = false;
- _resamplingComboBox.Width = 100;
- _resamplingComboBox.DropDownWidth = 100;
- _resamplingComboBox.SelectedIndexChanged += ResamplingComboBoxSelectedIndexChanged;
- //
- // colorPickerSeparator
- //
- _colorPickerSeparator.Name = "colorPickerSeparator";
- //
- // colorPickerLabel
- //
- _colorPickerLabel.Name = "colorPickerLabel";
- //
- // colorPickerComboBox
- //
- _colorPickerComboBox.Name = "colorPickerComboBox";
- _colorPickerComboBox.AutoSize = true;
- _colorPickerComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
- _colorPickerComboBox.Width = 200;
- _colorPickerComboBox.DropDownWidth = 200;
- _colorPickerComboBox.Sorted = false;
- _colorPickerComboBox.SelectedIndexChanged += ColorPickerComboBoxSelectedIndexChanged;
- //
- // selectionCombineModeSeparator
- //
- _selectionCombineModeSeparator.Name = "selectionCombineModeSeparator";
- //
- // selectionCombineModeLabel
- //
- _selectionCombineModeLabel.Name = "selectionCombineModeLabel";
- //
- // selectionCombineModeSplitButton
- //
- _selectionCombineModeSplitButton.Name = "selectionCombineModeSplitButton";
- _selectionCombineModeSplitButton.DisplayStyle = ToolStripItemDispla…
Large files files are truncated, but you can click here to view the full file