SDK Question Placing text next to MFD buttons

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
3
Points
18
In programming MasterMFD, which is my first MFD, I came across a problem.

I want to place text next to the MFD buttons, regardless of current MFD size. My two current functions to do that are:
Code:
void MasterMFD::drawTextNextToButton(int buttonNum, std::string text, oapi::Sketchpad* skp)
{
	[COLOR="Red"]double percentY = .143 * (buttonNum % 6) + .14;[/COLOR]
	//if buttonNum is less than 6 (on the left side), just draw normally
	//otherwise, draw out from the right
	if (buttonNum < 6)
		drawAtLinePercentage(3, percentY, text, skp); //3 pixels out for spacing
	else
		drawAtLinePercentage(width - skp->GetTextWidth(text.c_str()) - 3, percentY, text, skp);
}

void MasterMFD::drawAtLinePercentage(int xLoc, double percentY, std::string text, oapi::Sketchpad* skp)
{
	skp->Text(xLoc, (int)(percentY * height), text.c_str(), text.size()); 
}

The most important line is highlighted in red. It's job is to select a percentage of the height to put the text, using two "magic constants" that I discovered with trial and error.

That line basically lines up the top row of MFD buttons with 14% of the way down the MFD screen, and adds 14.3% more of the screen for each button downto the y coordinate.

Is there an easier way to make a size-agnostic alignment function?

---------- Post added at 01:37 PM ---------- Previous post was at 01:34 PM ----------

For example, in the generic MFD view, the text is pretty well lined up:
masterMFD_1.JPG


But in the DGIV 2D panel, the text at the bottom is slightly misaligned:
masterMFD_problem.JPG
 
Back
Top