Page 1 of 1

Centering Text

Posted: Sun May 16, 2004 5:49 am
by Cryptonomic
I have what amounts to an epigram page that is essentially going to flash a quote at the player before the game proper begins. What I am wondering is what is the best way to center text on the screen?

With this, I should probably mention that my text is not just one line. Here is the quote I would be using:

"I became possessed with the keenest curiosity about"
"the whirl itself. I positively felt a wish to explore"
"its depths, even at the sacrifice I was going to make;"
"and my principal grief was that I should never be able"
"to tell my old companions on shore about the mysteries"
"I should see."
" - Edgar Allan Poe, \IA Descent into the Maelstrom\i, 1840"

I do see some code in the game "Guilty Bastards" that seems to point the way, but I wanted to get other people's take on this in terms of what they felt was the easiest way to center text like this by itself on the screen.

Any advice and/or thoughts would be appreciated. Thanks.

Posted: Mon May 17, 2004 2:39 pm
by Ice Cream Jonsey
Is there a center command? I can't recall one.

Otherwise, I guess you could get the number of display lines that you have available and do some math, and then use the tab command (argh, can't recall what it is -- it's in the manual, though) and go from there.

Anyone else got an idea?

Posted: Mon May 17, 2004 3:04 pm
by Roody_Yogurt
Looking at the manual, maybe you want to do that CenterTitle thing, which says it's called like this:

CenterTitle(text[, lines])

"Clears the screen and centers the text given by the
specified dictionary entry in the top window. The
default height of the title (i.e., one line) can be
overridden with a second argument giving the
number of lines."

So you could have crazy big letters if you wanted to by putting a higher number in the second argument.

In the Hugo zork code, it's just used like this (and therefore just one line tall):

CenterTitle("Introduction")

Posted: Mon May 17, 2004 3:24 pm
by Roody_Yogurt
Oops, reading that again and looking at the Zork example, I see that's only a status bar thing and wouldn't help here at all.

Seems like one has to do it by hand. Kent says, "Basically you do it in the non-proportional font, figure out the length of the string, and 'locate x' where x = display.screenwidth/2 - string_length/2."

Another way to do it is to use the window.h library to make a window, clear it to the color you want, and print or put graphics in it, I guess.

I haven't tried any of this.

Posted: Mon May 17, 2004 3:30 pm
by Hugella
Forgive my ignorance, but does all this finagling assume that players are using a given screen height/width?

Posted: Mon May 17, 2004 6:02 pm
by Roody_Yogurt
I don't really know how all this stuff works, either. I try not to think about it.

Sort of easy

Posted: Mon May 17, 2004 9:48 pm
by Kent
Basically you just need to know the length of the string you're printing. Then, either use either 'locate' or 'print to' to get to your position, using something like:

locate display.screenwidth/2 - string_length/2

where string_length is the length of the string. I'm a big proponent of checking display.screenwidth each time you do something like this (or anything involving screen positioning) in case the dimensions of the screen change.

(Note also that this requires the fixed-width font to work perfectly.)