Example #1
0
def _timer_callback(interval, param):
    if sdl.SDL_WasInit(sdl.SDL_INIT_VIDEO):
        event = ffi.new("SDL_Event*")
        event.type = ffi.cast("intptr_t", param)
        # SDL will make a copy of the event while handling SDL_PushEvent,
        # so we don't need to hold the allocated memory after this call.
        sdl.SDL_PushEvent(event)
    return interval
Example #2
0
def post(event):
    """post(Event): return None
       place a new event on the queue"""
    # SDL requires video to be initialised before PushEvent does the right thing
    check_video()
    is_blocked = sdl.SDL_EventState(event.type, sdl.SDL_QUERY) == sdl.SDL_IGNORE
    if is_blocked:
        # Silently drop blocked events, since that's what pygame does
        # (maybe worth logging somehow?)
        return None

    sdl_event = ffi.new("SDL_Event *")
    sdl_event.type = event.type
    sdl_event.user.code = _USEROBJECT_CHECK1
    sdl_event.user.data1 = _USEROBJECT_CHECK2
    sdl_event.user.data2 = ffi.cast("void*", sdl_event)
    _user_events[sdl_event] = event
    if sdl.SDL_PushEvent(sdl_event) == -1:
        raise SDLError.from_sdl_error()
Example #3
0
def post(event):
    """post(Event): return None
       place a new event on the queue"""
    # SDL requires video to be initialised before PushEvent does the right thing
    check_video()
    is_blocked = sdl.SDL_EventState(event.type,
                                    sdl.SDL_QUERY) == sdl.SDL_IGNORE
    if is_blocked:
        raise RuntimeError("event post blocked for %s" %
                           event_name(event.type))

    sdl_event = ffi.new("SDL_Event *")
    sdl_event.type = event.type
    sdl_event.user.code = _USEROBJECT_CHECK1
    sdl_event.user.data1 = _USEROBJECT_CHECK2
    sdl_event.user.data2 = ffi.cast("void*", sdl_event)
    _user_events[sdl_event] = event
    if sdl.SDL_PushEvent(sdl_event) == -1:
        raise SDLError.from_sdl_error()
Example #4
0
def _endmusic_callback():
    global _current_music, _queue_music, _music_pos, _music_pos_time
    if _endmusic_event is not None and sdl.SDL_WasInit(sdl.SDL_INIT_AUDIO):
        # Pygame doesn't do the same checks for this path as in
        # event.post, and people rely on that, so we also duplicate
        # the logic
        event = ffi.new('SDL_Event*')
        event.type = _endmusic_event
        sdl.SDL_PushEvent(event)

    if _queue_music:
        if _current_music:
            sdl.Mix_FreeMusic(_current_music)
        _current_music = _queue_music
        _queue_music = None
        sdl.Mix_HookMusicFinished(_endmusic_callback)
        _music_pos = 0
        sdl.Mix_PlayMusic(_current_music, 0)
    else:
        _music_pos_time = -1
        sdl.Mix_SetPostMix(ffi.NULL, ffi.NULL)
Example #5
0
def _endsound_callback(channelnum):
    if not _channeldata:
        return

    data = _channeldata[channelnum]
    # post sound ending event
    if data.endevent != sdl.SDL_NOEVENT and sdl.SDL_WasInit(sdl.SDL_INIT_VIDEO):
        event = ffi.new('SDL_Event*')
        event.type = data.endevent
        if event.type >= sdl.SDL_USEREVENT and event.type < sdl.SDL_NUMEVENTS:
            event.user.code = channelnum
        sdl.SDL_PushEvent(event)

    if data.queue:
        sound_chunk = data.sound.chunk
        data.sound = data.queue
        data.queue = None
        channelnum = sdl.Mix_PlayChannelTimed(channelnum, sound_chunk, 0, -1)
        if channelnum != -1:
            sdl.Mix_GroupChannel(channelnum, data.sound._chunk_tag)
    else:
        data.sound = None
Example #6
0
def _timer_callback(interval, param):
    if sdl.SDL_WasInit(sdl.SDL_INIT_VIDEO):
        event = ffi.new("SDL_Event")
        event.type = ffi.cast("intptr_t", param)
        sdl.SDL_PushEvent(event)
    return interval