コード例 #1
0
ファイル: touchhandler.go プロジェクト: vanadium/croupier
func OnTouch(t touch.Event, u *uistate.UIState) {
	if t.Type == touch.TypeBegin {
		u.ViewOnTouch = u.CurView
		beganTouchX = t.X
		beganTouchY = t.Y
	} else if u.CurView != u.ViewOnTouch {
		return
	}
	// tap 5 times to trigger debug mode
	if t.Type == touch.TypeEnd {
		if t.X == beganTouchX && t.Y == beganTouchY && time.Since(timeStartedTapping).Seconds() <= 5.0 {
			numTaps++
			if numTaps == 5 {
				fmt.Println("TOGGLING DEBUG")
				u.Debug = !u.Debug
				view.ReloadView(u)
				numTaps = 0
			}
		} else {
			numTaps = 0
			timeStartedTapping = time.Now()
		}
	}
	switch u.CurView {
	case uistate.Discovery:
		switch t.Type {
		case touch.TypeBegin:
			beginClickDiscovery(t, u)
		case touch.TypeMove:
			moveClickDiscovery(t, u)
		case touch.TypeEnd:
			endClickDiscovery(t, u)
		}
	case uistate.Arrange:
		switch t.Type {
		case touch.TypeBegin:
			beginClickArrange(t, u)
		case touch.TypeMove:
			moveClickArrange(t, u)
		case touch.TypeEnd:
			endClickArrange(t, u)
		}
	case uistate.Table:
		switch t.Type {
		case touch.TypeBegin:
			beginClickTable(t, u)
		case touch.TypeMove:
			moveClickTable(t, u)
		case touch.TypeEnd:
			endClickTable(t, u)
		}
	case uistate.Pass:
		switch t.Type {
		case touch.TypeBegin:
			beginClickPass(t, u)
		case touch.TypeMove:
			moveClickPass(t, u)
		case touch.TypeEnd:
			endClickPass(t, u)
		}
	case uistate.Take:
		switch t.Type {
		case touch.TypeBegin:
			beginClickTake(t, u)
		case touch.TypeMove:
			moveClickTake(t, u)
		case touch.TypeEnd:
			endClickTake(t, u)
		}
	case uistate.Play:
		switch t.Type {
		case touch.TypeBegin:
			beginClickPlay(t, u)
		case touch.TypeMove:
			moveClickPlay(t, u)
		case touch.TypeEnd:
			endClickPlay(t, u)
		}
	case uistate.Split:
		switch t.Type {
		case touch.TypeBegin:
			beginClickSplit(t, u)
		case touch.TypeMove:
			moveClickSplit(t, u)
		case touch.TypeEnd:
			endClickSplit(t, u)
		}
	case uistate.Score:
		switch t.Type {
		case touch.TypeBegin:
			beginClickScore(t, u)
		case touch.TypeMove:
			moveClickScore(t, u)
		case touch.TypeEnd:
			endClickScore(t, u)
		}
	}
	u.LastMouseXY.X = t.X
	u.LastMouseXY.Y = t.Y
}