Quantcast
Viewing all articles
Browse latest Browse all 112

Get x value in relation to horizontal bar

I'm wanting to create my own ProgressBar, more specifically using XNA. In order to do this, I need to fill the ProgressBar from position 0(which represents the minimum) to the value in relation to the min/max. This is easy if the minimum is 0 and the maximum is 100.

If the value was 5 then I'd fill 5% of the ProgressBar. However this is not always the case as the Min/Max are properties(doubles) and the minimum could be... say -57 and the maximum could be... say -3. How would I find out what percentage to fill the ProgressBar?

Why did I ever curse out my 8th grade algebra teacher telling her I'd never use this crap?!!!

Edit: Ok, so I think I may have figured it out. Could somebody confirm it for me?

Take the maximum and subtract it from the minimum. I'll call this x
Take the value and subtract it from the minimum. I'll call this y
Divide y into x to get the percentage.

Using this with Min: -57 and Max: -3 and Value: -10, I'd do this:
-57 - -3 = 54
-10 - -3 = 47
47 / 54 = 0.87 or 87%

Edit #2: Then to figure out the amount needed to fill the control then I'd take the percentage above and multiply it by the control's width:
Code:

Private Function GetPercentage() As Double
    Dim x As Double = max - min
    Dim y As Double = pValue - min

    Return y / x
End Function

Private Function GetFillWidth() As Double
    Return Me.GetPercentage * Me.Width
End Function

Again, I'd love for somebody to confirm this for me because I don't trust my math enough.

Viewing all articles
Browse latest Browse all 112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>