コード例 #1
0
ファイル: surface.py プロジェクト: gdos/pgreloaded
def fill_rects(dst, rects, color):
    """Fills multiple areas with a certain color on the surface."""
    rects, count = array.to_ctypes(rects, SDL_Rect)
    rects = ctypes.cast(rects, ctypes.POINTER(SDL_Rect))
    retval = dll.SDL_FillRects(ctypes.byref(dst), rects, count, color)
    if retval == -1:
        raise SDLError()
コード例 #2
0
ファイル: render.py プロジェクト: gdos/pgreloaded
def render_draw_points(renderer, points):
    """Draws multiple points on the current rendering target.
    """
    points, count = array.to_ctypes(points, SDL_Point)
    retval = dll.SDL_RenderDrawPoints(ctypes.byref(renderer),
                                      ctypes.byref(points), count)
    if retval == -1:
        raise SDLError()
コード例 #3
0
ファイル: render.py プロジェクト: gdos/pgreloaded
def render_draw_lines(renderer, points):
    """Draws a series of connected lines on the current rendering target.
    """
    points, count = array.to_ctypes(points, SDL_Point)
    retval = dll.SDL_RenderDrawLines(ctypes.byref(renderer),
                                     ctypes.byref(points), count)
    if retval == -1:
        raise SDLError()
コード例 #4
0
ファイル: render.py プロジェクト: gdos/pgreloaded
def render_draw_rects(renderer, rects):
    """Draw multiple rectangles on the current rendering target.
    """
    rects, count = array.to_ctypes(rects, SDL_Rect)
    retval = dll.SDL_RenderDrawRects(ctypes.byref(renderer),
                                     ctypes.byref(rects), count)
    if retval == -1:
        raise SDLError()
コード例 #5
0
ファイル: render.py プロジェクト: gdos/pgreloaded
def render_fill_rects(renderer, rects):
    """Fills multiple rectangles on the current rendering target with
    the set drawing color.
    """
    rects, count = array.to_ctypes(rects, SDL_Rect)
    retval = dll.SDL_RenderFillRects(ctypes.byref(renderer),
                                     ctypes.byref(rects), count)
    if retval == -1:
        raise SDLError()
コード例 #6
0
ファイル: pixels.py プロジェクト: gdos/pgreloaded
def set_palette_colors(palette, colors, first=0, ncolors=0):
    """Sets the colors of a SDL_Palette to the passed values, starting at
    first in the colors array and setting ncolors.
    """
    colors, size = array.to_ctypes(colors, SDL_Color)
    ncolors = max(size, ncolors)
    pcolor = ctypes.cast(colors, ctypes.POINTER(SDL_Color))
    return dll.SDL_SetPaletteColors(ctypes.byref(palette), pcolor, first,
                                    ncolors)
コード例 #7
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def source_queue_buffers(sid, bids):
    """Queues a set of buffers on a source.

    All buffers attached to a source will be played in sequence and the
    number of buffers played can be retrieved using a source_i() call to
    retrieve AL_BUFFERS_PROCESSED.
    """
    bufs, size = array.to_ctypes(bids, ctypes.c_uint)
    dll.alSourceQueueBuffers(sid, size, bufs)
    _raise_error_or_continue()
コード例 #8
0
ファイル: array_test.py プロジェクト: gdos/pgreloaded
 def test_to_ctypes(self):
     for seq, dtype in ((singlebyteseq, ctypes.c_ubyte),
                        (singlebytebuf, ctypes.c_ubyte),
                        (doublebyteseq, ctypes.c_ushort),
                        (doublebytebuf, ctypes.c_ushort),
                        (quadbyteseq, ctypes.c_uint),
                        (quadbytebuf, ctypes.c_uint)):
         bytebuf, size = pgarray.to_ctypes(seq, dtype)
         self.assertEqual(size, len(seq))
         for index, x in enumerate(bytebuf):
             self.assertEqual(x, seq[index])
コード例 #9
0
ファイル: alc.py プロジェクト: gdos/pgreloaded
def create_context(device, attrs=None):
    """Creates a context from the specified device."""
    ptr = None
    if attrs is not None:
        arr, size = array.to_ctypes(attrs, ctypes.c_int, len(attrs) + 1)
        arr[-1] = 0
        ptr = ctypes.cast(arr, ctypes.POINTER(ctypes.c_int))
    retval = dll.alcCreateContext(ctypes.byref(device), ptr)
    if retval is None or not bool(retval):
        raise OpenALError(_FASTERROR(device))
    return retval.contents
コード例 #10
0
ファイル: video.py プロジェクト: gdos/pgreloaded
def update_window_surface_rects(window, rects):
    """Copies a set of areas of the window surface to the screen.

    The rects argument must be a sequence of SDL_Rect instances.

    Raises a SDLError, if an error occured.
    """
    rptr, count = array.to_ctypes(rects, SDL_Rect)
    rptr = ctypes.cast(rptr, ctypes.POINTER(SDL_Rect))
    retval = dll.SDL_UpdateWindowSurfaceRects(ctypes.byref(window), rptr,
                                              count)
    if retval == -1:
        raise SDLError()
コード例 #11
0
ファイル: video.py プロジェクト: gdos/pgreloaded
def set_window_gamma_ramp(window, red, green, blue):
    """Sets the window's gamma ramp based on the passed red, green and
    blue tables.

    Each value table has to have 256 entries for calculating the gamma
    of the specific color channel.
    """
    rptr, gptr, bptr, size = None, None, None, None

    if isinstance(red, array.CTypesView):
        rptr = red.to_uint16()
        size = len(red)
    else:
        rptr, size = array.to_ctypes(red, ctypes.c_ushort)
    if size != 256:
        raise ValueError("red gamma table must contain 256 values")

    if isinstance(green, array.CTypesView):
        gptr = green.to_uint16()
        size = len(green)
    else:
        gptr, size = array.to_ctypes(green, ctypes.c_ushort)
    if size != 256:
        raise ValueError("green gamma table must contain 256 values")

    if isinstance(blue, array.CTypesView):
        bptr = blue.to_uint16()
        size = len(bptr)
    else:
        bptr, size = array.to_ctypes(blue, ctypes.c_ushort)
    if size != 256:
        raise ValueError("blue gamma table must contain 256 values")

    retval = dll.SDL_SetWindowGammaRamp(ctypes.byref(window), rptr, gptr, bptr)
    if retval == -1:
        raise SDLError()
コード例 #12
0
ファイル: rect.py プロジェクト: gdos/pgreloaded
def enclose_points(points, clip=None):
    """Calculates the minimum rectangle enclosing the passed point list.

    If the clip rectangle is passed, all points outside that rectangle will be
    ignored.
    """
    result = SDL_Rect()
    arptr, count = array.to_ctypes(points, SDL_Point)
    arptr = ctypes.cast(arptr, ctypes.POINTER(SDL_Point))
    if count == 0:
        return False, SDL_Rect()

    clipval = None
    if clip is not None:
        clipval = ctypes.byref(clip)
    retval = dll.SDL_EnclosePoints(arptr, count, clipval, ctypes.byref(result))
    return (retval == SDL_TRUE), result
コード例 #13
0
ファイル: surface.py プロジェクト: gdos/pgreloaded
def convert_pixels(width, height, srcformat, src, srcpitch, dstformat,
                   dstpitch):
    """Converts the passed pixel pixel buffer and returns a new buffer.

    The pixels of the passed src buffer will be converted from srcformat
    to values of dstformat. The size of the result buffer will be
    height * dstpitch.
    """
    srcp = src
    srcsize = len(src)
    if isinstance(src, array.CTypesView):
        srcp = src.to_bytes()
    else:
        srcp, srcsize = array.to_ctypes(src, ctypes.c_ubyte)
    srcp = ctypes.cast(srcp, ctypes.POINTER(ctypes.c_ubyte))
    dst = (ctypes.c_ubyte * (height * dstpitch))()
    dstp = ctypes.cast(dst, ctypes.POINTER(ctypes.c_ubyte))
    ret = dll.SDL_ConvertPixels(width, height, srcformat, srcp, srcpitch,
                                dstformat, dstp, dstpitch)
    if ret == -1:
        raise SDLError()
    return dst
コード例 #14
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def buffer_fv(bid, param, values):
    """Sets a floating point-vector property of the buffer."""
    values, size = array.to_ctypes(values, ctypes.c_float)
    ptr = ctypes.cast(values, ctypes.POINTER(ctypes.c_float))
    dll.alBufferfv(bid, param, ptr)
    _raise_error_or_continue()
コード例 #15
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def listener_fv(param, values):
    """Sets a floating point-vector property for the listener """
    values, size = array.to_ctypes(values, ctypes.c_float)
    ptr = ctypes.cast(values, ctypes.POINTER(ctypes.c_float))
    dll.alListenerfv(param, ptr)
    _raise_error_or_continue()
コード例 #16
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def delete_sources(sources):
    """Deletes one or more sources."""
    sources, size = array.to_ctypes(sources, ctypes.c_uint)
    ptr = ctypes.cast(sources, ctypes.POINTER(ctypes.c_uint))
    dll.alDeleteSources(size, ptr)
    _raise_error_or_continue()
コード例 #17
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def listener_iv(param, values):
    """Sets an integer-vector property for the listener."""
    values, size = array.to_ctypes(values, ctypes.c_int)
    ptr = ctypes.cast(values, ctypes.POINTER(ctypes.c_int))
    dll.alListeneriv(param, ptr)
    _raise_error_or_continue()
コード例 #18
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def source_iv(sid, param, values):
    """Sets an integer-vector property of a source."""
    values, size = array.to_ctypes(values, ctypes.c_int)
    ptr = ctypes.cast(values, ctypes.POINTER(ctypes.c_int))
    dll.alSourceiv(sid, param, ptr)
    _raise_error_or_continue()
コード例 #19
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def source_fv(sid, param, values):
    """Sets a floating point-vector property of a source."""
    values, size = array.to_ctypes(values, ctypes.c_float)
    ptr = ctypes.cast(values, ctypes.POINTER(ctypes.c_float))
    dll.alSourcefv(sid, param, ptr)
    _raise_error_or_continue()
コード例 #20
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def source_rewind_v(sids):
    """Rewinds a set of sources."""
    sids, size = array.to_ctypes(sids, ctypes.c_uint)
    ptr = ctypes.cast(sids, ctypes.POINTER(ctypes.c_uint))
    dll.alSourceRewindv(size, ptr)
    _raise_error_or_continue()
コード例 #21
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def source_pause_v(sids):
    """Pauses a set of sources."""
    sids, size = array.to_ctypes(sids, ctypes.c_uint)
    ptr = ctypes.cast(sids, ctypes.POINTER(ctypes.c_uint))
    dll.alSourcePausev(size, ptr)
    _raise_error_or_continue()
コード例 #22
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def source_unqueue_buffers(sid, bids):
    """Unqueues a set of buffers attached to a source."""
    bufs, size = array.to_ctypes(bids, ctypes.c_uint)
    dll.alSourceUnqueueBuffers(sid, size, bufs)
    _raise_error_or_continue()
コード例 #23
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def buffer_iv(bid, param, values):
    """Sets an integer-vector property of the buffer."""
    values, size = array.to_ctypes(values, ctypes.c_int)
    ptr = ctypes.cast(values, ctypes.POINTER(ctypes.c_int))
    dll.alBufferiv(bid, param, ptr)
    _raise_error_or_continue()
コード例 #24
0
ファイル: al.py プロジェクト: gdos/pgreloaded
def delete_buffers(buffers):
    """Deletes one or more buffers, freeing the resources used by them."""
    buffers, size = array.to_ctypes(buffers, ctypes.c_uint)
    ptr = ctypes.cast(buffers, ctypes.POINTER(ctypes.c_uint))
    dll.alDeleteBuffers(size, ptr)
    _raise_error_or_continue()