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

/windows/ManagedBlink1/Blink1.ColorPicker/ColorManager.cs

https://github.com/ecxr/blink1
C# | 1183 lines | 859 code | 82 blank | 242 comment | 29 complexity | 257b35abfb760f10bcbd7799024db177 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, GPL-3.0, ISC, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. namespace ThingM.Blink1.ColorManager
  7. {
  8. using System.Collections.Generic;
  9. using System.Dynamic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net;
  13. using System.Xml.Linq;
  14. using ThingM.Blink1;
  15. using ThingM.Blink1.ColorProcessor;
  16. /// <summary>
  17. /// Summary description for ColorManager.
  18. /// </summary>
  19. public class ColorManager : System.Windows.Forms.Form
  20. {
  21. internal System.Windows.Forms.Label lblBlue;
  22. internal System.Windows.Forms.Label lblGreen;
  23. internal System.Windows.Forms.Label lblRed;
  24. internal System.Windows.Forms.Label lblBrightness;
  25. internal System.Windows.Forms.Label lblSaturation;
  26. internal System.Windows.Forms.Label lblHue;
  27. internal System.Windows.Forms.HScrollBar hsbBlue;
  28. internal System.Windows.Forms.HScrollBar hsbGreen;
  29. internal System.Windows.Forms.HScrollBar hsbRed;
  30. internal System.Windows.Forms.HScrollBar hsbBrightness;
  31. internal System.Windows.Forms.HScrollBar hsbSaturation;
  32. internal System.Windows.Forms.HScrollBar hsbHue;
  33. internal System.Windows.Forms.Label Label3;
  34. internal System.Windows.Forms.Label Label7;
  35. internal System.Windows.Forms.Panel pnlColor;
  36. internal System.Windows.Forms.Label Label6;
  37. internal System.Windows.Forms.Label Label1;
  38. internal System.Windows.Forms.Label Label5;
  39. internal System.Windows.Forms.Panel pnlSelectedColor;
  40. internal System.Windows.Forms.Panel pnlBrightness;
  41. internal System.Windows.Forms.Label Label2;
  42. private ThingM.Blink1.ColorManager.PresetControl preset0;
  43. private ThingM.Blink1.ColorManager.PresetControl preset1;
  44. private ThingM.Blink1.ColorManager.PresetControl preset2;
  45. private ThingM.Blink1.ColorManager.PresetControl preset3;
  46. private ThingM.Blink1.ColorManager.PresetControl preset4;
  47. private ThingM.Blink1.ColorManager.PresetControl preset5;
  48. private ThingM.Blink1.ColorManager.PresetControl preset6;
  49. private ThingM.Blink1.ColorManager.PresetControl preset7;
  50. private ThingM.Blink1.ColorManager.PresetControl preset8;
  51. private ThingM.Blink1.ColorManager.PresetControl preset9;
  52. private ThingM.Blink1.ColorManager.PresetControl preset10;
  53. private ThingM.Blink1.ColorManager.PresetControl preset11;
  54. private FlowLayoutPanel flowLayoutPanelPreset;
  55. private GroupBox groupBoxWaveLength;
  56. private GroupBox groupBoxColor;
  57. private GroupBox groupBoxDevice;
  58. private ComboBox comboBoxDevice;
  59. private MenuStrip menuStripForm;
  60. private ToolStripMenuItem fileToolStripMenuItem;
  61. private ToolStripMenuItem deviceToolStripMenuItem;
  62. private ToolStripMenuItem loadPresetFromFileToolStripMenuItem;
  63. private ToolStripSeparator toolStripMenuItem1;
  64. private ToolStripMenuItem savePresetToFileToolStripMenuItem;
  65. private ToolStripSeparator toolStripMenuItem2;
  66. private ToolStripMenuItem exitToolStripMenuItem;
  67. private ToolStripMenuItem loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem;
  68. private ToolStripSeparator toolStripMenuItem3;
  69. private ToolStripMenuItem savePresetToTheSelectedBlink1DeviceToolStripMenuItem;
  70. private ToolStripMenuItem fileToolStripMenuItem1;
  71. private ToolStripMenuItem loadPresetFromFileToolStripMenuItem1;
  72. private ToolStripSeparator toolStripMenuItem4;
  73. private ToolStripMenuItem savePresetToFileToolStripMenuItem1;
  74. private ToolStripSeparator toolStripMenuItem5;
  75. private ToolStripMenuItem exitToolStripMenuItem1;
  76. private ToolStripMenuItem deviceToolStripMenuItem1;
  77. private ToolStripMenuItem loadPresetFromSelectedBlink1DeviceToolStripMenuItem;
  78. private ToolStripSeparator toolStripMenuItem6;
  79. private ToolStripMenuItem savePresetToSelectedBlink1DeviceToolStripMenuItem;
  80. private TextBox textBoxInactivityMillisecond;
  81. private CheckBox checkBoxInactivityMode;
  82. private Label labelInactivityMillisecond;
  83. /// <summary>
  84. /// Required designer variable.
  85. /// </summary>
  86. private System.ComponentModel.Container components = null;
  87. public ColorManager()
  88. {
  89. //
  90. // Required for Windows Form Designer support
  91. //
  92. InitializeComponent();
  93. //
  94. // TODO: Add any constructor code after InitializeComponent call
  95. //
  96. }
  97. /// <summary>
  98. /// Clean up any resources being used.
  99. /// </summary>
  100. protected override void Dispose( bool disposing )
  101. {
  102. if( disposing )
  103. {
  104. if(components != null)
  105. {
  106. components.Dispose();
  107. }
  108. }
  109. base.Dispose( disposing );
  110. }
  111. #region Windows Form Designer generated code
  112. /// <summary>
  113. /// Required method for Designer support - do not modify
  114. /// the contents of this method with the code editor.
  115. /// </summary>
  116. private void InitializeComponent()
  117. {
  118. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ColorManager));
  119. this.lblBlue = new System.Windows.Forms.Label();
  120. this.lblGreen = new System.Windows.Forms.Label();
  121. this.lblRed = new System.Windows.Forms.Label();
  122. this.lblBrightness = new System.Windows.Forms.Label();
  123. this.lblSaturation = new System.Windows.Forms.Label();
  124. this.lblHue = new System.Windows.Forms.Label();
  125. this.hsbBlue = new System.Windows.Forms.HScrollBar();
  126. this.hsbGreen = new System.Windows.Forms.HScrollBar();
  127. this.hsbRed = new System.Windows.Forms.HScrollBar();
  128. this.hsbBrightness = new System.Windows.Forms.HScrollBar();
  129. this.hsbSaturation = new System.Windows.Forms.HScrollBar();
  130. this.hsbHue = new System.Windows.Forms.HScrollBar();
  131. this.Label3 = new System.Windows.Forms.Label();
  132. this.Label7 = new System.Windows.Forms.Label();
  133. this.pnlColor = new System.Windows.Forms.Panel();
  134. this.Label6 = new System.Windows.Forms.Label();
  135. this.Label1 = new System.Windows.Forms.Label();
  136. this.Label5 = new System.Windows.Forms.Label();
  137. this.pnlSelectedColor = new System.Windows.Forms.Panel();
  138. this.pnlBrightness = new System.Windows.Forms.Panel();
  139. this.Label2 = new System.Windows.Forms.Label();
  140. this.flowLayoutPanelPreset = new System.Windows.Forms.FlowLayoutPanel();
  141. this.groupBoxWaveLength = new System.Windows.Forms.GroupBox();
  142. this.groupBoxColor = new System.Windows.Forms.GroupBox();
  143. this.groupBoxDevice = new System.Windows.Forms.GroupBox();
  144. this.labelInactivityMillisecond = new System.Windows.Forms.Label();
  145. this.textBoxInactivityMillisecond = new System.Windows.Forms.TextBox();
  146. this.checkBoxInactivityMode = new System.Windows.Forms.CheckBox();
  147. this.comboBoxDevice = new System.Windows.Forms.ComboBox();
  148. this.menuStripForm = new System.Windows.Forms.MenuStrip();
  149. this.fileToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  150. this.loadPresetFromFileToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  151. this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator();
  152. this.savePresetToFileToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  153. this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripSeparator();
  154. this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  155. this.deviceToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  156. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  157. this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripSeparator();
  158. this.savePresetToSelectedBlink1DeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  159. this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  160. this.deviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  161. this.loadPresetFromFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  162. this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
  163. this.savePresetToFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  164. this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
  165. this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  166. this.loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  167. this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
  168. this.savePresetToTheSelectedBlink1DeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  169. this.preset0 = new ThingM.Blink1.ColorManager.PresetControl();
  170. this.preset1 = new ThingM.Blink1.ColorManager.PresetControl();
  171. this.preset2 = new ThingM.Blink1.ColorManager.PresetControl();
  172. this.preset3 = new ThingM.Blink1.ColorManager.PresetControl();
  173. this.preset4 = new ThingM.Blink1.ColorManager.PresetControl();
  174. this.preset5 = new ThingM.Blink1.ColorManager.PresetControl();
  175. this.preset6 = new ThingM.Blink1.ColorManager.PresetControl();
  176. this.preset7 = new ThingM.Blink1.ColorManager.PresetControl();
  177. this.preset8 = new ThingM.Blink1.ColorManager.PresetControl();
  178. this.preset9 = new ThingM.Blink1.ColorManager.PresetControl();
  179. this.preset10 = new ThingM.Blink1.ColorManager.PresetControl();
  180. this.preset11 = new ThingM.Blink1.ColorManager.PresetControl();
  181. this.flowLayoutPanelPreset.SuspendLayout();
  182. this.groupBoxWaveLength.SuspendLayout();
  183. this.groupBoxColor.SuspendLayout();
  184. this.groupBoxDevice.SuspendLayout();
  185. this.menuStripForm.SuspendLayout();
  186. this.SuspendLayout();
  187. //
  188. // lblBlue
  189. //
  190. this.lblBlue.Location = new System.Drawing.Point(315, 64);
  191. this.lblBlue.Name = "lblBlue";
  192. this.lblBlue.Size = new System.Drawing.Size(40, 23);
  193. this.lblBlue.TabIndex = 54;
  194. this.lblBlue.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  195. //
  196. // lblGreen
  197. //
  198. this.lblGreen.Location = new System.Drawing.Point(315, 40);
  199. this.lblGreen.Name = "lblGreen";
  200. this.lblGreen.Size = new System.Drawing.Size(40, 23);
  201. this.lblGreen.TabIndex = 53;
  202. this.lblGreen.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  203. //
  204. // lblRed
  205. //
  206. this.lblRed.Location = new System.Drawing.Point(315, 16);
  207. this.lblRed.Name = "lblRed";
  208. this.lblRed.Size = new System.Drawing.Size(40, 23);
  209. this.lblRed.TabIndex = 52;
  210. this.lblRed.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  211. //
  212. // lblBrightness
  213. //
  214. this.lblBrightness.Location = new System.Drawing.Point(315, 64);
  215. this.lblBrightness.Name = "lblBrightness";
  216. this.lblBrightness.Size = new System.Drawing.Size(40, 23);
  217. this.lblBrightness.TabIndex = 51;
  218. this.lblBrightness.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  219. //
  220. // lblSaturation
  221. //
  222. this.lblSaturation.Location = new System.Drawing.Point(315, 40);
  223. this.lblSaturation.Name = "lblSaturation";
  224. this.lblSaturation.Size = new System.Drawing.Size(40, 23);
  225. this.lblSaturation.TabIndex = 50;
  226. this.lblSaturation.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  227. //
  228. // lblHue
  229. //
  230. this.lblHue.Location = new System.Drawing.Point(315, 16);
  231. this.lblHue.Name = "lblHue";
  232. this.lblHue.Size = new System.Drawing.Size(40, 23);
  233. this.lblHue.TabIndex = 49;
  234. this.lblHue.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  235. //
  236. // hsbBlue
  237. //
  238. this.hsbBlue.LargeChange = 1;
  239. this.hsbBlue.Location = new System.Drawing.Point(83, 64);
  240. this.hsbBlue.Maximum = 255;
  241. this.hsbBlue.Name = "hsbBlue";
  242. this.hsbBlue.Size = new System.Drawing.Size(224, 18);
  243. this.hsbBlue.TabIndex = 48;
  244. this.hsbBlue.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleRGBScroll);
  245. //
  246. // hsbGreen
  247. //
  248. this.hsbGreen.LargeChange = 1;
  249. this.hsbGreen.Location = new System.Drawing.Point(83, 40);
  250. this.hsbGreen.Maximum = 255;
  251. this.hsbGreen.Name = "hsbGreen";
  252. this.hsbGreen.Size = new System.Drawing.Size(224, 18);
  253. this.hsbGreen.TabIndex = 47;
  254. this.hsbGreen.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleRGBScroll);
  255. //
  256. // hsbRed
  257. //
  258. this.hsbRed.LargeChange = 1;
  259. this.hsbRed.Location = new System.Drawing.Point(83, 16);
  260. this.hsbRed.Maximum = 255;
  261. this.hsbRed.Name = "hsbRed";
  262. this.hsbRed.Size = new System.Drawing.Size(224, 18);
  263. this.hsbRed.TabIndex = 46;
  264. this.hsbRed.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleRGBScroll);
  265. //
  266. // hsbBrightness
  267. //
  268. this.hsbBrightness.LargeChange = 1;
  269. this.hsbBrightness.Location = new System.Drawing.Point(83, 64);
  270. this.hsbBrightness.Maximum = 255;
  271. this.hsbBrightness.Name = "hsbBrightness";
  272. this.hsbBrightness.Size = new System.Drawing.Size(224, 18);
  273. this.hsbBrightness.TabIndex = 45;
  274. this.hsbBrightness.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleHSVScroll);
  275. //
  276. // hsbSaturation
  277. //
  278. this.hsbSaturation.LargeChange = 1;
  279. this.hsbSaturation.Location = new System.Drawing.Point(83, 40);
  280. this.hsbSaturation.Maximum = 255;
  281. this.hsbSaturation.Name = "hsbSaturation";
  282. this.hsbSaturation.Size = new System.Drawing.Size(224, 18);
  283. this.hsbSaturation.TabIndex = 44;
  284. this.hsbSaturation.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleHSVScroll);
  285. //
  286. // hsbHue
  287. //
  288. this.hsbHue.LargeChange = 1;
  289. this.hsbHue.Location = new System.Drawing.Point(83, 16);
  290. this.hsbHue.Maximum = 255;
  291. this.hsbHue.Name = "hsbHue";
  292. this.hsbHue.Size = new System.Drawing.Size(224, 18);
  293. this.hsbHue.TabIndex = 43;
  294. this.hsbHue.Scroll += new System.Windows.Forms.ScrollEventHandler(this.HandleHSVScroll);
  295. //
  296. // Label3
  297. //
  298. this.Label3.Location = new System.Drawing.Point(11, 64);
  299. this.Label3.Name = "Label3";
  300. this.Label3.Size = new System.Drawing.Size(72, 18);
  301. this.Label3.TabIndex = 34;
  302. this.Label3.Text = "Blue";
  303. this.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  304. //
  305. // Label7
  306. //
  307. this.Label7.Location = new System.Drawing.Point(11, 64);
  308. this.Label7.Name = "Label7";
  309. this.Label7.Size = new System.Drawing.Size(72, 18);
  310. this.Label7.TabIndex = 37;
  311. this.Label7.Text = "Brightness";
  312. this.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  313. //
  314. // pnlColor
  315. //
  316. this.pnlColor.Location = new System.Drawing.Point(12, 95);
  317. this.pnlColor.Name = "pnlColor";
  318. this.pnlColor.Size = new System.Drawing.Size(224, 216);
  319. this.pnlColor.TabIndex = 38;
  320. this.pnlColor.Visible = false;
  321. //
  322. // Label6
  323. //
  324. this.Label6.Location = new System.Drawing.Point(11, 40);
  325. this.Label6.Name = "Label6";
  326. this.Label6.Size = new System.Drawing.Size(72, 18);
  327. this.Label6.TabIndex = 36;
  328. this.Label6.Text = "Saturation";
  329. this.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  330. //
  331. // Label1
  332. //
  333. this.Label1.Location = new System.Drawing.Point(11, 16);
  334. this.Label1.Name = "Label1";
  335. this.Label1.Size = new System.Drawing.Size(72, 18);
  336. this.Label1.TabIndex = 32;
  337. this.Label1.Text = "Red";
  338. this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  339. //
  340. // Label5
  341. //
  342. this.Label5.Location = new System.Drawing.Point(11, 16);
  343. this.Label5.Name = "Label5";
  344. this.Label5.Size = new System.Drawing.Size(72, 18);
  345. this.Label5.TabIndex = 35;
  346. this.Label5.Text = "Hue";
  347. this.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  348. //
  349. // pnlSelectedColor
  350. //
  351. this.pnlSelectedColor.Location = new System.Drawing.Point(292, 95);
  352. this.pnlSelectedColor.Name = "pnlSelectedColor";
  353. this.pnlSelectedColor.Size = new System.Drawing.Size(82, 216);
  354. this.pnlSelectedColor.TabIndex = 40;
  355. this.pnlSelectedColor.Visible = false;
  356. //
  357. // pnlBrightness
  358. //
  359. this.pnlBrightness.Location = new System.Drawing.Point(244, 95);
  360. this.pnlBrightness.Name = "pnlBrightness";
  361. this.pnlBrightness.Size = new System.Drawing.Size(28, 216);
  362. this.pnlBrightness.TabIndex = 39;
  363. this.pnlBrightness.Visible = false;
  364. //
  365. // Label2
  366. //
  367. this.Label2.Location = new System.Drawing.Point(11, 40);
  368. this.Label2.Name = "Label2";
  369. this.Label2.Size = new System.Drawing.Size(72, 18);
  370. this.Label2.TabIndex = 33;
  371. this.Label2.Text = "Green";
  372. this.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  373. //
  374. // flowLayoutPanelPreset
  375. //
  376. this.flowLayoutPanelPreset.Controls.Add(this.preset0);
  377. this.flowLayoutPanelPreset.Controls.Add(this.preset1);
  378. this.flowLayoutPanelPreset.Controls.Add(this.preset2);
  379. this.flowLayoutPanelPreset.Controls.Add(this.preset3);
  380. this.flowLayoutPanelPreset.Controls.Add(this.preset4);
  381. this.flowLayoutPanelPreset.Controls.Add(this.preset5);
  382. this.flowLayoutPanelPreset.Controls.Add(this.preset6);
  383. this.flowLayoutPanelPreset.Controls.Add(this.preset7);
  384. this.flowLayoutPanelPreset.Controls.Add(this.preset8);
  385. this.flowLayoutPanelPreset.Controls.Add(this.preset9);
  386. this.flowLayoutPanelPreset.Controls.Add(this.preset10);
  387. this.flowLayoutPanelPreset.Controls.Add(this.preset11);
  388. this.flowLayoutPanelPreset.Location = new System.Drawing.Point(380, 85);
  389. this.flowLayoutPanelPreset.Name = "flowLayoutPanelPreset";
  390. this.flowLayoutPanelPreset.Size = new System.Drawing.Size(588, 550);
  391. this.flowLayoutPanelPreset.TabIndex = 56;
  392. //
  393. // groupBoxWaveLength
  394. //
  395. this.groupBoxWaveLength.Controls.Add(this.hsbHue);
  396. this.groupBoxWaveLength.Controls.Add(this.Label7);
  397. this.groupBoxWaveLength.Controls.Add(this.lblHue);
  398. this.groupBoxWaveLength.Controls.Add(this.lblSaturation);
  399. this.groupBoxWaveLength.Controls.Add(this.Label6);
  400. this.groupBoxWaveLength.Controls.Add(this.lblBrightness);
  401. this.groupBoxWaveLength.Controls.Add(this.hsbSaturation);
  402. this.groupBoxWaveLength.Controls.Add(this.hsbBrightness);
  403. this.groupBoxWaveLength.Controls.Add(this.Label5);
  404. this.groupBoxWaveLength.Location = new System.Drawing.Point(12, 323);
  405. this.groupBoxWaveLength.Name = "groupBoxWaveLength";
  406. this.groupBoxWaveLength.Size = new System.Drawing.Size(362, 93);
  407. this.groupBoxWaveLength.TabIndex = 57;
  408. this.groupBoxWaveLength.TabStop = false;
  409. this.groupBoxWaveLength.Text = "Wavelength";
  410. //
  411. // groupBoxColor
  412. //
  413. this.groupBoxColor.Controls.Add(this.hsbRed);
  414. this.groupBoxColor.Controls.Add(this.hsbBlue);
  415. this.groupBoxColor.Controls.Add(this.Label3);
  416. this.groupBoxColor.Controls.Add(this.Label2);
  417. this.groupBoxColor.Controls.Add(this.hsbGreen);
  418. this.groupBoxColor.Controls.Add(this.lblBlue);
  419. this.groupBoxColor.Controls.Add(this.Label1);
  420. this.groupBoxColor.Controls.Add(this.lblRed);
  421. this.groupBoxColor.Controls.Add(this.lblGreen);
  422. this.groupBoxColor.Location = new System.Drawing.Point(12, 426);
  423. this.groupBoxColor.Name = "groupBoxColor";
  424. this.groupBoxColor.Size = new System.Drawing.Size(362, 93);
  425. this.groupBoxColor.TabIndex = 58;
  426. this.groupBoxColor.TabStop = false;
  427. this.groupBoxColor.Text = "Color";
  428. //
  429. // groupBoxDevice
  430. //
  431. this.groupBoxDevice.Controls.Add(this.labelInactivityMillisecond);
  432. this.groupBoxDevice.Controls.Add(this.textBoxInactivityMillisecond);
  433. this.groupBoxDevice.Controls.Add(this.checkBoxInactivityMode);
  434. this.groupBoxDevice.Controls.Add(this.comboBoxDevice);
  435. this.groupBoxDevice.Location = new System.Drawing.Point(12, 27);
  436. this.groupBoxDevice.Name = "groupBoxDevice";
  437. this.groupBoxDevice.Size = new System.Drawing.Size(944, 51);
  438. this.groupBoxDevice.TabIndex = 59;
  439. this.groupBoxDevice.TabStop = false;
  440. this.groupBoxDevice.Text = "Device(s)";
  441. //
  442. // labelInactivityMillisecond
  443. //
  444. this.labelInactivityMillisecond.AutoSize = true;
  445. this.labelInactivityMillisecond.Location = new System.Drawing.Point(862, 23);
  446. this.labelInactivityMillisecond.Name = "labelInactivityMillisecond";
  447. this.labelInactivityMillisecond.Size = new System.Drawing.Size(64, 13);
  448. this.labelInactivityMillisecond.TabIndex = 4;
  449. this.labelInactivityMillisecond.Text = "Milliseconds";
  450. //
  451. // textBoxInactivityMillisecond
  452. //
  453. this.textBoxInactivityMillisecond.Location = new System.Drawing.Point(813, 20);
  454. this.textBoxInactivityMillisecond.Name = "textBoxInactivityMillisecond";
  455. this.textBoxInactivityMillisecond.Size = new System.Drawing.Size(43, 20);
  456. this.textBoxInactivityMillisecond.TabIndex = 3;
  457. this.textBoxInactivityMillisecond.Text = "60000";
  458. this.textBoxInactivityMillisecond.Validating += new System.ComponentModel.CancelEventHandler(this.textBoxInactivityMillisecond_Validating);
  459. //
  460. // checkBoxInactivityMode
  461. //
  462. this.checkBoxInactivityMode.AutoSize = true;
  463. this.checkBoxInactivityMode.Location = new System.Drawing.Point(598, 21);
  464. this.checkBoxInactivityMode.Name = "checkBoxInactivityMode";
  465. this.checkBoxInactivityMode.Size = new System.Drawing.Size(212, 17);
  466. this.checkBoxInactivityMode.TabIndex = 1;
  467. this.checkBoxInactivityMode.Text = "Inactivity Mode After Being Inactive For";
  468. this.checkBoxInactivityMode.UseVisualStyleBackColor = true;
  469. //
  470. // comboBoxDevice
  471. //
  472. this.comboBoxDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  473. this.comboBoxDevice.FormattingEnabled = true;
  474. this.comboBoxDevice.Location = new System.Drawing.Point(6, 19);
  475. this.comboBoxDevice.Name = "comboBoxDevice";
  476. this.comboBoxDevice.Size = new System.Drawing.Size(577, 21);
  477. this.comboBoxDevice.TabIndex = 0;
  478. this.comboBoxDevice.SelectedIndexChanged += new System.EventHandler(this.comboBoxDevice_SelectedIndexChanged);
  479. //
  480. // menuStripForm
  481. //
  482. this.menuStripForm.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  483. this.fileToolStripMenuItem1,
  484. this.deviceToolStripMenuItem1});
  485. this.menuStripForm.Location = new System.Drawing.Point(0, 0);
  486. this.menuStripForm.Name = "menuStripForm";
  487. this.menuStripForm.Size = new System.Drawing.Size(968, 24);
  488. this.menuStripForm.TabIndex = 60;
  489. //
  490. // fileToolStripMenuItem1
  491. //
  492. this.fileToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  493. this.loadPresetFromFileToolStripMenuItem1,
  494. this.toolStripMenuItem4,
  495. this.savePresetToFileToolStripMenuItem1,
  496. this.toolStripMenuItem5,
  497. this.exitToolStripMenuItem1});
  498. this.fileToolStripMenuItem1.Name = "fileToolStripMenuItem1";
  499. this.fileToolStripMenuItem1.Size = new System.Drawing.Size(37, 20);
  500. this.fileToolStripMenuItem1.Text = "File";
  501. //
  502. // loadPresetFromFileToolStripMenuItem1
  503. //
  504. this.loadPresetFromFileToolStripMenuItem1.Image = global::ThingM.Blink1.ColorManager.Properties.Resources.LoadFromFile;
  505. this.loadPresetFromFileToolStripMenuItem1.Name = "loadPresetFromFileToolStripMenuItem1";
  506. this.loadPresetFromFileToolStripMenuItem1.Size = new System.Drawing.Size(196, 22);
  507. this.loadPresetFromFileToolStripMenuItem1.Text = "Load Preset From File...";
  508. this.loadPresetFromFileToolStripMenuItem1.Click += new System.EventHandler(this.loadPresetFromFileToolStripMenuItem1_Click);
  509. //
  510. // toolStripMenuItem4
  511. //
  512. this.toolStripMenuItem4.Name = "toolStripMenuItem4";
  513. this.toolStripMenuItem4.Size = new System.Drawing.Size(193, 6);
  514. //
  515. // savePresetToFileToolStripMenuItem1
  516. //
  517. this.savePresetToFileToolStripMenuItem1.Image = global::ThingM.Blink1.ColorManager.Properties.Resources.SaveToFile;
  518. this.savePresetToFileToolStripMenuItem1.Name = "savePresetToFileToolStripMenuItem1";
  519. this.savePresetToFileToolStripMenuItem1.Size = new System.Drawing.Size(196, 22);
  520. this.savePresetToFileToolStripMenuItem1.Text = "Save Preset To File...";
  521. this.savePresetToFileToolStripMenuItem1.Click += new System.EventHandler(this.savePresetToFileToolStripMenuItem1_Click);
  522. //
  523. // toolStripMenuItem5
  524. //
  525. this.toolStripMenuItem5.Name = "toolStripMenuItem5";
  526. this.toolStripMenuItem5.Size = new System.Drawing.Size(193, 6);
  527. //
  528. // exitToolStripMenuItem1
  529. //
  530. this.exitToolStripMenuItem1.Image = global::ThingM.Blink1.ColorManager.Properties.Resources.ExitApplication;
  531. this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
  532. this.exitToolStripMenuItem1.Size = new System.Drawing.Size(196, 22);
  533. this.exitToolStripMenuItem1.Text = "Exit";
  534. this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem1_Click);
  535. //
  536. // deviceToolStripMenuItem1
  537. //
  538. this.deviceToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
  539. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem,
  540. this.toolStripMenuItem6,
  541. this.savePresetToSelectedBlink1DeviceToolStripMenuItem});
  542. this.deviceToolStripMenuItem1.Name = "deviceToolStripMenuItem1";
  543. this.deviceToolStripMenuItem1.Size = new System.Drawing.Size(54, 20);
  544. this.deviceToolStripMenuItem1.Text = "Device";
  545. //
  546. // loadPresetFromSelectedBlink1DeviceToolStripMenuItem
  547. //
  548. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem.Image = global::ThingM.Blink1.ColorManager.Properties.Resources.LoadFromDevice;
  549. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem.Name = "loadPresetFromSelectedBlink1DeviceToolStripMenuItem";
  550. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem.Size = new System.Drawing.Size(294, 22);
  551. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem.Text = "Load Preset From Selected Blink(1) Device";
  552. this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem.Click += new System.EventHandler(this.loadPresetFromSelectedBlink1DeviceToolStripMenuItem_Click);
  553. //
  554. // toolStripMenuItem6
  555. //
  556. this.toolStripMenuItem6.Name = "toolStripMenuItem6";
  557. this.toolStripMenuItem6.Size = new System.Drawing.Size(291, 6);
  558. //
  559. // savePresetToSelectedBlink1DeviceToolStripMenuItem
  560. //
  561. this.savePresetToSelectedBlink1DeviceToolStripMenuItem.Image = global::ThingM.Blink1.ColorManager.Properties.Resources.SaveToDevice;
  562. this.savePresetToSelectedBlink1DeviceToolStripMenuItem.Name = "savePresetToSelectedBlink1DeviceToolStripMenuItem";
  563. this.savePresetToSelectedBlink1DeviceToolStripMenuItem.Size = new System.Drawing.Size(294, 22);
  564. this.savePresetToSelectedBlink1DeviceToolStripMenuItem.Text = "Save Preset To Selected Blink(1) Device";
  565. this.savePresetToSelectedBlink1DeviceToolStripMenuItem.Click += new System.EventHandler(this.savePresetToSelectedBlink1DeviceToolStripMenuItem_Click);
  566. //
  567. // fileToolStripMenuItem
  568. //
  569. this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
  570. this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
  571. this.fileToolStripMenuItem.Text = "File";
  572. //
  573. // deviceToolStripMenuItem
  574. //
  575. this.deviceToolStripMenuItem.Name = "deviceToolStripMenuItem";
  576. this.deviceToolStripMenuItem.Size = new System.Drawing.Size(54, 20);
  577. this.deviceToolStripMenuItem.Text = "Device";
  578. //
  579. // loadPresetFromFileToolStripMenuItem
  580. //
  581. this.loadPresetFromFileToolStripMenuItem.Name = "loadPresetFromFileToolStripMenuItem";
  582. this.loadPresetFromFileToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
  583. this.loadPresetFromFileToolStripMenuItem.Text = "Load preset from file...";
  584. //
  585. // toolStripMenuItem1
  586. //
  587. this.toolStripMenuItem1.Name = "toolStripMenuItem1";
  588. this.toolStripMenuItem1.Size = new System.Drawing.Size(189, 6);
  589. //
  590. // savePresetToFileToolStripMenuItem
  591. //
  592. this.savePresetToFileToolStripMenuItem.Name = "savePresetToFileToolStripMenuItem";
  593. this.savePresetToFileToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
  594. this.savePresetToFileToolStripMenuItem.Text = "Save preset to file...";
  595. //
  596. // toolStripMenuItem2
  597. //
  598. this.toolStripMenuItem2.Name = "toolStripMenuItem2";
  599. this.toolStripMenuItem2.Size = new System.Drawing.Size(189, 6);
  600. //
  601. // exitToolStripMenuItem
  602. //
  603. this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
  604. this.exitToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
  605. this.exitToolStripMenuItem.Text = "Exit";
  606. //
  607. // loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem
  608. //
  609. this.loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem.Name = "loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem";
  610. this.loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem.Size = new System.Drawing.Size(310, 22);
  611. this.loadPresetFromTheSelectedBlink1DeviceToolStripMenuItem.Text = "Load preset from the selected Blink(1) device";
  612. //
  613. // toolStripMenuItem3
  614. //
  615. this.toolStripMenuItem3.Name = "toolStripMenuItem3";
  616. this.toolStripMenuItem3.Size = new System.Drawing.Size(307, 6);
  617. //
  618. // savePresetToTheSelectedBlink1DeviceToolStripMenuItem
  619. //
  620. this.savePresetToTheSelectedBlink1DeviceToolStripMenuItem.Name = "savePresetToTheSelectedBlink1DeviceToolStripMenuItem";
  621. this.savePresetToTheSelectedBlink1DeviceToolStripMenuItem.Size = new System.Drawing.Size(310, 22);
  622. this.savePresetToTheSelectedBlink1DeviceToolStripMenuItem.Text = "Save preset to the selected Blink(1) device";
  623. //
  624. // preset0
  625. //
  626. this.preset0.Location = new System.Drawing.Point(3, 3);
  627. this.preset0.Millisecond = ((ushort)(1000));
  628. this.preset0.Name = "preset0";
  629. this.preset0.Size = new System.Drawing.Size(580, 40);
  630. this.preset0.TabIndex = 0;
  631. this.preset0.Title = "Preset # 1";
  632. //
  633. // preset1
  634. //
  635. this.preset1.Location = new System.Drawing.Point(3, 49);
  636. this.preset1.Millisecond = ((ushort)(1000));
  637. this.preset1.Name = "preset1";
  638. this.preset1.Size = new System.Drawing.Size(580, 40);
  639. this.preset1.TabIndex = 1;
  640. this.preset1.Title = "Preset # 2";
  641. //
  642. // preset2
  643. //
  644. this.preset2.Location = new System.Drawing.Point(3, 95);
  645. this.preset2.Millisecond = ((ushort)(1000));
  646. this.preset2.Name = "preset2";
  647. this.preset2.Size = new System.Drawing.Size(580, 40);
  648. this.preset2.TabIndex = 2;
  649. this.preset2.Title = "Preset # 3";
  650. //
  651. // preset3
  652. //
  653. this.preset3.Location = new System.Drawing.Point(3, 141);
  654. this.preset3.Millisecond = ((ushort)(1000));
  655. this.preset3.Name = "preset3";
  656. this.preset3.Size = new System.Drawing.Size(580, 40);
  657. this.preset3.TabIndex = 3;
  658. this.preset3.Title = "Preset # 4";
  659. //
  660. // preset4
  661. //
  662. this.preset4.Location = new System.Drawing.Point(3, 187);
  663. this.preset4.Millisecond = ((ushort)(1000));
  664. this.preset4.Name = "preset4";
  665. this.preset4.Size = new System.Drawing.Size(580, 40);
  666. this.preset4.TabIndex = 4;
  667. this.preset4.Title = "Preset # 5";
  668. //
  669. // preset5
  670. //
  671. this.preset5.Location = new System.Drawing.Point(3, 233);
  672. this.preset5.Millisecond = ((ushort)(1000));
  673. this.preset5.Name = "preset5";
  674. this.preset5.Size = new System.Drawing.Size(580, 40);
  675. this.preset5.TabIndex = 5;
  676. this.preset5.Title = "Preset # 6";
  677. //
  678. // preset6
  679. //
  680. this.preset6.Location = new System.Drawing.Point(3, 279);
  681. this.preset6.Millisecond = ((ushort)(1000));
  682. this.preset6.Name = "preset6";
  683. this.preset6.Size = new System.Drawing.Size(580, 40);
  684. this.preset6.TabIndex = 6;
  685. this.preset6.Title = "Preset # 7";
  686. //
  687. // preset7
  688. //
  689. this.preset7.Location = new System.Drawing.Point(3, 325);
  690. this.preset7.Millisecond = ((ushort)(1000));
  691. this.preset7.Name = "preset7";
  692. this.preset7.Size = new System.Drawing.Size(580, 40);
  693. this.preset7.TabIndex = 7;
  694. this.preset7.Title = "Preset # 8";
  695. //
  696. // preset8
  697. //
  698. this.preset8.Location = new System.Drawing.Point(3, 371);
  699. this.preset8.Millisecond = ((ushort)(1000));
  700. this.preset8.Name = "preset8";
  701. this.preset8.Size = new System.Drawing.Size(580, 40);
  702. this.preset8.TabIndex = 8;
  703. this.preset8.Title = "Preset # 9";
  704. //
  705. // preset9
  706. //
  707. this.preset9.Location = new System.Drawing.Point(3, 417);
  708. this.preset9.Millisecond = ((ushort)(1000));
  709. this.preset9.Name = "preset9";
  710. this.preset9.Size = new System.Drawing.Size(580, 40);
  711. this.preset9.TabIndex = 9;
  712. this.preset9.Title = "Preset # 10";
  713. //
  714. // preset10
  715. //
  716. this.preset10.Location = new System.Drawing.Point(3, 463);
  717. this.preset10.Millisecond = ((ushort)(1000));
  718. this.preset10.Name = "preset10";
  719. this.preset10.Size = new System.Drawing.Size(580, 40);
  720. this.preset10.TabIndex = 10;
  721. this.preset10.Title = "Preset # 11";
  722. //
  723. // preset11
  724. //
  725. this.preset11.Location = new System.Drawing.Point(3, 509);
  726. this.preset11.Millisecond = ((ushort)(1000));
  727. this.preset11.Name = "preset11";
  728. this.preset11.Size = new System.Drawing.Size(580, 40);
  729. this.preset11.TabIndex = 11;
  730. this.preset11.Title = "Preset # 12";
  731. //
  732. // ColorManager
  733. //
  734. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  735. this.ClientSize = new System.Drawing.Size(968, 645);
  736. this.Controls.Add(this.groupBoxDevice);
  737. this.Controls.Add(this.groupBoxColor);
  738. this.Controls.Add(this.groupBoxWaveLength);
  739. this.Controls.Add(this.pnlSelectedColor);
  740. this.Controls.Add(this.flowLayoutPanelPreset);
  741. this.Controls.Add(this.pnlBrightness);
  742. this.Controls.Add(this.pnlColor);
  743. this.Controls.Add(this.menuStripForm);
  744. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  745. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  746. this.MainMenuStrip = this.menuStripForm;
  747. this.MaximizeBox = false;
  748. this.Name = "ColorManager";
  749. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  750. this.Text = "Blink(1) Color Manager";
  751. this.Load += new System.EventHandler(this.ColorManager_Load);
  752. this.Paint += new System.Windows.Forms.PaintEventHandler(this.ColorManager_Paint);
  753. this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.HandleMouse);
  754. this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HandleMouse);
  755. this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseUp);
  756. this.flowLayoutPanelPreset.ResumeLayout(false);
  757. this.groupBoxWaveLength.ResumeLayout(false);
  758. this.groupBoxColor.ResumeLayout(false);
  759. this.groupBoxDevice.ResumeLayout(false);
  760. this.groupBoxDevice.PerformLayout();
  761. this.menuStripForm.ResumeLayout(false);
  762. this.menuStripForm.PerformLayout();
  763. this.ResumeLayout(false);
  764. this.PerformLayout();
  765. }
  766. #endregion
  767. private enum ChangeStyle
  768. {
  769. MouseMove,
  770. RGB,
  771. HSV,
  772. None
  773. }
  774. private ChangeStyle changeType = ChangeStyle.None;
  775. private Point selectedPoint;
  776. private ColorWheel myColorWheel;
  777. private ColorHandler.RGB RGB;
  778. private ColorHandler.HSV HSV;
  779. private Blink1 blink1 = new Blink1();
  780. private void ColorManager_Load(object sender, System.EventArgs e)
  781. {
  782. // Turn on double-buffering, so the form looks better.
  783. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  784. this.SetStyle(ControlStyles.UserPaint, true);
  785. this.SetStyle(ControlStyles.DoubleBuffer, true);
  786. // These properties are set in design view, as well, but they
  787. // have to be set to false in order for the Paint
  788. // event to be able to display their contents.
  789. // Never hurts to make sure they're invisible.
  790. pnlSelectedColor.Visible = false;
  791. pnlBrightness.Visible = false;
  792. pnlColor.Visible = false;
  793. // Calculate the coordinates of the three
  794. // required regions on the form.
  795. Rectangle SelectedColorRectangle = new Rectangle(pnlSelectedColor.Location, pnlSelectedColor.Size);
  796. Rectangle BrightnessRectangle = new Rectangle(pnlBrightness.Location, pnlBrightness.Size);
  797. Rectangle ColorRectangle = new Rectangle(pnlColor.Location, pnlColor.Size);
  798. // Create the new ColorWheel class, indicating
  799. // the locations of the color wheel itself, the
  800. // brightness area, and the position of the selected color.
  801. myColorWheel = new ColorWheel(ColorRectangle, BrightnessRectangle, SelectedColorRectangle);
  802. myColorWheel.ColorChanged +=
  803. new ColorWheel.ColorChangedEventHandler(this.myColorWheel_ColorChanged);
  804. // Set the RGB and HSV values
  805. // of the NumericUpDown controls.
  806. SetRGB(RGB);
  807. SetHSV(HSV);
  808. hsbBrightness.Value = 255;
  809. HandleHSVScroll(null, null);
  810. this.LoadBlinkDevice();
  811. }
  812. private void LoadBlinkDevice()
  813. {
  814. List<string> devicePaths = Blink1Info.GetDevicePath();
  815. if (devicePaths.Count == 0)
  816. {
  817. MessageBox.Show("No Blink(1) devices found.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  818. return;
  819. }
  820. Dictionary<string, string> deviceSources = new Dictionary<string, string>();
  821. for (int counter = 0; counter < devicePaths.Count; counter++)
  822. {
  823. deviceSources.Add(devicePaths[counter], string.Format("Blink(1) # {0}: HID: {1}", counter + 1, devicePaths[counter]));
  824. }
  825. this.comboBoxDevice.Enabled = false;
  826. this.comboBoxDevice.DataSource = new BindingSource(deviceSources, null);
  827. this.comboBoxDevice.DisplayMember = "Value";
  828. this.comboBoxDevice.ValueMember = "Key";
  829. this.comboBoxDevice.Enabled = true;
  830. if (deviceSources.Count > 0)
  831. {
  832. this.OpenSelectedBlinkDevice();
  833. }
  834. }
  835. private void OpenSelectedBlinkDevice()
  836. {
  837. if (this.comboBoxDevice.Enabled == false)
  838. {
  839. return;
  840. }
  841. if (this.comboBoxDevice.SelectedIndex < 0)
  842. {
  843. return;
  844. }
  845. if (this.blink1.IsConnected)
  846. {
  847. this.blink1.Close();
  848. }
  849. KeyValuePair<string, string> selectedItem = (KeyValuePair<string, string>)this.comboBoxDevice.SelectedItem;
  850. try
  851. {
  852. this.blink1.Open(selectedItem.Key);
  853. this.blink1.Blink(3, 250, 100, 255, 0, 0);
  854. }
  855. catch (Exception ex)
  856. {
  857. MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  858. }
  859. }
  860. private void HandleMouse(object sender, MouseEventArgs e)
  861. {
  862. // If you have the left mouse button down,
  863. // then update the selectedPoint value and
  864. // force a repaint of the color wheel.
  865. if ( e.Button == MouseButtons.Left )
  866. {
  867. changeType = ChangeStyle.MouseMove;
  868. selectedPoint = new Point(e.X, e.Y);
  869. this.Invalidate();
  870. }
  871. }
  872. private void frmMain_MouseUp(object sender, MouseEventArgs e)
  873. {
  874. myColorWheel.SetMouseUp();
  875. changeType = ChangeStyle.None;
  876. }
  877. private void SetRGBLabels(ColorHandler.RGB RGB)
  878. {
  879. RefreshText(lblRed, RGB.Red);
  880. RefreshText(lblBlue, RGB.Blue);
  881. RefreshText(lblGreen, RGB.Green);
  882. }
  883. private void SetHSVLabels(ColorHandler.HSV HSV)
  884. {
  885. RefreshText(lblHue, HSV.Hue);
  886. RefreshText(lblSaturation, HSV.Saturation);
  887. RefreshText(lblBrightness, HSV.value);
  888. }
  889. private void SetRGB(ColorHandler.RGB RGB)
  890. {
  891. // Update the RGB values on the form.
  892. RefreshValue(hsbRed, RGB.Red);
  893. RefreshValue(hsbBlue, RGB.Blue);
  894. RefreshValue(hsbGreen, RGB.Green);
  895. SetRGBLabels(RGB);
  896. }
  897. private void SetHSV( ColorHandler.HSV HSV)
  898. {
  899. // Update the HSV values on the form.
  900. RefreshValue(hsbHue, HSV.Hue);
  901. RefreshValue(hsbSaturation, HSV.Saturation);
  902. RefreshValue(hsbBrightness, HSV.value);
  903. SetHSVLabels(HSV);
  904. }
  905. private void RefreshValue(HScrollBar hsb, int value)
  906. {
  907. hsb.Value = value;
  908. }
  909. private void RefreshText(Label lbl, int value)
  910. {
  911. lbl.Text = value.ToString();
  912. }
  913. public Color Color
  914. {
  915. // Get or set the color to be
  916. // displayed in the color wheel.
  917. get
  918. {
  919. return myColorWheel.Color;
  920. }
  921. set
  922. {
  923. // Indicate the color change type. Either RGB or HSV
  924. // will cause the color wheel to update the position
  925. // of the pointer.
  926. changeType = ChangeStyle.RGB;
  927. RGB = new ColorHandler.RGB(value.R, value.G, value.B);
  928. HSV = ColorHandler.RGBtoHSV(RGB);
  929. }
  930. }
  931. private void myColorWheel_ColorChanged(object sender, ColorChangedEventArgs e)
  932. {
  933. SetRGB(e.RGB);
  934. SetHSV(e.HSV);
  935. if (this.blink1.IsConnected)
  936. {
  937. this.blink1.SetColor((ushort)e.RGB.Red, (ushort)e.RGB.Green, (ushort)e.RGB.Blue);
  938. }
  939. }
  940. private void HandleHSVScroll(object sender, ScrollEventArgs e)
  941. // If the H, S, or V values change, use this
  942. // code to update the RGB values and invalidate
  943. // the color wheel (so it updates the pointers).
  944. // Check the isInUpdate flag to avoid recursive events
  945. // when you update the NumericUpdownControls.
  946. {
  947. changeType = ChangeStyle.HSV;
  948. HSV = new ColorHandler.HSV(hsbHue.Value, hsbSaturation.Value, hsbBrightness.Value);
  949. SetRGB(ColorHandler.HSVtoRGB(HSV));
  950. SetHSVLabels(HSV);
  951. this.Invalidate();
  952. }
  953. private void HandleRGBScroll(object sender, ScrollEventArgs e)
  954. {
  955. // If the R, G, or B values change, use this
  956. // code to update the HSV values and invalidate
  957. // the color wheel (so it updates the pointers).
  958. // Check the isInUpdate flag to avoid recursive events
  959. // when you update the NumericUpdownControls.
  960. changeType = ChangeStyle.RGB;
  961. RGB = new ColorHandler.RGB(hsbRed.Value, hsbGreen.Value, hsbBlue.Value);
  962. SetHSV(ColorHandler.RGBtoHSV(RGB));
  963. SetRGBLabels(RGB);
  964. this.Invalidate();
  965. }
  966. private void ColorManager_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  967. {
  968. // Depending on the circumstances, force a repaint
  969. // of the color wheel passing different information.
  970. switch (changeType)
  971. {
  972. case ChangeStyle.HSV:
  973. myColorWheel.Draw(e.Graphics, HSV);
  974. break;
  975. case ChangeStyle.MouseMove:
  976. case ChangeStyle.None:
  977. myColorWheel.Draw(e.Graphics, selectedPoint);
  978. break;
  979. case ChangeStyle.RGB:
  980. myColorWheel.Draw(e.Graphics, RGB);
  981. break;
  982. }
  983. }
  984. private void btnOK_Click(object sender, EventArgs e)
  985. {
  986. }
  987. private void importPresetFromTheSelectedBlink1DeviceToolStripMenuItem_Click(object sender, EventArgs e)
  988. {
  989. }
  990. private void comboBoxDevice_SelectedIndexChanged(object sender, EventArgs e)
  991. {
  992. this.OpenSelectedBlinkDevice();
  993. }
  994. private void loadPresetFromSelectedBlink1DeviceToolStripMenuItem_Click(object sender, EventArgs e)
  995. {
  996. if (this.blink1.IsConnected == false)
  997. {
  998. MessageBox.Show("No Blink(1) devices found.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  999. return;
  1000. }
  1001. for (int counter = 0; counter < Blink1Constant.NumberOfPreset; counter++)
  1002. {
  1003. Blink1Preset blink1Preset = this.blink1.ReadPreset((uint)counter);
  1004. PresetControl control = (PresetControl)this.flowLayoutPanelPreset.Controls[counter];
  1005. control.Color = blink1Preset.Rgb;
  1006. control.Millisecond = blink1Preset.Millisecond;
  1007. }
  1008. }
  1009. private void savePresetToSelectedBlink1DeviceToolStripMenuItem_Click(object sender, EventArgs e)
  1010. {
  1011. if (this.blink1.IsConnected == false)

Large files files are truncated, but you can click here to view the full file