private void SetHSV(ColorHandler.HSV HSV) { // Update the HSV values on the form. RefreshValue(hsbHue, HSV.Hue); RefreshValue(hsbSaturation, HSV.Saturation); SetHSVLabels(HSV); }
private void CalcCoordsAndUpdate(ColorHandler.HSV HSV) { // Convert color to real-world coordinates and then calculate // the various points. HSV.Hue represents the degrees (0 to 360), // HSV.Saturation represents the radius. // This procedure doesn't draw anything--it simply // updates class-level variables. The UpdateDisplay // procedure uses these values to update the screen. // Given the angle (HSV.Hue), and distance from // the center (HSV.Saturation), and the center, // calculate the point corresponding to // the selected color, on the color wheel. colorPoint = GetPoint((double)HSV.Hue / 255 * 360, (double)HSV.Saturation / 255 * radius, centerPoint); // Given the brightness (HSV.value), calculate the // point corresponding to the brightness indicator. brightnessPoint = CalcBrightnessPoint(HSV.value); // Store information about the selected color. brightness = HSV.value; selectedColor = ColorHandler.HSVtoColor(HSV); RGB = ColorHandler.HSVtoRGB(HSV); // The full color is the same as HSV, except that the // brightness is set to full (255). This is the top-most // color in the brightness gradient. fullColor = ColorHandler.HSVtoColor(HSV.Hue, HSV.Saturation, 255); }
private void SetHSVLabels(ColorHandler.HSV HSV) { RefreshText(lblHue, HSV.Hue); RefreshText(lblSaturation, HSV.Saturation); RefreshText(lblValue, HSV.Value); RefreshText(lblAlpha2, HSV.Alpha); }
public void Draw(Graphics g, ColorHandler.HSV HSV) { // Given HSV values, update the screen. this.g = g; this.HSV = HSV; CalcCoordsAndUpdate(this.HSV); UpdateDisplay(); }
public void Draw(Graphics g, ColorHandler.RGB RGB) { // Given RGB values, calculate HSV and then update the screen. this.g = g; this.HSV = ColorHandler.RGBtoHSV(RGB); CalcCoordsAndUpdate(this.HSV); UpdateDisplay(); }
private void SetHSV(ColorHandler.HSV HSV) { // Update the HSV values on the form, but don't trigger // the ValueChanged event of the form. The isInUpdate // variable ensures that the event procedures // exit without doing anything. isInUpdate = true; RefreshValue(nudHue, HSV.Hue); RefreshValue(nudSaturation, HSV.Saturation); RefreshValue(nudBrightness, HSV.value); isInUpdate = false; }
private void HandleHSVScroll(object sender, EventArgs e) // If the H, S, or V values change, use this // code to update the RGB values and invalidate // the color wheel (so it updates the pointers). // Check the isInUpdate flag to avoid recursive events // when you update the NumericUpdownControls. { changeType = ChangeStyle.HSV; hsv = new ColorHandler.HSV(tbAlpha.Value, tbHue.Value, tbSaturation.Value, tbValue.Value); SetRGB(ColorHandler.HSVtoRGB(hsv)); SetHSVLabels(hsv); Invalidate(); }
private void HandleHSVChange(object sender, EventArgs e) { // If the H, S, or V values change, use this // code to update the RGB values and invalidate // the color wheel (so it updates the pointers). // Check the isInUpdate flag to avoid recursive events // when you update the NumericUpdownControls. if (!isInUpdate) { changeType = ChangeStyle.HSV; HSV = new ColorHandler.HSV((int)(nudHue.Value), (int)(nudSaturation.Value), (int)(nudBrightness.Value)); SetRGB(ColorHandler.HSVtoRGB(HSV)); this.Invalidate(); } }
private void GrabColor(object sender, Point mouseXY) { int cntlNum = this.Controls.IndexOf((Control)sender); int cx = mouseXY.X; int cy = mouseXY.Y; switch (cntlNum) { case 0: // center our coordinate system so the middle is (0,0), and positive Y is facing up cx -= (this.Controls[cntlNum].Width / 2); cy -= (this.Controls[cntlNum].Height / 2); if (cx < this.Controls[cntlNum].Width / 2) { double theta = Math.Atan2(cy, cx); if (theta < 0) { theta += 2 * Math.PI; } double alpha = Math.Sqrt((cx * cx) + (cy * cy)); int h = (int)((theta / (Math.PI * 2)) * 360.0); int s = (int)Math.Min(100.0, (alpha / (double)(this.Controls[0].Width / 2)) * 100); int v = hsvColor.value; hsvColor = new ColorHandler.HSV(h, s, v); OnColorChanged(); updateBar(); } break; case 1: if (cx < this.Controls[cntlNum].Width) { hsvColor.value = Math.Max(0, Math.Min(100, 100 - (cy * 100 / this.Controls[cntlNum].Height))); updateBox(); } break; } this.color = ColorHandler.HSVtoRGB(hsvColor); Invalidate(true); }
/// <summary> /// The draw bar. /// </summary> /// <param name="g"> /// The g. /// </param> /// <param name="width"> /// The width. /// </param> /// <param name="height"> /// The height. /// </param> private void DrawBar(Graphics g, int width, int height) { PointF[] points = new PointF[2]; for (int i = 0; i < points.Length; i++) { points[i].X = width / 2; points[i].Y = i * height; } ColorHandler.HSV col = new ColorHandler.HSV(hsvColor.Hue, hsvColor.Saturation, 100); using ( LinearGradientBrush lgb = new LinearGradientBrush( points[0], points[1], ColorHandler.HSVtoColor(col), Color.Black)) { g.FillRectangle(lgb, 0, 0, width, height); } }
private void ColorChooser1_Load(object sender, System.EventArgs e) { // Turn on double-buffering, so the form looks better. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); // These properties are set in design view, as well, but they // have to be set to false in order for the Paint // event to be able to display their contents. // Never hurts to make sure they're invisible. pnlSelectedColor.Visible = false; pnlBrightness.Visible = false; pnlColor.Visible = false; // Calculate the coordinates of the three // required regions on the form. Rectangle SelectedColorRectangle = new Rectangle(pnlSelectedColor.Location, pnlSelectedColor.Size); Rectangle BrightnessRectangle = new Rectangle(pnlBrightness.Location, pnlBrightness.Size); Rectangle ColorRectangle = new Rectangle(pnlColor.Location, pnlColor.Size); // Create the new ColorWheel class, indicating // the locations of the color wheel itself, the // brightness area, and the position of the selected color. myColorWheel = new ColorWheel( ColorRectangle, BrightnessRectangle, SelectedColorRectangle); myColorWheel.ColorChanged += new ColorWheel.ColorChangedEventHandler( this.myColorWheel_ColorChanged); // Set the RGB and HSV values // of the NumericUpDown controls. SetRGB(RGB); HSV = ColorHandler.RGBtoHSV(RGB); SetHSV(HSV); changeType = ChangeStyle.RGB; }
/// <summary> /// The control_ text changed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Control_TextChanged(object sender, EventArgs e) { if (updatingColors) { return; } Control c = (Control)sender; try { if ((Color)c.Tag == Color.White) { this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Red) { this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Green) { this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } if ((Color)c.Tag == Color.Blue) { this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255))); } this.hsvColor = ColorHandler.RGBtoHSV(this.color); updateBar(); } catch { } }
// If the H, S, or V values change, use this // code to update the RGB values and invalidate // the color wheel (so it updates the pointers). // Check the isInUpdate flag to avoid recursive events // when you update the NumericUpdownControls. private void HandleHSVScroll(object sender, ScrollEventArgs e) { changeType = ChangeStyle.HSV; HSV = new ColorHandler.HSV(Hue.Value, Saturation.Value, Brightness.Value); SetRGB(ColorHandler.HSVtoRGB(HSV)); SetHSVLabels(HSV); this.ColorTab.Invalidate(); }
private void SetHSVLabels(ColorHandler.HSV HSV) { RefreshText(lblHue, HSV.Hue); RefreshText(lblSaturation, HSV.Saturation); RefreshText(lblBrightness, HSV.value); }
protected void OnColorChanged(ColorHandler.RGB RGB, ColorHandler.HSV HSV) { ColorChangedEventArgs e = new ColorChangedEventArgs(RGB, HSV); ColorChanged(this, e); }
/// <summary> /// The control_ lost focus. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Control_LostFocus(object sender, EventArgs e) { hsvColor = ColorHandler.RGBtoHSV(this.color); updateBar(); this.Refresh(); }
private void HandleHSVChange( object sender, EventArgs e) { // If the H, S, or V values change, use this // code to update the RGB values and invalidate // the color wheel (so it updates the pointers). // Check the isInUpdate flag to avoid recursive events // when you update the NumericUpdownControls. if (! isInUpdate ) { changeType = ChangeStyle.HSV; HSV = new ColorHandler.HSV((int)(nudHue.Value), (int)(nudSaturation.Value), (int)(nudBrightness.Value)); SetRGB(ColorHandler.HSVtoRGB(HSV)); this.Invalidate(); } }
public ColorChangedEventArgs(ColorHandler.RGB RGB, ColorHandler.HSV HSV) { mRGB = RGB; mHSV = HSV; }
private void GrabColor(object sender, Point mouseXY) { int cntlNum = this.Controls.IndexOf((Control)sender); int cx = mouseXY.X; int cy = mouseXY.Y; switch (cntlNum) { case 0: // center our coordinate system so the middle is (0,0), and positive Y is facing up cx -= (this.Controls[cntlNum].Width / 2); cy -= (this.Controls[cntlNum].Height / 2); if (cx < this.Controls[cntlNum].Width / 2) { double theta = Math.Atan2(cy, cx); if (theta < 0) { theta += 2 * Math.PI; } double alpha = Math.Sqrt((cx * cx) + (cy * cy)); int h = (int)((theta / (Math.PI * 2)) * 360.0); int s = (int)Math.Min(100.0, (alpha / (double)(this.Controls[0].Width / 2)) * 100); int v = hsvColor.value; hsvColor = new ColorHandler.HSV(h, s, v); OnColorChanged(); updateBar(); } break; case 1: if (cx < this.Controls[cntlNum].Width) { hsvColor.value = Math.Max(0, Math.Min(100,100 - (cy * 100 / this.Controls[cntlNum].Height))); updateBox(); } break; } this.color = ColorHandler.HSVtoRGB(hsvColor); Invalidate(true); }