PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ColorsForm.cs

https://bitbucket.org/tuldok89/openpdn
C# | 1986 lines | 1579 code | 246 blank | 161 comment | 127 complexity | 5d339fe38fe66f6437f439a9a23d2443 MD5 | raw file
  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.Base;
  10. using PaintDotNet.SystemLayer;
  11. using System;
  12. using System.Drawing;
  13. using System.Drawing.Imaging;
  14. using System.Collections.Generic;
  15. using System.ComponentModel;
  16. using System.Windows.Forms;
  17. namespace PaintDotNet
  18. {
  19. // TODO: rewrite this ... the code is out of control here as it has grown organically,
  20. // and it's impossible to maintain. post-3.0
  21. internal class ColorsForm
  22. : FloatingToolForm
  23. {
  24. // We want some buttons that don't have a gradient background or fancy border
  25. private sealed class OurToolStripRenderer
  26. : ToolStripProfessionalRenderer
  27. {
  28. protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
  29. {
  30. if (e.ToolStrip is ToolStripDropDown)
  31. {
  32. base.OnRenderToolStripBackground(e);
  33. }
  34. else
  35. {
  36. using (var backBrush = new SolidBrush(e.BackColor))
  37. {
  38. e.Graphics.FillRectangle(backBrush, e.AffectedBounds);
  39. }
  40. }
  41. }
  42. protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
  43. {
  44. // Do not render a border.
  45. }
  46. }
  47. private Label _redLabel;
  48. private Label _blueLabel;
  49. private Label _greenLabel;
  50. private Label _hueLabel;
  51. private NumericUpDown _redUpDown;
  52. private NumericUpDown _greenUpDown;
  53. private NumericUpDown _blueUpDown;
  54. private NumericUpDown _hueUpDown;
  55. private NumericUpDown _valueUpDown;
  56. private NumericUpDown _saturationUpDown;
  57. private Container _components;
  58. private Label _saturationLabel;
  59. private Label _valueLabel;
  60. private ComboBox _whichUserColorBox;
  61. private ColorGradientControl _valueGradientControl;
  62. private NumericUpDown _alphaUpDown;
  63. private ColorGradientControl _alphaGradientControl;
  64. private ColorWheel _colorWheel;
  65. private int _ignoreChangedEvents;
  66. private ColorBgra _lastPrimaryColor;
  67. private Button _moreLessButton;
  68. private ColorBgra _lastSecondaryColor;
  69. private int _suspendSetWhichUserColor;
  70. private readonly string _lessText;
  71. private readonly string _moreText;
  72. private readonly Size _moreSize;
  73. private readonly Size _lessSize;
  74. private Control _lessModeButtonSentinel;
  75. private Control _moreModeButtonSentinel;
  76. private Control _lessModeHeaderSentinel;
  77. private Control _moreModeHeaderSentinel;
  78. private bool _inMoreState = true;
  79. private Label _hexLabel;
  80. private TextBox _hexBox;
  81. private uint _ignore;
  82. private HeaderLabel _rgbHeader;
  83. private HeaderLabel _hsvHeader;
  84. private HeaderLabel _swatchHeader;
  85. private SwatchControl _swatchControl;
  86. private ColorDisplayWidget _colorDisplayWidget;
  87. private ToolStripEx _toolStrip;
  88. private ToolStripButton _colorAddButton;
  89. private HeaderLabel _alphaHeader;
  90. private readonly Image _colorAddOverlay;
  91. private ToolStripSplitButton _colorPalettesButton;
  92. private Bitmap _colorAddIcon;
  93. private ColorGradientControl _hueGradientControl;
  94. private ColorGradientControl _saturationGradientControl;
  95. private ColorGradientControl _redGradientControl;
  96. private ColorGradientControl _greenGradientControl;
  97. private ColorGradientControl _blueGradientControl;
  98. private PaletteCollection _paletteCollection;
  99. public PaletteCollection PaletteCollection
  100. {
  101. get
  102. {
  103. return _paletteCollection;
  104. }
  105. set
  106. {
  107. _paletteCollection = value;
  108. }
  109. }
  110. private bool IgnoreChangedEvents
  111. {
  112. get
  113. {
  114. return _ignoreChangedEvents != 0;
  115. }
  116. }
  117. private class WhichUserColorWrapper
  118. {
  119. private readonly WhichUserColor _whichUserColor;
  120. public WhichUserColor WhichUserColor
  121. {
  122. get
  123. {
  124. return _whichUserColor;
  125. }
  126. }
  127. public override int GetHashCode()
  128. {
  129. return _whichUserColor.GetHashCode();
  130. }
  131. public override bool Equals(object obj)
  132. {
  133. var rhs = obj as WhichUserColorWrapper;
  134. if (rhs == null)
  135. {
  136. return false;
  137. }
  138. return rhs._whichUserColor == _whichUserColor;
  139. }
  140. public override string ToString()
  141. {
  142. return PdnResources.GetString("WhichUserColor." + _whichUserColor);
  143. }
  144. public WhichUserColorWrapper(WhichUserColor whichUserColor)
  145. {
  146. _whichUserColor = whichUserColor;
  147. }
  148. }
  149. public void SuspendSetWhichUserColor()
  150. {
  151. ++_suspendSetWhichUserColor;
  152. }
  153. public void ResumeSetWhichUserColor()
  154. {
  155. --_suspendSetWhichUserColor;
  156. }
  157. public WhichUserColor WhichUserColor
  158. {
  159. get
  160. {
  161. return ((WhichUserColorWrapper)_whichUserColorBox.SelectedItem).WhichUserColor;
  162. }
  163. set
  164. {
  165. if (_suspendSetWhichUserColor <= 0)
  166. {
  167. _whichUserColorBox.SelectedItem = new WhichUserColorWrapper(value);
  168. }
  169. }
  170. }
  171. public void ToggleWhichUserColor()
  172. {
  173. switch (WhichUserColor)
  174. {
  175. case WhichUserColor.Primary:
  176. WhichUserColor = WhichUserColor.Secondary;
  177. break;
  178. case WhichUserColor.Secondary:
  179. WhichUserColor = WhichUserColor.Primary;
  180. break;
  181. default:
  182. throw new InvalidEnumArgumentException();
  183. }
  184. }
  185. public void SetColorControlsRedraw(bool enabled)
  186. {
  187. var controls =
  188. new Control[]
  189. {
  190. _colorWheel,
  191. _whichUserColorBox,
  192. _hueGradientControl,
  193. _saturationGradientControl,
  194. _valueGradientControl,
  195. _redGradientControl,
  196. _greenGradientControl,
  197. _blueGradientControl,
  198. _alphaGradientControl,
  199. _hueUpDown,
  200. _saturationUpDown,
  201. _valueUpDown,
  202. _redUpDown,
  203. _greenUpDown,
  204. _blueUpDown,
  205. _alphaUpDown,
  206. _toolStrip
  207. };
  208. foreach (Control control in controls)
  209. {
  210. if (enabled)
  211. {
  212. UI.ResumeControlPainting(control);
  213. control.Invalidate(true);
  214. }
  215. else
  216. {
  217. UI.SuspendControlPainting(control);
  218. }
  219. }
  220. }
  221. public event ColorEventHandler UserPrimaryColorChanged;
  222. protected virtual void OnUserPrimaryColorChanged(ColorBgra newColor)
  223. {
  224. if (UserPrimaryColorChanged != null && _ignore == 0)
  225. {
  226. _userPrimaryColor = newColor;
  227. UserPrimaryColorChanged(this, new ColorEventArgs(newColor));
  228. _lastPrimaryColor = newColor;
  229. _colorDisplayWidget.UserPrimaryColor = newColor;
  230. }
  231. RenderColorAddIcon(newColor);
  232. }
  233. private ColorBgra _userPrimaryColor;
  234. public ColorBgra UserPrimaryColor
  235. {
  236. get
  237. {
  238. return _userPrimaryColor;
  239. }
  240. set
  241. {
  242. if (IgnoreChangedEvents)
  243. {
  244. return;
  245. }
  246. if (_userPrimaryColor == value) return;
  247. _userPrimaryColor = value;
  248. OnUserPrimaryColorChanged(value);
  249. if (WhichUserColor != WhichUserColor.Primary)
  250. {
  251. WhichUserColor = WhichUserColor.Primary;
  252. }
  253. _ignore++;
  254. // only do the update on the last one, so partial RGB info isn't parsed.
  255. Utility.SetNumericUpDownValue(_alphaUpDown, value.A);
  256. Utility.SetNumericUpDownValue(_redUpDown, value.R);
  257. Utility.SetNumericUpDownValue(_greenUpDown, value.G);
  258. SetColorGradientValuesRgb(value.R, value.G, value.B);
  259. SetColorGradientMinMaxColorsRgb(value.R, value.G, value.B);
  260. SetColorGradientMinMaxColorsAlpha(value.A);
  261. _ignore--;
  262. Utility.SetNumericUpDownValue(_blueUpDown, value.B);
  263. Update();
  264. string hexText = GetHexNumericUpDownValue(value.R, value.G, value.B);
  265. _hexBox.Text = hexText;
  266. SyncHsvFromRgb(value);
  267. _colorDisplayWidget.UserPrimaryColor = _userPrimaryColor;
  268. }
  269. }
  270. private static string GetHexNumericUpDownValue(int red, int green, int blue)
  271. {
  272. int newHexNumber = (red << 16) | (green << 8) | blue;
  273. string newHexText = Convert.ToString(newHexNumber, 16);
  274. while (newHexText.Length < 6)
  275. {
  276. newHexText = "0" + newHexText;
  277. }
  278. return newHexText.ToUpper();
  279. }
  280. public event ColorEventHandler UserSecondaryColorChanged;
  281. protected virtual void OnUserSecondaryColorChanged(ColorBgra newColor)
  282. {
  283. if (UserSecondaryColorChanged != null && _ignore == 0)
  284. {
  285. _userSecondaryColor = newColor;
  286. UserSecondaryColorChanged(this, new ColorEventArgs(newColor));
  287. _lastSecondaryColor = newColor;
  288. _colorDisplayWidget.UserSecondaryColor = newColor;
  289. }
  290. RenderColorAddIcon(newColor);
  291. }
  292. private ColorBgra _userSecondaryColor;
  293. public ColorBgra UserSecondaryColor
  294. {
  295. get
  296. {
  297. return _userSecondaryColor;
  298. }
  299. set
  300. {
  301. if (IgnoreChangedEvents)
  302. {
  303. return;
  304. }
  305. if (_userSecondaryColor == value) return;
  306. _userSecondaryColor = value;
  307. OnUserSecondaryColorChanged(value);
  308. if (WhichUserColor != WhichUserColor.Secondary)
  309. {
  310. WhichUserColor = WhichUserColor.Secondary;
  311. }
  312. _ignore++;
  313. //only do the update on the last one, so partial RGB info isn't parsed.
  314. Utility.SetNumericUpDownValue(_alphaUpDown, value.A);
  315. Utility.SetNumericUpDownValue(_redUpDown, value.R);
  316. Utility.SetNumericUpDownValue(_greenUpDown, value.G);
  317. SetColorGradientValuesRgb(value.R, value.G, value.B);
  318. SetColorGradientMinMaxColorsRgb(value.R, value.G, value.B);
  319. SetColorGradientMinMaxColorsAlpha(value.A);
  320. _ignore--;
  321. Utility.SetNumericUpDownValue(_blueUpDown, value.B);
  322. Update();
  323. string hexText = GetHexNumericUpDownValue(value.R, value.G, value.B);
  324. _hexBox.Text = hexText;
  325. SyncHsvFromRgb(value);
  326. _colorDisplayWidget.UserSecondaryColor = _userSecondaryColor;
  327. }
  328. }
  329. /// <summary>
  330. /// Convenience function for ColorsForm internals. Checks the value of the
  331. /// WhichUserColor property and raises either the UserPrimaryColorChanged or
  332. /// the UserSecondaryColorChanged events.
  333. /// </summary>
  334. /// <param name="newColor">The new color to notify clients about.</param>
  335. private void OnUserColorChanged(ColorBgra newColor)
  336. {
  337. switch (WhichUserColor)
  338. {
  339. case WhichUserColor.Primary:
  340. OnUserPrimaryColorChanged(newColor);
  341. break;
  342. case WhichUserColor.Secondary:
  343. OnUserSecondaryColorChanged(newColor);
  344. break;
  345. default:
  346. throw new InvalidEnumArgumentException("WhichUserColor property");
  347. }
  348. }
  349. /// <summary>
  350. /// Whenever a color is changed via RGB methods, call this and the HSV
  351. /// counterparts will be sync'd up.
  352. /// </summary>
  353. /// <param name="newColor">The RGB color that should be converted to HSV.</param>
  354. private void SyncHsvFromRgb(ColorBgra newColor)
  355. {
  356. if (_ignore != 0) return;
  357. _ignore++;
  358. HsvColor hsvColor = HsvColor.FromColor(newColor.ToColor());
  359. Utility.SetNumericUpDownValue(_hueUpDown, hsvColor.Hue);
  360. Utility.SetNumericUpDownValue(_saturationUpDown, hsvColor.Saturation);
  361. Utility.SetNumericUpDownValue(_valueUpDown, hsvColor.Value);
  362. SetColorGradientValuesHsv(hsvColor.Hue, hsvColor.Saturation, hsvColor.Value);
  363. SetColorGradientMinMaxColorsHsv(hsvColor.Hue, hsvColor.Saturation, hsvColor.Value);
  364. _colorWheel.HsvColor = hsvColor;
  365. _ignore--;
  366. }
  367. private void SetColorGradientValuesRgb(int r, int g, int b)
  368. {
  369. PushIgnoreChangedEvents();
  370. if (_redGradientControl.Value != r)
  371. {
  372. _redGradientControl.Value = r;
  373. }
  374. if (_greenGradientControl.Value != g)
  375. {
  376. _greenGradientControl.Value = g;
  377. }
  378. if (_blueGradientControl.Value != b)
  379. {
  380. _blueGradientControl.Value = b;
  381. }
  382. PopIgnoreChangedEvents();
  383. }
  384. private void SetColorGradientValuesHsv(int h, int s, int v)
  385. {
  386. PushIgnoreChangedEvents();
  387. if (((_hueGradientControl.Value * 360) / 255) != h)
  388. {
  389. _hueGradientControl.Value = (255 * h) / 360;
  390. }
  391. if (((_saturationGradientControl.Value * 100) / 255) != s)
  392. {
  393. _saturationGradientControl.Value = (255 * s) / 100;
  394. }
  395. if (((_valueGradientControl.Value * 100) / 255) != v)
  396. {
  397. _valueGradientControl.Value = (255 * v) / 100;
  398. }
  399. PopIgnoreChangedEvents();
  400. }
  401. /// <summary>
  402. /// Whenever a color is changed via HSV methods, call this and the RGB
  403. /// counterparts will be sync'd up.
  404. /// </summary>
  405. /// <param name="newColor">The HSV color that should be converted to RGB.</param>
  406. private void SyncRgbFromHsv(HsvColor newColor)
  407. {
  408. if (_ignore != 0) return;
  409. _ignore++;
  410. RgbColor rgbColor = newColor.ToRgb();
  411. Utility.SetNumericUpDownValue(_redUpDown, rgbColor.Red);
  412. Utility.SetNumericUpDownValue(_greenUpDown, rgbColor.Green);
  413. Utility.SetNumericUpDownValue(_blueUpDown, rgbColor.Blue);
  414. string hexText = GetHexNumericUpDownValue(rgbColor.Red, rgbColor.Green, rgbColor.Blue);
  415. _hexBox.Text = hexText;
  416. SetColorGradientValuesRgb(rgbColor.Red, rgbColor.Green, rgbColor.Blue);
  417. SetColorGradientMinMaxColorsRgb(rgbColor.Red, rgbColor.Green, rgbColor.Blue);
  418. SetColorGradientMinMaxColorsAlpha((int)_alphaUpDown.Value);
  419. _ignore--;
  420. }
  421. private void RenderColorAddIcon(ColorBgra newColor)
  422. {
  423. if (_colorAddIcon == null)
  424. {
  425. _colorAddIcon = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
  426. }
  427. using (Graphics g = Graphics.FromImage(_colorAddIcon))
  428. {
  429. var rect = new Rectangle(0, 0, _colorAddIcon.Width - 2, _colorAddIcon.Height - 2);
  430. Utility.DrawColorRectangle(g, rect, newColor.ToColor(), true);
  431. g.DrawImage(_colorAddOverlay, 0, 0);
  432. }
  433. _colorAddButton.Image = _colorAddIcon;
  434. _colorAddButton.Invalidate();
  435. }
  436. public ColorsForm()
  437. {
  438. //
  439. // Required for Windows Form Designer support
  440. //
  441. InitializeComponent();
  442. _whichUserColorBox.Items.Add(new WhichUserColorWrapper(WhichUserColor.Primary));
  443. _whichUserColorBox.Items.Add(new WhichUserColorWrapper(WhichUserColor.Secondary));
  444. _whichUserColorBox.SelectedIndex = 0;
  445. _moreSize = ClientSize;
  446. _lessSize = new Size(_swatchHeader.Width + UI.ScaleWidth(16), _moreSize.Height);
  447. Text = PdnResources.GetString("ColorsForm.Text");
  448. _redLabel.Text = PdnResources.GetString("ColorsForm.RedLabel.Text");
  449. _blueLabel.Text = PdnResources.GetString("ColorsForm.BlueLabel.Text");
  450. _greenLabel.Text = PdnResources.GetString("ColorsForm.GreenLabel.Text");
  451. _saturationLabel.Text = PdnResources.GetString("ColorsForm.SaturationLabel.Text");
  452. _valueLabel.Text = PdnResources.GetString("ColorsForm.ValueLabel.Text");
  453. _hueLabel.Text = PdnResources.GetString("ColorsForm.HueLabel.Text");
  454. _rgbHeader.Text = PdnResources.GetString("ColorsForm.RgbHeader.Text");
  455. _hexLabel.Text = PdnResources.GetString("ColorsForm.HexLabel.Text");
  456. _hsvHeader.Text = PdnResources.GetString("ColorsForm.HsvHeader.Text");
  457. _alphaHeader.Text = PdnResources.GetString("ColorsForm.AlphaHeader.Text");
  458. _lessText = "<< " + PdnResources.GetString("ColorsForm.MoreLessButton.Text.Less");
  459. _moreText = PdnResources.GetString("ColorsForm.MoreLessButton.Text.More") + " >>";
  460. _moreLessButton.Text = _lessText;
  461. _toolStrip.Renderer = new OurToolStripRenderer();
  462. _colorAddOverlay = PdnResources.GetImageResource("Icons.ColorAddOverlay.png").Reference;
  463. _colorPalettesButton.Image = PdnResources.GetImageResource("Icons.ColorPalettes.png").Reference;
  464. RenderColorAddIcon(UserPrimaryColor);
  465. _colorAddButton.ToolTipText = PdnResources.GetString("ColorsForm.ColorAddButton.ToolTipText");
  466. _colorPalettesButton.ToolTipText = PdnResources.GetString("ColorsForm.ColorPalettesButton.ToolTipText");
  467. // Load the current palette
  468. string currentPaletteString;
  469. try
  470. {
  471. currentPaletteString = Settings.CurrentUser.GetString(SettingNames.CurrentPalette, null);
  472. }
  473. catch (Exception)
  474. {
  475. currentPaletteString = null;
  476. }
  477. if (currentPaletteString == null)
  478. {
  479. string defaultPaletteString = PaletteCollection.GetPaletteSaveString(PaletteCollection.DefaultPalette);
  480. currentPaletteString = defaultPaletteString;
  481. }
  482. ColorBgra[] currentPalette = PaletteCollection.ParsePaletteString(currentPaletteString);
  483. _swatchControl.Colors = currentPalette;
  484. }
  485. public override sealed string Text
  486. {
  487. get { return base.Text; }
  488. set { base.Text = value; }
  489. }
  490. protected override void OnLoad(EventArgs e)
  491. {
  492. _inMoreState = true;
  493. _moreLessButton.PerformClick();
  494. base.OnLoad(e);
  495. }
  496. /// <summary>
  497. /// Clean up any resources being used.
  498. /// </summary>
  499. protected override void Dispose(bool disposing)
  500. {
  501. if (disposing)
  502. {
  503. if (_components != null)
  504. {
  505. _components.Dispose();
  506. _components = null;
  507. }
  508. }
  509. base.Dispose(disposing);
  510. }
  511. #region Windows Form Designer generated code
  512. /// <summary>
  513. /// Required method for Designer support - do not modify
  514. /// the contents of this method with the code editor.
  515. /// </summary>
  516. private void InitializeComponent()
  517. {
  518. this._valueGradientControl = new PaintDotNet.ColorGradientControl();
  519. this._colorWheel = new PaintDotNet.ColorWheel();
  520. this._redUpDown = new System.Windows.Forms.NumericUpDown();
  521. this._greenUpDown = new System.Windows.Forms.NumericUpDown();
  522. this._blueUpDown = new System.Windows.Forms.NumericUpDown();
  523. this._redLabel = new System.Windows.Forms.Label();
  524. this._blueLabel = new System.Windows.Forms.Label();
  525. this._greenLabel = new System.Windows.Forms.Label();
  526. this._saturationLabel = new System.Windows.Forms.Label();
  527. this._valueLabel = new System.Windows.Forms.Label();
  528. this._hueLabel = new System.Windows.Forms.Label();
  529. this._valueUpDown = new System.Windows.Forms.NumericUpDown();
  530. this._saturationUpDown = new System.Windows.Forms.NumericUpDown();
  531. this._hueUpDown = new System.Windows.Forms.NumericUpDown();
  532. this._hexBox = new System.Windows.Forms.TextBox();
  533. this._hexLabel = new System.Windows.Forms.Label();
  534. this._whichUserColorBox = new System.Windows.Forms.ComboBox();
  535. this._alphaUpDown = new System.Windows.Forms.NumericUpDown();
  536. this._moreLessButton = new System.Windows.Forms.Button();
  537. this._lessModeButtonSentinel = new System.Windows.Forms.Control();
  538. this._moreModeButtonSentinel = new System.Windows.Forms.Control();
  539. this._lessModeHeaderSentinel = new System.Windows.Forms.Control();
  540. this._moreModeHeaderSentinel = new System.Windows.Forms.Control();
  541. this._rgbHeader = new PaintDotNet.HeaderLabel();
  542. this._hsvHeader = new PaintDotNet.HeaderLabel();
  543. this._alphaHeader = new PaintDotNet.HeaderLabel();
  544. this._swatchHeader = new PaintDotNet.HeaderLabel();
  545. this._swatchControl = new PaintDotNet.SwatchControl();
  546. this._colorDisplayWidget = new PaintDotNet.ColorDisplayWidget();
  547. this._toolStrip = new PaintDotNet.SystemLayer.ToolStripEx();
  548. this._colorAddButton = new System.Windows.Forms.ToolStripButton();
  549. this._colorPalettesButton = new System.Windows.Forms.ToolStripSplitButton();
  550. this._hueGradientControl = new PaintDotNet.ColorGradientControl();
  551. this._saturationGradientControl = new PaintDotNet.ColorGradientControl();
  552. this._alphaGradientControl = new PaintDotNet.ColorGradientControl();
  553. this._redGradientControl = new PaintDotNet.ColorGradientControl();
  554. this._greenGradientControl = new PaintDotNet.ColorGradientControl();
  555. this._blueGradientControl = new PaintDotNet.ColorGradientControl();
  556. ((System.ComponentModel.ISupportInitialize)(this._redUpDown)).BeginInit();
  557. ((System.ComponentModel.ISupportInitialize)(this._greenUpDown)).BeginInit();
  558. ((System.ComponentModel.ISupportInitialize)(this._blueUpDown)).BeginInit();
  559. ((System.ComponentModel.ISupportInitialize)(this._valueUpDown)).BeginInit();
  560. ((System.ComponentModel.ISupportInitialize)(this._saturationUpDown)).BeginInit();
  561. ((System.ComponentModel.ISupportInitialize)(this._hueUpDown)).BeginInit();
  562. ((System.ComponentModel.ISupportInitialize)(this._alphaUpDown)).BeginInit();
  563. this._toolStrip.SuspendLayout();
  564. this.SuspendLayout();
  565. //
  566. // valueGradientControl
  567. //
  568. this._valueGradientControl.Count = 1;
  569. this._valueGradientControl.CustomGradient = null;
  570. this._valueGradientControl.DrawFarNub = true;
  571. this._valueGradientControl.DrawNearNub = false;
  572. this._valueGradientControl.Location = new System.Drawing.Point(243, 185);
  573. this._valueGradientControl.MaxColor = System.Drawing.Color.White;
  574. this._valueGradientControl.MinColor = System.Drawing.Color.Black;
  575. this._valueGradientControl.Name = "_valueGradientControl";
  576. this._valueGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  577. this._valueGradientControl.Size = new System.Drawing.Size(73, 19);
  578. this._valueGradientControl.TabIndex = 2;
  579. this._valueGradientControl.TabStop = false;
  580. this._valueGradientControl.Value = 0;
  581. this._valueGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.HsvGradientControlValueChanged);
  582. //
  583. // colorWheel
  584. //
  585. this._colorWheel.Location = new System.Drawing.Point(65, 35);
  586. this._colorWheel.Name = "_colorWheel";
  587. this._colorWheel.Size = new System.Drawing.Size(129, 130);
  588. this._colorWheel.TabIndex = 3;
  589. this._colorWheel.TabStop = false;
  590. this._colorWheel.ColorChanged += new System.EventHandler(this.ColorWheelColorChanged);
  591. //
  592. // redUpDown
  593. //
  594. this._redUpDown.Location = new System.Drawing.Point(320, 24);
  595. this._redUpDown.Maximum = new decimal(new int[] {
  596. 255,
  597. 0,
  598. 0,
  599. 0});
  600. this._redUpDown.Name = "_redUpDown";
  601. this._redUpDown.Size = new System.Drawing.Size(56, 20);
  602. this._redUpDown.TabIndex = 2;
  603. this._redUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  604. this._redUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  605. this._redUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  606. this._redUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  607. this._redUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  608. //
  609. // greenUpDown
  610. //
  611. this._greenUpDown.Location = new System.Drawing.Point(320, 48);
  612. this._greenUpDown.Maximum = new decimal(new int[] {
  613. 255,
  614. 0,
  615. 0,
  616. 0});
  617. this._greenUpDown.Name = "_greenUpDown";
  618. this._greenUpDown.Size = new System.Drawing.Size(56, 20);
  619. this._greenUpDown.TabIndex = 3;
  620. this._greenUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  621. this._greenUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  622. this._greenUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  623. this._greenUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  624. this._greenUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  625. //
  626. // blueUpDown
  627. //
  628. this._blueUpDown.Location = new System.Drawing.Point(320, 72);
  629. this._blueUpDown.Maximum = new decimal(new int[] {
  630. 255,
  631. 0,
  632. 0,
  633. 0});
  634. this._blueUpDown.Name = "_blueUpDown";
  635. this._blueUpDown.Size = new System.Drawing.Size(56, 20);
  636. this._blueUpDown.TabIndex = 4;
  637. this._blueUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  638. this._blueUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  639. this._blueUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  640. this._blueUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  641. this._blueUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  642. //
  643. // redLabel
  644. //
  645. this._redLabel.AutoSize = true;
  646. this._redLabel.Location = new System.Drawing.Point(222, 28);
  647. this._redLabel.Name = "_redLabel";
  648. this._redLabel.Size = new System.Drawing.Size(15, 13);
  649. this._redLabel.TabIndex = 7;
  650. this._redLabel.Text = "R";
  651. this._redLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  652. //
  653. // blueLabel
  654. //
  655. this._blueLabel.AutoSize = true;
  656. this._blueLabel.Location = new System.Drawing.Point(222, 76);
  657. this._blueLabel.Name = "_blueLabel";
  658. this._blueLabel.Size = new System.Drawing.Size(14, 13);
  659. this._blueLabel.TabIndex = 8;
  660. this._blueLabel.Text = "B";
  661. this._blueLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  662. //
  663. // greenLabel
  664. //
  665. this._greenLabel.AutoSize = true;
  666. this._greenLabel.Location = new System.Drawing.Point(222, 52);
  667. this._greenLabel.Name = "_greenLabel";
  668. this._greenLabel.Size = new System.Drawing.Size(15, 13);
  669. this._greenLabel.TabIndex = 9;
  670. this._greenLabel.Text = "G";
  671. this._greenLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  672. //
  673. // saturationLabel
  674. //
  675. this._saturationLabel.AutoSize = true;
  676. this._saturationLabel.Location = new System.Drawing.Point(222, 164);
  677. this._saturationLabel.Name = "_saturationLabel";
  678. this._saturationLabel.Size = new System.Drawing.Size(17, 13);
  679. this._saturationLabel.TabIndex = 16;
  680. this._saturationLabel.Text = "S:";
  681. this._saturationLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  682. //
  683. // valueLabel
  684. //
  685. this._valueLabel.AutoSize = true;
  686. this._valueLabel.Location = new System.Drawing.Point(222, 188);
  687. this._valueLabel.Name = "_valueLabel";
  688. this._valueLabel.Size = new System.Drawing.Size(17, 13);
  689. this._valueLabel.TabIndex = 15;
  690. this._valueLabel.Text = "V:";
  691. this._valueLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  692. //
  693. // hueLabel
  694. //
  695. this._hueLabel.AutoSize = true;
  696. this._hueLabel.Location = new System.Drawing.Point(222, 140);
  697. this._hueLabel.Name = "_hueLabel";
  698. this._hueLabel.Size = new System.Drawing.Size(18, 13);
  699. this._hueLabel.TabIndex = 14;
  700. this._hueLabel.Text = "H:";
  701. this._hueLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  702. //
  703. // valueUpDown
  704. //
  705. this._valueUpDown.Location = new System.Drawing.Point(320, 184);
  706. this._valueUpDown.Name = "_valueUpDown";
  707. this._valueUpDown.Size = new System.Drawing.Size(56, 20);
  708. this._valueUpDown.TabIndex = 8;
  709. this._valueUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  710. this._valueUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  711. this._valueUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  712. this._valueUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  713. this._valueUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  714. //
  715. // saturationUpDown
  716. //
  717. this._saturationUpDown.Location = new System.Drawing.Point(320, 160);
  718. this._saturationUpDown.Name = "_saturationUpDown";
  719. this._saturationUpDown.Size = new System.Drawing.Size(56, 20);
  720. this._saturationUpDown.TabIndex = 7;
  721. this._saturationUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  722. this._saturationUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  723. this._saturationUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  724. this._saturationUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  725. this._saturationUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  726. //
  727. // hueUpDown
  728. //
  729. this._hueUpDown.Location = new System.Drawing.Point(320, 136);
  730. this._hueUpDown.Maximum = new decimal(new int[] {
  731. 360,
  732. 0,
  733. 0,
  734. 0});
  735. this._hueUpDown.Name = "_hueUpDown";
  736. this._hueUpDown.Size = new System.Drawing.Size(56, 20);
  737. this._hueUpDown.TabIndex = 6;
  738. this._hueUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  739. this._hueUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  740. this._hueUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  741. this._hueUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  742. this._hueUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  743. //
  744. // hexBox
  745. //
  746. this._hexBox.Location = new System.Drawing.Point(320, 96);
  747. this._hexBox.Name = "_hexBox";
  748. this._hexBox.Size = new System.Drawing.Size(56, 20);
  749. this._hexBox.TabIndex = 5;
  750. this._hexBox.Text = "000000";
  751. this._hexBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  752. this._hexBox.Enter += new System.EventHandler(this.HexUpDownEnter);
  753. this._hexBox.Leave += new System.EventHandler(this.HexUpDownLeave);
  754. this._hexBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.HexUpDownKeyUp);
  755. this._hexBox.TextChanged += new System.EventHandler(this.UpDownValueChanged);
  756. //
  757. // hexLabel
  758. //
  759. this._hexLabel.AutoSize = true;
  760. this._hexLabel.Location = new System.Drawing.Point(222, 99);
  761. this._hexLabel.Name = "_hexLabel";
  762. this._hexLabel.Size = new System.Drawing.Size(26, 13);
  763. this._hexLabel.TabIndex = 13;
  764. this._hexLabel.Text = "Hex";
  765. this._hexLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  766. //
  767. // whichUserColorBox
  768. //
  769. this._whichUserColorBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  770. this._whichUserColorBox.Location = new System.Drawing.Point(8, 8);
  771. this._whichUserColorBox.Name = "_whichUserColorBox";
  772. this._whichUserColorBox.Size = new System.Drawing.Size(112, 21);
  773. this._whichUserColorBox.TabIndex = 0;
  774. this._whichUserColorBox.SelectedIndexChanged += new System.EventHandler(this.WhichUserColorBoxSelectedIndexChanged);
  775. //
  776. // alphaUpDown
  777. //
  778. this._alphaUpDown.Location = new System.Drawing.Point(320, 228);
  779. this._alphaUpDown.Maximum = new decimal(new int[] {
  780. 255,
  781. 0,
  782. 0,
  783. 0});
  784. this._alphaUpDown.Name = "_alphaUpDown";
  785. this._alphaUpDown.Size = new System.Drawing.Size(56, 20);
  786. this._alphaUpDown.TabIndex = 10;
  787. this._alphaUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  788. this._alphaUpDown.Enter += new System.EventHandler(this.UpDownEnter);
  789. this._alphaUpDown.ValueChanged += new System.EventHandler(this.UpDownValueChanged);
  790. this._alphaUpDown.Leave += new System.EventHandler(this.UpDownLeave);
  791. this._alphaUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UpDownKeyUp);
  792. //
  793. // moreLessButton
  794. //
  795. this._moreLessButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
  796. this._moreLessButton.Location = new System.Drawing.Point(126, 7);
  797. this._moreLessButton.Name = "_moreLessButton";
  798. this._moreLessButton.Size = new System.Drawing.Size(75, 23);
  799. this._moreLessButton.TabIndex = 1;
  800. this._moreLessButton.Click += new System.EventHandler(this.MoreLessButtonClick);
  801. //
  802. // lessModeButtonSentinel
  803. //
  804. this._lessModeButtonSentinel.Location = new System.Drawing.Point(128, 7);
  805. this._lessModeButtonSentinel.Name = "_lessModeButtonSentinel";
  806. this._lessModeButtonSentinel.Size = new System.Drawing.Size(0, 0);
  807. this._lessModeButtonSentinel.TabIndex = 22;
  808. this._lessModeButtonSentinel.Text = "we put the lessMore control here when in \"Less\" mode";
  809. this._lessModeButtonSentinel.Visible = false;
  810. //
  811. // moreModeButtonSentinel
  812. //
  813. this._moreModeButtonSentinel.Location = new System.Drawing.Point(165, 7);
  814. this._moreModeButtonSentinel.Name = "_moreModeButtonSentinel";
  815. this._moreModeButtonSentinel.Size = new System.Drawing.Size(0, 0);
  816. this._moreModeButtonSentinel.TabIndex = 23;
  817. this._moreModeButtonSentinel.Visible = false;
  818. //
  819. // lessModeHeaderSentinel
  820. //
  821. this._lessModeHeaderSentinel.Location = new System.Drawing.Point(8, 40);
  822. this._lessModeHeaderSentinel.Name = "_lessModeHeaderSentinel";
  823. this._lessModeHeaderSentinel.Size = new System.Drawing.Size(195, 185);
  824. this._lessModeHeaderSentinel.TabIndex = 24;
  825. this._lessModeHeaderSentinel.Visible = false;
  826. //
  827. // moreModeHeaderSentinel
  828. //
  829. this._moreModeHeaderSentinel.Location = new System.Drawing.Point(8, 40);
  830. this._moreModeHeaderSentinel.Name = "_moreModeHeaderSentinel";
  831. this._moreModeHeaderSentinel.Size = new System.Drawing.Size(232, 216);
  832. this._moreModeHeaderSentinel.TabIndex = 25;
  833. this._moreModeHeaderSentinel.TabStop = false;
  834. this._moreModeHeaderSentinel.Visible = false;
  835. //
  836. // rgbHeader
  837. //
  838. this._rgbHeader.Location = new System.Drawing.Point(222, 8);
  839. this._rgbHeader.Name = "_rgbHeader";
  840. this._rgbHeader.RightMargin = 0;
  841. this._rgbHeader.Size = new System.Drawing.Size(154, 14);
  842. this._rgbHeader.TabIndex = 27;
  843. this._rgbHeader.TabStop = false;
  844. //
  845. // hsvHeader
  846. //
  847. this._hsvHeader.Location = new System.Drawing.Point(222, 120);
  848. this._hsvHeader.Name = "_hsvHeader";
  849. this._hsvHeader.RightMargin = 0;
  850. this._hsvHeader.Size = new System.Drawing.Size(154, 14);
  851. this._hsvHeader.TabIndex = 28;
  852. this._hsvHeader.TabStop = false;
  853. //
  854. // alphaHeader
  855. //
  856. this._alphaHeader.Location = new System.Drawing.Point(222, 212);
  857. this._alphaHeader.Name = "_alphaHeader";
  858. this._alphaHeader.RightMargin = 0;
  859. this._alphaHeader.Size = new System.Drawing.Size(154, 14);
  860. this._alphaHeader.TabIndex = 29;
  861. this._alphaHeader.TabStop = false;
  862. //
  863. // swatchHeader
  864. //
  865. this._swatchHeader.Location = new System.Drawing.Point(8, 177);
  866. this._swatchHeader.Name = "_swatchHeader";
  867. this._swatchHeader.RightMargin = 0;
  868. this._swatchHeader.Size = new System.Drawing.Size(193, 14);
  869. this._swatchHeader.TabIndex = 30;
  870. this._swatchHeader.TabStop = false;
  871. //
  872. // swatchControl
  873. //
  874. this._swatchControl.BlinkHighlight = false;
  875. this._swatchControl.Colors = new PaintDotNet.ColorBgra[0];
  876. this._swatchControl.Location = new System.Drawing.Point(8, 189);
  877. this._swatchControl.Name = "_swatchControl";
  878. this._swatchControl.Size = new System.Drawing.Size(192, 74);
  879. this._swatchControl.TabIndex = 31;
  880. this._swatchControl.Text = "swatchControl1";
  881. this._swatchControl.ColorsChanged += this.SwatchControlColorsChanged;
  882. this._swatchControl.ColorClicked += this.SwatchControlColorClicked;
  883. //
  884. // colorDisplayWidget
  885. //
  886. this._colorDisplayWidget.Location = new System.Drawing.Point(4, 32);
  887. this._colorDisplayWidget.Name = "_colorDisplayWidget";
  888. this._colorDisplayWidget.Size = new System.Drawing.Size(52, 52);
  889. this._colorDisplayWidget.TabIndex = 32;
  890. this._colorDisplayWidget.BlackAndWhiteButtonClicked += ColorDisplayWidgetBlackAndWhiteButtonClicked;
  891. this._colorDisplayWidget.SwapColorsClicked += ColorDisplayWidgetSwapColorsClicked;
  892. this._colorDisplayWidget.UserPrimaryColorClick += ColorDisplayPrimaryColorClicked;
  893. this._colorDisplayWidget.UserSecondaryColorClick += ColorDisplaySecondaryColorClicked;
  894. //
  895. // toolStrip
  896. //
  897. this._toolStrip.ClickThrough = true;
  898. this._toolStrip.Dock = System.Windows.Forms.DockStyle.None;
  899. this._toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
  900. this._toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  901. this._colorAddButton,
  902. this._colorPalettesButton});
  903. this._toolStrip.Location = new System.Drawing.Point(5, 157);
  904. this._toolStrip.ManagedFocus = true;
  905. this._toolStrip.Name = "_toolStrip";
  906. this._toolStrip.Size = new System.Drawing.Size(65, 25);
  907. this._toolStrip.TabIndex = 33;
  908. this._toolStrip.Text = "toolStrip";
  909. //
  910. // colorAddButton
  911. //
  912. this._colorAddButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  913. this._colorAddButton.ImageTransparentColor = System.Drawing.Color.Magenta;
  914. this._colorAddButton.Name = "colorAddButton";
  915. this._colorAddButton.Size = new System.Drawing.Size(23, 22);
  916. this._colorAddButton.Text = "colorAddButton";
  917. this._colorAddButton.Click += new System.EventHandler(this.ColorAddButtonClick);
  918. //
  919. // colorPalettesButton
  920. //
  921. this._colorPalettesButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
  922. this._colorPalettesButton.Name = "colorPalettesButton";
  923. this._colorPalettesButton.Size = new System.Drawing.Size(16, 22);
  924. this._colorPalettesButton.Click += new System.EventHandler(this.ColorPalettesButtonClick);
  925. this._colorPalettesButton.DropDownOpening += new System.EventHandler(this.ColorPalettesButtonDropDownOpening);
  926. //
  927. // hueGradientControl
  928. //
  929. this._hueGradientControl.Count = 1;
  930. this._hueGradientControl.CustomGradient = null;
  931. this._hueGradientControl.DrawFarNub = true;
  932. this._hueGradientControl.DrawNearNub = false;
  933. this._hueGradientControl.Location = new System.Drawing.Point(243, 137);
  934. this._hueGradientControl.MaxColor = System.Drawing.Color.White;
  935. this._hueGradientControl.MinColor = System.Drawing.Color.Black;
  936. this._hueGradientControl.Name = "_hueGradientControl";
  937. this._hueGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  938. this._hueGradientControl.Size = new System.Drawing.Size(73, 19);
  939. this._hueGradientControl.TabIndex = 34;
  940. this._hueGradientControl.TabStop = false;
  941. this._hueGradientControl.Value = 0;
  942. this._hueGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.HsvGradientControlValueChanged);
  943. //
  944. // saturationGradientControl
  945. //
  946. this._saturationGradientControl.Count = 1;
  947. this._saturationGradientControl.CustomGradient = null;
  948. this._saturationGradientControl.DrawFarNub = true;
  949. this._saturationGradientControl.DrawNearNub = false;
  950. this._saturationGradientControl.Location = new System.Drawing.Point(243, 161);
  951. this._saturationGradientControl.MaxColor = System.Drawing.Color.White;
  952. this._saturationGradientControl.MinColor = System.Drawing.Color.Black;
  953. this._saturationGradientControl.Name = "_saturationGradientControl";
  954. this._saturationGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  955. this._saturationGradientControl.Size = new System.Drawing.Size(73, 19);
  956. this._saturationGradientControl.TabIndex = 35;
  957. this._saturationGradientControl.TabStop = false;
  958. this._saturationGradientControl.Value = 0;
  959. this._saturationGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.HsvGradientControlValueChanged);
  960. //
  961. // alphaGradientControl
  962. //
  963. this._alphaGradientControl.Count = 1;
  964. this._alphaGradientControl.CustomGradient = null;
  965. this._alphaGradientControl.DrawFarNub = true;
  966. this._alphaGradientControl.DrawNearNub = false;
  967. this._alphaGradientControl.Location = new System.Drawing.Point(243, 229);
  968. this._alphaGradientControl.MaxColor = System.Drawing.Color.White;
  969. this._alphaGradientControl.MinColor = System.Drawing.Color.Black;
  970. this._alphaGradientControl.Name = "_alphaGradientControl";
  971. this._alphaGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  972. this._alphaGradientControl.Size = new System.Drawing.Size(73, 19);
  973. this._alphaGradientControl.TabIndex = 36;
  974. this._alphaGradientControl.TabStop = false;
  975. this._alphaGradientControl.Value = 0;
  976. this._alphaGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.UpDownValueChanged);
  977. //
  978. // redGradientControl
  979. //
  980. this._redGradientControl.Count = 1;
  981. this._redGradientControl.CustomGradient = null;
  982. this._redGradientControl.DrawFarNub = true;
  983. this._redGradientControl.DrawNearNub = false;
  984. this._redGradientControl.Location = new System.Drawing.Point(243, 25);
  985. this._redGradientControl.MaxColor = System.Drawing.Color.White;
  986. this._redGradientControl.MinColor = System.Drawing.Color.Black;
  987. this._redGradientControl.Name = "_redGradientControl";
  988. this._redGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  989. this._redGradientControl.Size = new System.Drawing.Size(73, 19);
  990. this._redGradientControl.TabIndex = 37;
  991. this._redGradientControl.TabStop = false;
  992. this._redGradientControl.Value = 0;
  993. this._redGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.RgbGradientControlValueChanged);
  994. //
  995. // greenGradientControl
  996. //
  997. this._greenGradientControl.Count = 1;
  998. this._greenGradientControl.CustomGradient = null;
  999. this._greenGradientControl.DrawFarNub = true;
  1000. this._greenGradientControl.DrawNearNub = false;
  1001. this._greenGradientControl.Location = new System.Drawing.Point(243, 49);
  1002. this._greenGradientControl.MaxColor = System.Drawing.Color.White;
  1003. this._greenGradientControl.MinColor = System.Drawing.Color.Black;
  1004. this._greenGradientControl.Name = "_greenGradientControl";
  1005. this._greenGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  1006. this._greenGradientControl.Size = new System.Drawing.Size(73, 19);
  1007. this._greenGradientControl.TabIndex = 38;
  1008. this._greenGradientControl.TabStop = false;
  1009. this._greenGradientControl.Value = 0;
  1010. this._greenGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.RgbGradientControlValueChanged);
  1011. //
  1012. // blueGradientControl
  1013. //
  1014. this._blueGradientControl.Count = 1;
  1015. this._blueGradientControl.CustomGradient = null;
  1016. this._blueGradientControl.DrawFarNub = true;
  1017. this._blueGradientControl.DrawNearNub = false;
  1018. this._blueGradientControl.Location = new System.Drawing.Point(243, 73);
  1019. this._blueGradientControl.MaxColor = System.Drawing.Color.White;
  1020. this._blueGradientControl.MinColor = System.Drawing.Color.Black;
  1021. this._blueGradientControl.Name = "_blueGradientControl";
  1022. this._blueGradientControl.Orientation = System.Windows.Forms.Orientation.Horizontal;
  1023. this._blueGradientControl.Size = new System.Drawing.Size(73, 19);
  1024. this._blueGradientControl.TabIndex = 39;
  1025. this._blueGradientControl.TabStop = false;
  1026. this._blueGradientControl.Value = 0;
  1027. this._blueGradientControl.ValueChanged += new PaintDotNet.IndexEventHandler(this.RgbGradientControlValueChanged);
  1028. //
  1029. // ColorsForm
  1030. //
  1031. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  1032. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
  1033. this.ClientSize = new System.Drawing.Size(386, 266);
  1034. this.Controls.Add(this._valueLabel);
  1035. this.Controls.Add(this._saturationLabel);
  1036. this.Controls.Add(this._hueLabel);
  1037. this.Controls.Add(this._greenLabel);
  1038. this.Controls.Add(this._blueLabel);
  1039. this.Controls.Add(this._redLabel);
  1040. this.Controls.Add(this._hexLabel);
  1041. this.Controls.Add(this._blueGradientControl);
  1042. this.Controls.Add(this._greenGradientControl);
  1043. this.Controls.Add(this._redGradientControl);
  1044. this.Controls.Add(this._alphaGradientControl);
  1045. this.Controls.Add(this._saturationGradientControl);
  1046. this.Controls.Add(this._hueGradientControl);
  1047. this.Controls.Add(this._toolStrip);
  1048. this.Controls.Add(this._colorWheel);
  1049. this.Controls.Add(this._colorDisplayWidget);
  1050. this.Controls.Add(this._swatchControl);
  1051. this.Controls.Add(this._swatchHeader);
  1052. this.Controls.Add(this._alphaHeader);
  1053. this.Controls.Add(this._hsvHeader);
  1054. this.Controls.Add(this._rgbHeader);
  1055. this.Controls.Add(this._valueGradientControl);
  1056. this.Controls.Add(this._moreModeButtonSentinel);
  1057. this.Controls.Add(this._lessModeButtonSentinel);
  1058. this.Controls.Add(this._moreLessButton);
  1059. this.Controls.Add(this._whichUserColorBox);
  1060. this.Controls.Add(this._lessModeHeaderSentinel);
  1061. this.Controls.Add(this._moreModeHeaderSentinel);
  1062. this.Controls.Add(this._blueUpDown);
  1063. this.Controls.Add(this._greenUpDown);
  1064. this.Controls.Add(this._redUpDown);
  1065. this.Controls.Add(this._hexBox);
  1066. this.Controls.Add(this._hueUpDown);
  1067. this.Controls.Add(this._saturationUpDown);
  1068. this.Controls.Add(this._valueUpDown);
  1069. this.Controls.Add(this._alphaUpDown);
  1070. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  1071. this.Name = "ColorsForm";
  1072. this.Controls.SetChildIndex(this._alphaUpDown, 0);
  1073. this.Controls.SetChildIndex(this._valueUpDown, 0);
  1074. this.Controls.SetChildIndex(this._saturationUpDown, 0);
  1075. this.Controls.SetChildIndex(this._hueUpDown, 0);
  1076. this.Controls.SetChildIndex(this._hexBox, 0);
  1077. this.Controls.SetChildIndex(this._redUpDown, 0);
  1078. this.Controls.SetChildIndex(this._greenUpDown, 0);
  1079. this.Controls.SetChildIndex(this._blueUpDown, 0);
  1080. this.Controls.SetChildIndex(this._moreModeHeaderSentinel, 0);
  1081. this.Controls.SetChildIndex(this._lessModeHeaderSentinel, 0);
  1082. this.Controls.SetChildIndex(this._whichUserColorBox, 0);
  1083. this.Controls.SetChildIndex(this._moreLessButton, 0);
  1084. this.Controls.SetChildIndex(this._lessModeButtonSentinel, 0);
  1085. this.Controls.SetChildIndex(this._moreModeButtonSentinel, 0);
  1086. this.Controls.SetChildIndex(this._valueGradientControl, 0);
  1087. this.Controls.SetChildIndex(this._rgbHeader, 0);
  1088. this.Controls.SetChildIndex(this._hsvHeader, 0);
  1089. this.Controls.SetChildIndex(this._alphaHeader, 0);
  1090. this.Controls.SetChildIndex(this._swatchHeader, 0);
  1091. this.Controls.SetChildIndex(this._swatchControl, 0);
  1092. this.Controls.SetChildIndex(this._colorDisplayWidget, 0);
  1093. this.Controls.SetChildIndex(this._colorWheel, 0);
  1094. this.Controls.SetChildIndex(this._toolStrip, 0);
  1095. this.Controls.SetChildIndex(this._hueGradientControl, 0);
  1096. this.Controls.SetChildIndex(this._saturationGradientControl, 0);
  1097. this.Controls.SetChildIndex(this._alphaGradientControl, 0);
  1098. this.Controls.SetChildIndex(this._redGradientControl, 0);
  1099. this.Controls.SetChildIndex(this._greenGradientControl, 0);
  1100. this.Controls.SetChildIndex(this._blueGradientControl, 0);
  1101. this.Controls.SetChildIndex(this._hexLabel, 0);
  1102. this.Controls.SetChildIndex(this._redLabel, 0);
  1103. this.Controls.SetChildIndex(this._blueLabel, 0);
  1104. this.Controls.SetChildIndex(this._greenLabel, 0);
  1105. this.Controls.SetChildIndex(this._hueLabel, 0);
  1106. this.Controls.SetChildIndex(this._saturationLabel, 0);
  1107. this.Controls.SetChildIndex(this._valueLabel, 0);
  1108. ((System.ComponentModel.ISupportInitialize)(this._redUpDown)).EndInit();
  1109. ((System.ComponentModel.ISupportInitialize)(this._greenUpDown)).EndInit();
  1110. ((System.ComponentModel.ISupportInitialize)(this._blueUpDown)).EndInit();
  1111. ((System.ComponentModel.ISupportInitialize)(this._valueUpDown)).EndInit();
  1112. ((System.ComponentModel.ISupportInitialize)(this._saturationUpDown)).EndInit();
  1113. ((System.ComponentModel.ISupportInitialize)(this._hueUpDown)).EndInit();
  1114. ((System.ComponentModel.ISupportInitialize)(this._alphaUpDown)).EndInit();
  1115. this._toolStrip.ResumeLayout(false);
  1116. this._toolStrip.PerformLayout();
  1117. this.ResumeLayout(false);
  1118. this.PerformLayout();
  1119. }
  1120. #endregion
  1121. public void SetUserColors(ColorBgra primary, ColorBgra secondary)
  1122. {
  1123. SetColorControlsRedraw(false);
  1124. WhichUserColor which = WhichUserColor;
  1125. UserPrimaryColor = primary;
  1126. UserSecondaryColor = secondary;
  1127. WhichUserColor = which;
  1128. SetColorControlsRedraw(true);
  1129. }
  1130. public void SwapUserColors()
  1131. {
  1132. ColorBgra primary = UserPrimaryColor;
  1133. ColorBgra secondary = UserSecondaryColor;
  1134. SetUserColors(secondary, primary);
  1135. }
  1136. public void SetUserColorsToBlackAndWhite()
  1137. {
  1138. SetUserColors(ColorBgra.Black, ColorBgra.White);
  1139. }
  1140. private void ColorDisplayWidgetSwapColorsClicked(object sender, EventArgs e)
  1141. {
  1142. SwapUserColors();
  1143. OnRelinquishFocus();
  1144. }
  1145. private void ColorDisplayWidgetBlackAndWhiteButtonClicked(object sender, EventArgs e)
  1146. {
  1147. SetUserColorsToBlackAndWhite();
  1148. OnRelinquishFocus();
  1149. }
  1150. private void ColorDisplayPrimaryColorClicked(object sender, EventArgs e)
  1151. {
  1152. WhichUserColor = WhichUserColor.Primary;
  1153. OnRelinquishFocus();
  1154. }
  1155. private void ColorDisplaySecondaryColorClicked(object sender, EventArgs e)
  1156. {
  1157. WhichUserColor = WhichUserColor.Secondary;
  1158. OnRelinquishFocus();
  1159. }
  1160. private void WhichUserColorBoxSelectedIndexChanged(object sender, EventArgs e)
  1161. {
  1162. ColorBgra color;
  1163. switch (WhichUserColor)
  1164. {
  1165. case WhichUserColor.Primary:
  1166. color = _userPrimaryColor;
  1167. break;
  1168. case WhichUserColor.Secondary:
  1169. color = _userSecondaryColor;
  1170. break;
  1171. default:
  1172. throw new InvalidEnumArgumentException("WhichUserColor property");
  1173. }
  1174. PushIgnoreChangedEvents();
  1175. Utility.SetNumericUpDownValue(_redUpDown, color.R);
  1176. Utility.SetNumericUpDownValue(_greenUpDown, color.G);
  1177. Utility.SetNumericUpDownValue(_blueUpDown, color.B);
  1178. string hexText = GetHexNumericUpDownValue(color.R, color.G, color.B);
  1179. _hexBox.Text = hexText;
  1180. Utility.SetNumericUpDownValue(_alphaUpDown, color.A);
  1181. PopIgnoreChangedEvents();
  1182. SetColorGradientMinMaxColorsRgb(color.R, color.G, color.B);
  1183. SetColorGradientValuesRgb(color.R, color.G, color.B);
  1184. SetColorGradientMinMaxColorsAlpha(color.A);
  1185. SyncHsvFromRgb(color);
  1186. OnRelinquishFocus();
  1187. }
  1188. private void ColorWheelColorChanged(object sender, EventArgs e)
  1189. {
  1190. if (IgnoreChangedEvents)
  1191. {
  1192. return;
  1193. }
  1194. PushIgnoreChangedEvents();
  1195. HsvColor hsvColor = _colorWheel.HsvColor;
  1196. RgbColor rgbColor = hsvColor.ToRgb();
  1197. ColorBgra color = ColorBgra.FromBgra((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red, (byte)_alphaUpDown.Value);
  1198. Utility.SetNumericUpDownValue(_hueUpDown, hsvColor.Hue);
  1199. Utility.SetNumericUpDownValue(_saturationUpDown, hsvColor.Saturation);
  1200. Utility.SetNumericUpDownValue(_valueUpDown, hsvColor.Value);
  1201. Utility.SetNumericUpDownValue(_redUpDown, color.R);
  1202. Utility.SetNumericUpDownValue(_greenUpDown, color.G);
  1203. Utility.SetNumericUpDownValue(_blueUpDown, color.B);
  1204. string hexText = GetHexNumericUpDownValue(color.R, color.G, color.B);
  1205. _hexBox.Text = hexText;
  1206. Utility.SetNumericUpDownValue(_alphaUpDown, color.A);
  1207. SetColorGradientValuesHsv(hsvColor.Hue, hsvColor.Saturation, hsvColor.Value);
  1208. SetColorGradientMinMaxColorsHsv(hsvColor.Hue, hsvColor.Saturation, hsvColor.Value);
  1209. SetColorGradientValuesRgb(color.R, color.G, color.B);
  1210. SetColorGradientMinMaxColorsRgb(color.R, color.G, color.B);
  1211. SetColorGradientMinMaxColorsAlpha(color.A);
  1212. switch (WhichUserColor)
  1213. {
  1214. case WhichUserColor.Primary:
  1215. //UserPrimaryColor = color;
  1216. _userPrimaryColor = color;
  1217. OnUserPrimaryColorChanged(color);
  1218. OnRelinquishFocus();
  1219. break;
  1220. case WhichUserColor.Secondary:
  1221. //UserSecondaryColor = color;
  1222. _userSecondaryColor = color;
  1223. OnUserSecondaryColorChanged(color);
  1224. OnRelinquishFocus();
  1225. break;
  1226. default:
  1227. throw new InvalidEnumArgumentException("WhichUserColor property");
  1228. }
  1229. PopIgnoreChangedEvents();
  1230. Update();
  1231. }
  1232. private void SetColorGradientMinMaxColorsHsv(int h, int s, int v)
  1233. {
  1234. var hueColors = new Color[361];
  1235. for (int newH = 0; newH <= 360; ++newH)
  1236. {
  1237. var hsv = new HsvColor(newH, 100, 100);
  1238. hueColors[newH] = hsv.ToColor();
  1239. }
  1240. _hueGradientControl.CustomGradient = hueColors;
  1241. var satColors = new Color[101];
  1242. for (int newS = 0; newS <= 100; ++newS)
  1243. {
  1244. var hsv = new HsvColor(h, newS, v);
  1245. satColors[newS] = hsv.ToColor();
  1246. }
  1247. _saturationGradientControl.CustomGradient = satColors;
  1248. _valueGradientControl.MaxColor = new HsvColor(h, s, 100).ToColor();
  1249. _valueGradientControl.MinColor = new HsvColor(h, s, 0).ToColor();
  1250. }
  1251. private void SetColorGradientMinMaxColorsRgb(int r, int g, int b)
  1252. {
  1253. _redGradientControl.MaxColor = Color.FromArgb(255, g, b);
  1254. _redGradientControl.MinColor = Color.FromArgb(0, g, b);
  1255. _greenGradientControl.MaxColor = Color.FromArgb(r, 255, b);
  1256. _greenGradientControl.MinColor = Color.FromArgb(r, 0, b);
  1257. _blueGradientControl.MaxColor = Color.FromArgb(r, g, 255);
  1258. _blueGradientControl.MinColor = Color.FromArgb(r, g, 0);
  1259. }
  1260. private void SetColorGradientMinMaxColorsAlpha(int a)
  1261. {
  1262. var colors = new Color[256];
  1263. for (int newA = 0; newA <= 255; ++newA)
  1264. {
  1265. colors[newA] = Color.FromArgb(newA, _redGradientControl.Value,
  1266. _greenGradientControl.Value, _blueGradientControl.Value);
  1267. }
  1268. _alphaGradientControl.CustomGradient = colors;
  1269. }
  1270. private void RgbGradientControlValueChanged(object sender, IndexEventArgs ce)
  1271. {
  1272. if (IgnoreChangedEvents)
  1273. {
  1274. return;
  1275. }
  1276. int red;
  1277. if (sender == _redGradientControl)
  1278. {
  1279. red = _redGradientControl.Value;
  1280. }
  1281. else
  1282. {
  1283. red = (int)_redUpDown.Value;
  1284. }
  1285. int green;
  1286. if (sender == _greenGradientControl)
  1287. {
  1288. green = _greenGradientControl.Value;
  1289. }
  1290. else
  1291. {
  1292. green = (int)_greenUpDown.Value;
  1293. }
  1294. int blue;
  1295. if (sender == _blueGradientControl)
  1296. {
  1297. blue = _blueGradientControl.Value;
  1298. }
  1299. else
  1300. {
  1301. blue = (int)_blueUpDown.Value;
  1302. }
  1303. int alpha;
  1304. if (sender == _alphaGradientControl)
  1305. {
  1306. alpha = _alphaGradientControl.Value;
  1307. }
  1308. else
  1309. {
  1310. alpha = (int)_alphaUpDown.Value;
  1311. }
  1312. Color rgbColor = Color.FromArgb(alpha, red, green, blue);
  1313. HsvColor hsvColor = HsvColor.FromColor(rgbColor);
  1314. PushIgnoreChangedEvents();
  1315. Utility.SetNumericUpDownValue(_hueUpDown, hsvColor.Hue);
  1316. Utility.SetNumericUpDownValue(_saturationUpDown, hsvColor.Saturation);
  1317. Utility.SetNumericUpDownValue(_valueUpDown, hsvColor.Value);
  1318. Utility.SetNumericUpDownValue(_redUpDown, rgbColor.R);
  1319. Utility.SetNumericUpDownValue(_greenUpDown, rgbColor.G);
  1320. Utility.SetNumericUpDownValue(_blueUpDown, rgbColor.B);
  1321. PopIgnoreChangedEvents();
  1322. Utility.SetNumericUpDownValue(_alphaUpDown, rgbColor.A);
  1323. string hexText = GetHexNumericUpDownValue(rgbColor.R, rgbColor.G, rgbColor.B);
  1324. _hexBox.Text = hexText;
  1325. ColorBgra color = ColorBgra.FromColor(rgbColor);
  1326. switch (WhichUserColor)
  1327. {
  1328. case WhichUserColor.Primary:
  1329. UserPrimaryColor = color;
  1330. OnRelinquishFocus();
  1331. break;
  1332. case WhichUserColor.Secondary:
  1333. UserSecondaryColor = color;
  1334. OnRelinquishFocus();
  1335. break;
  1336. default:
  1337. throw new InvalidEnumArgumentException("WhichUserColor property");
  1338. }
  1339. Update();
  1340. }
  1341. private void HsvGradientControlValueChanged(object sender, IndexEventArgs e)
  1342. {
  1343. if (IgnoreChangedEvents)
  1344. {
  1345. return;
  1346. }
  1347. int hue;
  1348. if (sender == _hueGradientControl)
  1349. {
  1350. hue = (_hueGradientControl.Value * 360) / 255;
  1351. }
  1352. else
  1353. {
  1354. hue = (int)_hueUpDown.Value;
  1355. }
  1356. int saturation;
  1357. if (sender == _saturationGradientControl)
  1358. {
  1359. saturation = (_saturationGradientControl.Value * 100) / 255;
  1360. }
  1361. else
  1362. {
  1363. saturation = (int)_saturationUpDown.Value;
  1364. }
  1365. int value;
  1366. if (sender == _valueGradientControl)
  1367. {
  1368. value = (_valueGradientControl.Value * 100) / 255;
  1369. }
  1370. else
  1371. {
  1372. value = (int)_valueUpDown.Value;
  1373. }
  1374. var hsvColor = new HsvColor(hue, saturation, value);
  1375. _colorWheel.HsvColor = hsvColor;
  1376. RgbColor rgbColor = hsvColor.ToRgb();
  1377. ColorBgra color = ColorBgra.FromBgra((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red, (byte)_alphaUpDown.Value);
  1378. Utility.SetNumericUpDownValue(_hueUpDown, hsvColor.Hue);
  1379. Utility.SetNumericUpDownValue(_saturationUpDown, hsvColor.Saturation);
  1380. Utility.SetNumericUpDownValue(_valueUpDown, hsvColor.Value);
  1381. Utility.SetNumericUpDownValue(_redUpDown, rgbColor.Red);
  1382. Utility.SetNumericUpDownValue(_greenUpDown, rgbColor.Green);
  1383. Utility.SetNumericUpDownValue(_blueUpDown, rgbColor.Blue);
  1384. string hexText = GetHexNumericUpDownValue(rgbColor.Red, rgbColor.Green, rgbColor.Blue);
  1385. _hexBox.Text = hexText;
  1386. switch (WhichUserColor)
  1387. {
  1388. case WhichUserColor.Primary:
  1389. UserPrimaryColor = color;
  1390. OnRelinquishFocus();
  1391. break;
  1392. case WhichUserColor.Secondary:
  1393. UserSecondaryColor = color;
  1394. OnRelinquishFocus();
  1395. break;
  1396. default:
  1397. throw new InvalidEnumArgumentException("WhichUserColor property");
  1398. }
  1399. Update();
  1400. }
  1401. private void UpDownEnter(object sender, EventArgs e)
  1402. {
  1403. var nud = (NumericUpDown)sender;
  1404. nud.Select(0, nud.Text.Length);
  1405. }
  1406. private void UpDownLeave(object sender, EventArgs e)
  1407. {
  1408. UpDownValueChanged(sender, e);
  1409. }
  1410. private void HexUpDownEnter(object sender, EventArgs e)
  1411. {
  1412. var tb = (TextBox)sender;
  1413. tb.Select(0, tb.Text.Length);
  1414. }
  1415. private void HexUpDownLeave(object sender, EventArgs e)
  1416. {
  1417. _hexBox.Text = _hexBox.Text.ToUpper();
  1418. UpDownValueChanged(sender, e);
  1419. }
  1420. private void HexUpDownKeyUp(object sender, KeyEventArgs e)
  1421. {
  1422. var tb = (TextBox)sender;
  1423. if (CheckHexBox(tb.Text))
  1424. {
  1425. UpDownValueChanged(sender, e);
  1426. }
  1427. }
  1428. private static bool CheckHexBox(String checkHex)
  1429. {
  1430. int num;
  1431. try
  1432. {
  1433. num = int.Parse(checkHex, System.Globalization.NumberStyles.HexNumber);
  1434. }
  1435. catch (FormatException)
  1436. {
  1437. return false;
  1438. }
  1439. catch (OverflowException)
  1440. {
  1441. return false;
  1442. }
  1443. return (num <= 16777215) && (num >= 0);
  1444. }
  1445. private void UpDownKeyUp(object sender, KeyEventArgs e)
  1446. {
  1447. var nud = (NumericUpDown)sender;
  1448. if (Utility.CheckNumericUpDown(nud))
  1449. {
  1450. UpDownValueChanged(sender, e);
  1451. }
  1452. }
  1453. private void UpDownValueChanged(object sender, EventArgs e)
  1454. {
  1455. if (sender == _alphaUpDown || sender == _alphaGradientControl)
  1456. {
  1457. if (sender == _alphaGradientControl)
  1458. {
  1459. if (_alphaUpDown.Value != _alphaGradientControl.Value)
  1460. {
  1461. _alphaUpDown.Value = _alphaGradientControl.Value;
  1462. }
  1463. }
  1464. else
  1465. {
  1466. if (_alphaGradientControl.Value != (int)_alphaUpDown.Value)
  1467. {
  1468. _alphaGradientControl.Value = (int)_alphaUpDown.Value;
  1469. }
  1470. }
  1471. PushIgnoreChangedEvents();
  1472. switch (WhichUserColor)
  1473. {
  1474. case WhichUserColor.Primary:
  1475. ColorBgra newPrimaryColor = ColorBgra.FromBgra(_lastPrimaryColor.B, _lastPrimaryColor.G, _lastPrimaryColor.R, (byte)_alphaGradientControl.Value);
  1476. _userPrimaryColor = newPrimaryColor;
  1477. OnUserPrimaryColorChanged(newPrimaryColor);
  1478. break;
  1479. case WhichUserColor.Secondary:
  1480. ColorBgra newSecondaryColor = ColorBgra.FromBgra(_lastSecondaryColor.B, _lastSecondaryColor.G, _lastSecondaryColor.R, (byte)_alphaGradientControl.Value);
  1481. _userSecondaryColor = newSecondaryColor;
  1482. OnUserSecondaryColorChanged(newSecondaryColor);
  1483. break;
  1484. default:
  1485. throw new InvalidEnumArgumentException("WhichUserColor property");
  1486. }
  1487. PopIgnoreChangedEvents();
  1488. Update();
  1489. }
  1490. else if (IgnoreChangedEvents)
  1491. {
  1492. return;
  1493. }
  1494. else
  1495. {
  1496. PushIgnoreChangedEvents();
  1497. if (sender == _redUpDown || sender == _greenUpDown || sender == _blueUpDown)
  1498. {
  1499. string hexText = GetHexNumericUpDownValue((int)_redUpDown.Value, (int)_greenUpDown.Value, (int)_blueUpDown.Value);
  1500. _hexBox.Text = hexText;
  1501. ColorBgra rgbColor = ColorBgra.FromBgra((byte)_blueUpDown.Value, (byte)_greenUpDown.Value, (byte)_redUpDown.Value, (byte)_alphaUpDown.Value);
  1502. SetColorGradientMinMaxColorsRgb(rgbColor.R, rgbColor.G, rgbColor.B);
  1503. SetColorGradientMinMaxColorsAlpha(rgbColor.A);
  1504. SetColorGradientValuesRgb(rgbColor.R, rgbColor.G, rgbColor.B);
  1505. SetColorGradientMinMaxColorsAlpha(rgbColor.A);
  1506. SyncHsvFromRgb(rgbColor);
  1507. OnUserColorChanged(rgbColor);
  1508. }
  1509. else if (sender == _hexBox)
  1510. {
  1511. int hexInt = 0;
  1512. if (_hexBox.Text.Length > 0)
  1513. {
  1514. try
  1515. {
  1516. hexInt = int.Parse(_hexBox.Text,System.Globalization.NumberStyles.HexNumber);
  1517. }
  1518. // Needs to be changed so it reads what the RGB values were last
  1519. catch (FormatException)
  1520. {
  1521. hexInt = 0;
  1522. _hexBox.Text = "";
  1523. }
  1524. catch (OverflowException)
  1525. {
  1526. hexInt = 16777215;
  1527. _hexBox.Text = "FFFFFF";
  1528. }
  1529. if (!((hexInt <= 16777215) && (hexInt >= 0)))
  1530. {
  1531. hexInt = 16777215;
  1532. _hexBox.Text = "FFFFFF";
  1533. }
  1534. }
  1535. int newRed = ((hexInt & 0xff0000) >> 16);
  1536. int newGreen = ((hexInt & 0x00ff00) >> 8);
  1537. int newBlue = (hexInt & 0x0000ff);
  1538. Utility.SetNumericUpDownValue(_redUpDown, newRed);
  1539. Utility.SetNumericUpDownValue(_greenUpDown, newGreen);
  1540. Utility.SetNumericUpDownValue(_blueUpDown, newBlue);
  1541. SetColorGradientMinMaxColorsRgb(newRed, newGreen, newBlue);
  1542. SetColorGradientValuesRgb(newRed, newGreen, newBlue);
  1543. SetColorGradientMinMaxColorsAlpha((int)_alphaUpDown.Value);
  1544. ColorBgra rgbColor = ColorBgra.FromBgra((byte)newBlue, (byte)newGreen, (byte)newRed, (byte)_alphaUpDown.Value);
  1545. SyncHsvFromRgb(rgbColor);
  1546. OnUserColorChanged(rgbColor);
  1547. }
  1548. else if (sender == _hueUpDown || sender == _saturationUpDown || sender == _valueUpDown)
  1549. {
  1550. HsvColor oldHsvColor = _colorWheel.HsvColor;
  1551. var newHsvColor = new HsvColor((int)_hueUpDown.Value, (int)_saturationUpDown.Value, (int)_valueUpDown.Value);
  1552. if (oldHsvColor != newHsvColor)
  1553. {
  1554. _colorWheel.HsvColor = newHsvColor;
  1555. SetColorGradientValuesHsv(newHsvColor.Hue, newHsvColor.Saturation, newHsvColor.Value);
  1556. SetColorGradientMinMaxColorsHsv(newHsvColor.Hue, newHsvColor.Saturation, newHsvColor.Value);
  1557. SyncRgbFromHsv(newHsvColor);
  1558. RgbColor rgbColor = newHsvColor.ToRgb();
  1559. OnUserColorChanged(ColorBgra.FromBgra((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red, (byte)_alphaUpDown.Value));
  1560. }
  1561. }
  1562. PopIgnoreChangedEvents();
  1563. }
  1564. }
  1565. private void PushIgnoreChangedEvents()
  1566. {
  1567. ++_ignoreChangedEvents;
  1568. }
  1569. private void PopIgnoreChangedEvents()
  1570. {
  1571. --_ignoreChangedEvents;
  1572. }
  1573. private void MoreLessButtonClick(object sender, EventArgs e)
  1574. {
  1575. OnRelinquishFocus();
  1576. SuspendLayout();
  1577. if (_inMoreState)
  1578. {
  1579. _inMoreState = false;
  1580. Size newSize = _lessSize;
  1581. _moreLessButton.Text = _moreText;
  1582. int heightDelta = (_moreModeHeaderSentinel.Height - _lessModeHeaderSentinel.Height);
  1583. newSize.Height -= heightDelta;
  1584. newSize.Height -= UI.ScaleHeight(18);
  1585. ClientSize = newSize;
  1586. }
  1587. else
  1588. {
  1589. _inMoreState = true;
  1590. _moreLessButton.Text = _lessText;
  1591. ClientSize = _moreSize;
  1592. }
  1593. _swatchControl.Height = ClientSize.Height - UI.ScaleHeight(4) - _swatchControl.Top;
  1594. ResumeLayout(false);
  1595. }
  1596. private void ColorAddButtonClick(object sender, EventArgs e)
  1597. {
  1598. if (_colorAddButton.Checked)
  1599. {
  1600. _colorAddButton.Checked = false;
  1601. _swatchControl.BlinkHighlight = false;
  1602. }
  1603. else
  1604. {
  1605. _colorAddButton.Checked = true;
  1606. _swatchControl.BlinkHighlight = true;
  1607. }
  1608. }
  1609. private ColorBgra GetColorFromUpDowns()
  1610. {
  1611. var r = (int)_redUpDown.Value;
  1612. var g = (int)_greenUpDown.Value;
  1613. var b = (int)_blueUpDown.Value;
  1614. var a = (int)_alphaUpDown.Value;
  1615. return ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
  1616. }
  1617. private void SwatchControlColorClicked(object sender, EventArgs<Pair<int, MouseButtons>> e)
  1618. {
  1619. var colors = new List<ColorBgra>(_swatchControl.Colors);
  1620. if (_colorAddButton.Checked)
  1621. {
  1622. colors[e.Data.First] = GetColorFromUpDowns();
  1623. _swatchControl.Colors = colors.ToArray();
  1624. _colorAddButton.Checked = false;
  1625. _swatchControl.BlinkHighlight = false;
  1626. }
  1627. else
  1628. {
  1629. ColorBgra color = colors[e.Data.First];
  1630. if (e.Data.Second == MouseButtons.Right)
  1631. {
  1632. SetUserColors(UserPrimaryColor, color);
  1633. }
  1634. else
  1635. {
  1636. switch (WhichUserColor)
  1637. {
  1638. case WhichUserColor.Primary:
  1639. UserPrimaryColor = color;
  1640. break;
  1641. case WhichUserColor.Secondary:
  1642. UserSecondaryColor = color;
  1643. break;
  1644. default:
  1645. throw new InvalidEnumArgumentException();
  1646. }
  1647. }
  1648. }
  1649. OnRelinquishFocus();
  1650. }
  1651. private void ColorPalettesButtonClick(object sender, EventArgs e)
  1652. {
  1653. _colorPalettesButton.ShowDropDown();
  1654. }
  1655. private void ColorPalettesButtonDropDownOpening(object sender, EventArgs e)
  1656. {
  1657. _colorPalettesButton.DropDownItems.Clear();
  1658. if (_paletteCollection != null)
  1659. {
  1660. using (new WaitCursorChanger(this))
  1661. {
  1662. _paletteCollection.Load();
  1663. }
  1664. string[] paletteNames = _paletteCollection.PaletteNames;
  1665. foreach (string paletteName in paletteNames)
  1666. {
  1667. _colorPalettesButton.DropDownItems.Add(
  1668. paletteName,
  1669. PdnResources.GetImageResource("Icons.SwatchIcon.png").Reference,
  1670. OnPaletteClickedHandler);
  1671. }
  1672. if (paletteNames.Length > 0)
  1673. {
  1674. _colorPalettesButton.DropDownItems.Add(new ToolStripSeparator());
  1675. }
  1676. }
  1677. _colorPalettesButton.DropDownItems.Add(
  1678. PdnResources.GetString("ColorsForm.ColorPalettesButton.SaveCurrentPaletteAs.Text"),
  1679. PdnResources.GetImageResource("Icons.SavePaletteIcon.png").Reference,
  1680. OnSavePaletteAsHandler);
  1681. _colorPalettesButton.DropDownItems.Add(
  1682. PdnResources.GetString("ColorsForm.ColorPalettesButton.OpenPalettesFolder.Text"),
  1683. PdnResources.GetImageResource("Icons.ColorPalettes.png").Reference,
  1684. OnOpenPalettesFolderClickedHandler);
  1685. _colorPalettesButton.DropDownItems.Add(new ToolStripSeparator());
  1686. _colorPalettesButton.DropDownItems.Add(
  1687. PdnResources.GetString("ColorsForm.ColorPalettesButton.ResetToDefaultPalette.Text"),
  1688. null,
  1689. OnResetPaletteHandler);
  1690. }
  1691. private void OnSavePaletteAsHandler(object sender, EventArgs e)
  1692. {
  1693. using (var spd = new SavePaletteDialog())
  1694. {
  1695. spd.PaletteNames = _paletteCollection.PaletteNames;
  1696. spd.ShowDialog(this);
  1697. if (spd.DialogResult != DialogResult.OK) return;
  1698. _paletteCollection.AddOrUpdate(spd.PaletteName, _swatchControl.Colors);
  1699. using (new WaitCursorChanger(this))
  1700. {
  1701. _paletteCollection.Save();
  1702. }
  1703. }
  1704. }
  1705. private void OnResetPaletteHandler(object sender, EventArgs e)
  1706. {
  1707. _swatchControl.Colors = PaletteCollection.DefaultPalette;
  1708. }
  1709. private void OnPaletteClickedHandler(object sender, EventArgs e)
  1710. {
  1711. var tsi = sender as ToolStripItem;
  1712. if (tsi == null) return;
  1713. ColorBgra[] palette = _paletteCollection.Get(tsi.Text);
  1714. if (palette != null)
  1715. {
  1716. _swatchControl.Colors = palette;
  1717. }
  1718. }
  1719. private void SwatchControlColorsChanged(object sender, EventArgs e)
  1720. {
  1721. string paletteString = PaletteCollection.GetPaletteSaveString(_swatchControl.Colors);
  1722. Settings.CurrentUser.SetString(SettingNames.CurrentPalette, paletteString);
  1723. }
  1724. private void OnOpenPalettesFolderClickedHandler(object sender, EventArgs e)
  1725. {
  1726. PaletteCollection.EnsurePalettesPathExists();
  1727. try
  1728. {
  1729. using (new WaitCursorChanger(this))
  1730. {
  1731. Shell.BrowseFolder(this, PaletteCollection.PalettesPath);
  1732. }
  1733. }
  1734. catch (Exception ex)
  1735. {
  1736. Tracing.Ping("Exception when launching PalettesPath (" + PaletteCollection.PalettesPath + "):" + ex.ToString());
  1737. }
  1738. }
  1739. }
  1740. }