PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/src/ToolConfigStrip.cs

https://bitbucket.org/tcz001/openpdn
C# | 3124 lines | 2471 code | 428 blank | 225 comment | 225 complexity | 3fcd10914ff97202e869d92fec081adf MD5 | raw file
Possible License(s): Unlicense
  1. /////////////////////////////////////////////////////////////////////////////////
  2. // Paint.NET //
  3. // Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors. //
  4. // Portions Copyright (C) Microsoft Corporation. All Rights Reserved. //
  5. // See src/Resources/Files/License.txt for full licensing and attribution //
  6. // details. //
  7. // . //
  8. /////////////////////////////////////////////////////////////////////////////////
  9. using PaintDotNet.SystemLayer;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Drawing;
  14. using System.Drawing.Drawing2D;
  15. using System.Globalization;
  16. using System.Text;
  17. using System.Threading;
  18. using System.Windows.Forms;
  19. namespace PaintDotNet
  20. {
  21. // TODO: for 4.0, refactor into smaller ToolConfigStrip "Sections"
  22. // better yet, use IndirectUI
  23. internal class ToolConfigStrip
  24. : ToolStripEx,
  25. IBrushConfig,
  26. IShapeTypeConfig,
  27. IPenConfig,
  28. IAntiAliasingConfig,
  29. IAlphaBlendingConfig,
  30. ITextConfig,
  31. IToleranceConfig,
  32. IColorPickerConfig,
  33. IGradientConfig,
  34. IResamplingConfig,
  35. ISelectionCombineModeConfig,
  36. IFloodModeConfig,
  37. ISelectionDrawModeConfig
  38. {
  39. private ToolBarConfigItems toolBarConfigItems = ToolBarConfigItems.None;
  40. private EnumLocalizer hatchStyleNames = EnumLocalizer.Create(typeof(HatchStyle));
  41. private string solidBrushText;
  42. private ImageResource shapeOutlineImage = PdnResources.GetImageResource("Icons.ShapeOutlineIcon.png");
  43. private ImageResource shapeInteriorImage = PdnResources.GetImageResource("Icons.ShapeInteriorIcon.png");
  44. private ImageResource shapeBothImage = PdnResources.GetImageResource("Icons.ShapeBothIcon.png");
  45. private ToolStripSeparator brushSeparator;
  46. private ToolStripLabel brushStyleLabel;
  47. private ToolStripComboBox brushStyleComboBox;
  48. private ToolStripSeparator shapeSeparator;
  49. private ToolStripSplitButton shapeButton;
  50. private ToolStripSeparator penSeparator;
  51. private ToolStripLabel penSizeLabel;
  52. private ToolStripButton penSizeDecButton;
  53. private ToolStripComboBox penSizeComboBox;
  54. private ToolStripButton penSizeIncButton;
  55. private ToolStripLabel penStyleLabel;
  56. private ToolStripSplitButton penStartCapSplitButton; // Tag property is used to store chosen LineCap value
  57. private ToolStripSplitButton penDashStyleSplitButton; // Tag property is used to store chosen DashStyle value
  58. private ToolStripSplitButton penEndCapSplitButton; // Tag property is used to store chosen LineCap value
  59. private EnumLocalizer lineCapLocalizer = EnumLocalizer.Create(typeof(LineCap2));
  60. private EnumLocalizer dashStyleLocalizer = EnumLocalizer.Create(typeof(DashStyle));
  61. private ToolStripSeparator blendingSeparator;
  62. private ToolStripSplitButton alphaBlendingSplitButton;
  63. private bool alphaBlendingEnabled = true;
  64. private ImageResource alphaBlendingEnabledImage;
  65. private ImageResource alphaBlendingOverwriteImage;
  66. private ToolStripSplitButton antiAliasingSplitButton;
  67. private bool antiAliasingEnabled = true;
  68. private ImageResource antiAliasingEnabledImage;
  69. private ImageResource antiAliasingDisabledImage;
  70. private EnumLocalizer resamplingAlgorithmNames = EnumLocalizer.Create(typeof(ResamplingAlgorithm));
  71. private ToolStripSeparator resamplingSeparator;
  72. private ToolStripLabel resamplingLabel;
  73. private ToolStripComboBox resamplingComboBox;
  74. private EnumLocalizer colorPickerBehaviorNames = EnumLocalizer.Create(typeof(ColorPickerClickBehavior));
  75. private ToolStripSeparator colorPickerSeparator;
  76. private ToolStripLabel colorPickerLabel;
  77. private ToolStripComboBox colorPickerComboBox;
  78. private ToolStripSeparator toleranceSeparator;
  79. private ToolStripLabel toleranceLabel;
  80. private ToolStripControlHost toleranceSliderStrip;
  81. private ToleranceSliderControl toleranceSlider;
  82. private LineCap2[] lineCaps =
  83. new LineCap2[]
  84. {
  85. LineCap2.Flat,
  86. LineCap2.Arrow,
  87. LineCap2.ArrowFilled,
  88. LineCap2.Rounded
  89. };
  90. private DashStyle[] dashStyles =
  91. new DashStyle[]
  92. {
  93. DashStyle.Solid,
  94. DashStyle.Dash,
  95. DashStyle.DashDot,
  96. DashStyle.DashDotDot,
  97. DashStyle.Dot
  98. };
  99. private const float minPenSize = 1.0f;
  100. private const float maxPenSize = 500.0f;
  101. private int[] brushSizes =
  102. new int[]
  103. {
  104. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  105. 11, 12, 13, 14, 15, 20, 25, 30,
  106. 35, 40, 45, 50, 55, 60, 65, 70,
  107. 75, 80, 85, 90, 95, 100, 125,
  108. 150, 175, 200, 225, 250, 275, 300,
  109. 325, 350, 375, 400, 425, 450, 475,
  110. 500
  111. };
  112. private ShapeDrawType shapeDrawType;
  113. private EnumLocalizer gradientTypeNames = EnumLocalizer.Create(typeof(GradientType));
  114. private GradientInfo gradientInfo = new GradientInfo(GradientType.LinearClamped, false);
  115. private ToolStripSeparator gradientSeparator1;
  116. private ToolStripButton gradientLinearClampedButton;
  117. private ToolStripButton gradientLinearReflectedButton;
  118. private ToolStripButton gradientLinearDiamondButton;
  119. private ToolStripButton gradientRadialButton;
  120. private ToolStripButton gradientConicalButton;
  121. private ToolStripSeparator gradientSeparator2;
  122. private ToolStripSplitButton gradientChannelsSplitButton;
  123. private ImageResource gradientAllColorChannelsImage;
  124. private ImageResource gradientAlphaChannelOnlyImage;
  125. private EnumLocalizer fontSmoothingLocalizer = EnumLocalizer.Create(typeof(FontSmoothing));
  126. private const int maxFontSize = 2000;
  127. private const int minFontSize = 1;
  128. private const int initialFontSize = 12;
  129. private FontFamily arialFontFamily;
  130. private FontStyle fontStyle;
  131. private TextAlignment alignment;
  132. private float oldSizeValue;
  133. private Brush highlightBrush;
  134. private Brush highlightTextBrush;
  135. private Brush windowBrush;
  136. private Brush windowTextBrush;
  137. private Font arialFontBase;
  138. private const string arialName = "Arial";
  139. private static ManualResetEvent staticFontNamesPopulatedEvent = new ManualResetEvent(false);
  140. private static List<string> staticFontNames = null;
  141. private bool fontsComboBoxPopulated = false;
  142. private ToolStripSeparator fontSeparator;
  143. private ToolStripLabel fontLabel;
  144. private ToolStripComboBox fontFamilyComboBox;
  145. private ToolStripComboBox fontSizeComboBox;
  146. private ToolStripComboBox fontSmoothingComboBox;
  147. private ToolStripSeparator fontStyleSeparator;
  148. private ToolStripButton fontBoldButton;
  149. private ToolStripButton fontItalicsButton;
  150. private ToolStripButton fontUnderlineButton;
  151. private ToolStripSeparator fontAlignSeparator;
  152. private ToolStripButton fontAlignLeftButton;
  153. private ToolStripButton fontAlignCenterButton;
  154. private ToolStripButton fontAlignRightButton;
  155. private int[] defaultFontSizes =
  156. new int[]
  157. {
  158. 8, 9, 10, 11, 12, 14, 16, 18, 20,
  159. 22, 24, 26, 28, 36, 48, 72, 84, 96,
  160. 108, 144, 192, 216, 288
  161. };
  162. private ToolStripSeparator selectionCombineModeSeparator;
  163. private ToolStripLabel selectionCombineModeLabel;
  164. private ToolStripSplitButton selectionCombineModeSplitButton;
  165. private ToolStripSeparator floodModeSeparator;
  166. private ToolStripLabel floodModeLabel;
  167. private ToolStripSplitButton floodModeSplitButton;
  168. private SelectionDrawModeInfo selectionDrawModeInfo;
  169. private ToolStripSeparator selectionDrawModeSeparator;
  170. private ToolStripLabel selectionDrawModeModeLabel;
  171. private ToolStripSplitButton selectionDrawModeSplitButton;
  172. private ToolStripLabel selectionDrawModeWidthLabel;
  173. private ToolStripTextBox selectionDrawModeWidthTextBox;
  174. private ToolStripButton selectionDrawModeSwapButton;
  175. private ToolStripLabel selectionDrawModeHeightLabel;
  176. private ToolStripTextBox selectionDrawModeHeightTextBox;
  177. private UnitsComboBoxStrip selectionDrawModeUnits;
  178. public event EventHandler SelectionDrawModeUnitsChanging;
  179. protected void OnSelectionDrawModeUnitsChanging()
  180. {
  181. if (SelectionDrawModeUnitsChanging != null)
  182. {
  183. SelectionDrawModeUnitsChanging(this, EventArgs.Empty);
  184. }
  185. }
  186. public event EventHandler SelectionDrawModeUnitsChanged;
  187. protected void OnSelectionDrawModeUnitsChanged()
  188. {
  189. if (SelectionDrawModeUnitsChanged != null)
  190. {
  191. SelectionDrawModeUnitsChanged(this, EventArgs.Empty);
  192. }
  193. }
  194. public void LoadFromAppEnvironment(AppEnvironment appEnvironment)
  195. {
  196. AlphaBlending = appEnvironment.AlphaBlending;
  197. AntiAliasing = appEnvironment.AntiAliasing;
  198. BrushInfo = appEnvironment.BrushInfo;
  199. ColorPickerClickBehavior = appEnvironment.ColorPickerClickBehavior;
  200. GradientInfo = appEnvironment.GradientInfo;
  201. PenInfo = appEnvironment.PenInfo;
  202. ResamplingAlgorithm = appEnvironment.ResamplingAlgorithm;
  203. ShapeDrawType = appEnvironment.ShapeDrawType;
  204. FontInfo = appEnvironment.FontInfo;
  205. FontSmoothing = appEnvironment.FontSmoothing;
  206. FontAlignment = appEnvironment.TextAlignment;
  207. Tolerance = appEnvironment.Tolerance;
  208. SelectionCombineMode = appEnvironment.SelectionCombineMode;
  209. FloodMode = appEnvironment.FloodMode;
  210. SelectionDrawModeInfo = appEnvironment.SelectionDrawModeInfo;
  211. }
  212. public event EventHandler BrushInfoChanged;
  213. protected virtual void OnBrushChanged()
  214. {
  215. if (BrushInfoChanged != null)
  216. {
  217. BrushInfoChanged(this, EventArgs.Empty);
  218. }
  219. }
  220. public BrushInfo BrushInfo
  221. {
  222. get
  223. {
  224. if (this.brushStyleComboBox.SelectedItem.ToString() == this.solidBrushText)
  225. {
  226. return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
  227. }
  228. if (this.brushStyleComboBox.SelectedIndex == -1)
  229. {
  230. return new BrushInfo(BrushType.Solid, HatchStyle.BackwardDiagonal);
  231. }
  232. else
  233. {
  234. return new BrushInfo(
  235. BrushType.Hatch,
  236. (HatchStyle)this.hatchStyleNames.LocalizedNameToEnumValue(this.brushStyleComboBox.SelectedItem.ToString()));
  237. }
  238. }
  239. set
  240. {
  241. if (value.BrushType == BrushType.Solid)
  242. {
  243. this.brushStyleComboBox.SelectedItem = this.solidBrushText;
  244. }
  245. else
  246. {
  247. this.brushStyleComboBox.SelectedItem = this.hatchStyleNames.EnumValueToLocalizedName(value.HatchStyle);
  248. }
  249. }
  250. }
  251. public event EventHandler GradientInfoChanged;
  252. protected virtual void OnGradientInfoChanged()
  253. {
  254. if (GradientInfoChanged != null)
  255. {
  256. GradientInfoChanged(this, EventArgs.Empty);
  257. }
  258. }
  259. public void PerformGradientInfoChanged()
  260. {
  261. OnGradientInfoChanged();
  262. }
  263. public GradientInfo GradientInfo
  264. {
  265. get
  266. {
  267. return this.gradientInfo;
  268. }
  269. set
  270. {
  271. if (value == null)
  272. {
  273. throw new ArgumentNullException();
  274. }
  275. this.gradientInfo = value;
  276. OnGradientInfoChanged();
  277. SyncGradientInfo();
  278. }
  279. }
  280. private void SyncGradientInfo()
  281. {
  282. this.gradientConicalButton.Checked = false;
  283. this.gradientRadialButton.Checked = false;
  284. this.gradientLinearClampedButton.Checked = false;
  285. this.gradientLinearReflectedButton.Checked = false;
  286. this.gradientLinearDiamondButton.Checked = false;
  287. switch (this.gradientInfo.GradientType)
  288. {
  289. case GradientType.Conical:
  290. this.gradientConicalButton.Checked = true;
  291. break;
  292. case GradientType.LinearClamped:
  293. this.gradientLinearClampedButton.Checked = true;
  294. break;
  295. case GradientType.LinearReflected:
  296. this.gradientLinearReflectedButton.Checked = true;
  297. break;
  298. case GradientType.LinearDiamond:
  299. this.gradientLinearDiamondButton.Checked = true;
  300. break;
  301. case GradientType.Radial:
  302. this.gradientRadialButton.Checked = true;
  303. break;
  304. default:
  305. throw new InvalidEnumArgumentException();
  306. }
  307. if (this.gradientInfo.AlphaOnly)
  308. {
  309. this.gradientChannelsSplitButton.Image = this.gradientAlphaChannelOnlyImage.Reference;
  310. }
  311. else
  312. {
  313. this.gradientChannelsSplitButton.Image = this.gradientAllColorChannelsImage.Reference;
  314. }
  315. }
  316. private void ShapeButton_DropDownOpening(object sender, EventArgs e)
  317. {
  318. ToolStripMenuItem outlineMI = new ToolStripMenuItem();
  319. outlineMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.OutlineButton.ToolTipText");
  320. outlineMI.Image = this.shapeOutlineImage.Reference;
  321. outlineMI.Tag = (object)ShapeDrawType.Outline;
  322. outlineMI.Click += new EventHandler(ShapeMI_Click);
  323. ToolStripMenuItem interiorMI = new ToolStripMenuItem();
  324. interiorMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.InteriorButton.ToolTipText");
  325. interiorMI.Image = this.shapeInteriorImage.Reference;
  326. interiorMI.Tag = (object)ShapeDrawType.Interior;
  327. interiorMI.Click += new EventHandler(ShapeMI_Click);
  328. ToolStripMenuItem bothMI = new ToolStripMenuItem();
  329. bothMI.Text = PdnResources.GetString("ShapeDrawTypeConfigWidget.BothButton.ToolTipText");
  330. bothMI.Image = this.shapeBothImage.Reference;
  331. bothMI.Tag = (object)ShapeDrawType.Both;
  332. bothMI.Click += new EventHandler(ShapeMI_Click);
  333. switch (this.shapeDrawType)
  334. {
  335. case ShapeDrawType.Outline:
  336. outlineMI.Checked = true;
  337. break;
  338. case ShapeDrawType.Interior:
  339. interiorMI.Checked = true;
  340. break;
  341. case ShapeDrawType.Both:
  342. bothMI.Checked = true;
  343. break;
  344. default:
  345. throw new InvalidEnumArgumentException();
  346. }
  347. this.shapeButton.DropDownItems.AddRange(
  348. new ToolStripItem[]
  349. {
  350. outlineMI,
  351. interiorMI,
  352. bothMI
  353. });
  354. }
  355. private void ShapeMI_Click(object sender, EventArgs e)
  356. {
  357. ShapeDrawType sdt = (ShapeDrawType)((ToolStripMenuItem)sender).Tag;
  358. Tracing.LogFeature("ToolConfigStrip(" + sdt.ToString() + ")");
  359. this.ShapeDrawType = sdt;
  360. }
  361. public ToolConfigStrip()
  362. {
  363. SuspendLayout();
  364. InitializeComponent();
  365. this.solidBrushText = PdnResources.GetString("BrushConfigWidget.SolidBrush.Text"); // "Solid Brush"
  366. this.brushStyleComboBox.Items.Add(this.solidBrushText);
  367. string[] styleNames = this.hatchStyleNames.GetLocalizedNames();
  368. Array.Sort(styleNames);
  369. foreach (string styleName in styleNames)
  370. {
  371. brushStyleComboBox.Items.Add(styleName);
  372. }
  373. brushStyleComboBox.SelectedIndex = 0;
  374. this.brushStyleLabel.Text = PdnResources.GetString("BrushConfigWidget.FillStyleLabel.Text");
  375. this.shapeDrawType = ShapeDrawType.Outline;
  376. this.shapeButton.Image = this.shapeOutlineImage.Reference;
  377. this.penSizeLabel.Text = PdnResources.GetString("PenConfigWidget.BrushWidthLabel");
  378. this.penSizeComboBox.ComboBox.SuspendLayout();
  379. for (int i = 0; i < this.brushSizes.Length; ++i)
  380. {
  381. this.penSizeComboBox.Items.Add(this.brushSizes[i].ToString());
  382. }
  383. this.penSizeComboBox.ComboBox.ResumeLayout(false);
  384. this.penSizeComboBox.SelectedIndex = 1; // default to brush size of 2
  385. this.penSizeDecButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeDecButton.ToolTipText");
  386. this.penSizeDecButton.Image = PdnResources.GetImageResource("Icons.MinusButtonIcon.png").Reference;
  387. this.penSizeIncButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenSizeIncButton.ToolTipText");
  388. this.penSizeIncButton.Image = PdnResources.GetImageResource("Icons.PlusButtonIcon.png").Reference;
  389. this.penStyleLabel.Text = PdnResources.GetString("ToolConfigStrip.PenStyleLabel.Text");
  390. this.penStartCapSplitButton.Tag = PenInfo.DefaultLineCap;
  391. this.penStartCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, true).Reference;
  392. this.penStartCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenStartCapSplitButton.ToolTipText");
  393. this.penDashStyleSplitButton.Tag = PenInfo.DefaultDashStyle;
  394. this.penDashStyleSplitButton.Image = GetDashStyleImage(PenInfo.DefaultDashStyle);
  395. this.penDashStyleSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenDashStyleSplitButton.ToolTipText");
  396. this.penEndCapSplitButton.Tag = PenInfo.DefaultLineCap;
  397. this.penEndCapSplitButton.Image = GetLineCapImage(PenInfo.DefaultLineCap, false).Reference;
  398. this.penEndCapSplitButton.ToolTipText = PdnResources.GetString("ToolConfigStrip.PenEndCapSplitButton.ToolTipText");
  399. this.gradientLinearClampedButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearClamped);
  400. this.gradientLinearClampedButton.Image = PdnResources.GetImageResource("Icons.LinearClampedGradientIcon.png").Reference;
  401. this.gradientLinearReflectedButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearReflected);
  402. this.gradientLinearReflectedButton.Image = PdnResources.GetImageResource("Icons.LinearReflectedGradientIcon.png").Reference;
  403. this.gradientLinearDiamondButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.LinearDiamond);
  404. this.gradientLinearDiamondButton.Image = PdnResources.GetImageResource("Icons.LinearDiamondGradientIcon.png").Reference;
  405. this.gradientRadialButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.Radial);
  406. this.gradientRadialButton.Image = PdnResources.GetImageResource("Icons.RadialGradientIcon.png").Reference;
  407. this.gradientConicalButton.ToolTipText = this.gradientTypeNames.EnumValueToLocalizedName(GradientType.Conical);
  408. this.gradientConicalButton.Image = PdnResources.GetImageResource("Icons.ConicalGradientIcon.png").Reference;
  409. this.gradientAllColorChannelsImage = PdnResources.GetImageResource("Icons.AllColorChannelsIcon.png");
  410. this.gradientAlphaChannelOnlyImage = PdnResources.GetImageResource("Icons.AlphaChannelOnlyIcon.png");
  411. this.gradientChannelsSplitButton.Image = this.gradientAllColorChannelsImage.Reference;
  412. this.antiAliasingEnabledImage = PdnResources.GetImageResource("Icons.AntiAliasingEnabledIcon.png");
  413. this.antiAliasingDisabledImage = PdnResources.GetImageResource("Icons.AntiAliasingDisabledIcon.png");
  414. this.antiAliasingSplitButton.Image = this.antiAliasingEnabledImage.Reference;
  415. this.alphaBlendingEnabledImage = PdnResources.GetImageResource("Icons.BlendingEnabledIcon.png");
  416. this.alphaBlendingOverwriteImage = PdnResources.GetImageResource("Icons.BlendingOverwriteIcon.png");
  417. this.alphaBlendingSplitButton.Image = this.alphaBlendingEnabledImage.Reference;
  418. this.penSizeComboBox.Size = new Size(UI.ScaleWidth(this.penSizeComboBox.Width), penSizeComboBox.Height);
  419. this.brushStyleComboBox.Size = new Size(UI.ScaleWidth(this.brushStyleComboBox.Width), brushStyleComboBox.Height);
  420. this.brushStyleComboBox.DropDownWidth = UI.ScaleWidth(this.brushStyleComboBox.DropDownWidth);
  421. this.brushStyleComboBox.DropDownHeight = UI.ScaleHeight(this.brushStyleComboBox.DropDownHeight);
  422. this.toleranceLabel.Text = PdnResources.GetString("ToleranceConfig.ToleranceLabel.Text");
  423. this.toleranceSlider.Tolerance = 0.5f;
  424. this.fontSizeComboBox.ComboBox.SuspendLayout();
  425. for (int i = 0; i < this.defaultFontSizes.Length; ++i)
  426. {
  427. this.fontSizeComboBox.Items.Add(this.defaultFontSizes[i].ToString());
  428. }
  429. this.fontSizeComboBox.ComboBox.ResumeLayout(false);
  430. this.fontSmoothingComboBox.Items.AddRange(
  431. new object[]
  432. {
  433. this.fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Smooth),
  434. this.fontSmoothingLocalizer.EnumValueToLocalizedName(FontSmoothing.Sharp)
  435. });
  436. this.fontSmoothingComboBox.SelectedIndex = 0;
  437. this.fontLabel.Text = PdnResources.GetString("TextConfigWidget.FontLabel.Text");
  438. try
  439. {
  440. this.arialFontFamily = new FontFamily(arialName);
  441. }
  442. catch (Exception)
  443. {
  444. this.arialFontFamily = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
  445. }
  446. try
  447. {
  448. this.arialFontBase = new Font(arialFontFamily, initialFontSize, FontStyle.Regular);
  449. }
  450. catch (Exception)
  451. {
  452. this.arialFontBase = new Font(FontFamily.GenericSansSerif, initialFontSize, FontStyle.Regular);
  453. }
  454. this.fontFamilyComboBox.ComboBox.DropDownHeight = 600;
  455. this.alignment = TextAlignment.Left;
  456. this.fontAlignLeftButton.Checked = true;
  457. this.oldSizeValue = initialFontSize;
  458. this.highlightBrush = new SolidBrush(SystemColors.Highlight);
  459. this.highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
  460. this.windowBrush = new SolidBrush(SystemColors.Window);
  461. this.windowTextBrush = new SolidBrush(SystemColors.WindowText);
  462. // These buttons need a color key to maintain consistency with v2.5 language packs
  463. this.fontBoldButton.ImageTransparentColor = Utility.TransparentKey;
  464. this.fontItalicsButton.ImageTransparentColor = Utility.TransparentKey;
  465. this.fontUnderlineButton.ImageTransparentColor = Utility.TransparentKey;
  466. this.fontBoldButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontBoldIcon");
  467. this.fontItalicsButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontItalicIcon");
  468. this.fontUnderlineButton.Image = PdnResources.GetImageBmpOrPng("Icons.FontUnderlineIcon");
  469. this.fontAlignLeftButton.Image = PdnResources.GetImageResource("Icons.TextAlignLeftIcon.png").Reference;
  470. this.fontAlignCenterButton.Image = PdnResources.GetImageResource("Icons.TextAlignCenterIcon.png").Reference;
  471. this.fontAlignRightButton.Image = PdnResources.GetImageResource("Icons.TextAlignRightIcon.png").Reference;
  472. this.fontBoldButton.ToolTipText = PdnResources.GetString("TextConfigWidget.BoldButton.ToolTipText");
  473. this.fontItalicsButton.ToolTipText = PdnResources.GetString("TextConfigWidget.ItalicButton.ToolTipText");
  474. this.fontUnderlineButton.ToolTipText = PdnResources.GetString("TextConfigWidget.UnderlineButton.ToolTipText");
  475. this.fontAlignLeftButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignLeftButton.ToolTipText");
  476. this.fontAlignCenterButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignCenterButton.ToolTipText");
  477. this.fontAlignRightButton.ToolTipText = PdnResources.GetString("TextConfigWidget.AlignRightButton.ToolTipText");
  478. this.fontFamilyComboBox.Size = new Size(UI.ScaleWidth(this.fontFamilyComboBox.Width), fontFamilyComboBox.Height);
  479. this.fontFamilyComboBox.DropDownWidth = UI.ScaleWidth(this.fontFamilyComboBox.DropDownWidth);
  480. this.fontSizeComboBox.Size = new Size(UI.ScaleWidth(this.fontSizeComboBox.Width), fontSizeComboBox.Height);
  481. this.fontSmoothingComboBox.Size = new Size(UI.ScaleWidth(this.fontSmoothingComboBox.Width), fontSmoothingComboBox.Height);
  482. this.fontSmoothingComboBox.DropDownWidth = UI.ScaleWidth(this.fontSmoothingComboBox.DropDownWidth);
  483. this.resamplingLabel.Text = PdnResources.GetString("ToolConfigStrip.ResamplingLabel.Text");
  484. this.resamplingComboBox.BeginUpdate();
  485. this.resamplingComboBox.Items.Add(this.resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.Bilinear));
  486. this.resamplingComboBox.Items.Add(this.resamplingAlgorithmNames.EnumValueToLocalizedName(ResamplingAlgorithm.NearestNeighbor));
  487. this.resamplingComboBox.EndUpdate();
  488. this.resamplingComboBox.SelectedIndex = 0; // bilinear
  489. this.resamplingComboBox.Size = new Size(UI.ScaleWidth(this.resamplingComboBox.Width), resamplingComboBox.Height);
  490. this.resamplingComboBox.DropDownWidth = UI.ScaleWidth(this.resamplingComboBox.DropDownWidth);
  491. this.colorPickerLabel.Text = PdnResources.GetString("ToolConfigStrip.ColorPickerLabel.Text");
  492. string[] colorPickerBehaviorNames = this.colorPickerBehaviorNames.GetLocalizedNames();
  493. // Make sure these items are sorted to be in the order specified by the enumeration
  494. Array.Sort<string>(
  495. colorPickerBehaviorNames,
  496. delegate(string lhs, string rhs)
  497. {
  498. ColorPickerClickBehavior lhsE = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(lhs);
  499. ColorPickerClickBehavior rhsE = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(rhs);
  500. if ((int)lhsE < (int)rhsE)
  501. {
  502. return -1;
  503. }
  504. else if ((int)lhsE > (int)rhsE)
  505. {
  506. return +1;
  507. }
  508. else
  509. {
  510. return 0;
  511. }
  512. });
  513. this.colorPickerComboBox.Items.AddRange(colorPickerBehaviorNames);
  514. this.colorPickerComboBox.SelectedIndex = 0;
  515. this.colorPickerComboBox.Size = new Size(UI.ScaleWidth(this.colorPickerComboBox.Width), colorPickerComboBox.Height);
  516. this.colorPickerComboBox.DropDownWidth = UI.ScaleWidth(this.colorPickerComboBox.DropDownWidth);
  517. this.toleranceSlider.Size = UI.ScaleSize(this.toleranceSlider.Size);
  518. this.selectionCombineModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionCombineModeLabel.Text");
  519. this.floodModeLabel.Text = PdnResources.GetString("ToolConfigStrip.FloodModeLabel.Text");
  520. this.selectionDrawModeModeLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeLabel.Text");
  521. this.selectionDrawModeWidthLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeWidthLabel.Text");
  522. this.selectionDrawModeHeightLabel.Text = PdnResources.GetString("ToolConfigStrip.SelectionDrawModeHeightLabel.Text");
  523. this.selectionDrawModeSwapButton.Image = PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSwapButton.png").Reference;
  524. this.selectionDrawModeWidthTextBox.Size = new Size(UI.ScaleWidth(this.selectionDrawModeWidthTextBox.Width), this.selectionDrawModeWidthTextBox.Height);
  525. this.selectionDrawModeHeightTextBox.Size = new Size(UI.ScaleWidth(this.selectionDrawModeHeightTextBox.Width), this.selectionDrawModeHeightTextBox.Height);
  526. this.selectionDrawModeUnits.Size = new Size(UI.ScaleWidth(this.selectionDrawModeUnits.Width), this.selectionDrawModeUnits.Height);
  527. ToolBarConfigItems = ToolBarConfigItems.None;
  528. ResumeLayout(false);
  529. }
  530. private void AsyncInitFontNames()
  531. {
  532. if (!IsHandleCreated)
  533. {
  534. CreateControl();
  535. }
  536. if (!this.fontFamilyComboBox.ComboBox.IsHandleCreated)
  537. {
  538. this.fontFamilyComboBox.ComboBox.CreateControl();
  539. }
  540. if (staticFontNames == null)
  541. {
  542. ThreadPool.QueueUserWorkItem(new WaitCallback(this.PopulateFontsBackgroundThread), null);
  543. }
  544. }
  545. protected override void OnHandleCreated(EventArgs e)
  546. {
  547. if ((this.toolBarConfigItems & ToolBarConfigItems.Text) == ToolBarConfigItems.Text)
  548. {
  549. AsyncInitFontNames();
  550. }
  551. base.OnHandleCreated(e);
  552. }
  553. private void InitializeComponent()
  554. {
  555. this.brushSeparator = new ToolStripSeparator();
  556. this.brushStyleLabel = new ToolStripLabel();
  557. this.brushStyleComboBox = new ToolStripComboBox();
  558. this.shapeSeparator = new ToolStripSeparator();
  559. this.shapeButton = new ToolStripSplitButton();
  560. this.gradientSeparator1 = new ToolStripSeparator();
  561. this.gradientLinearClampedButton = new ToolStripButton();
  562. this.gradientLinearReflectedButton = new ToolStripButton();
  563. this.gradientLinearDiamondButton = new ToolStripButton();
  564. this.gradientRadialButton = new ToolStripButton();
  565. this.gradientConicalButton = new ToolStripButton();
  566. this.gradientSeparator2 = new ToolStripSeparator();
  567. this.gradientChannelsSplitButton = new ToolStripSplitButton();
  568. this.penSeparator = new ToolStripSeparator();
  569. this.penSizeLabel = new ToolStripLabel();
  570. this.penSizeDecButton = new ToolStripButton();
  571. this.penSizeComboBox = new ToolStripComboBox();
  572. this.penSizeIncButton = new ToolStripButton();
  573. this.penStyleLabel = new ToolStripLabel();
  574. this.penStartCapSplitButton = new ToolStripSplitButton();
  575. this.penDashStyleSplitButton = new ToolStripSplitButton();
  576. this.penEndCapSplitButton = new ToolStripSplitButton();
  577. this.blendingSeparator = new ToolStripSeparator();
  578. this.antiAliasingSplitButton = new ToolStripSplitButton();
  579. this.alphaBlendingSplitButton = new ToolStripSplitButton();
  580. this.toleranceSeparator = new ToolStripSeparator();
  581. this.toleranceLabel = new ToolStripLabel();
  582. this.toleranceSlider = new ToleranceSliderControl();
  583. this.toleranceSliderStrip = new ToolStripControlHost(this.toleranceSlider);
  584. this.fontSeparator = new ToolStripSeparator();
  585. this.fontLabel = new ToolStripLabel();
  586. this.fontFamilyComboBox = new ToolStripComboBox();
  587. this.fontSizeComboBox = new ToolStripComboBox();
  588. this.fontSmoothingComboBox = new ToolStripComboBox();
  589. this.fontStyleSeparator = new ToolStripSeparator();
  590. this.fontBoldButton = new ToolStripButton();
  591. this.fontItalicsButton = new ToolStripButton();
  592. this.fontUnderlineButton = new ToolStripButton();
  593. this.fontAlignSeparator = new ToolStripSeparator();
  594. this.fontAlignLeftButton = new ToolStripButton();
  595. this.fontAlignCenterButton = new ToolStripButton();
  596. this.fontAlignRightButton = new ToolStripButton();
  597. this.resamplingSeparator = new ToolStripSeparator();
  598. this.resamplingLabel = new ToolStripLabel();
  599. this.resamplingComboBox = new ToolStripComboBox();
  600. this.colorPickerSeparator = new ToolStripSeparator();
  601. this.colorPickerLabel = new ToolStripLabel();
  602. this.colorPickerComboBox = new ToolStripComboBox();
  603. this.selectionCombineModeSeparator = new ToolStripSeparator();
  604. this.selectionCombineModeLabel = new ToolStripLabel();
  605. this.selectionCombineModeSplitButton = new ToolStripSplitButton();
  606. this.floodModeSeparator = new ToolStripSeparator();
  607. this.floodModeLabel = new ToolStripLabel();
  608. this.floodModeSplitButton = new ToolStripSplitButton();
  609. this.selectionDrawModeSeparator = new ToolStripSeparator();
  610. this.selectionDrawModeModeLabel = new ToolStripLabel();
  611. this.selectionDrawModeSplitButton = new ToolStripSplitButton();
  612. this.selectionDrawModeWidthLabel = new ToolStripLabel();
  613. this.selectionDrawModeWidthTextBox = new ToolStripTextBox();
  614. this.selectionDrawModeSwapButton = new ToolStripButton();
  615. this.selectionDrawModeHeightLabel = new ToolStripLabel();
  616. this.selectionDrawModeHeightTextBox = new ToolStripTextBox();
  617. this.selectionDrawModeUnits = new UnitsComboBoxStrip();
  618. this.SuspendLayout();
  619. //
  620. // brushStyleLabel
  621. //
  622. this.brushStyleLabel.Name = "fillStyleLabel";
  623. //
  624. // brushStyleComboBox
  625. //
  626. this.brushStyleComboBox.Name = "styleComboBox";
  627. this.brushStyleComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  628. this.brushStyleComboBox.DropDownWidth = 234;
  629. this.brushStyleComboBox.AutoSize = true;
  630. //
  631. // brushStyleComboBox.ComboBox
  632. //
  633. this.brushStyleComboBox.ComboBox.DrawMode = DrawMode.OwnerDrawVariable;
  634. this.brushStyleComboBox.ComboBox.MeasureItem += ComboBoxStyle_MeasureItem;
  635. this.brushStyleComboBox.ComboBox.SelectedValueChanged += ComboBoxStyle_SelectedValueChanged;
  636. this.brushStyleComboBox.ComboBox.DrawItem += ComboBoxStyle_DrawItem;
  637. //
  638. // shapeButton
  639. //
  640. this.shapeButton.Name = "shapeButton";
  641. this.shapeButton.DropDownOpening += new EventHandler(ShapeButton_DropDownOpening);
  642. this.shapeButton.DropDownClosed +=
  643. delegate(object sender, EventArgs e)
  644. {
  645. this.shapeButton.DropDownItems.Clear();
  646. };
  647. this.shapeButton.ButtonClick +=
  648. delegate(object sender, EventArgs e)
  649. {
  650. Tracing.LogFeature("ToolConfigStrip(shapeButton)");
  651. switch (ShapeDrawType)
  652. {
  653. case ShapeDrawType.Outline:
  654. ShapeDrawType = ShapeDrawType.Interior;
  655. break;
  656. case ShapeDrawType.Interior:
  657. ShapeDrawType = ShapeDrawType.Both;
  658. break;
  659. case ShapeDrawType.Both:
  660. ShapeDrawType = ShapeDrawType.Outline;
  661. break;
  662. default:
  663. throw new InvalidEnumArgumentException();
  664. }
  665. };
  666. //
  667. // gradientSeparator
  668. //
  669. this.gradientSeparator1.Name = "gradientSeparator";
  670. //
  671. // gradientLinearClampedButton
  672. //
  673. this.gradientLinearClampedButton.Name = "gradientLinearClampedButton";
  674. this.gradientLinearClampedButton.Click += GradientTypeButtonClicked;
  675. this.gradientLinearClampedButton.Tag = GradientType.LinearClamped;
  676. //
  677. // gradientLinearReflectedButton
  678. //
  679. this.gradientLinearReflectedButton.Name = "gradientLinearReflectedButton";
  680. this.gradientLinearReflectedButton.Click += GradientTypeButtonClicked;
  681. this.gradientLinearReflectedButton.Tag = GradientType.LinearReflected;
  682. //
  683. // gradientLinearDiamondButton
  684. //
  685. this.gradientLinearDiamondButton.Name = "gradientLinearDiamondButton";
  686. this.gradientLinearDiamondButton.Click += GradientTypeButtonClicked;
  687. this.gradientLinearDiamondButton.Tag = GradientType.LinearDiamond;
  688. //
  689. // gradientRadialButton
  690. //
  691. this.gradientRadialButton.Name = "gradientRadialButton";
  692. this.gradientRadialButton.Click += GradientTypeButtonClicked;
  693. this.gradientRadialButton.Tag = GradientType.Radial;
  694. //
  695. // gradientConicalButton
  696. //
  697. this.gradientConicalButton.Name = "gradientConicalButton";
  698. this.gradientConicalButton.Click += GradientTypeButtonClicked;
  699. this.gradientConicalButton.Tag = GradientType.Conical;
  700. //
  701. // gradientSeparator2
  702. //
  703. this.gradientSeparator2.Name = "gradientSeparator2";
  704. //
  705. // gradientChannelsSplitButton
  706. //
  707. this.gradientChannelsSplitButton.Name = "gradientChannelsSplitButton";
  708. this.gradientChannelsSplitButton.DropDownOpening += new EventHandler(GradientChannelsSplitButton_DropDownOpening);
  709. this.gradientChannelsSplitButton.DropDownClosed +=
  710. delegate(object sender, EventArgs e)
  711. {
  712. this.gradientChannelsSplitButton.DropDownItems.Clear();
  713. };
  714. this.gradientChannelsSplitButton.ButtonClick +=
  715. delegate(object sender, EventArgs e)
  716. {
  717. Tracing.LogFeature("ToolConfigStrip(gradientChannelsSplitButton)");
  718. GradientInfo = new GradientInfo(GradientInfo.GradientType, !GradientInfo.AlphaOnly);
  719. };
  720. //
  721. // penSeparator
  722. //
  723. this.penSeparator.Name = "penSeparator";
  724. //
  725. // penSizeLabel
  726. //
  727. this.penSizeLabel.Name = "brushSizeLabel";
  728. //
  729. // penSizeDecButton
  730. //
  731. this.penSizeDecButton.Name = "penSizeDecButton";
  732. this.penSizeDecButton.Click +=
  733. delegate(object sender, EventArgs e)
  734. {
  735. Tracing.LogFeature("ToolConfigStrip(penSizeDecButton)");
  736. float amount = -1.0f;
  737. if ((Control.ModifierKeys & Keys.Control) != 0)
  738. {
  739. amount *= 5.0f;
  740. }
  741. AddToPenSize(amount);
  742. };
  743. //
  744. // penSizeComboBox
  745. //
  746. this.penSizeComboBox.Name = "penSizeComboBox";
  747. this.penSizeComboBox.Validating += new CancelEventHandler(this.BrushSizeComboBox_Validating);
  748. this.penSizeComboBox.TextChanged += new EventHandler(this.SizeComboBox_TextChanged);
  749. this.penSizeComboBox.AutoSize = false;
  750. this.penSizeComboBox.Width = 44;
  751. //
  752. // penSizeIncButton
  753. //
  754. this.penSizeIncButton.Name = "penSizeIncButton";
  755. this.penSizeIncButton.Click +=
  756. delegate(object sender, EventArgs e)
  757. {
  758. Tracing.LogFeature("ToolConfigStrip(penSizeIncButton)");
  759. float amount = 1.0f;
  760. if ((Control.ModifierKeys & Keys.Control) != 0)
  761. {
  762. amount *= 5.0f;
  763. }
  764. AddToPenSize(amount);
  765. };
  766. //
  767. // penStartCapLabel
  768. //
  769. this.penStyleLabel.Name = "penStartCapLabel";
  770. //
  771. // penStartCapSplitButton
  772. //
  773. this.penStartCapSplitButton.Name = "penStartCapSplitButton";
  774. this.penStartCapSplitButton.DropDownOpening += PenCapSplitButton_DropDownOpening;
  775. this.penStartCapSplitButton.DropDownClosed +=
  776. delegate(object sender, EventArgs e)
  777. {
  778. this.penStartCapSplitButton.DropDownItems.Clear();
  779. };
  780. this.penStartCapSplitButton.ButtonClick +=
  781. delegate(object sender, EventArgs e)
  782. {
  783. Tracing.LogFeature("ToolConfigStrip(penStartCapSplitButton)");
  784. CyclePenStartCap();
  785. };
  786. //
  787. // penDashStyleSplitButton
  788. //
  789. this.penDashStyleSplitButton.Name = "penDashStyleSplitButton";
  790. this.penDashStyleSplitButton.ImageScaling = ToolStripItemImageScaling.None;
  791. this.penDashStyleSplitButton.DropDownOpening += PenDashStyleButton_DropDownOpening;
  792. this.penDashStyleSplitButton.DropDownClosed +=
  793. delegate(object sender, EventArgs e)
  794. {
  795. this.penDashStyleSplitButton.DropDownItems.Clear();
  796. };
  797. this.penDashStyleSplitButton.ButtonClick +=
  798. delegate(object sender, EventArgs e)
  799. {
  800. Tracing.LogFeature("ToolConfigStrip(penDashStyleSplitButton)");
  801. CyclePenDashStyle();
  802. };
  803. //
  804. // penEndCapSplitButton
  805. //
  806. this.penEndCapSplitButton.Name = "penEndCapSplitButton";
  807. this.penEndCapSplitButton.DropDownOpening += PenCapSplitButton_DropDownOpening;
  808. this.penEndCapSplitButton.DropDownClosed +=
  809. delegate(object sender, EventArgs e)
  810. {
  811. this.penEndCapSplitButton.DropDownItems.Clear();
  812. };
  813. this.penEndCapSplitButton.ButtonClick +=
  814. delegate(object sender, EventArgs e)
  815. {
  816. Tracing.LogFeature("ToolConfigStrip(penEndCapSplitButton)");
  817. CyclePenEndCap();
  818. };
  819. //
  820. // antiAliasingSplitButton
  821. //
  822. this.antiAliasingSplitButton.Name = "antiAliasingSplitButton";
  823. this.antiAliasingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  824. this.antiAliasingSplitButton.DropDownOpening += AntiAliasingSplitButton_DropDownOpening;
  825. this.antiAliasingSplitButton.DropDownClosed +=
  826. delegate(object sender, EventArgs e)
  827. {
  828. this.antiAliasingSplitButton.DropDownItems.Clear();
  829. };
  830. this.antiAliasingSplitButton.ButtonClick +=
  831. delegate(object sender, EventArgs e)
  832. {
  833. Tracing.LogFeature("ToolConfigStrip(antiAliasingSplitButton)");
  834. AntiAliasing = !AntiAliasing;
  835. };
  836. //
  837. // alphaBlendingSplitButton
  838. //
  839. this.alphaBlendingSplitButton.Name = "alphaBlendingSplitButton";
  840. this.alphaBlendingSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  841. this.alphaBlendingSplitButton.DropDownOpening += new EventHandler(AlphaBlendingSplitButton_DropDownOpening);
  842. this.alphaBlendingSplitButton.DropDownClosed +=
  843. delegate(object sender, EventArgs e)
  844. {
  845. this.alphaBlendingSplitButton.DropDownItems.Clear();
  846. };
  847. this.alphaBlendingSplitButton.ButtonClick +=
  848. delegate(object sender, EventArgs e)
  849. {
  850. Tracing.LogFeature("ToolConfigStrip(alphaBlendingSplitButton)");
  851. AlphaBlending = !AlphaBlending;
  852. };
  853. //
  854. // toleranceLabel
  855. //
  856. this.toleranceLabel.Name = "toleranceLabel";
  857. //
  858. // toleranceSlider
  859. //
  860. this.toleranceSlider.Name = "toleranceSlider";
  861. this.toleranceSlider.ToleranceChanged += new EventHandler(ToleranceSlider_ToleranceChanged);
  862. this.toleranceSlider.Size = new Size(150, 16);
  863. //
  864. // toleranceSliderStrip
  865. //
  866. this.toleranceSliderStrip.Name = "toleranceSliderStrip";
  867. this.toleranceSliderStrip.AutoSize = false;
  868. //
  869. // fontLabel
  870. //
  871. this.fontLabel.Name = "fontLabel";
  872. //
  873. // fontFamilyComboBox
  874. //
  875. this.fontFamilyComboBox.Name = "fontComboBox";
  876. this.fontFamilyComboBox.DropDownWidth = 240;
  877. this.fontFamilyComboBox.MaxDropDownItems = 12;
  878. this.fontFamilyComboBox.Sorted = true;
  879. this.fontFamilyComboBox.GotFocus += new EventHandler(FontFamilyComboBox_GotFocus);
  880. this.fontFamilyComboBox.Items.Add(arialName);
  881. this.fontFamilyComboBox.SelectedItem = arialName;
  882. this.fontFamilyComboBox.SelectedIndexChanged += FontFamilyComboBox_SelectedIndexChanged;
  883. this.fontFamilyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  884. //
  885. // fontFamilyComboBox.ComboBox
  886. //
  887. this.fontFamilyComboBox.ComboBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  888. this.fontFamilyComboBox.ComboBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.FontFamilyComboBox_MeasureItem);
  889. this.fontFamilyComboBox.ComboBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.FontFamilyComboBox_DrawItem);
  890. //
  891. // fontSizeComboBox
  892. //
  893. this.fontSizeComboBox.Name = "fontSizeComboBox";
  894. this.fontSizeComboBox.AutoSize = false;
  895. this.fontSizeComboBox.TextChanged += new EventHandler(FontSizeComboBox_TextChanged);
  896. this.fontSizeComboBox.Validating += new CancelEventHandler(FontSizeComboBox_Validating);
  897. this.fontSizeComboBox.Text = initialFontSize.ToString();
  898. this.fontSizeComboBox.Width = 44;
  899. //
  900. // fontSmoothingComboBox
  901. //
  902. this.fontSmoothingComboBox.Name = "smoothingComboBOx";
  903. this.fontSmoothingComboBox.AutoSize = false;
  904. this.fontSmoothingComboBox.Sorted = false;
  905. this.fontSmoothingComboBox.Width = 70;
  906. this.fontSmoothingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  907. this.fontSmoothingComboBox.SelectedIndexChanged += new EventHandler(SmoothingComboBox_SelectedIndexChanged);
  908. //
  909. // fontBoldButton
  910. //
  911. this.fontBoldButton.Name = "boldButton";
  912. //
  913. // fontItalicsButton
  914. //
  915. this.fontItalicsButton.Name = "italicsButton";
  916. //
  917. // fontUnderlineButton
  918. //
  919. this.fontUnderlineButton.Name = "underlineButton";
  920. //
  921. // fontAlignLeftButton
  922. //
  923. this.fontAlignLeftButton.Name = "alignLeftButton";
  924. //
  925. // fontAlignCenterButton
  926. //
  927. this.fontAlignCenterButton.Name = "alignCenterButton";
  928. //
  929. // fontAlignRightButton
  930. //
  931. this.fontAlignRightButton.Name = "alignRightButton";
  932. //
  933. // resamplingSeparator
  934. //
  935. this.resamplingSeparator.Name = "resamplingSeparator";
  936. //
  937. // resamplingLabel
  938. //
  939. this.resamplingLabel.Name = "resamplingLabel";
  940. //
  941. // resamplingComboBox
  942. //
  943. this.resamplingComboBox.Name = "resamplingComboBox";
  944. this.resamplingComboBox.AutoSize = true;
  945. this.resamplingComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  946. this.resamplingComboBox.Sorted = false;
  947. this.resamplingComboBox.Width = 100;
  948. this.resamplingComboBox.DropDownWidth = 100;
  949. this.resamplingComboBox.SelectedIndexChanged += new EventHandler(ResamplingComboBox_SelectedIndexChanged);
  950. //
  951. // colorPickerSeparator
  952. //
  953. this.colorPickerSeparator.Name = "colorPickerSeparator";
  954. //
  955. // colorPickerLabel
  956. //
  957. this.colorPickerLabel.Name = "colorPickerLabel";
  958. //
  959. // colorPickerComboBox
  960. //
  961. this.colorPickerComboBox.Name = "colorPickerComboBox";
  962. this.colorPickerComboBox.AutoSize = true;
  963. this.colorPickerComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  964. this.colorPickerComboBox.Width = 200;
  965. this.colorPickerComboBox.DropDownWidth = 200;
  966. this.colorPickerComboBox.Sorted = false;
  967. this.colorPickerComboBox.SelectedIndexChanged += new EventHandler(ColorPickerComboBox_SelectedIndexChanged);
  968. //
  969. // selectionCombineModeSeparator
  970. //
  971. this.selectionCombineModeSeparator.Name = "selectionCombineModeSeparator";
  972. //
  973. // selectionCombineModeLabel
  974. //
  975. this.selectionCombineModeLabel.Name = "selectionCombineModeLabel";
  976. //
  977. // selectionCombineModeSplitButton
  978. //
  979. this.selectionCombineModeSplitButton.Name = "selectionCombineModeSplitButton";
  980. this.selectionCombineModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  981. this.selectionCombineModeSplitButton.DropDownOpening += new EventHandler(SelectionCombineModeSplitButton_DropDownOpening);
  982. this.selectionCombineModeSplitButton.DropDownClosed +=
  983. delegate(object sender, EventArgs e)
  984. {
  985. this.selectionCombineModeSplitButton.DropDownItems.Clear();
  986. };
  987. this.selectionCombineModeSplitButton.ButtonClick +=
  988. delegate(object sender, EventArgs e)
  989. {
  990. Tracing.LogFeature("ToolConfigStrip(selectionCombineModeSplitButton)");
  991. this.SelectionCombineMode = CycleSelectionCombineMode(this.SelectionCombineMode);
  992. };
  993. //
  994. // floodModeSeparator
  995. //
  996. this.floodModeSeparator.Name = "floodModeSeparator";
  997. //
  998. // floodModeLabel
  999. //
  1000. this.floodModeLabel.Name = "floodModeLabel";
  1001. //
  1002. // floodModeSplitButton
  1003. //
  1004. this.floodModeSplitButton.Name = "floodModeSplitButton";
  1005. this.floodModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
  1006. this.floodModeSplitButton.DropDownOpening += new EventHandler(FloodModeSplitButton_DropDownOpening);
  1007. this.floodModeSplitButton.DropDownClosed +=
  1008. delegate(object sender, EventArgs e)
  1009. {
  1010. this.floodModeSplitButton.DropDownItems.Clear();
  1011. };
  1012. this.floodModeSplitButton.ButtonClick +=
  1013. delegate(object sender, EventArgs e)
  1014. {
  1015. Tracing.LogFeature("ToolConfigStrip(floodModeSplitButton)");
  1016. this.FloodMode = CycleFloodMode(this.FloodMode);
  1017. };
  1018. //
  1019. // selectionDrawModeSeparator
  1020. //
  1021. this.selectionDrawModeSeparator.Name = "selectionDrawModeSeparator";
  1022. //
  1023. // selectionDrawModeModeLabel
  1024. //
  1025. this.selectionDrawModeModeLabel.Name = "selectionDrawModeModeLabel";
  1026. //
  1027. // selectionDrawModeSplitButton
  1028. //
  1029. this.selectionDrawModeSplitButton.Name = "selectionDrawModeSplitButton";
  1030. this.selectionDrawModeSplitButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
  1031. this.selectionDrawModeSplitButton.DropDownOpening += new EventHandler(SelectionDrawModeSplitButton_DropDownOpening);
  1032. this.selectionDrawModeSplitButton.DropDownClosed +=
  1033. delegate(object sender, EventArgs e)
  1034. {
  1035. this.selectionDrawModeSplitButton.DropDownItems.Clear();
  1036. };
  1037. this.selectionDrawModeSplitButton.ButtonClick +=
  1038. delegate(object sender, EventArgs e)
  1039. {
  1040. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSplitButton)");
  1041. SelectionDrawMode newSDM = CycleSelectionDrawMode(this.SelectionDrawModeInfo.DrawMode);
  1042. this.SelectionDrawModeInfo = this.SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
  1043. };
  1044. //
  1045. // selectionDrawModeWidthLabel
  1046. //
  1047. this.selectionDrawModeWidthLabel.Name = "selectionDrawModeWidthLabel";
  1048. //
  1049. // selectionDrawModeWidthTextBox
  1050. //
  1051. this.selectionDrawModeWidthTextBox.Name = "selectionDrawModeWidthTextBox";
  1052. this.selectionDrawModeWidthTextBox.TextBox.Width = 50;
  1053. this.selectionDrawModeWidthTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
  1054. this.selectionDrawModeWidthTextBox.Enter +=
  1055. delegate(object sender, EventArgs e)
  1056. {
  1057. this.selectionDrawModeWidthTextBox.TextBox.Select(0, this.selectionDrawModeWidthTextBox.TextBox.Text.Length);
  1058. };
  1059. this.selectionDrawModeWidthTextBox.Leave +=
  1060. delegate(object sender, EventArgs e)
  1061. {
  1062. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeWidthTextBox.Leave)");
  1063. double newWidth;
  1064. if (double.TryParse(this.selectionDrawModeWidthTextBox.Text, out newWidth))
  1065. {
  1066. this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewWidth(newWidth);
  1067. }
  1068. else
  1069. {
  1070. this.selectionDrawModeWidthTextBox.Text = this.selectionDrawModeInfo.Width.ToString();
  1071. }
  1072. };
  1073. //
  1074. // selectionDrawModeSwapButton
  1075. //
  1076. this.selectionDrawModeSwapButton.Name = "selectionDrawModeSwapButton";
  1077. this.selectionDrawModeSwapButton.Click +=
  1078. delegate(object sender, EventArgs e)
  1079. {
  1080. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeSwapButton)");
  1081. SelectionDrawModeInfo oldSDMI = this.SelectionDrawModeInfo;
  1082. SelectionDrawModeInfo newSDMI = new SelectionDrawModeInfo(oldSDMI.DrawMode, oldSDMI.Height, oldSDMI.Width, oldSDMI.Units);
  1083. this.SelectionDrawModeInfo = newSDMI;
  1084. };
  1085. //
  1086. // selectionDrawModeHeightLabel
  1087. //
  1088. this.selectionDrawModeHeightLabel.Name = "selectionDrawModeHeightLabel";
  1089. //
  1090. // selectionDrawModeHeightTextBox
  1091. //
  1092. this.selectionDrawModeHeightTextBox.Name = "selectionDrawModeHeightTextBox";
  1093. this.selectionDrawModeHeightTextBox.TextBox.Width = 50;
  1094. this.selectionDrawModeHeightTextBox.TextBoxTextAlign = HorizontalAlignment.Right;
  1095. this.selectionDrawModeHeightTextBox.Enter +=
  1096. delegate(object sender, EventArgs e)
  1097. {
  1098. this.selectionDrawModeHeightTextBox.TextBox.Select(0, this.selectionDrawModeHeightTextBox.TextBox.Text.Length);
  1099. };
  1100. this.selectionDrawModeHeightTextBox.Leave +=
  1101. delegate(object sender, EventArgs e)
  1102. {
  1103. Tracing.LogFeature("ToolConfigStrip(selectionDrawModeHeightTextBox.Leave)");
  1104. double newHeight;
  1105. if (double.TryParse(this.selectionDrawModeHeightTextBox.Text, out newHeight))
  1106. {
  1107. this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewHeight(newHeight);
  1108. }
  1109. else
  1110. {
  1111. this.selectionDrawModeHeightTextBox.Text = this.selectionDrawModeInfo.Height.ToString();
  1112. }
  1113. };
  1114. //
  1115. // selectionDrawModeUnits
  1116. //
  1117. this.selectionDrawModeUnits.Name = "selectionDrawModeUnits";
  1118. this.selectionDrawModeUnits.UnitsDisplayType = UnitsDisplayType.Plural;
  1119. this.selectionDrawModeUnits.LowercaseStrings = true;
  1120. this.selectionDrawModeUnits.Size = new Size(90, this.selectionDrawModeUnits.Height);
  1121. //
  1122. // DrawConfigStrip
  1123. //
  1124. this.AutoSize = true;
  1125. this.Items.AddRange(
  1126. new ToolStripItem[]
  1127. {
  1128. this.selectionCombineModeSeparator,
  1129. this.selectionCombineModeLabel,
  1130. this.selectionCombineModeSplitButton,
  1131. this.selectionDrawModeSeparator,
  1132. this.selectionDrawModeModeLabel,
  1133. this.selectionDrawModeSplitButton,
  1134. this.selectionDrawModeWidthLabel,
  1135. this.selectionDrawModeWidthTextBox,
  1136. this.selectionDrawModeSwapButton,
  1137. this.selectionDrawModeHeightLabel,
  1138. this.selectionDrawModeHeightTextBox,
  1139. this.selectionDrawModeUnits,
  1140. this.floodModeSeparator,
  1141. this.floodModeLabel,
  1142. this.floodModeSplitButton,
  1143. this.resamplingSeparator,
  1144. this.resamplingLabel,
  1145. this.resamplingComboBox,
  1146. this.colorPickerSeparator,
  1147. this.colorPickerLabel,
  1148. this.colorPickerComboBox,
  1149. this.fontSeparator,
  1150. this.fontLabel,
  1151. this.fontFamilyComboBox,
  1152. this.fontSizeComboBox,
  1153. this.fontSmoothingComboBox,
  1154. this.fontStyleSeparator,
  1155. this.fontBoldButton,
  1156. this.fontItalicsButton,
  1157. this.fontUnderlineButton,
  1158. this.fontAlignSeparator,
  1159. this.fontAlignLeftButton,
  1160. this.fontAlignCenterButton,
  1161. this.fontAlignRightButton,
  1162. this.shapeSeparator,
  1163. this.shapeButton,
  1164. this.gradientSeparator1,
  1165. this.gradientLinearClampedButton,
  1166. this.gradientLinearReflectedButton,
  1167. this.gradientLinearDiamondButton,
  1168. this.gradientRadialButton,
  1169. this.gradientConicalButton,
  1170. this.gradientSeparator2,
  1171. this.gradientChannelsSplitButton,
  1172. this.penSeparator,
  1173. this.penSizeLabel,
  1174. this.penSizeDecButton,
  1175. this.penSizeComboBox,
  1176. this.penSizeIncButton,
  1177. this.penStyleLabel,
  1178. this.penStartCapSplitButton,
  1179. this.penDashStyleSplitButton,
  1180. this.penEndCapSplitButton,
  1181. this.brushSeparator,
  1182. this.brushStyleLabel,
  1183. this.brushStyleComboBox,
  1184. this.toleranceSeparator,
  1185. this.toleranceLabel,
  1186. this.toleranceSliderStrip,
  1187. this.blendingSeparator,
  1188. this.antiAliasingSplitButton,
  1189. this.alphaBlendingSplitButton
  1190. });
  1191. this.ResumeLayout(false);
  1192. }
  1193. public void CyclePenEndCap()
  1194. {
  1195. PenInfo newPenInfo = PenInfo.Clone();
  1196. newPenInfo.EndCap = NextLineCap(newPenInfo.EndCap);
  1197. PenInfo = newPenInfo;
  1198. }
  1199. public void CyclePenStartCap()
  1200. {
  1201. PenInfo newPenInfo = PenInfo.Clone();
  1202. newPenInfo.StartCap = NextLineCap(newPenInfo.StartCap);
  1203. PenInfo = newPenInfo;
  1204. }
  1205. public void CyclePenDashStyle()
  1206. {
  1207. PenInfo newPenInfo = PenInfo.Clone();
  1208. newPenInfo.DashStyle = NextDashStyle(newPenInfo.DashStyle);
  1209. PenInfo = newPenInfo;
  1210. }
  1211. private DashStyle NextDashStyle(DashStyle oldDash)
  1212. {
  1213. int dashIndex = Array.IndexOf<DashStyle>(this.dashStyles, oldDash);
  1214. int newDashIndex = (dashIndex + 1) % this.dashStyles.Length;
  1215. return this.dashStyles[newDashIndex];
  1216. }
  1217. private LineCap2 NextLineCap(LineCap2 oldCap)
  1218. {
  1219. int capIndex = Array.IndexOf<LineCap2>(this.lineCaps, oldCap);
  1220. int newCapIndex = (capIndex + 1) % this.lineCaps.Length;
  1221. return this.lineCaps[newCapIndex];
  1222. }
  1223. private void GradientTypeButtonClicked(object sender, EventArgs e)
  1224. {
  1225. Tracing.LogFeature("ToolConfigStrip(GradientTypeButtonClicked)");
  1226. GradientType newType = (GradientType)((ToolStripButton)sender).Tag;
  1227. GradientInfo = new GradientInfo(newType, GradientInfo.AlphaOnly);
  1228. }
  1229. private void ComboBoxStyle_SelectedValueChanged(object sender, EventArgs e)
  1230. {
  1231. OnBrushChanged();
  1232. }
  1233. public void PerformBrushChanged()
  1234. {
  1235. OnBrushChanged();
  1236. }
  1237. private void ComboBoxStyle_DrawItem(object sender, DrawItemEventArgs e)
  1238. {
  1239. e.DrawBackground();
  1240. Rectangle r = e.Bounds;
  1241. if (e.Index != -1)
  1242. {
  1243. string itemName = (string)this.brushStyleComboBox.Items[e.Index];
  1244. if (itemName != this.solidBrushText)
  1245. {
  1246. Rectangle rd = r;
  1247. rd.Width = rd.Left + 25;
  1248. Rectangle rt = r;
  1249. r.X = rd.Right;
  1250. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1251. HatchStyle hs = (HatchStyle)this.hatchStyleNames.LocalizedNameToEnumValue(displayText);
  1252. using (HatchBrush b = new HatchBrush(hs, e.ForeColor, e.BackColor))
  1253. {
  1254. e.Graphics.FillRectangle(b, rd);
  1255. }
  1256. StringFormat sf = new StringFormat();
  1257. sf.Alignment = StringAlignment.Near;
  1258. using (SolidBrush sb = new SolidBrush(Color.White))
  1259. {
  1260. if ((e.State & DrawItemState.Focus) == 0)
  1261. {
  1262. sb.Color = SystemColors.Window;
  1263. e.Graphics.FillRectangle(sb, r);
  1264. sb.Color = SystemColors.WindowText;
  1265. e.Graphics.DrawString(displayText, this.Font, sb, r, sf);
  1266. }
  1267. else
  1268. {
  1269. sb.Color = SystemColors.Highlight;
  1270. e.Graphics.FillRectangle(sb, r);
  1271. sb.Color = SystemColors.HighlightText;
  1272. e.Graphics.DrawString(displayText, this.Font, sb, r, sf);
  1273. }
  1274. }
  1275. sf.Dispose();
  1276. sf = null;
  1277. }
  1278. else
  1279. {
  1280. // Solid Brush
  1281. using (SolidBrush sb = new SolidBrush(Color.White))
  1282. {
  1283. if ((e.State & DrawItemState.Focus) == 0)
  1284. {
  1285. sb.Color = SystemColors.Window;
  1286. e.Graphics.FillRectangle(sb, e.Bounds);
  1287. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1288. sb.Color = SystemColors.WindowText;
  1289. e.Graphics.DrawString(displayText, this.Font, sb, e.Bounds);
  1290. }
  1291. else
  1292. {
  1293. sb.Color = SystemColors.Highlight;
  1294. e.Graphics.FillRectangle(sb, e.Bounds);
  1295. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1296. sb.Color = SystemColors.HighlightText;
  1297. e.Graphics.DrawString(displayText, this.Font, sb, e.Bounds);
  1298. }
  1299. }
  1300. }
  1301. e.DrawFocusRectangle();
  1302. }
  1303. }
  1304. private void ComboBoxStyle_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
  1305. {
  1306. // Work out what the text will be
  1307. string displayText = this.brushStyleComboBox.Items[e.Index].ToString();
  1308. // Get width & height of string
  1309. SizeF stringSize = e.Graphics.MeasureString(displayText, this.Font);
  1310. // set height to text height
  1311. e.ItemHeight = (int)stringSize.Height;
  1312. // set width to text width
  1313. e.ItemWidth = (int)stringSize.Width;
  1314. }
  1315. public event EventHandler ShapeDrawTypeChanged;
  1316. protected virtual void OnShapeDrawTypeChanged()
  1317. {
  1318. if (ShapeDrawTypeChanged != null)
  1319. {
  1320. ShapeDrawTypeChanged(this, EventArgs.Empty);
  1321. }
  1322. }
  1323. public void PerformShapeDrawTypeChanged()
  1324. {
  1325. OnShapeDrawTypeChanged();
  1326. }
  1327. public ShapeDrawType ShapeDrawType
  1328. {
  1329. get
  1330. {
  1331. return shapeDrawType;
  1332. }
  1333. set
  1334. {
  1335. if (shapeDrawType != value)
  1336. {
  1337. shapeDrawType = value;
  1338. // if the user sets the shape the buttons must be updated
  1339. if (shapeDrawType == ShapeDrawType.Outline)
  1340. {
  1341. this.shapeButton.Image = shapeOutlineImage.Reference;
  1342. }
  1343. else if (shapeDrawType == ShapeDrawType.Both)
  1344. {
  1345. this.shapeButton.Image = shapeBothImage.Reference;
  1346. }
  1347. else if (shapeDrawType == ShapeDrawType.Interior)
  1348. {
  1349. this.shapeButton.Image = shapeInteriorImage.Reference;
  1350. }
  1351. else
  1352. {
  1353. // invalid shape
  1354. throw new InvalidOperationException("Shape draw type is invalid");
  1355. }
  1356. this.OnShapeDrawTypeChanged();
  1357. }
  1358. }
  1359. }
  1360. private void SetFontStyleButtons(FontStyle style)
  1361. {
  1362. bool bold = ((style & FontStyle.Bold) != 0);
  1363. bool italic = ((style & FontStyle.Italic) != 0);
  1364. bool underline = ((style & FontStyle.Underline) != 0);
  1365. this.fontBoldButton.Checked = bold;
  1366. this.fontItalicsButton.Checked = italic;
  1367. this.fontUnderlineButton.Checked = underline;
  1368. }
  1369. protected override void OnItemClicked(ToolStripItemClickedEventArgs e)
  1370. {
  1371. if (e.ClickedItem == fontBoldButton)
  1372. {
  1373. Tracing.LogFeature("ToolConfigStrip(fontBoldButton)");
  1374. this.fontStyle ^= FontStyle.Bold;
  1375. SetFontStyleButtons(this.fontStyle);
  1376. this.OnFontInfoChanged();
  1377. }
  1378. else if (e.ClickedItem == fontItalicsButton)
  1379. {
  1380. Tracing.LogFeature("ToolConfigStrip(fontItalicsButton)");
  1381. this.fontStyle ^= FontStyle.Italic;
  1382. SetFontStyleButtons(this.fontStyle);
  1383. this.OnFontInfoChanged();
  1384. }
  1385. else if (e.ClickedItem == fontUnderlineButton)
  1386. {
  1387. Tracing.LogFeature("ToolConfigStrip(fontUnderlineButton)");
  1388. this.fontStyle ^= FontStyle.Underline;
  1389. SetFontStyleButtons(this.fontStyle);
  1390. this.OnFontInfoChanged();
  1391. }
  1392. else if (e.ClickedItem == fontAlignLeftButton)
  1393. {
  1394. Tracing.LogFeature("ToolConfigStrip(fontAlignLeftButton)");
  1395. this.FontAlignment = TextAlignment.Left;
  1396. }
  1397. else if (e.ClickedItem == fontAlignCenterButton)
  1398. {
  1399. Tracing.LogFeature("ToolConfigStrip(fontAlignCenterButton)");
  1400. this.FontAlignment = TextAlignment.Center;
  1401. }
  1402. else if (e.ClickedItem == fontAlignRightButton)
  1403. {
  1404. Tracing.LogFeature("ToolConfigStrip(fontAlignRightButton)");
  1405. this.FontAlignment = TextAlignment.Right;
  1406. }
  1407. base.OnItemClicked(e);
  1408. }
  1409. public event EventHandler PenInfoChanged;
  1410. protected virtual void OnPenChanged()
  1411. {
  1412. if (PenInfoChanged != null)
  1413. {
  1414. PenInfoChanged(this, EventArgs.Empty);
  1415. }
  1416. }
  1417. public void PerformPenChanged()
  1418. {
  1419. OnPenChanged();
  1420. }
  1421. public void AddToPenSize(float delta)
  1422. {
  1423. if ((this.toolBarConfigItems & ToolBarConfigItems.Pen) == ToolBarConfigItems.Pen)
  1424. {
  1425. float newWidth = Utility.Clamp(PenInfo.Width + delta, minPenSize, maxPenSize);
  1426. PenInfo newPenInfo = PenInfo.Clone();
  1427. newPenInfo.Width += delta;
  1428. newPenInfo.Width = (float)Utility.Clamp(newPenInfo.Width, minPenSize, maxPenSize);
  1429. PenInfo = newPenInfo;
  1430. }
  1431. }
  1432. public PenInfo PenInfo
  1433. {
  1434. get
  1435. {
  1436. float width;
  1437. try
  1438. {
  1439. width = float.Parse(this.penSizeComboBox.Text);
  1440. }
  1441. catch (FormatException)
  1442. {
  1443. // TODO: would much rather grab the value from AppEnvironment
  1444. // or in some way that we keep track of the "last good value"
  1445. width = 2;
  1446. }
  1447. LineCap2 startCap;
  1448. try
  1449. {
  1450. startCap = (LineCap2)this.penStartCapSplitButton.Tag;
  1451. }
  1452. catch (Exception)
  1453. {
  1454. startCap = PenInfo.DefaultLineCap;
  1455. }
  1456. LineCap2 endCap;
  1457. try
  1458. {
  1459. endCap = (LineCap2)this.penEndCapSplitButton.Tag;
  1460. }
  1461. catch (Exception)
  1462. {
  1463. endCap = PenInfo.DefaultLineCap;
  1464. }
  1465. DashStyle dashStyle = (DashStyle)this.penDashStyleSplitButton.Tag;
  1466. return new PenInfo(dashStyle, width, startCap, endCap, PenInfo.DefaultCapScale);
  1467. }
  1468. set
  1469. {
  1470. if (this.PenInfo != value)
  1471. {
  1472. this.penSizeComboBox.Text = value.Width.ToString();
  1473. this.penStartCapSplitButton.Tag = value.StartCap;
  1474. this.penStartCapSplitButton.Image = GetLineCapImage(value.StartCap, true).Reference;
  1475. this.penDashStyleSplitButton.Tag = value.DashStyle;
  1476. this.penDashStyleSplitButton.Image = GetDashStyleImage(value.DashStyle);
  1477. this.penEndCapSplitButton.Tag = value.EndCap;
  1478. this.penEndCapSplitButton.Image = GetLineCapImage(value.EndCap, false).Reference;
  1479. OnPenChanged();
  1480. }
  1481. }
  1482. }
  1483. private void SizeComboBox_TextChanged(object sender, System.EventArgs e)
  1484. {
  1485. BrushSizeComboBox_Validating(this, new CancelEventArgs());
  1486. }
  1487. private void BrushSizeComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  1488. {
  1489. float penSize;
  1490. bool valid = float.TryParse(this.penSizeComboBox.Text, out penSize);
  1491. if (!valid)
  1492. {
  1493. this.penSizeComboBox.BackColor = Color.Red;
  1494. this.penSizeComboBox.ToolTipText = PdnResources.GetString("PenConfigWidget.Error.InvalidNumber");
  1495. }
  1496. else
  1497. {
  1498. if (penSize < minPenSize)
  1499. {
  1500. // Set the error if the size is too small.
  1501. this.penSizeComboBox.BackColor = Color.Red;
  1502. string tooSmallFormat = PdnResources.GetString("PenConfigWidget.Error.TooSmall.Format");
  1503. string tooSmall = string.Format(tooSmallFormat, minPenSize);
  1504. this.penSizeComboBox.ToolTipText = tooSmall;
  1505. }
  1506. else if (penSize > maxPenSize)
  1507. {
  1508. // Set the error if the size is too large.
  1509. this.penSizeComboBox.BackColor = Color.Red;
  1510. string tooLargeFormat = PdnResources.GetString("PenConfigWidget.Error.TooLarge.Format");
  1511. string tooLarge = string.Format(tooLargeFormat, maxPenSize);
  1512. this.penSizeComboBox.ToolTipText = tooLarge;
  1513. }
  1514. else
  1515. {
  1516. // Clear the error, if any
  1517. this.penSizeComboBox.BackColor = SystemColors.Window;
  1518. this.penSizeComboBox.ToolTipText = string.Empty;
  1519. OnPenChanged();
  1520. }
  1521. }
  1522. }
  1523. public event EventHandler AlphaBlendingChanged;
  1524. protected virtual void OnAlphaBlendingChanged()
  1525. {
  1526. if (AlphaBlendingChanged != null)
  1527. {
  1528. AlphaBlendingChanged(this, EventArgs.Empty);
  1529. }
  1530. }
  1531. public void PerformAlphaBlendingChanged()
  1532. {
  1533. OnAlphaBlendingChanged();
  1534. }
  1535. private void GradientChannelsSplitButton_DropDownOpening(object sender, EventArgs e)
  1536. {
  1537. ToolStripMenuItem allChannels = new ToolStripMenuItem(
  1538. PdnResources.GetString("GradientChannels.AllColorChannels.Text"),
  1539. this.gradientAllColorChannelsImage.Reference,
  1540. delegate(object sender2, EventArgs e2)
  1541. {
  1542. GradientInfo = new GradientInfo(GradientInfo.GradientType, false);
  1543. });
  1544. ToolStripMenuItem alphaOnly = new ToolStripMenuItem(
  1545. PdnResources.GetString("GradientChannels.AlphaChannelOnly.Text"),
  1546. this.gradientAlphaChannelOnlyImage.Reference,
  1547. delegate(object sender3, EventArgs e3)
  1548. {
  1549. GradientInfo = new GradientInfo(GradientInfo.GradientType, true);
  1550. });
  1551. allChannels.Checked = !GradientInfo.AlphaOnly;
  1552. alphaOnly.Checked = GradientInfo.AlphaOnly;
  1553. this.gradientChannelsSplitButton.DropDownItems.Clear();
  1554. this.gradientChannelsSplitButton.DropDownItems.AddRange(
  1555. new ToolStripItem[]
  1556. {
  1557. allChannels,
  1558. alphaOnly
  1559. });
  1560. }
  1561. private void AlphaBlendingSplitButton_DropDownOpening(object sender, EventArgs e)
  1562. {
  1563. ToolStripMenuItem abEnabled = new ToolStripMenuItem(
  1564. PdnResources.GetString("AlphaBlendingSplitButton.BlendingEnabled.Text"),
  1565. this.alphaBlendingEnabledImage.Reference,
  1566. delegate(object sender2, EventArgs e2)
  1567. {
  1568. AlphaBlending = true;
  1569. });
  1570. ToolStripMenuItem abOverwrite = new ToolStripMenuItem(
  1571. PdnResources.GetString("AlphaBlendingSplitButton.BlendingOverwrite.Text"),
  1572. this.alphaBlendingOverwriteImage.Reference,
  1573. delegate(object sender3, EventArgs e3)
  1574. {
  1575. AlphaBlending = false;
  1576. });
  1577. abEnabled.Checked = AlphaBlending;
  1578. abOverwrite.Checked = !AlphaBlending;
  1579. this.alphaBlendingSplitButton.DropDownItems.Clear();
  1580. this.alphaBlendingSplitButton.DropDownItems.AddRange(
  1581. new ToolStripItem[]
  1582. {
  1583. abEnabled,
  1584. abOverwrite
  1585. });
  1586. }
  1587. public bool AlphaBlending
  1588. {
  1589. get
  1590. {
  1591. return this.alphaBlendingEnabled;
  1592. }
  1593. set
  1594. {
  1595. if (value != this.alphaBlendingEnabled)
  1596. {
  1597. this.alphaBlendingEnabled = value;
  1598. if (value)
  1599. {
  1600. this.alphaBlendingSplitButton.Image = this.alphaBlendingEnabledImage.Reference;
  1601. }
  1602. else
  1603. {
  1604. this.alphaBlendingSplitButton.Image = this.alphaBlendingOverwriteImage.Reference;
  1605. }
  1606. OnAlphaBlendingChanged();
  1607. }
  1608. }
  1609. }
  1610. private void AlphaBlendingComboBox_SelectedIndexChanged(object sender, EventArgs e)
  1611. {
  1612. OnAlphaBlendingChanged();
  1613. }
  1614. public event EventHandler AntiAliasingChanged;
  1615. protected virtual void OnAntiAliasingChanged()
  1616. {
  1617. if (AntiAliasingChanged != null)
  1618. {
  1619. AntiAliasingChanged(this, EventArgs.Empty);
  1620. }
  1621. }
  1622. public void PerformAntiAliasingChanged()
  1623. {
  1624. OnAntiAliasingChanged();
  1625. }
  1626. public bool AntiAliasing
  1627. {
  1628. get
  1629. {
  1630. return this.antiAliasingEnabled;
  1631. }
  1632. set
  1633. {
  1634. if (this.antiAliasingEnabled != value)
  1635. {
  1636. if (value)
  1637. {
  1638. this.antiAliasingSplitButton.Image = this.antiAliasingEnabledImage.Reference;
  1639. }
  1640. else
  1641. {
  1642. this.antiAliasingSplitButton.Image = this.antiAliasingDisabledImage.Reference;
  1643. }
  1644. this.antiAliasingEnabled = value;
  1645. OnAntiAliasingChanged();
  1646. }
  1647. }
  1648. }
  1649. private Image GetDashStyleImage(DashStyle dashStyle)
  1650. {
  1651. string nameFormat = "Images.DashStyleButton.{0}.png";
  1652. string name = string.Format(nameFormat, dashStyle.ToString());
  1653. ImageResource imageResource = PdnResources.GetImageResource(name);
  1654. Image returnImage;
  1655. if (UI.GetXScaleFactor() == 1.0f && UI.GetYScaleFactor() == 1.0f)
  1656. {
  1657. returnImage = imageResource.Reference;
  1658. }
  1659. else
  1660. {
  1661. returnImage = new Bitmap(imageResource.Reference, UI.ScaleSize(imageResource.Reference.Size));
  1662. }
  1663. return returnImage;
  1664. }
  1665. private ImageResource GetLineCapImage(LineCap2 lineCap, bool isStartCap)
  1666. {
  1667. string nameFormat = "Images.LineCapButton.{0}.{1}.png";
  1668. string name = string.Format(nameFormat, lineCap.ToString(), isStartCap ? "Start" : "End");
  1669. ImageResource imageResource = PdnResources.GetImageResource(name);
  1670. return imageResource;
  1671. }
  1672. private void PenDashStyleButton_DropDownOpening(object sender, EventArgs e)
  1673. {
  1674. List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
  1675. foreach (DashStyle dashStyle in this.dashStyles)
  1676. {
  1677. ToolStripMenuItem mi = new ToolStripMenuItem(
  1678. this.dashStyleLocalizer.EnumValueToLocalizedName(dashStyle),
  1679. GetDashStyleImage(dashStyle),
  1680. delegate(object sender2, EventArgs e2)
  1681. {
  1682. ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
  1683. DashStyle newDashStyle = (DashStyle)tsmi.Tag;
  1684. PenInfo newPenInfo = PenInfo.Clone();
  1685. newPenInfo.DashStyle = newDashStyle;
  1686. PenInfo = newPenInfo;
  1687. });
  1688. mi.ImageScaling = ToolStripItemImageScaling.None;
  1689. if (dashStyle == PenInfo.DashStyle)
  1690. {
  1691. mi.Checked = true;
  1692. }
  1693. mi.Tag = dashStyle;
  1694. menuItems.Add(mi);
  1695. }
  1696. this.penDashStyleSplitButton.DropDownItems.Clear();
  1697. this.penDashStyleSplitButton.DropDownItems.AddRange(menuItems.ToArray());
  1698. }
  1699. private void PenCapSplitButton_DropDownOpening(object sender, EventArgs e)
  1700. {
  1701. ToolStripSplitButton splitButton = (ToolStripSplitButton)sender;
  1702. List<ToolStripMenuItem> menuItems = new List<ToolStripMenuItem>();
  1703. LineCap2 currentLineCap = PenInfo.DefaultLineCap;
  1704. bool isStartCap;
  1705. if (object.ReferenceEquals(splitButton, this.penStartCapSplitButton))
  1706. {
  1707. isStartCap = true;
  1708. currentLineCap = PenInfo.StartCap;
  1709. }
  1710. else if (object.ReferenceEquals(splitButton, this.penEndCapSplitButton))
  1711. {
  1712. isStartCap = false;
  1713. currentLineCap = PenInfo.EndCap;
  1714. }
  1715. else
  1716. {
  1717. throw new InvalidOperationException();
  1718. }
  1719. foreach (LineCap2 lineCap in this.lineCaps)
  1720. {
  1721. ToolStripMenuItem mi = new ToolStripMenuItem(
  1722. this.lineCapLocalizer.EnumValueToLocalizedName(lineCap),
  1723. GetLineCapImage(lineCap, isStartCap).Reference,
  1724. delegate(object sender2, EventArgs e2)
  1725. {
  1726. ToolStripMenuItem tsmi = (ToolStripMenuItem)sender2;
  1727. Pair<ToolStripSplitButton, LineCap2> data = (Pair<ToolStripSplitButton, LineCap2>)tsmi.Tag;
  1728. PenInfo newPenInfo = PenInfo.Clone();
  1729. if (object.ReferenceEquals(data.First, this.penStartCapSplitButton))
  1730. {
  1731. newPenInfo.StartCap = data.Second;
  1732. }
  1733. else if (object.ReferenceEquals(data.First, this.penEndCapSplitButton))
  1734. {
  1735. newPenInfo.EndCap = data.Second;
  1736. }
  1737. PenInfo = newPenInfo;
  1738. });
  1739. mi.Tag = Pair.Create(splitButton, lineCap);
  1740. if (lineCap == currentLineCap)
  1741. {
  1742. mi.Checked = true;
  1743. }
  1744. menuItems.Add(mi);
  1745. }
  1746. splitButton.DropDownItems.Clear();
  1747. splitButton.DropDownItems.AddRange(menuItems.ToArray());
  1748. }
  1749. private void AntiAliasingSplitButton_DropDownOpening(object sender, EventArgs e)
  1750. {
  1751. ToolStripMenuItem aaEnabled = new ToolStripMenuItem(
  1752. PdnResources.GetString("AntiAliasingSplitButton.Enabled.Text"),
  1753. this.antiAliasingEnabledImage.Reference,
  1754. delegate(object sender2, EventArgs e2)
  1755. {
  1756. AntiAliasing = true;
  1757. });
  1758. ToolStripMenuItem aaDisabled = new ToolStripMenuItem(
  1759. PdnResources.GetString("AntiAliasingSplitButton.Disabled.Text"),
  1760. this.antiAliasingDisabledImage.Reference,
  1761. delegate(object sender3, EventArgs e3)
  1762. {
  1763. AntiAliasing = false;
  1764. });
  1765. aaEnabled.Checked = AntiAliasing;
  1766. aaDisabled.Checked = !AntiAliasing;
  1767. this.antiAliasingSplitButton.DropDownItems.Clear();
  1768. this.antiAliasingSplitButton.DropDownItems.AddRange(
  1769. new ToolStripItem[]
  1770. {
  1771. aaEnabled,
  1772. aaDisabled
  1773. });
  1774. }
  1775. private void SmoothingComboBox_SelectedIndexChanged(object sender, EventArgs e)
  1776. {
  1777. OnFontSmoothingChanged();
  1778. }
  1779. private void PopulateFontsBackgroundThread(object ignored)
  1780. {
  1781. PopulateFontsBackgroundThread();
  1782. }
  1783. private void PopulateFontsBackgroundThread()
  1784. {
  1785. try
  1786. {
  1787. using (new ThreadBackground(ThreadBackgroundFlags.Cpu))
  1788. {
  1789. PopulateFonts();
  1790. }
  1791. }
  1792. finally
  1793. {
  1794. staticFontNamesPopulatedEvent.Set();
  1795. }
  1796. }
  1797. private void PopulateFonts()
  1798. {
  1799. List<string> fontNames = new List<string>();
  1800. using (Graphics g = this.CreateGraphics())
  1801. {
  1802. FontFamily[] families = FontFamily.GetFamilies(g);
  1803. foreach (FontFamily family in families)
  1804. {
  1805. using (FontInfo fi = new FontInfo(family, 10, FontStyle.Regular))
  1806. {
  1807. if (!fontNames.Contains(family.Name) && fi.CanCreateFont())
  1808. {
  1809. fontNames.Add(family.Name);
  1810. }
  1811. }
  1812. }
  1813. }
  1814. staticFontNames = fontNames;
  1815. Tracing.LogFeature("PopulateFonts()");
  1816. }
  1817. public event EventHandler FontInfoChanged;
  1818. protected virtual void OnFontInfoChanged()
  1819. {
  1820. if (FontInfoChanged != null)
  1821. {
  1822. FontInfoChanged(this, EventArgs.Empty);
  1823. }
  1824. }
  1825. public event EventHandler FontAlignmentChanged;
  1826. protected virtual void OnTextAlignmentChanged()
  1827. {
  1828. if (FontAlignmentChanged != null)
  1829. {
  1830. FontAlignmentChanged(this, EventArgs.Empty);
  1831. }
  1832. }
  1833. public event EventHandler FontSmoothingChanged;
  1834. protected virtual void OnFontSmoothingChanged()
  1835. {
  1836. if (FontSmoothingChanged != null)
  1837. {
  1838. FontSmoothingChanged(this, EventArgs.Empty);
  1839. }
  1840. }
  1841. public FontSmoothing FontSmoothing
  1842. {
  1843. get
  1844. {
  1845. return (FontSmoothing)this.fontSmoothingLocalizer.LocalizedNameToEnumValue((string)this.fontSmoothingComboBox.SelectedItem);
  1846. }
  1847. set
  1848. {
  1849. if (value != this.FontSmoothing)
  1850. {
  1851. this.fontSmoothingComboBox.SelectedItem = this.fontSmoothingLocalizer.EnumValueToLocalizedName(value);
  1852. }
  1853. }
  1854. }
  1855. public FontInfo FontInfo
  1856. {
  1857. get
  1858. {
  1859. return new FontInfo(this.FontFamily, this.FontSize, this.FontStyle);
  1860. }
  1861. set
  1862. {
  1863. this.FontFamily = value.FontFamily;
  1864. this.FontSize = value.Size;
  1865. this.FontStyle = value.FontStyle;
  1866. }
  1867. }
  1868. /// <summary>
  1869. /// Gets or sets the font style i.e. bold, italic, and underline
  1870. /// </summary>
  1871. public FontStyle FontStyle
  1872. {
  1873. get
  1874. {
  1875. return this.fontStyle;
  1876. }
  1877. set
  1878. {
  1879. if (this.fontStyle != value)
  1880. {
  1881. this.fontStyle = value;
  1882. SetFontStyleButtons(FontStyle);
  1883. this.OnFontInfoChanged();
  1884. }
  1885. }
  1886. }
  1887. /// <summary>
  1888. /// Gets or sets the size of the font.
  1889. /// </summary>
  1890. public float FontSize
  1891. {
  1892. get
  1893. {
  1894. bool invalid = false;
  1895. float number = oldSizeValue;
  1896. try
  1897. {
  1898. number = float.Parse(fontSizeComboBox.Text);
  1899. }
  1900. catch (FormatException)
  1901. {
  1902. invalid = true;
  1903. }
  1904. catch (OverflowException)
  1905. {
  1906. invalid = true;
  1907. }
  1908. // if the size is valid update the new size else return the last known good size.
  1909. if (!invalid)
  1910. {
  1911. oldSizeValue = number;
  1912. }
  1913. return oldSizeValue;
  1914. }
  1915. set
  1916. {
  1917. bool invalid = false;
  1918. float number = oldSizeValue;
  1919. try
  1920. {
  1921. number = float.Parse(fontSizeComboBox.Text);
  1922. }
  1923. catch (FormatException)
  1924. {
  1925. invalid = true;
  1926. }
  1927. catch (OverflowException)
  1928. {
  1929. invalid = true;
  1930. }
  1931. // if the size is valid update the new size else return the last known good size.
  1932. if (!invalid)
  1933. {
  1934. if (float.Parse(fontSizeComboBox.Text) != value)
  1935. {
  1936. fontSizeComboBox.Text = value.ToString();
  1937. this.OnFontInfoChanged();
  1938. }
  1939. }
  1940. }
  1941. }
  1942. private FontFamily IndexToFontFamily(int i)
  1943. {
  1944. try
  1945. {
  1946. return new FontFamily((string)this.fontFamilyComboBox.Items[i]);
  1947. }
  1948. catch (Exception)
  1949. {
  1950. return FontFamily.GenericSansSerif;
  1951. }
  1952. }
  1953. private Font IndexToFont(int i, float size, FontStyle style)
  1954. {
  1955. using (FontFamily ff = IndexToFontFamily(i))
  1956. {
  1957. return new FontInfo(ff, size, style).CreateFont();
  1958. }
  1959. }
  1960. /// <summary>
  1961. /// Gets or sets the font family.
  1962. /// </summary>
  1963. public FontFamily FontFamily
  1964. {
  1965. get
  1966. {
  1967. try
  1968. {
  1969. return new FontFamily((string)this.fontFamilyComboBox.SelectedItem);
  1970. }
  1971. catch (ArgumentException)
  1972. {
  1973. return FontFamily.GenericSansSerif;
  1974. }
  1975. }
  1976. set
  1977. {
  1978. string current = (string)this.fontFamilyComboBox.SelectedItem;
  1979. if (current != value.Name)
  1980. {
  1981. int index = fontFamilyComboBox.Items.IndexOf(value.Name);
  1982. if (index != -1)
  1983. {
  1984. fontFamilyComboBox.SelectedIndex = index;
  1985. this.OnFontInfoChanged();
  1986. }
  1987. else
  1988. {
  1989. // Maybe they're just specifying a font we didn't add to the list yet? aka pre-list initialization
  1990. FontInfo oldFI = this.FontInfo;
  1991. FontFamily newFF;
  1992. try
  1993. {
  1994. newFF = new FontFamily(value.Name);
  1995. }
  1996. catch (Exception)
  1997. {
  1998. newFF = new FontFamily(System.Drawing.Text.GenericFontFamilies.SansSerif);
  1999. }
  2000. FontInfo newFI = new FontInfo(newFF, oldFI.Size, oldFI.FontStyle);
  2001. if (newFI.CanCreateFont())
  2002. {
  2003. this.fontFamilyComboBox.Items.Add(value.Name);
  2004. this.fontFamilyComboBox.SelectedItem = value.Name;
  2005. }
  2006. else
  2007. {
  2008. throw new InvalidOperationException("FontFamily is not valid");
  2009. }
  2010. }
  2011. }
  2012. }
  2013. }
  2014. public TextAlignment FontAlignment
  2015. {
  2016. get
  2017. {
  2018. return this.alignment;
  2019. }
  2020. set
  2021. {
  2022. if (this.alignment != value)
  2023. {
  2024. this.alignment = value;
  2025. // if the user sets the text alignment the buttons must be updated
  2026. if (this.alignment == TextAlignment.Left)
  2027. {
  2028. this.fontAlignLeftButton.Checked = true;
  2029. this.fontAlignCenterButton.Checked = false;
  2030. this.fontAlignRightButton.Checked = false;
  2031. }
  2032. else if (this.alignment == TextAlignment.Center)
  2033. {
  2034. this.fontAlignLeftButton.Checked = false;
  2035. this.fontAlignCenterButton.Checked = true;
  2036. this.fontAlignRightButton.Checked = false;
  2037. }
  2038. else if (this.alignment == TextAlignment.Right)
  2039. {
  2040. this.fontAlignLeftButton.Checked = false;
  2041. this.fontAlignCenterButton.Checked = false;
  2042. this.fontAlignRightButton.Checked = true;
  2043. }
  2044. else
  2045. {
  2046. throw new InvalidOperationException("Text alignment type is invalid");
  2047. }
  2048. this.OnTextAlignmentChanged();
  2049. }
  2050. }
  2051. }
  2052. private void FontFamilyComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
  2053. {
  2054. if (e.Index != -1)
  2055. {
  2056. string displayText = (string)this.fontFamilyComboBox.Items[e.Index];
  2057. SizeF stringSize = e.Graphics.MeasureString(displayText, arialFontBase);
  2058. int size = (int)stringSize.Width;
  2059. // set up two areas to draw
  2060. const int leftMargin = 3;
  2061. Rectangle bounds = e.Bounds;
  2062. bounds.X += leftMargin;
  2063. bounds.Width -= leftMargin;
  2064. Rectangle r = bounds;
  2065. Rectangle rd = r;
  2066. rd.Width = rd.Left + size;
  2067. Rectangle rt = r;
  2068. r.X = rd.Right;
  2069. using (Font myFont = IndexToFont(e.Index, 10, FontStyle.Regular))
  2070. {
  2071. StringFormat sf = (StringFormat)StringFormat.GenericTypographic.Clone();
  2072. sf.LineAlignment = StringAlignment.Center;
  2073. sf.FormatFlags &= ~StringFormatFlags.LineLimit;
  2074. sf.FormatFlags |= StringFormatFlags.NoWrap;
  2075. bool isSymbol = PaintDotNet.SystemLayer.Fonts.IsSymbolFont(myFont);
  2076. bool isSelected = ((e.State & DrawItemState.Selected) != 0);
  2077. Brush fillBrush;
  2078. Brush textBrush;
  2079. if (isSelected)
  2080. {
  2081. fillBrush = highlightBrush;
  2082. textBrush = highlightTextBrush;
  2083. }
  2084. else
  2085. {
  2086. fillBrush = windowBrush;
  2087. textBrush = windowTextBrush;
  2088. }
  2089. e.Graphics.FillRectangle(fillBrush, e.Bounds);
  2090. if (isSymbol)
  2091. {
  2092. e.Graphics.DrawString(displayText, arialFontBase, textBrush, bounds, sf);
  2093. e.Graphics.DrawString(displayText, myFont, textBrush, r, sf);
  2094. }
  2095. else
  2096. {
  2097. e.Graphics.DrawString(displayText, myFont, textBrush, bounds, sf);
  2098. }
  2099. sf.Dispose();
  2100. sf = null;
  2101. }
  2102. }
  2103. e.DrawFocusRectangle();
  2104. }
  2105. private void FontFamilyComboBox_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
  2106. {
  2107. // Work out what the text will be
  2108. string displayText = (string)this.fontFamilyComboBox.Items[e.Index];
  2109. // Get width & height of string
  2110. SizeF stringSize;
  2111. using (Font font = IndexToFont(e.Index, 10, FontStyle.Regular))
  2112. {
  2113. stringSize = e.Graphics.MeasureString(displayText, font);
  2114. }
  2115. // Account for top margin
  2116. stringSize.Height += UI.ScaleHeight(6);
  2117. // set hight to text height
  2118. e.ItemHeight = (int)stringSize.Height;
  2119. int maxHeight = UI.ScaleHeight(20);
  2120. if (e.ItemHeight > maxHeight)
  2121. {
  2122. e.ItemHeight = maxHeight;
  2123. }
  2124. // set width to text width
  2125. e.ItemWidth = (int)stringSize.Width;
  2126. }
  2127. private void FontSizeComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  2128. {
  2129. try
  2130. {
  2131. bool invalid = false;
  2132. try
  2133. {
  2134. float number = float.Parse(fontSizeComboBox.Text);
  2135. }
  2136. catch (FormatException)
  2137. {
  2138. invalid = true;
  2139. }
  2140. catch (OverflowException)
  2141. {
  2142. invalid = true;
  2143. }
  2144. if (invalid)
  2145. {
  2146. this.fontSizeComboBox.BackColor = Color.Red;
  2147. this.fontSizeComboBox.ToolTipText = PdnResources.GetString("TextConfigWidget.Error.InvalidNumber");
  2148. }
  2149. else
  2150. {
  2151. if ((float.Parse(fontSizeComboBox.Text) < minFontSize))
  2152. {
  2153. // Set the error if the size is too small.
  2154. this.fontSizeComboBox.BackColor = Color.Red;
  2155. string format = PdnResources.GetString("TextConfigWidget.Error.TooSmall.Format");
  2156. string text = string.Format(format, minFontSize);
  2157. this.fontSizeComboBox.ToolTipText = text;
  2158. }
  2159. else if ((float.Parse(fontSizeComboBox.Text) > maxFontSize))
  2160. {
  2161. // Set the error if the size is too large.
  2162. this.fontSizeComboBox.BackColor = Color.Red;
  2163. string format = PdnResources.GetString("TextConfigWidget.Error.TooLarge.Format");
  2164. string text = string.Format(format, maxFontSize);
  2165. this.fontSizeComboBox.ToolTipText = text;
  2166. }
  2167. else
  2168. {
  2169. // Clear the error, if any
  2170. this.fontSizeComboBox.ToolTipText = string.Empty;
  2171. this.fontSizeComboBox.BackColor = SystemColors.Window;
  2172. OnFontInfoChanged();
  2173. }
  2174. }
  2175. }
  2176. catch (FormatException)
  2177. {
  2178. e.Cancel = true;
  2179. }
  2180. }
  2181. private void FontSizeComboBox_TextChanged(object sender, System.EventArgs e)
  2182. {
  2183. FontSizeComboBox_Validating(sender, new CancelEventArgs());
  2184. }
  2185. private void FontFamilyComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
  2186. {
  2187. OnFontInfoChanged();
  2188. }
  2189. private void FontFamilyComboBox_GotFocus(object sender, EventArgs e)
  2190. {
  2191. if (!fontsComboBoxPopulated)
  2192. {
  2193. AsyncInitFontNames();
  2194. using (new WaitCursorChanger(this))
  2195. {
  2196. staticFontNamesPopulatedEvent.WaitOne();
  2197. this.fontFamilyComboBox.ComboBox.BeginUpdate();
  2198. List<string> fontNames = staticFontNames;
  2199. foreach (string name in fontNames)
  2200. {
  2201. if (!this.fontFamilyComboBox.Items.Contains(name))
  2202. {
  2203. this.fontFamilyComboBox.Items.Add(name);
  2204. }
  2205. }
  2206. this.fontFamilyComboBox.ComboBox.EndUpdate();
  2207. }
  2208. fontsComboBoxPopulated = true;
  2209. }
  2210. }
  2211. public ToolBarConfigItems ToolBarConfigItems
  2212. {
  2213. get
  2214. {
  2215. return this.toolBarConfigItems;
  2216. }
  2217. set
  2218. {
  2219. this.toolBarConfigItems = value;
  2220. SuspendLayout();
  2221. bool showPen = ((value & ToolBarConfigItems.Pen) != ToolBarConfigItems.None);
  2222. this.penSeparator.Visible = showPen;
  2223. this.penSizeLabel.Visible = showPen;
  2224. this.penSizeDecButton.Visible = showPen;
  2225. this.penSizeComboBox.Visible = showPen;
  2226. this.penSizeIncButton.Visible = showPen;
  2227. bool showPenCaps = ((value & ToolBarConfigItems.PenCaps) != ToolBarConfigItems.None);
  2228. this.penStyleLabel.Visible = showPenCaps;
  2229. this.penStartCapSplitButton.Visible = showPenCaps;
  2230. this.penDashStyleSplitButton.Visible = showPenCaps;
  2231. this.penEndCapSplitButton.Visible = showPenCaps;
  2232. bool showBrush = ((value & ToolBarConfigItems.Brush) != ToolBarConfigItems.None);
  2233. this.brushSeparator.Visible = showBrush;
  2234. this.brushStyleLabel.Visible = showBrush;
  2235. this.brushStyleComboBox.Visible = showBrush;
  2236. bool showShape = ((value & ToolBarConfigItems.ShapeType) != ToolBarConfigItems.None);
  2237. this.shapeSeparator.Visible = showShape;
  2238. this.shapeButton.Visible = showShape;
  2239. bool showGradient = ((value & ToolBarConfigItems.Gradient) != ToolBarConfigItems.None);
  2240. this.gradientSeparator1.Visible = showGradient;
  2241. this.gradientLinearClampedButton.Visible = showGradient;
  2242. this.gradientLinearReflectedButton.Visible = showGradient;
  2243. this.gradientLinearDiamondButton.Visible = showGradient;
  2244. this.gradientRadialButton.Visible = showGradient;
  2245. this.gradientConicalButton.Visible = showGradient;
  2246. this.gradientSeparator2.Visible = showGradient;
  2247. this.gradientChannelsSplitButton.Visible = showGradient;
  2248. bool showAA = ((value & ToolBarConfigItems.Antialiasing) != ToolBarConfigItems.None);
  2249. this.antiAliasingSplitButton.Visible = showAA;
  2250. bool showAB = ((value & ToolBarConfigItems.AlphaBlending) != ToolBarConfigItems.None);
  2251. this.alphaBlendingSplitButton.Visible = showAB;
  2252. bool showBlendingSep = ((value & (ToolBarConfigItems.AlphaBlending | ToolBarConfigItems.Antialiasing)) != ToolBarConfigItems.None);
  2253. this.blendingSeparator.Visible = showBlendingSep;
  2254. bool showTolerance = ((value & ToolBarConfigItems.Tolerance) != ToolBarConfigItems.None);
  2255. this.toleranceSeparator.Visible = showTolerance;
  2256. this.toleranceLabel.Visible = showTolerance;
  2257. this.toleranceSliderStrip.Visible = showTolerance;
  2258. bool showText = ((value & ToolBarConfigItems.Text) != ToolBarConfigItems.None);
  2259. this.fontSeparator.Visible = showText;
  2260. this.fontLabel.Visible = showText;
  2261. this.fontFamilyComboBox.Visible = showText;
  2262. this.fontSizeComboBox.Visible = showText;
  2263. this.fontSmoothingComboBox.Visible = showText;
  2264. this.fontStyleSeparator.Visible = showText;
  2265. this.fontBoldButton.Visible = showText;
  2266. this.fontItalicsButton.Visible = showText;
  2267. this.fontUnderlineButton.Visible = showText;
  2268. this.fontAlignSeparator.Visible = showText;
  2269. this.fontAlignLeftButton.Visible = showText;
  2270. this.fontAlignCenterButton.Visible = showText;
  2271. this.fontAlignRightButton.Visible = showText;
  2272. if (showText && IsHandleCreated)
  2273. {
  2274. AsyncInitFontNames();
  2275. }
  2276. bool showResampling = ((value & ToolBarConfigItems.Resampling) != ToolBarConfigItems.None);
  2277. this.resamplingSeparator.Visible = showResampling;
  2278. this.resamplingLabel.Visible = showResampling;
  2279. this.resamplingComboBox.Visible = showResampling;
  2280. bool showColorPicker = ((value & ToolBarConfigItems.ColorPickerBehavior) != ToolBarConfigItems.None);
  2281. this.colorPickerSeparator.Visible = showColorPicker;
  2282. this.colorPickerLabel.Visible = showColorPicker;
  2283. this.colorPickerComboBox.Visible = showColorPicker;
  2284. bool showSelectionCombineMode = ((value & ToolBarConfigItems.SelectionCombineMode) != ToolBarConfigItems.None);
  2285. this.selectionCombineModeSeparator.Visible = showSelectionCombineMode;
  2286. this.selectionCombineModeLabel.Visible = showSelectionCombineMode;
  2287. this.selectionCombineModeSplitButton.Visible = showSelectionCombineMode;
  2288. bool showFloodMode = ((value & ToolBarConfigItems.FloodMode) != ToolBarConfigItems.None);
  2289. this.floodModeSeparator.Visible = showFloodMode;
  2290. this.floodModeLabel.Visible = showFloodMode;
  2291. this.floodModeSplitButton.Visible = showFloodMode;
  2292. bool showSelectionDrawMode = ((value & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None);
  2293. this.selectionDrawModeSeparator.Visible = showSelectionDrawMode;
  2294. this.selectionDrawModeModeLabel.Visible = showSelectionDrawMode;
  2295. this.selectionDrawModeSplitButton.Visible = showSelectionDrawMode;
  2296. this.selectionDrawModeWidthLabel.Visible = showSelectionDrawMode;
  2297. this.selectionDrawModeSwapButton.Visible = showSelectionDrawMode;
  2298. this.selectionDrawModeHeightLabel.Visible = showSelectionDrawMode;
  2299. RefreshSelectionDrawModeInfoVisibilities();
  2300. if (value == ToolBarConfigItems.None)
  2301. {
  2302. this.Visible = false;
  2303. }
  2304. else
  2305. {
  2306. this.Visible = true;
  2307. }
  2308. ResumeLayout();
  2309. PerformLayout();
  2310. }
  2311. }
  2312. private void ToleranceSlider_ToleranceChanged(object sender, EventArgs e)
  2313. {
  2314. OnToleranceChanged();
  2315. }
  2316. public void PerformToleranceChanged()
  2317. {
  2318. OnToleranceChanged();
  2319. }
  2320. public float Tolerance
  2321. {
  2322. get
  2323. {
  2324. return this.toleranceSlider.Tolerance;
  2325. }
  2326. set
  2327. {
  2328. if (value != this.toleranceSlider.Tolerance)
  2329. {
  2330. this.toleranceSlider.Tolerance = value;
  2331. }
  2332. }
  2333. }
  2334. public event EventHandler ToleranceChanged;
  2335. protected void OnToleranceChanged()
  2336. {
  2337. if (ToleranceChanged != null)
  2338. {
  2339. ToleranceChanged(this, EventArgs.Empty);
  2340. }
  2341. }
  2342. public event EventHandler ColorPickerClickBehaviorChanged;
  2343. protected void OnColorPickerClickBehaviorChanged()
  2344. {
  2345. if (ColorPickerClickBehaviorChanged != null)
  2346. {
  2347. ColorPickerClickBehaviorChanged(this, EventArgs.Empty);
  2348. }
  2349. }
  2350. public ColorPickerClickBehavior ColorPickerClickBehavior
  2351. {
  2352. get
  2353. {
  2354. string selectedItem = (string)this.colorPickerComboBox.SelectedItem;
  2355. ColorPickerClickBehavior cpcb = (ColorPickerClickBehavior)this.colorPickerBehaviorNames.LocalizedNameToEnumValue(selectedItem);
  2356. return cpcb;
  2357. }
  2358. set
  2359. {
  2360. if (value != ColorPickerClickBehavior)
  2361. {
  2362. this.colorPickerComboBox.SelectedItem = this.colorPickerBehaviorNames.EnumValueToLocalizedName(value);
  2363. }
  2364. }
  2365. }
  2366. public void PerformColorPickerClickBehaviorChanged()
  2367. {
  2368. OnColorPickerClickBehaviorChanged();
  2369. }
  2370. private void ColorPickerComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2371. {
  2372. OnColorPickerClickBehaviorChanged();
  2373. }
  2374. private void ResamplingComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2375. {
  2376. OnResamplingAlgorithmChanged();
  2377. }
  2378. public event EventHandler ResamplingAlgorithmChanged;
  2379. protected void OnResamplingAlgorithmChanged()
  2380. {
  2381. if (ResamplingAlgorithmChanged != null)
  2382. {
  2383. ResamplingAlgorithmChanged(this, EventArgs.Empty);
  2384. }
  2385. }
  2386. public ResamplingAlgorithm ResamplingAlgorithm
  2387. {
  2388. get
  2389. {
  2390. string selectedItem = (string)this.resamplingComboBox.SelectedItem;
  2391. ResamplingAlgorithm ra = (ResamplingAlgorithm)this.resamplingAlgorithmNames.LocalizedNameToEnumValue(selectedItem);
  2392. return ra;
  2393. }
  2394. set
  2395. {
  2396. if (value != ResamplingAlgorithm)
  2397. {
  2398. if (value != ResamplingAlgorithm.NearestNeighbor && value != ResamplingAlgorithm.Bilinear)
  2399. {
  2400. throw new InvalidEnumArgumentException();
  2401. }
  2402. this.resamplingComboBox.SelectedItem = this.resamplingAlgorithmNames.EnumValueToLocalizedName(value);
  2403. }
  2404. }
  2405. }
  2406. public void PerformResamplingAlgorithmChanged()
  2407. {
  2408. OnResamplingAlgorithmChanged();
  2409. }
  2410. public event EventHandler SelectionCombineModeChanged;
  2411. protected void OnSelectionCombineModeChanged()
  2412. {
  2413. if (SelectionCombineModeChanged != null)
  2414. {
  2415. SelectionCombineModeChanged(this, EventArgs.Empty);
  2416. }
  2417. }
  2418. public CombineMode SelectionCombineMode
  2419. {
  2420. get
  2421. {
  2422. object tag = this.selectionCombineModeSplitButton.Tag;
  2423. CombineMode cm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
  2424. return cm;
  2425. }
  2426. set
  2427. {
  2428. object tag = this.selectionCombineModeSplitButton.Tag;
  2429. CombineMode oldCm = (tag == null) ? CombineMode.Replace : (CombineMode)tag;
  2430. if (tag == null || (tag != null && value != oldCm))
  2431. {
  2432. this.selectionCombineModeSplitButton.Tag = value;
  2433. UI.SuspendControlPainting(this);
  2434. this.selectionCombineModeSplitButton.Image = GetSelectionCombineModeImage(value).Reference;
  2435. UI.ResumeControlPainting(this);
  2436. OnSelectionCombineModeChanged();
  2437. Invalidate(true);
  2438. }
  2439. }
  2440. }
  2441. public void PerformSelectionCombineModeChanged()
  2442. {
  2443. OnSelectionCombineModeChanged();
  2444. }
  2445. private ImageResource GetSelectionCombineModeImage(CombineMode cm)
  2446. {
  2447. return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionCombineMode." + cm.ToString() + ".png");
  2448. }
  2449. private void SelectionCombineModeSplitButton_DropDownOpening(object sender, EventArgs e)
  2450. {
  2451. this.selectionCombineModeSplitButton.DropDownItems.Clear();
  2452. foreach (CombineMode cm in
  2453. new CombineMode[]
  2454. {
  2455. CombineMode.Replace,
  2456. CombineMode.Union,
  2457. CombineMode.Exclude,
  2458. CombineMode.Intersect,
  2459. CombineMode.Xor
  2460. })
  2461. {
  2462. ToolStripMenuItem cmMI = new ToolStripMenuItem(
  2463. PdnResources.GetString("ToolConfigStrip.SelectionCombineModeSplitButton." + cm.ToString() + ".Text"),
  2464. GetSelectionCombineModeImage(cm).Reference,
  2465. delegate(object sender2, EventArgs e2)
  2466. {
  2467. ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
  2468. CombineMode newCM = (CombineMode)asTSMI.Tag;
  2469. this.SelectionCombineMode = newCM;
  2470. });
  2471. cmMI.Tag = cm;
  2472. cmMI.Checked = (cm == SelectionCombineMode);
  2473. this.selectionCombineModeSplitButton.DropDownItems.Add(cmMI);
  2474. }
  2475. }
  2476. private CombineMode CycleSelectionCombineMode(CombineMode mode)
  2477. {
  2478. CombineMode newMode;
  2479. // Replace -> Union -> Exclude -> Intersect -> Xor -> Replace
  2480. switch (mode)
  2481. {
  2482. default:
  2483. case CombineMode.Complement:
  2484. throw new InvalidEnumArgumentException();
  2485. case CombineMode.Exclude:
  2486. newMode = CombineMode.Intersect;
  2487. break;
  2488. case CombineMode.Intersect:
  2489. newMode = CombineMode.Xor;
  2490. break;
  2491. case CombineMode.Replace:
  2492. newMode = CombineMode.Union;
  2493. break;
  2494. case CombineMode.Union:
  2495. newMode = CombineMode.Exclude;
  2496. break;
  2497. case CombineMode.Xor:
  2498. newMode = CombineMode.Replace;
  2499. break;
  2500. }
  2501. return newMode;
  2502. }
  2503. public event EventHandler FloodModeChanged;
  2504. protected void OnFloodModeChanged()
  2505. {
  2506. if (FloodModeChanged != null)
  2507. {
  2508. FloodModeChanged(this, EventArgs.Empty);
  2509. }
  2510. }
  2511. public FloodMode FloodMode
  2512. {
  2513. get
  2514. {
  2515. object tag = this.floodModeSplitButton.Tag;
  2516. FloodMode fm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
  2517. return fm;
  2518. }
  2519. set
  2520. {
  2521. object tag = this.floodModeSplitButton.Tag;
  2522. FloodMode oldFm = (tag == null) ? FloodMode.Local : (FloodMode)tag;
  2523. if (tag == null || (tag != null && value != oldFm))
  2524. {
  2525. this.floodModeSplitButton.Tag = value;
  2526. this.floodModeSplitButton.Image = GetFloodModeImage(value).Reference;
  2527. OnFloodModeChanged();
  2528. }
  2529. }
  2530. }
  2531. public void PerformFloodModeChanged()
  2532. {
  2533. OnFloodModeChanged();
  2534. }
  2535. private ImageResource GetFloodModeImage(FloodMode cm)
  2536. {
  2537. return PdnResources.GetImageResource("Icons.ToolConfigStrip.FloodMode." + cm.ToString() + ".png");
  2538. }
  2539. private void FloodModeSplitButton_DropDownOpening(object sender, EventArgs e)
  2540. {
  2541. this.floodModeSplitButton.DropDownItems.Clear();
  2542. foreach (FloodMode fm in
  2543. new FloodMode[]
  2544. {
  2545. FloodMode.Local,
  2546. FloodMode.Global
  2547. })
  2548. {
  2549. ToolStripMenuItem fmMI = new ToolStripMenuItem(
  2550. PdnResources.GetString("ToolConfigStrip.FloodModeSplitButton." + fm.ToString() + ".Text"),
  2551. GetFloodModeImage(fm).Reference,
  2552. delegate(object sender2, EventArgs e2)
  2553. {
  2554. ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
  2555. FloodMode newFM = (FloodMode)asTSMI.Tag;
  2556. this.FloodMode = newFM;
  2557. });
  2558. fmMI.Tag = fm;
  2559. fmMI.Checked = (fm == FloodMode);
  2560. this.floodModeSplitButton.DropDownItems.Add(fmMI);
  2561. }
  2562. }
  2563. private FloodMode CycleFloodMode(FloodMode mode)
  2564. {
  2565. FloodMode newMode;
  2566. switch (mode)
  2567. {
  2568. default:
  2569. throw new InvalidEnumArgumentException();
  2570. case FloodMode.Global:
  2571. newMode = FloodMode.Local;
  2572. break;
  2573. case FloodMode.Local:
  2574. newMode = FloodMode.Global;
  2575. break;
  2576. }
  2577. return newMode;
  2578. }
  2579. public event EventHandler SelectionDrawModeInfoChanged;
  2580. protected void OnSelectionDrawModeInfoChanged()
  2581. {
  2582. if (SelectionDrawModeInfoChanged != null)
  2583. {
  2584. SelectionDrawModeInfoChanged(this, EventArgs.Empty);
  2585. }
  2586. }
  2587. // syncs this.SelectionDrawModeInfo into the controls
  2588. private void SyncSelectionDrawModeInfoUI()
  2589. {
  2590. this.selectionDrawModeSplitButton.Text = GetSelectionDrawModeString(this.selectionDrawModeInfo.DrawMode);
  2591. this.selectionDrawModeSplitButton.Image = GetSelectionDrawModeImage(this.selectionDrawModeInfo.DrawMode);
  2592. this.selectionDrawModeWidthTextBox.Text = this.selectionDrawModeInfo.Width.ToString();
  2593. this.selectionDrawModeHeightTextBox.Text = this.selectionDrawModeInfo.Height.ToString();
  2594. this.selectionDrawModeUnits.UnitsChanged -= SelectionDrawModeUnits_UnitsChanged;
  2595. this.selectionDrawModeUnits.Units = this.selectionDrawModeInfo.Units;
  2596. this.selectionDrawModeUnits.UnitsChanged += SelectionDrawModeUnits_UnitsChanged;
  2597. RefreshSelectionDrawModeInfoVisibilities();
  2598. }
  2599. private void RefreshSelectionDrawModeInfoVisibilities()
  2600. {
  2601. if (this.selectionDrawModeInfo != null)
  2602. {
  2603. SuspendLayout();
  2604. bool anyVisible = (this.ToolBarConfigItems & ToolBarConfigItems.SelectionDrawMode) != ToolBarConfigItems.None;
  2605. this.selectionDrawModeModeLabel.Visible = false;
  2606. bool showWidthHeight = anyVisible & (this.selectionDrawModeInfo.DrawMode != SelectionDrawMode.Normal);
  2607. this.selectionDrawModeWidthTextBox.Visible = showWidthHeight;
  2608. this.selectionDrawModeHeightTextBox.Visible = showWidthHeight;
  2609. this.selectionDrawModeWidthLabel.Visible = showWidthHeight;
  2610. this.selectionDrawModeHeightLabel.Visible = showWidthHeight;
  2611. this.selectionDrawModeSwapButton.Visible = showWidthHeight;
  2612. this.selectionDrawModeUnits.Visible = anyVisible & (this.selectionDrawModeInfo.DrawMode == SelectionDrawMode.FixedSize);
  2613. ResumeLayout(false);
  2614. PerformLayout();
  2615. }
  2616. }
  2617. public SelectionDrawModeInfo SelectionDrawModeInfo
  2618. {
  2619. get
  2620. {
  2621. return (this.selectionDrawModeInfo ?? SelectionDrawModeInfo.CreateDefault()).Clone();
  2622. }
  2623. set
  2624. {
  2625. if (this.selectionDrawModeInfo == null || !this.selectionDrawModeInfo.Equals(value))
  2626. {
  2627. this.selectionDrawModeInfo = value.Clone();
  2628. OnSelectionDrawModeInfoChanged();
  2629. SyncSelectionDrawModeInfoUI();
  2630. }
  2631. }
  2632. }
  2633. public void PerformSelectionDrawModeInfoChanged()
  2634. {
  2635. OnSelectionDrawModeInfoChanged();
  2636. }
  2637. private string GetSelectionDrawModeString(SelectionDrawMode drawMode)
  2638. {
  2639. return PdnResources.GetString("ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode.ToString() + ".Text");
  2640. }
  2641. private Image GetSelectionDrawModeImage(SelectionDrawMode drawMode)
  2642. {
  2643. return PdnResources.GetImageResource("Icons.ToolConfigStrip.SelectionDrawModeSplitButton." + drawMode.ToString() + ".png").Reference;
  2644. }
  2645. private void SelectionDrawModeSplitButton_DropDownOpening(object sender, EventArgs e)
  2646. {
  2647. this.selectionDrawModeSplitButton.DropDownItems.Clear();
  2648. foreach (SelectionDrawMode sdm in
  2649. new SelectionDrawMode[]
  2650. {
  2651. SelectionDrawMode.Normal,
  2652. SelectionDrawMode.FixedRatio,
  2653. SelectionDrawMode.FixedSize
  2654. })
  2655. {
  2656. ToolStripMenuItem sdmTSMI = new ToolStripMenuItem(
  2657. GetSelectionDrawModeString(sdm),
  2658. GetSelectionDrawModeImage(sdm),
  2659. delegate(object sender2, EventArgs e2)
  2660. {
  2661. ToolStripMenuItem asTSMI = (ToolStripMenuItem)sender2;
  2662. SelectionDrawMode newSDM = (SelectionDrawMode)asTSMI.Tag;
  2663. this.SelectionDrawModeInfo = this.SelectionDrawModeInfo.CloneWithNewDrawMode(newSDM);
  2664. });
  2665. sdmTSMI.Tag = sdm;
  2666. sdmTSMI.Checked = (sdm == this.SelectionDrawModeInfo.DrawMode);
  2667. this.selectionDrawModeSplitButton.DropDownItems.Add(sdmTSMI);
  2668. }
  2669. }
  2670. private SelectionDrawMode CycleSelectionDrawMode(SelectionDrawMode drawMode)
  2671. {
  2672. SelectionDrawMode newSDM;
  2673. switch (drawMode)
  2674. {
  2675. case SelectionDrawMode.Normal:
  2676. newSDM = SelectionDrawMode.FixedRatio;
  2677. break;
  2678. case SelectionDrawMode.FixedRatio:
  2679. newSDM = SelectionDrawMode.FixedSize;
  2680. break;
  2681. case SelectionDrawMode.FixedSize:
  2682. newSDM = SelectionDrawMode.Normal;
  2683. break;
  2684. default:
  2685. throw new InvalidEnumArgumentException();
  2686. }
  2687. return newSDM;
  2688. }
  2689. private void SelectionDrawModeUnits_UnitsChanged(object sender, EventArgs e)
  2690. {
  2691. OnSelectionDrawModeUnitsChanging();
  2692. this.SelectionDrawModeInfo = this.selectionDrawModeInfo.CloneWithNewUnits(this.selectionDrawModeUnits.Units);
  2693. OnSelectionDrawModeUnitsChanged();
  2694. }
  2695. }
  2696. }