/* * Copyright (c) 2022 LG Electronics Inc. * SPDX-License-Identifier: LicenseRef-LGE-Proprietary */ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; 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; namespace AuroraUIComponent.UserControls { /// /// Interaction logic for UCMagnification.xaml /// public partial class UCMagnification : UserControl { public static readonly DependencyProperty RectangleBrushProperty = DependencyProperty.Register( "RectangleBrush", typeof(Brush), typeof(UCMagnification), new PropertyMetadata(Brushes.Transparent, OnBrushPropertyChanged)); public Brush RectangleBrush { get { return (Brush)GetValue(RectangleBrushProperty); } set { SetValue(RectangleBrushProperty, value); } } private static void OnBrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { //(d as UCMagnification).InvalidateVisual(); (d as UCMagnification).Rect.Fill = (Brush)e.NewValue; } public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register( "Caption", typeof(string), typeof(UCMagnification), new PropertyMetadata("DateTime", OnCaptionPropertyChanged)); public string Caption { get { return (string)GetValue(CaptionProperty); } set { SetValue(CaptionProperty, value); } } private static void OnCaptionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { //(d as UCMagnification).InvalidateVisual(); (d as UCMagnification).TextCaption.Text = (string)e.NewValue; } public static readonly DependencyProperty RatioProperty = DependencyProperty.Register( "Ratio", typeof(double), typeof(UCMagnification), new PropertyMetadata(5.000, OnRatioPropertyChanged)); public double Ratio { get { return (double)GetValue(RatioProperty); } set { SetValue(RatioProperty, value); TextRatio.Text = $"x{value.ToString("N3")}"; RatioSlider.Value = value; SliderValue = value; } } public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register( "CenterX", typeof(double), typeof(UCMagnification), new PropertyMetadata(0.000)); public double CenterX { get { return (double)GetValue(CenterXProperty); } set { SetValue(CenterXProperty, value); } } public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register( "CenterY", typeof(double), typeof(UCMagnification), new PropertyMetadata(0.000)); public double CenterY { get { return (double)GetValue(CenterYProperty); } set { SetValue(CenterYProperty, value); } } public static readonly DependencyProperty CmdRatioChangedProperty = DependencyProperty.Register( "CmdRatioChanged", typeof(ICommand), typeof(UCMagnification), new PropertyMetadata(null)); public ICommand CmdRatioChanged { get { if (GetValue(CmdRatioChangedProperty) != null) { return (ICommand)GetValue(CmdRatioChangedProperty); } else { return null; } } set { SetValue(CmdRatioChangedProperty, value); } } private static void OnRatioPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { //(d as UCMagnification).InvalidateVisual(); //var newSize = e.NewValue * 100; //(d as UCMagnification).SetWindowSize(newSize, newSize); var uc = (d as UCMagnification); if (uc.CmdRatioChanged != null) { uc.CmdRatioChanged.Execute(new Tuple(uc.CenterX, uc.CenterY, (double)e.NewValue)); } } public UCMagnification() { InitializeComponent(); } private void Button_Click_x1(object sender, RoutedEventArgs e) { Ratio = 1; } private void Button_Click_x2(object sender, RoutedEventArgs e) { Ratio = 2; } private void Button_Click_x5(object sender, RoutedEventArgs e) { Ratio = 5; } private void Button_Click_x8(object sender, RoutedEventArgs e) { Ratio = 8; } private void Button_Click_x10(object sender, RoutedEventArgs e) { Ratio = 10; } private void Button_Click_x20(object sender, RoutedEventArgs e) { Ratio = 20; } // 2024.04.02. Window Size를 바꾸는 대신 Capture 영역 크기를 조정 //private void SetWindowSize(double width, double height) //{ // var window = Window.GetWindow(this); // if (window != null) { // window.Width = width; // window.Height = height; // } //} private double SliderValue; private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { SliderValue = e.NewValue; } private void RatioSlider_PreviewMouseUp(object sender, MouseButtonEventArgs e) { if (CmdRatioChanged != null) { CmdRatioChanged.Execute(new Tuple(CenterX, CenterY, SliderValue)); } } } }