protected override bool OnDraw(SciterElement se, DrawArgs args) { if (args.DrawEvent == DrawEvent.Content) { using (var graphics = SciterGraphics.Create(args.Handle)) { graphics.SaveState() .Translate(args.Area.Left, args.Area.Top) .SetLineColor(SciterColor.Create(0, 255, 255, .75f)) .SetFillColor(SciterColor.Create(127, 78, 194, .75f)) .SetLineWidth(4) .DrawPolygon( PolygonPoint.Create(51.0f, 58.0f), PolygonPoint.Create(70.0f, 28.0f), PolygonPoint.Create(48.0f, 1.0f), PolygonPoint.Create(15.0f, 14.0f), PolygonPoint.Create(17.0f, 49.0f) ) .DrawEllipse(200, 50, 50, 50) .RestoreState(); } return(true); } return(false); }
public void PolygonPoint_create(float x, float y) { var point = PolygonPoint.Create(x, y); Assert.AreEqual(x, point.X); Assert.AreEqual(y, point.Y); }
protected override bool OnDraw(SciterElement se, DrawArgs args) { if (args.DrawEvent == DrawEvent.Content) { using (var graphics = SciterGraphics.Create(args.Handle)) { graphics .SaveState() .Translate(args.Area.Left, args.Area.Top) .SetLineColor(0, 255, 255, .75f) .SetFillColor(127, 78, 194, .75f) .SetLineWidth(4) .DrawPolygon( PolygonPoint.Create(51.0f, 58.0f), PolygonPoint.Create(70.0f, 28.0f), PolygonPoint.Create(48.0f, 1.0f), PolygonPoint.Create(15.0f, 14.0f), PolygonPoint.Create(17.0f, 49.0f) ) .SetLineWidth(2) .SetLineColor(SciterColor.IndianRed) .SetFillColor(SciterColor.CornflowerBlue) .DrawRectangle(25, 125, 75, 175) .SetLineColor(SciterColor.Goldenrod) .DrawLine(50, 125, 50, 175) .DrawLine(25, 150, 75, 150) .SetLineWidth(0) .SetLineColor(127, 78, 194, .75f) .SetFillColor(0, 255, 255, .75f) .DrawEllipse(200, 50, 50, 50) .SetFillColor(127, 78, 194, .75f) .DrawEllipse(225, 100, 50, 50) .SetFillColor(255, 0, 0, 127) .DrawEllipse(175, 100, 50, 50) .RestoreState(); } return(true); } return(false); }
public void Polygon(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 (int i = 0; i < byte.MaxValue; i++) { graphics.SaveState() .Translate(prms.Area.Left, prms.Area.Top) .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)) .DrawPolygon((g) => { var result = new List <PolygonPoint>(); for (var j = 0; j < random.Next(3, 12); j++) { result.Add(PolygonPoint.Create( random.Next(byte.MinValue, prms.Area.Width), random.Next(byte.MinValue, prms.Area.Height))); } return result; }) .RestoreState(); } } element?.Window?.Close(); return true; })); }); _ = new TestableSciterHost(_sciterWindow) .SetBehaviorResolver(_mockBehaviorResolver.Object); _sciterWindow.Show(); var backgroundColor = random.Next(byte.MinValue, 80); _sciterWindow.RootElement.AppendElement("body", elm => elm) .SetStyleValue("background", $"rgb({backgroundColor}, {backgroundColor}, {backgroundColor})") .SetStyleValue("behavior", behaviorName); SciterPlatform.RunMessageLoop(); //Assert.NotNull(_sciterGraphics); }
private void DrawCirclesClock( SciterGraphics graphics, SciterRectangle area, float scale, DateTime timeInfo) { var markColor = SciterColor.Parse("#969696"); var hourColor = SciterColor.Parse("#969696"); var minuteColor = SciterColor.Parse("#969696"); var secondColor = SciterColor.Parse("#64C439"); graphics .SaveState() .Translate(area.Left + area.Width / 2.0f, area.Top + area.Height / 2.0f) .Scale(scale, scale) .Rotate(-Pi / 2) .SetLineColor(SciterColor.Transparent) .SetLineCap(LineCapType.Square); int sec = timeInfo.Second; int min = timeInfo.Minute; int hr = timeInfo.Hour; hr = hr >= 12 ? hr - 12 : hr; // Background graphics .SaveState() .Translate(0, 0) .SetLineColor(SciterColor.Transparent) .SetFillGradientLinear(0f, 75f, 150f, 75f, SciterColorStop.Create(0f, SciterColor.Parse("#242424")), SciterColorStop.Create(1f, SciterColor.Parse("#545454"))) .DrawEllipse(0, 0, 150, 150) .SetFillColor(SciterColor.Transparent) .SetLineColor(minuteColor) .DrawEllipse(0, 0, 150, 150) .RestoreState(); graphics .SaveState() .Translate(-(area.Height / 3.0f), 0) .SetLineWidth(2f) .SetLineColor(SciterColor.Black) .SetFillColor(SciterColor.Parse("#222222")) .DrawEllipse(0, 0, 50, 50) .SetLineColor(markColor) .Using(@ref => { for (var i = 0; i < 12; ++i) { @ref .Rotate(Pi / 6, 0, 0) .DrawLine(34, 0, 44f, 0); } }) .RestoreState(); graphics .SaveState() .Translate(-(area.Height / 3.0f), 0) .SetLineColor(secondColor) .Using(@ref => { @ref .SetLineWidth(2f) .SetLineColor(markColor); for (var i = 0; i < 60; ++i) { if (i % 5 != 0) { @ref.DrawLine(40f, 0, 44f, 0); } @ref.Rotate(Pi / 30f); } }) .RestoreState(); graphics .SaveState() .Translate(-(area.Height / 3.0f), 0) .Rotate(sec * Pi / 30) .SetLineColor(secondColor) .SetFillColor(secondColor) .SetLineWidth(2f) .DrawLine(0, 0, 44, 0) .DrawEllipse(0, 0, 3, 3) .RestoreState(); // Hour marks graphics .SaveState() .SetLineColor(markColor) .Using(@ref => { for (var i = 0; i < 12; ++i) { @ref.Rotate(Pi / 6, 0, 0); if (new [] { 2, 5, 8, 11 }.Contains(i)) { @ref .SetLineWidth(8f) .DrawLine(125f, 0, 142f, 0); } else { @ref .SetLineWidth(2f) .DrawLine(125f, 0, 145f, 0); } } }) .RestoreState(); // Minute marks graphics .SaveState() .SetLineWidth(2f) .SetLineColor(markColor) .Using(@ref => { for (var i = 0; i < 60; ++i) { if (i % 5 != 0) { @ref.DrawLine(138f, 0, 144f, 0); } @ref.Rotate(Pi / 30f); } }) .SetLineColor(minuteColor) .DrawEllipse(0, 0, 150, 150) .RestoreState(); // draw Hours graphics.SaveState() .Rotate(hr * (Pi / 6) + (Pi / 360) * min + (Pi / 21600) * sec) .SetLineWidth(1f) .SetFillGradientLinear(50f, -3f, 50f, 3f, SciterColorStop.Create(0f, SciterColor.Parse("#c4c4c4")), SciterColorStop.Create(1f, SciterColor.Parse("#B2B2B2"))) .DrawPolygon(() => new List <PolygonPoint>() { PolygonPoint.Create(0f, -3f), PolygonPoint.Create(90f, -3f), PolygonPoint.Create(100f, 0f), PolygonPoint.Create(90f, 3f), PolygonPoint.Create(0f, 3f), }) //.SetLineWidth(0f) //.DrawEllipse(0, 0, 10, 10) .RestoreState(); // draw Minutes graphics .SaveState() .Rotate((Pi / 30) * min + (Pi / 1800) * sec) //.SetLineColor(SciterColor.Transparent) //.SetLineWidth(0f) //.SetFillColor(SciterColor.Create(0, 0, 0, .5f)) //.DrawEllipse(0, 0, 10, 10) .SetLineWidth(1f) .SetLineColor(minuteColor) .SetFillColor(minuteColor) .SetFillGradientLinear(65, -3f, 65f, 3f, SciterColorStop.Create(0f, SciterColor.Parse("#c4c4c4")), SciterColorStop.Create(1f, SciterColor.Parse("#B2B2B2"))) .DrawPolygon(() => new List <PolygonPoint>() { PolygonPoint.Create(0, -3), PolygonPoint.Create(120, -3), PolygonPoint.Create(130, 0), PolygonPoint.Create(120, 3), PolygonPoint.Create(0, 3), }) .DrawEllipse(0, 0, 8, 8) .SetLineColor(SciterColor.Parse("#686868")) .SetFillColor(SciterColor.Parse("#2E2E2E")) .SetLineWidth(2f) .DrawEllipse(0, 0, 4, 4) //.SetLineWidth(1f) .RestoreState(); // Outer ring graphics .SaveState() .SetLineColor(minuteColor) .DrawEllipse(0, 0, 150, 150) .RestoreState(); graphics.RestoreState(); }