Example #1
0
 def pixelSizeOf(self, text):
     screen_height = gl2D.screenSize()[1]
     cx = 0; cy = 0
     last_character = 0
     current_page = 0
     texwidth = self.texture_pages[current_page].width
     texheight = self.texture_pages[current_page].height
     for c in text:
         if ord(c) == 10:
             cy += self.size
             cx = x
             continue
         try:
             ch = self.chars[ord(c)]
         except KeyError:
             ch = self.chars[0]
         kerning_key = (last_character,ch.id)
         if kerning_key in self.kerning:
             k_amt = self.kerning[ kerning_key ]
             cx += int(k_amt)
         if ch.page != current_page:
             current_page = ch.page
             texwidth = self.texture_pages[current_page].width
             texheight = self.texture_pages[current_page].height
         cx += ch.xadvance
         last_character = ord(c)
     return (cx, cy)
Example #2
0
 def pixelSizeOf(self, text):
     screen_height = gl2D.screenSize()[1]
     cx = 0
     cy = 0
     last_character = 0
     current_page = 0
     texwidth = self.texture_pages[current_page].width
     texheight = self.texture_pages[current_page].height
     for c in text:
         if ord(c) == 10:
             cy += self.size
             cx = x
             continue
         try:
             ch = self.chars[ord(c)]
         except KeyError:
             ch = self.chars[0]
         kerning_key = (last_character, ch.id)
         if kerning_key in self.kerning:
             k_amt = self.kerning[kerning_key]
             cx += int(k_amt)
         if ch.page != current_page:
             current_page = ch.page
             texwidth = self.texture_pages[current_page].width
             texheight = self.texture_pages[current_page].height
         cx += ch.xadvance
         last_character = ord(c)
     return (cx, cy)
Example #3
0
def drawQuad( texwidth, texheight, dx, dy, sx, sy, sw, sh ):
    u1 = float(sx)/texwidth
    v1 = float(sy)/texheight
    u2 = float((sx+sw))/texwidth
    v2 = float((sy+sh))/texheight
    y = gl2D.screenSize()[1] - dy

    glTexCoord2f( u1, v2 )
    glVertex3f( dx, y-sh, -.1 )
    glTexCoord2f( u2, v2 )
    glVertex3f(  dx+sw, y-sh, -.1 )
    glTexCoord2f( u2, v1 )
    glVertex3f(  dx+sw, y, -.1 )
    glTexCoord2f( u1, v1 )
    glVertex3f( dx, y, -.1 )
Example #4
0
def drawQuad(texwidth, texheight, dx, dy, sx, sy, sw, sh):
    u1 = float(sx) / texwidth
    v1 = float(sy) / texheight
    u2 = float((sx + sw)) / texwidth
    v2 = float((sy + sh)) / texheight
    y = gl2D.screenSize()[1] - dy

    glTexCoord2f(u1, v2)
    glVertex3f(dx, y - sh, -.1)
    glTexCoord2f(u2, v2)
    glVertex3f(dx + sw, y - sh, -.1)
    glTexCoord2f(u2, v1)
    glVertex3f(dx + sw, y, -.1)
    glTexCoord2f(u1, v1)
    glVertex3f(dx, y, -.1)
Example #5
0
    def drawPrim(self, x, y, text, max_width=None ):
        screen_height = gl2D.screenSize()[1]
        gl2D.start2D()
        cx = x
        cy = y
        last_character = 0
        current_page = 0
        self.texture_pages[current_page].bind()
        texwidth = self.texture_pages[current_page].width
        texheight = self.texture_pages[current_page].height
        glPushMatrix()
        glTranslatef(cx, screen_height-cy, 0)
        #glBegin(GL_QUADS)
        for c in text:
            if ord(c) == 10:
                cy += self.size
                glTranslatef( -(cx-x), -self.size, 0)
                cx = x
                continue
            ch = self.chars[ord(c)]
            kerning_key = (last_character,ch.id)
            if kerning_key in self.kerning:
                k_amt = self.kerning[ kerning_key ]
                cx += int(k_amt)
                glTranslatef(cx, 0, 0)

            if ch.page != current_page:
                current_page = ch.page
                self.texture_pages[current_page].bind()
                texwidth = self.texture_pages[current_page].width
                texheight = self.texture_pages[current_page].height

            #gl2D.drawSubTexture2D( self.texture_pages[current_page],  cx + ch.xoffset, cy + ch.yoffset, ch.x, ch.y, ch.width, ch.height )
            #drawQuad( texwidth, texheight, cx+ch.xoffset, cy+ch.yoffset, ch.x, ch.y, ch.width, ch.height )
            #glPushMatrix()
            #glTranslatef(cx, screen_height-cy, 0)
            if max_width and (cx-x)+ch.xadvance > max_width:
                break
            ch.draw()
            #glPopMatrix()
            cx += ch.xadvance

            glTranslatef( ch.xadvance, 0, 0 )
            last_character = ord(c)
        #glEnd()
        glPopMatrix()
        gl2D.end2D()
        return (cx, cy)
Example #6
0
    def drawPrim(self, x, y, text, max_width=None):
        screen_height = gl2D.screenSize()[1]
        gl2D.start2D()
        cx = x
        cy = y
        last_character = 0
        current_page = 0
        self.texture_pages[current_page].bind()
        texwidth = self.texture_pages[current_page].width
        texheight = self.texture_pages[current_page].height
        glPushMatrix()
        glTranslatef(cx, screen_height - cy, 0)
        #glBegin(GL_QUADS)
        for c in text:
            if ord(c) == 10:
                cy += self.size
                glTranslatef(-(cx - x), -self.size, 0)
                cx = x
                continue
            ch = self.chars[ord(c)]
            kerning_key = (last_character, ch.id)
            if kerning_key in self.kerning:
                k_amt = self.kerning[kerning_key]
                cx += int(k_amt)
                glTranslatef(cx, 0, 0)

            if ch.page != current_page:
                current_page = ch.page
                self.texture_pages[current_page].bind()
                texwidth = self.texture_pages[current_page].width
                texheight = self.texture_pages[current_page].height

            #gl2D.drawSubTexture2D( self.texture_pages[current_page],  cx + ch.xoffset, cy + ch.yoffset, ch.x, ch.y, ch.width, ch.height )
            #drawQuad( texwidth, texheight, cx+ch.xoffset, cy+ch.yoffset, ch.x, ch.y, ch.width, ch.height )
            #glPushMatrix()
            #glTranslatef(cx, screen_height-cy, 0)
            if max_width and (cx - x) + ch.xadvance > max_width:
                break
            ch.draw()
            #glPopMatrix()
            cx += ch.xadvance

            glTranslatef(ch.xadvance, 0, 0)
            last_character = ord(c)
        #glEnd()
        glPopMatrix()
        gl2D.end2D()
        return (cx, cy)