private void EhUserRequest_ForAllSelectedItemSetOpacity(double opacity) { var alphaValue = AxoColor.NormFloatToByte((float)opacity); bool anyChange = false; foreach (var item in _currentItems.Where(node => node.IsSelected)) { var color = ((NamedColor)item.Tag).Color; if (color.A != alphaValue) { color.A = alphaValue; var ncolor = new NamedColor(color); item.Tag = ncolor; item.Text = ToDisplayName(ncolor); anyChange = true; } } if (anyChange) { SetListDirty(); } }
private void EhUserRequest_ForAllSelectedItemShiftHue(double hueShift) { if (0 == hueShift || -1 == hueShift || 1 == hueShift) { return; } bool anyChange = false; foreach (var item in _currentItems.Where(node => node.IsSelected)) { var color = ((NamedColor)item.Tag).Color; var(a, h, s, b) = color.ToAhsb(); h += (float)hueShift; h -= (float)Math.Floor(h); // Normalize hue to 0..1 color = AxoColor.FromAhsb(a, h, s, b); var ncolor = new NamedColor(color); item.Tag = ncolor; item.Text = ToDisplayName(ncolor); anyChange = true; } if (anyChange) { SetListDirty(); } }
private void EhUserRequest_ForAllSelectedItemSetBrightness(double brightness) { bool anyChange = false; foreach (var item in _currentItems.Where(node => node.IsSelected)) { var color = ((NamedColor)item.Tag).Color; var(a, h, s, b) = color.ToAhsb(); if (b != brightness) { b = (float)brightness; color = AxoColor.FromAhsb(a, h, s, b); var ncolor = new NamedColor(color); item.Tag = ncolor; item.Text = ToDisplayName(ncolor); anyChange = true; } } if (anyChange) { SetListDirty(); } }
public string[] GetComponentsForColor(AxoColor color, IFormatProvider formatProvider) { return(new string[] { (1 - color.ScR).ToString("F3", formatProvider), (1 - color.ScG).ToString("F3", formatProvider), (1 - color.ScB).ToString("F3", formatProvider) }); }
public static ImageSource GetImageSourceFromAxoColor(AxoColor axoColor, int width, int height) { var innerRect = new Rect(0, 0, width, height); var geometryDrawing = new GeometryDrawing() { Geometry = new RectangleGeometry(innerRect) }; geometryDrawing.Brush = new SolidColorBrush(GuiHelper.ToWpf(axoColor)); DrawingImage geometryImage = new DrawingImage(geometryDrawing); geometryImage.Freeze(); // Freeze the DrawingImage for performance benefits. return geometryImage; }
public string[] GetComponentsForColor(AxoColor color, IFormatProvider formatProvider) { var(a, h, s, b) = color.ToAhsb(); return(new string[] { h.ToString("F3", formatProvider), s.ToString("F3", formatProvider), b.ToString("F3", formatProvider) }); }
/// <summary> /// Get the index of the given color in the ColorSet. /// </summary> /// <param name="color">The color.</param> /// <returns>The index of the color in the set. If the color is not found in the set, a negative value is returned.</returns> public virtual int IndexOf(AxoColor color) { if (_colorToIndexDictionary.Value.TryGetValue(color, out var idx)) { return(idx); } else { return(-1); } }
public void AmendAlphaComponent(ref AxoColor color) { if (_colorModel.IsUsingByteComponents) { color.A = (byte)_guiAlphaValue.Value; } else { color.ScA = (float)_guiAlphaValue.Value; } }
public object BuildItem(BuildItemArgs args) { string id = args.Codon.Id; string value = args.Codon.Properties["Value"]; if (!string.IsNullOrEmpty(value)) { var c = AxoColor.FromInvariantString(value); return(new NamedColor(c, id)); } return(null); }
public string[] GetComponentsForColor(AxoColor color, IFormatProvider formatProvider) { var(a, c, m, y, k) = color.ToAcmyk(); return(new string[] { c.ToString("F3", formatProvider), m.ToString("F3", formatProvider), y.ToString("F3", formatProvider), k.ToString("F3", formatProvider) }); }
public static BitmapSource GetBitmap() { const int widthheight = 256; const float innerRadiusRatio2 = 0.25f; float mid = (widthheight - 1) / 2f; float r2max = mid * mid; float r2min = r2max * innerRadiusRatio2; var wbitmap = new WriteableBitmap(widthheight, widthheight, 96, 96, PixelFormats.Bgra32, null); byte[] pixels = new byte[widthheight * widthheight * 4]; // The bitmap is already by default transparent for (int row = 0; row < widthheight; ++row) { for (int col = 0; col < widthheight; ++col) { var dx = col - mid; var dy = row - mid; var r2 = dx * dx + dy * dy; if (r2 < r2min || r2 > r2max) { continue; } int idx = (row * widthheight + col) * 4; // calculate angle var phi = (Math.Atan2(dy, dx) / (2 * Math.PI)); if (phi < 0) { phi += 1; } // calculate color AxoColor.FromHue((float)phi, out var red, out var green, out var blue); pixels[idx + 0] = blue; // B pixels[idx + 1] = green; // G pixels[idx + 2] = red; // R pixels[idx + 3] = 255; // A } } // Update writeable bitmap with the colorArray to the image. var rect = new Int32Rect(0, 0, widthheight, widthheight); int stride = 4 * widthheight; wbitmap.WritePixels(rect, pixels, stride, 0); return(wbitmap); }
/// <summary> /// Tries to find a color with the color and the name of the given named color. /// </summary> /// <param name="colorValue">The color value to find.</param> /// <param name="colorName">The color name to find.</param> /// <param name="namedColor">On return, if a color with the same color value and name is found in the collection, that color is returned.</param> /// <returns> /// <c>True</c>, if the color with the given color value and name is found in this collection. Otherwise, <c>false</c> is returned. /// </returns> public bool TryGetValue(AxoColor colorValue, string colorName, out NamedColor namedColor) { if (_namecolorToIndexDictionary.Value.TryGetValue(new ColorNameKey(colorValue, colorName), out var idx)) { namedColor = _innerList[idx]; return(true); } else { namedColor = default(NamedColor); return(false); } }
public static ImageSource GetImageSourceFromAxoColor(AxoColor axoColor, int width, int height) { var innerRect = new Rect(0, 0, width, height); var geometryDrawing = new GeometryDrawing() { Geometry = new RectangleGeometry(innerRect) }; geometryDrawing.Brush = new SolidColorBrush(GuiHelper.ToWpf(axoColor)); var geometryImage = new DrawingImage(geometryDrawing); geometryImage.Freeze(); // Freeze the DrawingImage for performance benefits. return(geometryImage); }
private void EhOpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (_notUserInitiated) { return; } var c = _newColor; float a = (float)e.NewValue; _newColor = AxoColor.FromScRgb(a, c.ScR, c.ScG, c.ScB); UpdateControlVisuals(); CurrentColorChanged?.Invoke(_newColor); }
public void GetColorVariations(AxoColor baseColor, AxoColor[] variations) { var(alpha, hue, saturation, brightness) = baseColor.ToAhsb(); // make darker, but still the last item should have a rest of color left (i.e. it should not be completely black) int numberOfItems = variations.Length; variations[0] = baseColor; for (int i = 1; i < numberOfItems; ++i) { var newBrightness = brightness * (1 - i / (float)numberOfItems); variations[i] = AxoColor.FromAhsb(alpha, hue, saturation, newBrightness); } }
public void GetColorVariations(AxoColor baseColor, AxoColor[] variations) { var(alpha, hue, saturation, brightness) = baseColor.ToAhsb(); // desaturate, but still the last item should have a rest of saturation left int numberOfItems = variations.Length; variations[0] = baseColor; for (int i = 1; i < numberOfItems; ++i) { var newSaturation = saturation * (1 - i / (float)numberOfItems); variations[i] = AxoColor.FromAhsb(alpha, hue, newSaturation, brightness); } }
public NamedColor GetDeserializedColorWithNoSet(AxoColor color, string name) { // test if it is a standard color if (_builtinKnownColors.TryGetValue(name, out var foundColor) && color.Equals(foundColor.Color)) // if the color is known by this name, and the color value matches { return(foundColor); // then return this found color } if (_builtinKnownColors.TryGetValue(color, out foundColor)) // if only the color value matches, then return the found color, even if it has another name than the deserialized color { return(foundColor); } // Note that name for a deserialized color can be null or empty. If this is the case, use the constructor without name return(string.IsNullOrEmpty(name) ? new NamedColor(color) : new NamedColor(color, name)); // if it is not a known color, then return the color without a color set as parent }
private ColorSet(Altaxo.Serialization.Xml.IXmlDeserializationInfo info) { _name = info.GetString("Name"); int count = info.OpenArray("Colors"); _innerList = new NamedColor[count]; for (int i = 0; i < count; ++i) { string name = info.GetStringAttribute("Name"); string cvalue = info.GetString("e"); _innerList[i] = new NamedColor(AxoColor.FromInvariantString(cvalue), name, this); } info.CloseArray(count); InitLazyVariables(); }
public void GetColorVariations(AxoColor baseColor, AxoColor[] variations) { var blue = baseColor.ScB; var red = baseColor.ScR; // make warmer = more red int numberOfItems = variations.Length; variations[0] = baseColor; for (int i = 1; i < numberOfItems; ++i) { var newBlue = (blue + (1 - blue) * (i / (float)numberOfItems)); var newRed = (red * (1 - i / (float)numberOfItems)); variations[i] = AxoColor.FromScRgb(baseColor.ScA, newRed, baseColor.ScG, newBlue); } }
public void ChangeCurrentColor(AxoColor newColor, bool updateCircle, bool updateVariations, bool updateComponents, bool updateAltComponents) { _currentColor = newColor; if (updateCircle) { _guiColorCircleSurface.SetHueBaseValue(_currentColor.GetHue(), false); } if (updateComponents) { // now calculate components var components = _colorModel.GetComponentsForColor(_currentColor); UpdateComponentValues(() => { for (int i = 0; i < components.Length; ++i) { _guiComponents[i].Value = (decimal)components[i]; } if (_colorModel.IsUsingByteComponents) { _guiAlphaValue.Value = _currentColor.A; } else { _guiAlphaValue.Value = (decimal)_currentColor.ScA; } } ); } if (updateAltComponents) { // update alternative components var altComponents = _altColorModel.GetComponentsForColor(_currentColor, Altaxo.Settings.GuiCulture.Instance); for (int i = 0; i < altComponents.Length; ++i) { _guiAltComponents[i].Text = altComponents[i]; } } CurrentColorChanged?.Invoke(_currentColor); }
public void ChangeCurrentColor(AxoColor newColor, bool update1D, bool update2D, bool updateComponents, bool updateAltComponents) { _currentColor = newColor; if (update1D || update2D) { var(pos1D, pos2D) = _colorModel.GetRelativePositionsFor1Dand2DColorSurfaceFromColor(_currentColor); _gui1DColorControl.SelectionRectangleRelativePositionChanged -= Eh1DColorControl_ValueChanged; _gui2DColorControl.SelectionRectangleRelativePositionChanged -= Eh2DColorControl_ValueChanged; _gui1DColorControl.SelectionRectangleRelativePosition = pos1D; _gui2DColorControl.SelectionRectangleRelativePosition = pos2D; _gui1DColorControl.SelectionRectangleRelativePositionChanged += Eh1DColorControl_ValueChanged; _gui2DColorControl.SelectionRectangleRelativePositionChanged += Eh2DColorControl_ValueChanged; } if (updateComponents) { // now calculate components var components = _colorModel.GetComponentsForColor(_currentColor); UpdateComponentValues(() => { for (int i = 0; i < components.Length; ++i) { _guiComponents[i].Value = (decimal)components[i]; } } ); } if (updateAltComponents) { // update alternative components var altComponents = _altColorModel.GetComponentsForColor(_currentColor, Altaxo.Settings.GuiCulture.Instance); for (int i = 0; i < altComponents.Length; ++i) { _guiAltComponents[i].Text = altComponents[i]; } } CurrentColorChanged?.Invoke(_currentColor); }
public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent) { string colorSetName = info.GetString("Name"); var colorSetLevel = (Altaxo.Main.ItemDefinitionLevel)info.GetEnum("Level", typeof(Altaxo.Main.ItemDefinitionLevel)); var creationDate = info.GetDateTime("CreationDate"); var isPlotColorSet = info.GetBoolean("IsPlotColorSet"); int count = info.OpenArray("Colors"); var colors = new NamedColor[count]; for (int i = 0; i < count; ++i) { string name = info.GetStringAttribute("Name"); string cvalue = info.GetString("e"); colors[i] = new NamedColor(AxoColor.FromInvariantString(cvalue), name); } info.CloseArray(count); return(new ColorSet(colorSetName, colors)); }
private void EhBrightnessSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (_notUserInitiated) { return; } Color nc = colorComb.SelectedColor; float f = (float)e.NewValue; float a, r, g, b; a = (float)opacitySlider.Value; r = f * nc.ScR; g = f * nc.ScG; b = f * nc.ScB; _newColor = AxoColor.FromScRgb(a, r, g, b); UpdateControlVisuals(); CurrentColorChanged?.Invoke(_newColor); }
// // Event Handlers private void EhColorCombControl_ColorSelected(object sender, ColorEventArgs e) { if (_notUserInitiated) { return; } float a, f, r, g, b; a = (float)opacitySlider.Value; f = (float)brightnessSlider.Value; Color nc = e.Color; r = f * nc.ScR; g = f * nc.ScG; b = f * nc.ScB; _newColor = AxoColor.FromScRgb(a, r, g, b); UpdateControlVisuals(); CurrentColorChanged?.Invoke(_newColor); }
public bool TryFindColorSetContaining(AxoColor colorValue, string colorName, out IColorSet value) { foreach (Main.ItemDefinitionLevel level in Enum.GetValues(typeof(Main.ItemDefinitionLevel))) { foreach (var entry in _allLists) { if (entry.Value.Level != level) { continue; } if (entry.Value.List.TryGetValue(colorValue, colorName, out var namedColor)) { value = entry.Value.List; return(true); } } } value = null; return(false); }
public ColorPickerControl(AxoColor oldColor) { _oldColor = oldColor; _newColor = _oldColor; InitializeComponent(); }
/// <summary> /// Get the index of the given color in the ColorSet. /// </summary> /// <param name="color">The color.</param> /// <returns>The index of the color in the set. If the color is not found in the set, a negative value is returned.</returns> public virtual int IndexOf(AxoColor color) { int idx; if (_colorToIndexDictionary.Value.TryGetValue(color, out idx)) { return idx; } else { return -1; } }
/// <summary> /// Tries to find a color with the color and the name of the given named color. /// </summary> /// <param name="colorValue">The color value to find.</param> /// <param name="colorName">The color name to find.</param> /// <param name="namedColor">On return, if a color with the same color value and name is found in the collection, that color is returned.</param> /// <returns> /// <c>True</c>, if the color with the given color value and name is found in this collection. Otherwise, <c>false</c> is returned. /// </returns> public bool TryGetValue(AxoColor colorValue, string colorName, out NamedColor namedColor) { int idx; if (_namecolorToIndexDictionary.Value.TryGetValue(new ColorNameKey(colorValue, colorName), out idx)) { namedColor = this._innerList[idx]; return true; } else { namedColor = default(NamedColor); return false; } }
public AxoColor GetColorFromComponents(double[] components) { return(AxoColor.FromArgb(255, (byte)(255 - components[0]), (byte)(255 - components[1]), (byte)(255 - components[2]))); }
public double[] GetComponentsForColor(AxoColor color) { return(new double[] { 255 - color.R, 255 - color.G, 255 - color.B }); }
public (double position1D, PointD2D position2D) GetRelativePositionsFor1Dand2DColorSurfaceFromColor(AxoColor color) { var(alpha, hue, saturation, brightness) = color.ToAhsb(); return(hue, new PointD2D(saturation, brightness)); }
public AxoColor GetColorFor2DColorSurfaceFromRelativePosition(PointD2D relativePosition, AxoColor c) { return(AxoColor.FromAhsb(1, c.GetHue(), (float)(relativePosition.X), (float)(relativePosition.Y))); }
public AxoColor GetColorFor1DColorSurfaceFromRelativePosition(double relativePosition) { return(AxoColor.FromAhsb(1, (float)(relativePosition), 1, 1)); }
public void SetSceneBackColor(AxoColor? sceneBackColor) { _sceneBackgroundColor = sceneBackColor; }