示例#1
0
文件: textbox.go 项目: bieber/drones
func (t *TextBox) buildText(
	text, font string,
	fontSize int,
	fontColor sdl.Color,
) {
	for _, line := range t.lines {
		line.Free()
	}
	t.lines = make([]*sdl.Surface, 0, 10)
	lines := strings.Split(strings.Trim(text, "\n"), "\n")
	for _, line := range lines {
		if line == "" {
			// SDL chokes on empty lines, so replace them with nil straight out
			t.lines = append(t.lines, nil)
			continue
		}
		words := strings.Split(line, " ")
		for current, rest := words[:], []string(nil); len(current) != 0; {
			w, _, _ := fonts.Size(strings.Join(current, " "), font, fontSize)
			if w > int(t.W) {
				rest = append(current[len(current)-1:], rest...)
				current = current[:len(current)-1]
			} else {
				t.lines = append(
					t.lines,
					fonts.BlendedText(
						strings.Join(current, " "),
						font,
						fontSize,
						fontColor,
					),
				)
				current = rest
				rest = nil
			}
		}
	}
}
示例#2
0
文件: button.go 项目: bieber/drones
func (b *Button) refreshText(text string, size int, color sdl.Color) {
	if b.labelText != nil {
		b.labelText.Free()
	}
	b.labelText = fonts.BlendedText(text, "sans_bold", size, color)
}