ImageViewerVisualSettings.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. namespace OINA.Extender.Testharness
  2. {
  3. using System;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using OINA.Extender.Controls.Styles;
  7. /// <summary>
  8. /// ImageViewerVisualSettings Form
  9. /// </summary>
  10. public partial class ImageViewerVisualSettings : Form
  11. {
  12. /// <summary>
  13. /// Gets or sets the color of ImageViewer background.
  14. /// </summary>
  15. public static Color BackgroundColor
  16. {
  17. get { return ColorConverter.Convert(ImageViewerStyle.BackgroundColor); }
  18. set { ImageViewerStyle.BackgroundColor = ColorConverter.Convert(value); }
  19. }
  20. /// <summary>
  21. /// Gets or sets the color of ImageViewer Heads and ScaleBar Foreground Color.
  22. /// </summary>
  23. public static Color ForegroundColor
  24. {
  25. get { return ColorConverter.Convert(ImageViewerStyle.ForegroundColor); }
  26. set { ImageViewerStyle.ForegroundColor = ColorConverter.Convert(value); }
  27. }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="ImageViewerVisualSettings"/> class.
  30. /// </summary>
  31. public ImageViewerVisualSettings()
  32. {
  33. this.InitializeComponent();
  34. this.InitializeComboBoxes();
  35. this.UpdateDisplay();
  36. this.cbBackgroundColor.SelectedValueChanged += this.OnBackgroundColorChanged;
  37. this.cbForegroundColor.SelectedValueChanged += this.OnForegroundColorChanged;
  38. this.cbHeaderFontSize.SelectedValueChanged += this.OnHeaderFontSizeChanged;
  39. this.cbHeaderFontFamily.SelectedValueChanged += this.OnHeaderFontFamilyChanged;
  40. this.cbScaleBarFontSize.SelectedValueChanged += this.OnScaleBarFontSizeChanged;
  41. }
  42. /// <summary>
  43. /// InitialComboBox
  44. /// </summary>
  45. private void InitializeComboBoxes()
  46. {
  47. this.cbBackgroundColor.DataSource = ColorConverter.GetSystemDrawingColors();
  48. this.cbForegroundColor.DataSource = ColorConverter.GetSystemDrawingColors();
  49. this.cbHeaderFontFamily.DataSource = System.Windows.Media.Fonts.SystemFontFamilies;
  50. this.cbHeaderFontSize.DataSource = new[] { 12d, 14d, 16d, 18d };
  51. this.cbScaleBarFontSize.DataSource = new[] { 8d, 10d, 12d, 14d };
  52. }
  53. /// <summary>
  54. /// Handles the SelectedValueChanged event of the CbBackgroundColor control.
  55. /// </summary>
  56. /// <param name="sender">The source of the event.</param>
  57. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  58. private void OnBackgroundColorChanged(object sender, EventArgs e)
  59. {
  60. if (this.cbBackgroundColor.SelectedValue != null)
  61. {
  62. BackgroundColor = (Color)this.cbBackgroundColor.SelectedValue;
  63. this.backgroundPanel.BackColor = BackgroundColor;
  64. }
  65. }
  66. /// <summary>
  67. /// Handles the SelectedValueChanged event of the cbForegroundColor control.
  68. /// </summary>
  69. /// <param name="sender">The source of the event.</param>
  70. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  71. private void OnForegroundColorChanged(object sender, EventArgs e)
  72. {
  73. if (this.cbForegroundColor.SelectedValue != null)
  74. {
  75. ForegroundColor = (Color)this.cbForegroundColor.SelectedValue;
  76. this.foregroundColorPanel.BackColor = ForegroundColor;
  77. }
  78. }
  79. /// <summary>
  80. /// Handles the SelectedValueChanged event of the CbHeaderFontSize control.
  81. /// </summary>
  82. /// <param name="sender">The source of the event.</param>
  83. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  84. private void OnHeaderFontSizeChanged(object sender, EventArgs e)
  85. {
  86. if (this.cbHeaderFontSize.SelectedValue != null)
  87. {
  88. ImageViewerStyle.HeaderFontSize = (double)this.cbHeaderFontSize.SelectedValue;
  89. }
  90. }
  91. /// <summary>
  92. /// Handles the SelectedValueChanged event of the CbHeaderFontFamily control.
  93. /// </summary>
  94. /// <param name="sender">The source of the event.</param>
  95. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  96. private void OnHeaderFontFamilyChanged(object sender, EventArgs e)
  97. {
  98. if (this.cbHeaderFontFamily.SelectedValue != null)
  99. {
  100. ImageViewerStyle.HeaderFontFamily = this.cbHeaderFontFamily.SelectedValue as System.Windows.Media.FontFamily;
  101. }
  102. }
  103. /// <summary>
  104. /// Handles the SelectedValueChanged event of the CbScaleBarFontSize control.
  105. /// </summary>
  106. /// <param name="sender">The source of the event.</param>
  107. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  108. private void OnScaleBarFontSizeChanged(object sender, EventArgs e)
  109. {
  110. if (this.cbScaleBarFontSize.SelectedValue != null)
  111. {
  112. ImageViewerStyle.ScaleBarFontSize = (double)this.cbScaleBarFontSize.SelectedValue;
  113. }
  114. }
  115. /// <summary>
  116. /// Handles the click event of the BtResetStyle button.
  117. /// </summary>
  118. /// <param name="sender">The source of the event.</param>
  119. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  120. private void OnResetStyle(object sender, EventArgs e)
  121. {
  122. ImageViewerStyle.ResetStyles();
  123. this.UpdateDisplay();
  124. }
  125. /// <summary>
  126. /// Updates the display on loading or resetting styleres
  127. /// </summary>
  128. private void UpdateDisplay()
  129. {
  130. this.backgroundPanel.BackColor = BackgroundColor;
  131. this.foregroundColorPanel.BackColor = ForegroundColor;
  132. ColorConverter.PickColourComboItem(this.cbBackgroundColor, BackgroundColor);
  133. ColorConverter.PickColourComboItem(this.cbForegroundColor, ForegroundColor);
  134. this.cbHeaderFontFamily.SelectedIndex = -1;
  135. this.cbHeaderFontFamily.SelectedItem = ImageViewerStyle.HeaderFontFamily;
  136. this.cbHeaderFontSize.SelectedItem = ImageViewerStyle.HeaderFontSize;
  137. this.cbScaleBarFontSize.SelectedItem = ImageViewerStyle.ScaleBarFontSize;
  138. }
  139. }
  140. }