def drawPolygon(self, pointlist, edgeColor=None, edgeWidth=None, fillColor=None, closed=0): eColor = edgeColor or self.defaultLineColor fColor = fillColor or self.defaultFillColor eWidth = edgeWidth or self.defaultLineWidth changed = self._protectArtState((eColor != self.defaultLineColor) or (eWidth != self.defaultLineWidth) or (fColor != self.defaultFillColor)) if eColor != self.defaultLineColor: self._pycan.gstate.stroke = eColor.toHexRGB() if fColor != self.defaultFillColor: self._pycan.gstate.fill = fColor.toHexRGB() if eWidth != self.defaultLineWidth: self._pycan.gstate.stroke_width = eWidth path = pyart.VectorPath(len(pointlist) + 1) if closed: path.moveto_closed(pointlist[0][0], pointlist[0][1]) else: path.moveto_open(pointlist[0][0], pointlist[0][1]) for pt in pointlist[1:]: path.lineto(pt[0], pt[1]) if closed: path.close() if fColor != transparent and closed: self._pycan.fill(path) if eColor != transparent: self._pycan.stroke(path) self._restoreArtState(changed)
def drawLine(self, x1, y1, x2, y2, color=None, width=None): ## standard code ## color = color or self.defaultLineColor width = width or self.defaultLineWidth if color != transparent: changed = self._protectArtState( (color != self.defaultLineColor) or (width != self.defaultLineWidth) ) if color != self.defaultLineColor: self._pycan.gstate.stroke = color.toHexRGB() # print("color is %s <-> %s" % (color, color.toHexStr())) if width != self.defaultLineWidth: self._pycan.gstate.stroke_width = width ################### # actual drawing p = pyart.VectorPath(3) p.moveto_open(x1,y1) p.lineto(x2,y2) self._pycan.stroke(p) ## standard code ## if changed: self._pycan.grestore()