sdl2.ext.draw - Drawing Routines for Software Surfaces

The sdl2.ext.draw module provides some basic methods for drawing to unaccelerated 2D SDL surfaces. At present, the functions in this module can fill the surface with a given color and draw rectangles and lines.

sdl2.ext.draw.prepare_color(color, target)[source]

Prepares a given color for a specific target.

Targets can be SDL_PixelFormat, SDL_Surface, or SoftwareSprite objects.

Colors can be provided in any form supported by sdl2.ext.convert_to_color().

Parameters:
  • color (sdl2.ext.Color) – The color to prepare for the pixel format of the given target.
  • target (SDL_PixelFormat, SDL_Surface, SoftwareSprite) – The target pixel format, surface, or sprite for which the color should be prepared.
Returns:

An integer approximating the given color in the target’s pixel format.

Return type:

int

sdl2.ext.draw.fill(target, color, area=None)[source]

Fills one or more rectangular areas on a surface with a given color.

Fill areas can be specified as 4-item (x, y, w, h) tuples, SDL_Rect objects, or a list containing multiple areas to fill in either format. If no area is provided, the entire target will be filled with the provided color.

The fill color can be provided in any format supported by convert_to_color().

Parameters:
  • target (SDL_Surface, SoftwareSprite) – The target surface or sprite to modify.
  • color (sdl2.ext.Color) – The color with which to fill the specified region(s) of the target.
  • area (tuple, SDL_Rect, list, optional) – The rectangular region (or regions) of the target surface to fill with the given colour. If no regions are specified (the default), the whole surface of the target will be filled.
sdl2.ext.draw.line(target, color, dline, width=1)[source]

Draws one or lines on a surface in a given color.

The fill color can be provided in any format supported by convert_to_color().

Parameters:
  • target (SDL_Surface, SoftwareSprite) – The target surface or sprite to modify.
  • color (sdl2.ext.Color) – The color with which to draw lines.
  • dline (tuple, list) – The (x1, y1, x2, y2) integer coordinates of a line to draw, or a list of multiple sets of (x1, y1, x2, y2) coordinates for multiple lines.
  • width (int, optional) – The width of the line(s) in pixels. Defaults to 1 if not specified.