示例#1
0
def paintGraph(cairo, win, draw, loss, rect):
    x, y, w, h = rect.x, rect.y, rect.width, rect.height

    cairo.save()
    cairo.rectangle(x, y, ceil(win * w), h)
    cairo.clip()
    pathBlock(cairo, x, y, w, h)
    cairo.set_source_rgb(0.9, 0.9, 0.9)
    cairo.fill()
    cairo.restore()

    cairo.save()
    cairo.rectangle(x + win * w, y, ceil(draw * w), h)
    cairo.clip()
    pathBlock(cairo, x, y, w, h)
    cairo.set_source_rgb(0.45, 0.45, 0.45)
    cairo.fill()
    cairo.restore()

    cairo.save()
    cairo.rectangle(x + win * w + draw * w, y, loss * w, h)
    cairo.clip()
    pathBlock(cairo, x, y, w, h)
    cairo.set_source_rgb(0, 0, 0)
    cairo.fill()
    cairo.restore()

    cairo.save()
    cairo.rectangle(x, y, w, h)
    cairo.clip()
    pathBlock(cairo, x, y, w, h)
    cairo.set_source_rgb(1, 1, 1)
    cairo.stroke()
    cairo.restore()
def paintGraph (cairo,win,draw,loss,rect):
    x,y,w,h = rect.x, rect.y, rect.width, rect.height

    cairo.save()
    cairo.rectangle(x,y,ceil(win*w),h)
    cairo.clip()
    pathBlock(cairo, x,y,w,h)
    cairo.set_source_rgb(0.9,0.9,0.9)
    cairo.fill()
    cairo.restore()
    
    cairo.save()
    cairo.rectangle(x+win*w,y,ceil(draw*w),h)
    cairo.clip()
    pathBlock(cairo, x,y,w,h)
    cairo.set_source_rgb(0.45,0.45,0.45)
    cairo.fill()
    cairo.restore()
    
    cairo.save()
    cairo.rectangle(x+win*w+draw*w,y,loss*w,h)
    cairo.clip()
    pathBlock(cairo, x,y,w,h)
    cairo.set_source_rgb(0,0,0)
    cairo.fill()
    cairo.restore()
    
    cairo.save()
    cairo.rectangle(x,y,w,h)
    cairo.clip()
    pathBlock(cairo, x,y,w,h)
    cairo.set_source_rgb(1,1,1)
    cairo.stroke()
    cairo.restore()
    def draw(self, cairo):
        cairo.set_source_rgb(1.0,1.0,1.0)
        cairo.rectangle(0,0,self.width/pixel_per_mm,self.height/pixel_per_mm)
        cairo.fill()

        cairo.set_line_width(self.lw)
        cairo.set_source_rgb(obstacle_color[0], obstacle_color[1], obstacle_color[2])
        cairo.move_to(0,self.lw/2)
        cairo.line_to(self.width/pixel_per_mm,self.lw/2)

        cairo.move_to(self.width/pixel_per_mm-self.lw/2,0)
        cairo.line_to(self.width/pixel_per_mm-self.lw/2,self.height/pixel_per_mm)

        cairo.move_to(self.width/pixel_per_mm,self.height/pixel_per_mm-self.lw/2)
        cairo.line_to(0,self.height/pixel_per_mm-self.lw/2)

        cairo.move_to(self.lw/2,self.height/pixel_per_mm)
        cairo.line_to(self.lw/2,0)

        cairo.stroke()
        cairo.set_line_width(2.0)
示例#4
0
    def _render_polygon(self, f, data, pxlsz, ss):
        c = self._slatectx
        c.set_operator(cr.OPERATOR_OVER)
        c.move_to(*self.imgcoords(*f.coords[0]))
        for x, y in f.exterior.coords[1:]:
            c.line_to(self.imgcoords(x,y))
        c.close_path()

        for interior in f.interiors:
            c.new_sub_path()
            c.move_to(*self.imgcoords(*f.coords[0]))
            for x, y in f.exterior.coords[1:]:
                c.line_to(self.imgcoords(x,y))
            c.close_path()

        if ss.style_fill(c, data, pxlsz):
            cr.fill_preserve()
        if ss.style_stroke(c, data, pxlsz):
            cr.stroke()
        
        label = ss.get_label(data)
        if label and len(label) > 0 and ss.style_label(c, data, pxlsz):
            anchor = self.imgcoords(*f.representative_point())
            xbear, ybear, width, height, _0, _1 = cr.text_extents(label)
            width = width * pxlsz[0]
            xoff = -(width+xbear) / 2.0
            yoff = (height-ybear) / 2.0
            c.move_to(anchor[0]+xoff, anchor[1]+yoff)

            if ss.style_labelhalo(c, data, pxlsz):
                c.text_path(label)
                c.stroke()
            
            c.text_path(label)
            if ss.style_labelfill(c, data, pxlsz):
                c.fill_preserve()
            if ss.style_labelstroke(c, data, pxlsz):
                c.stroke()
示例#5
0
    def _render_polygon(self, f, data, pxlsz, ss):
        c = self._slatectx
        c.set_operator(cr.OPERATOR_OVER)
        c.move_to(*self.imgcoords(*f.coords[0]))
        for x, y in f.exterior.coords[1:]:
            c.line_to(self.imgcoords(x, y))
        c.close_path()

        for interior in f.interiors:
            c.new_sub_path()
            c.move_to(*self.imgcoords(*f.coords[0]))
            for x, y in f.exterior.coords[1:]:
                c.line_to(self.imgcoords(x, y))
            c.close_path()

        if ss.style_fill(c, data, pxlsz):
            cr.fill_preserve()
        if ss.style_stroke(c, data, pxlsz):
            cr.stroke()

        label = ss.get_label(data)
        if label and len(label) > 0 and ss.style_label(c, data, pxlsz):
            anchor = self.imgcoords(*f.representative_point())
            xbear, ybear, width, height, _0, _1 = cr.text_extents(label)
            width = width * pxlsz[0]
            xoff = -(width + xbear) / 2.0
            yoff = (height - ybear) / 2.0
            c.move_to(anchor[0] + xoff, anchor[1] + yoff)

            if ss.style_labelhalo(c, data, pxlsz):
                c.text_path(label)
                c.stroke()

            c.text_path(label)
            if ss.style_labelfill(c, data, pxlsz):
                c.fill_preserve()
            if ss.style_labelstroke(c, data, pxlsz):
                c.stroke()