private void MoveSelectionIndex(int delta) { if (!HasSelection) { return; } SelectedIndex = (int)Util.Clamp(_selectedIndex + delta, 0, Count - 1); }
/** Enable touch to scroll, and mousewheel scroll */ public override void Update() { base.Update(); if (ScrollMode == ScrollMode.None) { return; } bool touchToScroll = Engine.TouchDevice; bool scrolling = false; float dragStrength = 10f; if (touchToScroll) { dragStrength = 10f; if ((Input.touchCount >= 1) && (Depressed) && (!CoM.DragDrop.IsDragging)) { var touch = Input.GetTouch(0); Velocity = touch.deltaPosition / Time.deltaTime / Engine.DPIScale; scrolling = true; } } else { dragStrength = 10f; if (IsMouseInside && Input.mouseScrollDelta.magnitude != 0) { Vector3 impluse = Input.mouseScrollDelta * -500; Velocity = Velocity + impluse; scrolling = true; } } if (!scrolling) { Vector3 drag = -Velocity * Time.deltaTime * dragStrength; float mangnitude = Util.Clamp(drag.magnitude, 1, 1000); drag.Normalize(); drag = drag * mangnitude; if (drag.magnitude > Velocity.magnitude) { Velocity = new Vector3(0, 0, 0); } else { Velocity += drag; } } ScrollLocation.x += Velocity.x * Time.deltaTime; ScrollLocation.y += Velocity.y * Time.deltaTime; }
/** Makes the splat larger over time and fades it out. */ private void updateFadeout() { if (age < 0) { return; } if (age >= Life) { Remove(); return; } float factor = 1f - (age / Life); CompositeAlpha = Util.Clamp(factor * 2f, 0f, 1f); Visible = true; }
public override void Update() { fitScrollBox(); if (Messages == null) { Label.Caption = ""; return; } yoffset = Util.Clamp(yoffset - Time.deltaTime * 100, 0, 32); // Detect any added messages int newMessages = newMessageCount(); if (newMessages > 0) { // a new message has been added, so invalidate. Invalidate(); removeMessageTimer = AutoRemoveMessageTimeout; if (ScrollOn) { yoffset += 16 * newMessages; } if (AutoScrollToBottom) { ScrollToBottom(); } } // Auto delete if (AutoRemoveMessageTimeout != 0.0f) { if (Messages.Count > 0) { removeMessageTimer -= Time.deltaTime; if (removeMessageTimer <= 0) { for (int lp = 0; lp < Messages.Count; lp++) { if (!Messages[lp].FadeAndRemove) { Messages[lp].FadeAndRemove = true; break; } } removeMessageTimer = 0.33f; } } } // Retraction if (hideValue != goalHideValue) { if (hideValue < goalHideValue) { hideValue = (FadeOutTime == 0) ? goalHideValue : Util.Clamp(hideValue + Time.deltaTime / FadeOutTime, 0, goalHideValue); } if (hideValue > goalHideValue) { hideValue = (FadeInTime == 0) ? goalHideValue : Util.Clamp(hideValue - Time.deltaTime / FadeInTime, goalHideValue, 1); } } // Auto hide. if (AutoHideTimeout != 0.0f) { if (Time.time > mostRecentTimeStamp + AutoHideTimeout) { goalHideValue = 1.0f; } else { goalHideValue = 0.0f; } } // Fade out and remove messages. for (int lp = Messages.Count - 1; lp >= 0; lp--) { if (Messages[lp].FadeAndRemove) { Invalidate(); Messages[lp].Color.a -= Time.deltaTime; if (Messages[lp].Color.a <= 0) { Messages.RemoveAt(lp); } } } // Refresh text if needed. if (needsUpdate) { RefreshText(); } // Auto fading if (HideStyle == MessageBoxHideStyle.FadingMouse) { if (IsMouseOver) { goalHideValue = 0f; } } base.Update(); }