private void CalcCoordsAndUpdate(ColorHandler.HSV hsv) { this._colorPoint = GetPoint((double)hsv.Hue / 255 * 360, (double)hsv.Saturation / 255 * this._radius, this._centerPoint); this._brightnessPoint = this.CalcBrightnessPoint(hsv.Value); this._brightness = hsv.Value; this._selectedColor = ColorHandler.HSVtoColor(hsv); this._argb = ColorHandler.HSVtoRGB(hsv); this._fullColor = ColorHandler.HSVtoColor(hsv.Alpha, hsv.Hue, hsv.Saturation, 255); }
/// <summary> /// Draws the images /// </summary> /// <param name="g">Graphics context to draw with</param> /// <param name="mousePoint">MousePoint to draw</param> public void Draw(Graphics g, Point mousePoint) { var newColorPoint = this._colorPoint; var newBrightnessPoint = this._brightnessPoint; this._graphics = g; if (this._currentState == MouseState.MouseUp) { if (!mousePoint.IsEmpty) { if (this._colorRegion.IsVisible(mousePoint)) this._currentState = MouseState.ClickOnColor; else if (this._brightnessRegion.IsVisible(mousePoint)) this._currentState = MouseState.ClickOnBrightness; else this._currentState = MouseState.ClickOutsideRegion; } } switch (this._currentState) { case MouseState.ClickOnBrightness: case MouseState.DragInBrightness: var newPoint = mousePoint; if (newPoint.Y < this._brightnessMin) { newPoint.Y = this._brightnessMin; } else if (newPoint.Y > this._brightnessMax) { newPoint.Y = this._brightnessMax; } newBrightnessPoint = new Point(this._brightnessX, newPoint.Y); this._brightness = (int)((this._brightnessMax - newPoint.Y) * this._brightnessScaling); this._hsv.Value = this._brightness; this._argb = ColorHandler.HSVtoRGB(this._hsv); break; case MouseState.ClickOnColor: case MouseState.DragInColor: newColorPoint = mousePoint; var delta = new Point(mousePoint.X - this._centerPoint.X, mousePoint.Y - this._centerPoint.Y); var degrees = CalcDegrees(delta); var distance = Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y) / this._radius; if (this._currentState == MouseState.DragInColor) { if (distance > 1) { distance = 1; newColorPoint = GetPoint(degrees, this._radius, this._centerPoint); } } this._hsv.Hue = (degrees * 255 / 360); this._hsv.Saturation = (int)(distance * 255); this._hsv.Value = this._brightness; this._argb = ColorHandler.HSVtoRGB(this._hsv); this._fullColor = ColorHandler.HSVtoColor(this._hsv.Alpha, this._hsv.Hue, this._hsv.Saturation, 255); break; } this._selectedColor = ColorHandler.HSVtoColor(this._hsv); this.OnColorChanged(this._argb, this._hsv); switch (this._currentState) { case MouseState.ClickOnBrightness: this._currentState = MouseState.DragInBrightness; break; case MouseState.ClickOnColor: this._currentState = MouseState.DragInColor; break; case MouseState.ClickOutsideRegion: this._currentState = MouseState.DragOutsideRegion; break; } this._colorPoint = newColorPoint; this._brightnessPoint = newBrightnessPoint; this.UpdateDisplay(); }