Ejemplo n.º 1
0
def poll():
    """Polls for currently pending events.

    Returns:
        Iterable[Event]: Events from the event queue.
    """
    event_ptr = ffi.new('SDL_Event *')
    while lib.SDL_PollEvent(event_ptr):
        yield Event._from_ptr(event_ptr)
        event_ptr = ffi.new('SDL_Event *')
Ejemplo n.º 2
0
def poll():
    """Polls for currently pending events.

    Returns:
        Iterable[Event]: Events from the event queue.
    """
    event_ptr = ffi.new('SDL_Event *')
    while lib.SDL_PollEvent(event_ptr):
        yield Event._from_ptr(event_ptr)
        event_ptr = ffi.new('SDL_Event *')
Ejemplo n.º 3
0
 def access(self):
     """TextureAccess: The actual access to the texture."""
     access = ffi.new('int *')
     check_int_err(
         lib.SDL_QueryTexture(self._ptr, ffi.NULL, access, ffi.NULL,
                              ffi.NULL))
     return TextureAccess(access[0])
Ejemplo n.º 4
0
 def color_mod(self):
     """Tuple[int, int, int]: The additional color value used in render copy operations in (red, green, blue)
                              format.
     """
     rgb = ffi.new('Uint8[]', 3)
     check_int_err(lib.SDL_GetTextureColorMod(self._ptr, rgb + 0, rgb + 1, rgb + 2))
     return (rgb[0], rgb[1], rgb[2])
Ejemplo n.º 5
0
 def format(self):
     """PixelFormat: The raw format of the texture. The actual format may differ, but pixel transfers will use this
                     format.
     """
     fmt = ffi.new('Uint32 *')
     check_int_err(lib.SDL_QueryTexture(self._ptr, fmt, ffi.NULL, ffi.NULL, ffi.NULL))
     return PixelFormat(fmt[0])
Ejemplo n.º 6
0
 def draw_color(self):
     """Tuple[int, int, int, int]: The color used for drawing operations in (red, green, blue, alpha) format."""
     rgba = ffi.new('Uint8[]', 4)
     check_int_err(
         lib.SDL_GetRenderDrawColor(self._ptr, rgba + 0, rgba + 1, rgba + 2,
                                    rgba + 3))
     return (rgba[0], rgba[1], rgba[2], rgba[3])
Ejemplo n.º 7
0
    def __init__(self, x=0, y=0):
        """Construct a new point.

        Args:
            x (int): The x position of the point.
            y (int): The y position of the point.
        """
        self._ptr = ffi.new('SDL_Point *', [x, y])
Ejemplo n.º 8
0
 def color_mod(self):
     """Tuple[int, int, int]: The additional color value used in render copy operations in (red, green, blue)
                              format.
     """
     rgb = ffi.new('Uint8[]', 3)
     check_int_err(
         lib.SDL_GetTextureColorMod(self._ptr, rgb + 0, rgb + 1, rgb + 2))
     return (rgb[0], rgb[1], rgb[2])
Ejemplo n.º 9
0
 def format(self):
     """PixelFormat: The raw format of the texture. The actual format may differ, but pixel transfers will use this
                     format.
     """
     fmt = ffi.new('Uint32 *')
     check_int_err(
         lib.SDL_QueryTexture(self._ptr, fmt, ffi.NULL, ffi.NULL, ffi.NULL))
     return PixelFormat(fmt[0])
Ejemplo n.º 10
0
    def __init__(self, x=0, y=0):
        """Construct a new point.

        Args:
            x (int): The x position of the point.
            y (int): The y position of the point.
        """
        self._ptr = ffi.new('SDL_Point *', [x, y])
Ejemplo n.º 11
0
def _peep(quantity, action, min_type, max_type):
    events = ffi.new('SDL_Event[]', quantity)
    quantity_retrieved = check_int_err(lib.SDL_PeepEvents(events, quantity, action, min_type, max_type))

    result = []
    for i in range(quantity_retrieved):
        event_ptr = events + i
        _event_reference_map[event_ptr] = events
        result.append(Event._from_ptr(event_ptr))
    return result
Ejemplo n.º 12
0
    def __init__(self, x=0, y=0, w=0, h=0):
        """Construct a new Rect with the given position and size.

        Args:
            x (int): The x position of the upper left corner of the rectangle.
            y (int): The y position of the upper left corner of the rectangle.
            w (int): The width of the rectangle.
            h (int): The height of the rectangle.
        """
        self._ptr = ffi.new('SDL_Rect *', [x, y, w, h])
Ejemplo n.º 13
0
    def __init__(self, x=0, y=0, w=0, h=0):
        """Construct a new Rect with the given position and size.

        Args:
            x (int): The x position of the upper left corner of the rectangle.
            y (int): The y position of the upper left corner of the rectangle.
            w (int): The width of the rectangle.
            h (int): The height of the rectangle.
        """
        self._ptr = ffi.new('SDL_Rect *', [x, y, w, h])
Ejemplo n.º 14
0
def _peep(quantity, action, min_type, max_type):
    events = ffi.new('SDL_Event[]', quantity)
    quantity_retrieved = check_int_err(
        lib.SDL_PeepEvents(events, quantity, action, min_type, max_type))

    result = []
    for i in range(quantity_retrieved):
        event_ptr = events + i
        _event_reference_map[event_ptr] = events
        result.append(Event._from_ptr(event_ptr))
    return result
Ejemplo n.º 15
0
    def draw_lines(self, *points):
        """Draw a series of connected lines on the current rendering target.

        Args:
            *points (Point): The points along the lines.

        Raises:
            SDLError: If an error is encountered.
        """
        point_array = ffi.new('SDL_Point[]', len(points))
        for i, p in enumerate(points):
            point_array[i] = p._ptr[0]
        check_int_err(lib.SDL_RenderDrawLines(self._ptr, point_array, len(points)))
Ejemplo n.º 16
0
    def draw_points(self, *points):
        """Draw multiple points on the current rendering target.

        Args:
            *points (Point): The points to draw.

        Raises:
            SDLError: If an error is encountered.
        """
        point_array = ffi.new('SDL_Point[]', len(points))
        for i, p in enumerate(points):
            point_array[i] = p._ptr[0]
        check_int_err(lib.SDL_RenderDrawPoints(self._ptr, point_array, len(points)))
Ejemplo n.º 17
0
    def fill_rects(self, *rects):
        """Fill some number of rectangles on the current rendering target with the drawing color.

        Args:
            *rects (Rect): The destination rectangles.

        Raises:
            SDLError: If an error is encountered.
        """
        rect_array = ffi.new('SDL_Rect[]', len(rects))
        for i, r in enumerate(rects):
            rect_array[i] = r._ptr[0]
        check_int_err(lib.SDL_RenderFillRects(self._ptr, rect_array, len(rects)))
Ejemplo n.º 18
0
    def draw_lines(self, *points):
        """Draw a series of connected lines on the current rendering target.

        Args:
            *points (Point): The points along the lines.

        Raises:
            SDLError: If an error is encountered.
        """
        point_array = ffi.new('SDL_Point[]', len(points))
        for i, p in enumerate(points):
            point_array[i] = p._ptr[0]
        check_int_err(
            lib.SDL_RenderDrawLines(self._ptr, point_array, len(points)))
Ejemplo n.º 19
0
    def draw_points(self, *points):
        """Draw multiple points on the current rendering target.

        Args:
            *points (Point): The points to draw.

        Raises:
            SDLError: If an error is encountered.
        """
        point_array = ffi.new('SDL_Point[]', len(points))
        for i, p in enumerate(points):
            point_array[i] = p._ptr[0]
        check_int_err(
            lib.SDL_RenderDrawPoints(self._ptr, point_array, len(points)))
Ejemplo n.º 20
0
    def fill_rects(self, *rects):
        """Fill some number of rectangles on the current rendering target with the drawing color.

        Args:
            *rects (Rect): The destination rectangles.

        Raises:
            SDLError: If an error is encountered.
        """
        rect_array = ffi.new('SDL_Rect[]', len(rects))
        for i, r in enumerate(rects):
            rect_array[i] = r._ptr[0]
        check_int_err(
            lib.SDL_RenderFillRects(self._ptr, rect_array, len(rects)))
Ejemplo n.º 21
0
    def enclose_points(points, clip_rect):
        """Return the minimal rectangle enclosing the given set of points

        Args:
            points (List[Point]): The set of points that the new Rect must enclose.
            clip_rect (Rect): A clipping Rect.

        Returns:
            Rect: A new Rect enclosing the given points.
        """
        point_array = ffi.new('SDL_Point[]', len(points))
        for i, p in enumerate(points):
            point_array[i] = p._ptr
        enclosing_rect = Rect()
        if lib.SDL_EnclosePoints(point_array, len(points), clip_rect._ptr, enclosing_rect._ptr):
            return enclosing_rect
        else:
            return None
Ejemplo n.º 22
0
    def enclose_points(points, clip_rect):
        """Return the minimal rectangle enclosing the given set of points

        Args:
            points (List[Point]): The set of points that the new Rect must enclose.
            clip_rect (Rect): A clipping Rect.

        Returns:
            Rect: A new Rect enclosing the given points.
        """
        point_array = ffi.new('SDL_Point[]', len(points))
        for i, p in enumerate(points):
            point_array[i] = p._ptr
        enclosing_rect = Rect()
        if lib.SDL_EnclosePoints(point_array, len(points), clip_rect._ptr,
                                 enclosing_rect._ptr):
            return enclosing_rect
        else:
            return None
Ejemplo n.º 23
0
 def _get_renderer_info(self):
     info = ffi.new('SDL_RendererInfo *')
     check_int_err(lib.SDL_GetRendererInfo(self._ptr, info))
     return info
Ejemplo n.º 24
0
 def alpha_mod(self):
     """int: The additional alpha value used in render copy operations."""
     a = ffi.new('Uint8 *')
     check_int_err(lib.SDL_GetTextureAlphaMod(self._ptr, a))
     return a[0]
Ejemplo n.º 25
0
 def blend_mode(self):
     """BlendMode: The blend mode used for drawing operations."""
     blend_mode_ptr = ffi.new('int *')
     lib.SDL_GetTextureBlendMode(self._ptr, blend_mode_ptr)
     return BlendMode(blend_mode_ptr[0])
Ejemplo n.º 26
0
 def h(self):
     """int: The height of the texture in pixels."""
     h = ffi.new('int *')
     check_int_err(
         lib.SDL_QueryTexture(self._ptr, ffi.NULL, ffi.NULL, ffi.NULL, h))
     return h[0]
Ejemplo n.º 27
0
 def blend_mode(self):
     """BlendMode: The blend mode used for drawing operations."""
     blend_mode_ptr = ffi.new('int *')
     check_int_err(lib.SDL_GetRenderDrawBlendMode(self._ptr, blend_mode_ptr))
     return BlendMode(blend_mode_ptr[0])
Ejemplo n.º 28
0
 def size(self):
     """Tuple[int, int]: The width and height of the window."""
     size = ffi.new('int[]', 2)
     lib.SDL_GetWindowSize(self._ptr, size + 0, size + 1)
     return (size[0], size[1])
Ejemplo n.º 29
0
 def position(self):
     """Tuple[int, int]: The x and y position of the window."""
     position = ffi.new('int[]', 2)
     lib.SDL_GetWindowPosition(self._ptr, position + 0, position + 1)
     return (position[0], position[1])
Ejemplo n.º 30
0
 def h(self):
     """int: The height of the texture in pixels."""
     h = ffi.new('int *')
     check_int_err(lib.SDL_QueryTexture(self._ptr, ffi.NULL, ffi.NULL, ffi.NULL, h))
     return h[0]
Ejemplo n.º 31
0
 def w(self):
     """int: The width of the texture in pixels."""
     w = ffi.new('int *')
     check_int_err(lib.SDL_QueryTexture(self._ptr, ffi.NULL, ffi.NULL, w, ffi.NULL))
     return w[0]
Ejemplo n.º 32
0
 def blend_mode(self):
     """BlendMode: The blend mode used for drawing operations."""
     blend_mode_ptr = ffi.new('int *')
     lib.SDL_GetTextureBlendMode(self._ptr, blend_mode_ptr)
     return BlendMode(blend_mode_ptr[0])
Ejemplo n.º 33
0
 def alpha_mod(self):
     """int: The additional alpha value used in render copy operations."""
     a = ffi.new('Uint8 *')
     check_int_err(lib.SDL_GetTextureAlphaMod(self._ptr, a))
     return a[0]
Ejemplo n.º 34
0
 def blend_mode(self):
     """BlendMode: The blend mode used for drawing operations."""
     blend_mode_ptr = ffi.new('int *')
     check_int_err(lib.SDL_GetRenderDrawBlendMode(self._ptr,
                                                  blend_mode_ptr))
     return BlendMode(blend_mode_ptr[0])
Ejemplo n.º 35
0
 def _get_renderer_info(self):
     info = ffi.new('SDL_RendererInfo *')
     check_int_err(lib.SDL_GetRendererInfo(self._ptr, info))
     return info
Ejemplo n.º 36
0
 def size(self):
     """Tuple[int, int]: The width and height of the window."""
     size = ffi.new('int[]', 2)
     lib.SDL_GetWindowSize(self._ptr, size + 0, size + 1)
     return (size[0], size[1])
Ejemplo n.º 37
0
 def __init__(self):
     self._ptr = ffi.new('SDL_Event *')
Ejemplo n.º 38
0
 def access(self):
     """TextureAccess: The actual access to the texture."""
     access = ffi.new('int *')
     check_int_err(lib.SDL_QueryTexture(self._ptr, ffi.NULL, access, ffi.NULL, ffi.NULL))
     return TextureAccess(access[0])
Ejemplo n.º 39
0
 def __init__(self):
     self._ptr = ffi.new('SDL_Event *')
Ejemplo n.º 40
0
 def w(self):
     """int: The width of the texture in pixels."""
     w = ffi.new('int *')
     check_int_err(
         lib.SDL_QueryTexture(self._ptr, ffi.NULL, ffi.NULL, w, ffi.NULL))
     return w[0]
Ejemplo n.º 41
0
 def draw_color(self):
     """Tuple[int, int, int, int]: The color used for drawing operations in (red, green, blue, alpha) format."""
     rgba = ffi.new('Uint8[]', 4)
     check_int_err(lib.SDL_GetRenderDrawColor(self._ptr, rgba + 0, rgba + 1, rgba + 2, rgba + 3))
     return (rgba[0], rgba[1], rgba[2], rgba[3])
Ejemplo n.º 42
0
 def position(self):
     """Tuple[int, int]: The x and y position of the window."""
     position = ffi.new('int[]', 2)
     lib.SDL_GetWindowPosition(self._ptr, position + 0, position + 1)
     return (position[0], position[1])
Ejemplo n.º 43
0
    def get_desktop_size(self):
        """Get the size of the desktop display"""

        _ptr = ffi.new('SDL_DisplayMode *')
        check_int_err(lib.SDL_GetDesktopDisplayMode(self._index, _ptr))
        return (_ptr.w, _ptr.h)
Ejemplo n.º 44
0
    def get_desktop_size(self):
        """Get the size of the desktop display"""

        _ptr = ffi.new('SDL_DisplayMode *')
        check_int_err(lib.SDL_GetDesktopDisplayMode(self._index, _ptr))
        return (_ptr.w, _ptr.h)