
using LogClass;
using MvCameraControl;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static System.Net.Mime.MediaTypeNames;

namespace CCDCountWpf.WpfPage
{
    /// <summary>
    /// MainPage.xaml 的交互逻辑
    /// </summary>
    public partial class MainPage : Page
    {
        #region 变量与实例
        #endregion
        public MainPage()
        {
            InitializeComponent();
            DataContext  =  MessageBus.ShowBinding;
        }

        private void DataClear_Click(object sender, RoutedEventArgs e)
        {
            if(MessageBus.MainThreadS.Count<MessageBus.NowLoadCameraIndex+1)
                return;
            MessageBus.MainThreadS[MessageBus.NowLoadCameraIndex].ClearHistoryActive();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            this.Width = double.NaN; // 等效于 Auto
            this.Height = double.NaN;
        }

        private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (sender is Grid grid)
            {
                double columnWidth = grid.ActualHeight / 2; // 高度/2作为列宽
                grid.ColumnDefinitions[1].Width = new GridLength(columnWidth);
                MiniShowImageBox1.Height = columnWidth / 2 - 10;
                MiniShowImageBox2.Height = columnWidth / 2 - 10;
                MiniShowImageBox3.Height = columnWidth / 2 - 10;
                MiniShowImageBox4.Height = columnWidth / 2 - 10;
            }
        }

        private void MiniShowImageBox2_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if(MessageBus.MainThreadS.Count < 2) return;
            MessageBus.NowLoadCameraIndex = 1;
        }

        private void MiniShowImageBox1_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (MessageBus.MainThreadS.Count < 1) return;
            MessageBus.NowLoadCameraIndex = 0;
        }

        private void MiniShowImageBox3_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (MessageBus.MainThreadS.Count < 3) return;
            MessageBus.NowLoadCameraIndex = 2;
        }

        private void MiniShowImageBox4_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (MessageBus.MainThreadS.Count < 4) return;
            MessageBus.NowLoadCameraIndex = 3;
        }
    }
}
