/src/ToolConfigStrip.cs
C# | 2979 lines | 2335 code | 419 blank | 225 comment | 220 complexity | b71bda30139507e48234f6a58848dd64 MD5 | raw 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 = ToolStripItemDisplayStyle.Image;
- _selectionCombineModeSplitButton.DropDownOpening += SelectionCombineModeSplitButtonDropDownOpening;
- _selectionCombineModeSplitButton.DropDownClosed +=
- (sender, e) => _selectionCombineModeSplitButton.DropDownItems.Clear();
- _selectionCombineModeSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(selectionCombineModeSplitButton)");
- SelectionCombineMode = CycleSelectionCombineMode(SelectionCombineMode);
- };
- //
- // floodModeSeparator
- //
- _floodModeSeparator.Name = "floodModeSeparator";
- //
- // floodModeLabel
- //
- _floodModeLabel.Name = "floodModeLabel";
- //
- // floodModeSplitButton
- //
- _floodModeSplitButton.Name = "floodModeSplitButton";
- _floodModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
- _floodModeSplitButton.DropDownOpening += FloodModeSplitButtonDropDownOpening;
- _floodModeSplitButton.DropDownClosed +=
- (sender, e) => _floodModeSplitButton.DropDownItems.Clear();
- _floodModeSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(floodModeSplitButton)");
- FloodMode = CycleFloodMode(FloodMode);
- };
- //
- // selectionDrawModeSeparator
- //
- _selectionDrawModeSeparator.Name = "selectionDrawModeSeparator";
- //
- // selectionDrawModeModeLabel
- //
- _selectionDrawModeModeLabel.Name = "selectionDrawModeModeLabel";
- //
- // selectionDrawModeSplitButton
- //
- _selectionDrawModeSplitButton.Name = "selectionDrawModeSplitButton";
- _selectionDrawModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
- _selectionDrawModeSplitButton.DropDownOpening += SelectionDrawModeSplitButtonDropDownOpening;
- _selectionDrawModeSplitButton.DropDownClosed +=
- (sender, e) => _selectionDrawModeSplitButton.DropDownItems.Clear();
- _selectionDrawModeSplitButton.ButtonClick +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSplitButton)");
- SelectionDrawMode newSDM = CycleSelectionDrawMode(SelectionDrawModeInfo.DrawMode);
- SelectionDrawModeInfo = SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
- };
- //
- // selectionDrawModeWidthLabel
- //
- _selectionDrawModeWidthLabel.Name = "selectionDrawModeWidthLabel";
- //
- // selectionDrawModeWidthTextBox
- //
- _selectionDrawModeWidthTextBox.Name = "selectionDrawModeWidthTextBox";
- _selectionDrawModeWidthTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
- _selectionDrawModeWidthTextBox.Enter +=
- (sender, e) =>
- _selectionDrawModeWidthTextBox.TextBox.Select(0,
- _selectionDrawModeWidthTextBox.TextBox.Text.
- Length);
- _selectionDrawModeWidthTextBox.Leave +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeWidthTextBox.Leave)");
-
- double newWidth;
- if (double.TryParse(_selectionDrawModeWidthTextBox.Text, out newWidth))
- {
- SelectionDrawModeInfo = _selectionDrawModeInfo.CloneWithNewWidth(newWidth);
- }
- else
- {
- _selectionDrawModeWidthTextBox.Text = _selectionDrawModeInfo.Width.ToString();
- }
- };
- //
- // selectionDrawModeSwapButton
- //
- _selectionDrawModeSwapButton.Name = "selectionDrawModeSwapButton";
- _selectionDrawModeSwapButton.Click +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSwapButton)");
-
- SelectionDrawModeInfo oldSDMI = SelectionDrawModeInfo;
- var newSDMI = new SelectionDrawModeInfo(oldSDMI.DrawMode, oldSDMI.Height, oldSDMI.Width, oldSDMI.Units);
- SelectionDrawModeInfo = newSDMI;
- };
- //
- // selectionDrawModeHeightLabel
- //
- _selectionDrawModeHeightLabel.Name = "selectionDrawModeHeightLabel";
- //
- // selectionDrawModeHeightTextBox
- //
- _selectionDrawModeHeightTextBox.Name = "selectionDrawModeHeightTextBox";
- _selectionDrawModeHeightTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
- _selectionDrawModeHeightTextBox.Enter +=
- (sender, e) =>
- _selectionDrawModeHeightTextBox.TextBox.Select(0,
- _selectionDrawModeHeightTextBox.TextBox.Text.
- Length);
- _selectionDrawModeHeightTextBox.Leave +=
- delegate
- {
- Tracing.LogFeature("ToolConfigStrip(selectionDrawModeHeightTextBox.Leave)");
-
- double newHeight;
- if (double.TryParse(_selectionDrawModeHeightTextBox.Text, out newHeight))
- {
- SelectionDrawModeInfo = _selectionDrawModeInfo.CloneWithNewHeight(newHeight);
- }
- else
- {
- _selectionDrawModeHeightTextBox.Text = _selectionDrawModeInfo.Height.ToString();
- }
- };
- //
- // selectionDrawModeUnits
- //
- _selectionDrawModeUnits.Name = "selectionDrawModeUnits";
- _selectionDrawModeUnits.UnitsDisplayType = UnitsDisplayType.Plural;
- _selectionDrawModeUnits.LowercaseStrings = true;
- _selectionDrawModeUnits.Size = new Size(90, _selectionDrawModeUnits.Height);
- //
- // DrawConfigStrip
- //
- AutoSize = true;
-
- Items.AddRange(
- new ToolStripItem[]
- {
- _selectionCombineModeSeparator,
- _selectionCombineModeLabel,
- _selectionCombineModeSplitButton,
-
- _selectionDrawModeSeparator,
- _selectionDrawModeModeLabel,
- _selectionDrawModeSplitButton,
- _selectionDrawModeWidthLabel,
- _selectionDrawModeWidthTextBox,
- _selectionDrawModeSwapButton,
- _selectionDrawModeHeightLabel,
- _selectionDrawModeHeightTextBox,
- _selectionDrawModeUnits,
-
- _floodModeSeparator,
- _floodModeLabel,
- _floodModeSplitButton,
-
- _resamplingSeparator,
- _resamplingLabel,
- _resamplingComboBox,
-
- _colorPickerSeparator,
- _colorPickerLabel,
- _colorPickerComboBox,
-
- _fontSeparator,
- _fontLabel,
- _fontFamilyComboBox,
- _fontSizeComboBox,
- _fontSmoothingComboBox,
- _fontStyleSeparator,
- _fontBoldButton,
- _fontItalicsButton,
- _fontUnderlineButton,
- _fontAlignSeparator,
- _fontAlignLeftButton,
- _fontAlignCenterButton,
- _fontAlignRightButton,
-
- _shapeSeparator,
- _shapeButton,
-
- _gradientSeparator1,
- _gradientLinearClampedButton,
- _gradientLinearReflectedButton,
- _gradientLinearDiamondButton,
- _gradientRadialButton,
- _gradientConicalButton,
- _gradientSeparator2,
- _gradientChannelsSplitButton,
-
- _penSeparator,
- _penSizeLabel,
- _penSizeDecButton,
- _penSizeComboBox,
- _penSizeIncButton,
- _penStyleLabel,
- _penStartCapSplitButton,
- _penDashStyleSplitButton,
- _penEndCapSplitButton,
-
- _brushSeparator,
- _brushStyleLabel,
- _brushStyleComboBox,
-
- _toleranceSeparator,
- _toleranceLabel,
- _toleranceSliderStrip,
-
- _blendingSeparator,
- _antiAliasingSplitButton,
- _alphaBlendingSplitButton
- });
-
- ResumeLayout(false);
- }
-
- public void CyclePenEndCap()
- {
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.EndCap = NextLineCap(newPenInfo.EndCap);
- PenInfo = newPenInfo;
- }
-
- public void CyclePenStartCap()
- {
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.StartCap = NextLineCap(newPenInfo.StartCap);
- PenInfo = newPenInfo;
- }
-
- public void CyclePenDashStyle()
- {
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.DashStyle = NextDashStyle(newPenInfo.DashStyle);
- PenInfo = newPenInfo;
- }
-
- private DashStyle NextDashStyle(DashStyle oldDash)
- {
- int dashIndex = Array.IndexOf(_dashStyles, oldDash);
- int newDashIndex = (dashIndex + 1) % _dashStyles.Length;
- return _dashStyles[newDashIndex];
- }
-
- private LineCap2 NextLineCap(LineCap2 oldCap)
- {
- int capIndex = Array.IndexOf(_lineCaps, oldCap);
- int newCapIndex = (capIndex + 1) % _lineCaps.Length;
- return _lineCaps[newCapIndex];
- }
-
- private void GradientTypeButtonClicked(object sender, EventArgs e)
- {
- Tracing.LogFeature("ToolConfigStrip(GradientTypeButtonClicked)");
-
- var newType = (GradientType)((ToolStripButton)sender).Tag;
- GradientInfo = new GradientInfo(newType, GradientInfo.AlphaOnly);
- }
-
- private void ComboBoxStyleSelectedValueChanged(object sender, EventArgs e)
- {
- OnBrushChanged();
- }
-
- public void PerformBrushChanged()
- {
- OnBrushChanged();
- }
-
- private void ComboBoxStyleDrawItem(object sender, DrawItemEventArgs e)
- {
- e.DrawBackground();
-
- Rectangle r = e.Bounds;
-
- if (e.Index == -1) return;
- var itemName = (string)_brushStyleComboBox.Items[e.Index];
-
- if (itemName != _solidBrushText)
- {
- Rectangle rd = r;
- rd.Width = rd.Left + 25;
-
- Rectangle rt = r;
- r.X = rd.Right;
-
- string displayText = _brushStyleComboBox.Items[e.Index].ToString();
- var hs = (HatchStyle)_hatchStyleNames.LocalizedNameToEnumValue(displayText);
-
- using (var b = new HatchBrush(hs, e.ForeColor, e.BackColor))
- {
- e.Graphics.FillRectangle(b, rd);
- }
-
- var sf = new StringFormat {Alignment = StringAlignment.Near};
-
- using (var sb = new SolidBrush(Color.White))
- {
- if ((e.State & DrawItemState.Focus) == 0)
- {
- sb.Color = SystemColors.Window;
- e.Graphics.FillRectangle(sb, r);
- sb.Color = SystemColors.WindowText;
- e.Graphics.DrawString(displayText, Font, sb, r, sf);
- }
- else
- {
- sb.Color = SystemColors.Highlight;
- e.Graphics.FillRectangle(sb, r);
- sb.Color = SystemColors.HighlightText;
- e.Graphics.DrawString(displayText, Font, sb, r, sf);
- }
- }
-
- sf.Dispose();
- sf = null;
- }
- else
- {
- // Solid Brush
- using (var sb = new SolidBrush(Color.White))
- {
- if ((e.State & DrawItemState.Focus) == 0)
- {
- sb.Color = SystemColors.Window;
- e.Graphics.FillRectangle(sb, e.Bounds);
- string displayText = _brushStyleComboBox.Items[e.Index].ToString();
- sb.Color = SystemColors.WindowText;
- e.Graphics.DrawString(displayText, Font, sb, e.Bounds);
- }
- else
- {
- sb.Color = SystemColors.Highlight;
- e.Graphics.FillRectangle(sb, e.Bounds);
- string displayText = _brushStyleComboBox.Items[e.Index].ToString();
- sb.Color = SystemColors.HighlightText;
- e.Graphics.DrawString(displayText, Font, sb, e.Bounds);
- }
- }
- }
-
- e.DrawFocusRectangle();
- }
-
- private void ComboBoxStyleMeasureItem(object sender, MeasureItemEventArgs e)
- {
- // Work out what the text will be
- string displayText = _brushStyleComboBox.Items[e.Index].ToString();
-
- // Get width & height of string
- SizeF stringSize = e.Graphics.MeasureString(displayText, Font);
-
- // set height to text height
- e.ItemHeight = (int)stringSize.Height;
-
- // set width to text width
- e.ItemWidth = (int)stringSize.Width;
- }
-
- public event EventHandler ShapeDrawTypeChanged;
- protected virtual void OnShapeDrawTypeChanged()
- {
- if (ShapeDrawTypeChanged != null)
- {
- ShapeDrawTypeChanged(this, EventArgs.Empty);
- }
- }
-
- public void PerformShapeDrawTypeChanged()
- {
- OnShapeDrawTypeChanged();
- }
-
- public ShapeDrawType ShapeDrawType
- {
- get
- {
- return _shapeDrawType;
- }
-
- set
- {
- if (_shapeDrawType == value) return;
- _shapeDrawType = value;
-
- // if the user sets the shape the buttons must be updated
- switch (_shapeDrawType)
- {
- case ShapeDrawType.Outline:
- _shapeButton.Image = _shapeOutlineImage.Reference;
- break;
- case ShapeDrawType.Both:
- _shapeButton.Image = _shapeBothImage.Reference;
- break;
- case ShapeDrawType.Interior:
- _shapeButton.Image = _shapeInteriorImage.Reference;
- break;
- default:
- throw new InvalidOperationException("Shape draw type is invalid");
- }
-
- OnShapeDrawTypeChanged();
- }
- }
-
- private void SetFontStyleButtons(FontStyle style)
- {
- bool bold = ((style & FontStyle.Bold) != 0);
- bool italic = ((style & FontStyle.Italic) != 0);
- bool underline = ((style & FontStyle.Underline) != 0);
-
- _fontBoldButton.Checked = bold;
- _fontItalicsButton.Checked = italic;
- _fontUnderlineButton.Checked = underline;
- }
-
- protected override void OnItemClicked(ToolStripItemClickedEventArgs e)
- {
- if (e.ClickedItem == _fontBoldButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontBoldButton)");
-
- _fontStyle ^= FontStyle.Bold;
- SetFontStyleButtons(_fontStyle);
- OnFontInfoChanged();
- }
- else if (e.ClickedItem == _fontItalicsButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontItalicsButton)");
-
- _fontStyle ^= FontStyle.Italic;
- SetFontStyleButtons(_fontStyle);
- OnFontInfoChanged();
- }
- else if (e.ClickedItem == _fontUnderlineButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontUnderlineButton)");
-
- _fontStyle ^= FontStyle.Underline;
- SetFontStyleButtons(_fontStyle);
- OnFontInfoChanged();
- }
- else if (e.ClickedItem == _fontAlignLeftButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontAlignLeftButton)");
- FontAlignment = TextAlignment.Left;
- }
- else if (e.ClickedItem == _fontAlignCenterButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontAlignCenterButton)");
- FontAlignment = TextAlignment.Center;
- }
- else if (e.ClickedItem == _fontAlignRightButton)
- {
- Tracing.LogFeature("ToolConfigStrip(fontAlignRightButton)");
- FontAlignment = TextAlignment.Right;
- }
-
- base.OnItemClicked(e);
- }
-
- public event EventHandler PenInfoChanged;
- protected virtual void OnPenChanged()
- {
- if (PenInfoChanged != null)
- {
- PenInfoChanged(this, EventArgs.Empty);
- }
- }
-
- public void PerformPenChanged()
- {
- OnPenChanged();
- }
-
- public void AddToPenSize(float delta)
- {
- if ((_toolBarConfigItems & ToolBarConfigItems.Pen) != ToolBarConfigItems.Pen) return;
- float newWidth = Utility.Clamp(PenInfo.Width + delta, MinPenSize, MaxPenSize);
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.Width += delta;
- newPenInfo.Width = Utility.Clamp(newPenInfo.Width, MinPenSize, MaxPenSize);
- PenInfo = newPenInfo;
- }
-
- public PenInfo PenInfo
- {
- get
- {
- float width;
-
- try
- {
- width = float.Parse(_penSizeComboBox.Text);
- }
-
- catch (FormatException)
- {
- // TODO: would much rather grab the value from AppEnvironment
- // or in some way that we keep track of the "last good value"
- width = 2;
- }
-
- LineCap2 startCap;
-
- try
- {
- startCap = (LineCap2)_penStartCapSplitButton.Tag;
- }
-
- catch (Exception)
- {
- startCap = PenInfo.DefaultLineCap;
- }
-
- LineCap2 endCap;
-
- try
- {
- endCap = (LineCap2)_penEndCapSplitButton.Tag;
- }
-
- catch (Exception)
- {
- endCap = PenInfo.DefaultLineCap;
- }
-
- var dashStyle = (DashStyle)_penDashStyleSplitButton.Tag;
-
- return new PenInfo(dashStyle, width, startCap, endCap, PenInfo.DefaultCapScale);
- }
-
- set
- {
- if (PenInfo == value) return;
- _penSizeComboBox.Text = value.Width.ToString();
- _penStartCapSplitButton.Tag = value.StartCap;
- _penStartCapSplitButton.Image = GetLineCapImage(value.StartCap, true).Reference;
- _penDashStyleSplitButton.Tag = value.DashStyle;
- _penDashStyleSplitButton.Image = GetDashStyleImage(value.DashStyle);
- _penEndCapSplitButton.Tag = value.EndCap;
- _penEndCapSplitButton.Image = GetLineCapImage(value.EndCap, false).Reference;
- OnPenChanged();
- }
- }
-
- private void SizeComboBoxTextChanged(object sender, EventArgs e)
- {
- BrushSizeComboBoxValidating(this, new CancelEventArgs());
- }
-
- private void BrushSizeComboBoxValidating(object sender, CancelEventArgs e)
- {
- float penSize;
- bool valid = float.TryParse(_penSizeComboBox.Text, out penSize);
-
- if (!valid)
- {
- _penSizeComboBox.BackColor = Color.Red;
- _penSizeComboBox.ToolTipText = PdnResources.GetString("PenConfigWidget.Error.InvalidNumber");
- }
- else
- {
- if (penSize < MinPenSize)
- {
- // Set the error if the size is too small.
- _penSizeComboBox.BackColor = Color.Red;
- string tooSmallFormat = PdnResources.GetString("PenConfigWidget.Error.TooSmall.Format");
- string tooSmall = string.Format(tooSmallFormat, MinPenSize);
- _penSizeComboBox.ToolTipText = tooSmall;
- }
- else if (penSize > MaxPenSize)
- {
- // Set the error if the size is too large.
- _penSizeComboBox.BackColor = Color.Red;
- string tooLargeFormat = PdnResources.GetString("PenConfigWidget.Error.TooLarge.Format");
- string tooLarge = string.Format(tooLargeFormat, MaxPenSize);
- _penSizeComboBox.ToolTipText = tooLarge;
- }
- else
- {
- // Clear the error, if any
- _penSizeComboBox.BackColor = SystemColors.Window;
- _penSizeComboBox.ToolTipText = string.Empty;
- OnPenChanged();
- }
- }
- }
-
- public event EventHandler AlphaBlendingChanged;
- protected virtual void OnAlphaBlendingChanged()
- {
- if (AlphaBlendingChanged != null)
- {
- AlphaBlendingChanged(this, EventArgs.Empty);
- }
- }
-
- public void PerformAlphaBlendingChanged()
- {
- OnAlphaBlendingChanged();
- }
-
- private void GradientChannelsSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- var allChannels = new ToolStripMenuItem(
- PdnResources.GetString("GradientChannels.AllColorChannels.Text"),
- _gradientAllColorChannelsImage.Reference,
- delegate {
- GradientInfo = new GradientInfo(GradientInfo.GradientType, false);
- });
-
- var alphaOnly = new ToolStripMenuItem(
- PdnResources.GetString("GradientChannels.AlphaChannelOnly.Text"),
- _gradientAlphaChannelOnlyImage.Reference,
- delegate {
- GradientInfo = new GradientInfo(GradientInfo.GradientType, true);
- });
-
- allChannels.Checked = !GradientInfo.AlphaOnly;
- alphaOnly.Checked = GradientInfo.AlphaOnly;
-
- _gradientChannelsSplitButton.DropDownItems.Clear();
- _gradientChannelsSplitButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- allChannels,
- alphaOnly
- });
- }
-
- private void AlphaBlendingSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- var abEnabled = new ToolStripMenuItem(
- PdnResources.GetString("AlphaBlendingSplitButton.BlendingEnabled.Text"),
- _alphaBlendingEnabledImage.Reference,
- delegate {
- AlphaBlending = true;
- });
-
- var abOverwrite = new ToolStripMenuItem(
- PdnResources.GetString("AlphaBlendingSplitButton.BlendingOverwrite.Text"),
- _alphaBlendingOverwriteImage.Reference,
- delegate {
- AlphaBlending = false;
- });
-
- abEnabled.Checked = AlphaBlending;
- abOverwrite.Checked = !AlphaBlending;
-
- _alphaBlendingSplitButton.DropDownItems.Clear();
- _alphaBlendingSplitButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- abEnabled,
- abOverwrite
- });
- }
-
- public bool AlphaBlending
- {
- get
- {
- return _alphaBlendingEnabled;
- }
-
- set
- {
- if (value == _alphaBlendingEnabled) return;
- _alphaBlendingEnabled = value;
-
- _alphaBlendingSplitButton.Image = value ? _alphaBlendingEnabledImage.Reference : _alphaBlendingOverwriteImage.Reference;
-
- OnAlphaBlendingChanged();
- }
- }
-
- private void AlphaBlendingComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- OnAlphaBlendingChanged();
- }
-
- public event EventHandler AntiAliasingChanged;
- protected virtual void OnAntiAliasingChanged()
- {
- if (AntiAliasingChanged != null)
- {
- AntiAliasingChanged(this, EventArgs.Empty);
- }
- }
-
- public void PerformAntiAliasingChanged()
- {
- OnAntiAliasingChanged();
- }
-
- public bool AntiAliasing
- {
- get
- {
- return _antiAliasingEnabled;
- }
-
- set
- {
- if (_antiAliasingEnabled == value) return;
- _antiAliasingSplitButton.Image = value ? _antiAliasingEnabledImage.Reference : _antiAliasingDisabledImage.Reference;
-
- _antiAliasingEnabled = value;
- OnAntiAliasingChanged();
- }
- }
-
- private static Image GetDashStyleImage(DashStyle dashStyle)
- {
- const string nameFormat = "Images.DashStyleButton.{0}.png";
- string name = string.Format(nameFormat, dashStyle);
- ImageResource imageResource = PdnResources.GetImageResource(name);
-
- Image returnImage;
-
- if (UI.GetXScaleFactor() == 1.0f && UI.GetYScaleFactor() == 1.0f)
- {
- returnImage = imageResource.Reference;
- }
- else
- {
- returnImage = new Bitmap(imageResource.Reference, UI.ScaleSize(imageResource.Reference.Size));
- }
-
- return returnImage;
- }
-
- private static ImageResource GetLineCapImage(LineCap2 lineCap, bool isStartCap)
- {
- const string nameFormat = "Images.LineCapButton.{0}.{1}.png";
- string name = string.Format(nameFormat, lineCap, isStartCap ? "Start" : "End");
- ImageResource imageResource = PdnResources.GetImageResource(name);
- return imageResource;
- }
-
- private void PenDashStyleButtonDropDownOpening(object sender, EventArgs e)
- {
- var menuItems = new List<ToolStripMenuItem>();
-
- foreach (DashStyle dashStyle in _dashStyles)
- {
- var mi = new ToolStripMenuItem(
- _dashStyleLocalizer.EnumValueToLocalizedName(dashStyle),
- GetDashStyleImage(dashStyle),
- delegate(object sender2, EventArgs e2)
- {
- var tsmi = (ToolStripMenuItem)sender2;
- var newDashStyle = (DashStyle)tsmi.Tag;
-
- PenInfo newPenInfo = PenInfo.Clone();
- newPenInfo.DashStyle = newDashStyle;
- PenInfo = newPenInfo;
- }) {ImageScaling = ToolStripItemImageScaling.None};
-
- if (dashStyle == PenInfo.DashStyle)
- {
- mi.Checked = true;
- }
-
- mi.Tag = dashStyle;
- menuItems.Add(mi);
- }
-
- _penDashStyleSplitButton.DropDownItems.Clear();
- _penDashStyleSplitButton.DropDownItems.AddRange(menuItems.ToArray());
- }
-
- private void PenCapSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- var splitButton = (ToolStripSplitButton)sender;
- var menuItems = new List<ToolStripMenuItem>();
-
- LineCap2 currentLineCap = PenInfo.DefaultLineCap;
- bool isStartCap;
-
- if (ReferenceEquals(splitButton, _penStartCapSplitButton))
- {
- isStartCap = true;
- currentLineCap = PenInfo.StartCap;
- }
- else if (ReferenceEquals(splitButton, _penEndCapSplitButton))
- {
- isStartCap = false;
- currentLineCap = PenInfo.EndCap;
- }
- else
- {
- throw new InvalidOperationException();
- }
-
- foreach (LineCap2 lineCap in _lineCaps)
- {
- var mi = new ToolStripMenuItem(
- _lineCapLocalizer.EnumValueToLocalizedName(lineCap),
- GetLineCapImage(lineCap, isStartCap).Reference,
- delegate(object sender2, EventArgs e2)
- {
- var tsmi = (ToolStripMenuItem)sender2;
- var data = (Pair<ToolStripSplitButton, LineCap2>)tsmi.Tag;
-
- PenInfo newPenInfo = PenInfo.Clone();
-
- if (ReferenceEquals(data.First, _penStartCapSplitButton))
- {
- newPenInfo.StartCap = data.Second;
- }
- else if (ReferenceEquals(data.First, _penEndCapSplitButton))
- {
- newPenInfo.EndCap = data.Second;
- }
-
- PenInfo = newPenInfo;
- }) {Tag = Pair.Create(splitButton, lineCap)};
-
- if (lineCap == currentLineCap)
- {
- mi.Checked = true;
- }
-
- menuItems.Add(mi);
- }
-
- splitButton.DropDownItems.Clear();
- splitButton.DropDownItems.AddRange(menuItems.ToArray());
- }
-
- private void AntiAliasingSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- var aaEnabled = new ToolStripMenuItem(
- PdnResources.GetString("AntiAliasingSplitButton.Enabled.Text"),
- _antiAliasingEnabledImage.Reference,
- delegate {
- AntiAliasing = true;
- });
-
- var aaDisabled = new ToolStripMenuItem(
- PdnResources.GetString("AntiAliasingSplitButton.Disabled.Text"),
- _antiAliasingDisabledImage.Reference,
- delegate {
- AntiAliasing = false;
- });
-
- aaEnabled.Checked = AntiAliasing;
- aaDisabled.Checked = !AntiAliasing;
-
- _antiAliasingSplitButton.DropDownItems.Clear();
- _antiAliasingSplitButton.DropDownItems.AddRange(
- new ToolStripItem[]
- {
- aaEnabled,
- aaDisabled
- });
- }
-
- private void SmoothingComboBoxSelectedIndexChanged(object sender, EventArgs e)
- {
- OnFontSmoothingChanged();
- }
-
- private void PopulateFontsBackgroundThread(object ignored)
- {
- PopulateFontsBackgroundThread();
- }
-
- private void PopulateFontsBackgroundThread()
- {
- try
- {
- using (new ThreadBackground(ThreadBackgroundFlags.Cpu))
- {
- PopulateFonts();
- }
- }
-
- finally
- {
- StaticFontNamesPopulatedEvent.Set();
- }
- }
- /*NOTE: CHECK THIS OVER*/
- private void PopulateFonts()
- {
- var fontNames = new List<string>();
-
- using (Graphics g = CreateGraphics())
- {
- FontFamily[] families = FontFamily.Families;
-
- foreach (FontFamily family in FontFamily.Families)
- {
- using (var fi = new FontInfo(family, 10, FontStyle.Regular))
- {
- if (!fontNames.Contains(family.Name) && fi.CanCreateFont())
- {
- fontNames.Add(family.Name);
- }
- }
- }
- }
-
- _staticFontNames = fontNames;
- Tracing.LogFeature("PopulateFonts()");
- }
-
- public event EventHandler FontInfoChanged;
- protected virtual void OnFontInfoChanged()
- {
- if (FontInfoChanged != null)
- {
- FontInfoChanged(this, EventArgs.Empty);
- }
- }
-
- public event EventHandler FontAlignmentChanged;
- protected virtual void OnTextAlignmentChanged()
- {
- if (FontAlignmentChanged != null)
- {
- FontAlignmentChanged(this, EventArgs.Empty);
- }
- }
-
- public event EventHandler FontSmoothingChanged;
- protected virtual void OnFontSmoothingChanged()
- {
- if (FontSmoothingChanged != null)
- {
- FontSmoothingChanged(this, EventArgs.Empty);
- }
- }
-
- public FontSmoothing FontSmoothing
- {
- get
- {
- return (FontSmoothing)_fontSmoothingLocalizer.LocalizedNameToEnumValue((string)_fontSmoothingComboBox.SelectedItem);
- }
-
- set
- {
- if (value != FontSmoothing)
- {
- _fontSmoothingComboBox.SelectedItem = _fontSmoothingLocalizer.EnumValueToLocalizedName(value);
- }
- }
- }
-
- public FontInfo FontInfo
- {
- get
- {
- return new FontInfo(FontFamily, FontSize, FontStyle);
- }
-
- set
- {
- FontFamily = value.FontFamily;
- FontSize = value.Size;
- FontStyle = value.FontStyle;
- }
- }
-
- /// <summary>
- /// Gets or sets the font style i.e. bold, italic, and underline
- /// </summary>
- public FontStyle FontStyle
- {
- get
- {
- return _fontStyle;
- }
-
- set
- {
- if (_fontStyle == value) return;
- _fontStyle = value;
- SetFontStyleButtons(FontStyle);
- OnFontInfoChanged();
- }
- }
-
- /// <summary>
- /// Gets or sets the size of the font.
- /// </summary>
- public float FontSize
- {
- get
- {
- bool invalid = false;
- float number = _oldSizeValue;
-
- try
- {
- number = float.Parse(_fontSizeComboBox.Text);
- }
-
- catch (FormatException)
- {
- invalid = true;
- }
-
- catch (OverflowException)
- {
- invalid = true;
- }
-
- // if the size is valid update the new size else return the last known good size.
- if (!invalid)
- {
- _oldSizeValue = number;
- }
-
- return _oldSizeValue;
- }
-
- set
- {
- bool invalid = false;
- float number = _oldSizeValue;
-
- try
- {
- number = float.Parse(_fontSizeComboBox.Text);
- }
-
- catch (FormatException)
- {
- invalid = true;
- }
-
- catch (OverflowException)
- {
- invalid = true;
- }
-
- // if the size is valid update the new size else return the last known good size.
- if (invalid) return;
- if (float.Parse(_fontSizeComboBox.Text) == value) return;
- _fontSizeComboBox.Text = value.ToString();
- OnFontInfoChanged();
- }
- }
-
- private FontFamily IndexToFontFamily(int i)
- {
- try
- {
- return new FontFamily((string)_fontFamilyComboBox.Items[i]);
- }
-
- catch (Exception)
- {
- return FontFamily.GenericSansSerif;
- }
- }
-
- private Font IndexToFont(int i, float size, FontStyle style)
- {
- using (FontFamily ff = IndexToFontFamily(i))
- {
- return new FontInfo(ff, size, style).CreateFont();
- }
- }
-
- /// <summary>
- /// Gets or sets the font family.
- /// </summary>
- public FontFamily FontFamily
- {
- get
- {
- try
- {
- return new FontFamily((string)_fontFamilyComboBox.SelectedItem);
- }
-
- catch (ArgumentException)
- {
- return FontFamily.GenericSansSerif;
- }
- }
-
- set
- {
- var current = (string)_fontFamilyComboBox.SelectedItem;
-
- if (current == value.Name)
- {
- }
- else
- {
- int index = _fontFamilyComboBox.Items.IndexOf(value.Name);
-
- if (index != -1)
- {
- _fontFamilyComboBox.SelectedIndex = index;
- OnFontInfoChanged();
- }
- else
- {
- // Maybe they're just specifying a font we didn't add to the list yet? aka pre-list initialization
- FontInfo oldFI = FontInfo;
-
- FontFamily newFF;
- try
- {
- newFF = new FontFamily(value.Name);
- }
-
- catch (Exception)
- {
- newFF = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
- }
-
- var newFI = new FontInfo(newFF, oldFI.Size, oldFI.FontStyle);
-
- if (newFI.CanCreateFont())
- {
- _fontFamilyComboBox.Items.Add(value.Name);
- _fontFamilyComboBox.SelectedItem = value.Name;
- }
- else
- {
- throw new InvalidOperationException("FontFamily is not valid");
- }
- }
- }
- }
- }
-
- public TextAlignment FontAlignment
- {
- get
- {
- return _alignment;
- }
- set
- {
- if (_alignment == value) return;
- _alignment = value;
-
- // if the user sets the text alignment the buttons must be updated
- if (_alignment == TextAlignment.Left)
- {
- _fontAlignLeftButton.Checked = true;
- _fontAlignCenterButton.Checked = false;
- _fontAlignRightButton.Checked = false;
- }
- else if (_alignment == TextAlignment.Center)
- {
- _fontAlignLeftButton.Checked = false;
- _fontAlignCenterButton.Checked = true;
- _fontAlignRightButton.Checked = false;
- }
- else if (_alignment == TextAlignment.Right)
- {
- _fontAlignLeftButton.Checked = false;
- _fontAlignCenterButton.Checked = false;
- _fontAlignRightButton.Checked = true;
- }
- else
- {
- throw new InvalidOperationException("Text alignment type is invalid");
- }
-
- OnTextAlignmentChanged();
- }
- }
-
- private void FontFamilyComboBoxDrawItem(object sender, DrawItemEventArgs e)
- {
- if (e.Index != -1)
- {
- var displayText = (string)_fontFamilyComboBox.Items[e.Index];
-
- SizeF stringSize = e.Graphics.MeasureString(displayText, _arialFontBase);
- var size = (int)stringSize.Width;
-
- // set up two areas to draw
- const int leftMargin = 3;
- Rectangle bounds = e.Bounds;
- bounds.X += leftMargin;
- bounds.Width -= leftMargin;
-
- Rectangle r = bounds;
-
- Rectangle rd = r;
- rd.Width = rd.Left + size;
-
- Rectangle rt = r;
- r.X = rd.Right;
-
- using (Font myFont = IndexToFont(e.Index, 10, FontStyle.Regular))
- {
- var sf = (StringFormat)StringFormat.GenericTypographic.Clone();
- sf.LineAlignment = StringAlignment.Center;
- sf.FormatFlags &= ~StringFormatFlags.LineLimit;
- sf.FormatFlags |= StringFormatFlags.NoWrap;
-
- bool isSymbol = Fonts.IsSymbolFont(myFont);
- bool isSelected = ((e.State & DrawItemState.Selected) != 0);
- Brush fillBrush;
- Brush textBrush;
-
- if (isSelected)
- {
- fillBrush = _highlightBrush;
- textBrush = _highlightTextBrush;
- }
- else
- {
- fillBrush = _windowBrush;
- textBrush = _windowTextBrush;
- }
-
- e.Graphics.FillRectangle(fillBrush, e.Bounds);
-
- if (isSymbol)
- {
- e.Graphics.DrawString(displayText, _arialFontBase, textBrush, bounds, sf);
- e.Graphics.DrawString(displayText, myFont, textBrush, r, sf);
- }
- else
- {
- e.Graphics.DrawString(displayText, myFont, textBrush, bounds, sf);
- }
-
- sf.Dispose();
- sf = null;
- }
- }
-
- e.DrawFocusRectangle();
- }
-
- private void FontFamilyComboBoxMeasureItem(object sender, MeasureItemEventArgs e)
- {
- // Work out what the text will be
- var displayText = (string)_fontFamilyComboBox.Items[e.Index];
-
- // Get width & height of string
- SizeF stringSize;
- using (Font font = IndexToFont(e.Index, 10, FontStyle.Regular))
- {
- stringSize = e.Graphics.MeasureString(displayText, font);
- }
-
- // Account for top margin
- stringSize.Height += UI.ScaleHeight(6);
-
- // set hight to text height
- e.ItemHeight = (int)stringSize.Height;
- int maxHeight = UI.ScaleHeight(20);
-
- if (e.ItemHeight > maxHeight)
- {
- e.ItemHeight = maxHeight;
- }
-
- // set width to text width
- e.ItemWidth = (int)stringSize.Width;
- }
-
- private void FontSizeComboBoxValidating(object sender, CancelEventArgs e)
- {
- try
- {
- bool invalid = false;
-
- try
- {
- float number = float.Parse(_fontSizeComboBox.Text);
- }
-
- catch (FormatException)
- {
- invalid = true;
- }
-
- catch (OverflowException)
- {
- invalid = true;
- }
-
- if (invalid)
- {
- _fontSizeComboBox.BackColor = Color.Red;
- _fontSizeComboBox.ToolTipText = PdnResources.GetString("TextConfigWidget.Error.InvalidNumber");
- }
- else
- {
- if ((float.Parse(_fontSizeComboBox.Text) < MinFontSize))
- {
- // Set the error if the size is too small.
- _fontSizeComboBox.BackColor = Color.Red;
- string format = PdnResources.GetString("TextConfigWidget.Error.TooSmall.Format");
- string text = string.Format(format, MinFontSize);
- _fontSizeComboBox.ToolTipText = text;
- }
- else if ((float.Parse(_fontSizeComboBox.Text) > MaxFontSize))
- {
- // Set the error if the size is too large.
- _fontSizeComboBox.BackColor = Color.Red;
- string format = PdnResources.GetString("TextConfigWidget.Error.TooLarge.Format");
- string text = string.Format(format, MaxFontSize);
- _fontSizeComboBox.ToolTipText = text;
- }
- else
- {
- // Clear the error, if any
- _fontSizeComboBox.ToolTipText = string.Empty;
- _fontSizeComboBox.BackColor = SystemColors.Window;
- OnFontInfoChanged();
- }
- }
- }
-
- catch (FormatException)
- {
- e.Cancel = true;
- }
- }
-
- private void FontSizeComboBoxTextChanged(object sender, EventArgs e)
- {
- FontSizeComboBoxValidating(sender, new CancelEventArgs());
- }
-
- private void FontFamilyComboBoxSelectedIndexChanged(object sender, EventArgs e)
- {
- OnFontInfoChanged();
- }
-
- private void FontFamilyComboBoxGotFocus(object sender, EventArgs e)
- {
- if (_fontsComboBoxPopulated) return;
- AsyncInitFontNames();
-
- using (new WaitCursorChanger(this))
- {
- StaticFontNamesPopulatedEvent.WaitOne();
-
- if (_fontFamilyComboBox.ComboBox != null) _fontFamilyComboBox.ComboBox.BeginUpdate();
- List<string> fontNames = _staticFontNames;
-
- foreach (string name in fontNames.Where(name => !_fontFamilyComboBox.Items.Contains(name)))
- {
- _fontFamilyComboBox.Items.Add(name);
- }
-
- if (_fontFamilyComboBox.ComboBox != null) _fontFamilyComboBox.ComboBox.EndUpdate();
- }
-
- _fontsComboBoxPopulated = true;
- }
-
- public ToolBarConfigItems ToolBarConfigItems
- {
- get
- {
- return _toolBarConfigItems;
- }
-
- set
- {
- _toolBarConfigItems = value;
-
- SuspendLayout();
-
- bool showPen = ((value & ToolBarConfigItems.Pen) != ToolBarConfigItems.None);
- _penSeparator.Visible = showPen;
- _penSizeLabel.Visible = showPen;
- _penSizeDecButton.Visible = showPen;
- _penSizeComboBox.Visible = showPen;
- _penSizeIncButton.Visible = showPen;
-
- bool showPenCaps = ((value & ToolBarConfigItems.PenCaps) != ToolBarConfigItems.None);
- _penStyleLabel.Visible = showPenCaps;
- _penStartCapSplitButton.Visible = showPenCaps;
- _penDashStyleSplitButton.Visible = showPenCaps;
- _penEndCapSplitButton.Visible = showPenCaps;
-
- bool showBrush = ((value & ToolBarConfigItems.Brush) != ToolBarConfigItems.None);
- _brushSeparator.Visible = showBrush;
- _brushStyleLabel.Visible = showBrush;
- _brushStyleComboBox.Visible = showBrush;
-
- bool showShape = ((value & ToolBarConfigItems.ShapeType) != ToolBarConfigItems.None);
- _shapeSeparator.Visible = showShape;
- _shapeButton.Visible = showShape;
-
- bool showGradient = ((value & ToolBarConfigItems.Gradient) != ToolBarConfigItems.None);
- _gradientSeparator1.Visible = showGradient;
- _gradientLinearClampedButton.Visible = showGradient;
- _gradientLinearReflectedButton.Visible = showGradient;
- _gradientLinearDiamondButton.Visible = showGradient;
- _gradientRadialButton.Visible = showGradient;
- _gradientConicalButton.Visible = showGradient;
- _gradientSeparator2.Visible = showGradient;
- _gradientChannelsSplitButton.Visible = showGradient;
-
- bool showAA = ((value & ToolBarConfigItems.Antialiasing) != ToolBarConfigItems.None);
- _antiAliasingSplitButton.Visible = showAA;
-
- bool showAB = ((value & ToolBarConfigItems.AlphaBlending) != ToolBarConfigItems.None);
- _alphaBlendingSplitButton.Visible = showAB;
-
- bool showBlendingSep = ((value & (ToolBarConfigItems.AlphaBlending | ToolBarConfigItems.Antialiasing)) != ToolBarConfigItems.None);
- _blendingSeparator.Visible = showBlendingSep;
-
- bool showTolerance = ((value & ToolBarConfigItems.Tolerance) != ToolBarConfigItems.None);
- _toleranceSeparator.Visible = showTolerance;
- _toleranceLabel.Visible = showTolerance;
- _toleranceSliderStrip.Visible = showTolerance;
-
- bool showText = ((value & ToolBarConfigItems.Text) != ToolBarConfigItems.None);
- _fontSeparator.Visible = showText;
- _fontLabel.Visible = showText;
- _fontFamilyComboBox.Visible = showText;
- _fontSizeComboBox.Visible = showText;
- _fontSmoothingComboBox.Visible = showText;
- _fontStyleSeparator.Visible = showText;
- _fontBoldButton.Visible = showText;
- _fontItalicsButton.Visible = showText;
- _fontUnderlineButton.Visible = showText;
- _fontAlignSeparator.Visible = showText;
- _fontAlignLeftButton.Visible = showText;
- _fontAlignCenterButton.Visible = showText;
- _fontAlignRightButton.Visible = showText;
-
- if (showText && IsHandleCreated)
- {
- AsyncInitFontNames();
- }
-
- bool showResampling = ((value & ToolBarConfigItems.Resampling) != ToolBarConfigItems.None);
- _resamplingSeparator.Visible = showResampling;
- _resamplingLabel.Visible = showResampling;
- _resamplingComboBox.Visible = showResampling;
-
- bool showColorPicker = ((value & ToolBarConfigItems.ColorPickerBehavior) != ToolBarConfigItems.None);
- _colorPickerSeparator.Visible = showColorPicker;
- _colorPickerLabel.Visible = showColorPicker;
- _colorPickerComboBox.Visible = showColorPicker;
-
- bool showSelectionCombineMode = ((value & ToolBarConfigItems.SelectionCombineMode) != ToolBarConfigItems.None);
- _selectionCombineModeSeparator.Visible = showSelectionCombineMode;
- _selectionCombineModeLabel.Visible = showSelectionCombineMode;
- _selectionCombineModeSplitButton.Visible = showSelectionCombineMode;
-
- bool showFloodMode = ((value & ToolBarConfigItems.FloodMode) != ToolBarConfigItems.None);
- _floodModeSeparator.Visible = showFloodMode;
- _floodModeLabel.Visible = showFloodMode;
- _floodModeSplitButton.Visible = showFloodMode;
-
- bool showSelectionDrawMode = ((value & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None);
- _selectionDrawModeSeparator.Visible = showSelectionDrawMode;
- _selectionDrawModeModeLabel.Visible = showSelectionDrawMode;
- _selectionDrawModeSplitButton.Visible = showSelectionDrawMode;
- _selectionDrawModeWidthLabel.Visible = showSelectionDrawMode;
- _selectionDrawModeSwapButton.Visible = showSelectionDrawMode;
- _selectionDrawModeHeightLabel.Visible = showSelectionDrawMode;
- RefreshSelectionDrawModeInfoVisibilities();
-
- Visible = value != ToolBarConfigItems.None;
-
- ResumeLayout();
- PerformLayout();
- }
- }
-
- private void ToleranceSliderToleranceChanged(object sender, EventArgs e)
- {
- OnToleranceChanged();
- }
-
- public void PerformToleranceChanged()
- {
- OnToleranceChanged();
- }
-
- public float Tolerance
- {
- get
- {
- return _toleranceSlider.Tolerance;
- }
-
- set
- {
- if (value != _toleranceSlider.Tolerance)
- {
- _toleranceSlider.Tolerance = value;
- }
- }
- }
-
- public event EventHandler ToleranceChanged;
- protected void OnToleranceChanged()
- {
- if (ToleranceChanged != null)
- {
- ToleranceChanged(this, EventArgs.Empty);
- }
- }
-
- public event EventHandler ColorPickerClickBehaviorChanged;
- protected void OnColorPickerClickBehaviorChanged()
- {
- if (ColorPickerClickBehaviorChanged != null)
- {
- ColorPickerClickBehaviorChanged(this, EventArgs.Empty);
- }
- }
-
- public ColorPickerClickBehavior ColorPickerClickBehavior
- {
- get
- {
- var selectedItem = (string)_colorPickerComboBox.SelectedItem;
- var cpcb = (ColorPickerClickBehavior)_colorPickerBehaviorNames.LocalizedNameToEnumValue(selectedItem);
- return cpcb;
- }
-
- set
- {
- if (value != ColorPickerClickBehavior)
- {
- _colorPickerComboBox.SelectedItem = _colorPickerBehaviorNames.EnumValueToLocalizedName(value);
- }
- }
- }
-
- public void PerformColorPickerClickBehaviorChanged()
- {
- OnColorPickerClickBehaviorChanged();
- }
-
- private void ColorPickerComboBoxSelectedIndexChanged(object sender, EventArgs e)
- {
- OnColorPickerClickBehaviorChanged();
- }
-
- private void ResamplingComboBoxSelectedIndexChanged(object sender, EventArgs e)
- {
- OnResamplingAlgorithmChanged();
- }
-
- public event EventHandler ResamplingAlgorithmChanged;
- protected void OnResamplingAlgorithmChanged()
- {
- if (ResamplingAlgorithmChanged != null)
- {
- ResamplingAlgorithmChanged(this, EventArgs.Empty);
- }
- }
-
- public ResamplingAlgorithm ResamplingAlgorithm
- {
- get
- {
- var selectedItem = (string)_resamplingComboBox.SelectedItem;
- var ra = (ResamplingAlgorithm)_resamplingAlgorithmNames.LocalizedNameToEnumValue(selectedItem);
- return ra;
- }
-
- set
- {
- if (value == ResamplingAlgorithm) return;
- if (value != ResamplingAlgorithm.NearestNeighbor && value != ResamplingAlgorithm.Bilinear)
- {
- throw new InvalidEnumArgumentException();
- }
-
- _resamplingComboBox.SelectedItem = _resamplingAlgorithmNames.EnumValueToLocalizedName(value);
- }
- }
-
- public void PerformResamplingAlgorithmChanged()
- {
- OnResamplingAlgorithmChanged();
- }
-
- public event EventHandler SelectionCombineModeChanged;
-
- protected void OnSelectionCombineModeChanged()
- {
- if (SelectionCombineModeChanged != null)
- {
- SelectionCombineModeChanged(this, EventArgs.Empty);
- }
- }
-
- public CombineMode SelectionCombineMode
- {
- get
- {
- object tag = _selectionCombineModeSplitButton.Tag;
- CombineMode cm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
- return cm;
- }
-
- set
- {
- object tag = _selectionCombineModeSplitButton.Tag;
- CombineMode oldCm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
-
- if (tag != null && (value == oldCm)) return;
- _selectionCombineModeSplitButton.Tag = value;
- UI.SuspendControlPainting(this);
- _selectionCombineModeSplitButton.Image = GetSelectionCombineModeImage(value).Reference;
- UI.ResumeControlPainting(this);
- OnSelectionCombineModeChanged();
- Invalidate(true);
- }
- }
-
- public void PerformSelectionCombineModeChanged()
- {
- OnSelectionCombineModeChanged();
- }
-
- private static ImageResource GetSelectionCombineModeImage(CombineMode cm)
- {
- return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionCombineMode." + cm + ".png");
- }
-
- private void SelectionCombineModeSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- _selectionCombineModeSplitButton.DropDownItems.Clear();
-
- foreach (var cmMI in new[]
- {
- CombineMode.Replace, CombineMode.Union, CombineMode.Exclude, CombineMode.Intersect, CombineMode.Xor
- }.Select(cm => new ToolStripMenuItem(PdnResources.GetString("ToolConfigStrip.SelectionCombineModeSplitButton." + cm + ".Text"), GetSelectionCombineModeImage(cm).Reference, delegate(object sender2, EventArgs e2)
- {
- var asTSMI = (ToolStripMenuItem) sender2;
- var newCM = (CombineMode) asTSMI.Tag;
- SelectionCombineMode = newCM;
- }) {Tag = cm, Checked = (cm == SelectionCombineMode)}))
- {
- _selectionCombineModeSplitButton.DropDownItems.Add(cmMI);
- }
- }
-
- private static CombineMode CycleSelectionCombineMode(CombineMode mode)
- {
- CombineMode newMode;
-
- // Replace -> Union -> Exclude -> Intersect -> Xor -> Replace
-
- switch (mode)
- {
- default:
- throw new InvalidEnumArgumentException();
-
- case CombineMode.Exclude:
- newMode = CombineMode.Intersect;
- break;
-
- case CombineMode.Intersect:
- newMode = CombineMode.Xor;
- break;
-
- case CombineMode.Replace:
- newMode = CombineMode.Union;
- break;
-
- case CombineMode.Union:
- newMode = CombineMode.Exclude;
- break;
-
- case CombineMode.Xor:
- newMode = CombineMode.Replace;
- break;
- }
-
- return newMode;
- }
-
- public event EventHandler FloodModeChanged;
-
- protected void OnFloodModeChanged()
- {
- if (FloodModeChanged != null)
- {
- FloodModeChanged(this, EventArgs.Empty);
- }
- }
-
- public FloodMode FloodMode
- {
- get
- {
- object tag = _floodModeSplitButton.Tag;
- FloodMode fm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
- return fm;
- }
-
- set
- {
- object tag = _floodModeSplitButton.Tag;
- FloodMode oldFm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
-
- if (tag != null && (value == oldFm)) return;
- _floodModeSplitButton.Tag = value;
- _floodModeSplitButton.Image = GetFloodModeImage(value).Reference;
- OnFloodModeChanged();
- }
- }
-
- public void PerformFloodModeChanged()
- {
- OnFloodModeChanged();
- }
-
- private static ImageResource GetFloodModeImage(FloodMode cm)
- {
- return PdnResources.GetImageResource("Icons.ToolConfigStrip.FloodMode." + cm + ".png");
- }
-
- private void FloodModeSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- _floodModeSplitButton.DropDownItems.Clear();
-
- foreach (var fmMI in new[]
- {
- FloodMode.Local, FloodMode.Global
- }.Select(fm => new ToolStripMenuItem(PdnResources.GetString("ToolConfigStrip.FloodModeSplitButton." + fm + ".Text"), GetFloodModeImage(fm).Reference, delegate(object sender2, EventArgs e2)
- {
- var asTSMI = (ToolStripMenuItem) sender2;
- var newFM = (FloodMode) asTSMI.Tag;
- FloodMode = newFM;
- }) {Tag = fm, Checked = (fm == FloodMode)}))
- {
- _floodModeSplitButton.DropDownItems.Add(fmMI);
- }
- }
-
- private static FloodMode CycleFloodMode(FloodMode mode)
- {
- FloodMode newMode;
-
- switch (mode)
- {
- default:
- throw new InvalidEnumArgumentException();
-
- case FloodMode.Global:
- newMode = FloodMode.Local;
- break;
-
- case FloodMode.Local:
- newMode = FloodMode.Global;
- break;
- }
-
- return newMode;
- }
-
- public event EventHandler SelectionDrawModeInfoChanged;
-
- protected void OnSelectionDrawModeInfoChanged()
- {
- if (SelectionDrawModeInfoChanged != null)
- {
- SelectionDrawModeInfoChanged(this, EventArgs.Empty);
- }
- }
-
- // syncs SelectionDrawModeInfo into the controls
- private void SyncSelectionDrawModeInfoUI()
- {
- _selectionDrawModeSplitButton.Text = GetSelectionDrawModeString(_selectionDrawModeInfo.DrawMode);
- _selectionDrawModeSplitButton.Image = GetSelectionDrawModeImage(_selectionDrawModeInfo.DrawMode);
-
- _selectionDrawModeWidthTextBox.Text = _selectionDrawModeInfo.Width.ToString();
-
- _selectionDrawModeHeightTextBox.Text = _selectionDrawModeInfo.Height.ToString();
-
- _selectionDrawModeUnits.UnitsChanged -= SelectionDrawModeUnitsUnitsChanged;
- _selectionDrawModeUnits.Units = _selectionDrawModeInfo.Units;
- _selectionDrawModeUnits.UnitsChanged += SelectionDrawModeUnitsUnitsChanged;
-
- RefreshSelectionDrawModeInfoVisibilities();
- }
-
- private void RefreshSelectionDrawModeInfoVisibilities()
- {
- if (_selectionDrawModeInfo == null) return;
- SuspendLayout();
-
- bool anyVisible = (ToolBarConfigItems & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None;
-
- _selectionDrawModeModeLabel.Visible = false;
-
- bool showWidthHeight = anyVisible & (_selectionDrawModeInfo.DrawMode != SelectionDrawMode.Normal);
-
- _selectionDrawModeWidthTextBox.Visible = showWidthHeight;
- _selectionDrawModeHeightTextBox.Visible = showWidthHeight;
- _selectionDrawModeWidthLabel.Visible = showWidthHeight;
- _selectionDrawModeHeightLabel.Visible = showWidthHeight;
- _selectionDrawModeSwapButton.Visible = showWidthHeight;
-
- _selectionDrawModeUnits.Visible = anyVisible & (_selectionDrawModeInfo.DrawMode == SelectionDrawMode.FixedSize);
-
- ResumeLayout(false);
- PerformLayout();
- }
-
- public SelectionDrawModeInfo SelectionDrawModeInfo
- {
- get
- {
- return (_selectionDrawModeInfo ?? SelectionDrawModeInfo.CreateDefault()).Clone();
- }
-
- set
- {
- if (_selectionDrawModeInfo != null && _selectionDrawModeInfo.Equals(value)) return;
- _selectionDrawModeInfo = value.Clone();
- OnSelectionDrawModeInfoChanged();
- SyncSelectionDrawModeInfoUI();
- }
- }
-
- public void PerformSelectionDrawModeInfoChanged()
- {
- OnSelectionDrawModeInfoChanged();
- }
-
- private static string GetSelectionDrawModeString(SelectionDrawMode drawMode)
- {
- return PdnResources.GetString("ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode + ".Text");
- }
-
- private static Image GetSelectionDrawModeImage(SelectionDrawMode drawMode)
- {
- return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode + ".png").Reference;
- }
-
- private void SelectionDrawModeSplitButtonDropDownOpening(object sender, EventArgs e)
- {
- _selectionDrawModeSplitButton.DropDownItems.Clear();
-
- foreach (var sdmTSMI in new[]
- {
- SelectionDrawMode.Normal, SelectionDrawMode.FixedRatio, SelectionDrawMode.FixedSize
- }.Select(sdm => new ToolStripMenuItem(GetSelectionDrawModeString(sdm), GetSelectionDrawModeImage(sdm), delegate(object sender2, EventArgs e2)
- {
- var asTSMI = (ToolStripMenuItem) sender2;
- var newSDM = (SelectionDrawMode) asTSMI.Tag;
- SelectionDrawModeInfo = SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
- }) {Tag = sdm, Checked = (sdm == SelectionDrawModeInfo.DrawMode)}))
- {
- _selectionDrawModeSplitButton.DropDownItems.Add(sdmTSMI);
- }
- }
-
- private static SelectionDrawMode CycleSelectionDrawMode(SelectionDrawMode drawMode)
- {
- SelectionDrawMode newSDM;
-
- switch (drawMode)
- {
- case SelectionDrawMode.Normal:
- newSDM = SelectionDrawMode.FixedRatio;
- break;
-
- case SelectionDrawMode.FixedRatio:
- newSDM = SelectionDrawMode.FixedSize;
- break;
-
- case SelectionDrawMode.FixedSize:
- newSDM = SelectionDrawMode.Normal;
- break;
-
- default:
- throw new InvalidEnumArgumentException();
- }
-
- return newSDM;
- }
-
- private void SelectionDrawModeUnitsUnitsChanged(object sender, EventArgs e)
- {
- OnSelectionDrawModeUnitsChanging();
- SelectionDrawModeInfo = _selectionDrawModeInfo.CloneWithNewUnits(_selectionDrawModeUnits.Units);
- OnSelectionDrawModeUnitsChanged();
- }
- }
- }