Skip to content

Commit 1b05ef7

Browse files
authored
Merge pull request #3165 from damusss/use-ColorLike-docs
Improve color notation in the docs
2 parents 908d3ef + 3757c47 commit 1b05ef7

File tree

6 files changed

+46
-51
lines changed

6 files changed

+46
-51
lines changed

docs/reST/ref/draw.rst

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ constrained to that area. The functions return a rectangle representing the
2020
bounding area of changed pixels. This bounding rectangle is the 'minimum'
2121
bounding box that encloses the affected area.
2222

23-
All the drawing functions accept a color argument that can be one of the
24-
following formats:
25-
26-
- a :mod:`pygame.Color` object, or a type (apart from ``int``) that can be passed to
27-
its constructor
28-
- an ``int`` value which must be mapped to the pixel format of the surface
29-
(see :func:`pygame.Surface.map_rgb` and :func:`pygame.Surface.unmap_rgb`)
23+
All the drawing functions accept a color argument that is compatible with
24+
:data:`pygame.typing.ColorLike`.
3025

3126
A color's alpha value will be written directly into the surface (if the
3227
surface contains pixel alphas), but the draw function will not draw
@@ -52,7 +47,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
5247
:param Surface surface: surface to draw on
5348
:param color: color to draw with, the alpha value is optional if using a
5449
tuple ``(RGB[A])``
55-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
50+
:type color: :data:`pygame.typing.ColorLike`
5651
:param Rect rect: rectangle to draw, position and dimensions
5752
:param int width: (optional) used for line thickness or to indicate that
5853
the rectangle is to be filled (not to be confused with the width value
@@ -110,7 +105,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
110105
:param Surface surface: surface to draw on
111106
:param color: color to draw with, the alpha value is optional if using a
112107
tuple ``(RGB[A])``
113-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
108+
:type color: :data:`pygame.typing.ColorLike`
114109
:param points: a sequence of 3 or more (x, y) coordinates that make up the
115110
vertices of the polygon, each point in the sequence must be a
116111
tuple/list/:class:`pygame.math.Vector2` of 2 ints/floats,
@@ -158,7 +153,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
158153
:param Surface surface: surface to draw on
159154
:param color: color to draw with, the alpha value is optional if using a
160155
tuple ``(RGB[A])``
161-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
156+
:type color: :data:`pygame.typing.ColorLike`
162157
:param center: center point of the circle as a sequence of 2 ints/floats,
163158
e.g. ``(x, y)``
164159
:type center: tuple(int or float, int or float) or
@@ -219,7 +214,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
219214
:param Surface surface: surface to draw on
220215
:param color: color to draw with, the alpha value is optional if using a
221216
tuple ``(RGB[A])``
222-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
217+
:type color: :data:`pygame.typing.ColorLike`
223218
:param center: center point of the circle as a sequence of 2 ints/floats,
224219
e.g. ``(x, y)``
225220
:type center: tuple(int or float, int or float) or
@@ -273,7 +268,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
273268
:param Surface surface: surface to draw on
274269
:param color: color to draw with, the alpha value is optional if using a
275270
tuple ``(RGB[A])``
276-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
271+
:type color: :data:`pygame.typing.ColorLike`
277272
:param Rect rect: rectangle to indicate the position and dimensions of the
278273
ellipse, the ellipse will be centered inside the rectangle and bounded
279274
by it
@@ -314,7 +309,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
314309
:param Surface surface: surface to draw on
315310
:param color: color to draw with, the alpha value is optional if using a
316311
tuple ``(RGB[A])``
317-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
312+
:type color: :data:`pygame.typing.ColorLike`
318313
:param Rect rect: rectangle to indicate the position and dimensions of the
319314
ellipse which the arc will be based on, the ellipse will be centered
320315
inside the rectangle
@@ -364,7 +359,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
364359
:param Surface surface: surface to draw on
365360
:param color: color to draw with, the alpha value is optional if using a
366361
tuple ``(RGB[A])``
367-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
362+
:type color: :data:`pygame.typing.ColorLike`
368363
:param start_pos: start position of the line, (x, y)
369364
:type start_pos: tuple(int or float, int or float) or
370365
list(int or float, int or float) or Vector2(int or float, int or float)
@@ -416,7 +411,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
416411
:param Surface surface: surface to draw on
417412
:param color: color to draw with, the alpha value is optional if using a
418413
tuple ``(RGB[A])``
419-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
414+
:type color: :data:`pygame.typing.ColorLike`
420415
:param bool closed: if ``True`` an additional line segment is drawn between
421416
the first and last points in the ``points`` sequence
422417
:param points: a sequence of 2 or more (x, y) coordinates, where each
@@ -474,7 +469,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
474469
:param Surface surface: surface to draw on
475470
:param color: color to draw with, the alpha value is optional if using a
476471
tuple ``(RGB[A])``
477-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
472+
:type color: :data:`pygame.typing.ColorLike`
478473
:param start_pos: start position of the line, (x, y)
479474
:type start_pos: tuple(int or float, int or float) or
480475
list(int or float, int or float) or Vector2(int or float, int or float)
@@ -513,7 +508,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
513508
:param Surface surface: surface to draw on
514509
:param color: color to draw with, the alpha value is optional if using a
515510
tuple ``(RGB[A])``
516-
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
511+
:type color: :data:`pygame.typing.ColorLike`
517512
:param bool closed: if ``True`` an additional line segment is drawn between
518513
the first and last points in the ``points`` sequence
519514
:param points: a sequence of 2 or more (x, y) coordinates, where each

docs/reST/ref/mask.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,12 @@ to store which parts collide.
593593
``(255, 255, 255, 255)``, white), use ``None`` to skip drawing the set
594594
bits, the ``setsurface`` parameter (if set) will takes precedence over
595595
this parameter
596-
:type setcolor: Color or str or int or tuple(int, int, int, [int]) or
597-
list(int, int, int, [int]) or None
596+
:type setcolor: :data:`pygame.typing.ColorLike` or ``None``
598597
:param unsetcolor: (optional) color to draw unset bits (default is
599598
``(0, 0, 0, 255)``, black), use ``None`` to skip drawing the unset
600599
bits, the ``unsetsurface`` parameter (if set) will takes precedence
601600
over this parameter
602-
:type unsetcolor: Color or str or int or tuple(int, int, int, [int]) or
603-
list(int, int, int, [int]) or None
601+
:type unsetcolor: :data:`pygame.typing.ColorLike` or ``None``
604602
:param dest: (optional) surface destination of where to position the
605603
topleft corner of the mask being drawn (default is ``(0, 0)``), if a
606604
Rect is used as the ``dest`` parameter, its ``x`` and ``y`` attributes

docs/reST/ref/surface.rst

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,9 @@
298298
entire Surface will be filled. The rect argument will limit the fill to a
299299
specific area. The fill will also be contained by the Surface clip area.
300300

301-
The color argument can be an ``RGB`` sequence, an ``RGBA`` sequence,
302-
a string (for :doc:`color_list`), or a mapped color index. If using ``RGBA``,
303-
the Alpha (A part of ``RGBA``) is ignored unless the surface uses per pixel
304-
alpha (Surface has the ``SRCALPHA`` flag).
301+
The color argument should be compatible with :data:`pygame.typing.ColorLike`.
302+
If using ``RGBA``, the Alpha (A part of ``RGBA``) is ignored unless the surface
303+
uses per pixel alpha (Surface has the ``SRCALPHA`` flag).
305304

306305
The special_flags argument controls how the colors are combined. See :doc:`special_flags_list`
307306
for a list of possible values.
@@ -338,9 +337,8 @@
338337
339338
Set the current color key for the Surface. When blitting this Surface
340339
onto a destination, any pixels that have the same color as the colorkey
341-
will be transparent. The color can be an ``RGB`` color, a string
342-
(for :doc:`color_list`), or a mapped color integer. If ``None`` is passed,
343-
the colorkey will be unset.
340+
will be transparent. The color should be compatible with :data:`pygame.typing.ColorLike`.
341+
If ``None`` is passed, the colorkey will be unset.
344342

345343
The colorkey will be ignored if the Surface is formatted to use per pixel
346344
alpha values. The colorkey can be mixed with the full Surface alpha
@@ -355,7 +353,7 @@
355353
.. method:: get_colorkey
356354

357355
| :sl:`get the current transparent colorkey`
358-
| :sg:`get_colorkey() -> RGB or None`
356+
| :sg:`get_colorkey() -> RGBA or None`
359357
360358
Return the current colorkey value for the Surface. If the colorkey is not
361359
set then ``None`` is returned.
@@ -510,10 +508,10 @@
510508
| :sl:`set the color value for a single pixel`
511509
| :sg:`set_at((x, y), color, /) -> None`
512510
513-
Set the color of a single pixel at the specified coordinates to be an ``RGB``,
514-
``RGBA``, string (for :doc:`color_list`), or mapped integer color value. If the Surface
515-
does not have per pixel alphas, the alpha value is ignored. Setting pixels outside the
516-
Surface area or outside the Surface clipping will have no effect.
511+
Set the color of a single pixel at the specified coordinates to be a
512+
:data:`pygame.typing.ColorLike` value. If the Surface does not have per pixel alphas,
513+
the alpha value is ignored. Setting pixels outside the Surface area or outside
514+
the Surface clipping will have no effect.
517515

518516
Getting and setting pixels one at a time is generally too slow to be used
519517
in a game or realtime situation.
@@ -550,7 +548,7 @@
550548
.. method:: get_palette
551549

552550
| :sl:`get the color index palette for an 8-bit Surface`
553-
| :sg:`get_palette() -> [RGB, RGB, RGB, ...]`
551+
| :sg:`get_palette() -> [Color, Color, Color, ...]`
554552
555553
Return a list of up to 256 color elements that represent the indexed
556554
colors used in an 8-bit Surface. The returned list is a copy of the
@@ -565,7 +563,7 @@
565563
.. method:: get_palette_at
566564

567565
| :sl:`get the color for a single entry in a palette`
568-
| :sg:`get_palette_at(index, /) -> RGB`
566+
| :sg:`get_palette_at(index, /) -> Color`
569567
570568
Returns the red, green, and blue color values for a single index in a
571569
Surface palette. The index should be a value from 0 to 255.
@@ -578,7 +576,7 @@
578576
.. method:: set_palette
579577

580578
| :sl:`set the color palette for an 8-bit Surface`
581-
| :sg:`set_palette([RGB, RGB, RGB, ...], /) -> None`
579+
| :sg:`set_palette([color, color, color, ...], /) -> None`
582580
583581
Set the full palette for an 8-bit Surface. This will replace the colors in
584582
the existing palette. A partial palette can be passed and only the first
@@ -591,7 +589,7 @@
591589
.. method:: set_palette_at
592590

593591
| :sl:`set the color for a single index in an 8-bit Surface palette`
594-
| :sg:`set_palette_at(index, RGB, /) -> None`
592+
| :sg:`set_palette_at(index, color, /) -> None`
595593
596594
Set the palette value for a single entry in a Surface palette. The index
597595
should be a value from 0 to 255.
@@ -605,10 +603,10 @@
605603
| :sl:`convert a color into a mapped color value`
606604
| :sg:`map_rgb(color, /) -> mapped_int`
607605
608-
Convert an ``RGBA`` color into the mapped integer value for this Surface.
609-
The returned integer will contain no more bits than the bit depth of the
610-
Surface. Mapped color values are not often used inside pygame, but can be
611-
passed to most functions that require a Surface and a color.
606+
Convert a :data:`pygame.typing.ColorLike` into the mapped integer value
607+
for this Surface. The returned integer will contain no more bits than the
608+
bit depth of the Surface. Mapped color values are not often used inside pygame,
609+
but can be passed to most functions that require a Surface and a color.
612610

613611
See the Surface object documentation for more information about colors
614612
and pixel formats.

docs/reST/ref/transform.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ Instead, always begin with the original image and scale to the desired size.)
364364

365365
:param pygame.Surface surface: The target surface.
366366

367-
:param pygame.Color color: Color which all non transparent within the target surface must be set to.
367+
:param color: Color which all non transparent within the target surface must be set to.
368+
:type color: :data:`pygame.typing.ColorLike`
368369

369370
:param dest_surface: Optional destination surface to which the changes will be applied.
370371
:type dest_surface: pygame.Surface or None
@@ -400,15 +401,17 @@ Instead, always begin with the original image and scale to the desired size.)
400401

401402
:param pygame.Surface surf: Surface we are looking at.
402403

403-
:param pygame.Color search_color: Color we are searching for.
404+
:param search_color: Color we are searching for.
405+
:type color: :data:`pygame.typing.ColorLike`
404406

405-
:param pygame.Color threshold: Within this distance from search_color (or search_surf).
407+
:param threshold: Within this distance from search_color (or search_surf).
406408
You can use a threshold of (r,g,b,a) where the r,g,b can have different
407409
thresholds. So you could use an r threshold of 40 and a blue threshold of 2
408410
if you like.
411+
:type color: :data:`pygame.typing.ColorLike`
409412

410413
:param set_color: Color we set in dest_surf.
411-
:type set_color: pygame.Color or None
414+
:type color: :data:`pygame.typing.ColorLike` or ``None``
412415

413416
:param int set_behavior:
414417
- set_behavior=1 (default). Pixels in dest_surface will be changed to 'set_color'.

docs/reST/ref/typing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ type aliases for proper typehint annotations.
6060
* ``(r, g, b)``
6161
* ``(r, g, b, a)``
6262
* ``[r, g, b, a]``
63-
* ``"green"``
63+
* ``"green"`` (:doc:`color_list`)
64+
* ``"#rrggbbaa"``
6465
* ``0`` (mapped color)
6566

6667
.. data:: RectLike

src_c/doc/surface_doc.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define DOC_SURFACE_FILL "fill(color, rect=None, special_flags=0) -> Rect\nfill Surface with a solid color"
1010
#define DOC_SURFACE_SCROLL "scroll(dx=0, dy=0, /) -> None\nshift the surface image in place"
1111
#define DOC_SURFACE_SETCOLORKEY "set_colorkey(color, flags=0, /) -> None\nset_colorkey(None) -> None\nset the transparent colorkey"
12-
#define DOC_SURFACE_GETCOLORKEY "get_colorkey() -> RGB or None\nget the current transparent colorkey"
12+
#define DOC_SURFACE_GETCOLORKEY "get_colorkey() -> RGBA or None\nget the current transparent colorkey"
1313
#define DOC_SURFACE_SETALPHA "set_alpha(value, flags=0, /) -> None\nset_alpha(None) -> None\nset the alpha value for the full Surface"
1414
#define DOC_SURFACE_GETALPHA "get_alpha() -> int_value\nget the current Surface transparency value"
1515
#define DOC_SURFACE_LOCK "lock() -> None\nlock the Surface memory for pixel access"
@@ -20,10 +20,10 @@
2020
#define DOC_SURFACE_GETAT "get_at((x, y), /) -> Color\nget the color value at a single pixel"
2121
#define DOC_SURFACE_SETAT "set_at((x, y), color, /) -> None\nset the color value for a single pixel"
2222
#define DOC_SURFACE_GETATMAPPED "get_at_mapped((x, y), /) -> Color\nget the mapped color value at a single pixel"
23-
#define DOC_SURFACE_GETPALETTE "get_palette() -> [RGB, RGB, RGB, ...]\nget the color index palette for an 8-bit Surface"
24-
#define DOC_SURFACE_GETPALETTEAT "get_palette_at(index, /) -> RGB\nget the color for a single entry in a palette"
25-
#define DOC_SURFACE_SETPALETTE "set_palette([RGB, RGB, RGB, ...], /) -> None\nset the color palette for an 8-bit Surface"
26-
#define DOC_SURFACE_SETPALETTEAT "set_palette_at(index, RGB, /) -> None\nset the color for a single index in an 8-bit Surface palette"
23+
#define DOC_SURFACE_GETPALETTE "get_palette() -> [Color, Color, Color, ...]\nget the color index palette for an 8-bit Surface"
24+
#define DOC_SURFACE_GETPALETTEAT "get_palette_at(index, /) -> Color\nget the color for a single entry in a palette"
25+
#define DOC_SURFACE_SETPALETTE "set_palette([color, color, color, ...], /) -> None\nset the color palette for an 8-bit Surface"
26+
#define DOC_SURFACE_SETPALETTEAT "set_palette_at(index, color, /) -> None\nset the color for a single index in an 8-bit Surface palette"
2727
#define DOC_SURFACE_MAPRGB "map_rgb(color, /) -> mapped_int\nconvert a color into a mapped color value"
2828
#define DOC_SURFACE_UNMAPRGB "unmap_rgb(mapped_int, /) -> Color\nconvert a mapped integer color value into a Color"
2929
#define DOC_SURFACE_SETCLIP "set_clip(rect, /) -> None\nset_clip(None) -> None\nset the current clipping area of the Surface"

0 commit comments

Comments
 (0)