private void FlickEventHandler(object sender, FlickEventArgs e) { this.animationState = InternalSpinBox.SpinList.AnimationState.Flick; float virtualVec = this.GetVirtualVec(e.Speed); this.flickDistance = virtualVec * this.flickSpeedCoeff; if (this.IsItemFit) { if (this.flickDistance > 0f) { if ((double)this.ItemGapLine * 2.0 - (double)this.ScrollAreaPixelOffset - (double)(this.flickDistance / this.flickInterpRate) > 0.0) { this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; this.fitInterpRate = this.flickDistance / (this.ItemGapLine - this.ScrollAreaPixelOffset); if (this.ScrollAreaFirstLine >= this.CalcMaxLineIndex() && !this.IsLoop) { this.fitTargetIndex = this.ScrollAreaFirstLine; } else { this.fitTargetIndex = this.ScrollAreaFirstLine + 1; } this.fitTargetOffsetPixel = 0f; return; } } else if ((double)(this.ItemGapLine + this.ScrollAreaPixelOffset + this.flickDistance / this.flickInterpRate) > 0.0) { this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; this.fitInterpRate = -this.flickDistance / this.ScrollAreaPixelOffset; this.fitTargetIndex = this.ScrollAreaFirstLine; this.fitTargetOffsetPixel = 0f; } } }
internal void ScrollTo(int scrollAreaLineIndex, float offsetPixel, bool withAnimate) { if (scrollAreaLineIndex < 0) { scrollAreaLineIndex += this.TotalLineNum; } this.NormalizeLineIndex(ref scrollAreaLineIndex, ref offsetPixel); if (this.IsItemFit) { if (offsetPixel > this.ItemGapLine * 0.5f) { scrollAreaLineIndex++; } offsetPixel = 0f; } if (!this.IsLoop) { if (scrollAreaLineIndex >= this.CalcMaxLineIndex()) { scrollAreaLineIndex = this.CalcMaxLineIndex(); offsetPixel = 0f; } if (scrollAreaLineIndex < this.CalcMinLineIndex()) { scrollAreaLineIndex = this.CalcMinLineIndex(); offsetPixel = 0f; } } else if (Math.Abs(scrollAreaLineIndex - scrollAreaLineIndex) > (this.TotalLineNum - 1) / 2) { if (scrollAreaLineIndex - scrollAreaLineIndex > 0) { scrollAreaLineIndex -= this.TotalLineNum; } else { scrollAreaLineIndex += this.TotalLineNum; } } if (this.isSetup && withAnimate) { this.fitTargetIndex = scrollAreaLineIndex; this.fitTargetOffsetPixel = offsetPixel; this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; this.fitInterpRate = 0.2f; return; } this.SetScrollAreaLineIndex(scrollAreaLineIndex, offsetPixel); }
protected internal override void OnTouchEvent(TouchEventCollection touchEvents) { base.OnTouchEvent(touchEvents); TouchEvent primaryTouchEvent = touchEvents.PrimaryTouchEvent; switch (primaryTouchEvent.Type) { case TouchEventType.Up: this.isPress = false; if (this.animationState != InternalSpinBox.SpinList.AnimationState.Flick && this.IsItemFit) { if (this.ScrollAreaPixelOffset > this.ItemGapLine * 0.5f) { this.fitTargetIndex = this.ScrollAreaFirstLine + 1; } else { this.fitTargetIndex = this.ScrollAreaFirstLine; } this.fitTargetOffsetPixel = 0f; this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; this.fitInterpRate = 0.2f; } break; case TouchEventType.Down: this.animationState = InternalSpinBox.SpinList.AnimationState.None; this.startTouchPos = primaryTouchEvent.LocalPosition; this.isPress = true; break; case TouchEventType.Move: if (this.isPress) { Vector2 realVec = this.startTouchPos - primaryTouchEvent.LocalPosition; if (Math.Abs(this.GetVirtualVec(realVec)) > this.minDelayDragDist) { this.animationState = InternalSpinBox.SpinList.AnimationState.Drag; } } break; } if (this.animationState != InternalSpinBox.SpinList.AnimationState.Drag && this.animationState != InternalSpinBox.SpinList.AnimationState.Flick) { touchEvents.Forward = true; } }
public SpinList() { this.basePanel = new Panel(); base.AddChildLast(this.basePanel); base.HookChildTouchEvent = true; this.IsLoop = true; this.scrollAreaLineNum = 1; this.listItemNum = 0; this.ItemGapLine = 0f; this.cacheLineCount = 1; this.IsItemFit = true; this.ScrollAreaFirstLine = 0; this.focusIndex = InternalSpinBox.SpinList.itemIdNoFocus; this.lastSelectIndex = InternalSpinBox.SpinList.itemIdNoSelect; this.cacheStartIndex = InternalSpinBox.SpinList.noCache; this.cacheEndIndex = InternalSpinBox.SpinList.noCache; this.isSetup = false; this.animationState = InternalSpinBox.SpinList.AnimationState.None; this.flickDistance = 0f; this.flickInterpRate = 0.09f; this.flickSpeedCoeff = 0.03f; this.fitTargetIndex = 0; this.fitTargetOffsetPixel = 0f; this.fitInterpRate = 0.2f; this.isPress = false; this.startTouchPos = Vector2.Zero; this.listItem = new List <InternalSpinBox.SpinList.ListContainer>(); this.poolItem = new List <InternalSpinBox.SpinList.ListContainer>(); this.minDelayDragDist = 5f; base.Clip = true; this.FocusChanged = null; DragGestureDetector dragGestureDetector = new DragGestureDetector(); dragGestureDetector.DragDetected += new EventHandler <DragEventArgs>(this.DragEventHandler); base.AddGestureDetector(dragGestureDetector); FlickGestureDetector flickGestureDetector = new FlickGestureDetector(); flickGestureDetector.FlickDetected += new EventHandler <FlickEventArgs>(this.FlickEventHandler); base.AddGestureDetector(flickGestureDetector); }
protected override void OnUpdate(float elapsedTime) { base.OnUpdate(elapsedTime); if (this.animationState == InternalSpinBox.SpinList.AnimationState.Flick) { if (0.5f > this.flickDistance && -0.5f < this.flickDistance && !this.IsItemFit) { this.flickDistance = 0f; this.animationState = InternalSpinBox.SpinList.AnimationState.None; } float num = this.flickDistance + this.ScrollAreaPixelOffset; int scrollAreaFirstLine = this.ScrollAreaFirstLine; this.NormalizeLineIndex(ref scrollAreaFirstLine, ref num); if (scrollAreaFirstLine < this.CalcMinLineIndex() && !this.IsLoop) { this.SetScrollAreaLineIndex(this.CalcMinLineIndex(), 0f); this.animationState = InternalSpinBox.SpinList.AnimationState.None; } else if (num > 0f && scrollAreaFirstLine >= this.CalcMaxLineIndex() && !this.IsLoop) { this.SetScrollAreaLineIndex(this.CalcMaxLineIndex(), 0f); this.animationState = InternalSpinBox.SpinList.AnimationState.None; } else { this.SetScrollAreaLineIndex(scrollAreaFirstLine, num); } this.flickDistance = MathUtility.Lerp(this.flickDistance, 0f, this.flickInterpRate); if (this.IsItemFit) { if (this.flickDistance > 0f) { if (this.ItemGapLine - this.ScrollAreaPixelOffset - this.flickDistance < 0f) { if (!this.IsLoop && this.ScrollAreaFirstLine + 2 > this.CalcMaxLineIndex()) { float num2 = this.ItemGapLine * (float)(this.CalcMaxLineIndex() - this.ScrollAreaFirstLine) - this.ScrollAreaPixelOffset; this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; if (num2 < 0.5f) { this.fitInterpRate = 0.2f; } else { this.fitInterpRate = this.flickDistance / num2; } this.fitTargetIndex = this.CalcMaxLineIndex(); this.fitTargetOffsetPixel = 0f; return; } if (this.ItemGapLine * 3f - this.ScrollAreaPixelOffset - this.flickDistance / this.flickInterpRate > 0f) { this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; this.fitInterpRate = this.flickDistance / (this.ItemGapLine * 2f - this.ScrollAreaPixelOffset); this.fitTargetIndex = this.ScrollAreaFirstLine + 2; this.fitTargetOffsetPixel = 0f; return; } } } else if (this.ScrollAreaPixelOffset + this.flickDistance < 0f) { if (!this.IsLoop && this.ScrollAreaFirstLine - 1 < this.CalcMinLineIndex()) { float num3 = -(this.ItemGapLine * (float)(this.ScrollAreaFirstLine - this.CalcMinLineIndex()) + this.ScrollAreaPixelOffset); this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; if (num3 < 0.5f) { this.fitInterpRate = 0.8f; } else { this.fitInterpRate = this.flickDistance / num3; } this.fitTargetIndex = this.CalcMinLineIndex(); this.fitTargetOffsetPixel = 0f; return; } if (this.ItemGapLine * 2f + this.ScrollAreaPixelOffset + this.flickDistance / this.flickInterpRate > 0f) { this.animationState = InternalSpinBox.SpinList.AnimationState.Fit; this.fitInterpRate = -this.flickDistance / (this.ItemGapLine * 1f + this.ScrollAreaPixelOffset); this.fitTargetIndex = this.ScrollAreaFirstLine - 1; this.fitTargetOffsetPixel = 0f; return; } } } } else if (this.animationState == InternalSpinBox.SpinList.AnimationState.Fit) { int num4 = this.ScrollAreaFirstLine - this.fitTargetIndex; if (this.isLoop) { if (num4 > this.TotalLineNum / 2) { num4 -= this.TotalLineNum; } else if (num4 < -this.TotalLineNum / 2) { num4 += this.TotalLineNum; } } float num5 = MathUtility.Lerp((float)num4, 0f, this.fitInterpRate); num4 = (int)num5; float num6 = (num5 - (float)num4) * this.ItemGapLine; num6 += MathUtility.Lerp(this.ScrollAreaPixelOffset - this.fitTargetOffsetPixel, 0f, this.fitInterpRate); this.SetScrollAreaLineIndex(num4 + this.fitTargetIndex, num6 + this.fitTargetOffsetPixel); if (num4 == 0 && Math.Abs(num6) <= 0.5f) { this.animationState = InternalSpinBox.SpinList.AnimationState.None; this.SetScrollAreaLineIndex(this.fitTargetIndex, this.fitTargetOffsetPixel); if (this.FocusChanged != null) { this.FocusChanged.Invoke(this, EventArgs.Empty); } } } }
protected internal override void OnResetState() { base.OnResetState(); this.animationState = InternalSpinBox.SpinList.AnimationState.None; this.isPress = false; }