PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Question regarding DrawText

I have a lame question regarding DrawText. I want to print lot of characters (rules of the game) out using DrawText and the system font will do. I never know how wide the screen will be (it depends on the device, orientation, etc) so I need something like a word wrap functionality to take care of the basic text formatting.

Yes, I can hear you guys saying to go word by word using the GDDRAWTEXT_CALCWIDTH flag until I reach the width of the actual screen and start a new line after reaching it but I'm just too lazy doing that if there is another way.

If there is no other way around I will write my own routine I promise :wink:

Thanks a lot for the help and GapiDraw!
Pejo Software - Per · 24 Aug 2002, 16:00 UTC
You could use GDI if you don't mind the performance penalty (this way you can also use true type fonts).
Here is an example:
Code:
m_TextSurface.CreateSurface(GDCREATESURFACE_CLEAR, 50, 60);
m_TextSurface.SetColorKey(RGB(0,0,0));
RECT r={0,0,80,60};
HDC hdc;
m_TextSurface.GetDC(&hdc;);
SetTextColor(hdc,RGB(255,255,255));
SetBkColor(hdc,RGB(0,0,0));
DrawText(hdc, _T("This is some text that I want to display."), -1, &r;, DT_LEFT|DT_WORDBREAK);
m_TextSurface.ReleaseDC(hdc);
There is no other way.. even when using GDI there is no magical "wrap me this text nicely" function or method ( unless you use build in widgets or controls as they are called in Windows world.)
Pejo Software - Per · 25 Aug 2002, 09:45 UTC
Warmi, I don't understand what you mean. If you correct the error in the code above (the Rect should not be wider than the surface, sorry about that) it will display the text and break to a new line if the next word doesn't fit into the current line. If you want some more fancy text formatting than what DrawText and other GDI functions can provide I guess you have to write your own routine or find some on the web.
I was replying to the original poster.
Thanks guys for the tips. I will try the GDI since I don't care the performance this time.