Пример #1
0
        public Button(string Text = "")
        {
            this.Text = Text;

            MainGrid.Background = BGBrush;
            MainGrid.Focusable  = true;

            Label.HorizontalAlignment        = HorizontalAlignment.Stretch;
            Label.VerticalAlignment          = VerticalAlignment.Stretch;
            Label.HorizontalContentAlignment = HorizontalAlignment.Center;
            Label.VerticalContentAlignment   = VerticalAlignment.Center;
            Label.Padding = new Thickness(0);

            Label.Foreground = FGBrush;

            MainGrid.Children.Add(Label);

            MainGrid.SizeChanged += (object sender, System.Windows.SizeChangedEventArgs e) =>
            {
                if (MainGrid.ActualHeight > 1)
                {
                    Label.FontSize = MainGrid.ActualHeight * 0.5;
                }
            };

            MainGrid.MouseEnter += (object sender, System.Windows.Input.MouseEventArgs e) =>
            {
                if (GlobalSettings.Animations)
                {
                    Animators.Animate(
                        HToken,
                        (double h) => { H = h; UpdateColors(); },
                        GlobalSettings.AnimationSpeed * 2,
                        H, 1);
                }
                else
                {
                    H = 1; UpdateColors();
                }
            };

            MainGrid.MouseLeave += (object sender, System.Windows.Input.MouseEventArgs e) =>
            {
                if (GlobalSettings.Animations)
                {
                    Animators.Animate(
                        HToken,
                        (double h) => { H = h; UpdateColors(); },
                        GlobalSettings.AnimationSpeed,
                        H, 0);
                    if (ClickPotential)
                    {
                        Animators.AnimateNatural(
                            PToken,
                            (double p) => { P = p; UpdateColors(); },
                            GlobalSettings.AnimationSpeed / 2,
                            P, 0);
                    }
                }
                else
                {
                    H = 0;
                    P = 0;
                    UpdateColors();
                }
                ClickPotential = false;
            };

            MainGrid.MouseDown += (object sender, System.Windows.Input.MouseButtonEventArgs e) =>
            {
                ClickPotential = true;
                if (GlobalSettings.Animations)
                {
                    Animators.Animate(
                        PToken,
                        (double p) => { P = p; UpdateColors(); },
                        GlobalSettings.AnimationSpeed * 4,
                        P, 1);
                }
                else
                {
                    P = 1; UpdateColors();
                }
                MainGrid.Focus();
            };

            MainGrid.MouseUp += (object sender, System.Windows.Input.MouseButtonEventArgs e) =>
            {
                if (ClickPotential)
                {
                    ClickPotential = false;
                    OnClick?.Invoke();
                }
                if (GlobalSettings.Animations)
                {
                    Animators.Animate(
                        PToken,
                        (double p) => { P = p; UpdateColors(); },
                        PSpeed,
                        P, 0);
                }
                else
                {
                    P = 0; UpdateColors();
                }
            };
        }
Пример #2
0
        public Toggle(string Text = "", bool InitialValue = false)
        {
            this.Text     = Text;
            ToggleState   = InitialValue;
            ThumbPosition = ToggleState ? 1 : 0;

            MainGrid.Background = BGBrush;
            MainGrid.Focusable  = true;

            Label.HorizontalAlignment        = HorizontalAlignment.Stretch;
            Label.VerticalAlignment          = VerticalAlignment.Stretch;
            Label.HorizontalContentAlignment = HorizontalAlignment.Center;
            Label.VerticalContentAlignment   = VerticalAlignment.Center;
            Label.Foreground = FGBrush;

            MainGrid.Children.Add(Label);

            ThumbHolderGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            ThumbHolderGrid.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;

            MainGrid.Children.Add(ThumbHolderGrid);

            ThumbGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            ThumbGrid.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;

            ThumbGrid.Background = FGBrush;

            ThumbHolderGrid.Children.Add(ThumbGrid);

            UpdatePosition();
            UpdateSize();
            UpdateColors();

            MainGrid.SizeChanged += (object sender, System.Windows.SizeChangedEventArgs e) =>
            {
                UpdatePosition();
                UpdateSize();
                if (MainGrid.ActualHeight > 1)
                {
                    Label.FontSize = MainGrid.ActualHeight * 0.4;
                }
            };

            MainGrid.MouseMove += (object sender, System.Windows.Input.MouseEventArgs e) =>
            {
                Point pos = e.MouseDevice.GetPosition(MainGrid);
                pos.X /= MainGrid.ActualWidth / 2;
                pos.Y /= MainGrid.ActualHeight / 2;
                pos.X -= 1;
                pos.Y -= 1;

                pos.X *= pos.X;
                pos.Y *= pos.Y;

                pos.X = 1 - pos.X;
                pos.Y = 1 - pos.Y;

                if (GlobalSettings.Animations)
                {
                    Animators.Tail(
                        ShrinkToken,
                        (double x) => { ThumbShrinkage = x; UpdateSize(); },
                        ThumbShrinkage,
                        1 - pos.X * pos.Y
                        );
                }
                else
                {
                    ThumbShrinkage = 1 - pos.X * pos.Y;
                    UpdateSize();
                }
            };

            MainGrid.MouseLeave += (object sender, System.Windows.Input.MouseEventArgs e) =>
            {
                ClickPotential = false;
                if (GlobalSettings.Animations)
                {
                    Animators.Tail(
                        ShrinkToken,
                        (double x) => { ThumbShrinkage = x; UpdateSize(); },
                        ThumbShrinkage,
                        1
                        );
                }
                else
                {
                    ThumbShrinkage = 1;
                    UpdateSize();
                }
            };

            MainGrid.MouseDown += (object sender, System.Windows.Input.MouseButtonEventArgs e) =>
            {
                ClickPotential = true;
                MainGrid.Focus();
            };

            MainGrid.MouseUp += (object sender, System.Windows.Input.MouseButtonEventArgs e) =>
            {
                if (ClickPotential)
                {
                    ClickPotential = false;
                    Value          = !Value;
                }
            };
        }