当前位置: 首页>>代码示例>>Golang>>正文


Golang C.SDL_ListModes函数代码示例

本文整理汇总了Golang中C.SDL_ListModes函数的典型用法代码示例。如果您正苦于以下问题:Golang SDL_ListModes函数的具体用法?Golang SDL_ListModes怎么用?Golang SDL_ListModes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_ListModes函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ListModes

// 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
}
开发者ID:kearsley,项目名称:Go-SDL,代码行数:37,代码来源:sdl.go

示例2: ListModes

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
}
开发者ID:badgerodon,项目名称:go,代码行数:13,代码来源:video.go

示例3: ListModes

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

}
开发者ID:gnanderson,项目名称:Go-SDL,代码行数:18,代码来源:sdl.go

示例4: ListModes

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
}
开发者ID:cjyar,项目名称:Go-SDL,代码行数:21,代码来源:sdl.go


注:本文中的C.SDL_ListModes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。