You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.0 KiB

3 years ago
using EC.Onvif;
using EC.UsingEventAggregator;
using Prism.Events;
using System.Windows;
using System.Windows.Controls;
namespace ECMonitor.Page.CameraMonitor
{
/// <summary>
/// UCMainRight.xaml 的交互逻辑
/// </summary>
public partial class CameraAdjust : UserControl
{
private IEventAggregator _ea { get; set; }
private OnvifClient _onvifClient { get; set; }
public CameraAdjust(IEventAggregator ea)
{
InitializeComponent();
_ea = ea;
_ea.GetEvent<SendOnvifClientEvent>().Subscribe(SetCurOnvifClient);
InitBtnListenEvent();
}
#region Get & Set
private void SetCurOnvifClient(OnvifClient obj)
{
_onvifClient = obj;
}
#endregion Get & Set
#region ListenEvent
private void InitBtnListenEvent()
{
//luBtn.Click += OperateOnvifMouseDown;
//lBtn.Click += OperateOnvifMouseDown;
//ldBtn.Click += OperateOnvifMouseDown;
//uBtn.Click += OperateOnvifMouseDown;
//dBtn.Click += OperateOnvifMouseDown;
//ruBtn.Click += OperateOnvifMouseDown;
//rBtn.Click += OperateOnvifMouseDown;
//rdBtn.Click += OperateOnvifMouseDown;
luBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
lBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
ldBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
uBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
cBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
dBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
ruBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
rBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
rdBtn.AddHandler(MouseDownEvent, new RoutedEventHandler(OperateOnvifMouseDown), true);
luBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
lBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
ldBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
uBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
cBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
dBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
ruBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
rBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
rdBtn.AddHandler(MouseUpEvent, new RoutedEventHandler(OperateOnvifMouseUp), true);
}
private bool IsOperateOnvif { get; set; }
private void OperateOnvifMouseDown(object sender, RoutedEventArgs e)
{
if (_onvifClient == null || IsOperateOnvif)
return;
IsOperateOnvif = true;
var btnName = ((Button)sender).Name;
var step = (float)stepSlider.Value;
var dist = step * OnvifClient.atomDist;
var speed = step * OnvifClient.atomSpeed;
float[] ptz = new float[] { 0, 0, 0 };//ptx,pty,zx
switch (btnName)
{
case "luBtn":
ptz = new float[] { -1, 1, 0 };
break;
case "uBtn":
ptz = new float[] { 0, 1, 0 };
break;
case "ruBtn":
ptz = new float[] { 1, 1, 0 };
break;
case "lBtn":
ptz = new float[] { -1, 0, 0 };
break;
case "cBtn":
ptz = new float[] { 0, 0, 0 };
break;
case "rBtn":
ptz = new float[] { 1, 0, 0 };
break;
case "ldBtn":
ptz = new float[] { -1, -1, 0 };
break;
case "dBtn":
ptz = new float[] { 0, -1, 0 };
break;
case "rdBtn":
ptz = new float[] { 1, -1, 0 };
break;
}
//_onvifClient.RelativeMoveAsync(ptz[0] * dist, ptz[1] * dist, ptz[2] * dist);
_onvifClient.ContinuousMoveAsync(ptz[0] * speed, ptz[1] * speed, ptz[2] * speed);
}
private void OperateOnvifMouseUp(object sender, RoutedEventArgs e)
{
if (_onvifClient == null)
return;
IsOperateOnvif = false;
_onvifClient.StopAsync();
}
#endregion ListenEvent
}
}