pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

add Font.render_to

Open Notenlish opened this issue 2 years ago • 7 comments
trafficstars

Thanks to starbuck, matt and other people who helped me

Notenlish avatar May 14 '23 17:05 Notenlish

Using this test code:

import pygame
pygame.init()

screen = pygame.display.set_mode((500, 500))

surf = pygame.Surface((50, 50), pygame.SRCALPHA)
surf.fill("red")
font = pygame.font.Font()

font.render_to(surf, (0, 0), "Hello World!", True, "blue")

screen.blit(surf, (100, 100))
pygame.display.flip()

input()

I got this result: image

oddbookworm avatar May 14 '23 18:05 oddbookworm

The method should also accept keyword arguments.

Matiiss avatar May 14 '23 18:05 Matiiss

And this needs tests too.

Matiiss avatar May 14 '23 18:05 Matiiss

Closing the pr as I'm not going to work on it

Notenlish avatar Jul 27 '23 17:07 Notenlish

test code:

import pygame

pygame.font.init()
screen = pygame.display.set_mode((512, 512))
font = pygame.font.SysFont("Arial", 20)
bigfont = pygame.font.SysFont("Arial", 32)
clock = pygame.time.Clock()

while True:
    screen.fill("black")

    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            raise SystemExit

    dt = clock.tick(60)

    rect = font.render_to(screen, pygame.mouse.get_pos(), f"{dt}", True, "red")
    pygame.draw.rect(screen, "white", rect, 1)
    rect = font.render_to(screen, [100,100], f"test", True, "red")
    pygame.draw.rect(screen, "white", rect, 1)

    rect = bigfont.render_to(screen, (250, 125), f"Wow big text", True, "red")
    pygame.draw.rect(screen, "white", rect, 1)

    pygame.display.update()

image

Notenlish avatar Jul 19 '24 20:07 Notenlish

Installing collected packages: urllib3, pytz, MarkupSafe, idna, charset-normalizer, certifi, sphinxcontrib-serializinghtml, sphinxcontrib-qthelp, sphinxcontrib-jsmath, sphinxcontrib-htmlhelp, sphinxcontrib-devhelp, sphinxcontrib-applehelp, snowballstemmer, requests, Pygments, Jinja2, imagesize, docutils, babel, alabaster, Sphinx
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Pygments-2.14.0 Sphinx-5.3.0 alabaster-0.7.13 babel-2.11.0 certifi-2024.7.4 charset-normalizer-2.0.12 docutils-0.18.1 idna-3.7 imagesize-1.4.1 pytz-2024.1 requests-2.27.1 snowballstemmer-2.2.0 sphinxcontrib-applehelp-1.0.2 sphinxcontrib-devhelp-1.0.2 sphinxcontrib-htmlhelp-2.0.0 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-1.0.3 sphinxcontrib-serializinghtml-1.1.5 urllib3-1.26.19
Pygame-ce requires Python3 version 3.7 or above.

How can I change the python version?

Notenlish avatar Aug 05 '24 20:08 Notenlish

big thanks to @bilhox for the segfault fix

Notenlish avatar Aug 12 '24 17:08 Notenlish

IIRC Notenlish has said that he does not want to work on this PR, so I'll close it. Maybe @Matiiss or @damusss can fix it up sometime and make a new PR (assuming we still want this API)?

zoldalma999 avatar Jan 05 '25 12:01 zoldalma999

Do we still want this API?

Matiiss avatar Mar 09 '25 02:03 Matiiss

Do we still want this API?

I still think people would like this, someone just needs to work on the pr

Notenlish avatar Mar 09 '25 17:03 Notenlish