Ejemplo n.º 1
0
// Testing full image adjustment after screen resizing (assumes adjustImgs is scaling dimensions)
func TestThree(test *testing.T) {
	u = uistate.MakeUIState()
	u.Scene = &sprite.Node{}
	u.Eng = glsprite.Engine(nil)
	u.Eng.Register(u.Scene)
	u.Eng.SetTransform(u.Scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})
	imgPos := coords.MakeVec(5, 20)
	imgDimensions := coords.MakeVec(10, 10)
	newButton := texture.MakeImgWithoutAlt(subtex, imgPos, imgDimensions, u)
	u.Buttons["1"] = newButton
	oldWindow := u.WindowSize.DividedBy(2)
	resize.AdjustImgs(oldWindow, u)
	newPos := u.Buttons["1"].GetCurrent()
	newDimensions := u.Buttons["1"].GetDimensions()
	dimExpect := imgDimensions.Times(2)
	posExpect := imgPos.Times(2)
	if newDimensions.X != dimExpect.X {
		test.Errorf("Expected width %f, got %f", dimExpect.X, newDimensions.X)
	}
	if newDimensions.Y != dimExpect.Y {
		test.Errorf("Expected height %f, got %f", dimExpect.Y, newDimensions.Y)
	}
	if newPos.X != posExpect.X {
		test.Errorf("Expected x %f, got %f", posExpect.X, newPos.X)
	}
	if newPos.Y != posExpect.Y {
		test.Errorf("Expected y %f, got %f", posExpect.Y, newPos.Y)
	}
}
Ejemplo n.º 2
0
// Testing NewImgWithoutAlt
func TestFour(test *testing.T) {
	scene := &sprite.Node{}
	eng := glsprite.Engine(nil)
	u.Eng = eng
	u.Scene = scene
	pos := coords.MakeVec(5, 10)
	dimensions := coords.MakeVec(20, 10)
	i := texture.MakeImgWithoutAlt(subtex, pos, dimensions, u)
	if i.GetCurrent().X != pos.X {
		test.Errorf("Expected x %f, got %f", pos.X, i.GetCurrent().X)
	}
	if i.GetCurrent().Y != pos.Y {
		test.Errorf("Expected y %f, got %f", pos.Y, i.GetCurrent().Y)
	}
	if i.GetInitial().X != pos.X {
		test.Errorf("Expected inital x %f, got %f", pos.X, i.GetInitial().X)
	}
	if i.GetInitial().Y != pos.Y {
		test.Errorf("Expected initial y %f, got %f", pos.Y, i.GetInitial().Y)
	}
	if i.GetDimensions().X != dimensions.X {
		test.Errorf("Expected width %f, got %f", dimensions.X, i.GetDimensions().X)
	}
	if i.GetDimensions().Y != dimensions.Y {
		test.Errorf("Expected height %f, got %f", dimensions.Y, i.GetDimensions().Y)
	}
}