private void DrawPathWithXRenderCompositeTriStrip(Color color, int width, Point[] points) { if (width == 0) { width = 1; } XRenderColor xColor = new XRenderColor(color); // todo: cache brush ulong brush = LibXRender.XRenderCreateSolidFill(display, ref xColor); try { XPointFixed[] stripPoints = new XPointFixed[(points.Length - 1) * 3 + 1]; for (int i = 1, t = 0, m = 1; i < points.Length; i++, m = -m) { Point p1 = points[i - 1]; Point p2 = points[i]; p1.Offset(-origin.X, -origin.Y); p2.Offset(-origin.X, -origin.Y); int dx = p2.X - p1.X; int dy = p2.Y - p1.Y; double len = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)); // todo: handle 0 points and zero-length segments int ox = Convert.ToInt32(-dy / len * 32768 * width) * m; int oy = Convert.ToInt32(dx / len * 32768 * width) * m; if (i == 1) { // todo: handle separately without if stripPoints[t++] = new XPointFixed { x = (p1.X << 16) + ox, y = (p1.Y << 16) + oy }; } stripPoints[t++] = new XPointFixed { x = (p1.X << 16) - ox, y = (p1.Y << 16) - oy }; stripPoints[t++] = new XPointFixed { x = (p2.X << 16) + ox, y = (p2.Y << 16) + oy }; stripPoints[t++] = new XPointFixed { x = (p2.X << 16) - ox, y = (p2.Y << 16) - oy }; } LibXRender.XRenderCompositeTriStrip(display, PictOp.PictOpOver, brush, pictureId, pictFormatPtr, 0, 0, stripPoints, stripPoints.Length); } finally { LibXRender.XRenderFreePicture(display, brush); } }
private void DrawPathWithXRenderCompositeDoublePoly(Color color, int width, Point[] points) { if (width == 0) { width = 1; } XRenderColor xColor = new XRenderColor(color); // todo: cache brush ulong brush = LibXRender.XRenderCreateSolidFill(display, ref xColor); try { XPointDouble[] polyPoints = new XPointDouble[points.Length * 2]; for (int i = 1, t = polyPoints.Length - 2; i < points.Length; i++, t--) { Point p1 = points[i - 1]; Point p2 = points[i]; p1.Offset(-origin.X, -origin.Y); p2.Offset(-origin.X, -origin.Y); int dx = p2.X - p1.X; int dy = p2.Y - p1.Y; double len = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)); double ox = -dy / len * width / 2; double oy = dx / len * width / 2; polyPoints[i] = new XPointDouble { x = points[i].X + ox, y = points[i].Y + oy }; polyPoints[t] = new XPointDouble { x = points[i].X - ox, y = points[i].Y - oy }; if (i == 1) { // todo: handle separately without if polyPoints[0] = new XPointDouble { x = points[0].X + ox, y = points[0].Y + oy }; polyPoints[polyPoints.Length - 1] = new XPointDouble { x = points[0].X - ox, y = points[0].Y - oy }; } } LibXRender.XRenderCompositeDoublePoly(display, PictOp.PictOpOver, brush, pictureId, pictFormatPtr, 0, 0, 0, 0, polyPoints, polyPoints.Length, 1); } finally { LibXRender.XRenderFreePicture(display, brush); } }