Ejemplo n.º 1
0
def set_hint_with_priority(name, value, priority):
    """Sets the value of a specific hint using a priority override.

    The hint priority can be one of
    * SDL_HINT_DEFAULT
    * SDL_HINT_NORMAL
    * SDL_HINT_OVERRIDE
    """
    if priority not in _SUPPORTED_HINTS:
        raise ValueError("unsupported priority")
    return dll.SDL_SetHintWithPriority(byteify(str(name), "utf-8"),
                                       byteify(str(value), "utf-8"), priority)
Ejemplo n.º 2
0
def load_texture(renderer, fname):
    """Create a SDL_Texture from the specified filename.

    Raises a SDLError, if the file could not be loaded.
    """
    fname = byteify(str(fname), "utf-8")
    return _check(dll.IMG_LoadTexture(ctypes.byref(renderer), fname))
Ejemplo n.º 3
0
def is_extension_present(device, extname):
    """Checks, if a certain extension is available for the passed device."""
    extname = byteify(str(extname), "utf-8")
    devptr = None
    if device is not None:
        devptr = ctypes.byref(device)
    return dll.alcIsExtensionPresent(devptr, extname) == ALC_TRUE
Ejemplo n.º 4
0
def load(fname):
    """Load an image into a SDL_Surface from the specified filename.

    Raises a SDLError, if the file could not be loaded.
    """
    fname = byteify(str(fname), "utf-8")
    return _check(dll.IMG_Load(fname))
Ejemplo n.º 5
0
def log_info(category, text):
    """Logs a message with the chosen category and SDL_LOG_PRIORITY_INFO."""
    if type(category) is not int:
        raise TypeError("category must be a valid SDL_LOG_CATEGORY value")
    if category not in _ALLOWED_CATEGORIES:
        raise ValueError("category must be a valid SDL_LOG_CATEGORY value")
    dll.SDL_LogInfo(category, byteify(str(text), "utf-8"))
Ejemplo n.º 6
0
def capture_open_device(devicename, frequency, dformat, buffersize):
    """Opens an OpenAL capture device with the specified name."""
    if devicename is not None:
        devicename = byteify(str(devicename), "utf-8")
    retval = dll.alcCaptureOpenDevice(devicename, frequency, dformat, buffersize)
    if retval is None or not bool(retval):
        return None  # TODO
    return retval.contents
Ejemplo n.º 7
0
def open_font(fname, ptsize):
    """Opens a TTF font file with a defined size in points.

    Raises a SDLError, if the font could not be loaded.
    """
    fname = byteify(str(fname), "utf-8")
    ptsize = int(ptsize)
    return _check_ptr(dll.TTF_OpenFont(fname, ptsize))
Ejemplo n.º 8
0
def create_window(title, x, y, w, h, flags):
    """Creates a new SDL window with the specified dimensions and title.
    """
    title = byteify(str(title), "utf-8")
    retval = dll.SDL_CreateWindow(title, x, y, w, h, flags)
    if retval is None or not bool(retval):
        raise SDLError()
    return retval.contents
Ejemplo n.º 9
0
def set_clipboard_text(text):
    """Puts text on the OS clipboard.

    This raises a SDLError, if the operation was not successful.
    """
    ptr = str(text)
    ret = dll.SDL_SetClipboardText(byteify(ptr, "utf-8"))
    if ret < 0:
        raise SDLError()
Ejemplo n.º 10
0
def audio_init(drivername):
    """Initializes the SDL audio subsystem with the passed driver.

    NOTE: Do not use audio_init() - this might lead to SIGSEGV crashes - use
    the SDL_AUDIODRIVER environment variable before calling
    pygame2.sdl.init_subsystem() instead.
    """
    drivername = byteify(drivername, "utf-8")
    retval = dll.SDL_AudioInit(drivername)
    if retval != 0:
        raise SDLError()
Ejemplo n.º 11
0
def log_message(category, priority, text):
    """Logs a message with the chosen category and priority."""
    if type(category) is not int:
        raise TypeError("category must be a valid SDL_LOG_CATEGORY value")
    if category not in _ALLOWED_CATEGORIES:
        raise ValueError("category must be a valid SDL_LOG_CATEGORY value")
    if type(priority) is not int:
        raise TypeError("priority must be a valid SDL_LOG_PRIORITY value")
    if priority not in _ALLOWED_PRIORITIES:
        raise ValueError("priority must be a valid SDL_LOG_PRIORITY value")
    dll.SDL_LogMessage(category, priority, byteify(str(text), "utf-8"))
Ejemplo n.º 12
0
def open_device(devicename=None):
    """Opens an OpenAL device with the specified name.

    If no devicename is passed, the default output device is opened.
    """
    if devicename is not None:
        devicename = byteify(str(devicename), "utf-8")
    retval = dll.alcOpenDevice(devicename)
    if retval is None or not bool(retval):
        return None
    return retval.contents
Ejemplo n.º 13
0
def create_shaped_window(title, x, y, w, h, flags):
    """Create a window that can be shaped with the specified position,
    dimension and flags.

    TODO
    """
    title = byteify(str(title), "utf-8")
    retval = dll.SDL_CreateShapedWindow(title, x, y, w, h, flags)
    if retval is None or not bool(retval):
        raise SDLError()
    return retval.contents
Ejemplo n.º 14
0
def open_font_index(fname, ptsize, idx):
    """Opens a TTF font file with a defined size in points, using the
    font type specified by idx.

    Raises a SDLError, if the font could not be loaded.
    """
    if int(idx) < 0:
        raise ValueError("idx must not be negative")
    fname = byteify(str(fname), "utf-8")
    ptsize = int(ptsize)
    return _check_ptr(dll.TTF_OpenFontIndex(fname, ptsize, idx))
Ejemplo n.º 15
0
def get_window_data(window, name):
    """Gets associated content from the window.

    The data to be retrieved is identified by the specified name. If there is
    no data found for name, None will be returned.
    """
    name = byteify(str(name), "utf-8")
    retval = dll.SDL_GetWindowData(ctypes.byref(window), name)
    retval = ctypes.cast(retval, ctypes.py_object)
    if retval is None or not bool(retval):
        return None
    return retval.value
Ejemplo n.º 16
0
def gl_load_library(path=None):
    """Dynamically loads the passed OpenGL library.

    if path is None, the default OpenGL library will be loaded.
    """
    if path is not None:
        path = byteify(str(path), "utf-8")
        retval = dll.SDL_GL_LoadLibrary(path)
    else:
        retval = dll.SDL_GL_LoadLibrary(None)
    if retval == -1:
        raise SDLError()
    return retval == 0
Ejemplo n.º 17
0
def init(drivername=None):
    """Initializes the SDL video subsystem.

    Initializes the SDL video subsystem with an optionally choosable driver to
    use. This is basically the same as calling

        pygame2.sdl.init(pygame2.sdl.SDL_INIT_VIDEO)

    but lets you choose a video driver instead of using the default driver for
    the platform your application is running on
    """
    if drivername is not None:
        drivername = byteify(str(drivername), "utf-8")
    dll.SDL_VideoInit(drivername)
Ejemplo n.º 18
0
def load_typed_rw(rwops, freesrc, itype):
    """Load a surface from a seekable data stream.

    itype specifies the image format to use for loading and may be a
    value of "BMP", "GIF", "PNG", etc.

    If freesrc evaluates to True, the passed stream will be closed after
    being read.

    Raises a SDLError, if the image could not be loaded.
    """
    itype = byteify(str(itype), "utf-8")
    if bool(freesrc):
        return _check(dll.IMG_LoadTyped_RW(ctypes.byref(rwops), 1, itype))
    else:
        return _check(dll.IMG_LoadTyped_RW(ctypes.byref(rwops), 0, itype))
Ejemplo n.º 19
0
def set_window_data(window, name, data):
    """Associate arbitrary content with a window.

    The passed data will be identified by the specified name.

    Note: you must keep a reference to the passed data to prevent it from
    being GC'd

    This will return the previous value.
    """
    name = byteify(str(name), "utf-8")
    ptr = ctypes.py_object(data)
    retval = dll.SDL_SetWindowData(ctypes.byref(window), name, ptr)
    retval = ctypes.cast(retval, ctypes.py_object)
    if retval is None or not bool(retval):
        return None
    return retval.value
Ejemplo n.º 20
0
def open_audio_device(device, iscapture, desired, allowed_changes):
    """Opens a specific audio device with the desired parameters.
    
    If the return value is None, the audio data passed to the set
    callback function in desired will be guaranteed to be in the
    requested format, and will be automatically converted to the
    hardware audio format if necessary.
    """
    device = byteify(str(device), "utf-8")
    if bool(iscapture):
        iscapture = 1
    else:
        iscapture = 0
    obtained = SDL_AudioSpec(0, 0, 0, 0, None, None)
    retval = dll.SDL_OpenAudioDevice(device, iscapture, ctypes.byref(desired),
                                     ctypes.byref(obtained), allowed_changes)
    if retval == 0:
        raise SDLError()
    return retval, obtained
Ejemplo n.º 21
0
def get_enum_value(device, enumname):
    """Retrieves the value for the specified enumeration name on the
    device.
    """
    enumname = byteify(str(enumname), "utf-8")
    return dll.alcGetEnumValue(ctypes.byref(device), enumname)
Ejemplo n.º 22
0
def get_proc_address(device, funcname):
    """Retrieves the address of the specified device extension function."""
    funcname = byteify(str(funcname), "utf-8")
    return dll.alcGetProcAddress(ctypes.byref(device), funcname)
Ejemplo n.º 23
0
def get_enum_value(ename):
    """Returns the enumeration value of an OpenAL enum."""
    ename = byteify(str(ename), "utf-8")
    return dll.alGetEnumValue(ename)
Ejemplo n.º 24
0
def set_error(text):
    """Sets a SDL error message that can be retrieved using get_error()."""
    dll.SDL_SetError(byteify(str(text), "utf-8"))
Ejemplo n.º 25
0
def gl_extension_supported(extension):
    """Checks, if the passed OpenGL extension is supported by the currently
    loaded OpenGL library.
    """
    extension = byteify(str(extension), "utf-8")
    return dll.SDL_GL_ExtensionSupported(extension) == SDL_TRUE
Ejemplo n.º 26
0
def gl_get_proc_address(proc):
    """Gets the function address pointer for the passed proc name."""
    proc = byteify(str(proc), "utf-8")
    return dll.SDL_GL_GetProcAddress(proc)
Ejemplo n.º 27
0
def get_hint(name):
    """Gets the currently set value for the passed hint."""
    retval = dll.SDL_GetHint(byteify(str(name), "utf-8"))
    if retval is not None:
        return stringify(retval, "utf-8")
    return None
Ejemplo n.º 28
0
def set_hint(name, value):
    """Sets the value of a specific hint."""
    return dll.SDL_SetHint(byteify(str(name), "utf-8"),
                           byteify(str(value), "utf-8"))
Ejemplo n.º 29
0
def set_window_title(window, title):
    """Sets the title to be used by a SDL_Window."""
    title = byteify(str(title), "utf-8")
    dll.SDL_SetWindowTitle(ctypes.byref(window), title)
Ejemplo n.º 30
0
def log(text):
    """Logs a message with SDL_LOG_CATEGORY_APPLICATION and
    SDL_LOG_PRIORITY_INFO.
    """
    dll.SDL_Log(byteify(str(text), "utf-8"))