Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Directx Font, setting rect x,x2,y,y2 to fit text

This topic is 5482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With directx font, im sick of having to set the rect size , the x,x2,y and y2. Or like in my class, x,y, width, height. Is there a way of calculating the size of the rectangle from the variables of the font...? heres a section of my font class, what values would i use to calculate the size of the rectangle?
void init(char font[], int size, int weight,bool underline, bool italic)
	lp_Font = NULL;
	HDC hDC= GetDC( NULL );
	int nHeight= -( MulDiv( size, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );
	ReleaseDC( NULL, hDC );					
	HFONT hFont = CreateFont(nHeight, 0, 0, 0, weight, italic, underline, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, font );
	D3DXCreateFont(D3D::lp_Device , hFont, &lp_Font);
	DeleteObject( hFont );	

void draw(char text[], int x, int y, int width, int height, DWORD colour)
	RECT destRect1;
	SetRect(&destRect1, x, y, x+width, y+height);
	lp_Font->DrawText(text, -1, &destRect1, DT_WORDBREAK, colour );

Share this post

Link to post
Share on other sites
include the DT_NOCLIP flag in your draw argument and you only have to set the x, and y. if you want to clip it against a given container, you should have the coordinates be generated by the container,(something like a bounding or clipping rect), which will automate your future calls.


"To die with your sword still in its sheath is most regrettable" -- Miyomoto Musashi

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!