CommonCameraControl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PaintDotNet.Base.SettingModel;
  11. using System.Collections;
  12. using PaintDotNet.ImageCollect;
  13. using PaintDotNet.Camera;
  14. using PaintDotNet.Base.CommTool;
  15. using System.IO;
  16. namespace PaintDotNet.Setting.LabelComponent
  17. {
  18. /// <summary>
  19. /// 相机设置,常规界面
  20. /// </summary>
  21. public class CommonCameraControl : UserControl
  22. {
  23. #region 控件
  24. private GroupBox gbxShadingCorrection;
  25. public CheckBox ckbShadingCorrect;
  26. private GroupBox gbxSharpening;
  27. private Label label2;
  28. private TrackBar tbrSharpness;
  29. private TextBox tbxSharpness;
  30. #endregion
  31. /// <summary>
  32. /// 相机参数的Model
  33. /// </summary>
  34. private CameraParamModel m_cameraParamModel;
  35. private ICamera m_camera;
  36. private CommonRotateControl commonRotateControl1;
  37. private GroupBox groupBox1;
  38. private Panel panel1;
  39. private TextBox txbNameEx;
  40. private Label lblName;
  41. private bool m_immediately = false; // 设置是否立刻生效,设置到相机
  42. public CommonCameraControl()
  43. {
  44. InitializeComponent();
  45. ConfigModel.OnCameraNameExChanged += OnCameraNameChanged;
  46. }
  47. protected override void Dispose(bool disposing)
  48. {
  49. ConfigModel.OnCameraNameExChanged -= OnCameraNameChanged;
  50. base.Dispose(disposing);
  51. }
  52. private void OnCameraNameChanged()
  53. {
  54. txbNameEx.Text = m_camera.GetExofName();
  55. }
  56. public void Initialize(CameraParamModel model, bool immediately = true)
  57. {
  58. m_immediately = immediately;
  59. m_cameraParamModel = model;
  60. m_camera = CameraManager.CurrentCamera;
  61. InitializeLanguageText();
  62. InitializeData();
  63. OnCameraNameChanged();
  64. }
  65. public void ResetCameraParamModel(CameraParamModel model)
  66. {
  67. m_cameraParamModel = model;
  68. InitializeData();
  69. }
  70. /// <summary>
  71. /// 绑定样式数据
  72. /// </summary>
  73. private void InitializeData()
  74. {
  75. tbrSharpness.SetRange(0, 160);
  76. tbrSharpness.Value = m_cameraParamModel.parame.Sharpness;
  77. tbxSharpness.Text = m_cameraParamModel.parame.Sharpness.ToString();
  78. ckbShadingCorrect.Checked = m_cameraParamModel.parame.ShadingCorrection == 1;
  79. this.commonRotateControl1.Initialize();
  80. }
  81. #region 初始化组件
  82. private void InitializeLanguageText()
  83. {
  84. this.gbxShadingCorrection.Text = PdnResources.GetString("Menu.Image.ShadingCorrection.Text");
  85. this.ckbShadingCorrect.Text = PdnResources.GetString("Menu.use.text");
  86. this.gbxSharpening.Text = PdnResources.GetString("Menu.Imagesharpening.text");
  87. this.label2.Text = PdnResources.GetString("Menu.Sharpeningstrength.text") + ":";
  88. }
  89. /// <summary>
  90. /// 初始化组件
  91. /// </summary>
  92. private void InitializeComponent()
  93. {
  94. this.gbxShadingCorrection = new System.Windows.Forms.GroupBox();
  95. this.ckbShadingCorrect = new System.Windows.Forms.CheckBox();
  96. this.gbxSharpening = new System.Windows.Forms.GroupBox();
  97. this.tbxSharpness = new System.Windows.Forms.TextBox();
  98. this.label2 = new System.Windows.Forms.Label();
  99. this.tbrSharpness = new System.Windows.Forms.TrackBar();
  100. this.commonRotateControl1 = new PaintDotNet.ImageCollect.CommonRotateControl();
  101. this.groupBox1 = new System.Windows.Forms.GroupBox();
  102. this.panel1 = new System.Windows.Forms.Panel();
  103. this.txbNameEx = new System.Windows.Forms.TextBox();
  104. this.lblName = new System.Windows.Forms.Label();
  105. this.gbxShadingCorrection.SuspendLayout();
  106. this.gbxSharpening.SuspendLayout();
  107. ((System.ComponentModel.ISupportInitialize)(this.tbrSharpness)).BeginInit();
  108. this.groupBox1.SuspendLayout();
  109. this.panel1.SuspendLayout();
  110. this.SuspendLayout();
  111. //
  112. // gbxShadingCorrection
  113. //
  114. this.gbxShadingCorrection.Controls.Add(this.ckbShadingCorrect);
  115. this.gbxShadingCorrection.Dock = System.Windows.Forms.DockStyle.Top;
  116. this.gbxShadingCorrection.Location = new System.Drawing.Point(8, 172);
  117. this.gbxShadingCorrection.Name = "gbxShadingCorrection";
  118. this.gbxShadingCorrection.Size = new System.Drawing.Size(474, 74);
  119. this.gbxShadingCorrection.TabIndex = 2;
  120. this.gbxShadingCorrection.TabStop = false;
  121. this.gbxShadingCorrection.Text = "阴影校正";
  122. //
  123. // ckbShadingCorrect
  124. //
  125. this.ckbShadingCorrect.AutoSize = true;
  126. this.ckbShadingCorrect.Location = new System.Drawing.Point(24, 37);
  127. this.ckbShadingCorrect.Name = "ckbShadingCorrect";
  128. this.ckbShadingCorrect.Size = new System.Drawing.Size(48, 16);
  129. this.ckbShadingCorrect.TabIndex = 2;
  130. this.ckbShadingCorrect.Text = "使用";
  131. this.ckbShadingCorrect.UseVisualStyleBackColor = true;
  132. this.ckbShadingCorrect.Click += new System.EventHandler(this.ckbShadingCorrect_Click);
  133. //
  134. // gbxSharpening
  135. //
  136. this.gbxSharpening.Controls.Add(this.tbxSharpness);
  137. this.gbxSharpening.Controls.Add(this.label2);
  138. this.gbxSharpening.Controls.Add(this.tbrSharpness);
  139. this.gbxSharpening.Dock = System.Windows.Forms.DockStyle.Top;
  140. this.gbxSharpening.Location = new System.Drawing.Point(8, 98);
  141. this.gbxSharpening.Name = "gbxSharpening";
  142. this.gbxSharpening.Size = new System.Drawing.Size(474, 74);
  143. this.gbxSharpening.TabIndex = 3;
  144. this.gbxSharpening.TabStop = false;
  145. this.gbxSharpening.Text = "图像锐化";
  146. //
  147. // tbxSharpness
  148. //
  149. this.tbxSharpness.Location = new System.Drawing.Point(382, 34);
  150. this.tbxSharpness.Name = "tbxSharpness";
  151. this.tbxSharpness.ReadOnly = true;
  152. this.tbxSharpness.Size = new System.Drawing.Size(55, 21);
  153. this.tbxSharpness.TabIndex = 5;
  154. this.tbxSharpness.Text = "5";
  155. //
  156. // label2
  157. //
  158. this.label2.AutoSize = true;
  159. this.label2.Location = new System.Drawing.Point(22, 35);
  160. this.label2.Name = "label2";
  161. this.label2.Size = new System.Drawing.Size(65, 12);
  162. this.label2.TabIndex = 4;
  163. this.label2.Text = "锐化强度:";
  164. //
  165. // tbrSharpness
  166. //
  167. this.tbrSharpness.AutoSize = false;
  168. this.tbrSharpness.Location = new System.Drawing.Point(81, 33);
  169. this.tbrSharpness.Maximum = 200;
  170. this.tbrSharpness.Minimum = 5;
  171. this.tbrSharpness.Name = "tbrSharpness";
  172. this.tbrSharpness.Size = new System.Drawing.Size(295, 35);
  173. this.tbrSharpness.TabIndex = 2;
  174. this.tbrSharpness.TickStyle = System.Windows.Forms.TickStyle.None;
  175. this.tbrSharpness.Value = 5;
  176. this.tbrSharpness.Scroll += new System.EventHandler(this.tbrSharpness_Scroll);
  177. //
  178. // commonRotateControl1
  179. //
  180. this.commonRotateControl1.Dock = System.Windows.Forms.DockStyle.Top;
  181. this.commonRotateControl1.Location = new System.Drawing.Point(8, 8);
  182. this.commonRotateControl1.Name = "commonRotateControl1";
  183. this.commonRotateControl1.Size = new System.Drawing.Size(474, 90);
  184. this.commonRotateControl1.TabIndex = 4;
  185. //
  186. // groupBox1
  187. //
  188. this.groupBox1.Controls.Add(this.panel1);
  189. this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
  190. this.groupBox1.Location = new System.Drawing.Point(8, 246);
  191. this.groupBox1.Name = "groupBox1";
  192. this.groupBox1.Padding = new System.Windows.Forms.Padding(8, 12, 8, 8);
  193. this.groupBox1.Size = new System.Drawing.Size(474, 55);
  194. this.groupBox1.TabIndex = 5;
  195. this.groupBox1.TabStop = false;
  196. this.groupBox1.Text = "相机名称";
  197. //
  198. // panel1
  199. //
  200. this.panel1.Controls.Add(this.txbNameEx);
  201. this.panel1.Controls.Add(this.lblName);
  202. this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
  203. this.panel1.Location = new System.Drawing.Point(8, 26);
  204. this.panel1.Name = "panel1";
  205. this.panel1.Size = new System.Drawing.Size(458, 21);
  206. this.panel1.TabIndex = 0;
  207. //
  208. // txbNameEx
  209. //
  210. this.txbNameEx.Dock = System.Windows.Forms.DockStyle.Left;
  211. this.txbNameEx.Location = new System.Drawing.Point(41, 0);
  212. this.txbNameEx.Name = "txbNameEx";
  213. this.txbNameEx.Size = new System.Drawing.Size(123, 21);
  214. this.txbNameEx.TabIndex = 2;
  215. this.txbNameEx.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txbNameEx_KeyDown);
  216. //
  217. // lblName
  218. //
  219. this.lblName.AutoSize = true;
  220. this.lblName.Dock = System.Windows.Forms.DockStyle.Left;
  221. this.lblName.Location = new System.Drawing.Point(0, 0);
  222. this.lblName.Name = "lblName";
  223. this.lblName.Padding = new System.Windows.Forms.Padding(0, 4, 0, 0);
  224. this.lblName.Size = new System.Drawing.Size(41, 16);
  225. this.lblName.TabIndex = 3;
  226. this.lblName.Text = "别名:";
  227. this.lblName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  228. //
  229. // CommonCameraControl
  230. //
  231. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  232. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  233. this.AutoSize = true;
  234. this.Controls.Add(this.groupBox1);
  235. this.Controls.Add(this.gbxShadingCorrection);
  236. this.Controls.Add(this.gbxSharpening);
  237. this.Controls.Add(this.commonRotateControl1);
  238. this.Name = "CommonCameraControl";
  239. this.Padding = new System.Windows.Forms.Padding(8);
  240. this.Size = new System.Drawing.Size(490, 338);
  241. this.gbxShadingCorrection.ResumeLayout(false);
  242. this.gbxShadingCorrection.PerformLayout();
  243. this.gbxSharpening.ResumeLayout(false);
  244. this.gbxSharpening.PerformLayout();
  245. ((System.ComponentModel.ISupportInitialize)(this.tbrSharpness)).EndInit();
  246. this.groupBox1.ResumeLayout(false);
  247. this.panel1.ResumeLayout(false);
  248. this.panel1.PerformLayout();
  249. this.ResumeLayout(false);
  250. }
  251. #endregion
  252. private void tbrSharpness_Scroll(object sender, EventArgs e)
  253. {
  254. m_camera.Sharpness = tbrSharpness.Value;
  255. m_cameraParamModel.parame.Sharpness = tbrSharpness.Value;
  256. tbxSharpness.Text = tbrSharpness.Value.ToString();
  257. }
  258. private void ckbShadingCorrect_Click(object sender, EventArgs e)
  259. {
  260. m_cameraParamModel.parame.ShadingCorrection = ckbShadingCorrect.Checked ? 1 : 0;
  261. }
  262. string _cameraNameEx;
  263. private void txbNameEx_KeyDown(object sender, KeyEventArgs e)
  264. {
  265. if (e.KeyCode == Keys.Enter)
  266. {
  267. var nameEx = txbNameEx.Text;
  268. m_camera.SetExofName(nameEx);
  269. }
  270. }
  271. }
  272. }