示例#1
0
文件: ttf.go 项目: jgastal/Go-SDL
// Return the width and height of the rendered Latin-1 text.
//
// Return values are (width, height, err) where err is 0 for success, -1 on any error.
func (f *Font) SizeText(text string) (int, int, int) {
	w := C.int(0)
	h := C.int(0)
	s := C.CString(text)
	err := C.TTF_SizeText(f.cfont, s, &w, &h)
	return int(w), int(h), int(err)
}
示例#2
0
文件: ttf.go 项目: krig/Go-SDL2
// Return the width and height of the rendered Latin-1 text.
//
// Return values are (width, height, err)
func (f *Font) SizeText(text string) (int, int, error) {
	w := C.int(0)
	h := C.int(0)
	s := C.CString(text)
	err := C.TTF_SizeText(f.cfont, s, &w, &h)
	if int(err) != 0 {
		return int(w), int(h), sdl.NewSDLError()
	}
	return int(w), int(h), nil
}
示例#3
0
文件: ttf.go 项目: willemvds/sdl
func (f *Font) SizeText(text string) (int, int, error) {
	w := C.int(0)
	h := C.int(0)
	ctext := C.CString(text)
	res := C.TTF_SizeText(f.c, ctext, &w, &h)
	var err error
	if res != 0 {
		err = getError()
	}
	return int(w), int(h), err
}
示例#4
0
文件: ttf.go 项目: Zwobot/Go-SDL
// Return the width and height of the rendered Latin-1 text.
//
// Return values are (width, height, err) where err is 0 for success, -1 on any error.
func (f *Font) SizeText(text string) (int, int, int) {
	sdl.GlobalMutex.Lock() // Because the underlying C code is fairly complex
	f.mutex.Lock()         // Use a write lock, because 'C.TTF_Size*' may update font's internal cache

	w := C.int(0)
	h := C.int(0)
	s := C.CString(text)
	err := C.TTF_SizeText(f.cfont, s, &w, &h)

	sdl.GlobalMutex.Unlock()
	f.mutex.Unlock()

	return int(w), int(h), int(err)
}