Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to use Font.Draw to draw a string longer than the width such that it will go to the next line
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
whaleye




PostPosted: Sat Dec 15, 2012 2:58 pm   Post subject: How to use Font.Draw to draw a string longer than the width such that it will go to the next line

What is it you are trying to achieve?
I am trying to make a string draw onto the screen and if the string is too long it will go and do it on a lower line


What is the problem you are having?
I can't figure out how to do this with Font.Draw, the string will always just go off the edge of the screen instead of text wrapping


Describe what you have tried to solve this problem
I tried implementing something with the Font.Width function but couldn't figure out how to use it to solve the problem.



Please specify what version of Turing you are using
<Answer Here>
4.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Dec 15, 2012 3:18 pm   Post subject: RE:How to use Font.Draw to draw a string longer than the width such that it will go to the next line

To wrap a string, you need to figure out how many characters you can fit on the screen, and any extra characters have to be drawn in a new line, with a new Font.Draw command. You can use Font.Width() to get the width of the string, and if it's too big, remove letters or words from the string until it fits. When you have to write the 2nd line, do the whole process again (otherwise, if the 2nd line is also too big, it won't wrap).
whaleye




PostPosted: Sat Dec 15, 2012 3:39 pm   Post subject: Re: How to use Font.Draw to draw a string longer than the width such that it will go to the next line

So I do:
if Font.Width(string)>maxx


Where do I go from there?
How do I split the string and know where to split it?
Insectoid




PostPosted: Sat Dec 15, 2012 3:46 pm   Post subject: RE:How to use Font.Draw to draw a string longer than the width such that it will go to the next line

You don't know where to split it. You have to try removing one letter or word at a time, depending on how you want it to wrap.
Panphobia




PostPosted: Sat Dec 15, 2012 3:47 pm   Post subject: RE:How to use Font.Draw to draw a string longer than the width such that it will go to the next line

you basically wrote your code yourself, then make a substring of the old string length - maxx to old string length, and make it on the next line, keep doing that until there are no more characters or the length is <= maxx
Insectoid




PostPosted: Sat Dec 15, 2012 4:03 pm   Post subject: RE:How to use Font.Draw to draw a string longer than the width such that it will go to the next line

code:
make a substring of the old string length - maxx to old string length


'old string length - maxx' is in pixels. Strings are measured in characters. You can't just subtract pixels off a string. It's more complicated than that.
Panphobia




PostPosted: Sat Dec 15, 2012 4:15 pm   Post subject: RE:How to use Font.Draw to draw a string longer than the width such that it will go to the next line

i didnt mean pixels i meant number of characters in a string
Insectoid




PostPosted: Sat Dec 15, 2012 4:17 pm   Post subject: RE:How to use Font.Draw to draw a string longer than the width such that it will go to the next line

maxx is in pixels. Not characters. I suggest you write your own working solution to a problem before you try to help someone with theirs.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: