Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
text_height - How to get height of a TEXT #422237
05/06/13 08:35
05/06/13 08:35
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
This is not really a contribution but a helpful hint. When you want to obtain the height of a TEXT object you can do it as follows:

Code:
int height = myText.font.dy;


Re: text_height - How to get height of a TEXT [Re: PadMalcom] #422253
05/06/13 12:19
05/06/13 12:19
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Very useful. Thanks!

Re: text_height - How to get height of a TEXT [Re: oliver2s] #422322
05/07/13 14:02
05/07/13 14:02
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
If the text contains multiple lines, you can use this function:
Code:
function txt_height(TEXT* text)
{
	int i = 0, linecount = 0;
	for(i = 0; i < text->strings; i++)
	{
		linecount += *(text->pstring)[i]->pad;
	}
	return text->font->dy * linecount;
}



Testcode:
Click to reveal..
Code:
#include <acknex.h>

TEXT* txttest =
{
	flags = SHOW;
	string("line1\nline2", "line3", "line4");
}

function txt_height(TEXT* text)
{
	int i = 0, linecount = 0;
	for(i = 0; i < text->strings; i++)
	{
		linecount += *(text->pstring)[i]->pad;
	}
	return text->font->dy * linecount;
}

function main() {
	//4 lines * 9 pixels = 36 pixels height
	printf("%i", (int)txt_height(txttest));
}


Re: text_height - How to get height of a TEXT [Re: krial057] #422324
05/07/13 15:05
05/07/13 15:05
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Would you mind explaining what you want to achieve with this line?
Code:
linecount += *(text->pstring)[i]->pad;



Always learn from history, to be sure you make the same mistakes again...
Re: text_height - How to get height of a TEXT [Re: Uhrwerk] #422333
05/07/13 16:17
05/07/13 16:17
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
I found out some time ago, that string->pad[0] to pad[3] contain the number of lines of the string(It is not documented. Because it is unofficial it might change in future versions of 3dgs). Some examples
"line1\nline2\line3" -> pad[0-3] = 3
"line1" -> pad[0-3] = 1
This is faster then checking every character of a string for a new-line.
Because linecount is an integer, only the 4 first bytes of pad are copied(that's what we want, becuase there the line count of the string is located)

Re: text_height - How to get height of a TEXT [Re: krial057] #422354
05/07/13 23:25
05/07/13 23:25
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Ok. O.o I honestly wouldn't rely on that.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1