From 64590d1ad79290aa9f9e4c9782a6ca9e7180dd9a Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 3 Apr 2023 15:57:53 -0700 Subject: [PATCH 01/18] Broke Up create_text_sprite https://github.com/pythonarcade/arcade/issues/1410 --- arcade/__init__.py | 1 + arcade/text.py | 57 +++++++++++++++++++++++++++++ tests/unit/text/test_text_sprite.py | 7 +++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/arcade/__init__.py b/arcade/__init__.py index 19adea6503..5ffcbb1fba 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -229,6 +229,7 @@ def configure_logging(level: Optional[int] = None): from .text import ( draw_text, load_font, + create_text_texture, create_text_sprite, Text, ) diff --git a/arcade/text.py b/arcade/text.py index 5db3ffbc2a..2c35cf4d3e 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -569,6 +569,51 @@ def position(self, point: Point): self._label.position = *point, self._label.z +def create_text_texture(text: str, + color: RGBA255 = arcade.color.WHITE, + font_size: float = 12, + width: int = 0, + align: str = "left", + font_name: FontNameOrNames = ("calibri", "arial"), + bold: bool = False, + italic: bool = False, + anchor_x: str = "left", + multiline: bool = False, + texture_atlas: Optional[arcade.TextureAtlas] = None): + + if align != "center" and align != "left" and align != "right": + raise ValueError("The 'align' parameter must be equal to 'left', 'right', or 'center'.") + + adjusted_font = _attempt_font_name_resolution(font_name) + _label = pyglet.text.Label( + text=text, + font_name=adjusted_font, + font_size=font_size, + anchor_x=anchor_x, + color=Color.from_iterable(color), + width=width, + align=align, + bold=bold, + italic=italic, + multiline=multiline, + ) + + size = ( + int(_label.width), + int(_label.height), + ) + + texture = arcade.Texture.create_empty(text, size) + + if not texture_atlas: + texture_atlas = arcade.get_window().ctx.default_atlas + texture_atlas.add(texture) + with texture_atlas.render_into(texture) as fbo: + fbo.clear((0, 0, 0, 255)) + _draw_pyglet_label(_label) + return texture + + def create_text_sprite( text: str, color: RGBA255 = arcade.color.WHITE, @@ -641,6 +686,18 @@ def create_text_sprite( fbo.clear((0, 0, 0, 255)) text_object.draw() + texture = create_text_texture(text, + color = color, + font_size = font_size, + width = width, + align = align, + font_name = font_name, + bold = bold, + italic = italic, + anchor_x = anchor_x, + multiline = multiline, + texture_atlas = texture_atlas) + return arcade.Sprite( texture, center_x=text_object.right - (size[0] / 2), diff --git a/tests/unit/text/test_text_sprite.py b/tests/unit/text/test_text_sprite.py index 04fea24564..f1ad3f1899 100644 --- a/tests/unit/text/test_text_sprite.py +++ b/tests/unit/text/test_text_sprite.py @@ -1,8 +1,13 @@ import pytest import arcade +def test_text_texture(window): + texture = arcade.create_text_texture("BRRRRRRR") + assert isinstance(texture, arcade.Texture) + assert texture.width == pytest.approx(75, rel=10) + assert texture.height == pytest.approx(20, rel=5) -def test_create(window): +def test_text_sprite(window): sprite = arcade.create_text_sprite("Hello World") assert isinstance(sprite, arcade.Sprite) assert sprite.width == pytest.approx(75, rel=10) From 626d6e0d8e761bb7946fea9a4f96fe4173936b0c Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 3 Apr 2023 16:03:09 -0700 Subject: [PATCH 02/18] Changed test --- tests/unit/text/test_text_sprite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/text/test_text_sprite.py b/tests/unit/text/test_text_sprite.py index f1ad3f1899..f06500c1cd 100644 --- a/tests/unit/text/test_text_sprite.py +++ b/tests/unit/text/test_text_sprite.py @@ -2,7 +2,7 @@ import arcade def test_text_texture(window): - texture = arcade.create_text_texture("BRRRRRRR") + texture = arcade.create_text_texture("Hello World") assert isinstance(texture, arcade.Texture) assert texture.width == pytest.approx(75, rel=10) assert texture.height == pytest.approx(20, rel=5) From a75b059bd5f5d5c1b8c632ba3fe35257ffbdbaac Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Mon, 3 Apr 2023 16:39:25 -0700 Subject: [PATCH 03/18] Had to add create_text_texture to __all__ --- arcade/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arcade/__init__.py b/arcade/__init__.py index 5ffcbb1fba..7c0b328b9e 100644 --- a/arcade/__init__.py +++ b/arcade/__init__.py @@ -332,6 +332,7 @@ def configure_logging(level: Optional[int] = None): 'get_sprites_at_point', 'SpatialHash', 'get_timings', + 'create_text_texture', 'create_text_sprite', 'clear_timings', 'get_window', From 5988ef59edf186f1da42d577380cfe089ebedd3d Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 4 Apr 2023 08:51:07 -0700 Subject: [PATCH 04/18] Fixed width and height bug. normal width and height is bugged on the label, have to use content_width and content_height --- arcade/text.py | 40 ++++++----------------------- tests/unit/text/test_text.py | 3 --- tests/unit/text/test_text_sprite.py | 4 +-- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 2c35cf4d3e..0934b82e1f 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -596,11 +596,16 @@ def create_text_texture(text: str, bold=bold, italic=italic, multiline=multiline, + group=None, ) - + + print(_label.content_width, _label.content_height) + if not _label.content_width or not _label.content_height: + warning("Width or height is 0") + return arcade.Texture.create_empty(text, (0, 0)) size = ( - int(_label.width), - int(_label.height), + int(_label.content_width), + int(_label.content_height), ) texture = arcade.Texture.create_empty(text, size) @@ -656,35 +661,6 @@ def create_text_sprite( :param Optional[arcade.TextureAtlas] texture_atlas: The texture atlas to use for the newly created texture. The default global atlas will be used if this is None. """ - text_object = Text( - text, - start_x=0, - start_y=0, - color=color, - font_size=font_size, - width=width, - align=align, - font_name=font_name, - bold=bold, - italic=italic, - anchor_x=anchor_x, - anchor_y="baseline", - multiline=multiline, - ) - - size = ( - int(text_object.right - text_object.left), - int(text_object.top - text_object.bottom), - ) - text_object.y = -text_object.bottom - texture = arcade.Texture.create_empty(text, size) - - if not texture_atlas: - texture_atlas = arcade.get_window().ctx.default_atlas - texture_atlas.add(texture) - with texture_atlas.render_into(texture) as fbo: - fbo.clear((0, 0, 0, 255)) - text_object.draw() texture = create_text_texture(text, color = color, diff --git a/tests/unit/text/test_text.py b/tests/unit/text/test_text.py index 3924b5ec27..3c502481aa 100644 --- a/tests/unit/text/test_text.py +++ b/tests/unit/text/test_text.py @@ -153,6 +153,3 @@ def new_text(*args, **kwargs) -> None: window.flip() - -# def test_create_text_sprite(window): -# pass diff --git a/tests/unit/text/test_text_sprite.py b/tests/unit/text/test_text_sprite.py index f06500c1cd..e93be9f5f9 100644 --- a/tests/unit/text/test_text_sprite.py +++ b/tests/unit/text/test_text_sprite.py @@ -4,11 +4,11 @@ def test_text_texture(window): texture = arcade.create_text_texture("Hello World") assert isinstance(texture, arcade.Texture) - assert texture.width == pytest.approx(75, rel=10) + assert texture.width == pytest.approx(80, rel=10) assert texture.height == pytest.approx(20, rel=5) def test_text_sprite(window): sprite = arcade.create_text_sprite("Hello World") assert isinstance(sprite, arcade.Sprite) - assert sprite.width == pytest.approx(75, rel=10) + assert sprite.width == pytest.approx(80, rel=10) assert sprite.height == pytest.approx(20, rel=5) From b53e5273f32231f05756d60f8a596793f1dc06a1 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 4 Apr 2023 08:56:10 -0700 Subject: [PATCH 05/18] Small change --- arcade/text.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 0934b82e1f..bf50d6ed71 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -599,7 +599,6 @@ def create_text_texture(text: str, group=None, ) - print(_label.content_width, _label.content_height) if not _label.content_width or not _label.content_height: warning("Width or height is 0") return arcade.Texture.create_empty(text, (0, 0)) @@ -673,11 +672,11 @@ def create_text_sprite( anchor_x = anchor_x, multiline = multiline, texture_atlas = texture_atlas) - + size = texture._size return arcade.Sprite( texture, - center_x=text_object.right - (size[0] / 2), - center_y=text_object.top, + center_x=size[0]/2, + center_y=size[1], ) From b062676696ff549dd3b22ba66205d0f0bd7feac5 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 4 Apr 2023 08:58:20 -0700 Subject: [PATCH 06/18] warning was breaking --- arcade/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/text.py b/arcade/text.py index bf50d6ed71..1beec1f1e5 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -600,7 +600,7 @@ def create_text_texture(text: str, ) if not _label.content_width or not _label.content_height: - warning("Width or height is 0") + warning(message="Width or height is 0") return arcade.Texture.create_empty(text, (0, 0)) size = ( int(_label.content_width), From fba6f40088e5a0e7f8130cd8221ce637427dda0a Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Tue, 4 Apr 2023 09:01:26 -0700 Subject: [PATCH 07/18] Warning should be fixed --- arcade/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 1beec1f1e5..682d2ee349 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -10,7 +10,7 @@ from arcade.types import Color, Point, RGBA255 from arcade.resources import resolve from arcade.utils import PerformanceWarning, warning - +from warnings import warn def load_font(path: Union[str, Path]) -> None: """ @@ -600,7 +600,7 @@ def create_text_texture(text: str, ) if not _label.content_width or not _label.content_height: - warning(message="Width or height is 0") + warn("Either width or height is 0") return arcade.Texture.create_empty(text, (0, 0)) size = ( int(_label.content_width), From 7e6b3baa7f9882ddb8847a582068f8f7f2323e53 Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Tue, 4 Apr 2023 19:06:39 -0700 Subject: [PATCH 08/18] Update text.py Add/Change comments on functions --- arcade/text.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 682d2ee349..83ea8ebd10 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -580,6 +580,32 @@ def create_text_texture(text: str, anchor_x: str = "left", multiline: bool = False, texture_atlas: Optional[arcade.TextureAtlas] = None): + """ + Creates a texture containing text based off of :py:class:`~pyglet.text.Label`. + + Internally this creates a pyglet.text.Label object and an empty texture. It then uses either the + provided texture atlas, or gets the default one, and draws the pyglet.text.Label object into the + texture atlas. Then it returns the texture. + + If you are providing a custom texture atlas, something important to keep in mind is + that the resulting Sprite can only be added to SpriteLists which use that atlas. If + it is added to a SpriteList which uses a different atlas, you will likely just see + a black box drawn in its place. + + :param str text: Initial text to display. Can be an empty string + :param RGBA255 color: Color of the text as a tuple or list of 3 (RGB) or 4 (RGBA) integers + :param float font_size: Size of the text in points + :param float width: A width limit in pixels + :param str align: Horizontal alignment; values other than "left" require width to be set + :param FontNameOrNames font_name: A font name, path to a font file, or list of names + :param bool bold: Whether to draw the text as bold + :param bool italic: Whether to draw the text as italic + :param str anchor_x: How to calculate the anchor point's x coordinate. + Options: "left", "center", or "right" + :param bool multiline: Requires width to be set; enables word wrap rather than clipping + :param Optional[arcade.TextureAtlas] texture_atlas: The texture atlas to use for the + newly created texture. The default global atlas will be used if this is None. + """ if align != "center" and align != "left" and align != "right": raise ValueError("The 'align' parameter must be equal to 'left', 'right', or 'center'.") @@ -632,13 +658,12 @@ def create_text_sprite( texture_atlas: Optional[arcade.TextureAtlas] = None, ) -> arcade.Sprite: """ - Creates a sprite containing text based off of :py:class:`~arcade.Text`. + Creates a sprite containing text based off of :py:func:`create_text_texture`. - Internally this creates a Text object and an empty texture. It then uses either the - provided texture atlas, or gets the default one, and draws the Text object into the - texture atlas. + Internally this calls the create_text_texture function and gives it the relevant information. + When it is done, the create_text_texture function returns a texture. - It then creates a sprite referencing the newly created texture, and positions it + The create_text_sprite then creates a sprite referencing the newly created texture, and positions it accordingly, and that is final result that is returned from the function. If you are providing a custom texture atlas, something important to keep in mind is From 84428d52e025e02723d65d3479816704b3c4dede Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 21 Apr 2023 16:35:36 -0700 Subject: [PATCH 09/18] Fix @eschan145 's review --- arcade/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 83ea8ebd10..6cb092ce8d 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -583,8 +583,8 @@ def create_text_texture(text: str, """ Creates a texture containing text based off of :py:class:`~pyglet.text.Label`. - Internally this creates a pyglet.text.Label object and an empty texture. It then uses either the - provided texture atlas, or gets the default one, and draws the pyglet.text.Label object into the + Internally this creates a :py:class:`~pyglet.text.Label` object and an empty texture. It then uses either the + provided texture atlas, or gets the default one, and draws the `~pyglet.text.Label` object into the texture atlas. Then it returns the texture. If you are providing a custom texture atlas, something important to keep in mind is From b435284859a26a2fbba368f32cd874daa744d89a Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sat, 22 Apr 2023 19:46:23 -0700 Subject: [PATCH 10/18] Fix whitespaces in text --- arcade/text.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 6cb092ce8d..937777a3f5 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -624,15 +624,15 @@ def create_text_texture(text: str, multiline=multiline, group=None, ) - - if not _label.content_width or not _label.content_height: + + if not _label.content_width or not _label.content_height: warn("Either width or height is 0") return arcade.Texture.create_empty(text, (0, 0)) size = ( int(_label.content_width), int(_label.content_height), ) - + texture = arcade.Texture.create_empty(text, size) if not texture_atlas: @@ -660,7 +660,7 @@ def create_text_sprite( """ Creates a sprite containing text based off of :py:func:`create_text_texture`. - Internally this calls the create_text_texture function and gives it the relevant information. + Internally this calls the create_text_texture function and gives it the relevant information. When it is done, the create_text_texture function returns a texture. The create_text_sprite then creates a sprite referencing the newly created texture, and positions it From 86fe78f229efe53210ed7e79ab195319b0d215e7 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 09:09:08 -0700 Subject: [PATCH 11/18] create_text_sprite --- arcade/text.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 937777a3f5..0f53a1cb5d 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -622,18 +622,13 @@ def create_text_texture(text: str, bold=bold, italic=italic, multiline=multiline, - group=None, ) if not _label.content_width or not _label.content_height: warn("Either width or height is 0") return arcade.Texture.create_empty(text, (0, 0)) - size = ( - int(_label.content_width), - int(_label.content_height), - ) - texture = arcade.Texture.create_empty(text, size) + texture = arcade.Texture.create_empty(text, (width, height)) if not texture_atlas: texture_atlas = arcade.get_window().ctx.default_atlas @@ -701,7 +696,7 @@ def create_text_sprite( return arcade.Sprite( texture, center_x=size[0]/2, - center_y=size[1], + center_y=size[1]/2, ) From d973a4101b0aa8cfd97d693f1f39dd18be16c127 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 09:15:11 -0700 Subject: [PATCH 12/18] // --- arcade/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/text.py b/arcade/text.py index 0f53a1cb5d..9f37e29a5f 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -622,7 +622,7 @@ def create_text_texture(text: str, bold=bold, italic=italic, multiline=multiline, - ) + ) if not _label.content_width or not _label.content_height: warn("Either width or height is 0") From f852ca527a30d25d7b9068d4b272b2a06306a0e4 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 10:01:40 -0700 Subject: [PATCH 13/18] .. --- arcade/text.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 9f37e29a5f..0d89f3d939 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -81,7 +81,6 @@ def _attempt_font_name_resolution(font_name: FontNameOrNames) -> FontNameOrNames def _draw_pyglet_label(label: pyglet.text.Label) -> None: """ - Helper for drawing pyglet labels with rotation within arcade. Originally part of draw_text in this module, now abstracted and improved @@ -569,7 +568,8 @@ def position(self, point: Point): self._label.position = *point, self._label.z -def create_text_texture(text: str, +def create_text_texture( + text: str, color: RGBA255 = arcade.color.WHITE, font_size: float = 12, width: int = 0, @@ -629,9 +629,9 @@ def create_text_texture(text: str, return arcade.Texture.create_empty(text, (0, 0)) texture = arcade.Texture.create_empty(text, (width, height)) - if not texture_atlas: texture_atlas = arcade.get_window().ctx.default_atlas + texture_atlas.add(texture) with texture_atlas.render_into(texture) as fbo: fbo.clear((0, 0, 0, 255)) @@ -691,7 +691,9 @@ def create_text_sprite( italic = italic, anchor_x = anchor_x, multiline = multiline, - texture_atlas = texture_atlas) + texture_atlas = texture_atlas + ) + size = texture._size return arcade.Sprite( texture, From 1461dc5c1cc0ce9d868d58e581105407048292b6 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Fri, 26 May 2023 13:08:40 -0700 Subject: [PATCH 14/18] hi --- HI.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ arcade/text.py | 12 +++++++- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 HI.py diff --git a/HI.py b/HI.py new file mode 100644 index 0000000000..c72e62420f --- /dev/null +++ b/HI.py @@ -0,0 +1,84 @@ +import arcade, pyglet + +def _attempt_font_name_resolution(font_name): + """ + Attempt to resolve a tuple of font names. + + Preserves the original logic of this section, even though it + doesn't seem to make sense entirely. Comments are an attempt + to make sense of the original code. + + If it can't resolve a definite path, it will return the original + argument for pyglet to attempt to resolve. This is consistent with + the original behavior of this code before it was encapsulated. + + :param Union[str, Tuple[str, ...]] font_name: + :return: Either a resolved path or the original tuple + """ + if font_name: + + # ensure + if isinstance(font_name, str): + font_list: Tuple[str, ...] = (font_name,) + elif isinstance(font_name, tuple): + font_list = font_name + else: + raise TypeError("font_name parameter must be a string, or a tuple of strings that specify a font name.") + + for font in font_list: + try: + path = resolve(font) + # print(f"Font path: {path=}") + + # found a font successfully! + return path.name + + except FileNotFoundError: + pass + + # failed to find it ourselves, hope pyglet can make sense of it + return font_name + + +class UsageAttempt(arcade.Window): + + def __init__(self, width: int = 320, height: int = 240): + super().__init__(width=width, height=height) + + self.sprites = arcade.SpriteList() + text_sprite = arcade.create_text_sprite( + "First line\nsecond line", + multiline=True, + width=200, + ) + text_sprite.position = self.width // 2, self.height // 2 + self.sprites.append(text_sprite) + + self._label = pyglet.text.Label( + text="First line\nsecond line\nTHIRD NIGER", + x = 200, + y = 200, + font_name="Arial", + font_size=12, + anchor_x="left", + width=100, + align="baseline", + bold=True, + italic=True, + multiline=True, + ) + + def on_draw(self): + self.clear() + self.sprites.draw() + + window = arcade.get_window() + with window.ctx.pyglet_rendering(): + self._label.draw() + + + + +if __name__ == "__main__": + w = UsageAttempt() + arcade.run() \ No newline at end of file diff --git a/arcade/text.py b/arcade/text.py index 0d89f3d939..33afedbfaf 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -623,12 +623,22 @@ def create_text_texture( italic=italic, multiline=multiline, ) + lines = _label._get_lines() + right = _label._get_right(lines) + left = _label._get_left(lines) + top = _label._get_top(lines) + bottom = _label._get_bottom(lines) + + size = ( + int(right - left), + int(top - bottom), + ) if not _label.content_width or not _label.content_height: warn("Either width or height is 0") return arcade.Texture.create_empty(text, (0, 0)) - texture = arcade.Texture.create_empty(text, (width, height)) + texture = arcade.Texture.create_empty(text, size) if not texture_atlas: texture_atlas = arcade.get_window().ctx.default_atlas From 497ead5180c76505d7a33d6eab8b6b696ad28ea3 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sun, 28 May 2023 11:03:01 -0700 Subject: [PATCH 15/18] changes as sugested --- arcade/text.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index 33afedbfaf..8043c94d86 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -10,6 +10,7 @@ from arcade.types import Color, Point, RGBA255 from arcade.resources import resolve from arcade.utils import PerformanceWarning, warning +from arcade.color import TRANSPARENT_BLACK from warnings import warn def load_font(path: Union[str, Path]) -> None: @@ -572,7 +573,7 @@ def create_text_texture( text: str, color: RGBA255 = arcade.color.WHITE, font_size: float = 12, - width: int = 0, + width: int = 100, align: str = "left", font_name: FontNameOrNames = ("calibri", "arial"), bold: bool = False, @@ -624,8 +625,8 @@ def create_text_texture( multiline=multiline, ) lines = _label._get_lines() - right = _label._get_right(lines) - left = _label._get_left(lines) + left = _label._get_left() + right = left + _label.content_width top = _label._get_top(lines) bottom = _label._get_bottom(lines) @@ -644,7 +645,7 @@ def create_text_texture( texture_atlas.add(texture) with texture_atlas.render_into(texture) as fbo: - fbo.clear((0, 0, 0, 255)) + fbo.clear(TRANSPARENT_BLACK) _draw_pyglet_label(_label) return texture From d37c3c634c368c4832664885501245fed1474080 Mon Sep 17 00:00:00 2001 From: Grant Hur <22hurg@sjchrisitan.org> Date: Sun, 28 May 2023 16:05:02 -0700 Subject: [PATCH 16/18] .. --- arcade/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcade/text.py b/arcade/text.py index 8043c94d86..cad86351d2 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -622,7 +622,7 @@ def create_text_texture( align=align, bold=bold, italic=italic, - multiline=multiline, + multiline=True, ) lines = _label._get_lines() left = _label._get_left() From eeb5f3d5ecfd612c4d4b0d793d6fe6314e32d927 Mon Sep 17 00:00:00 2001 From: Grant Yul Hur Date: Tue, 30 May 2023 17:55:05 -0700 Subject: [PATCH 17/18] small fixes --- arcade/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/text.py b/arcade/text.py index cad86351d2..a6f11d50bb 100644 --- a/arcade/text.py +++ b/arcade/text.py @@ -622,7 +622,7 @@ def create_text_texture( align=align, bold=bold, italic=italic, - multiline=True, + multiline=multiline, ) lines = _label._get_lines() left = _label._get_left() @@ -654,7 +654,7 @@ def create_text_sprite( text: str, color: RGBA255 = arcade.color.WHITE, font_size: float = 12, - width: int = 0, + width: int = 100, align: str = "left", font_name: FontNameOrNames = ("calibri", "arial"), bold: bool = False, From ae759317f5b7fc379a1a65744d6ead00bfc7e8fe Mon Sep 17 00:00:00 2001 From: Grant Hur Date: Thu, 17 Aug 2023 16:55:48 -0700 Subject: [PATCH 18/18] . --- HI.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HI.py b/HI.py index c72e62420f..6e8f435961 100644 --- a/HI.py +++ b/HI.py @@ -49,13 +49,13 @@ def __init__(self, width: int = 320, height: int = 240): text_sprite = arcade.create_text_sprite( "First line\nsecond line", multiline=True, - width=200, + width=100, ) text_sprite.position = self.width // 2, self.height // 2 self.sprites.append(text_sprite) self._label = pyglet.text.Label( - text="First line\nsecond line\nTHIRD NIGER", + text="First line\nsecond line\nTHIRD Line", x = 200, y = 200, font_name="Arial",