Esempio 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)
	}
}
Esempio n. 2
0
// Testing resetting card position
func TestSix(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},
	})
	u.EmptySuitImgs = []*staticimg.StaticImg{staticimg.MakeStaticImg(), staticimg.MakeStaticImg(), staticimg.MakeStaticImg(), staticimg.MakeStaticImg()}
	u.WindowSize = windowSize
	n := texture.MakeNode(u)
	for _, e := range u.EmptySuitImgs {
		e.SetImage(subtex)
		e.SetAlt(subtex)
		e.SetNode(n)
	}
	c := card.NewCard(card.Two, card.Heart)
	c2 := card.NewCard(card.Four, card.Heart)
	n = texture.MakeNode(u)
	n2 := texture.MakeNode(u)
	initialXY := coords.MakeVec(10, 10)
	curXY := coords.MakeVec(100, 30)
	dimensions := coords.MakeVec(5, 5)
	c.SetNode(n)
	c2.SetNode(n2)
	c.SetInitial(initialXY)
	c2.SetInitial(initialXY)
	c.Move(curXY, dimensions, u.Eng)
	c2.Move(curXY, dimensions, u.Eng)
	u.Cards = append(u.Cards, c)
	u.Cards = append(u.Cards, c2)
	if c.GetCurrent().X != curXY.X {
		test.Errorf("Expected x %f, got %f", curXY.X, c.GetCurrent().X)
	}
	if c.GetCurrent().Y != curXY.Y {
		test.Errorf("Expected y %f, got %f", curXY.Y, c.GetCurrent().Y)
	}
	reposition.ResetCardPosition(c, u.Eng)
	reposition.ResetCardPosition(c2, u.Eng)
	reposition.RealignSuit(c.GetSuit(), c.GetInitial().Y, u)
	if c.GetCurrent().X != u.Padding {
		test.Errorf("Expected x %f, got %f", initialXY.X, c.GetCurrent().X)
	}
	if c.GetCurrent().Y != initialXY.Y {
		test.Errorf("Expected y %f, got %f", initialXY.Y, c.GetCurrent().Y)
	}
	if c2.GetCurrent().X != u.Padding+dimensions.X+u.Padding {
		test.Errorf("Expected x %f, got %f", u.Padding+dimensions.X+u.Padding, c2.GetCurrent().X)
	}
	if c2.GetCurrent().Y != initialXY.Y {
		test.Errorf("Expected y %f, got %f", initialXY.Y, c2.GetCurrent().Y)
	}
}
Esempio n. 3
0
func main() {
	app.Main(func(a app.App) {
		var glctx gl.Context
		var sz size.Event
		u := uistate.MakeUIState()
		for e := range a.Events() {
			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					glctx, _ = e.DrawContext.(gl.Context)
					onStart(glctx, u)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					glctx = nil
					onStop(u)
				}
			case size.Event:
				if !u.Done {
					// rearrange images on screen based on new size
					sz = e
					resize.UpdateImgPositions(sz, u)
				}
			case touch.Event:
				touchhandler.OnTouch(e, u)
			case paint.Event:
				if !u.Done {
					if glctx == nil || e.External {
						continue
					}
					onPaint(glctx, sz, u)
					a.Publish()
					a.Send(paint.Event{}) // keep animating
				}
			}
		}
	})
}