internal void RecalculateSliderPosition(int posX = -1) { var offset = RelativeOffset + Background.AlignOffset; if (MaxValue - MinValue == 0) { ControlHandle.AlignOffset = offset; } else if (posX > 0) { if (posX <= Background.Position.X) { CurrentValue = MinValue; ControlHandle.AlignOffset = offset; } else if (posX >= Background.Position.X + SliderWidth) { CurrentValue = MaxValue; ControlHandle.AlignOffset = offset + new Vector2(SliderWidth, 0); } else { CurrentValue = (int)Math.Round(MinValue + ((posX - Background.Position.X) / SliderWidth) * (MaxValue - MinValue)); ControlHandle.AlignOffset = offset + new Vector2(((float)SliderWidth / (MaxValue - MinValue)) * (CurrentValue - MinValue), 0); } } else { if (CurrentValue == MinValue) { ControlHandle.AlignOffset = offset; } else if (CurrentValue == MaxValue) { ControlHandle.AlignOffset = offset + new Vector2(SliderWidth, 0); } else { ControlHandle.AlignOffset = offset + new Vector2(((float)SliderWidth / (MaxValue - MinValue)) * (CurrentValue - MinValue), 0); } } if (DisplayName.Contains("{")) { TextHandle.TextValue = string.Format(DisplayName, CurrentValue, MinValue, MaxValue); } ValueDisplayHandle.TextValue = string.Format("{0}/{1}", CurrentValue, MaxValue); ValueDisplayHandle.ApplyToControlPosition(this); }
protected internal override void OnThemeChange() { // Apply base theme base.OnThemeChange(); // Update height Height = DefaultHeight + (int)Background.Size.Y; // Update text offset TextHandle.Padding = new Vector2((Width - Background.Size.X) / 4, (DefaultHeight - TextHandle.Bounding.Height) / 2f); TextHandle.ApplyToControlPosition(this); ValueDisplayHandle.Padding = new Vector2(-TextHandle.Padding.X, TextHandle.Padding.Y); ValueDisplayHandle.ApplyToControlPosition(this); // Update aligns Background.AlignOffset = new Vector2(Size.X / 2 - Background.Size.X / 2, Size.Y - Background.Size.Y); RecalculateSliderPosition(); }