Beispiel #1
0
def load(file):
    """Load an image from a file name in a new surface. Type detected from file name.
    Args
        file: The name of the image file.

    Returns:
        A new surface.

    """
    return Surface._from_ptr(check_ptr_err(lib.IMG_Load(file)))
Beispiel #2
0
def load(file):
    """Load an image from a file name in a new surface. Type detected from file name.
    Args
        file: The name of the image file.

    Returns:
        A new surface.

    """
    return Surface._from_ptr(check_ptr_err(lib.IMG_Load(file)))
Beispiel #3
0
def load_texture(renderer, file):
    """Load an image directly into a render texture.
    Args:
        renderer: The renderer to make the texture.
        file: The image file to load.

    Returns:
        A new texture
    """
    return Texture._from_ptr(check_ptr_err(lib.IMG_LoadTexture(renderer._ptr, file)))
Beispiel #4
0
def load_texture(renderer, file):
    """Load an image directly into a render texture.
    Args:
        renderer: The renderer to make the texture.
        file: The image file to load.

    Returns:
        A new texture
    """
    return Texture._from_ptr(
        check_ptr_err(lib.IMG_LoadTexture(renderer._ptr, file)))
Beispiel #5
0
    def __init__(self, window, index=-1, flags=frozenset()):
        """Create a 2D rendering context for a window.

        Args:
            window (Window): The window where rendering is displayed.
            index (int): The index of the rendering driver to initialize, or -1 to initialize the first one supporting
                         the requested flags.
            flags (Set[RendererFlags]): The requested renderer flags.

        Raises:
            SDLError: If there was an error creating the renderer.
        """
        self._ptr = check_ptr_err(lib.SDL_CreateRenderer(window._ptr, index, enumtools.get_mask(flags)))
Beispiel #6
0
    def __init__(self, window, index=-1, flags=frozenset()):
        """Create a 2D rendering context for a window.

        Args:
            window (Window): The window where rendering is displayed.
            index (int): The index of the rendering driver to initialize, or -1 to initialize the first one supporting
                         the requested flags.
            flags (Set[RendererFlags]): The requested renderer flags.

        Raises:
            SDLError: If there was an error creating the renderer.
        """
        self._ptr = check_ptr_err(
            lib.SDL_CreateRenderer(window._ptr, index,
                                   enumtools.get_mask(flags)))
Beispiel #7
0
    def __init__(self, renderer, fmt, access, w, h):
        """Create a texture for a rendering context.

        Args:
            renderer (Renderer): The renderer.
            fmt (PixelFormat): The format of the texture.
            access (TextureAccess): The access value for the texture.
            w (int): The width of the texture in pixels.
            h (int): The height of the texture in pixels.

        Raises:
            SDLError: If no rendering context was active, the format was unsupported, or the width or height were out
                      of range.
        """
        self._ptr = check_ptr_err(lib.SDL_CreateTexture(renderer._ptr, fmt, access, w, h))
Beispiel #8
0
    def create_software_renderer(self, surface):
        """Create a 2D software rendering context for a surface.

        Args:
            surface (Surface): The surface where rendering is done.

        Returns:
            Renderer: A 2D software rendering context.

        Raises:
            SDLError: If there was an error creating the renderer.
        """
        renderer = object.__new__(Renderer)
        renderer._ptr = self._ptr = check_ptr_err(lib.SDL_CreateSoftwareRenderer(surface._ptr))
        return renderer
Beispiel #9
0
    def from_surface(renderer, surface):
        """Create a texture from an existing surface.

        Args:
            surface (Surface): The surface containing pixel data used to fill the texture.

        Returns:
            Texture: A texture containing the pixels from surface.

        Raises:
            SDLError: If an error is encountered.
        """
        texture = object.__new__(Texture)
        texture._ptr = check_ptr_err(lib.SDL_CreateTextureFromSurface(renderer._ptr, surface._ptr))
        return texture
Beispiel #10
0
    def __init__(self, title='sdl2', x=lib.SDL_WINDOWPOS_CENTERED, y=lib.SDL_WINDOWPOS_CENTERED,
                 w=640, h=480, flags=frozenset()):
        """Create a window with the specified position, dimensions, and flags.

        Args:
            title (str): The title of the window.
            x (int): The x postion of the window.
            y (int): The y position of the window.
            w (int): The width of the window.
            h (int): The height of the window.
            flags (Set[WindowFlags]): The flags for the window.
        Raises:
            SDLError: If the window could not be created.
        """
        self._ptr = check_ptr_err(lib.SDL_CreateWindow(title.encode('utf-8'), x, y, w, h, enumtools.get_mask(flags)))
Beispiel #11
0
    def __init__(self, renderer, fmt, access, w, h):
        """Create a texture for a rendering context.

        Args:
            renderer (Renderer): The renderer.
            fmt (PixelFormat): The format of the texture.
            access (TextureAccess): The access value for the texture.
            w (int): The width of the texture in pixels.
            h (int): The height of the texture in pixels.

        Raises:
            SDLError: If no rendering context was active, the format was unsupported, or the width or height were out
                      of range.
        """
        self._ptr = check_ptr_err(
            lib.SDL_CreateTexture(renderer._ptr, fmt, access, w, h))
Beispiel #12
0
    def from_surface(renderer, surface):
        """Create a texture from an existing surface.

        Args:
            surface (Surface): The surface containing pixel data used to fill the texture.

        Returns:
            Texture: A texture containing the pixels from surface.

        Raises:
            SDLError: If an error is encountered.
        """
        texture = object.__new__(Texture)
        texture._ptr = check_ptr_err(
            lib.SDL_CreateTextureFromSurface(renderer._ptr, surface._ptr))
        return texture
Beispiel #13
0
    def create_software_renderer(self, surface):
        """Create a 2D software rendering context for a surface.

        Args:
            surface (Surface): The surface where rendering is done.

        Returns:
            Renderer: A 2D software rendering context.

        Raises:
            SDLError: If there was an error creating the renderer.
        """
        renderer = object.__new__(Renderer)
        renderer._ptr = self._ptr = check_ptr_err(
            lib.SDL_CreateSoftwareRenderer(surface._ptr))
        return renderer
Beispiel #14
0
    def __init__(self,
                 title='sdl2',
                 x=lib.SDL_WINDOWPOS_CENTERED,
                 y=lib.SDL_WINDOWPOS_CENTERED,
                 w=640,
                 h=480,
                 flags=frozenset()):
        """Create a window with the specified position, dimensions, and flags.

        Args:
            title (str): The title of the window.
            x (int): The x postion of the window.
            y (int): The y position of the window.
            w (int): The width of the window.
            h (int): The height of the window.
            flags (Set[WindowFlags]): The flags for the window.
        Raises:
            SDLError: If the window could not be created.
        """
        self._ptr = check_ptr_err(
            lib.SDL_CreateWindow(title.encode('utf-8'), x, y, w, h,
                                 enumtools.get_mask(flags)))
Beispiel #15
0
 def from_path(path):
     rw = check_ptr_err(lib.SDL_RWFromFile(path, "rb"))
     chunk = object.__new__(Chunk)
     chunk._ptr = check_ptr_err(lib.Mix_LoadWAV_RW(rw, 1))
     return chunk
Beispiel #16
0
 def __init__(self, audio_bytes):
     rw = check_ptr_err(lib.SDL_RWFromConstMem(audio_bytes, len(audio_bytes)))
     self._ptr = check_ptr_err(lib.Mix_LoadWAV_RW(rw, 1))
Beispiel #17
0
 def render_blended(self, text, color):
     return Surface._from_ptr(check_ptr_err(lib.TTF_RenderUTF8_Blended(self._ptr, text.encode('utf-8'), color)))
Beispiel #18
0
 def __init__(self, audio_bytes):
     rw = check_ptr_err(
         lib.SDL_RWFromConstMem(audio_bytes, len(audio_bytes)))
     self._ptr = check_ptr_err(lib.Mix_LoadWAV_RW(rw, 1))
Beispiel #19
0
 def from_path(path):
     rw = check_ptr_err(lib.SDL_RWFromFile(path, "rb"))
     chunk = object.__new__(Chunk)
     chunk._ptr = check_ptr_err(lib.Mix_LoadWAV_RW(rw, 1))
     return chunk
Beispiel #20
0
 def __del__(self):
     check_ptr_err(lib.SDL_GameControllerClose(self._ptr))
Beispiel #21
0
 def from_path(path, size):
     font = object.__new__(Font)
     font._ptr = check_ptr_err(lib.TTF_OpenFont(path, size))
     return font
Beispiel #22
0
 def __init__(self, index=0):
     self._ptr = check_ptr_err(lib.SDL_GameControllerOpen(index))
Beispiel #23
0
 def __init__(self, font_bytes, size):
     self._bytes = font_bytes # This is a workaround for some sort of weird lifetime issue.
     rw = check_ptr_err(lib.SDL_RWFromConstMem(self._bytes, len(self._bytes)))
     self._ptr = check_ptr_err(lib.TTF_OpenFontRW(rw, 1, size))