Пример #1
0
    def draw(self, cr, hover=None):
        if hover is not None:
            hover, Hside = hover
        
        set_fonts(cr, * self._cells[0][1][:2] )
        for i, ((cx, cy, ch, ck), textline) in enumerate(self._cells):
            count = self._table[i][0]
            if count: # nonzero count
                if count > 0:
                    R = range(count)
                    bg = accent
                else:
                    R = reversed(range(0, count, -1))
                    bg = negative_accent
                for c in R:
                    cr.set_source_rgba(1, 1, 1, 0.5)
                    cr.rectangle(cx + 2*c - 1, cy - 2*c + 1, ch, ck)
                    cr.fill()
                    cr.set_source_rgb( * bg )
                    cr.rectangle(cx + 2*c, cy - 2*c, ch, ck)
                    cr.fill()
                
                offset = max(0, (count - 1) * 2)
                
                cr.set_source_rgb(1, 1, 1)
                cr.show_glyphs((g[0], g[1] + offset, g[2] - offset) for g in textline[2])
                minus_sign(cr, cx - 2 + offset, cy - 1 - offset)
                plus_sign(cr, cx + ch - 24 + offset, cy - 1 - offset)
                
                cr.fill()
                continue
            
            elif hover == i:
                minus_sign(cr, cx - 2, cy)
                if Hside:
                    cr.set_source_rgba(0, 0, 0, 0.7)
                else:
                    cr.set_source_rgb( * accent )
                cr.fill()

                plus_sign(cr, cx + ch - 24, cy)
                if Hside:
                    cr.set_source_rgb( * accent )
                else:
                    cr.set_source_rgba(0, 0, 0, 0.7)
                cr.fill()

                cr.set_source_rgb( * accent )
                cr.show_glyphs(textline[2])
            
            else:
                cr.set_source_rgba(0, 0, 0, 0.7)
                cr.show_glyphs(textline[2])
Пример #2
0
 def draw(self, cr, hover=None):
     if hover is None:
         ink = (1, 1, 1), (0.4, 0.4, 0.4), (0.4, 0.4, 0.4), negative_accent
     else:
         ink = (1, 1, 1), (0  , 0  , 0  ), (0.2, 0.2, 0.2), negative_accent_dark
     if self._state:
         half_pi = pi*0.5
         radius = 13
         centerline = self._from_top + 13
         cr.arc(self._zero + radius - 6, centerline, radius,  half_pi, -half_pi)
         cr.arc( self._one - radius + 6, centerline, radius, -half_pi,  half_pi)
         cr.close_path()
         ink = ink[2 + (self._state < 0)], ink[0]
         cr.set_source_rgba( * ink[0] )
         cr.fill()
         hover = None
     
     inks = [ink[1]] * 3
     if hover is not None:
         inks[hover - 1] = accent
     
     cr.set_source_rgba( * inks[0] )
     show_text(cr, self._label)
     if self._state < 0:
         cr.fill()
         cr.set_line_width(2)
         cross(cr, self._anchors[0], self._from_top)
         cr.stroke()
     else:
         show_text(cr, self._number)
         cr.fill()
     
     cr.set_source_rgba( * inks[1] )
     minus_sign(cr, self._anchors[2] - 6, self._from_top)
     cr.fill()
     
     cr.set_source_rgba( * inks[2] )
     plus_sign (cr, self._anchors[3] - 6, self._from_top)
     cr.fill()