public void TextUtilsShadowParametersConstructor() { tlog.Debug(tag, $"TextUtilsShadowParametersConstructor START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsShadowParametersConstructor END (OK)"); }
static void GetShadowPattern(Cairo.Gradient shadow, ShadowParameters shadowParams) { double denLog = Math.Log(1.0f / shadowParams.shadowRadius); shadow.AddColorStop(0.0, new Cairo.Color(0, 0, 0, shadowParams.shadowAlpha)); for (int i = 2; i <= shadowParams.shadowRadius; i++) { double step = i / shadowParams.shadowRadius; shadow.AddColorStop(step, new Cairo.Color(0, 0, 0, shadowParams.shadowAlpha * (Math.Log(step) / denLog))); } }
public void TextUtilsShadowParametersOffset() { tlog.Debug(tag, $"TextUtilsShadowParametersOffset START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.Offset = new Vector2(0.3f, 0.8f); Assert.AreEqual(0.3f, testingTarget.Offset.X, "Should be equal!"); Assert.AreEqual(0.8f, testingTarget.Offset.Y, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsShadowParametersOffset END (OK)"); }
public void TextUtilsShadowParametersInput() { tlog.Debug(tag, $"TextUtilsShadowParametersInput START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.Input = new PixelBuffer(30, 50, PixelFormat.A8); Assert.AreEqual(30, testingTarget.Input.GetWidth(), "Should be equal!"); Assert.AreEqual(50, testingTarget.Input.GetHeight(), "Should be equal!"); Assert.AreEqual(PixelFormat.A8, testingTarget.Input.GetPixelFormat(), "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsShadowParametersInput END (OK)"); }
public void TextUtilsShadowParametersTextColor() { tlog.Debug(tag, $"TextUtilsShadowParametersTextColor START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.TextColor = new Vector4(0.3f, 0.8f, 1.0f, 0.0f); Assert.AreEqual(0.3f, testingTarget.TextColor.R, "Should be equal!"); Assert.AreEqual(0.8f, testingTarget.TextColor.G, "Should be equal!"); Assert.AreEqual(1.0f, testingTarget.TextColor.B, "Should be equal!"); Assert.AreEqual(0.0f, testingTarget.TextColor.A, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsShadowParametersTextColor END (OK)"); }
public void TextUtilsCreateShadow() { tlog.Debug(tag, $"TextUtilsCreateShadow START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.Input = new PixelBuffer(30, 50, PixelFormat.A8); testingTarget.blendShadow = true; var result = TextUtils.CreateShadow(testingTarget); Assert.IsNotNull(result, "Can't create success object PixelBuffer"); Assert.IsInstanceOf <PixelBuffer>(result, "Should be an instance of PixelBuffer type."); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsCreateShadow END (OK)"); }
public void TextUtilsShadowParametersColor() { tlog.Debug(tag, $"TextUtilsShadowParametersColor START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.Input = new PixelBuffer(30, 50, PixelFormat.A8); testingTarget.Color = new Vector4(0.3f, 0.8f, 1.0f, 0.0f); var color = new Vector4(0.3f, 0.8f, 1.0f, 0.0f); Assert.AreEqual(true, CheckColor(color, testingTarget.Color), "Should be true!"); color.Dispose(); testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsShadowParametersColor END (OK)"); }
public void TextUtilsShadowParametersblendShadow() { tlog.Debug(tag, $"TextUtilsShadowParametersblendShadow START"); var testingTarget = new ShadowParameters(); Assert.IsNotNull(testingTarget, "Can't create success object ShadowParameters"); Assert.IsInstanceOf <ShadowParameters>(testingTarget, "Should be an instance of ShadowParameters type."); testingTarget.blendShadow = true; try { var result = testingTarget.blendShadow; } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception: Failed!"); } testingTarget.Dispose(); tlog.Debug(tag, $"TextUtilsShadowParametersblendShadow END (OK)"); }
public static void DrawShadow(Cairo.Context cr, double x, double y, double width, double height, double radius, ShadowParameters shadowParams) { using (Surface sr = cr.CreateSimilarToTarget((int)width + (int)(2 * shadowParams.shadowRadius) + (int)x, (int)height + (int)(2 * shadowParams.shadowRadius) + (int)y)) { using (Context cairo = new Context(sr)) { radius++; y++; height--; Cairo.Gradient shadow; /* Top Left */ using (shadow = new Cairo.RadialGradient(x + radius, y + radius, radius, x + radius, y + radius, radius + shadowParams.shadowRadius)) { cairo.Rectangle(x - shadowParams.shadowRadius, y - shadowParams.shadowRadius, radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius); FillShadowPattern(cairo, shadow, shadowParams); } /* Top */ using (shadow = new Cairo.LinearGradient(0.0, y, 0.0, y - shadowParams.shadowRadius)) { cairo.Rectangle(x + radius, y - shadowParams.shadowRadius, width - radius * 2, shadowParams.shadowRadius); FillShadowPattern(cairo, shadow, shadowParams); } /* Top Right */ using (shadow = new Cairo.RadialGradient(width + x - radius, y + radius, radius, width + x - radius, y + radius, radius + shadowParams.shadowRadius)) { cairo.Rectangle(width + x - radius, y - shadowParams.shadowRadius, radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius); FillShadowPattern(cairo, shadow, shadowParams); } /* Right */ using (shadow = new Cairo.LinearGradient(width + x, 0.0, width + x + shadowParams.shadowRadius, 0.0)) { cairo.Rectangle(width + x, y + radius, shadowParams.shadowRadius, height - radius * 2); FillShadowPattern(cairo, shadow, shadowParams); } /* Bottom Right */ using (shadow = new Cairo.RadialGradient(width + x - radius, height + y - radius, radius, width + x - radius, height + y - radius, radius + shadowParams.shadowRadius)) { cairo.Rectangle(width + x - radius, height + y - radius, radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius); FillShadowPattern(cairo, shadow, shadowParams); } /* Bottom */ using (shadow = new Cairo.LinearGradient(0.0, height + y, 0.0, height + y + shadowParams.shadowRadius)) { cairo.Rectangle(x + radius, height + y, width - radius * 2, shadowParams.shadowRadius); FillShadowPattern(cairo, shadow, shadowParams); } /* Bottom Left */ using (shadow = new Cairo.RadialGradient(x + radius, height + y - radius, radius, x + radius, height + y - radius, radius + shadowParams.shadowRadius)) { cairo.Rectangle(x - shadowParams.shadowRadius, height + y - radius, radius + shadowParams.shadowRadius, radius + shadowParams.shadowRadius); FillShadowPattern(cairo, shadow, shadowParams); } /* Left */ using (shadow = new Cairo.LinearGradient(x, 0.0, x - shadowParams.shadowRadius, 0.0)) { cairo.Rectangle(x - shadowParams.shadowRadius, y + radius, radius + shadowParams.shadowRadius, height - radius * 2); FillShadowPattern(cairo, shadow, shadowParams); } y--; height++; /* Clear inner rectangle */ GetFrame(cairo, x, y, width, height, radius); cairo.Operator = Cairo.Operator.Clear; cairo.Fill(); cr.SetSource(sr); cr.Paint(); } } }
static void FillShadowPattern(Cairo.Context cairo, Cairo.Gradient shadow, ShadowParameters shadowParams) { GetShadowPattern(shadow, shadowParams); cairo.SetSource(shadow); cairo.Fill(); }