public override BitmapBase Draw(Tank tank) { var outline = new Pen(new SolidColorBrush(Colors.Black), 1); var outlineInner = new Pen(new SolidColorBrush(Color.FromArgb(50, 255, 255, 255)), 1); var hsv = ColorHSV.FromColor(BackColor.GetColorWpf(tank)); var brush = new LinearGradientBrush { GradientStops = new GradientStopCollection { new GradientStop(hsv.ToColorWpf(), 0.1), new GradientStop(hsv.ScaleValue(0.56).ToColorWpf(), 0.49), new GradientStop(hsv.ScaleValue(0.39).ToColorWpf(), 0.51), new GradientStop(hsv.ScaleValue(0.56).ToColorWpf(), 0.9), }, StartPoint = new Point(0, 0), EndPoint = new Point(0, 1), }; return(Ut.NewBitmapWpf(ParentStyle.IconWidth, ParentStyle.IconHeight, dc => { dc.DrawRectangle(brush, outline, new Rect(0.5, 1.5, ParentStyle.IconWidth - 1, ParentStyle.IconHeight - 3)); dc.DrawRectangle(null, outlineInner, new Rect(1.5, 2.5, ParentStyle.IconWidth - 3, ParentStyle.IconHeight - 5)); }).ToBitmapRam()); }
public override BitmapBase Apply(RenderTask renderTask, BitmapBase layer) { Tank tank = renderTask.Tank; var color = ColorHSV.FromColor(Color.GetColorWpf(tank)); layer.Colorize(color.Hue, color.Saturation / 100.0, color.Value / 100.0 - 0.5, color.Alpha / 255.0); return(layer); }
public void TestHSV2RGBConversion() { Assert.Equal(Color.Black.ToColor4(), ColorHSV.FromColor(Color.Black).ToColor()); Assert.Equal(Color.White.ToColor4(), ColorHSV.FromColor(Color.White).ToColor()); Assert.Equal(Color.Red.ToColor4(), ColorHSV.FromColor(Color.Red).ToColor()); Assert.Equal(Color.Lime.ToColor4(), ColorHSV.FromColor(Color.Lime).ToColor()); Assert.Equal(Color.Blue.ToColor4(), ColorHSV.FromColor(Color.Blue).ToColor()); Assert.Equal(Color.Silver.ToColor4(), ColorHSV.FromColor(Color.Silver).ToColor()); Assert.Equal(Color.Maroon.ToColor4(), ColorHSV.FromColor(Color.Maroon).ToColor()); Assert.Equal(new Color(184, 209, 219, 255).ToRgba(), ColorHSV.FromColor(new Color(184, 209, 219, 255)).ToColor().ToRgba()); }
public void TestRGB2HSVConversion() { Assert.Equal(new ColorHSV(312, 1, 1, 1), ColorHSV.FromColor(new Color4(1, 0, 0.8f, 1))); Assert.Equal(new ColorHSV(0, 0, 0, 1), ColorHSV.FromColor(Color.Black)); Assert.Equal(new ColorHSV(0, 0, 1, 1), ColorHSV.FromColor(Color.White)); Assert.Equal(new ColorHSV(0, 1, 1, 1), ColorHSV.FromColor(Color.Red)); Assert.Equal(new ColorHSV(120, 1, 1, 1), ColorHSV.FromColor(Color.Lime)); Assert.Equal(new ColorHSV(240, 1, 1, 1), ColorHSV.FromColor(Color.Blue)); Assert.Equal(new ColorHSV(60, 1, 1, 1), ColorHSV.FromColor(Color.Yellow)); Assert.Equal(new ColorHSV(180, 1, 1, 1), ColorHSV.FromColor(Color.Cyan)); Assert.Equal(new ColorHSV(300, 1, 1, 1), ColorHSV.FromColor(Color.Magenta)); Assert.Equal(new ColorHSV(0, 0, 0.7529412f, 1), ColorHSV.FromColor(Color.Silver)); Assert.Equal(new ColorHSV(0, 0, 0.5019608f, 1), ColorHSV.FromColor(Color.Gray)); Assert.Equal(new ColorHSV(0, 1, 0.5019608f, 1), ColorHSV.FromColor(Color.Maroon)); }
/// <summary> /// Raised when the <see cref="Red"/>, <see cref="Green"/>, <see cref="Blue"/> or <see cref="Alpha"/> properties are modified. /// </summary> /// <param name="e">The dependency property that has changed.</param> private void OnRGBAValueChanged(DependencyPropertyChangedEventArgs e) { bool isInitializing = !templateApplied && initializingProperty == null; if (isInitializing) { initializingProperty = e.Property; } if (!interlock) { Color4 colorRGBA; if (e.Property == RedProperty) { colorRGBA = new Color4((byte)e.NewValue / 255.0f, Green / 255.0f, Blue / 255.0f, Alpha / 255.0f); } else if (e.Property == GreenProperty) { colorRGBA = new Color4(Red / 255.0f, (byte)e.NewValue / 255.0f, Blue / 255.0f, Alpha / 255.0f); } else if (e.Property == BlueProperty) { colorRGBA = new Color4(Red / 255.0f, Green / 255.0f, (byte)e.NewValue / 255.0f, Alpha / 255.0f); } else if (e.Property == AlphaProperty) { colorRGBA = new Color4(Red / 255.0f, Green / 255.0f, Blue / 255.0f, (byte)e.NewValue / 255.0f); } else { throw new ArgumentException("Property unsupported by method OnRGBAValueChanged."); } interlock = true; InternalColor = ColorHSV.FromColor(colorRGBA); SetCurrentValue(HueProperty, InternalColor.H); SetCurrentValue(SaturationProperty, InternalColor.S * 100.0f); SetCurrentValue(BrightnessProperty, InternalColor.V * 100.0f); interlock = false; } UpdateBinding(e.Property); if (isInitializing) { initializingProperty = null; } }
/// <summary> /// Raised when the <see cref="Color"/> property is modified. /// </summary> private void OnColorChanged() { bool isInitializing = !templateApplied && initializingProperty == null; if (isInitializing) { initializingProperty = ColorProperty; } if (!interlock) { InternalColor = ColorHSV.FromColor(Color); var colorRGBA = InternalColor.ToColor(); interlock = true; SetCurrentValue(RedProperty, (byte)(Math.Round(colorRGBA.R * 255.0f))); SetCurrentValue(GreenProperty, (byte)(Math.Round(colorRGBA.G * 255.0f))); SetCurrentValue(BlueProperty, (byte)(Math.Round(colorRGBA.B * 255.0f))); SetCurrentValue(AlphaProperty, (byte)(Math.Round(colorRGBA.A * 255.0f))); SetCurrentValue(HueProperty, InternalColor.H); SetCurrentValue(SaturationProperty, InternalColor.S * 100.0f); SetCurrentValue(BrightnessProperty, InternalColor.V * 100.0f); interlock = false; } if (!suspendBindingUpdates) { RenderColorPickerSurface(); } else if (colorPreviewRenderSurface != null) { colorPreviewRenderSurface.Fill = new SolidColorBrush(Color.ToSystemColor()); } UpdateBinding(ColorProperty); if (isInitializing) { initializingProperty = null; } }