protected internal override void OnTouchEvent(TouchEventCollection touchEvents) { base.OnTouchEvent(touchEvents); TouchEvent primaryTouchEvent = touchEvents.PrimaryTouchEvent; if (primaryTouchEvent.Type == TouchEventType.Down) { this.isFlick = false; if (this.animationState == LiveScrollPanel.AnimationState.Up) { this.animationState = LiveScrollPanel.AnimationState.Migrate; this.migrateDownPos = primaryTouchEvent.LocalPosition; this.migratePos = this.migrateDownPos; } else { this.touchDownPos = primaryTouchEvent.LocalPosition; this.touchPos = this.touchDownPos; touchEvents.Forward = true; } } else if (primaryTouchEvent.Type == TouchEventType.Up) { this.isDrag = false; } if (!this.isDrag) { touchEvents.Forward = true; } if (primaryTouchEvent.Type == TouchEventType.Up) { this.animationState = LiveScrollPanel.AnimationState.Up; this.flickElapsedTime = 0f; } }
public LiveScrollPanel() { this.animationSprt = new UISprite(1); this.animationSprt.InternalShaderType = InternalShaderType.LiveScrollPanel; this.animationSprt.TextureWrapMode = (TextureWrapMode)1; this.animationSprt.BlendMode = BlendMode.Premultiplied; this.animationSprt.Visible = false; base.RootUIElement.AddChildLast(this.animationSprt); this.MaxTextureWidth = this.defaultMaxTextureWidth; this.MaxTextureHeight = this.defaultMaxtextureHeight; this.needPartialTexture = false; this.textureOffsetX = 0f; this.textureOffsetY = 0f; this.frontPanel = new Panel(); base.AddChildLast(this.frontPanel); this.frontPanel.Clip = true; this.frontPanel.X = 0f; this.frontPanel.Y = 0f; 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); base.Clip = true; this.HorizontalScroll = true; this.VerticalScroll = true; this.animationState = LiveScrollPanel.AnimationState.None; base.HookChildTouchEvent = true; base.Width = 600f; base.Height = 300f; this.UpdateView(); }
private void FlickEventHandler(object sender, FlickEventArgs e) { base.ResetState(false); this.animationState = LiveScrollPanel.AnimationState.Up; this.isFlick = true; this.touchVelocity = e.Speed / 1000f * this.flickCoeff; this.panelVelocity += e.Speed / 1000f * this.flickCoeff; }
protected internal override void OnResetState() { this.animationState = LiveScrollPanel.AnimationState.None; this.unsetTexture(); this.touchPos = default(Vector2); this.panelVelocity = default(Vector2); this.touchVelocity = default(Vector2); this.flickElapsedTime = 0f; }
private void DragEventHandler(object sender, DragEventArgs e) { base.ResetState(false); this.isDrag = true; if (this.animationState == LiveScrollPanel.AnimationState.None) { this.animationState = LiveScrollPanel.AnimationState.Migrate; this.migrateDownPos = e.LocalPosition; this.migratePos = this.migrateDownPos; return; } if (this.animationState == LiveScrollPanel.AnimationState.Migrate) { this.migratePos = e.LocalPosition; return; } this.animationState = LiveScrollPanel.AnimationState.Drag; this.touchPos = e.LocalPosition; }
private void internalUpdate(float elapsedTime) { if (this.animationState == LiveScrollPanel.AnimationState.Drag || this.animationState == LiveScrollPanel.AnimationState.Migrate) { float num; float num2; if (this.needPartialTexture) { num = this.CalculateTextureOffsetX(); num2 = this.CalculateTextureOffsetY(); } else { num = 0f; num2 = 0f; } if (this.texImage == null) { this.textureOffsetX = num; this.textureOffsetY = num2; this.setTexture(); } else if (this.textureOffsetX != num || this.textureOffsetY != num2) { this.textureOffsetX = num; this.textureOffsetY = num2; this.unsetTexture(); this.setTexture(); } if (this.animationState == LiveScrollPanel.AnimationState.Migrate) { bool flag = true; Vector2 vector = this.migratePos - this.touchPos; if (vector.LengthSquared() > 4f) { this.touchPos += vector * (elapsedTime / 100f) + vector.Normalize() * 2f; flag = false; } else { this.touchPos = this.migratePos; } Vector2 vector2 = this.migrateDownPos - this.touchDownPos; if (vector2.LengthSquared() > 4f) { this.touchDownPos += vector2 * (elapsedTime / 100f) + vector2.Normalize() * 2f; flag = false; } else { this.touchDownPos = this.migrateDownPos; } if (flag) { this.animationState = LiveScrollPanel.AnimationState.Drag; } } if (this.panelVelocity.LengthSquared() > 1E-09f) { Vector2 vector3 = -this.panelVelocity.Normalize() * this.kineticFriction - this.panelVelocity * this.viscousFriction; this.panelVelocity += (this.tension + vector3) * elapsedTime * this.forceCoeff; } else if (this.tension.LengthSquared() > (this.isFlick ? (this.staticFrictionSq / 100f) : this.staticFrictionSq)) { this.panelVelocity += this.tension * elapsedTime * this.forceCoeff; } if (this.HorizontalScroll) { this.frontPanel.X += this.panelVelocity.X * elapsedTime; } if (this.VerticalScroll) { this.frontPanel.Y += this.panelVelocity.Y * elapsedTime; } this.adjustPanelEdge(); return; } if (this.animationState == LiveScrollPanel.AnimationState.Up) { if (this.needPartialTexture) { float num3 = this.CalculateTextureOffsetX(); float num4 = this.CalculateTextureOffsetY(); if (this.textureOffsetX != num3 || this.textureOffsetY != num4) { this.textureOffsetX = num3; this.textureOffsetY = num4; this.unsetTexture(); this.setTexture(); } } if (this.texImage == null || (this.tension.LengthSquared() < 4f && this.touchVelocity.LengthSquared() < 0.01f && this.panelVelocity.LengthSquared() < 0.01f)) { this.OnResetState(); return; } if (this.panelVelocity.LengthSquared() > 0.0001f) { Vector2 vector4 = -this.panelVelocity.Normalize() * this.kineticFriction - this.panelVelocity * this.viscousFriction; this.panelVelocity += (this.tension + vector4) * elapsedTime * this.forceCoeff * this.panelTouchRatio; } else if (this.tension.LengthSquared() > this.staticFrictionSq || this.isFlick) { this.panelVelocity += this.tension * elapsedTime * this.forceCoeff * this.panelTouchRatio; } if (!this.isFlick) { if (this.frontPanel.X > -10f && this.panelVelocity.X < 0f) { this.panelVelocity.X = (this.frontPanel.X + 10f) * elapsedTime * this.forceCoeff; } else if (this.frontPanel.X < this.Width - this.frontPanel.Width + 10f && this.panelVelocity.X > 0f) { this.panelVelocity.X = (this.frontPanel.X - (this.Width - this.frontPanel.Width + 10f)) * elapsedTime * this.forceCoeff; } if (this.frontPanel.Y > -10f && this.panelVelocity.Y < 0f) { this.panelVelocity.Y = (this.frontPanel.Y + 10f) * elapsedTime * this.forceCoeff; } else if (this.frontPanel.Y < this.Height - this.frontPanel.Height + 10f && this.panelVelocity.Y > 0f) { this.panelVelocity.Y = (this.frontPanel.Y - (this.Height - this.frontPanel.Height + 10f)) * elapsedTime * this.forceCoeff; } } this.isFlick = false; Vector2 vector5 = default(Vector2); if (this.touchVelocity.LengthSquared() > 0.0001f) { vector5 = -this.touchVelocity.Normalize() * this.kineticFriction - this.touchVelocity * this.viscousFriction; vector5 *= this.touchFrictionRatio; } if (this.touchVelocity.LengthSquared() < 0.01f && this.tension.LengthSquared() < 50f) { this.touchVelocity += (vector5 - this.tension * (1f + 100f / this.tension.LengthSquared())) * elapsedTime * this.forceCoeff * (1f - this.panelTouchRatio); if (this.tension.LengthSquared() < 1.401298E-45f || this.touchVelocity.Dot(this.tension) / this.tension.LengthSquared() * elapsedTime < -1f) { this.touchVelocity = -this.tension / elapsedTime; } } else { this.touchVelocity += (vector5 - this.tension) * elapsedTime * this.forceCoeff * (1f - this.panelTouchRatio); } if (this.tension.LengthSquared() > 1.401298E-45f) { this.touchVelocity = this.tension * this.touchVelocity.Dot(this.tension) / this.tension.LengthSquared(); } if (this.HorizontalScroll) { this.frontPanel.X += this.panelVelocity.X * elapsedTime; } if (this.VerticalScroll) { this.frontPanel.Y += this.panelVelocity.Y * elapsedTime; } this.touchPos += this.touchVelocity * elapsedTime; this.adjustPanelEdge(); } }