Example #1
0
// PeepEvents (https://wiki.libsdl.org/SDL_PeepEvents)
func PeepEvents(events []Event, action EventAction, minType, maxType uint32) int {
	var _events []CEvent = make([]CEvent, len(events))

	if action == ADDEVENT { // the contents of _events matter if they are to be added
		for i := 0; i < len(events); i++ {
			_events[i] = *cEvent(events[i])
		}
	}

	_pevents := (*C.SDL_Event)(unsafe.Pointer(&_events[0]))
	retVal := int(C.SDL_PeepEvents(_pevents, C.int(len(events)), action.c(), C.Uint32(minType), C.Uint32(maxType)))

	if action != ADDEVENT { // put events into slice, events unchanged if action = ADDEVENT
		for i := 0; i < retVal; i++ {
			events[i] = goEvent(&_events[i])
		}
	}
	return retVal
}
Example #2
0
func PeepEvents(events []Event, action Eventaction, min, max uint32) (int, error) {
	cevents := make([]cEvent, len(events))
	n := C.SDL_PeepEvents(
		(*C.SDL_Event)(unsafe.Pointer(&cevents[0])),
		C.int(len(cevents)),
		C.SDL_eventaction(action),
		C.Uint32(min),
		C.Uint32(max),
	)
	if n < 0 {
		return 0, getError()
	}

	for i := 0; i < int(n); i++ {
		events[i] = cevents[i].toGo()
	}

	return int(n), nil
}