Skip to content

Shim and deprecate pygame.gfxdraw using pygame.draw #3006

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

Closed
wants to merge 8 commits into from

Conversation

damusss
Copy link
Member

@damusss damusss commented Jul 18, 2024

Functions that need to be ported to complete it:

  • aaellipse
  • aapolygon
  • bezier

PR will be ready to review when the deprecation is 100% complete

[WARNING: the diff looks huge, but it's really just removing useless things! Don't be scared :(]

This could potentially fix this issues: #1487, #2450, #2463 and start fixing #172 .

gfxdraw is a dying module, draw is just so much better, and this creates a lot of duplicates. gfxdraw should become deprecated, and until the functions are removed (maybe) they should be implemented with the draw module in a python file. This is not possible 100% right now as there are functions with no equivalent, but this is the start of the shim. Everytime something is added, more shim is added until it's 100% python.

In this PR I renamed old gfxdraw to _gfxdraw (will be removed at the end of the deprecation), created gfxdraw.py and impllemented most of the functions (the stub is almost intact, the user shouldn't know about shims). I then went in _gfxdraw.c and removed all non necessary functions. Finally, I removed a LOT of code from the src_c/SDL_gfx/ folder, everything that is not needed in the current state. I also removed a useless file which we won't need since gfxdraw is not going to grow.

[REVIEW WARNING: it seems like I added code to _gfxdraw.c and the SDL_gfx files but I did not. I only removed code!]

I am working to fix the tests.

NOTE: the signature in the @deprecated decorator for stubs and py files must be different otherwise the raised message will seem incomplete.

@damusss damusss added the gfxdraw pygame.gfxdraw label Jul 18, 2024
@damusss damusss requested a review from a team as a code owner July 18, 2024 21:57
@Starbuck5
Copy link
Member

Starbuck5 commented Jul 19, 2024

[Not Complete]

Marking draft then.

@Starbuck5 Starbuck5 marked this pull request as draft July 19, 2024 06:48
@bilhox
Copy link
Contributor

bilhox commented Jul 19, 2024

Hello,

You did a good work ! I have extra things to say :

  • If you're moving every functions that should be deprecated in python side, you should add the deprecated decorator.
  • If I'm not wrong you kept textured_polygon in C side, but this can easily be done with other functions ! You draw an ellipse on a surface with alpha, and then you blit it on the image with a BLEND_RGBA flag.

@Starbuck5
Copy link
Member

My take on this is that SDL_gfx is a vendored library, so deleting parts of its source code isn't what we should be after. If that's true, then I don't see why a partial shim helps us much. It would need to be a full replacement to delete the gfxdraw source. Maybe there's some benefit to just removing the Python->C layer for the function we no longer need with a partial shim?

That being said, maybe I'm wrong. Deleting parts of their code does reduce the amount of code that needs to get compiled with SDL3. - Although, I have had barely any issues getting it to compile. Like all the patches it needed (last time I checked with SDL3) have already been added.

This is definitely a good exercise to see what draw needs. I just don't know if there's a good reason to merge a partial shim.

@damusss
Copy link
Member Author

damusss commented Jul 19, 2024

@Starbuck5 alright, maybe a partial shim isn't a good option. Draw is only missing bezier, aaellipse and aapolygon, so with a bit of effort we can soon enough shim it all. This pr could stay draft while me and other members port the missing functions and at that point all vendored code is removed and only the python shim remains.

Textured polygon can already be added to the shim.

@bilhox proposed to deprecate pie as it can be achieved with other draw functions. What do you think?

  • port it to C draw
  • deprecate it
  • create a python version similar to textured polygon that emulates it.

Thanks for the review.

@damusss damusss changed the title Shim pygame.gfxdraw using pygame.draw (and start its deprecation) Shim and deprecate pygame.gfxdraw using pygame.draw Jul 19, 2024
@mzivic7 mzivic7 mentioned this pull request Jul 19, 2024
19 tasks
@damusss
Copy link
Member Author

damusss commented Jul 21, 2024

After some discussion, pull request #3010 closes this one as not planned.

@damusss damusss closed this Jul 21, 2024
@damusss damusss deleted the gfxdraw-partial-shim branch August 3, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gfxdraw pygame.gfxdraw
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants