|
|
This thread is locked; no one can reply to it.
|
1
2
|
| Quick question on newlines.. |
|
Neil Black
Member #7,867
October 2006
|
Yeah, I know it isn't that hard to do. But when I was first starting out I had no idea how to do it.
|
|
OICW
Member #4,069
November 2003
|
Reminds me of myself five years ago (that's approximately how that thread is old). [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I have a question about the modified version of Kitty Cat's multi line text output. Specifically the line : *(next++) = '\n'; From : Since a copy is being worked on , the newline doesn't need to be replaced , just setting the address to the next character should suffice. What I don't understand is why the character after the detected newline should be set to a newline? Isn't "*(next++)" the same as "*(next + 1)"? Since 'cur' gets set to the character position right after where the newline is detected and that character position's value has been set to a newline , why doesn't strchr(cur , '\n') keep returning the same value as 'cur'? In any case , I came up with another version , based on Kitty Cat's as well :
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
Mark Oates
Member #1,146
March 2001
|
Openlayer's TextRenderer does newlines automatically. -- |
|
Kitty Cat
Member #2,815
October 2002
|
Quote: Since a copy is being worked on , the newline doesn't need to be replaced , just setting the address to the next character should suffice.
Correct. A mistake on my part.. Quote: What I don't understand is why the character after the detected newline should be set to a newline? Isn't "*(next++)" the same as "*(next + 1)"? No. next++ post-increments the 'next' variable. It increments the variable, but "returns" the original value. ++next would increment the variable and give the new value. A fixed version of my code would be:
-- |
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Quote: No. next++ post-increments the 'next' variable. It increments the variable, but "returns" the original value. ++next would increment the variable and give the new value. Weird. Not what I would expect to happen given that it's in parentheses. I never thought of post-incrementation as returning the original value. Had to fix a bug in the version I put up and I also added in a function pointer parameter for which text function gets called. So now you can call textout_ex , textout_centre_ex , or textout_right_ex as an input parameter. My version now also displays the trailing end of the string containing newlines so you don't have to end it with a newline character. Use the v_spacing parameter to control the vertical spacing , and enter one of the three aforementioned allegro text functions for the text_func parameter. Revised code :
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|
|
1
2
|