ColorDisplayWidget.cs 9.9 KB

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