Skip to content
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

Merged
merged 32 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e7a5d2b
Implementation, stubs and docs
damusss May 14, 2024
c348a96
Remove spaces added by clang-format
damusss May 14, 2024
4012c89
Fix variable could not be initialized
damusss May 14, 2024
76760fd
Rewrite tests, fix code, add more exceptions
damusss May 15, 2024
5f0923d
Fix format 1
damusss May 15, 2024
94355a7
Modify test
damusss May 15, 2024
0769e00
Merge branch 'pygame-community:main' into surface-scroll-repeat
damusss May 19, 2024
a1ce581
Generate docs
damusss May 19, 2024
01a36b8
Merge branch 'surface-scroll-repeat' of https://github.com/Damus666/p…
damusss May 19, 2024
35fb956
Allow non erasing pixels
damusss May 25, 2024
fd38aa8
Fix doc
damusss May 25, 2024
2fcdc6d
Fix bug with erase
damusss May 26, 2024
a71d96f
Remove useless memset
damusss May 27, 2024
3002969
Merge branch 'pygame-community:main' into surface-scroll-repeat
damusss Jun 9, 2024
326bfd2
Separate in 2 functions for clarity
damusss Jun 22, 2024
d6dd961
Use SDL function to secure the clip
damusss Jun 23, 2024
e02794c
Update docs
damusss Jun 23, 2024
be6f9c0
build docs
damusss Jun 23, 2024
d40f8ab
Merge branch 'main' into surface-scroll-repeat
damusss Jun 23, 2024
0cea30d
FLAG SYSTEM (I can revert if you don't like it)
damusss Jun 26, 2024
2a5ada8
FLAG_SYSTEM fix stubs
damusss Jun 26, 2024
04bfa81
Merge branch 'pygame-community:main' into surface-scroll-repeat
damusss Jun 30, 2024
cd08d67
Update Docs
damusss Aug 3, 2024
0a6c05f
Merge branch 'pygame-community:main' into surface-scroll-repeat
damusss Aug 3, 2024
86479bd
Merge branch 'main' into surface-scroll-repeat
MyreMylar Oct 5, 2024
8bb6786
Update versionchanged
damusss Oct 5, 2024
0878f96
FIX THE MISSING PIXEL BUG
damusss Oct 8, 2024
a2bf38e
Merge branch 'surface-scroll-repeat' of https://github.com/Damus666/p…
damusss Oct 8, 2024
a2bab10
Simplify conditional statement
damusss Oct 8, 2024
fed0acc
fix format
damusss Oct 8, 2024
d6d7bf3
Split in 2 functions, update versionchanged
damusss Oct 17, 2024
dc9042d
Fix docs and remove redundant C code
damusss Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions buildconfig/stubs/pygame/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ from .constants import (
SCRAP_PPM as SCRAP_PPM,
SCRAP_SELECTION as SCRAP_SELECTION,
SCRAP_TEXT as SCRAP_TEXT,
SCROLL_ERASE as SCROLL_ERASE,
SCROLL_REPEAT as SCROLL_REPEAT,
SHOWN as SHOWN,
SRCALPHA as SRCALPHA,
SRCCOLORKEY as SRCCOLORKEY,
Expand Down
2 changes: 2 additions & 0 deletions buildconfig/stubs/pygame/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ SCRAP_PBM: str
SCRAP_PPM: str
SCRAP_SELECTION: int
SCRAP_TEXT: str
SCROLL_ERASE: int
SCROLL_REPEAT: int
SHOWN: int
SRCALPHA: int
SRCCOLORKEY: int
Expand Down
2 changes: 2 additions & 0 deletions buildconfig/stubs/pygame/locals.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ SCRAP_PBM: str
SCRAP_PPM: str
SCRAP_SELECTION: int
SCRAP_TEXT: str
SCROLL_ERASE: int
SCROLL_REPEAT: int
SHOWN: int
SRCALPHA: int
SRCCOLORKEY: int
Expand Down
4 changes: 3 additions & 1 deletion buildconfig/stubs/pygame/surface.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class Surface:
rect: Optional[RectLike] = None,
special_flags: int = 0,
) -> Rect: ...
def scroll(self, dx: int = 0, dy: int = 0, /) -> None: ...
def scroll(
self, dx: int = 0, dy: int = 0, scroll_flag: int = 0, /
) -> None: ...
@overload
def set_colorkey(self, color: ColorLike, flags: int = 0, /) -> None: ...
@overload
Expand Down
27 changes: 20 additions & 7 deletions docs/reST/ref/surface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,30 @@

.. method:: scroll

| :sl:`shift the surface image in place`
| :sg:`scroll(dx=0, dy=0, /) -> None`
| :sl:`shift the Surface pixels in place`
| :sg:`scroll(dx=0, dy=0, scroll_flag=0, /) -> None`

Move the image by dx pixels right and dy pixels down. dx and dy may be
negative for left and up scrolls respectively. Areas of the surface that
are not overwritten retain their original pixel values. Scrolling is
contained by the Surface clip area. It is safe to have dx and dy values
that exceed the surface size.
Move the Surface by dx pixels right and dy pixels down. dx and dy may be
negative for left and up scrolls respectively.

Scrolling is contained by the Surface clip area. It is safe to have dx
and dy values that exceed the surface size.

The scroll flag can be:
* ``0`` (default): the pixels are shifted but previous pixels are
not modified.

* ``pygame.SCROLL_ERASE``: the space created by the shifting pixels
is filled with black or transparency.

* ``pygame.SCROLL_REPEAT``: the pixels that disappear out of the
surface or clip bounds are brought back on the opposite side
resulting in an infinitely scrolling and repeating surface.

.. versionaddedold:: 1.9

.. versionchanged:: 2.5.3 Add repeating scroll and allow erasing pixels

.. ## Surface.scroll ##

.. method:: set_colorkey
Expand Down
6 changes: 6 additions & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ typedef enum {
PGS_PREALLOC = 0x01000000
} PygameSurfaceFlags;

typedef enum {
PGS_SCROLL_DEFAULT = 0x00000000,
PGS_SCROLL_REPEAT = 0x00000001,
PGS_SCROLL_ERASE = 0x00000004
} PygameScrollSurfaceFlags;

#define RAISE(x, y) (PyErr_SetString((x), (y)), NULL)
#define RAISERETURN(x, y, r) \
PyErr_SetString((x), (y)); \
Expand Down
3 changes: 3 additions & 0 deletions src_c/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ MODINIT_DEFINE(constants)
DEC_CONSTSF(SHOWN);
DEC_CONSTSF(HIDDEN);

DEC_CONSTSF(SCROLL_ERASE);
DEC_CONSTSF(SCROLL_REPEAT);

DEC_CONSTSF(SCALED);

DEC_CONST(GL_RED_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion src_c/doc/surface_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define DOC_SURFACE_CONVERTALPHA "convert_alpha() -> Surface\nchange the pixel format of a surface including per pixel alphas"
#define DOC_SURFACE_COPY "copy() -> Surface\ncreate a new copy of a Surface"
#define DOC_SURFACE_FILL "fill(color, rect=None, special_flags=0) -> Rect\nfill Surface with a solid color"
#define DOC_SURFACE_SCROLL "scroll(dx=0, dy=0, /) -> None\nshift the surface image in place"
#define DOC_SURFACE_SCROLL "scroll(dx=0, dy=0, scroll_flag=0, /) -> None\nshift the Surface pixels in place"
#define DOC_SURFACE_SETCOLORKEY "set_colorkey(color, flags=0, /) -> None\nset_colorkey(None) -> None\nset the transparent colorkey"
#define DOC_SURFACE_GETCOLORKEY "get_colorkey() -> RGB or None\nget the current transparent colorkey"
#define DOC_SURFACE_SETALPHA "set_alpha(value, flags=0, /) -> None\nset_alpha(None) -> None\nset the alpha value for the full Surface"
Expand Down
Loading
Loading