protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; HSLColor oHlc = HSLColor.FromColor(_bColor); float oLight = oHlc.Lightness; float height = this.Height / 22f; mCurrentIdx = _selectedIndex; for (int i = 0; i <= 20; i++) { bool c = false; bool fc = (mCurrentIdx < i && mCurrentIdx != -1); oHlc.Lightness = 1f - (i * 5f) / 100; // 오차범위 계산 if (_selectedIndex == -1 && Math.Abs(oLight - oHlc.Lightness) <= 0.025) { mCurrentIdx = i; c = true; } float dHeight = height * (fc ? 1f : 2f); float top = (i + (fc ? 1 : 0)) * height + dHeight / 2f; using (SolidBrush sb = new SolidBrush(c ? _bColor : oHlc.ToColor())) { using (Pen p = new Pen(sb, dHeight)) { g.DrawLine(p, new PointF(0, top), new PointF(this.Width, top)); } } } if (mCurrentIdx > -1) { float top = mCurrentIdx * height; oHlc.Lightness = 1f - (mCurrentIdx * 5f) / 100; using (SolidBrush sb = new SolidBrush(ColorUtils.Invert(oHlc.ToColor()))) { using (Pen p = new Pen(sb)) { g.DrawRectangle(p, new Rectangle(0, (int)top, this.Width - 1, (int)(height * 2f))); } } } base.OnPaint(e); }
private void UpdateSpectrumShapes() { List <(HSLColor hsl, int p)> ColorsAndPeaks = new List <(HSLColor hsl, int p)>(VolumeAndPitch.ColorsAndPeaks); HSLColor AverageColor = VolumeAndPitch.AverageColor; //If nothing is playing, then don't update if (AverageColor != new HSLColor(0, 0, 0) && ColorsAndPeaks.Count > 0) { for (int i = 0; i < BarCount; i++) { double barHeight = ColorsAndPeaks[i].hsl.Luminosity * spectrumCanvas.RenderSize.Height; ((Rectangle)spectrumCanvas.Children[i]).Margin = new Thickness((barWidth * i) + 1, (spectrumCanvas.RenderSize.Height - 1) - barHeight, 0, 0); ((Rectangle)spectrumCanvas.Children[i]).Height = barHeight; //Add white border to the peaks on the UI, to show what's being used in the color calculation. //Was originally for diagnostic, but it looks neat. if (ColorsAndPeaks[i].p > 0) { ((Rectangle)spectrumCanvas.Children[i]).StrokeThickness = 2; } else { ((Rectangle)spectrumCanvas.Children[i]).StrokeThickness = 0; } //Set color for the rectangles System.Drawing.Color RGB = new HSLColor((double)i / BarCount, 1, ColorsAndPeaks[i].hsl.Luminosity); ((Rectangle)spectrumCanvas.Children[i]).Fill = new SolidColorBrush(Color.FromRgb(RGB.R, RGB.G, RGB.B)); } //convert for solid brush Color AVG_RGB = Color.FromArgb(255, AverageColor.ToColor().R, AverageColor.ToColor().G, AverageColor.ToColor().B); spectrumCanvas.Background = new SolidColorBrush(Color.FromRgb(AVG_RGB.R, AVG_RGB.G, AVG_RGB.B)); //Display stats } else { for (int i = 0; i < BarCount; i++) { ((Rectangle)spectrumCanvas.Children[i]).Margin = new Thickness((barWidth * i) + 1, (spectrumCanvas.RenderSize.Height - 1), 0, 0); ((Rectangle)spectrumCanvas.Children[i]).Height = 0; ((Rectangle)spectrumCanvas.Children[i]).StrokeThickness = 0; } spectrumCanvas.Background = new SolidColorBrush(Colors.Black); } if (!Sound_Library.BassEngine.Instance.IsPlaying) { animationTimer.Stop(); } }
private void ColorScroll(MouseEventArgs e) { if (e.Button == MouseButtons.Left && mCurrentIdx > -1) { HSLColor oHlc = HSLColor.FromColor(_bColor); int idx = (int)Math.Floor(e.Y / (this.Height / 22f)); int dt = idx - mCurrentIdx; if (dt >= 0 && dt <= 1) { idx = mCurrentIdx; } if (idx > mCurrentIdx) { idx -= 1; } SelectedIndex = Math.Max(Math.Min(idx, 20), 0); oHlc.Lightness = 1f - (SelectedIndex * 5f) / 100; _selectedColor = oHlc.ToColor(); SelectedColorChanged?.Invoke(this, _selectedColor); } }
public static Color addHue(Color color, double change) { HSLColor hslColor = new HSLColor(color); hslColor.Hue += change; return(hslColor.ToColor()); }
public static Color addSaturation(Color color, double change) { HSLColor hslColor = new HSLColor(color); hslColor.Saturation += change; return(hslColor.ToColor()); }
public static Color addHue(Color color, int change) { HSLColor hslColor = new HSLColor(color); double delta = change / 360.0; hslColor.Hue += delta; return(hslColor.ToColor()); }
public static Color addSaturation(Color color, int change) { HSLColor hslColor = new HSLColor(color); double delta = change / 255.0; hslColor.Saturation += delta; return(hslColor.ToColor()); }
public static Color addLuminance(Color color, int change) { HSLColor hslColor = new HSLColor(color); double delta = change / 255.0; hslColor.Luminance += delta; return(hslColor.ToColor()); }
public NickColor(String nick) { this.nick = nick; var hue = (int)((float)Hash * (360.0 / 255.0)); var saturation = 60; var light = 40; var hsl = new HSLColor(hue, saturation, light); RGB = hsl.ToColor(); }
public ChatterinoImage DrawImageBackground(ChatterinoImage image, HSLColor color) { var img = image; var bitmap = new Bitmap(img.Width, img.Height); using (var g = Graphics.FromImage(bitmap)) { g.Clear(color.ToColor()); img.DrawImage(g, 0, 0, img.Width, img.Height); } return(new ChatterinoImage(bitmap)); }
public object DrawImageBackground(object image, HSLColor color) { var img = (Image)image; var bitmap = new Bitmap(img.Width, img.Height); using (var g = Graphics.FromImage(bitmap)) { g.Clear(color.ToColor()); g.DrawImage(img, 0, 0); } return(bitmap); }
private void ApplyTheme_Click(object sender, RoutedEventArgs e) { var newBaseColor = new HSLColor(_model.BaseColor); var lightDictionary = new ResourceDictionary(); var darkDictionary = new ResourceDictionary(); foreach (var group in _model.ColorGroups) { foreach (var setting in group.Colors) { var lightColor = new HSLColor(setting.LightColor); var darkColor = new HSLColor(setting.DarkColor); var origLightColor = new HSLColor(setting.OriginalLightColor); var origDarkColor = new HSLColor(setting.OriginalDarkColor); var newLightColor = new HSLColor(origLightColor.Alpha, newBaseColor.Hue, newBaseColor.Saturation, origLightColor.Luminosity); var newDarkColor = new HSLColor(origDarkColor.Alpha, newBaseColor.Hue, newBaseColor.Saturation, origDarkColor.Luminosity); var lightResult = newLightColor.ToColor(); var darkResult = newDarkColor.ToColor(); setting.DarkColor = darkResult; setting.LightColor = lightResult; lightDictionary[setting.ResourceName] = setting.CreateResourceObject(lightResult); darkDictionary[setting.ResourceName] = setting.CreateResourceObject(darkResult); } } ChangeTheme(lightDictionary, darkDictionary); }
public override bool Draw(bool checkDrawTimer) { if (!base.Draw(checkDrawTimer)) { return(false); } //this has a timer so that no matter how often you might call draw, the dialog //only updates 10x per second ModuleAttention parent = (ModuleAttention)base.ParentModule; theCanvas.Children.Clear(); Point windowSize = new Point(theCanvas.ActualWidth, theCanvas.ActualHeight); ModuleView naSource = MainWindow.theNeuronArray.FindModuleByLabel("UKS"); if (naSource == null) { return(false); } uks = (ModuleUKS)naSource.TheModule; Thing mentalModel = uks.GetOrAddThing("MentalModel", "Visual"); if (mentalModel == null || mentalModel.Children.Count == 0) { return(false); } Thing attn = uks.Labeled("ATTN"); if (attn == null || attn.References.Count == 0) { return(false); } Thing attnTarget = attn.GetReferenceWithAncestor(uks.Labeled("Visual")); var values = uks.GetValues(attnTarget); HSLColor c1 = new HSLColor(values["Hue+"], values["Sat+"], values["Lum+"]); Color fillColor = c1.ToColor(); try { double largest = 0; foreach (Thing area in mentalModel.Children) { var areaValues = uks.GetValues(area); Thing theShape = area.Children[0]; var shapeValues = uks.GetValues(theShape); PointPlus pOffset = new PointPlus(areaValues["CtrX+"] - shapeValues["CtrX+"], areaValues["CtrY+"] - shapeValues["CtrY+"]); foreach (Thing corner in theShape.Children) { Point p = (Point)corner.Children[0].V; p = p + pOffset; largest = Math.Max(largest, p.X); largest = Math.Max(largest, p.Y); } } largest += 10; //a little margin float scale = (float)Math.Min(windowSize.X, windowSize.Y) / (float)largest; if (scale == 0) { return(false); } theCanvas.Children.Clear(); foreach (Thing area in mentalModel.Children) { PointCollection pts = new PointCollection(); var areaValues = uks.GetValues(area); Thing theShape = area.Children[0]; var shapeValues = uks.GetValues(theShape); //These corrections are needed because known objects are stored at the location and size when they were first seen //now the viewed object will have a different size and location PointPlus pAreaCtr = new PointPlus(areaValues["CtrX+"], areaValues["CtrY+"]); PointPlus pShapeCtr = new PointPlus(shapeValues["CtrX+"], shapeValues["CtrY+"]); float areaSize = areaValues["Siz+"]; float shapeSize = shapeValues["Siz+"]; Angle areaAngle = areaValues["Ang+"]; Angle shapeAngle = shapeValues["Ang+"]; Angle rotation = areaAngle - shapeAngle; foreach (Thing corner in theShape.Children) { PointPlus p = new PointPlus((Point)corner.Children[0].V); p = p - pShapeCtr; p.Theta += rotation; float ratio = areaSize / shapeSize; p.X *= ratio; p.Y *= ratio; p = p + pAreaCtr; p.X *= scale; p.Y *= scale; pts.Add(p); } Polygon poly = new Polygon { Points = pts, Stroke = new SolidColorBrush(Colors.AliceBlue) }; poly.ToolTip = area.Label; poly.Fill = this.Background; if (attnTarget == area) { poly.Fill = new SolidColorBrush(fillColor); poly.Stroke = new SolidColorBrush(fillColor); poly.Fill.Opacity = 1; } poly.MouseDown += Poly_MouseDown; poly.SetValue(AttentionObjectProperty, area); theCanvas.Children.Add(poly); } } #pragma warning disable 168 catch (Exception e) //sometimes useful for debugging #pragma warning restore 168 { } return(true); }
public static void ColorOut(HSLColor Color) { Arduino_Host.WriteColor.RGB(Color.ToColor()); }