General Question Scaling a bar graph in an MFD

slaver0110

Member
Joined
Mar 21, 2011
Messages
72
Reaction score
2
Points
6
I'm trying to implement a simple horizontal-bar display of propellant resources in an MFD.

It goes like: (just as an example)
Propellant Resource: PR
Bar-Width at full propellant: 350 pixels from left
Bar-Width at zero propellant: zero pixels from left

The filled bar is simply a visual representation of how much of a given propellant resource remains; much like in the RefuelMFD, and others like it.

Obviously, if PR is greater than 350, the bar will appear off-scale, so I need to mathematically scale the bar to fit within a certain range.

I realize that the answer/formula for this is most likely rediculously simple, but after an hour of trying on my own (I can be stubborn that way) I can't figure it out.

I ask the community for a little help again.:shrug:
 

Face

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 18, 2008
Messages
4,403
Reaction score
581
Points
153
Location
Vienna
I'm trying to implement a simple horizontal-bar display of propellant resources in an MFD.

It goes like: (just as an example)
Propellant Resource: PR
Bar-Width at full propellant: 350 pixels from left
Bar-Width at zero propellant: zero pixels from left

The filled bar is simply a visual representation of how much of a given propellant resource remains; much like in the RefuelMFD, and others like it.

Obviously, if PR is greater than 350, the bar will appear off-scale, so I need to mathematically scale the bar to fit within a certain range.

Perhaps I'm not understanding your problem fully, but to me that sounds like a percentage problem. You'd simply calculate
Code:
int Wbar=(int)((double)PR/(double)PRmax*350);

The casts are to ensure that the ratio is not truncated to zero during calculation if your PR values are stored as integers.

It sure is trivial, but I hope it helps.
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
In addition to Face's answer for scaling with the propellant capacity, you should also scale your bar with the MFD display area (the 350 pixels sounds suspicious. You can never assume that an MFD display has a fixed width).

So instead of making the bar 350 pixels wide, you should make it a certain percentage of the MFD screen width. You can use the MFD2::GetWidth() function for that. For example, if you want the bar to be 3/4 of the MFD display width, you can say

Code:
double WbarMax = 0.75*GetWidth();
int Wbar=(int)((double)PR/(double)PRmax*WbarMax);
 

slaver0110

Member
Joined
Mar 21, 2011
Messages
72
Reaction score
2
Points
6
In addition to Face's answer for scaling with the propellant capacity, you should also scale your bar with the MFD display area (the 350 pixels sounds suspicious. You can never assume that an MFD display has a fixed width).

So instead of making the bar 350 pixels wide, you should make it a certain percentage of the MFD screen width. You can use the MFD2::GetWidth() function for that. For example, if you want the bar to be 3/4 of the MFD display width, you can say

Code:
double WbarMax = 0.75*GetWidth();
int Wbar=(int)((double)PR/(double)PRmax*WbarMax);

Face and Martin, thanks for that. The 350 figure was just an arbitrary number I used in the example. As well, I should have used the term "progress bar", which would have been less confusing.
I figured it was a percentage, just couldn't work out how it was implemented.
Cheers, everyone!!
 
Top