×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Aug 2003
    Location
    Eire
    Posts
    182

    Jumping to a new line. Is there a command to put in the middle of the text?

    I am using my own menu but was using an Alert to display all the help info i.e. the rules.

    But the Alert doesn’t look like the Main menu so it looks out of place so I have an idea to create my own canvas based help screen.

    What I was wondering is there a way to write a few lines of text to the screen without using say 10 drawstrings to do each new line.

    I would like to have my test like this


    Code:
    g.drawString("Controls /newline
     2 = Up /newline
     8 = Down / newline
     4 = Left /newline
     6 = Right / newline
     Keep the ball on the / newline 
     court and hit the  / newline
     targets for bonuses", screenCenter,17, g.TOP | g.HCENTER);
    I would like to be able to specify when to go to a new line?
    Is there a little command or something for this?

    Thanks
    B

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    No, I'm afraid you need to write each line to the right place. You could do something like:
    Code:
    String [] asHelpText = {
        "Controls", "2 = up", "and so on"
    };
    
    // g is the Graphics context passed to paint()
    
    int nFontHeight = g.getFont ().getHeight ();
    
    for (int i = 0; i < asHelpText.length; i ++) {
        g.drawString (asHelpText [i], 0, i * nFontHeight, Graphics.TOP | Graphics.LEFT);
    }
    This assumes that each line is short enough to fit in the screen, and that there are few enough lines to fit without scrolling. If you only need to support one phone and the text will fit, you're OK. Otherwise, you'll need to write code to handle word wrapping to the screen width, and scrolling if you run out of screen.

    One alternative is to use a Form, and append StringItem objects to it. Most phones will handle word wrapping and scrolling automatically this way.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Aug 2003
    Location
    Eire
    Posts
    182
    That is such a pity!

    Graham how do you handle displaying help?

    I was really hoping there was away to format this kind of thing.
    I saw somewhere somebody using something like /n but cant find it anymore.

    Might just stay using an alert though it just does'nt fit in as well with the colour of the menu.

    No!! i'm going to give your way a lash.... its early yet and i've very little else do be doing tonight.

    Thanks
    B

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    And of course this might help you out. You could use it in a loop instead of putting the lines in an array, just draw substrings with the positions it gives you (notice that it also outputs linebreaks with '\n').

    shmoove

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×