-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Allow erasing pixels in pygame.Surface.scroll and add repeat functionality #2855
base: main
Are you sure you want to change the base?
Conversation
Could the 2 faulty tests be rerun? |
Why do you think this is incorrect? The docs currently say:
Which looks to me like what the current behaviour is. e.g. Current main branch scroll a 200 pixel wide surface right by 100 pixels: After this PR: I think we should retain the current behaviour as the default, and if we want the original pixels not overwritten by scrolled pixels cleared to a colour (and why specifically black?) that should be an option/parameter. Otherwise we will probably accidentally break somebody's code. As an addendum - do we think this function is likely to be a performance sensitive one like blit, or one used less frequently? I'm wondering whether it should support keyword arguments or not, now it has 3 params (possibly 4 after the above). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
@MyreMylar yeah that was a misunderstanding on my side. I don't think 4 arguments are too much. If they are, what do you suggest? Another function for repeat? only positional? |
Looking at how you implemented it, I believe the best option would be to use the same system used for flags on surfaces and window. Like that we can a fair amount of arguments for this function. |
That would require 2 new constants pygame.SCROLL_REPEAT and pygame.SCROLL_ERASE i believe. the new arguments would go from 2 to 1, i guess |
I prefer this approach. |
src_c/surface.c
Outdated
if (dx >= w || dx <= -w) { | ||
dx = dx % w; | ||
} | ||
if (dy >= h || dy <= -h) { | ||
dy = dy % h; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These conditions are not necessary, you can calculate the result directly.
if (dx >= w || dx <= -w) { | |
dx = dx % w; | |
} | |
if (dy >= h || dy <= -h) { | |
dy = dy % h; | |
} | |
dx = dx % w; | |
dy = dy % h; |
Furthermore, this has to be done when repeat
is enabled which is not the case here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary. When dx or dy are >= w or h, and there is no repeat, that function returns early, so that code is never reached.
I see that I can remove the conditions tho, thanks.
I also have to test a specific case that just came to my mind.
I think there were separate functions for the actual process of scrolling and the function definition, what about doing this to keep some kind of readability ? |
After a little digging with @damusss about some issues, here are the potential problem we are facing out currently:
surface_scroll_erase.mp4 |
Code example so you understand how it simplifies the life a lot : https://gist.github.com/bilhox/ce024b994e536338a750a760024b5939 |
The shifting was incorrect, not setting the space created by the shifted pixels to black. Now it does that [EDIT: Now it does that only if the erase argument is True], but most importantly I think I implemented this feature idea: #2159 implementing a way to allow for repeated shifting. The video proof is here: https://discord.com/channels/772505616680878080/772940667231928360/1240055647584911443
I would love feedback about the C code as I did quite a lot of pointer operations.
Why?
Question: how can I add a test for it? Edit: I modified the test, tell me if it's incomplete
You can use the following code with my request to test locally: