ColorsForm.cs 81 KB

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