1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
10 private bool isHorizontal;
11 private readonly
GUIFrame frame, slider;
12 private float barSize;
13 private readonly
bool showFrame;
20 get {
return isHorizontal; }
21 set { isHorizontal = value; }
26 get {
return barSize; }
29 if (!MathUtils.IsValid(value))
31 GameAnalyticsManager.AddErrorEventOnce(
32 "GUIProgressBar.BarSize_setter",
33 GameAnalyticsManager.ErrorSeverity.Error,
34 "Attempted to set the BarSize of a GUIProgressBar to an invalid value (" + value +
")\n" + Environment.StackTrace.CleanupStackTrace());
37 barSize = MathHelper.Clamp(value, 0.0f, 1.0f);
48 isHorizontal = (
Rect.Width >
Rect.Height);
50 GUIStyle.Apply(frame,
"",
this);
52 GUIStyle.Apply(slider,
"Slider",
this);
53 this.showFrame = showFrame;
54 this.barSize = barSize;
70 Vector4 sliceBorderSizes = Vector4.Zero;
71 if (slider.sprites.ContainsKey(slider.State) && (slider.sprites[slider.State].First()?.Slice ??
false))
73 var slices = slider.sprites[slider.State].First().Slices;
74 sliceBorderSizes =
new Vector4(slices[0].Width, slices[0].Height, slices[8].Width, slices[8].Height);
75 sliceBorderSizes *= slider.sprites[slider.State].First().GetSliceBorderScale(sliderArea.Size);
80 sliderArea.X + (
int)sliceBorderSizes.X,
82 (
int)Math.Round((sliderArea.Width - sliceBorderSizes.X - sliceBorderSizes.Z) * fillAmount),
87 (
int)Math.Round(sliderArea.Bottom - (sliderArea.Height - sliceBorderSizes.Y - sliceBorderSizes.W) * fillAmount - sliceBorderSizes.W),
89 (
int)Math.Round((sliderArea.Height - sliceBorderSizes.Y - sliceBorderSizes.W) * fillAmount));
91 sliderRect.Width = Math.Max(sliderRect.Width, 1);
92 sliderRect.Height = Math.Max(sliderRect.Height, 1);
97 protected override void Draw(SpriteBatch spriteBatch)
104 if (!MathUtils.IsValid(newSize))
106 GameAnalyticsManager.AddErrorEventOnce(
107 "GUIProgressBar.Draw:GetProgress",
108 GameAnalyticsManager.ErrorSeverity.Error,
109 "ProgressGetter of a GUIProgressBar (" +
ProgressGetter.Target.ToString() +
" - " +
ProgressGetter.Method.ToString() +
") returned an invalid value (" + newSize +
")\n" + Environment.StackTrace.CleanupStackTrace());
120 slider.RectTransform.MaxSize =
new Point(
123 frame.Visible = showFrame;
124 slider.Visible =
BarSize > 0.0f;
130 frame.DrawAuto(spriteBatch);
134 frame.DrawManually(spriteBatch);
138 Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;
142 spriteBatch.GraphicsDevice.ScissorRectangle =
Rectangle.Intersect(prevScissorRect, sliderRect);
148 slider.Color = currColor;
151 slider.DrawAuto(spriteBatch);
155 slider.DrawManually(spriteBatch);
158 frame.Visible =
false;
159 slider.Visible =
false;
164 spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
virtual ComponentState State
virtual Color GetColor(ComponentState state)
RectTransform RectTransform
override void Draw(SpriteBatch spriteBatch)
delegate float ProgressGetterHandler()
ProgressGetterHandler ProgressGetter
GUIProgressBar(RectTransform rectT, float barSize, Color? color=null, string style="", bool showFrame=true)
Rectangle GetSliderRect(float fillAmount)
Get the area the slider should be drawn inside
static RasterizerState ScissorTestEnable