Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 12-01-2017, 04:55 AM   #1
slaver0110
Orbinaut
 
slaver0110's Avatar
Default Scaling a bar graph in an MFD

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.
slaver0110 is offline   Reply With Quote
Old 12-01-2017, 06:29 AM   #2
Face
Beta Tester
 
Face's Avatar

Default

Quote:
Originally Posted by slaver0110 View Post
 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.
Face is offline   Reply With Quote
Old 12-01-2017, 11:32 AM   #3
martins
Orbiter Founder
Default

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);
martins is online now   Reply With Quote
Thanked by:
Old 12-01-2017, 05:58 PM   #4
slaver0110
Orbinaut
 
slaver0110's Avatar
Default

Quote:
Originally Posted by martins View Post
 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!!
slaver0110 is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 07:26 PM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.