Ejemplo n.º 1
0
    def text(self, text):
        self._text = text
        self._lines = []

        if self._bounds_w > 0:
            for user_line in self._text.split('\n'):
                self._lines += self._parse_line(user_line)
        else:
            for user_line in self._text.split('\n'):
                self._lines.append(
                    (user_line,
                     arcade.get_text_image(user_line, self._color,
                                           self._font_size)))
    def __init__(self, text, center_x, center_y,
                 text_color: Color,
                 text_color_mouse_over: Color = None,
                 text_color_mouse_press: Color = None,
                 font_size: float = 12,
                 font_name: Union[str, Tuple[str, ...]] = ('calibri', 'arial'),
                 ):
        super().__init__(center_x, center_y)

        if text_color_mouse_over is None:
            text_color_mouse_over = text_color

        if text_color_mouse_press is None:
            text_color_mouse_press = text_color

        text_image_normal = arcade.get_text_image(text=text, text_color=text_color, font_size=font_size, font_name=font_name)
        text_image_mouse_over = arcade.get_text_image(text=text, text_color=text_color_mouse_over, font_size=font_size, font_name=font_name)
        text_image_mouse_press = arcade.get_text_image(text=text, text_color=text_color_mouse_press, font_size=font_size, font_name=font_name)

        self.texture = arcade.Texture(image=text_image_normal, name=text)
        self.normal_texture = self.texture
        self.mouse_press_texture = arcade.Texture(image=text_image_mouse_press, name=text+"3")
        self.mouse_over_texture = arcade.Texture(image=text_image_mouse_over, name=text+"6")
Ejemplo n.º 3
0
    def _parse_line(self, line):
        words = line.split(' ')
        lines = []
        current_line = ''

        for word in words:
            if arcade.get_text_image(current_line + word, self._color,
                                     self._font_size).width > self._bounds_w:
                line = current_line.strip()
                lines.append((line,
                              arcade.get_text_image(line, self._color,
                                                    self._font_size)))
                current_line = ''
                continue
            current_line += word + ' '

        if len(current_line) > 0:
            line = current_line.strip()
            lines.append(
                (line, arcade.get_text_image(line, self._color,
                                             self._font_size)))

        return lines
Ejemplo n.º 4
0
def get_text_image(text,text_color=arcade.color.BLACK,font_size=1,width=0,align="left",font_name=('calibri','arial')):
  global text_images_save
  
  """
  Wrapper for get_text_image in text.py of arcade
  """
  
  # Get identifier for image
  idimage = text+str(text_color)+str(font_size)+str(font_size)
  
  # First try to get the word from the text_images_save dictionary
  try: 
    image = text_images_save[idimage]
  except:
    # Does not exist so make and save it
    image = arcade.get_text_image(text=text,
                          text_color=text_color,
                          font_size=font_size,
                          width=width,
                          align=align,
                          font_name=font_name)
    text_images_save[idimage] = image
    
  return image
Ejemplo n.º 5
0
    def __init__(self, text, center_x, center_y, width, height, theme: Theme):
        super().__init__(center_x, center_y)

        assert theme.text_color is not None
        assert theme.background_color is not None
        assert theme.text_color_mouse_over is not None
        assert theme.background_color_mouse_over is not None

        text_image_normal = arcade.get_text_image(
            text,
            theme.text_color,
            width=width,
            height=height,
            align="center",
            valign="middle",
            background_color=theme.background_color,
            font_size=theme.font_size,
            font_name=theme.font_name)
        text_image_mouse_over = arcade.get_text_image(
            text,
            theme.text_color_mouse_over,
            width=width,
            height=height,
            align="center",
            valign="middle",
            background_color=theme.background_color_mouse_over,
            font_size=theme.font_size,
            font_name=theme.font_name)
        text_image_mouse_press = arcade.get_text_image(
            text,
            text_color=theme.text_color_mouse_press,
            width=width,
            height=height,
            align="center",
            valign="middle",
            background_color=theme.background_color_mouse_press,
            font_size=theme.font_size,
            font_name=theme.font_name)

        rect = [
            0, 0, text_image_normal.width - theme.border_width / 2,
            text_image_normal.height - theme.border_width / 2
        ]

        if theme.border_color and theme.border_width:
            d = ImageDraw.Draw(text_image_normal)
            d.rectangle(rect,
                        fill=None,
                        outline=theme.border_color,
                        width=theme.border_width)

        if theme.border_color_mouse_over:
            d = ImageDraw.Draw(text_image_mouse_over)
            d.rectangle(rect,
                        fill=None,
                        outline=theme.border_color_mouse_over,
                        width=theme.border_width)

        if theme.border_color_mouse_press:
            d = ImageDraw.Draw(text_image_mouse_press)
            d.rectangle(rect,
                        fill=None,
                        outline=theme.border_color_mouse_press,
                        width=theme.border_width)

        self.texture = arcade.Texture(image=text_image_normal, name=text)
        self.normal_texture = self.texture
        self.mouse_press_texture = arcade.Texture(image=text_image_mouse_press,
                                                  name=text + "4")
        self.mouse_over_texture = arcade.Texture(image=text_image_mouse_over,
                                                 name=text + "5")
Ejemplo n.º 6
0
 def text(self, text):
     self._text = text
     self._image = arcade.get_text_image(self._text, self._color,
                                         self._font_size)