Ejemplo n.º 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)))
Ejemplo n.º 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)))
Ejemplo n.º 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)))
Ejemplo n.º 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)))
Ejemplo n.º 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)))
Ejemplo n.º 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)))
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)))
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)))
Ejemplo n.º 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
Ejemplo n.º 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))
Ejemplo n.º 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)))
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 20
0
 def __del__(self):
     check_ptr_err(lib.SDL_GameControllerClose(self._ptr))
Ejemplo n.º 21
0
 def from_path(path, size):
     font = object.__new__(Font)
     font._ptr = check_ptr_err(lib.TTF_OpenFont(path, size))
     return font
Ejemplo n.º 22
0
 def __init__(self, index=0):
     self._ptr = check_ptr_err(lib.SDL_GameControllerOpen(index))
Ejemplo n.º 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))