Computer Science Canada

Centre Text?!

Author:  mike200015 [ Sun Jan 30, 2005 7:30 pm ]
Post subject:  Centre Text?!

Is there any way to centre text automatically instead of trial and error of trying to change the coordinates ??

Author:  Mr. T [ Sun Jan 30, 2005 7:33 pm ]
Post subject: 

no

Author:  person [ Sun Jan 30, 2005 7:48 pm ]
Post subject: 

i think there is, since a standard text screen, is 25 rows by 80 columns, so the centre is (1,40)

Author:  ssr [ Sun Jan 30, 2005 7:58 pm ]
Post subject: 

well, u can put the text in middle by doing something like index
first count how many chars are there
then div them by 2
locate (1,maxcol div 2 - the number of char div 2)
put the text
And there u go

Also, u can chaneg the size of thee output window by doing somethign liek
setscreen("graphics:x;y")
yep adn there u go
8)

Author:  ssr [ Sun Jan 30, 2005 8:05 pm ]
Post subject: 

Here's a code for ya
use length to coutn how many chars are there and then use the way I mentioned above! Very Happy Smile

code:

var word : string
var length1:int
    get word:*
    length1:= length (word) div 2
locate ( maxrow div 2,maxcol div 2 - length1)
put word

Author:  basketball4ever [ Sun Jan 30, 2005 8:09 pm ]
Post subject: 

code:
    var len : int := length ("Hello World")
    locate (1, (maxcol - len) div 2)
    put "Hello World" ..


hope it helps...
first u calculate how many letters are in ur string... and set it as a variable, so basically hello world has 11 characters.

Then in ur locate, you have 1 (being the row) then have the max col of the screen, minus the length, so in a default screen... (80-11) then div 2... = the center will be the center leter of ur text, in this case, a space.

Author:  ssr [ Sun Jan 30, 2005 8:14 pm ]
Post subject: 

srry made a mistake ,
subtract first then div
srry
basketball4ever is right, its the same thing as I said
and hopefully it helps! Rolling Eyes

Author:  mike200015 [ Sun Jan 30, 2005 11:17 pm ]
Post subject: 

hey, yea thanx .. both of those helped me

but what i dont understand is why you use maxcol?.. isnt that maximum colour? what does that have to do with centring text?

Author:  mike200015 [ Sun Jan 30, 2005 11:20 pm ]
Post subject: 

o wait.. never mind.. i figured it out.. its maximum column not colour lol

and also how would you incorporate that into Font.Draw , since i usually use that rather than jus the regular put

Author:  Bacchus [ Sun Jan 30, 2005 11:23 pm ]
Post subject: 

no maxcol is for the maximum column, for the maximum color its maxcolor close but no cigar. they use maxcol because the text (even when you use locatxy) gets printed in the row and column specified (nearest row and column for locatexy) except if you dont use locatexy or locate then it starts at the maxrow (or is it row 1? which one is the top lol, i dunno i never use locate Razz) and either decreases or increases by one, depending on which is the top maxrow or 1 lol. rows go across and column go up and down. but you probably kno this so ive just wasted my time explaining.... meh

Author:  mike200015 [ Sun Jan 30, 2005 11:31 pm ]
Post subject: 

lol.. yea knew some of that.. but watever.. thanx anyway Very Happy

Author:  Bacchus [ Sun Jan 30, 2005 11:55 pm ]
Post subject: 

lol im bored so i went a bit in depth Razz

Author:  Cervantes [ Mon Jan 31, 2005 8:26 am ]
Post subject: 

mike200015 wrote:
and also how would you incorporate that into Font.Draw , since i usually use that rather than jus the regular put


Turing:

var word := "Hello World"
const fontHeight := 48
var font := Font.New ("Times New Roman:" + intstr (fontHeight))
Font.Draw (word, round ((maxx - Font.Width (word, font)) / 2), round ((maxy - fontHeight) / 2), font, black)

It's the same idea. THINK! Rolling Eyes

Author:  ssr [ Mon Jan 31, 2005 8:07 pm ]
Post subject: 

Yep, but instead of using maxcol adn maxrow, u use maxx and maxy because font draw are measured in pixels instead of rows and columns! Idea

Author:  basketball4ever [ Mon Jan 31, 2005 8:13 pm ]
Post subject: 

ssr wrote:
Yep, but instead of using maxcol adn maxrow, u use maxx and maxy because font draw are measured in pixels instead of rows and columns! Idea


unless you're using locatexy go see my tutorial on basic text stuff Very Happy

Author:  ssr [ Mon Jan 31, 2005 8:19 pm ]
Post subject: 

yep locatexy too Very Happy actually its easier to use locatexy, um...
tnx
Very Happy

Author:  [Gandalf] [ Tue Feb 01, 2005 12:34 pm ]
Post subject: 

I do it ssr's way. You could also (for left/right) use something like Center.Text or something, but I forget the exact command since like I said, I don't use it.

Author:  ste_louis26 [ Thu Feb 03, 2005 5:52 pm ]
Post subject: 

code:

var str:string:="what is this???"
locate (1,(maxcol - length (str)) div 2)
put str


: