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, Grant, Neb), 908 guests, and 6 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
adding space to text #451679
05/16/15 11:40
05/16/15 11:40
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline 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):

Code:
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: Reconnoiter] #451680
05/16/15 13:49
05/16/15 13:49
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
str_len takes STRING* as parameter not TEXT*


3333333333
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 Offline OP
Serious User
Reconnoiter  Offline 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 Offline
Serious User
DLively  Offline
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 laugh : 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... laugh

Last edited by DLively; 05/16/15 14:49.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: adding space to text [Re: DLively] #451685
05/16/15 15:25
05/16/15 15:25
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

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

M
Malice
Unregistered
Malice
Unregistered
M



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 Offline OP
Serious User
Reconnoiter  Offline 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.

Quote:
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.

Quote:
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.

Quote:
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.

Quote:
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 grin

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 Offline OP
Serious User
Reconnoiter  Offline 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:

Code:
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: Reconnoiter] #451692
05/16/15 19:23
05/16/15 19:23

M
Malice
Unregistered
Malice
Unregistered
M



Quote:
I quess it is not possible to set the position of strings of a text object, right?



check out offset_y http://www.conitec.net/beta/atext-offset_y.htm

and
FLAGS CENTER_X CENTER_Y http://www.conitec.net/beta/atext-flags.htm

Last edited by Malice; 05/16/15 19:24. Reason: Bad copy paste
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 Offline OP
Serious User
Reconnoiter  Offline 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 laugh . 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.

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