/// <summary> /// 封闭的三角形线帽 /// </summary> /// <param name="pt_start"></param> /// <param name="pt_end"></param> /// <param name="cap_start"></param> /// <param name="cap_end"></param> private void SetTriangleCap(LineCapType lineCapType, Point pt_start, Point pt_end, Polygon cap_start, Polygon cap_end) { double theta = Math.Atan2(pt_start.Y - pt_end.Y, pt_start.X - pt_end.X); double sint = Math.Sin(theta); double cost = Math.Cos(theta); if (lineCapType == LineCapType.LineCap_Start) { cap_start.Points.Add( new Point( pt_start.X - (_arrow.TailWidth * cost - _arrow.TailHeight * sint), pt_start.Y - (_arrow.TailWidth * sint + _arrow.TailHeight * cost)) ); cap_start.Points.Add(new Point(pt_start.X + 20 * cost, pt_start.Y + 20 * sint)); cap_start.Points.Add(new Point( pt_start.X - (_arrow.TailWidth * cost + _arrow.TailHeight * sint), pt_start.Y + (_arrow.TailHeight * cost - _arrow.TailWidth * sint)) ); } if (lineCapType == LineCapType.LineCap_End) { cap_end.Points.Add( new Point( pt_end.X + (_arrow.HeadWidth * cost - _arrow.HeadHeight * sint), pt_end.Y + (_arrow.HeadWidth * sint + _arrow.HeadHeight * cost)) ); cap_end.Points.Add(new Point(pt_end.X - 20 * cost, pt_end.Y - 20 * sint)); cap_end.Points.Add( new Point( pt_end.X + (_arrow.HeadWidth * cost + _arrow.HeadHeight * sint), pt_end.Y - (_arrow.HeadHeight * cost - _arrow.HeadWidth * sint)) ); } }
/// <summary> /// Sets the type of line beginging and ending caps /// </summary> /// <param name="join">Type of the line begin and end caps</param> public void SetCapType(LineCapType cap) { if ((int)CapType != (int)cap) { CapType = (JoinType)cap; HasChanged = true; } }
private ShapeStroke(string name, AnimatableFloatValue offset, IList <AnimatableFloatValue> lineDashPattern, AnimatableColorValue color, AnimatableIntegerValue opacity, AnimatableFloatValue width, LineCapType capType, LineJoinType joinType) { Name = name; DashOffset = offset; LineDashPattern = lineDashPattern; Color = color; Opacity = opacity; Width = width; CapType = capType; JoinType = joinType; }
private void ts_endcap_round_Click(object sender, EventArgs e) { ToolStripMenuItem mi = (ToolStripMenuItem)sender; ts_endcap.Image = mi.Image; LineCapType type = (LineCapType)mi.Tag; CanvasMain.Kernel.SetNewShapePropertyValue(ShapePropertyValueType.EndLineCap, type); proCollector.EndLineCap = type; }
public ShapeStroke(string name, AnimatableFloatValue offset, List <AnimatableFloatValue> lineDashPattern, AnimatableColorValue color, AnimatableIntegerValue opacity, AnimatableFloatValue width, LineCapType capType, LineJoinType joinType, float miterLimit, bool hidden) { Name = name; DashOffset = offset; LineDashPattern = lineDashPattern; Color = color; Opacity = opacity; Width = width; CapType = capType; JoinType = joinType; MiterLimit = miterLimit; IsHidden = hidden; }
internal static PenLineCap LineCapTypeToPaintCap(LineCapType lineCapType) { switch (lineCapType) { case LineCapType.Butt: return(PenLineCap.Flat); case LineCapType.Round: return(PenLineCap.Round); case LineCapType.Unknown: default: return(PenLineCap.Square); } }
internal static CanvasCapStyle LineCapTypeToPaintCap(LineCapType lineCapType) { switch (lineCapType) { case LineCapType.Butt: return(CanvasCapStyle.Flat); case LineCapType.Round: return(CanvasCapStyle.Round); case LineCapType.Unknown: default: return(CanvasCapStyle.Square); } }
public LinearGradientStroke( string name, string matchName, Animatable <double> opacityPercent, Animatable <double> strokeWidth, LineCapType capType, LineJoinType joinType, double miterLimit) : base(name, matchName) { OpacityPercent = opacityPercent; StrokeWidth = strokeWidth; CapType = capType; JoinType = joinType; MiterLimit = miterLimit; }
public SolidColorStroke( string name, string matchName, Animatable <double> dashOffset, IEnumerable <double> dashPattern, Animatable <Color> color, Animatable <double> opacityPercent, Animatable <double> thickness, LineCapType capType, LineJoinType joinType, double miterLimit) : base(name, matchName) { DashOffset = dashOffset; _dashPattern = dashPattern.ToArray(); Color = color; OpacityPercent = opacityPercent; Thickness = thickness; CapType = capType; JoinType = joinType; MiterLimit = miterLimit; }
public void DrawLine_with_lineCap_and_lineJoin(string behaviorName, LineCapType lineCap, LineJoinType lineJoin) { var random = new Random(); _mockBehaviorResolver.Setup(resolver => resolver.GetBehaviorHandler(behaviorName)) .Returns(() => { return(new DrawContentBehavior(_sciterWindow, (element, args) => { if (args.DrawEvent != DrawEvent.Content) { return false; } using (var graphics = SciterGraphics.Create(args.Handle)) { for (var i = 0; i < byte.MaxValue; i++) { graphics.SaveState() .Translate(args.Area.Left, args.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)) .SetLineCap(lineCap) .SetLineJoin(lineJoin) .DrawLine(random.Next(byte.MinValue, args.Area.Width), random.Next(byte.MinValue, args.Area.Height), random.Next(byte.MinValue, args.Area.Width), random.Next(byte.MinValue, args.Area.Height)) .SetLineGradientLinear( 0f, 0f, args.Area.Width / 2f, args.Area.Height, SciterColorStop.Create(0f, (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)), SciterColorStop.Create(.5f, (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)), SciterColorStop.Create(1f, (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))) .DrawLine(random.Next(byte.MinValue, args.Area.Width), random.Next(byte.MinValue, args.Area.Height), random.Next(byte.MinValue, args.Area.Width), random.Next(byte.MinValue, args.Area.Height)) .RestoreState(); } } element?.Window?.Close(); return true; })); }); _ = new TestableSciterHost(_sciterWindow) .SetBehaviorResolver(_mockBehaviorResolver.Object); _sciterWindow.Show(); _sciterWindow.RootElement.AppendElement("body", elm => elm) .SetStyleValue("background", $"rgb({random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)}, {random.Next(byte.MinValue, byte.MaxValue)})") .SetStyleValue("behavior", behaviorName); SciterPlatform.RunMessageLoop(); //Assert.NotNull(_sciterGraphics); }
public void Polyline(string behaviorName, LineCapType lineCap, LineJoinType lineJoin) { 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)) .SetLineCap(lineCap) .SetLineJoin(lineJoin) .SetLineWidth(random.Next(2, 10)) .DrawPolyline(() => { var result = new List <PolylinePoint>(); for (var j = 0; j < random.Next(3, 12); j++) { result.Add(PolylinePoint.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); }
public static bool TrySetLineCap(this SciterGraphics graphics, LineCapType capType) { return(graphics?.TrySetLineCapInternal(capType: capType) == true); }
public static SciterGraphics SetLineCap(this SciterGraphics graphics, LineCapType capType) { graphics?.SetLineCapInternal(capType: capType); return(graphics); }