Skip to content

Commit 091f89c

Browse files
authored
Merge pull request #2114 from yunline/port-window
Port video.Window to C
2 parents c427a36 + f1d5abd commit 091f89c

File tree

20 files changed

+3877
-2641
lines changed

20 files changed

+3877
-2641
lines changed

buildconfig/Setup.Emscripten.SDL2.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ surflock src_c/void.c
6161
rect src_c/void.c
6262
rwobject src_c/void.c
6363
system src_c/void.c
64+
_window src_c/void.c
6465

6566
#_sdl2.controller src_c/_sdl2/controller.c $(SDL) $(DEBUG) -Isrc_c
6667
_sdl2.controller_old src_c/void.c

buildconfig/Setup.SDL2.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ math src_c/math.c $(SDL) $(DEBUG)
7575
pixelcopy src_c/pixelcopy.c $(SDL) $(DEBUG)
7676
newbuffer src_c/newbuffer.c $(SDL) $(DEBUG)
7777
system src_c/system.c $(SDL) $(DEBUG)
78+
_window src_c/window.c $(SDL) $(DEBUG)

buildconfig/stubs/gen_stubs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"font": ["Font"],
6868
"mixer": ["Channel"],
6969
"time": ["Clock"],
70-
"joystick": ["Joystick"]
70+
"joystick": ["Joystick"],
7171
}
7272

7373
# pygame modules from which __init__.py does the equivalent of

buildconfig/stubs/pygame/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ from .constants import (
639639
WINDOWMAXIMIZED as WINDOWMAXIMIZED,
640640
WINDOWMINIMIZED as WINDOWMINIMIZED,
641641
WINDOWMOVED as WINDOWMOVED,
642+
WINDOWPOS_CENTERED as WINDOWPOS_CENTERED,
643+
WINDOWPOS_UNDEFINED as WINDOWPOS_UNDEFINED,
642644
WINDOWRESIZED as WINDOWRESIZED,
643645
WINDOWRESTORED as WINDOWRESTORED,
644646
WINDOWSHOWN as WINDOWSHOWN,

buildconfig/stubs/pygame/_sdl2/video.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Generator, Iterable, Optional, Tuple, Union
1+
from typing import Any, Generator, Iterable, Optional, Tuple, Union, final
22

33
from pygame.color import Color
44
from pygame.rect import Rect
@@ -38,6 +38,7 @@ def messagebox(
3838
escape_button: int = 0,
3939
) -> int: ...
4040

41+
@final
4142
class Window:
4243
DEFAULT_SIZE: Tuple[Literal[640], Literal[480]]
4344
def __init__(
@@ -73,6 +74,8 @@ class Window:
7374
display_index: int
7475
def set_modal_for(self, Window) -> None: ...
7576

77+
_Window = Window
78+
7679
class Texture:
7780
def __init__(
7881
self,
@@ -153,14 +156,14 @@ class Image:
153156
class Renderer:
154157
def __init__(
155158
self,
156-
window: Window,
159+
window: Union[Window,_Window],
157160
index: int = -1,
158161
accelerated: int = -1,
159162
vsync: bool = False,
160163
target_texture: bool = False,
161164
) -> None: ...
162165
@classmethod
163-
def from_window(cls, window: Window) -> Renderer: ...
166+
def from_window(cls, window: Union[Window,_Window]) -> Renderer: ...
164167
draw_blend_mode: int
165168
draw_color: Color
166169
def clear(self) -> None: ...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from pygame._sdl2.video import _Window as Window

buildconfig/stubs/pygame/_window.pyi

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Iterable, Optional, Tuple, Union, final
2+
from pygame.surface import Surface
3+
from ._common import RectValue
4+
from pygame.locals import WINDOWPOS_UNDEFINED
5+
6+
def get_grabbed_window() -> Optional[Window]: ...
7+
@final
8+
class Window:
9+
def __init__(
10+
self,
11+
title: str = "pygame window",
12+
size: Iterable[int] = (640, 480),
13+
position: Union[int, Iterable[int]] = WINDOWPOS_UNDEFINED,
14+
**flags: bool
15+
) -> None: ...
16+
def destroy(self) -> None: ...
17+
def set_windowed(self) -> None: ...
18+
def set_fullscreen(self, desktop: bool = False) -> None: ...
19+
def focus(self, input_only: bool = False) -> None: ...
20+
def hide(self) -> None: ...
21+
def show(self) -> None: ...
22+
def restore(self) -> None: ...
23+
def maximize(self) -> None: ...
24+
def minimize(self) -> None: ...
25+
def set_modal_for(self, parent: Window) -> None: ...
26+
def set_icon(self, icon: Surface) -> None: ...
27+
grab: bool
28+
title: str
29+
resizable: bool
30+
borderless: bool
31+
relative_mouse: bool
32+
id: int
33+
size: Iterable[int]
34+
position: Union[int, Iterable[int]]
35+
opacity: float
36+
display_index: int
37+
@classmethod
38+
def from_display_module(cls) -> Window: ...

buildconfig/stubs/pygame/constants.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ WINDOWLEAVE: int
561561
WINDOWMAXIMIZED: int
562562
WINDOWMINIMIZED: int
563563
WINDOWMOVED: int
564+
WINDOWPOS_CENTERED: int
565+
WINDOWPOS_UNDEFINED: int
564566
WINDOWRESIZED: int
565567
WINDOWRESTORED: int
566568
WINDOWSHOWN: int

buildconfig/stubs/pygame/locals.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ WINDOWLEAVE: int
563563
WINDOWMAXIMIZED: int
564564
WINDOWMINIMIZED: int
565565
WINDOWMOVED: int
566+
WINDOWPOS_CENTERED: int
567+
WINDOWPOS_UNDEFINED: int
566568
WINDOWRESIZED: int
567569
WINDOWRESTORED: int
568570
WINDOWSHOWN: int

docs/reST/c_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pygame C API
1919
c_api/surface.rst
2020
c_api/surflock.rst
2121
c_api/version.rst
22+
c_api/window.rst
2223

2324

2425
src_c/include/ contains header files for applications

docs/reST/c_api/window.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. include:: ../common.txt
2+
3+
.. highlight:: c
4+
5+
************************************************
6+
Class Window API exported by pygame.window
7+
************************************************
8+
9+
src_c/window.c
10+
===============
11+
12+
This extension module defines Python type :py:class:`pygame.Window`.
13+
14+
Header file: src_c/include/pygame.h
15+
16+
17+
.. c:type:: pgWindowObject
18+
19+
A :py:class:`pygame.window.Window` instance.
20+
21+
.. c:var:: PyTypeObject *pgWindow_Type
22+
23+
The :py:class:`pygame.window.Window` Python type.
24+
25+
.. c:function:: int pgWindow_Check(PyObject *x)
26+
27+
Return true if *x* is a :py:class:`pygame.window.Window` instance
28+
29+
Will return false if *x* is not a subclass of `Window`.
30+
This is a macro. No check is made that *x* is not *NULL*.

src_c/_pygame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,6 @@ struct pgColorObject {
341341
#define PYGAMEAPI_MATH_NUMSLOTS 2
342342
#define PYGAMEAPI_BASE_NUMSLOTS 24
343343
#define PYGAMEAPI_EVENT_NUMSLOTS 6
344+
#define PYGAMEAPI_WINDOW_NUMSLOTS 1
344345

345346
#endif /* _PYGAME_INTERNAL_H */

0 commit comments

Comments
 (0)