public static VertexBrush Blend(VertexBrush a, VertexBrush b, float value) { MathHelper.Clamp(value, 0f, 1f); return(new VertexBrush( ColorHSL.Blend(a.hsl, b.hsl, value), a.size, a.opacity, a.hardness )); }
public override void Logic() { if (mouse.WheelDelta != 0) { if (keyboard.HasPrefix(KeyPrefix.Alt)) { brush.Size += mouse.WheelDelta * 0.12f; if (brush.Size < 0) { brush.Size = 0f; } if (brushForm != null) { brushForm.Size = brush.Size; } } if (keyboard.HasPrefix(KeyPrefix.Control)) { brush.Opacity += mouse.WheelDelta * 0.05f; brush.Opacity = MathHelper.Clamp(brush.Opacity, 0, 1); if (brushForm != null) { brushForm.Opacity = brush.Opacity; } } if (keyboard.HasPrefix(KeyPrefix.Shift)) { brush.Hardness += mouse.WheelDelta * 0.05f; brush.Hardness = MathHelper.Clamp(brush.Hardness, 0, 1); if (brushForm != null) { brushForm.Hardness = brush.Hardness; } } } if (mouse[MouseButton.Left] && editor.form.Focused) { foreach (EVertex v in SelectedVertices) { float weight = 1 - (v.Position - Position).Length / brush.Size; if (weight < 1 - brush.Hardness) { weight = weight / (1f - brush.Hardness); } else { weight = 1f; } if (vertexData.ContainsKey(v)) { if (vertexData[v].Weight > weight) { continue; } vertexData[v].Weight = weight; } else { vertexData.Add(v, new PaintData(weight, v.HSL)); } v.Paint(ColorHSL.Blend(vertexData[v].Origin, brush.HSL, weight * brush.Opacity)); DebugForm.debugString = "Weight: " + weight.ToString(); } } if (!mouse[MouseButton.Left] && vertexData.Count > 0) { EVertex[] vertices = new EVertex[vertexData.Count]; ColorHSL[] begins = new ColorHSL[vertexData.Count]; ColorHSL[] ends = new ColorHSL[vertexData.Count]; int index = 0; foreach (KeyValuePair <EVertex, PaintData> data in vertexData) { vertices[index] = data.Key; begins[index] = data.Value.Origin; ends[index] = data.Key.HSL; index++; } editor.ActiveLayers[0].History.Add(new PaintAction(vertices, begins, ends, editor.ActiveHistory)); vertexData.Clear(); } }
public void Paint(ColorHSL brush, float weight = 1f) { ColorHSL c = ColorHSL.Blend(HSL, brush, weight); HSL = c; }