public void Reset(ResetMode mode) { if (firstTime) { return; } bool valid = Validate(); if (!valid) { Kill(); return; } Elapsed = 0.0f; switch (mode) { case ResetMode.InitialValues: { setter(firstTimeInitialValue); finalValue = firstTimeFinalValue; } break; case ResetMode.IncrementalValues: { T difference = interpolator.Subtract(firstTimeInitialValue, firstTimeFinalValue); initialValue = currentValue; finalValue = interpolator.Add(currentValue, difference); } break; } }
private void DrawToGraphics(Graphics g) { ColorBgra colorSolid = ColorBgra.FromColor(this.ForeColor); ColorBgra colorGuide = ColorBgra.FromColor(this.ForeColor); ColorBgra colorGrid = ColorBgra.FromColor(this.ForeColor); colorGrid.A = 128; colorGuide.A = 96; Pen penSolid = new Pen(colorSolid.ToColor(), 1); Pen penGrid = new Pen(colorGrid.ToColor(), 1); Pen penGuide = new Pen(colorGuide.ToColor(), 1); penGrid.DashStyle = DashStyle.Dash; g.Clear(this.BackColor); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle ourRect = ClientRectangle; ourRect.Inflate(-1, -1); if (lastMouseXY.Y >= 0) { g.DrawLine(penGuide, 0, lastMouseXY.Y, Width, lastMouseXY.Y); } if (lastMouseXY.X >= 0) { g.DrawLine(penGuide, lastMouseXY.X, 0, lastMouseXY.X, Height); } for (float f = 0.25f; f <= 0.75f; f += 0.25f) { float x = Utility.Lerp(ourRect.Left, ourRect.Right, f); float y = Utility.Lerp(ourRect.Top, ourRect.Bottom, f); g.DrawLine(penGrid, Point.Round(new PointF(x, ourRect.Top)), Point.Round(new PointF(x, ourRect.Bottom))); g.DrawLine(penGrid, Point.Round(new PointF(ourRect.Left, y)), Point.Round(new PointF(ourRect.Right, y))); } g.DrawLine(penGrid, ourRect.Left, ourRect.Bottom, ourRect.Right, ourRect.Top); float width = this.ClientRectangle.Width; float height = this.ClientRectangle.Height; for (int c = 0; c < channels; ++c) { SortedList <int, int> channelControlPoints = controlPoints[c]; int points = channelControlPoints.Count; ColorBgra color = GetVisualColor(c); ColorBgra colorSelected = ColorBgra.Blend(color, ColorBgra.White, 128); const float penWidthNonSelected = 1; const float penWidthSelected = 2; float penWidth = mask[c] ? penWidthSelected : penWidthNonSelected; Pen penSelected = new Pen(color.ToColor(), penWidth); color.A = 128; Pen pen = new Pen(color.ToColor(), penWidth); Brush brush = new SolidBrush(color.ToColor()); SolidBrush brushSelected = new SolidBrush(Color.White); IInterpolator _interpolator = InterpolatorFactory.GetInterpolator(_interpolatorType); IList <int> xa = channelControlPoints.Keys; IList <int> ya = channelControlPoints.Values; PointF[] line = new PointF[Entries]; for (int i = 0; i < points; ++i) { _interpolator.Add(xa[i], ya[i]); } for (int i = 0; i < line.Length; ++i) { line[i].X = (float)i * (width - 1) / (entries - 1); line[i].Y = (float)(Utility.Clamp(entries - 1 - _interpolator.Interpolate((byte)i), 0, entries - 1)) * (height - 1) / (entries - 1); } pen.LineJoin = LineJoin.Round; g.DrawLines(pen, line); for (int i = 0; i < points; ++i) { int k = channelControlPoints.Keys[i]; float x = k * (width - 1) / (entries - 1); float y = (entries - 1 - channelControlPoints.Values[i]) * (height - 1) / (entries - 1); const float radiusSelected = 4; const float radiusNotSelected = 3; const float radiusUnMasked = 2; bool selected = (mask[c] && pointsNearMousePerChannel[c] == i); float size = selected ? radiusSelected : (mask[c] ? radiusNotSelected : radiusUnMasked); RectangleF rect = Utility.RectangleFromCenter(new PointF(x, y), size); g.FillEllipse(selected ? brushSelected : brush, rect.X, rect.Y, rect.Width, rect.Height); g.DrawEllipse(selected ? penSelected : pen, rect.X, rect.Y, rect.Width, rect.Height); } pen.Dispose(); } penSolid.Dispose(); penGrid.Dispose(); penGuide.Dispose(); }
/// <summary> /// 将控件参数传递到参数对象中 /// </summary> protected override void CollectArguments() { if (_arg == null) { return; } CurveAdjustProcessorArg actualArg = _arg as CurveAdjustProcessorArg; IInterpolator interpolator = GetInterpolator(); if (curveControl.Channels == 3) { for (int i = 0; i < curveControl.Channels; i++) { interpolator.Clear(); CurveControl curve = curveControl;// curveControls[CA.ColorTransferMode.Rgb]; SortedList <int, int> cps = curve.ControlPoints[i]; for (int s = 0; s < cps.Count; s++) { interpolator.Add(cps.Keys[s], cps.Values[s]); } byte[] rgbMap = new byte[curveControl.Entries]; for (int j = 0; j < curveControl.Entries; j++) { rgbMap[j] = (byte)Utility.Clamp(interpolator.Interpolate((byte)j), 0, curveControl.Entries - 1); } if (i == 0) { actualArg.Red.Values = rgbMap; } else if (i == 1) { actualArg.Green.Values = rgbMap; } else if (i == 2) { actualArg.Blue.Values = rgbMap; } } actualArg.RGB.Values = null; } else { interpolator.Clear(); CurveControl curve = curveControl;// curveControls[CA.ColorTransferMode.Luminosity]; SortedList <int, int> cps = curve.ControlPoints[0]; for (int s = 0; s < cps.Count; s++) { interpolator.Add(cps.Keys[s], cps.Values[s]); } byte[] rgbMap = new byte[curveControl.Entries]; for (int j = 0; j < curveControl.Entries; j++) { rgbMap[j] = (byte)Utility.Clamp(interpolator.Interpolate((byte)j), 0, curveControl.Entries - 1); } actualArg.RGB.Values = rgbMap; actualArg.Red.Values = null; actualArg.Green.Values = null; actualArg.Blue.Values = null; } base.CollectArguments(); }