Пример #1
0
    def render(self, text, antialias=True, color=(0,0,0), background=None, surface=None):      #optional surface for text rendering
        """
        Render text onto surface.
        Arguments are text to render, and optional antialias, RGB color of text, RGB color of background, and surface for text rendering.
        """
        if not surface:
            w,h = self.size(text)
            surf = Surface((w,h))
        else:
            surf = surface
            w,h = surface.width, surface.height
        if background:
            surf.setFillStyle(Color(background))
            surf.fillRect(0,0,w,h)
        surf.setFont('%s %dpx %s' % (self.fontstyle, self.fontsize, self.fontname))
#        if antialias: pass
        surf.setFillStyle(Color(color))
        surf.setTextAlign('center')
        surf.setTextBaseline('middle')
        surf.fillText(text,w/2,h/2)
        if self.underline:
            surf.setLineWidth(self.fontsize/20)
            surf.setStrokeStyle(Color(color))
            surf.beginPath()
            surf.moveTo(0, h*0.85)
            surf.lineTo(w, h*0.85)
            surf.stroke()
        return surf
Пример #2
0
def create_cursor(size, data, mask):
    """
    Create cursor image from binary data.
    Arguments cursor size and its binary data and mask.
    Return surface, can be used with mouse.set_cursor.
    """
    surface = Surface(size, Const.SRCALPHA)
    black = Color(0, 0, 0, 255)
    white = Color(255, 255, 255, 255)
    x = y = 0
    rang = range(8)
    for i in range(len(data)):
        if data[i] or mask[i]:
            for j in rang:
                if data[i] & 0x01 << 7 - j:
                    surface.setFillStyle(black)
                    surface.fillRect(x + j, y, 1, 1)
                elif mask[i] & 0x01 << 7 - j:
                    surface.setFillStyle(white)
                    surface.fillRect(x + j, y, 1, 1)
        x += 8
        if x >= size[0]:
            x = 0
            y += 1
    return surface
Пример #3
0
 def render(self,
            text,
            antialias=True,
            color=(0, 0, 0),
            background=None,
            surface=None):  #optional surface for text rendering
     """
     Render text onto surface.
     Arguments are text to render, and optional antialias, RGB color of text, RGB color of background, and surface for text rendering.
     """
     if not surface:
         w, h = self.size(text)
         surf = Surface((w, h))
     else:
         surf = surface
         w, h = surface.width, surface.height
     if background:
         surf.setFillStyle(Color(background))
         surf.fillRect(0, 0, w, h)
     surf.setFont('%s %dpx %s' %
                  (self.fontstyle, self.fontsize, self.fontname))
     #        if antialias: pass
     surf.setFillStyle(Color(color))
     surf.setTextAlign('center')
     surf.setTextBaseline('middle')
     surf.fillText(text, w / 2, h / 2)
     if self.underline:
         surf.setLineWidth(self.fontsize / 20)
         surf.setStrokeStyle(Color(color))
         surf.beginPath()
         surf.moveTo(0, h * 0.85)
         surf.lineTo(w, h * 0.85)
         surf.stroke()
     return surf
Пример #4
0
def create_cursor(size, data, mask):
    """
    Create cursor image from binary data.
    Arguments cursor size and its binary data and mask.
    Return surface, can be used with mouse.set_cursor.
    """
    surface = Surface(size, Const.SRCALPHA)
    black = Color(0, 0, 0, 255)
    white = Color(255, 255, 255, 255)
    x = y = 0
    rang = range(8)
    for i in range(len(data)):
        if data[i] or mask[i]:
            for j in rang:
                if data[i] & 0x01 << 7 - j:
                    surface.setFillStyle(black)
                    surface.fillRect(x + j, y, 1, 1)
                elif mask[i] & 0x01 << 7 - j:
                    surface.setFillStyle(white)
                    surface.fillRect(x + j, y, 1, 1)
        x += 8
        if x >= size[0]:
            x = 0
            y += 1
    return surface