Help With Aligning Font.Draw/Draw.Text
Author |
Message |
Beaner7
|
Posted: Mon Jan 29, 2007 8:15 pm Post subject: Help With Aligning Font.Draw/Draw.Text |
|
|
I know when you use Draw.Text it should look like this
Draw.Text ("What you want it to say",x coordinate,y coordinate,the font you previously declared,colour)
but the "x coordinate" and "y coordinate" are for the bottom left hand corner.
What i am trying to do is let the user enter the word they want and then have it appear
in the bottom right hand corner of the screen. But when i set the x and y it will always
start at the same spot and if the word is to long it will run off the page.
So is there anyway to change it so that the end of the word will always end somewhere
around maxx-50, letting the word start where ever it needs to make this happen.
__________________________________
|-----------------------------------------------------|
|-------------------------------Really Long Word|
|-----------------------------------------------------|
|------------Instead of this-----------------------|
|-----------------------------------------------------|
|------------------------------------------Really Lo|ng Word
|_________________________________|
And is there a way to center the middle of the word over the middle of the page
even when the user inputs the word which means it will have different amounts
of letters (different length each time).
_________________________________
|------------------------|--------------------------|
|--------------------Wo|rd-----------------------|
|-------------------Big |Word-------------------| (You get the idea)
|________________________________|
Thanks
(not for a project, semester already ended. Mainly for fun and next year) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
syntax_error
|
Posted: Mon Jan 29, 2007 8:29 pm Post subject: Re: Help With Aligning Font.Draw/Draw.Text |
|
|
u could do this code: |
var word : string
qwer := boolean
var font :int
font :=Font.New ("Ariel:18:Italic")
var x : int % max letter in the font
put "ehter ur word"
get word
if word <= x then
qwer := true
else
qwer := false
end if
Font.Draw (x,0,0,font,colour)
|
|
|
|
|
|
|
Beaner7
|
Posted: Mon Jan 29, 2007 8:55 pm Post subject: Re: Help With Aligning Font.Draw/Draw.Text |
|
|
im trying to figure out how that wil help
im assuming it is for aligning the text in the center
I get an error right here because word is a string and x is a int
Quote: if word <= x then
qwer := true
and x is always changing because the user can input as many
characters as they want.
--------------------------------------------------------------------------------
From what you gave me there i got an idea
For the centering one
If there is a way to find out how many characters the user inputted,
then i could multiply the number of characters by roughly the number
of pixels each character takes up
( 8 characters * 20 pixels each = 160 pixels)
if i take how many pixels the entire word takes up divided by 2
(160 / 2 = 80)
then i could take "maxx div 2 - the half of the toal pixels
(maxx div 2 - 80)
that way it is aligning it at bottom left but yet the middle ends up on the
middle roughly
I might have just answered my own question but how do i count how
many characters they input. |
|
|
|
|
|
Bored
|
Posted: Mon Jan 29, 2007 9:13 pm Post subject: Re: Help With Aligning Font.Draw/Draw.Text |
|
|
Or you could use Turings built in functions Font.Width and Font.Height. Look them up in the reference, if you have any trouble just tell us and we'll try to help.
An example:
|
|
|
|
|
|
syntax_error
|
Posted: Mon Jan 29, 2007 9:32 pm Post subject: Re: Help With Aligning Font.Draw/Draw.Text |
|
|
when i said x is the max number of char i ment it as you manully try and find the max number and is it is more that max then it wont work.. |
|
|
|
|
|
Beaner7
|
Posted: Mon Jan 29, 2007 9:34 pm Post subject: Re: Help With Aligning Font.Draw/Draw.Text |
|
|
Thanks Alot
That was exactly what I was look for and i Modified it for the center as well
Heres what it looks like by itself
Quote:
var font := Font.New ("Serif:30:bold")
var font1:= Font.New ("Freestyle Script:20:bold")
var name,title : string
put"Enter The Title: "..
get title:*
put"Enter Your Name: "..
get name:*
cls
Font.Draw (""+title, maxx div 2 - Font.Width (""+title, font) div 2 ,maxy-40,font,red)
Font.Draw (""+name, maxx - 10 - Font.Width (""+name, font1), 10, font1, red)
And depending on how the finish product looks i might realease here. |
|
|
|
|
|
Clayton
|
Posted: Tue Jan 30, 2007 12:51 pm Post subject: Re: Help With Aligning Font.Draw/Draw.Text |
|
|
Turing: |
Font.Draw (""+title, maxx div 2 - Font.Width (""+title, font ) div 2 ,maxy- 40,font, red)
Font.Draw (""+name, maxx - 10 - Font.Width (""+name, font1 ), 10, font1, red)
|
why have the ""+title/name? Font.Draw accepts a string parameter and title and name are both strings, so concatenating them with an empty string makes no sense. All you need is:
Turing: |
Font.Draw (title, maxx div 2 - Font.Width (title, font ) div 2, maxy - 40, font, red)
Font.Draw (name, maxx div 2 - 10, - Font.Width (name, font1 ), 10, font1, red)
|
|
|
|
|
|
|
|
|