Skip to content

Commit 1242584

Browse files
committed
Implement draw_triangle and draw_quad in pygame._sdl2
1 parent a775a50 commit 1242584

File tree

6 files changed

+9783
-6439
lines changed

6 files changed

+9783
-6439
lines changed

buildconfig/stubs/pygame/_sdl2/video.pyi

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ class Texture:
9696
flip_x: bool = False,
9797
flip_y: bool = False,
9898
) -> None: ...
99+
def draw_triangle(
100+
self,
101+
p1_xy,
102+
p2_xy,
103+
p3_xy,
104+
p1_uv=(0.0, 0.0),
105+
p2_uv=(1.0, 1.0),
106+
p3_uv=(0.0, 1.0),
107+
p1_mod=(255, 255, 255, 255),
108+
p2_mod=(255, 255, 255, 255),
109+
p3_mod=(255, 255, 255, 255),
110+
) -> None: ...
111+
def draw_quad(
112+
self,
113+
p1_xy,
114+
p2_xy,
115+
p3_xy,
116+
p4_xy,
117+
p1_uv=(0.0, 0.0),
118+
p2_uv=(1.0, 0.0),
119+
p3_uv=(1.0, 1.0),
120+
p4_uv=(0.0, 1.0),
121+
p1_mod=(255, 255, 255, 255),
122+
p2_mod=(255, 255, 255, 255),
123+
p3_mod=(255, 255, 255, 255),
124+
p4_mod=(255, 255, 255, 255),
125+
) -> None: ...
99126
def update(self, surface: Surface, area: Optional[RectValue] = None) -> None: ...
100127

101128
class Image:
@@ -149,6 +176,18 @@ class Renderer:
149176
def draw_point(self, point: Iterable[int]) -> None: ...
150177
def draw_rect(self, rect: RectValue) -> None: ...
151178
def fill_rect(self, rect: RectValue) -> None: ...
179+
def draw_triangle(
180+
self, p1: Iterable[int], p2: Iterable[int], p3: Iterable[int]
181+
) -> None: ...
182+
def fill_triangle(
183+
self, p1: Iterable[int], p2: Iterable[int], p3: Iterable[int]
184+
) -> None: ...
185+
def draw_quad(
186+
self, p1: Iterable[int], p2: Iterable[int], p3: Iterable[int], p4: Iterable[int]
187+
) -> None: ...
188+
def fill_quad(
189+
self, p1: Iterable[int], p2: Iterable[int], p3: Iterable[int], p4: Iterable[int]
190+
) -> None: ...
152191
def to_surface(
153192
self, surface: Optional[Surface] = None, area: Optional[RectValue] = None
154193
) -> Surface: ...

docs/reST/ref/sdl2_video.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@
178178
| :sl:`Copy a portion of the texture to the rendering target.`
179179
| :sg:`draw(srcrect=None, dstrect=None, angle=0, origin=None, flip_x=False, flip_y=False) -> None`
180180
181+
.. method:: draw_triangle
182+
183+
| :sl:`Copy a triangle portion of the texture to the rendering target by vertices coordinates.`
184+
| :sg:`draw_triangle(p1_xy, p2_xy, p3_xy, p1_uv=(0.0, 0.0), p2_uv=(1.0, 1.0), p3_uv=(0.0, 1.0), p1_mod=(255, 255, 255, 255), p2_mod=(255, 255, 255, 255), p3_mod=(255, 255, 255, 255)) -> None`
185+
186+
.. method:: draw_quad
187+
188+
| :sl:`Copy a quad portion of the texture to the rendering target by vertices coordinates.`
189+
| :sg:`draw_quad(p1_xy, p2_xy, p3_xy, p4_xy, p1_uv=(0.0, 0.0), p2_uv=(1.0, 0.0), p3_uv=(1.0, 1.0), p4_uv=(0.0, 1.0), p1_mod=(255, 255, 255, 255), p2_mod=(255, 255, 255, 255), p3_mod=(255, 255, 255, 255), p4_mod=(255, 255, 255, 255)) -> None`
190+
181191
.. method:: update
182192

183193
| :sl:`Update the texture with a Surface. WARNING: Slow operation, use sparingly.`
@@ -326,4 +336,24 @@
326336
.. method:: to_surface
327337

328338
| :sl:`Read pixels from current render target and create a pygame.Surface. WARNING: Slow operation, use sparingly.`
329-
| :sg:`to_surface(surface=None, area=None)-> Surface`
339+
| :sg:`to_surface(surface=None, area=None)-> Surface`
340+
341+
.. method:: draw_triangle
342+
343+
| :sl:`Draws a triangle.`
344+
| :sg:`draw_triangle(p1, p2, p3) -> None`
345+
346+
.. method:: fill_triangle
347+
348+
| :sl:`Fills a triangle.`
349+
| :sg:`fill_triangle(p1, p2, p3) -> None`
350+
351+
.. method:: draw_quad
352+
353+
| :sl:`Draws a quad.`
354+
| :sg:`draw_quad(p1, p2, p3, p4) -> None`
355+
356+
.. method:: fill_quad
357+
358+
| :sl:`Fills a quad.`
359+
| :sg:`fill_quad(p1, p2, p3, p4) -> None`

0 commit comments

Comments
 (0)