Esempio n. 1
0
// Returns the list of available screen dimensions for the given format.
//
// NOTE: The result of this function uses a different encoding than the underlying C function.
// It returns an empty array if no modes are available,
// and nil if any dimension is okay for the given format.
func ListModes(format *PixelFormat, flags uint32) []Rect {
	modes := C.SDL_ListModes((*C.SDL_PixelFormat)(cast(format)), C.Uint32(flags))

	// No modes available
	if modes == nil {
		return make([]Rect, 0)
	}

	// (modes == -1) --> Any dimension is ok
	if uintptr(unsafe.Pointer(modes))+1 == uintptr(0) {
		return nil
	}

	count := 0
	ptr := *modes //first element in the list
	for ptr != nil {
		count++
		ptr = *(**C.SDL_Rect)(unsafe.Pointer(uintptr(unsafe.Pointer(modes)) + uintptr(count*unsafe.Sizeof(ptr))))
	}

	ret := make([]Rect, count)
	for i := 0; i < count; i++ {
		ptr := (**C.SDL_Rect)(unsafe.Pointer(uintptr(unsafe.Pointer(modes)) + uintptr(i*unsafe.Sizeof(*modes))))
		var r *C.SDL_Rect = *ptr
		ret[i].X = int16(r.x)
		ret[i].Y = int16(r.y)
		ret[i].W = uint16(r.w)
		ret[i].H = uint16(r.h)
	}

	return ret
}
Esempio n. 2
0
func ListModes(pixelFormat *PixelFormat, flags SurfaceFlags) []Rect {
	var c_format *C.SDL_PixelFormat
	if pixelFormat != nil {
		c_format = (*C.SDL_PixelFormat)(unsafe.Pointer(pixelFormat))
	}
	c_flags := C.Uint32(flags)
	ret := C.SDL_ListModes(c_format, c_flags)
	modes := []Rect{}
	walkArray(unsafe.Pointer(ret), func(v unsafe.Pointer) {
		modes = append(modes, *(*Rect)(v))
	})
	return modes
}
Esempio n. 3
0
func ListModes(format *PixelFormat, flags uint32) []*Rect {

	modes := C.SDL_ListModes((*C.SDL_PixelFormat)(cast(format)), C.Uint32(flags))

	if modes == nil { //modes == 0, no modes available
		return make([]*Rect, 0)
	}

	if ^uintptr(unsafe.Pointer(modes)) == 0 { //modes == -1, any dimension is ok
		return nil
	}

	var ret = make([]*Rect, C.vectorLength((*unsafe.Pointer)(unsafe.Pointer(modes))))
	*((***C.SDL_Rect)(unsafe.Pointer(&ret))) = modes // TODO

	return ret

}
Esempio n. 4
0
File: sdl.go Progetto: cjyar/Go-SDL
func ListModes(format *PixelFormat, flags uint32) []Rect {
	modes := C.SDL_ListModes((*C.SDL_PixelFormat)(cast(format)), C.Uint32(flags))
	if modes == nil { //no modes available
		return make([]Rect, 0)
	}
	var any int
	*((***C.SDL_Rect)(unsafe.Pointer(&any))) = modes
	if any == -1 { //any dimension is ok
		return nil
	}

	var count int
	ptr := *modes //first element in the list
	for count = 0; ptr != nil; count++ {
		ptr = *(**C.SDL_Rect)(unsafe.Pointer(uintptr(unsafe.Pointer(modes)) + uintptr(uintptr(count)*unsafe.Sizeof(ptr))))
	}
	var ret = make([]Rect, count-1)

	*((***C.SDL_Rect)(unsafe.Pointer(&ret))) = modes // TODO
	return ret
}