is 'GetTextHeight' reliable?

Started by EnterTheStory (aka tolworthy), Sat 31/05/2008 11:09:10

Previous topic - Next topic

EnterTheStory (aka tolworthy)

I tried the following code to see if the height was being correctly reported:
Code: ags

String what ="1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 0 0 0 0 0";
int length =GetTextHeight(what, 1, 165);   Display("next string, width 165, height %d", length); cEgo.Say(what);
what ="1111 1111 2222 2222 3333 3333 4444 4444 5555 5555 6666 6666 7777 7777 8888 8888 9999 9999 0000 0000";
length =GetTextHeight(what, 1, 165);   Display("next string, width 165, height %d", length); cEgo.Say(what);
what ="111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999999 000000000";
length =GetTextHeight(what, 1, 165);   Display("next string, width 165, height %d", length); cEgo.Say(what);
what ="1111111111222222222 3333333333444444444 5555555555666666666 7777777777888888888 9999999999000000000 1111111111222222222";
length =GetTextHeight(what, 1, 165);   Display("next string, width 165, height %d", length); cEgo.Say(what);
   
The results were:
First string: actual height 2 lines, or 20 game pixels. Reported as 30.
Second string: actual height 2 lines, or 20 game pixels. Reported as 30.
Third string: actual height 2 lines, or 20 game pixels. Reported as 40.
Fourth string: actual height 3 lines, or 30 game pixels. Reported as 60.
Any idea what is going on here?

Notes:
This refers to text spoken when ego is near the edge of the screen. I calculate that near the edge of my 320x240 screen, text width is 165. Experiments confirm this. I'm referring to game pixels here - my game is actually 640x480 in real pixels. Also, I loaded the exact same font into all three font slots, just to make sure that wasn't the issue.

Radiant

I believe it is, except if the text needs to be wrapped for the screen edge.

ATOTK uses gettextheight for its customized text box, and that works out.

EnterTheStory (aka tolworthy)

#2
Quote from: Radiant on Sat 31/05/2008 13:16:39
I believe it is, except if the text needs to be wrapped for the screen edge.

ATOTK uses gettextheight for its customized text box, and that works out.
So you force a particular width rather than letting 'Say' decide its own? I wonder if that can be done with "Say"? I don't think a customized box would work in my game, as I make heavy use of text (so a box would be too intrusive for me) and heavy use of "SayBackground" (so it would be a headache to code)

Radiant

Quote from: tolworthy on Sat 31/05/2008 13:24:47
So you force a particular width rather than letting 'Say' decide its own?
Yes.

Quote
I wonder if that can be done with "Say"?
As far as I know, no. You can, however, use RawPrint, or DisplaySpeechAt (SayAt).

Pumaman

You can't necessarily assume that Say uses a 165 width.

The algorithm for lucasarts-style speech is that the speech area width is 4/6 of the screen width, minus 1/5 if the character is within 80 pixels of the screen edge. In this case that would mean a 149 pixel-wide speech area -- but this isn't guaranteed to be fixed and could change in future versions of AGS.

Perhaps what you're after is some sort of Game.MAxSpeechWidth setting that you could manually set to allow you to specify the width of character speech?

EnterTheStory (aka tolworthy)

Quote from: Pumaman on Sun 01/06/2008 13:06:00
You can't necessarily assume that Say uses a 165 width.

The algorithm for lucasarts-style speech is that the speech area width is 4/6 of the screen width, minus 1/5 if the character is within 80 pixels of the screen edge. In this case that would mean a 149 pixel-wide speech area
Ah! So the 1/5 refers to the screen width. I thought it was the speech width. That makes more sense now. Thanks.

Quote from: Pumaman on Sun 01/06/2008 13:06:00Perhaps what you're after is some sort of Game.MAxSpeechWidth setting that you could manually set to allow you to specify the width of character speech?
Actually, all I really wanted was to fade out the background immediately behind the text in 'Say' or 'SayBackground'. The only way I can do it is by making several fuzzy cloud characters at different transparencies, and place them behind the text. Hence the need to know exactly where the text is at all times.

Pumaman

Would it be useful if you could specify that lucasarts-style speech was drawn in a text window GUI, which would allow you to use an alpha-transparent background image?

EnterTheStory (aka tolworthy)

Quote from: Pumaman on Sun 01/06/2008 17:00:02
Would it be useful if you could specify that lucasarts-style speech was drawn in a text window GUI, which would allow you to use an alpha-transparent background image?
Yes, definitely! Though in my case I'm wedded to 2.72 for Linux, and 16 bit for speed reasons, but it sounds like a very useful feature for anyone who can upgrade.

naltimari

Quote from: Pumaman on Sun 01/06/2008 17:00:02
Would it be useful if you could specify that lucasarts-style speech was drawn in a text window GUI, which would allow you to use an alpha-transparent background image?

I have implemented my own 'Say' routine, in a custom GUI because I needed to fade the background too (assigning an alpha masked background to the GUI). Actually, it also uses a 'queued' approach to the speech, so the dialog can be rewinded/skipped.

I am about to publish it as a module, if you find it interesting. You can customize the appearance of the GUI, in a much more flexible way than the 'text window' GUIs.

Anyway, it would be interesting to be able to apply an alpha-masked background to a text window GUI too.

SMF spam blocked by CleanTalk