|
3 registered members (AndrewAMD, Grant, Neb),
908
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
adding space to text
#451679
05/16/15 11:40
05/16/15 11:40
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Howdy, How come to following code only works for text objects that don't have a font set (so it uses the standard / build in? gs3d font):
function list_addspaces(var maxcheck)
{
var length = str_len(mystring);
var addspace = clamp(maxcheck - length, 1, maxcheck);
var i;
for (i = 0; i < addspace; i++) str_cat(mystring, " ");
}
function writestrings()
{
...
list_addspaces(10);
...
}
I want to use this for a big list.
Last edited by Reconnoiter; 05/16/15 13:57.
|
|
|
Re: adding space to text
[Re: Quad]
#451681
05/16/15 14:00
05/16/15 14:00
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
I accidently typed mytext here instead of mystring when writing this post.
But anyway, how to get the above working for a text with a font set to it (like arial, calibri whatever)? It does work when not setting a font, but when I set a font it does not work anymore. Does this have to with differences in pixel width between letters and spaces in fonts?
Last edited by Reconnoiter; 05/16/15 14:01.
|
|
|
Re: adding space to text
[Re: Reconnoiter]
#451683
05/16/15 14:47
05/16/15 14:47
|
Joined: Apr 2005
Posts: 1,988 Canadian, Eh
DLively
Serious User
|
Serious User
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
|
I didn't want to suggest this because it may seem redundant or even stupid at worst - to some. But make sure you spelt it right  : FONT* arial_font = "Arial#20b"; I seriously doubt the above is the problem - but the engine will allow you to run the game even if you don't correctly type in your font names. Just a thought... 
Last edited by DLively; 05/16/15 14:49.
|
|
|
Re: adding space to text
[Re: DLively]
#451685
05/16/15 15:25
05/16/15 15:25
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
try replacing the space with another caracter to see what happen .. (havent really looked in to it)
but after that I think try something like chr() or ascii() I cannot remember right now , dont know if gamestudio has it
Compulsive compiler
|
|
|
Re: adding space to text
[Re: Wjbender]
#451686
05/16/15 16:08
05/16/15 16:08
|
Malice
Unregistered
|
Malice
Unregistered
|
I know you are looking to solve this. However, a very easy way is to use different TEXT* object for each column. If you are making a list then this is a fine solution. But this is a design solution to a code problem.
also try str_length(myText->pstring[0])
that's wrong but you get the idea. str_len((my_text.pstring)[7]);
Last edited by Malice; 05/16/15 16:15.
|
|
|
Re: adding space to text
[Re: ]
#451687
05/16/15 16:32
05/16/15 16:32
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
ty for all the fast reactions; @DLively, double checked it just to be sure, the font itself looks fine. try replacing the space with another caracter to see what happen .. (havent really looked in to it) , yes this makes a difference, the "_" seems to be working alot better than " ". Probably cause its pixel size is bigger(?). Still not perfect, but I will try to toy around with str_width. but after that I think try something like chr() or ascii() I cannot remember right now , dont know if gamestudio has it , there is _chr and _str, but that doesn't seem to have any effect. also try str_length(myText->pstring[0]) , yes I am actually using an text array with pstring already, but I wanted it to keep it clear here. I know you are looking to solve this. However, a very easy way is to use different TEXT* object for each column. If you are making a list then this is a fine solution. But this is a design solution to a code problem. , this is probably the best solution, as in multiple strings per text objects for each column. Though I am a bit wary of using multiple strings cause the list is going to be enormous (with a slider etc to scroll quickly through it). It should able to contain a 1000 lines atleast. So I was thinking adding multiple strings would increase memory usage to much, but maybe I am wrong here?? I hope to be wrong at that 
|
|
|
Re: adding space to text
[Re: Reconnoiter]
#451688
05/16/15 17:56
05/16/15 17:56
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
I quess it is not possible to set the position of strings of a text object, right? Would be nice if I can use them as columns. Or atleast to try it out. -edit str_width works better than str_length, its not yet perfect though:
function list_addspaces(var count, var maxcheck)
{
var length = str_width( mystring, calibri15_font) / 10;
var addspace = clamp(maxcheck - length, 1, maxcheck);
var i;
for (i = 0; i < addspace; i++) str_cat( mystring, " ");
}
Last edited by Reconnoiter; 05/16/15 19:12.
|
|
|
Re: adding space to text
[Re: ]
#451695
05/17/15 15:09
05/17/15 15:09
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Thanks but that effects the whole text object instead of only part of it and it effects the y pos not the x pos. But there is a solution, monospaced fonts do the trick when combining with my first code example (the one that use str_len instead of str_width), cause in a monospaced font every letter has the same size  . It can look a bit uglier, but so far I am happy with FONT* CourierNew18 = "Courier New#18"; . -edit LucidaConsole14 is a very good choice if you don't have much space while still wanting to keep it a bit clear.
Last edited by Reconnoiter; 05/17/15 15:40.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|