Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 02/21/26 19:15
Camera always moves upwards?
by clonman. 02/21/26 09:29
Zorro version 3.0 prerelease!
by TipmyPip. 02/20/26 13:22
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 7,008 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Request: str_height #412859
12/04/12 13:11
12/04/12 13:11
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline OP
Junior Member
Talemon  Offline OP
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
Why isn't there a str_height function? I would be glad if you could implement it.

Re: Request: str_height [Re: Talemon] #413153
12/09/12 07:56
12/09/12 07:56
Joined: Jul 2000
Posts: 28,074
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,074
Frankfurt
The height of a string is just the number of lines multiplied with the font size. Only the width is complicated to calculate, that's why we only have a width function.

Re: Request: str_height [Re: jcl] #413203
12/10/12 07:46
12/10/12 07:46
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline OP
Junior Member
Talemon  Offline OP
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
Thank you, I didn't know that font size equals to text height.

Re: Request: str_height [Re: Talemon] #413230
12/10/12 16:06
12/10/12 16:06
Joined: Nov 2012
Posts: 62
Istanbul
T
Talemon Offline OP
Junior Member
Talemon  Offline OP
Junior Member
T

Joined: Nov 2012
Posts: 62
Istanbul
Well, I realized that my problem was dealing with word-wrapped TEXT strings so I wrote a function to calculate how many lines would a string take given a fixed width. In case anyone needs it, here it is:

Code:
int CountLines(STRING* str, FONT* font, var width)
{
	if(str == NULL) return 0;
	if(str_width(str, font) < width)return 1;
	
	var chr = str_chr(str, -str_len(str), 0x20);
	if(chr == 0) 
	{
		chr = str_len(str) - 1;
		while(str_width(str_cut(NULL, str, 0, chr), font) > width)
			chr -= 1;
	}
	
	STRING* rest = str_cut(NULL, str, chr + 1, 0);
	return 1 + CountLines(rest, font, width);
}


Re: Request: str_height [Re: Talemon] #413234
12/10/12 16:39
12/10/12 16:39
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
...adding this to my file with useful functions, thanks Talemon smile


POTATO-MAN saves the day! - Random
Re: Request: str_height [Re: Kartoffel] #413267
12/11/12 07:33
12/11/12 07:33
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
You might want to convert this into a loop, this doesn't have to be recursive at all.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Request: str_height [Re: WretchedSid] #413275
12/11/12 14:17
12/11/12 14:17
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Here is a simple implementation of str_height if anyone else needs it (without wwrap in texts):

Code:
function str_height(STRING* str, FONT* fnt)
{
	return fnt->dy * (int)*str->pad; 
}



Only tested on A7. It might change(or already have changed in A8) because pad is not documented wink

Re: Request: str_height [Re: krial057] #413277
12/11/12 14:44
12/11/12 14:44
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Just a question:
would
Code:
#define str_height(str,fnt) fnt->dy * (int)*str->pad


be faster than using it as a seperate function?

Last edited by Kartoffel; 12/11/12 15:41.

POTATO-MAN saves the day! - Random
Re: Request: str_height [Re: Kartoffel] #413377
12/12/12 21:43
12/12/12 21:43
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Yes, that would be faster. However you have to put everything in Parentheses:
Code:
#define str_height(str,fnt) (fnt->dy * (int)*str->pad)


Otherwise code like this would fail, because in this case / is evaluated before *:
Code:
printf("%i", 40/str_height(test, arial));


if str_height returns 40, your old macro would return 2 instead of 1.

Further more, you get strange compiler errors if something goes wrong in or near the macro and you can't get a function-pointer(but I don't think you will ever need to have to point to the str_height function wink )

If you can live with that, I don't see why not to use your macro(with parentheses of course laugh ) and it should be faster


Moderated by  aztec, Spirit 

Gamestudio download | 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