Exemplo n.º 1
0
    def __init__(self, font, camera, max_chars=100, point_size=48):
        """ Arguments:
    *font*:
      A PointFont object.
    *camera*:
      camera to use for drawing the text.  Normally a fixed 2d camera.
    *max_chars*:
      maximum number of chars, which determines the number of points in the buffer
    *point_size*:
      size of "default" characters created using the Points class and the
      font. This is further scaled by the TextBlock.size
      This refinement is needed to allow pointsize to be different in Points from
      Font to avoid clipping or overlap of corners when rotation some truetype fonts
    """
        self.max_chars = max_chars
        self.font = font
        self.shader = Shader("uv_pointsprite")

        self.locations = np.zeros((max_chars, 3))
        # :,2 for size and z offset.
        # size=fract(location[2] range 0.0 to 0.999)
        # zoffset = (location[2] - size)*0.1

        self.normals = np.zeros((max_chars, 3))
        # :,0 for rotation
        # :,1 for red and green, red=normal[1]/999, green=fract(normal[1])
        # :,2 for blue and alpha, blue=normal[2]/999, alpha=fract(normal[2])
        self.normals[:, 1] = 0.0
        self.normals[:, 2] = 0.0
        self.uv = np.zeros((max_chars, 2))  # u picnum.u v

        self.text_blocks = []
        self._first_free_char = 0
        self._do_buffer_reinit = False

        self.point_size = point_size
        self.text = Points(camera=camera,
                           vertices=self.locations,
                           normals=self.normals,
                           tex_coords=self.uv,
                           point_size=self.point_size)
        self.text.set_draw_details(self.shader, [self.font])
        self.text.unif[
            48] = 0.058  # used to hold "patch size" passed to shader
        #Reset all characters to space so there are no false character shadows
        try:
            glyph = self.font.glyph_table[
                ' ']  #u' ' doesn't work on python3.2!!
        except:
            glyph = list(
                self.font.glyph_table.values())[0]  #in case ' ' isn't there
        self.uv[:] = glyph[0:2]
Exemplo n.º 2
0
    def __init__(self, font, camera, max_chars = 100):
        """ Arguments:
        *font*:
          A PointFont object.
        *fmax_chars*:
          maximum number of chars which determines the number of points in the buffer
        """
        self.max_chars = max_chars
        self.font = font

        self.shader = Shader("shaders/uv_fontmult")
        
        self.locations = np.zeros((max_chars, 3))
        # :,2 for size range 0.0 to 0.999           

        self.normals = np.zeros((max_chars, 3))
        # :,0 for rotation
        # :,1 for alpha
        self.normals[:,1] = 0.0
        self.normals[:,2] = 0.057
        """  :,2 for sub-size i.e 64x64 images on 1024x1024 image each is 0.0625 
        there is margin on each side to avoidproblems with overlapping on rotations.
        """
        self.uv = np.zeros((max_chars, 2)) # u picnum.u v

        self.text = None
        
        self.text_blocks = []
        
        self.text = Points(camera=camera, vertices=self.locations, normals=self.normals, tex_coords=self.uv,
                       point_size=self.font.height)
        self.text.set_draw_details(self.shader, [self.font])
Exemplo n.º 3
0
  def __init__(self, font, camera, max_chars=100, point_size=48):
    """ Arguments:
    *font*:
      A PointFont object.
    *camera*:
      camera to use for drawing the text.  Normally a fixed 2d camera.
    *max_chars*:
      maximum number of chars, which determines the number of points in the buffer
    *point_size*:
      size of "default" characters created using the Points class and the
      font. This is further scaled by the TextBlock.size
      This refinement is needed to allow pointsize to be different in Points from
      Font to avoid clipping or overlap of corners when rotation some truetype fonts
    """
    self.max_chars = max_chars
    self.font = font
    self.shader = Shader("uv_pointsprite")
    
    self.locations = np.zeros((max_chars, 3))
    # :,2 for size and z offset. 
    # size=fract(location[2] range 0.0 to 0.999)
    # zoffset = (location[2] - size)*0.1

    self.normals = np.zeros((max_chars, 3))
    # :,0 for rotation
    # :,1 for red and green, red=normal[1]/999, green=fract(normal[1])
    # :,2 for blue and alpha, blue=normal[2]/999, alpha=fract(normal[2])    
    self.normals[:,1] = 0.0
    self.normals[:,2] = 0.0
    self.uv = np.zeros((max_chars, 2)) # u picnum.u v

    self.text_blocks = []
    self._first_free_char = 0
    self._do_buffer_reinit = False

    self.point_size = point_size
    self.text = Points(camera=camera, vertices=self.locations, normals=self.normals,
                       tex_coords=self.uv, point_size=self.point_size)
    self.text.set_draw_details(self.shader, [self.font])
    self.text.unif[48] = 0.058  # used to hold "patch size" passed to shader
    #Reset all characters to space so there are no false character shadows
    try:
      glyph = self.font.glyph_table[' '] #u' ' doesn't work on python3.2!!
    except:
      glyph = list(self.font.glyph_table.values())[0] #in case ' ' isn't there
    self.uv[:] = glyph[0:2]
Exemplo n.º 4
0
    def __init__(self, font, camera, max_chars = 100):
        """ Arguments:
        *font*:
          A PointFont object.
        *camera*:
          camera to use for drawing the text.  Normally a fixed 2d camera.
        *fmax_chars*:
          maximum number of chars which determines the number of points in the buffer
        """
        self.max_chars = max_chars
        self.font = font

        self.shader = Shader("shaders/uv_fontmultcoloured")
        
        self.locations = np.zeros((max_chars, 3))
        # :,2 for size and z offset. 
        # size=fract(location[2] range 0.0 to 0.99)
        # zoffset = (location[2]-size)*0.1

        self.normals = np.zeros((max_chars, 3))
        # :,0 for rotation
        # :,1 for red and alpha, red=normal[1]/256, alpha=fract(normal[1])
        # :,2 for green and blue, blue=normal[2]/256, green=fract(normal[2])    
        self.normals[:,1] = 0.0
        self.normals[:,2] = 0.0
        self.uv = np.zeros((max_chars, 2)) # u picnum.u v
        
        self.text_blocks = []
        self._first_free_char = 0
        self._do_buffer_reinit = False
        
        self.text = Points(camera=camera, vertices=self.locations, normals=self.normals, tex_coords=self.uv,
                       point_size=64)
        self.text.set_draw_details(self.shader, [self.font])
        
        #Reset all characters to space so there are no false character shadows
        glyph = self.font.glyph_table[u' ']
        self.uv[:] = glyph[0:2]
Exemplo n.º 5
0
class PointText(object):
  def __init__(self, font, camera, max_chars=100, point_size=48):
    """ Arguments:
    *font*:
      A PointFont object.
    *camera*:
      camera to use for drawing the text.  Normally a fixed 2d camera.
    *max_chars*:
      maximum number of chars, which determines the number of points in the buffer
    *point_size*:
      size of "default" characters created using the Points class and the
      font. This is further scaled by the TextBlock.size
      This refinement is needed to allow pointsize to be different in Points from
      Font to avoid clipping or overlap of corners when rotation some truetype fonts
    """
    self.max_chars = max_chars
    self.font = font
    self.shader = Shader("uv_pointsprite")
    
    self.locations = np.zeros((max_chars, 3))
    # :,2 for size and z offset. 
    # size=fract(location[2] range 0.0 to 0.999)
    # zoffset = (location[2] - size)*0.1

    self.normals = np.zeros((max_chars, 3))
    # :,0 for rotation
    # :,1 for red and green, red=normal[1]/999, green=fract(normal[1])
    # :,2 for blue and alpha, blue=normal[2]/999, alpha=fract(normal[2])    
    self.normals[:,1] = 0.0
    self.normals[:,2] = 0.0
    self.uv = np.zeros((max_chars, 2)) # u picnum.u v

    self.text_blocks = []
    self._first_free_char = 0
    self._do_buffer_reinit = False

    self.point_size = point_size
    self.text = Points(camera=camera, vertices=self.locations, normals=self.normals,
                       tex_coords=self.uv, point_size=self.point_size)
    self.text.set_draw_details(self.shader, [self.font])
    self.text.unif[48] = 0.058  # used to hold "patch size" passed to shader
    #Reset all characters to space so there are no false character shadows
    try:
      glyph = self.font.glyph_table[' '] #u' ' doesn't work on python3.2!!
    except:
      glyph = list(self.font.glyph_table.values())[0] #in case ' ' isn't there
    self.uv[:] = glyph[0:2]

  def regen(self):
    ''' Regenerate all text blocks that are linked to data objects and have
    changed value '''
    for block in self.text_blocks:
      if block.data_obj is not None:
        value = block.get_value()
        if value != block.last_value:
          block.last_value = value
          block.set_text()

  def add_text_block(self, text_block):
    ''' Add a text block to the collection, setting the object link to this
    service and setting the buffer offset allocated to the text block.
    This is required for the text block to update the buffer allocated to
    it. Also tracks the next unallocated character in the buffer. '''
    if self._first_free_char + text_block.char_count >= self.max_chars:
      print("failed to allocate space in characers for " + text_block.char_count + " characters")
      return -1
    self.text_blocks.append(text_block)
    text_block.set_text_manager(self, self._first_free_char)
    text_block.set_text()
    self._first_free_char += text_block.char_count
    return 0

  def draw(self):
    ''' Draw all the text characters.  If the re_init flag is set then
    update the points shape buffer. '''
    if self._do_buffer_reinit:
        self.text.buf[0].re_init(pts=self.locations, normals=self.normals,
                              texcoords=self.uv) # reform opengles array_buffer

    self.text.draw()

  def set_do_reinit(self):
    self._do_buffer_reinit = True
Exemplo n.º 6
0
class FastText(object):
    def __init__(self, font, camera, max_chars = 100):
        """ Arguments:
        *font*:
          A PointFont object.
        *fmax_chars*:
          maximum number of chars which determines the number of points in the buffer
        """
        self.max_chars = max_chars
        self.font = font

        self.shader = Shader("shaders/uv_fontmult")
        
        self.locations = np.zeros((max_chars, 3))
        # :,2 for size range 0.0 to 0.999           

        self.normals = np.zeros((max_chars, 3))
        # :,0 for rotation
        # :,1 for alpha
        self.normals[:,1] = 0.0
        self.normals[:,2] = 0.057
        """  :,2 for sub-size i.e 64x64 images on 1024x1024 image each is 0.0625 
        there is margin on each side to avoidproblems with overlapping on rotations.
        """
        self.uv = np.zeros((max_chars, 2)) # u picnum.u v

        self.text = None
        
        self.text_blocks = []
        
        self.text = Points(camera=camera, vertices=self.locations, normals=self.normals, tex_coords=self.uv,
                       point_size=self.font.height)
        self.text.set_draw_details(self.shader, [self.font])
            

    def regen(self):
        ##### regenerate text from text blocks
        char_index = 0
        
        #Reset all chars to zero alpha
#        self.normals[:,1] = 0.0

        for block in self.text_blocks:
            if (char_index + block.char_count) < self.max_chars:
                SystemError("FastText exceeded maximum characters")
            
            xpos = block.x
            ypos = block.y
            value = block.get_value()
                        
            if value != block.last_value:
                block.last_value = value

                # Set alpha for whole text block to zero. Hides old strings that are longer than new ones
#                for index in range(char_index,char_index+block.char_count+1):
#                    self.normals[index,1] = 0.0
                self.normals[char_index:char_index+block.char_count,1] = 0.0
                
                str = block.get_string(value)
                            
                index = 0
                for char in str:
                    ind = index + char_index
                    
                                                            
                    glyph = self.font.glyph_table[char]
                    self.uv[ind] = glyph[0:2]
                    
#                    if index == 0:
#                        xpos += float(glyph[2]) *  block.size * 0.25
                    
                    if block.spacing == "F":
                        self.locations[ind][0] = xpos + (float(glyph[2]) *  block.size * 0.5)
                    else:
                        self.locations[ind][0] = xpos #+ (64.0 - (float(glyph[2])) *  block.size * 0.25)
                    self.locations[ind][1] = block.y
                    self.locations[ind][2] = block.size
                    
                    # Set alpha
                    self.normals[ind][0] = block.rot
                    self.normals[ind][1] = block.alpha
                    
                    if block.spacing == "C":
                        xpos += self.font.height * block.size * block.space
                    if block.spacing == "M":
                        xpos += glyph[2] * block.size * block.space
                    if block.spacing == "F":
                        xpos += (glyph[2] * block.size) + (self.font.height * block.space * block.size)
                    index += 1
            
            elif block.rotation_changed:
                #Set the rotation of the block 
                self.normals[char_index:char_index+block.char_count,0] = block.rot
                   
            char_index = char_index + block.char_count
                    
        self.text.buf[0].re_init(pts=self.locations, normals=self.normals, texcoords=self.uv) # reform opengles array_buffer
  
    def add_text_block(self, text_block):
        self.text_blocks.append(text_block)
        return len(self.text_blocks) - 1
    
    def set_text_block_position_xy(self, index, x, y):
        if index >= len(self.text_blocks):
            return
        block = self.text_blocks[index]
        block.x = x
        block.y = y
        
    def set_text_block_rotation(self, index, rot):
        if index >= len(self.text_blocks):
            return
        self.text_blocks[index].rot = rot

    def draw(self):
        self.text.draw()
Exemplo n.º 7
0
class PointText(object):
    def __init__(self, font, camera, max_chars = 100):
        """ Arguments:
        *font*:
          A PointFont object.
        *camera*:
          camera to use for drawing the text.  Normally a fixed 2d camera.
        *fmax_chars*:
          maximum number of chars which determines the number of points in the buffer
        """
        self.max_chars = max_chars
        self.font = font

        self.shader = Shader("shaders/uv_fontmultcoloured")
        
        self.locations = np.zeros((max_chars, 3))
        # :,2 for size and z offset. 
        # size=fract(location[2] range 0.0 to 0.99)
        # zoffset = (location[2]-size)*0.1

        self.normals = np.zeros((max_chars, 3))
        # :,0 for rotation
        # :,1 for red and alpha, red=normal[1]/256, alpha=fract(normal[1])
        # :,2 for green and blue, blue=normal[2]/256, green=fract(normal[2])    
        self.normals[:,1] = 0.0
        self.normals[:,2] = 0.0
        self.uv = np.zeros((max_chars, 2)) # u picnum.u v
        
        self.text_blocks = []
        self._first_free_char = 0
        self._do_buffer_reinit = False
        
        self.text = Points(camera=camera, vertices=self.locations, normals=self.normals, tex_coords=self.uv,
                       point_size=64)
        self.text.set_draw_details(self.shader, [self.font])
        
        #Reset all characters to space so there are no false character shadows
        glyph = self.font.glyph_table[u' ']
        self.uv[:] = glyph[0:2]
        

    def regen(self):
        ''' Regenerate all text blocks that are linked to data objects and have changed value
        '''
        for block in self.text_blocks:
            if block.data_obj != None:
                value = block.get_value()
                if value != block.last_value:
                    block.last_value = value
                    block.set_text()
                    
  
  
    def add_text_block(self, text_block):
        ''' Add a text block to the collection, setting the object link to this service and setting
            the buffer offset allocated to the text block.  This is required for the text block to
            update the buffer allocated to it. Also tracks the next unallocated character in the
            buffer.
        '''
        if self._first_free_char + text_block.char_count >= self.max_chars:
            print("failed to allocate space in characers for " + text_block.char_count + " characters")
            return -1
        self.text_blocks.append(text_block)
        text_block.set_text_manager(self, self._first_free_char)
        text_block.set_text()
        self._first_free_char += text_block.char_count
        return 0
    
    
    def draw(self):
        ''' Draw all the text characters.  If the re_init flag is set then update the points shape buffer.
        '''
        if self._do_buffer_reinit == True:
            self.text.buf[0].re_init(pts=self.locations, normals=self.normals, texcoords=self.uv) # reform opengles array_buffer

        self.text.draw()
        
    def set_do_reinit(self):
        self._do_buffer_reinit = True