API Question How to display text in an mfd

weepleman

New member
Joined
Aug 9, 2008
Messages
57
Reaction score
0
Points
0
Hi, I have read through the API Reference, and I cannot find where it says how to display a string of text onto the mfd. If anyone can tell me ho to do this, or where in the reference it is, it would be greatly aprechiated
 
You need to use the windows GDI functions, like TextOutA.
 
Are there any tutorials that show how to use those, or is it possible to use SDL?
 
Are there any tutorials that show how to use those, or is it possible to use SDL?

No. The examples are in the samples folder and in the MSDN documentation of the compiler. It is rather straight forward.

For example

Code:
TextOutA(hdc, x, y, text, strlen(text));

SDL also uses the windows functions (or similar) for such drawing, as SDL has only bitmap manipulation functions.
 
example, untested:

Code:
// width and height = MFD width and MFD height divided by 35 and 24
// respectively, save in the MFD constructor

void MyMFD::Update(HDC hDC)
{
    int len, y = height;
    char buffer[256];  
    VESSEL * v = oapiGetFocusInterface();

    len = sprintf(buffer, "Alt:   %.2f m", v->GetAltitude()); 
    TextOut(hDC, width, y, buffer, len); 
    y += height; // skip a line

    len = sprintf(buffer, "spd:  %.2f m", v->GetAirspeed()); 
    TextOut(hDC, width, y, buffer, len);
    y += height*2; // skip two lines
}
 
Just as additional clarification:

TextOut uses the current character set settings for your compiler, for example Unicode wide-chars (wchar_t).
TextOutA uses 8-bit ANSI characters (char).

I am not sure about the version with forced unicode, I think it was TextOutW.
 
Thanks for the help, I got the text working. Now, I need to be able to only press the buttons once when clicked on. Right now I am using PANEL_MOUSE_LBPRESSED for the consumebutton, is there a better event to use?
 
Now, I need to be able to only press the buttons once when clicked on. Right now I am using PANEL_MOUSE_LBPRESSED for the consumebutton, is there a better event to use?
I normally use PANEL_MOUSE_LBDOWN, but that is just personal preference.
 
I normally use PANEL_MOUSE_LBDOWN, but that is just personal preference.

Does that only make one mouse event per click on a button?

---------- Post added at 07:47 PM ---------- Previous post was at 07:38 PM ----------

The only mode that works at all is MOUSE_PANEL_LBPRESSED, is there something I need to do to make the other ones work?
 
The only mode that works at all is MOUSE_PANEL_LBPRESSED, is there something I need to do to make the other ones work?
My typical ConsumeButton:
Code:
bool YourMfd::ConsumeButton(int bt, int event)
{
	if(!(event & PANEL_MOUSE_LBDOWN)) return false; // only respond to left button down events

	switch (bt)
	{
	//...
	}

	return false;
}
 
That works! Thank You!:):):):):speakcool::speakcool::speakcool::speakcool::):);)!!!!!!!!!!!!!!!!!!!
 
Just as additional clarification:

TextOut uses the current character set settings for your compiler, for example Unicode wide-chars (wchar_t).
TextOutA uses 8-bit ANSI characters (char).

I am not sure about the version with forced unicode, I think it was TextOutW.
Yes, unicode uses TextOutW.

You should always try to use TextOut (over TextOutA/TextOutW) and set your project settings to use the correct character set. TextOut is just a macro to either TextOutA or TextOutW. Using those functions directly can cause problems if you platform architecture changes at a later date (ie, if orbiter changes to use Unicode strings at some future point)
 
Not to hijack the thread. But how does one display text on the screen? I have part. which works fine. But I want it to say Camera: 1 "pad#1" . I figure the pad1 is a value or enum. And if cam==1 then camname ="Pad 1"

char cbuf[128];
// char cbuf2[128];
int n, tx, ty, ty2, yoff, bs, ap,n1,ty3;
double apd;
GetTextMetrics(hdc, &tm);
yoff = tm.tmHeight;
tx = tm.tmAveCharWidth;
ty3 = 9 * yoff;
ty = 10 * yoff;
ty2 = 11 * yoff;

//Rectangle (hdc, tx-2, ty-1, tx+120,ty+(yoff*7));
SetTextColor (hdc, colRed);
n1 = sprintf (cbuf, "CAMERA: %d", (CAM));
TextOut(hdc,tx,ty3,cbuf,n1 );
 
If you are creating a vessel, you can write text on the screen by overriding the clbkDrawHUD method of the VESSEL2 class. If you are writing anything else, the easiest method is to use orbiter's annotation functions to write text on the screen. However using this method restricts you to writing text on the screen, you can't use standard GDI functions. You can also try Face's vessel hooking method if you require drawing using GDI.
 
Back
Top