ColorDisplayWidget.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. using SmartCoalApplication.Core;
  2. using SmartCoalApplication.SystemLayer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace SmartCoalApplication.PluginAssemblys
  13. {
  14. internal class ColorDisplayWidget : UserControl
  15. {
  16. private System.ComponentModel.IContainer components;
  17. private ColorRectangleControl primaryColorRectangle;
  18. private ColorRectangleControl secondaryColorRectangle;
  19. private IconBox blackAndWhiteIconBox;
  20. private ToolTip toolTip;
  21. private IconBox swapIconBox;
  22. protected override Size DefaultSize
  23. {
  24. get
  25. {
  26. return new Size(48, 48);
  27. }
  28. }
  29. public event EventHandler UserPrimaryColorChanged;
  30. protected virtual void OnUserPrimaryColorChanged()
  31. {
  32. if (UserPrimaryColorChanged != null)
  33. {
  34. UserPrimaryColorChanged(this, EventArgs.Empty);
  35. }
  36. }
  37. private ColorBgra userPrimaryColor;
  38. public ColorBgra UserPrimaryColor
  39. {
  40. get
  41. {
  42. return this.userPrimaryColor;
  43. }
  44. set
  45. {
  46. ColorBgra oldColor = this.userPrimaryColor;
  47. this.userPrimaryColor = value;
  48. this.primaryColorRectangle.RectangleColor = value.ToColor();
  49. Invalidate();
  50. Update();
  51. }
  52. }
  53. public event EventHandler UserSecondaryColorChanged;
  54. protected virtual void OnUserSecondaryColorChanged()
  55. {
  56. if (UserSecondaryColorChanged != null)
  57. {
  58. UserSecondaryColorChanged(this, EventArgs.Empty);
  59. }
  60. }
  61. private ColorBgra userSecondaryColor;
  62. public ColorBgra UserSecondaryColor
  63. {
  64. get
  65. {
  66. return userSecondaryColor;
  67. }
  68. set
  69. {
  70. ColorBgra oldColor = this.userSecondaryColor;
  71. this.userSecondaryColor = value;
  72. this.secondaryColorRectangle.RectangleColor = value.ToColor();
  73. Invalidate();
  74. Update();
  75. }
  76. }
  77. public ColorDisplayWidget()
  78. {
  79. // This call is required by the Windows.Forms Form Designer.
  80. InitializeComponent();
  81. /*this.swapIconBox.Icon = new Bitmap(PdnResources.GetImageResource("Icons.SwapIcon.png").Reference);
  82. this.blackAndWhiteIconBox.Icon = new Bitmap(PdnResources.GetImageResource("Icons.BlackAndWhiteIcon.png").Reference);
  83. if (!DesignMode)
  84. {
  85. this.toolTip.SetToolTip(swapIconBox, PdnResources.GetString("ColorDisplayWidget.SwapIconBox.ToolTipText"));
  86. this.toolTip.SetToolTip(blackAndWhiteIconBox, PdnResources.GetString("ColorDisplayWidget.BlackAndWhiteIconBox.ToolTipText"));
  87. this.toolTip.SetToolTip(primaryColorRectangle, PdnResources.GetString("ColorDisplayWidget.ForeColorRectangle.ToolTipText"));
  88. this.toolTip.SetToolTip(secondaryColorRectangle, PdnResources.GetString("ColorDisplayWidget.BackColorRectangle.ToolTipText"));
  89. }*/
  90. }
  91. protected override void OnLayout(LayoutEventArgs levent)
  92. {
  93. int ulX = (this.ClientRectangle.Width - UI.ScaleWidth(this.DefaultSize.Width)) / 2;
  94. int ulY = (this.ClientRectangle.Height - UI.ScaleHeight(this.DefaultSize.Height)) / 2;
  95. this.primaryColorRectangle.Location = new System.Drawing.Point(UI.ScaleWidth(ulX + 2), UI.ScaleHeight(ulY + 2));
  96. this.secondaryColorRectangle.Location = new System.Drawing.Point(UI.ScaleWidth(ulX + 18), UI.ScaleHeight(ulY + 18));
  97. this.swapIconBox.Location = new System.Drawing.Point(UI.ScaleWidth(ulX + 30), UI.ScaleHeight(ulY + 2));
  98. this.blackAndWhiteIconBox.Location = new System.Drawing.Point(UI.ScaleWidth(ulX + 2), UI.ScaleHeight(ulY + 31));
  99. base.OnLayout(levent);
  100. }
  101. /// <summary>
  102. /// Clean up any resources being used.
  103. /// </summary>
  104. protected override void Dispose(bool disposing)
  105. {
  106. if (disposing)
  107. {
  108. if (components != null)
  109. {
  110. components.Dispose();
  111. components = null;
  112. }
  113. }
  114. base.Dispose(disposing);
  115. }
  116. #region Component Designer generated code
  117. /// <summary>
  118. /// Required method for Designer support - do not modify
  119. /// the contents of this method with the code editor.
  120. /// </summary>
  121. private void InitializeComponent()
  122. {
  123. this.components = new System.ComponentModel.Container();
  124. this.primaryColorRectangle = new ColorRectangleControl();
  125. this.secondaryColorRectangle = new ColorRectangleControl();
  126. this.swapIconBox = new SmartCoalApplication.IconBox();
  127. this.blackAndWhiteIconBox = new SmartCoalApplication.IconBox();
  128. this.toolTip = new System.Windows.Forms.ToolTip(this.components);
  129. this.SuspendLayout();
  130. //
  131. // foreColorRectangle
  132. //
  133. this.primaryColorRectangle.Name = "foreColorRectangle";
  134. this.primaryColorRectangle.RectangleColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
  135. this.primaryColorRectangle.Size = new System.Drawing.Size(28, 28);
  136. this.primaryColorRectangle.TabIndex = 0;
  137. this.primaryColorRectangle.Click += new System.EventHandler(this.PrimaryColorRectangle_Click);
  138. this.primaryColorRectangle.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Control_KeyUp);
  139. //
  140. // backColorRectangle
  141. //
  142. this.secondaryColorRectangle.Name = "backColorRectangle";
  143. this.secondaryColorRectangle.RectangleColor = System.Drawing.Color.Magenta;
  144. this.secondaryColorRectangle.Size = new System.Drawing.Size(28, 28);
  145. this.secondaryColorRectangle.TabIndex = 1;
  146. this.secondaryColorRectangle.Click += new System.EventHandler(this.SecondaryColorRectangle_Click);
  147. this.secondaryColorRectangle.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Control_KeyUp);
  148. //
  149. // swapIconBox
  150. //
  151. this.swapIconBox.Icon = null;
  152. this.swapIconBox.Name = "swapIconBox";
  153. this.swapIconBox.Size = new System.Drawing.Size(15, 15);
  154. this.swapIconBox.TabIndex = 2;
  155. this.swapIconBox.TabStop = false;
  156. this.swapIconBox.Click += new System.EventHandler(this.SwapIconBox_Click);
  157. this.swapIconBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Control_KeyUp);
  158. this.swapIconBox.DoubleClick += new System.EventHandler(this.SwapIconBox_Click);
  159. //
  160. // blackAndWhiteIconBox
  161. //
  162. this.blackAndWhiteIconBox.Icon = null;
  163. this.blackAndWhiteIconBox.Name = "blackAndWhiteIconBox";
  164. this.blackAndWhiteIconBox.Size = new System.Drawing.Size(15, 15);
  165. this.blackAndWhiteIconBox.TabIndex = 3;
  166. this.blackAndWhiteIconBox.TabStop = false;
  167. this.blackAndWhiteIconBox.Click += new System.EventHandler(this.BlackAndWhiteIconBox_Click);
  168. this.blackAndWhiteIconBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Control_KeyUp);
  169. this.blackAndWhiteIconBox.DoubleClick += new System.EventHandler(this.BlackAndWhiteIconBox_Click);
  170. //
  171. // toolTip
  172. //
  173. this.toolTip.ShowAlways = true;
  174. //
  175. // ColorDisplayWidget
  176. //
  177. this.Controls.Add(this.blackAndWhiteIconBox);
  178. this.Controls.Add(this.swapIconBox);
  179. this.Controls.Add(this.primaryColorRectangle);
  180. this.Controls.Add(this.secondaryColorRectangle);
  181. this.AutoScaleDimensions = new SizeF(96F, 96F);
  182. this.AutoScaleMode = AutoScaleMode.Dpi;
  183. this.Name = "ColorDisplayWidget";
  184. this.Size = new System.Drawing.Size(48, 48);
  185. this.ResumeLayout(false);
  186. }
  187. #endregion
  188. public event EventHandler SwapColorsClicked;
  189. protected virtual void OnSwapColorsClicked()
  190. {
  191. if (SwapColorsClicked != null)
  192. {
  193. SwapColorsClicked(this, EventArgs.Empty);
  194. }
  195. }
  196. private void SwapIconBox_Click(object sender, System.EventArgs e)
  197. {
  198. OnSwapColorsClicked();
  199. }
  200. public event EventHandler BlackAndWhiteButtonClicked;
  201. protected virtual void OnBlackAndWhiteButtonClicked()
  202. {
  203. if (BlackAndWhiteButtonClicked != null)
  204. {
  205. BlackAndWhiteButtonClicked(this, EventArgs.Empty);
  206. }
  207. }
  208. private void BlackAndWhiteIconBox_Click(object sender, System.EventArgs e)
  209. {
  210. OnBlackAndWhiteButtonClicked();
  211. }
  212. public event EventHandler UserPrimaryColorClick;
  213. protected virtual void OnUserPrimaryColorClick()
  214. {
  215. if (UserPrimaryColorClick != null)
  216. {
  217. UserPrimaryColorClick(this, EventArgs.Empty);
  218. }
  219. }
  220. private void PrimaryColorRectangle_Click(object sender, System.EventArgs e)
  221. {
  222. OnUserPrimaryColorClick();
  223. }
  224. public event EventHandler UserSecondaryColorClick;
  225. protected virtual void OnUserSecondaryColorClick()
  226. {
  227. if (UserSecondaryColorClick != null)
  228. {
  229. UserSecondaryColorClick(this, EventArgs.Empty);
  230. }
  231. }
  232. private void SecondaryColorRectangle_Click(object sender, System.EventArgs e)
  233. {
  234. OnUserSecondaryColorClick();
  235. }
  236. private void Control_KeyUp(object sender, KeyEventArgs e)
  237. {
  238. this.OnKeyUp(e);
  239. }
  240. }
  241. }