public void DrawLine(string behaviorName) { var random = new Random(); _mockBehaviorResolver .Setup(resolver => resolver.GetBehaviorHandler(behaviorName)).Returns(() => { return(new DrawContentBehavior(_sciterWindow, (element, prms) => { if (prms.DrawEvent != DrawEvent.Content) { return false; } using (var graphics = SciterGraphics.Create(prms.Handle)) { for (var i = 0; i < byte.MaxValue; i++) { graphics.SaveState() .Translate(prms.Area.Left, prms.Area.Top) .SetLineColor((byte)random.Next(byte.MinValue, byte.MaxValue), (byte)random.Next(byte.MinValue, byte.MaxValue), (byte)random.Next(byte.MinValue, byte.MaxValue), (byte)random.Next(byte.MinValue, byte.MaxValue)) .SetFillColor((byte)random.Next(byte.MinValue, byte.MaxValue), (byte)random.Next(byte.MinValue, byte.MaxValue), (byte)random.Next(byte.MinValue, byte.MaxValue), (byte)random.Next(byte.MinValue, byte.MaxValue)) .SetLineWidth(random.Next(2, 10)) .DrawText( SciterText.CreateForElementAndStyle( "The quick brown fox jumps over the lazy dog", element.Handle, $"color: rgba({random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)});font-size: {random.Next(12, 48)}dip;"), random.Next(byte.MinValue, prms.Area.Width), random.Next(byte.MinValue, prms.Area.Height), 5) .RestoreState(); } } element?.Window?.Close(); return true; })); }); _ = new TestableSciterHost(_sciterWindow) .SetBehaviorResolver(_mockBehaviorResolver.Object); _sciterWindow.Show(); _sciterWindow.RootElement.AppendElement("body", elm => elm) .SetStyleValue("background-color", $"black") .SetStyleValue("behavior", behaviorName); SciterPlatform.RunMessageLoop(); //Assert.NotNull(_sciterGraphics); }
protected override bool OnDraw(SciterElement se, SciterXBehaviors.DRAW_PARAMS prms) { if (prms.cmd == SciterXBehaviors.DRAW_EVENTS.DRAW_CONTENT) { SciterText txt = SciterText.Create("hi", se._he); using (SciterGraphics g = new SciterGraphics(prms.gfx)) { g.DrawText(txt, 0, 0, 7); } return(true); } return(false); }
protected override bool OnDraw(SciterElement se, DrawArgs args) { if (args.DrawEvent != DrawEvent.Content) { return(false); } var txt = SciterText.CreateForElement("hi", se); using (var g = SciterGraphics.Create(args.Handle)) { g.DrawText(txt, 0, 0, 1); } return(true); }
public override void DrawText(ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalAlignment halign, VerticalAlignment valign, OxySize?maxSize) { /*SciterXGraphics.SCITER_TEXT_ALIGNMENT line_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_DEFAULT; * switch(halign) * { * case HorizontalAlignment.Left: line_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_START; break; * case HorizontalAlignment.Center: line_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_CENTER; break; * case HorizontalAlignment.Right: line_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_END; break; * } * * SciterXGraphics.SCITER_TEXT_ALIGNMENT text_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_DEFAULT; * switch(valign) * { * case VerticalAlignment.Top: text_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_START; break; * case VerticalAlignment.Middle: text_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_CENTER; break; * case VerticalAlignment.Bottom: text_alg = SciterXGraphics.SCITER_TEXT_ALIGNMENT.TEXT_ALIGN_END; break; * } * * var txt = SciterText.Create(text, new SciterXGraphics.SCITER_TEXT_FORMAT * { * fontFamily = fontFamily, * fontSize = (float) fontSize, * fontWeight = (uint) fontWeight, * lineAlignment = line_alg, * textAlignment = text_alg * });*/ var txt = SciterText.CreateWithStyle(text, _se._he, "color: red;"); if (maxSize.HasValue) { Debug.Assert(false); txt.SetBox((float)maxSize.Value.Width, (float)maxSize.Value.Height); } if (rotate != 0) { Debug.Assert(false); _g.Rotate((float)rotate, 0, 0); } _g.DrawText(txt, (float)p.X, (float)p.Y, 5); }
protected override bool OnDraw(SciterElement se, SciterXBehaviors.DRAW_PARAMS prms) { if (prms.cmd == SciterXBehaviors.DRAW_EVENTS.DRAW_CONTENT) { SciterText txt = SciterText.Create("hi", new SciterXGraphics.SCITER_TEXT_FORMAT { fontFamily = "Arial", fontSize = 15, fontWeight = 400, lineHeight = 30 }); using (SciterGraphics g = new SciterGraphics(prms.gfx)) { g.DrawText(txt, 0, 0, 7); } return(true); } return(false); }
public static bool TryToValue(this SciterText sciterText, out SciterValue sciterValue) { sciterValue = default; return(sciterText?.TryToValueInternal(sciterValue: out sciterValue) == true); }
public static SciterValue ToValue(this SciterText sciterText) { return(sciterText?.ToValueInternal()); }
public static bool TrySetBox(this SciterText sciterText, float width, float height) { return(sciterText?.TrySetBoxInternal(width: width, height: height) == true); }
public static void SetBox(this SciterText sciterText, float width, float height) { sciterText?.SetBoxInternal(width: width, height: height); }
public static bool TryGetMetrics(this SciterText sciterText, out TextMetrics textMetrics) { textMetrics = default; return(sciterText?.TryGetMetricsInternal(textMetrics: out textMetrics) == true); }
public static TextMetrics GetMetrics(this SciterText sciterText) { return(sciterText?.GetMetricsInternal() ?? default); }