void SetColor(PointF mousepoint) { if (WheelRectangle.Contains(mousepoint) == false) return; PointF center = Util.Center(ColorWheelRectangle); double radius = Radius(ColorWheelRectangle); double dx = Math.Abs(mousepoint.X - center.X); double dy = Math.Abs(mousepoint.Y - center.Y); double angle = Math.Atan(dy / dx) / Math.PI * 180; double dist = Math.Pow((Math.Pow(dx, 2) + (Math.Pow(dy, 2))), 0.5); double saturation = dist/radius; //if (dist > radius + 5) // give 5 pixels slack // return; if (dist < 6) saturation = 0; // snap to center if (mousepoint.X < center.X) angle = 180 - angle; if (mousepoint.Y > center.Y) angle = 360 - angle; SelectedHSLColor = new HSLColor(angle, saturation, SelectedHSLColor.Lightness); }
void OnWheelColorChanged(object sender, EventArgs e) { m_selectedColor.Hue = m_colorWheel.SelectedHSLColor.Hue; m_selectedColor.Saturation = m_colorWheel.SelectedHSLColor.Saturation; SelectedHSLColor = m_selectedColor; }
void UpdateInfo(Color c, HSLColor hsl) { // Set RGBA fields. txtR.Text = c.R.ToString(); txtG.Text = c.G.ToString(); txtB.Text = c.B.ToString(); txtA.Text = Math.Round( (c.A / 255f) , 2 ).ToString(); txtRGBA.Text = this.RGBA; // Set HSL fields. txtH.Text = Math.Round(hsl.Hue, 2).ToString(); txtS.Text = Math.Round(hsl.Saturation * 255f, 2).ToString(); txtL.Text = Math.Round(hsl.Lightness * 255f, 2).ToString(); // Hex txtHex.Text = this.HexColor.ToString(); //m_infoLabel.Text = sRGBA; }
void OnLightnessColorChanged(object sender, EventArgs e) { m_selectedColor.Lightness = m_colorBar.SelectedHSLColor.Lightness; SelectedHSLColor = m_selectedColor; }
protected override void SetPercent(float percent) { base.SetPercent(percent); m_selectedColor.Lightness = percent / 100; SelectedHSLColor = m_selectedColor; }