Beispiel #1
0
func (t *Text) draw_texture(texture *sdl.Texture, x, y int32, center_x, center_y bool) {
	_, _, t.w, t.h, _ = texture.Query()
	if center_x {
		x = int32(win_size/2 - t.w/2)
	}
	if center_y {
		y = int32(win_size/2 - t.h/2)
	}
	dst = sdl.Rect{x, y, int32(t.w), int32(t.h)}
	renderer.Copy(texture, &src, &dst)
}
Beispiel #2
0
// GetSizeOfGraphic returns the width and heigth of the Graphic, g.
// GetSizeOfGraphic returns two numbers of type int. The first numnber,
// marked as 'width', is the width of the Graphic, g, in pixels. The second number,
// marked as 'height' is the height of the Graphic, g, in pixels.
//
// GetSizeOfGraphic will panic if:
//
// 1. The Graphic, g, does not contain a Graphic type.
//
// 2. The toolbox has not been initialised.
func GetSizeOfGraphic(g Graphic) (width, height int) {
	if !initialised {
		// this stops execution here, so ne need for an else after the if
		panic(notInitialisedMessage)
	}
	if g == nil {
		panic(nilGraphicMessage)
	}
	var w, h int32
	var err error
	var t *sdl.Texture
	t = g
	_, _, w, h, err = t.Query()
	if err != nil {
		fmt.Print("Failed to query texture: ")
		fmt.Println(err)
		panic(err)
	}
	width = int(w)
	height = int(h)
	// return is implicit - using named return paramaters
	return
}