Page 1 of 2

Wrapping with DrawText

PostPosted: Jul 4, 2003 @ 8:17am
by Sparkie

PostPosted: Jul 4, 2003 @ 9:55am
by Johan
Hi! Please feel email me any suggestions you might have regarding function names and data return types at gapidraw@viktoria.se

PostPosted: Jul 4, 2003 @ 11:55am
by ppcStudios
I was just thinking about creating a wrapper for simple text processing that would parse the input string for \n and simply 'chop' it up and draw the text on separate lines. Warlords does a TON of text rendering from a file-based string table and this feature would be wonderful to have in GapiDraw 2.02

Another nice text feature (I'm just dreaming here) would be to pass DrawText a string with basic format commands (such as %d) along with an argument list and have the method insert the embedded text. Many of our text strings are currently broken up into multiple segments that have to be read in separately and have a value inserted in them, then drawn out. For example :

read in : You have
embed : (some number)
read in : cities
merge them together and DrawText

It would be nice if I could :

read in : You have %d cities
pass DrawText the string and some number in an arglist.

Just a thought =)

PostPosted: Jul 5, 2003 @ 8:55am
by Sparkie

PostPosted: Jul 7, 2003 @ 12:11pm
by ppcStudios

PostPosted: Jul 7, 2003 @ 4:39pm
by Sparkie

Agreed

PostPosted: Jul 8, 2003 @ 5:16am
by cottrelld

PostPosted: Jul 8, 2003 @ 9:30am
by Sparkie

PostPosted: Jul 8, 2003 @ 11:08am
by 8bit
I'm new to GD but can I make a suggestion? Create a function that takes a whole string of characters and then returns the dimensions used up by the string - Width & Height in pixels.

For a fixedsize 8x8 font:
"ace" will give us a dimension of Width = 24 and Height = 6 (lowercase).
"ACE" will give us a dimension of Width = 24 and Height = 8 (uppercase).

GD will then do the calculation natively which will be a big performance boost, rather than making multiple function calls for every character in the a string which will take longer.

Uses for this function for example will allow one to create a destination surface according to the dimensions, blit the string to that surface, then do all sorts of extra effects like scaling and rotation...

Like I said, just a suggestion - use it don't use it. :)

[EDIT - a few minute later]

I see that CGapiSurface::DrawText has support for GDDRAWTEXT_CALCWIDTH, but doesn't have a GDDRAWTEXT_CALCHEIGHT, which would be a nice to have. But CGapiSurface::RenderSystemFont does not have the same ability.

PostPosted: Jul 8, 2003 @ 1:57pm
by Sparkie

PostPosted: Jul 8, 2003 @ 10:08pm
by Sm!rk

PostPosted: Jul 9, 2003 @ 8:54am
by Pejo Software - Per

PostPosted: Jul 9, 2003 @ 10:30am
by maurice

PostPosted: Jul 10, 2003 @ 10:01am
by Johan
Hi,

Unfortunately I don't have the time to revamp the DrawText function.. But I will add the following functions in 2.02:

// Returns the width in pixels needed to draw the string pString
HRESULT GetStringWidth(const TCHAR* pString, DWORD* pWidth);

// Returns the width in pixels for the specified character
HRESULT GetCharWidth(TCHAR tcChar, DWORD* pWidth);

// Returns the white space in pixels between the two characters
HRESULT GetSpacing(TCHAR tcChar1, TCHAR tcChar2, DWORD* pSpacing);

Hope it's enough for most uses. It would involve too much work to add the individual height of each character so unfortunately this will not be added.

I will however probably change the DrawText function to support features such as drawing text in columns etc in the future, hope it's not too much pain to change all the DrawText calls (The last parameter DWORD* pWidth would be changed to GDDRAWTEXTFX* pFX)...

PostPosted: Jul 10, 2003 @ 10:09am
by Johan