aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs
blob: 55dd5d23ce38e01266fb71dc8f876ed1a9581c75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.SharedUI.Helpers;

namespace Tango.MachineStudio.Common.Controls
{
    /// <summary>
    /// Represents an MDI-style container
    /// </summary>
    /// <seealso cref="System.Windows.Controls.UserControl" />
    /// <seealso cref="System.Windows.Markup.IComponentConnector" />
    /// <seealso cref="System.Windows.Markup.IStyleConnector" />
    public partial class MdiContainerControl : UserControl
    {
        private const int MIN_SIZE = 200;

        public MdiContainerControl()
        {
            InitializeComponent();
        }

        public IEnumerable ItemsSource
        {
            get { return (IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(MdiContainerControl), new PropertyMetadata(null));

        private void OnControlDragging(object sender, DragDeltaEventArgs e)
        {
            var mdiControl = GetSenderTag<MdiChild>(sender);
            mdiControl.Location = new Point(mdiControl.Location.X + e.HorizontalChange, mdiControl.Location.Y + e.VerticalChange);
            FitCanvas();
        }

        private T GetSenderTag<T>(object sender) where T : class
        {
            return (T)((sender as FrameworkElement).Tag);
        }

        private void FitCanvas()
        {
            Canvas canvas = GetCanvas();
            canvas.Width = canvas.Children.OfType<FrameworkElement>().Max(x => Canvas.GetLeft(x) + x.ActualWidth);
            canvas.Height = canvas.Children.OfType<FrameworkElement>().Max(x => Canvas.GetTop(x) + x.ActualHeight);
        }

        private Canvas GetCanvas()
        {
            return itemsControl.FindChild<Canvas>("canvas");
        }

        private void OnControlMouseDown(object sender, MouseButtonEventArgs e)
        {
            Canvas.SetZIndex(sender as FrameworkElement, GetCanvas().Children.OfType<FrameworkElement>().Max(x => Canvas.GetZIndex(x) + 1));
        }

        private void OnControlSizeRight(object sender, DragDeltaEventArgs e)
        {
            var mdiControl = GetSenderTag<MdiChild>(sender);
            if (double.IsNaN(mdiControl.View.Width)) mdiControl.View.Width = mdiControl.View.ActualWidth;
            if (mdiControl.View.Width + e.HorizontalChange > MIN_SIZE) mdiControl.View.Width += e.HorizontalChange;
        }

        private void OnControlSizeBottom(object sender, DragDeltaEventArgs e)
        {
            var mdiControl = GetSenderTag<MdiChild>(sender);
            if (double.IsNaN(mdiControl.View.Height)) mdiControl.View.Height = mdiControl.View.ActualHeight;
            if (mdiControl.View.Height + e.VerticalChange > MIN_SIZE) mdiControl.View.Height += e.VerticalChange;
        }

        private void OnControlResize(object sender, DragDeltaEventArgs e)
        {
            var mdiControl = GetSenderTag<MdiChild>(sender);

            if (double.IsNaN(mdiControl.View.Height)) mdiControl.View.Height = mdiControl.View.ActualHeight;
            if (double.IsNaN(mdiControl.View.Width)) mdiControl.View.Width = mdiControl.View.ActualWidth;

            if (mdiControl.View.Height + e.VerticalChange > MIN_SIZE) mdiControl.View.Height += e.VerticalChange;
            if (mdiControl.View.Width + e.HorizontalChange > MIN_SIZE) mdiControl.View.Width += e.HorizontalChange;
        }

        private void OnControlClosed(object sender, RoutedEventArgs e)
        {
            (ItemsSource as IList).Remove(GetSenderTag<MdiChild>(sender));
        }
    }
}
l VerticalAlignment="Bottom" Margin="0 10 0 0" DockPanel.Dock="Bottom"> <Grid Margin="50 0 0 0"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center"> <Button Command="{Binding MediaSeekBackwardCommand}" Margin="0 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="60" Height="60" Background="Transparent"> <materialDesign:PackIcon Width="40" Height="40" Kind="Rewind" Foreground="{StaticResource AccentColorBrush}" /> </Button> <Button Command="{Binding MediaPlayPauseCommand}" Margin="20 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="80" Height="80" Background="Transparent"> <materialDesign:PackIcon Width="60" Height="60" Foreground="{StaticResource AccentColorBrush}"> <materialDesign:PackIcon.Style> <Style TargetType="materialDesign:PackIcon"> <Setter Property="Kind" Value="Play"></Setter> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding Player.IsPlaying}" Value="True" /> <Condition Binding="{Binding Player.IsPaused}" Value="False" /> </MultiDataTrigger.Conditions> <Setter Property="Kind" Value="Pause"></Setter> </MultiDataTrigger> </Style.Triggers> </Style> </materialDesign:PackIcon.Style> </materialDesign:PackIcon> </Button> <Button Command="{Binding MediaStopCommand}" Margin="20 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="60" Height="60" Background="Transparent"> <materialDesign:PackIcon Width="40" Height="40" Kind="Stop" Foreground="{StaticResource AccentColorBrush}" /> </Button> <Button Command="{Binding MediaSeekForwardCommand}" Margin="20 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="60" Height="60" Background="Transparent"> <materialDesign:PackIcon Width="40" Height="40" Kind="FastForward" Foreground="{StaticResource AccentColorBrush}" /> </Button> <Button Command="{Binding MediaRecordingCommand}" Margin="20 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Foreground="#FF7A7A" BorderBrush="#FF8585" Padding="0" Width="50" Height="50" Background="Transparent" ToolTip="Start Recording"> <materialDesign:PackIcon Width="30" Height="30" Kind="Record" /> </Button> </StackPanel> <Grid> <Label Margin="0 0 15 0" VerticalAlignment="Center" HorizontalAlignment="Right" Foreground="#FF8585" FontSize="40" FontFamily="{StaticResource digital-7}"> <Label.Style> <Style TargetType="Label"> <Setter Property="Opacity" Value="1"></Setter> <Setter Property="Content"> <Setter.Value> <TextBlock> <Run Text="{Binding Player.CurrentTime,Mode=OneWay,StringFormat=hh\\:mm\\:ss,FallbackValue='00:00:00'}"/> <Run>/</Run> <Run Text="{Binding Player.TotalTime,Mode=OneWay,StringFormat=hh\\:mm\\:ss,FallbackValue='00:00:00'}"/> </TextBlock> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding Recorder.IsRecording}" Value="True"> <Setter Property="Content"> <Setter.Value> <TextBlock> <Run Text="{Binding Recorder.RecordingTime,Mode=OneWay,StringFormat=hh\\:mm\\:ss,FallbackValue='00:00:00'}"/> </TextBlock> </Setter.Value> </Setter> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Duration="00:00:01" RepeatBehavior="Forever"> <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="1" /> <DiscreteDoubleKeyFrame KeyTime="00:00:0.5" Value="0" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Duration="00:00:01"> <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="1" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> </Label.Style> </Label> </Grid> <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" TextElement.FontSize="16" Visibility="{Binding Recorder.IsRecording,Converter={StaticResource BooleanToVisibilityConverter}}"> <TextBlock DockPanel.Dock="Left"> <Run FontWeight="SemiBold" FontStyle="Italic">Total Frames:</Run> <Run FontStyle="Italic" Foreground="#545454" Text="{Binding Recorder.TotalFramesRecorded,StringFormat={}{0:N0},Mode=OneWay,TargetNullValue=0,FallbackValue=0}"></Run> </TextBlock> <TextBlock Margin="80 0 0 0" HorizontalAlignment="Right" Width="250"> <Run FontWeight="SemiBold" FontStyle="Italic">File Size:</Run> <Run FontStyle="Italic" Foreground="#545454" Text="{Binding Recorder.TotalBytesRecorded,Mode=OneWay,Converter={StaticResource NumberToFileSizeConverter},TargetNullValue=0,FallbackValue=0}"></Run> </TextBlock> </DockPanel> </Grid> <Slider x:Name="slider" Margin="0 10 20 0" Visibility="{Binding Recorder.IsRecording,Converter={StaticResource BooleanToVisibilityInverseConverter}}" Maximum="{Binding Player.TotalFrames}" Value="{Binding Player.CurrentFrame,Mode=OneWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewMouseDown"> <i:InvokeCommandAction Command="{Binding MediaSeekHoldCommand}"></i:InvokeCommandAction> </i:EventTrigger> <i:EventTrigger EventName="PreviewMouseUp"> <i:InvokeCommandAction Command="{Binding MediaSeekCommand}" CommandParameter="{Binding ElementName=slider,Path=Value}"></i:InvokeCommandAction> </i:EventTrigger> </i:Interaction.Triggers> </Slider> </StackPanel> <logging:TimelineView RenderTransformOrigin="0.5,0.5" DataContext="{Binding TimelineViewVM}" Margin="0 0 0 10"> <FrameworkElement.Style> <Style TargetType="FrameworkElement"> <Setter Property="RenderTransform"> <Setter.Value> <ScaleTransform ScaleX="0" ScaleY="0" /> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.Player.IsPlaying}" Value="True"> <DataTrigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="00:00:0.2" /> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="1" Duration="00:00:0.2" /> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="0" Duration="00:00:0.2" /> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="0" Duration="00:00:0.2" /> </Storyboard> </BeginStoryboard> </DataTrigger.ExitActions> </DataTrigger> </Style.Triggers> </Style> </FrameworkElement.Style> </logging:TimelineView> </DockPanel> </Grid> </Grid> </Grid> </Grid> </UserControl>