From 3fe361681a67a37cb198ea56e3fadeb0c784fbc8 Mon Sep 17 00:00:00 2001 From: Starbuck5 Date: Fri, 6 Aug 2021 17:56:52 -0700 Subject: [PATCH 1/4] Add sdl2_video types --- buildconfig/pygame-stubs/_sdl2/__init__.pyi | 2 +- buildconfig/pygame-stubs/_sdl2/video.pyi | 164 ++++++++++++++++++++ docs/reST/ref/sdl2_video.rst | 2 +- 3 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 buildconfig/pygame-stubs/_sdl2/video.pyi diff --git a/buildconfig/pygame-stubs/_sdl2/__init__.pyi b/buildconfig/pygame-stubs/_sdl2/__init__.pyi index 8b13789179..0106556e1a 100644 --- a/buildconfig/pygame-stubs/_sdl2/__init__.pyi +++ b/buildconfig/pygame-stubs/_sdl2/__init__.pyi @@ -1 +1 @@ - +from pygame._sdl2.video import * diff --git a/buildconfig/pygame-stubs/_sdl2/video.pyi b/buildconfig/pygame-stubs/_sdl2/video.pyi new file mode 100644 index 0000000000..f9fbf6966a --- /dev/null +++ b/buildconfig/pygame-stubs/_sdl2/video.pyi @@ -0,0 +1,164 @@ +from _typeshed import NoneType +from typing import Union, Tuple, Iterable, Optional, Any, Generator, List + +from pygame.surface import Surface +from pygame.rect import Rect +from pygame.math import Vector2 +from pygame.color import Color + +_ColorValue = Union[ + "Color", str, Tuple[int, int, int], List[int], int, Tuple[int, int, int, int] +] + +_CanBeRect = Union[ + "Rect", + Tuple[float, float, float, float], + Tuple[Tuple[float, float], Tuple[float, float]], + List[float], + List[Vector2], + Tuple[Vector2, Vector2], + Iterable[Vector2], +] + +WINDOWPOS_UNDEFINED: int +WINDOWPOS_CENTERED: int + +MESSAGEBOX_ERROR: int +MESSAGEBOX_WARNING: int +MESSAGEBOX_INFORMATION: int + +class RendererDriverInfo: + name: str + flags: int + num_texture_formats: int + max_texture_width: int + max_texture_height: int + +def get_drivers() -> Generator[RendererDriverInfo, None, None]: ... +def get_grabbed_window() -> Optional[Window]: ... +def messagebox( + title: str, + message: str, + window: Optional[Window] = None, + info: bool = False, + warn: bool = False, + error: bool = False, + buttons: Tuple[str, ...] = ("OK",), + return_button: int = 0, + escape_button: int = 0, +) -> int: ... + +class Window: + def __init__( + self, + title: str = "pygame", + size: Iterable[int, int] = (640, 480), + position: Optional[Iterable[int, int]] = None, + fullscreen: bool = False, + fullscreen_desktop=False, + **kwargs: Any + ) -> None: ... + grab: bool + relative_mouse: bool + def set_windowed(self) -> None: ... + def set_fullscreen(self, desktop: bool = False) -> None: ... + title: str + def destroy(self) -> None: ... + def hide(self) -> None: ... + def show(self) -> None: ... + def focus(self, input_only: bool = False) -> None: ... + def restore(self) -> None: ... + def maximize(self) -> None: ... + def minimize(self) -> None: ... + resizable: bool + borderless: bool + def set_icon(self, surface: Surface) -> None: ... + id: int + size: Iterable[int, int] + position: Union[int, Iterable[int, int]] + opacity: float + brightness: float + display_index: int + def set_modal_for(Window) -> None: ... + +class Texture: + def __init__( + self, + renderer: Renderer, + size: Iterable[int, int], + static: bool = False, + streaming: bool = False, + target: bool = False, + ) -> None: ... + def from_surface(renderer: Renderer, surface: Surface) -> Texture: ... + renderer: Renderer + width: int + height: int + alpha: int + blend_mode: int + color: _ColorValue + def get_rect(self, kwargs: Any) -> Rect: ... + def draw( + self, + srcrect: Optional[_CanBeRect] = None, + dstrect: Union[NoneType, _CanBeRect, Iterable[int, int]] = None, + angle: int = 0, + origin: Optional[Iterable[int, int]] = None, + flipX: bool = False, + flipY: bool = False, + ) -> None: ... + def update(self, surface: Surface, area: Optional[_CanBeRect] = None) -> None: ... + +class Image: + def __init__( + self, + textureOrImage: Union[Texture, Image], + srcrect: Optional[_CanBeRect] = None, + ) -> None: ... + def get_rect(self, kwargs: Any) -> Rect: ... + def draw( + srcrect: Optional[_CanBeRect] = None, dstrect: Optional[_CanBeRect] = None + ) -> None: ... + angle: float + origin: Optional[Iterable[float, float]] + flipX: bool + flipY: bool + color: _ColorValue + alpha: float + blend_mode: int + texture: Texture + srcrect: Rect + +class Renderer: + def __init__( + self, + window: Window, + index: int = -1, + accelerated: int = -1, + vsync: bool = False, + target_texture: bool = False, + ) -> None: ... + def from_window(window: Window) -> Renderer: ... + draw_blend_mode: int + draw_color: _ColorValue + def clear(self) -> None: ... + def present(self) -> None: ... + def get_viewport(self) -> Rect: ... + def set_viewport(self, area: Optional[_CanBeRect]) -> None: ... + logical_size: Iterable[int, int] + scale: Iterable[float, float] + target: Union[Texture, None] + def blit( + self, + source: Union[Texture, Image], + dest: Optional[_CanBeRect] = None, + area: Optional[_CanBeRect] = None, + special_flags: int = 0, + ) -> Rect: ... + def draw_line(self, p1: Iterable[int, int], p2: Iterable[int, int]) -> None: ... + def draw_point(self, point: Iterable[int, int]) -> None: ... + def draw_rect(self, rect: _CanBeRect) -> None: ... + def fill_rect(self, rect: _CanBeRect) -> None: ... + def to_surface( + self, surface: Optional[Surface] = None, area: Optional[_CanBeRect] = None + ) -> Surface: ... diff --git a/docs/reST/ref/sdl2_video.rst b/docs/reST/ref/sdl2_video.rst index ae68fe9eb9..c822be2f82 100644 --- a/docs/reST/ref/sdl2_video.rst +++ b/docs/reST/ref/sdl2_video.rst @@ -306,7 +306,7 @@ .. method:: blit | :sl:`For compatibility purposes. Textures created by different Renderers cannot be shared!` - | :sg:`blit(soure, dest, area=None, special_flags=0)-> None` + | :sg:`blit(soure, dest, area=None, special_flags=0)-> Rect` .. method:: draw_line From a7f47454aa03c4271e1ffd10522d58d3423f6589 Mon Sep 17 00:00:00 2001 From: Starbuck5 Date: Sun, 8 Aug 2021 14:16:19 -0700 Subject: [PATCH 2/4] sdl2_video typing fixes --- buildconfig/pygame-stubs/_sdl2/video.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/buildconfig/pygame-stubs/_sdl2/video.pyi b/buildconfig/pygame-stubs/_sdl2/video.pyi index f9fbf6966a..42ed3a3a46 100644 --- a/buildconfig/pygame-stubs/_sdl2/video.pyi +++ b/buildconfig/pygame-stubs/_sdl2/video.pyi @@ -7,11 +7,11 @@ from pygame.math import Vector2 from pygame.color import Color _ColorValue = Union[ - "Color", str, Tuple[int, int, int], List[int], int, Tuple[int, int, int, int] + Color, str, Tuple[int, int, int], List[int], int, Tuple[int, int, int, int] ] _CanBeRect = Union[ - "Rect", + Rect, Tuple[float, float, float, float], Tuple[Tuple[float, float], Tuple[float, float]], List[float], @@ -96,12 +96,12 @@ class Texture: height: int alpha: int blend_mode: int - color: _ColorValue - def get_rect(self, kwargs: Any) -> Rect: ... + color: Color + def get_rect(self, **kwargs: Any) -> Rect: ... def draw( self, srcrect: Optional[_CanBeRect] = None, - dstrect: Union[NoneType, _CanBeRect, Iterable[int, int]] = None, + dstrect: Optional[Union[_CanBeRect, Iterable[int, int]]] = None, angle: int = 0, origin: Optional[Iterable[int, int]] = None, flipX: bool = False, @@ -115,7 +115,7 @@ class Image: textureOrImage: Union[Texture, Image], srcrect: Optional[_CanBeRect] = None, ) -> None: ... - def get_rect(self, kwargs: Any) -> Rect: ... + def get_rect(self, **kwargs: Any) -> Rect: ... def draw( srcrect: Optional[_CanBeRect] = None, dstrect: Optional[_CanBeRect] = None ) -> None: ... @@ -123,7 +123,7 @@ class Image: origin: Optional[Iterable[float, float]] flipX: bool flipY: bool - color: _ColorValue + color: Color alpha: float blend_mode: int texture: Texture @@ -140,7 +140,7 @@ class Renderer: ) -> None: ... def from_window(window: Window) -> Renderer: ... draw_blend_mode: int - draw_color: _ColorValue + draw_color: Color def clear(self) -> None: ... def present(self) -> None: ... def get_viewport(self) -> Rect: ... From 47e180c65603030ad6807855adc3a9eb7bb3a245 Mon Sep 17 00:00:00 2001 From: Starbuck5 Date: Mon, 9 Aug 2021 02:42:17 -0700 Subject: [PATCH 3/4] Update sdl_video_doc.h [skip ci] --- src_c/doc/sdl2_video_doc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src_c/doc/sdl2_video_doc.h b/src_c/doc/sdl2_video_doc.h index 4c8baf03ec..ca451c6674 100644 --- a/src_c/doc/sdl2_video_doc.h +++ b/src_c/doc/sdl2_video_doc.h @@ -58,7 +58,7 @@ #define DOC_RENDERERLOGICALSIZE "logical_size -> (int width, int height)\nGets and sets the logical size." #define DOC_RENDERERSCALE "scale -> (float x_scale, float y_scale)\nGets and sets the scale." #define DOC_RENDERERTARGET "target -> Texture or None\nGets and sets the render target. None represents the default target (the renderer)." -#define DOC_RENDERERBLIT "blit(soure, dest, area=None, special_flags=0)-> None\nFor compatibility purposes. Textures created by different Renderers cannot be shared!" +#define DOC_RENDERERBLIT "blit(soure, dest, area=None, special_flags=0)-> Rect\nFor compatibility purposes. Textures created by different Renderers cannot be shared!" #define DOC_RENDERERDRAWLINE "draw_line(p1, p2) -> None\nDraws a line." #define DOC_RENDERERDRAWPOINT "draw_point(point) -> None\nDraws a point." #define DOC_RENDERERDRAWRECT "draw_rect(rect)-> None\nDraws a rectangle." @@ -306,7 +306,7 @@ pygame._sdl2.video.Renderer.target Gets and sets the render target. None represents the default target (the renderer). pygame._sdl2.video.Renderer.blit - blit(soure, dest, area=None, special_flags=0)-> None + blit(soure, dest, area=None, special_flags=0)-> Rect For compatibility purposes. Textures created by different Renderers cannot be shared! pygame._sdl2.video.Renderer.draw_line From 83d89f96c609c1e48d4983db5c4914e8af069864 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Sun, 17 Oct 2021 23:57:34 -0700 Subject: [PATCH 4/4] sdl2_video typing fixes --- buildconfig/pygame-stubs/_sdl2/video.pyi | 34 +++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/buildconfig/pygame-stubs/_sdl2/video.pyi b/buildconfig/pygame-stubs/_sdl2/video.pyi index 42ed3a3a46..46af30307b 100644 --- a/buildconfig/pygame-stubs/_sdl2/video.pyi +++ b/buildconfig/pygame-stubs/_sdl2/video.pyi @@ -52,12 +52,14 @@ class Window: def __init__( self, title: str = "pygame", - size: Iterable[int, int] = (640, 480), - position: Optional[Iterable[int, int]] = None, + size: Iterable[int] = (640, 480), + position: Optional[Iterable[int]] = None, fullscreen: bool = False, - fullscreen_desktop=False, - **kwargs: Any + fullscreen_desktop: bool = False, + **kwargs: bool ) -> None: ... + @staticmethod + def from_display_module() -> Window: ... grab: bool relative_mouse: bool def set_windowed(self) -> None: ... @@ -74,22 +76,23 @@ class Window: borderless: bool def set_icon(self, surface: Surface) -> None: ... id: int - size: Iterable[int, int] - position: Union[int, Iterable[int, int]] + size: Iterable[int] + position: Union[int, Iterable[int]] opacity: float brightness: float display_index: int - def set_modal_for(Window) -> None: ... + def set_modal_for(self, Window) -> None: ... class Texture: def __init__( self, renderer: Renderer, - size: Iterable[int, int], + size: Iterable[int], static: bool = False, streaming: bool = False, target: bool = False, ) -> None: ... + @staticmethod def from_surface(renderer: Renderer, surface: Surface) -> Texture: ... renderer: Renderer width: int @@ -101,9 +104,9 @@ class Texture: def draw( self, srcrect: Optional[_CanBeRect] = None, - dstrect: Optional[Union[_CanBeRect, Iterable[int, int]]] = None, + dstrect: Optional[Union[_CanBeRect, Iterable[int]]] = None, angle: int = 0, - origin: Optional[Iterable[int, int]] = None, + origin: Optional[Iterable[int]] = None, flipX: bool = False, flipY: bool = False, ) -> None: ... @@ -120,7 +123,7 @@ class Image: srcrect: Optional[_CanBeRect] = None, dstrect: Optional[_CanBeRect] = None ) -> None: ... angle: float - origin: Optional[Iterable[float, float]] + origin: Optional[Iterable[float]] flipX: bool flipY: bool color: Color @@ -138,6 +141,7 @@ class Renderer: vsync: bool = False, target_texture: bool = False, ) -> None: ... + @staticmethod def from_window(window: Window) -> Renderer: ... draw_blend_mode: int draw_color: Color @@ -145,8 +149,8 @@ class Renderer: def present(self) -> None: ... def get_viewport(self) -> Rect: ... def set_viewport(self, area: Optional[_CanBeRect]) -> None: ... - logical_size: Iterable[int, int] - scale: Iterable[float, float] + logical_size: Iterable[int] + scale: Iterable[float] target: Union[Texture, None] def blit( self, @@ -155,8 +159,8 @@ class Renderer: area: Optional[_CanBeRect] = None, special_flags: int = 0, ) -> Rect: ... - def draw_line(self, p1: Iterable[int, int], p2: Iterable[int, int]) -> None: ... - def draw_point(self, point: Iterable[int, int]) -> None: ... + def draw_line(self, p1: Iterable[int], p2: Iterable[int]) -> None: ... + def draw_point(self, point: Iterable[int]) -> None: ... def draw_rect(self, rect: _CanBeRect) -> None: ... def fill_rect(self, rect: _CanBeRect) -> None: ... def to_surface(