Author |
Message |
whaleye
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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). |
|
|
|
|
![](images/spacer.gif) |
whaleye
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Panphobia
![](http://compsci.ca/v3/uploads/user_avatars/62033050050c6b61548706.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Panphobia
![](http://compsci.ca/v3/uploads/user_avatars/62033050050c6b61548706.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|