-
-
Notifications
You must be signed in to change notification settings - Fork 183
Add support for rounded rects to surfaces #2695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For the purposes of GUI, with scalability in mind, I one technique people often use is 9-patching. https://en.wikipedia.org/wiki/9-slice_scaling. |
Also I slightly misread your report, so I ended up whipping up an example of how to do this, which I might as well share. import pygame
surface = pygame.image.load("cool.jpg")
# Poor man's convert alpha without a display, I want this and the
# mock_surface to have the same pixelformat.
standardized = pygame.Surface(surface.get_size(), pygame.SRCALPHA)
standardized.blit(surface, (0,0))
surface = standardized
mock_surface = pygame.Surface(surface.get_size(), pygame.SRCALPHA)
mock_surface.fill((0,0,0,0))
pygame.draw.rect(mock_surface, "white", mock_surface.get_rect(), border_radius=100)
surface.blit(mock_surface, (0,0), special_flags=pygame.BLEND_RGBA_MULT)
pygame.image.save(surface, "out.png") |
I thought about the same solution, I know it works, but I believe we can make it more intuitive for users. |
@Starbuck5 do you think pygame should export 9 patching or do you think users should do it themselves? |
Maybe we should add something for this, but it's not something we're actively planning to do soon, and maybe will seem moot with SDL3+sdl_gpu so I want to close and then we can make a new ticket in the future if we need to. Also since last motion here a nine patch example was added (by damusss himself) to the examples: #2985 |
Hello,
It would be great to add a way to round surface corners. I believe it wouldn't be difficult to implement it, since we do it manually in
pygame.draw.rect
. What do you think about adding a new function in transform sub module likepygame.transform.round_corners
?I'm pretty surprised no one is talking about it, maybe there is already a pretty efficient way to do that ? (Maybe there is even an issue already opened ?) I mean with blendmodes it's possible, but it isn't intuitive at all for beginners for example, and I believe we can optimise the process.
This feature would be helpful for everyone creating gui with buttons with rounded corners + texture.
The text was updated successfully, but these errors were encountered: