示例#1
0
文件: button.go 项目: bieber/drones
func (b *Button) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{
			X: b.X,
			Y: b.Y,
			W: b.W,
			H: b.H,
		},
		ui.ColorToInt(b.BorderColor),
	)
	var fillColor sdl.Color
	if b.hovered {
		fillColor = b.HoverColor
	} else {
		fillColor = b.BGColor
	}
	screen.FillRect(
		&sdl.Rect{
			X: b.X + int16(b.BorderWidth),
			Y: b.Y + int16(b.BorderWidth),
			W: b.W - 2*uint16(b.BorderWidth),
			H: b.H - 2*uint16(b.BorderWidth),
		},
		ui.ColorToInt(fillColor),
	)
	screen.Blit(
		&sdl.Rect{
			X: b.X + int16((int32(b.W)-b.labelText.W)/2),
			Y: b.Y + int16((int32(b.H)-b.labelText.H)/2),
			W: uint16(b.labelText.W),
			H: uint16(b.labelText.H),
		},
		b.labelText,
		&sdl.Rect{W: uint16(b.labelText.W), H: uint16(b.labelText.H)},
	)
}
示例#2
0
文件: window.go 项目: bieber/drones
func (w *Window) Draw(screen *sdl.Surface) {
	screen.FillRect(
		&sdl.Rect{
			X: w.X,
			Y: w.Y,
			W: w.W,
			H: w.H,
		},
		ui.ColorToInt(w.BorderColor),
	)
	screen.FillRect(
		&sdl.Rect{
			X: w.X + int16(w.BorderWidth),
			Y: w.Y + int16(w.BorderWidth),
			W: w.W - w.BorderWidth*2,
			H: w.H - w.BorderWidth*2,
		},
		ui.ColorToInt(w.BGColor),
	)

	for _, child := range w.children {
		child.Draw(screen)
	}
}