AITSignalTower.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Effects;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Aitex.Core.Common.DeviceData;
  16. using Aitex.Core.UI.ControlDataContext;
  17. namespace Aitex.Core.UI.DeviceControl
  18. {
  19. public partial class AITSignalTower : UserControl
  20. {
  21. public AITSignalTower()
  22. {
  23. InitializeComponent();
  24. redLightEffect.BlurRadius = 20;
  25. redLightEffect.Opacity = 1;
  26. redLightEffect.Color = Colors.Red;
  27. yellowLightEffect.BlurRadius = 20;
  28. yellowLightEffect.Opacity = 1;
  29. yellowLightEffect.Color = Colors.Yellow;
  30. greenLightEffect.BlurRadius = 20;
  31. greenLightEffect.Opacity = 1;
  32. greenLightEffect.Color = Colors.Green;
  33. blueLightEffect.BlurRadius = 20;
  34. blueLightEffect.Opacity = 1;
  35. blueLightEffect.Color = Colors.Blue;
  36. }
  37. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  38. "DeviceData", typeof(AITSignalTowerData), typeof(AITSignalTower),
  39. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  40. public static readonly DependencyProperty BuzzingWarningConfigCommandProperty = DependencyProperty.Register(
  41. "BuzzingWarningConfigCallback", typeof(Action), typeof(AITSignalTower),
  42. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.None));
  43. public Action BuzzingWarningConfigCallback
  44. {
  45. get
  46. {
  47. return (Action)GetValue(BuzzingWarningConfigCommandProperty);
  48. }
  49. set
  50. {
  51. SetValue(BuzzingWarningConfigCommandProperty, value);
  52. }
  53. }
  54. public AITSignalTowerData DeviceData
  55. {
  56. get
  57. {
  58. return (AITSignalTowerData)GetValue(DeviceDataProperty);
  59. }
  60. set
  61. {
  62. SetValue(DeviceDataProperty, value);
  63. }
  64. }
  65. DropShadowEffect redLightEffect = new DropShadowEffect();
  66. DropShadowEffect yellowLightEffect = new DropShadowEffect();
  67. DropShadowEffect greenLightEffect = new DropShadowEffect();
  68. DropShadowEffect blueLightEffect = new DropShadowEffect();
  69. public double OutLights = 0.2;
  70. protected override void OnRender(DrawingContext drawingContext)
  71. {
  72. base.OnRender(drawingContext);
  73. if (DeviceData == null)
  74. return;
  75. if (DeviceData.IsRedLightOn)
  76. {
  77. if (rectangle1.Opacity != 1)
  78. {
  79. rectangle1.Opacity = 1;
  80. rectangle1.Effect = redLightEffect;
  81. }
  82. }
  83. else
  84. {
  85. if (rectangle1.Opacity != OutLights)
  86. {
  87. rectangle1.Opacity = OutLights;
  88. rectangle1.Effect = null;
  89. }
  90. }
  91. if (DeviceData.IsYellowLightOn)
  92. {
  93. if (rectangle2.Opacity != 1)
  94. {
  95. rectangle2.Opacity = 1;
  96. rectangle2.Effect = yellowLightEffect;
  97. }
  98. }
  99. else
  100. {
  101. if (rectangle2.Opacity != OutLights)
  102. {
  103. rectangle2.Opacity = OutLights;
  104. rectangle2.Effect = null;
  105. }
  106. }
  107. if (DeviceData.IsGreenLightOn)
  108. {
  109. if (rectangle3.Opacity != 1)
  110. {
  111. rectangle3.Opacity = 1;
  112. rectangle3.Effect = greenLightEffect;
  113. }
  114. }
  115. else
  116. {
  117. if (rectangle3.Opacity != OutLights)
  118. {
  119. rectangle3.Opacity = OutLights;
  120. rectangle3.Effect = null;
  121. }
  122. }
  123. }
  124. private void rectangle2_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  125. {
  126. if (BuzzingWarningConfigCallback != null)
  127. {
  128. BuzzingWarningConfigCallback.Invoke();
  129. }
  130. }
  131. }
  132. }