Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnAlphaChanged(object sender, EventArgs <byte> e)
 {
     SetValue(ColorProperty, Color.WithAlpha(e.Value));
     ColorChanged?.Invoke(this, new EventArgs <Color>(Color));
     Alpha = e.Value;
     AlphaChanged?.Invoke(this, new EventArgs <byte>(Alpha));
 }
Пример #2
0
 private void OnColorChange()
 {
     if(ColorChanged != null)
     {
         ColorChanged.Invoke();
     }
 }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="OldValue"></param>
        /// <param name="NewValue"></param>
        protected virtual void OnColorChanged(Color OldValue, Color NewValue)
        {
            if (OldValue != NewValue)
            {
                if (SelectedComponent != null)
                {
                    if (ColorChangeSource == ColorChangeSourceType.ColorPropertySet)
                    {
                        UpdatePlane(SelectedComponent.GetValue(NewValue).Round().ToInt32());

                        SelectionPoint       = SelectedComponent.PointFromColor(NewValue);
                        SelectionTransform.X = SelectionPoint.X - (SelectionPane.PixelWidth / 2.0);
                        SelectionTransform.Y = SelectionPoint.Y - (SelectionPane.PixelHeight / 2.0);

                        PART_Slider.Value = SelectedComponent.GetValue(NewValue);

                        if (!SelectedComponent.IsUniform)
                        {
                            SelectedComponent.UpdateSlider(NormalPane, NewValue);
                        }
                    }
                    if (SelectionRing == ColorSelectorRing.BlackOrWhite)
                    {
                        AdjustRing(NewValue);
                    }
                }
                PART_AlphaSlider.Alpha = NewValue.A;

                ColorChanged?.Invoke(this, new EventArgs <Color>(NewValue));
            }
        }
Пример #4
0
 private void cs2_ColorChanged(ColorPicker sender, ColorChangedEventArgs args)
 {
     ColorChanged?.Invoke(new SolidColorBrush(Color.FromArgb(args.NewColor.A, args.NewColor.R, args.NewColor.G, args.NewColor.B)), new ColorPickerEventArgs()
     {
         ColorType = (string)rcb.Value2
     });
 }
Пример #5
0
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            int value;
            var format = (mode == EnumMode.Dec) ? NumberStyles.Integer : NumberStyles.HexNumber;

            isValid = int.TryParse(Text, format, CultureInfo.CurrentCulture, out value);
            if (isValid)
            {
                if (value < 0)
                {
                    value = 0;
                }
                if (value > 255)
                {
                    value = 255;
                }
                colorValue = (byte)value;
                ColorChanged?.Invoke(colorValue);
            }

            if (!isValid)
            {
                ForeColor = Color.Red;
            }
            else
            {
                ForeColor = Color.Black;
            }
        }
Пример #6
0
        private void UpdateControls(Color color)
        {
            // What in the F**K

            TextBoxNumeric redBox = FindChildByName("RedBox", false) as TextBoxNumeric;

            if (redBox != null)
            {
                redBox.SetText(color.R.ToString(), false);
            }

            TextBoxNumeric greenBox = FindChildByName("GreenBox", false) as TextBoxNumeric;

            if (greenBox != null)
            {
                greenBox.SetText(color.G.ToString(), false);
            }

            TextBoxNumeric blueBox = FindChildByName("BlueBox", false) as TextBoxNumeric;

            if (blueBox != null)
            {
                blueBox.SetText(color.B.ToString(), false);
            }

            m_After.Color = color;

            if (ColorChanged != null)
            {
                ColorChanged.Invoke(this);
            }
        }
        private void _slider_ValueChanged(object sender, EventArgs <float> e)
        {
            var value = e.Data;

            SetColorByValue(value);
            ColorChanged?.Invoke(this, new EventArgs <SKColor>(_slider.Color));
        }
Пример #8
0
        /// <summary>
        /// Reset specific .Net system color to default values defined by Windows theme
        /// </summary>
        public void ResetColor(KnownColor name)
        {
            _sysColors.Remove(name);

            ResetGdiCaches();
            ColorChanged?.Invoke();
        }
Пример #9
0
        private void ColorPalettePage_ItemClick(object sender, ItemClickEventArgs e)
        {
            var colorPaletteItem = e.ClickedItem as ColorPaletteItem;

            // The sender's GridView.SelectedIndex hasn't been updated yet,
            // so get the value through the clicked item.
            int selectedIndex = (sender as GridView).Items.IndexOf(colorPaletteItem);

            if ((sender as GridView).ItemsPanelRoot == null)
            {
                return;
            }

            if ((sender as GridView).ItemsPanelRoot.Children[selectedIndex]
                is GridViewItem clickedGridViewItem)
            {
                if (clickedGridViewItem != SelectedGrid)
                {
                    UpdateGridViewItemSelectionState(clickedGridViewItem);
                }

                if (colorPaletteItem.IsColorSet)
                {
                    ViewModel.SelectItem(colorPaletteItem);
                    ColorChanged?.Invoke(this,
                                         new PaletteColorChangedEventArgs {
                        NewColor = colorPaletteItem.ColorBrush.Color
                    });
                }
                else
                {
                    SelectAndOpenColorPicker(clickedGridViewItem.ContentTemplateRoot as Grid);
                }
            }
        }
Пример #10
0
        private void UpdateColorByHsvValues()
        {
            var color = Color.HSVToRGB(_hValue, _sValue, _vValue);

            if (_colorPreview != null)
            {
                _colorPreview.color = color;
            }
            if (_colorCodeFierd != null)
            {
                _colorCodeFierd.text = ColorToHex(color);
            }
            if (_sSliderBackground != null)
            {
                _sSliderBackground.material.SetFloat(_vShaderId, _vValue);
            }
            if (_vSliderBackground != null)
            {
                _vSliderBackground.material.SetFloat(_sShaderId, _sValue);
            }
            CurrentColor = color;
            if (ColorChanged != null)
            {
                ColorChanged.Invoke(color);
            }
        }
Пример #11
0
        /// <summary>
        /// Handler invoked on mouse moved event.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        /// <param name="dx">X change.</param>
        /// <param name="dy">Y change.</param>
        protected override void onMouseMoved(int x, int y, int dx, int dy)
        {
            if (depressed)
            {
                cursorPos = CanvasPosToLocal(new Point(x, y));
                //Do we have clamp?
                if (cursorPos.X < 0)
                {
                    cursorPos.X = 0;
                }
                if (cursorPos.X > Width)
                {
                    cursorPos.X = Width;
                }

                if (cursorPos.Y < 0)
                {
                    cursorPos.Y = 0;
                }
                if (cursorPos.Y > Height)
                {
                    cursorPos.Y = Height;
                }

                if (ColorChanged != null)
                {
                    ColorChanged.Invoke(this, EventArgs.Empty);
                }
            }
        }
        private async void OnTouchEffectAction(object sender, TouchActionEventArgs args)
        {
            if (args.Type == TouchActionType.Released)
            {
                var pnt = args.Location.ToPixelSKPoint(canvasView);

                // loop through all colors
                foreach (var cp in ColorPicks)
                {
                    // check if selecting a color
                    if (cp.IsTouched(pnt))
                    {
                        _colorChanged = true;
                        _pickedColor  = cp;
                        break; // get out of loop
                    }
                }

                canvasView.InvalidateSurface();

                if (_colorChanged)
                {
                    ColorChanged?.Invoke(this, new ColorChangedEventArgs(_pickedColor.Color));
                    _colorChanged = false;
                    await Navigation.PopPopupAsync();
                }
            }
        }
Пример #13
0
 private void cs_ColorChanged(object sender, EventArgs e)
 {
     ColorChanged?.Invoke(sender, new ColorPickerEventArgs()
     {
         ColorType = (string)rcb.Value2
     });
 }
Пример #14
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            //if (e.X < 0 || e.X > Width ||
            //e.Y < 0 || e.Y > Height)
            //return;

            _mousex = e.X / _zoom;
            _mousey = e.Y / _zoom;

            if (e.Button == MouseButtons.Left)
            {
                _mousebtn = true;

                Graphics g = Graphics.FromImage(_canvas);
                g.DrawImage(_brushbmp, (float)_mousex, (float)_mousey);

                Invalidate(new Rectangle((int)(_mousex * _zoom), (int)(_mousey * _zoom),
                                         (int)(_pencilwidth * _zoom), (int)(_pencilwidth * _zoom)));
            }
            else if (e.Button == MouseButtons.Right)
            {
                PencilColor = _canvas.GetPixel((int)_mousex, (int)_mousey);

                ColorChanged?.Invoke();
            }

            _oldmousex = _mousex;
            _oldmousey = _mousey;
        }
Пример #15
0
        private int EventNotificationCallback(int message, IntPtr data)
        {
            if (message == 1)
            {
                if (data != IntPtr.Zero)
                {
                    Color[] colors    = new Color[maxColors];
                    int[]   colorData = new int[maxColors];

                    Marshal.Copy(data, colorData, 0, maxColors);

                    for (int i = 0; i < colorData.Length; i++)
                    {
                        int r = (byte)((colorData[i] >> 0) & 0xff);
                        int g = (byte)((colorData[i] >> 8) & 0xff);
                        int b = (byte)((colorData[i] >> 16) & 0xff);

                        colors[i] = Color.FromArgb(r, g, b);
                    }

                    ColorChanged?.Invoke(this, new RzChromaBroadcastColorChangedEventArgs(colors));
                }
            }
            else if (message == 2)
            {
                ConnectionChanged?.Invoke(this, new RzChromaBroadcastConnectionChangedEventArgs(data.ToInt32() == 1));
            }

            return(0);
        }
        private void OnColorChanged <T>(AvaloniaPropertyChangedEventArgs <T> args)
        {
            // If we're in the process of internally updating the color, then we don't want to respond to the Color property changing,
            // aside from raising the ColorChanged event.
            if (!m_updatingColor)
            {
                var color = Color;

                m_currentRgb   = new Rgb(color.R / 255.0, color.G / 255.0, color.B / 255.0);
                m_currentAlpha = color.A / 255.0;
                m_currentHsv   = ColorConversion.RgbToHsv(m_currentRgb);
                m_currentHex   = GetCurrentHexValue();

                UpdateColorControls(ColorUpdateReason.ColorPropertyChanged);
            }

            var oldColor = args.OldValue.GetValueOrDefault <Color>();
            var newColor = args.NewValue.GetValueOrDefault <Color>();

            if (oldColor.A != newColor.A ||
                oldColor.R != newColor.R ||
                oldColor.G != newColor.G ||
                oldColor.B != newColor.B)
            {
                var colorChangedEventArgs = new ColorChangedEventArgs(oldColor, newColor);
                ColorChanged?.Invoke(this, colorChangedEventArgs);
            }
        }
Пример #17
0
        private void OnColorChanged(Color newValue, Color oldValue)
        {
            if (newValue == oldValue && _loaded)
            {
                return;
            }

            ColorChanged?.Invoke(this, new ColorChangedEventArgs(newValue, oldValue));

            if (newValue == _current && _loaded)
            {
                return;
            }

            var rgb = (RGB)newValue;
            var hsv = rgb.ToHSV();


            _current = newValue;
            _color   = new HSV(hsv.H, hsv.S, 1);
            _value   = hsv.V;

            if (Spectrum != null && ValueSlider != null)
            {
                _loaded = true;

                UpdateSpectrumPointer(new Point(hsv.H / 360 * Spectrum.ActualWidth, (1 - hsv.S) * Spectrum.ActualHeight), false);
                ValueSlider.Value = hsv.V * 100;
            }
        }
Пример #18
0
        /// <summary>
        /// Handler invoked on mouse moved event.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        /// <param name="dx">X change.</param>
        /// <param name="dy">Y change.</param>
        protected override void OnMouseMoved(int x, int y, int dx, int dy)
        {
            if (m_Depressed)
            {
                m_CursorPos = CanvasPosToLocal(new Vector2i(x, y));
                //Do we have clamp?
                if (m_CursorPos.X < 0)
                {
                    m_CursorPos.X = 0;
                }
                if (m_CursorPos.X > Width)
                {
                    m_CursorPos.X = Width;
                }

                if (m_CursorPos.Y < 0)
                {
                    m_CursorPos.Y = 0;
                }
                if (m_CursorPos.Y > Height)
                {
                    m_CursorPos.Y = Height;
                }

                if (ColorChanged != null)
                {
                    ColorChanged.Invoke(this);
                }
            }
        }
Пример #19
0
        private void BSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            RSlider.ValueChanged -= RSlider_ValueChanged;
            GSlider.ValueChanged -= GSlider_ValueChanged;

            HSlider.ValueChanged -= HSlider_ValueChanged;
            SSlider.ValueChanged -= SSlider_ValueChanged;
            LSlider.ValueChanged -= LSlider_ValueChanged;

            //事件
            color.B = (byte)e.NewValue;
            Color   = color;
            ColorChanged?.Invoke(Color.FromArgb(color.A, color.R, color.G, color.B), ColorBrush);
            FollowRGB(true, true, false);
            FollowHSL();
            FollowCopy();

            RSlider.ValueChanged += RSlider_ValueChanged;
            GSlider.ValueChanged += GSlider_ValueChanged;

            HSlider.ValueChanged += HSlider_ValueChanged;
            SSlider.ValueChanged += SSlider_ValueChanged;
            LSlider.ValueChanged += LSlider_ValueChanged;

            //  Copy
            色相变();
            饱和度变();
            亮度变();
        }
Пример #20
0
        private void updateControls(Color color)
        {
            // [???] TODO: Make this code safer.
            // [halfofastaple] This code SHOULD (in theory) never crash/not work as intended, but referencing children by their name is unsafe.
            //		Instead, a direct reference to their objects should be maintained. Worst case scenario, we grab the wrong "RedBox".

            TextBoxNumeric redBox = FindChildByName("RedBox", false) as TextBoxNumeric;

            if (redBox != null)
            {
                redBox.SetText(color.R.ToString(), false);
            }

            TextBoxNumeric greenBox = FindChildByName("GreenBox", false) as TextBoxNumeric;

            if (greenBox != null)
            {
                greenBox.SetText(color.G.ToString(), false);
            }

            TextBoxNumeric blueBox = FindChildByName("BlueBox", false) as TextBoxNumeric;

            if (blueBox != null)
            {
                blueBox.SetText(color.B.ToString(), false);
            }

            after.Color = color;

            if (ColorChanged != null)
            {
                ColorChanged.Invoke(this, EventArgs.Empty);
            }
        }
Пример #21
0
        //控件拖拽


        //《圆形》
        private void 圆拉扯(double 横, double 纵) //根据角度改变位置方法
        {
            //《原文》
            //double angle = Math.Atan2(y - 圆直径 / 2, x - 圆直径 / 2);  //计算点的所在Pi角度
            //double Degrees = angle * 180.0 / Math.PI;  //计算点的所在360角度
            //H= (Degrees + 450) % 360;  //偏转加取值

            //《精简》(看不懂就看上面的原文):计算360角度
            H = ((Math.Atan2(纵 - 圆直径 / 2, 横 - 圆直径 / 2) * 180.0 / Math.PI) + 450) % 360; //偏转加取值
            矩形赋色();                                                                     //一.《形形色色》:根据色相

            //计算X轴Y轴距离
            横 = (圆直径 - 圆边距) / 2 * Math.Sin(H / 180 * Math.PI);
            纵 = (圆直径 - 圆边距) / 2 * -Math.Cos(H / 180 * Math.PI);

            //改变位置
            圆指.Margin = new Thickness(圆直径 / 2 + 横 - 圆指.Width / 2, 圆直径 / 2 + 纵 - 圆指.Height / 2, 0, 0);



            var left = 矩指.Margin.Left - 10;

            if (left < 0)
            {
                S = 0;
            }
            else if (left > 矩边长 - 30)
            {
                S = 1;
            }
            else
            {
                S = (left + 矩指.Width / 2) / (double)矩边长;
            }

            var top = 矩指.Margin.Top - 10;

            if (top < 0)
            {
                L = 1;
            }
            else if (top > 矩边长 - 30)
            {
                L = 0;
            }
            else
            {
                L = 1.0d - ((top + 矩指.Height / 2) / (double)矩边长);
            }



            //HSL
            Hi                  = (int)H;
            HSlider.Value       = Hi;
            HNumberPicker.Value = Hi;
            Color               = Method.HSLtoRGB(Opacity, H, S, L);
            ColorChanged?.Invoke(Color, ColorBrush);
            FollowRGB(false, false, false);
        }
Пример #22
0
 private void lstPalette_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (lstPalette.SelectedIndex != -1)
     {
         ColorChanged?.Invoke(this, new ColorChangedEventArgs((Color)ColorConverter.ConvertFromString(((PColor)lstPalette.SelectedItem).Hex)));
     }
 }
Пример #23
0
        private void OnColorChangedProgramatically(object sender, PaletteColorChangedEventArgs e)
        {
            var flipViewItems = ColorPaletteFlipView.ItemsPanelRoot?.Children;

            if (flipViewItems != null)
            {
                foreach (FlipViewItem flipViewItem in flipViewItems)
                {
                    if ((flipViewItem.Content as ColorPalettePageViewModel) == ColorPaletteFlipView.SelectedItem)
                    {
                        if (!(flipViewItem.ContentTemplateRoot is GridView currentGridView))
                        {
                            continue;
                        }

                        int index = currentGridView.SelectedIndex;

                        if (!(currentGridView.ItemsPanelRoot?.Children[index] is GridViewItem item))
                        {
                            continue;
                        }

                        UpdateGridViewItemSelectionState(item);
                    }
                }
            }

            ColorChanged?.Invoke(this, e);
        }
Пример #24
0
 public static void DisConnectTrigger()
 {
     foreach (Delegate d in ColorChanged.GetInvocationList())
     {
         ColorChanged -= (EventHandler <EventArgs>)d;
     }
 }
Пример #25
0
        /// <summary>
        /// Reset current theme colors to default values.
        /// GitExtensions app-specific colors are reset to <see cref="AppColorDefaults"/>
        /// .Net system colors are reset to values defined by Windows theme
        /// </summary>
        public void ResetAllColors()
        {
            SysColors.ForEach(ResetColor);
            AppColors.ForEach(ResetInternal);

            ResetGdiCaches();
            ColorChanged?.Invoke();
        }
Пример #26
0
        private void ImgColors_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            _mouseDown = true;
            var pos = e.GetPosition(ImgColors);

            _currentColor = GetPixel((BitmapSource)ImgColors.Source, (int)pos.X, (int)pos.Y);
            ColorChanged?.Invoke(this, new ColorPickerEventArgs(_currentColor));
        }
Пример #27
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            Color = GetColorAtPoint(e.X, e.Y);

            base.OnMouseClick(e);

            ColorChanged?.Invoke(this, Color);
        }
Пример #28
0
        private void OnColorPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            var color = Color;

            Selection.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
            alpha.Value          = color.A;
            ColorChanged?.Invoke(this, EventArgs.Empty);
        }
 protected void RaiseColorChangeEvent(SimpleWireColors oldColor, SimpleWireColors newColor)
 {
     ColorChanged?.Invoke(this, new ColorChangeEventArgs()
     {
         OldColor = oldColor, NewColor = newColor
     });
     LastColor = newColor;
 }
Пример #30
0
 private void ColorPickerOkButton_OnClick(object sender, RoutedEventArgs e)
 {
     ViewModel.ColorPickerConfirm(ColorPicker.Color);
     ColorChanged?.Invoke(this, new PaletteColorChangedEventArgs {
         NewColor = ColorPicker.Color
     });
     ColorPickerFlyout.Hide();
 }