RotateControl.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 PaintDotNet.Camera;
  12. using PaintDotNet.ImageCollect;
  13. namespace PaintDotNet.Preview2
  14. {
  15. public partial class RotateControl : UserControl
  16. {
  17. public Action OnRotated;
  18. private ICamera m_camera => CameraManager.CurrentCamera;
  19. private CameraParamModel.ParameterSets _settings
  20. {
  21. get
  22. {
  23. return CameraConfigs.Settings;
  24. }
  25. }
  26. private void InitializeLanguageText()
  27. {
  28. this.groupBox1.Text = PdnResources.GetString("Menu.Imagerotation.text");
  29. this.ckbHorizontal.Text = PdnResources.GetString("Menu.Imagerotation.Horizontal.text");
  30. this.ckbVertical.Text = PdnResources.GetString("Menu.Imagerotation.Vertical.text");
  31. var rotateArray = new string[] { PdnResources.GetString("Menu.original.text"), PdnResources.GetString("Menu.Edit.Rotate90CW.Text")/*, PdnResources.GetString("Menu.Edit.Rotate180.Text")*/, PdnResources.GetString("Menu.Rotate270degrees.Text") };
  32. imgRotateComboBox.Items.Clear();
  33. this.imgRotateComboBox.Items.AddRange(rotateArray);
  34. }
  35. public RotateControl()
  36. {
  37. InitializeComponent();
  38. imgRotateComboBox.MouseWheel += ImgRotateComboBox_MouseWheel;
  39. }
  40. public void Initialize()
  41. {
  42. InitializeLanguageText();
  43. UpdateDisplay();
  44. }
  45. private void ImgRotateComboBox_MouseWheel(object sender, MouseEventArgs e)
  46. {
  47. var handle = e as HandledMouseEventArgs;
  48. handle.Handled = true;
  49. }
  50. private void imgRotateComboBox_SelectedIndexChanged(object sender, EventArgs e)
  51. {
  52. if (_settings.Rotate == imgRotateComboBox.SelectedIndex)
  53. return;
  54. try
  55. {
  56. m_camera.Rotate = imgRotateComboBox.SelectedIndex;
  57. _settings.Rotate = imgRotateComboBox.SelectedIndex;
  58. }
  59. catch
  60. {
  61. MessageBox.Show("该相机不支持该操作。");
  62. imgRotateComboBox.SelectedIndex = _settings.Rotate;
  63. }
  64. OnRotated?.Invoke();
  65. }
  66. private void ckbVertical_Click(object sender, EventArgs e)
  67. {
  68. _settings.Vertical = ckbVertical.Checked ? 1 : 0;
  69. m_camera.VerticalMirrored = ckbVertical.Checked;
  70. OnRotated?.Invoke();
  71. }
  72. private void ckbHorizontal_Click(object sender, EventArgs e)
  73. {
  74. _settings.Horizontal = ckbHorizontal.Checked ? 1 : 0;
  75. m_camera.HorizontalMirrored = ckbHorizontal.Checked;
  76. OnRotated?.Invoke();
  77. }
  78. public void UpdateDisplay()
  79. {
  80. imgRotateComboBox.SelectedIndex = _settings.Rotate==3?2: _settings.Rotate;
  81. ckbHorizontal.Checked = _settings.Horizontal > 0;
  82. ckbVertical.Checked = _settings.Vertical > 0;
  83. }
  84. }
  85. }