×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jun 2007
    Location
    Bangkok
    Posts
    84

    draw Text "Hello World1\Hello World2" at center of screen

    I would like to write symbian code drawing text "Hello World1\nHello Word2" at the center of my application view.

    Code has to automatically check resolution of phone(176x208, 240x320, 352x418) and also choose the right font size(not too big and too small).

    Please guide me some symbian code. Thank you in advance.
    Sawaddee krab.

  2. #2
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: draw Text "Hello World1\Hello World2" at center of screen

    Hi,

    TRect tells you the screen size your can calculate the center on this basis and see HelloWorldPlus application that display the text on the screen

    hope will be helpful to you

  3. #3
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: draw Text "Hello World1\Hello World2" at center of screen

    also you can calculate the centre of screen, choose font (say Symbol Font) and then calculate point of text draw as centreX - (textWidth/2)

    as said this is a very simple case and you will find good enough help with sdk examples (helloworld itself)
    Amit Kankani
    Nokia Developer Champion

  4. #4
    Regular Contributor
    Join Date
    Jun 2007
    Location
    Bangkok
    Posts
    84

    Re: draw Text "Hello World1\Hello World2" at center of screen

    Thank you for amitkankani and kkrish.

    So,I decide to choose CEikLabel to layout text at the center of screen

    Code:
        iLabel = new ( ELeave ) CEikLabel;
        iLabel->SetContainerWindowL( *this );
        iLabel->SetAlignment( EHCenterVCenter );
            
        // Set lablel's font
        iLabel->SetFont( LatinBold19() );
    
        iLabel->SetTextL( _L("Hello World"));
    but how can i choose the correct font suitable for different resolution of phones.

    Please guide me some symbian code. Thankyou.
    Last edited by junmobus; 2008-05-23 at 20:22.
    Sawaddee krab.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,570

    Re: draw Text "Hello World1\Hello World2" at center of screen

    Wiki article http://wiki.forum.nokia.com/index.ph..._scalable_text shows something you might consider usable - however it works in the opposite direction.

  6. #6
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: draw Text "Hello World1\Hello World2" at center of screen

    yah thats a good idea, but if you want to simply change the size of the text and not the text itself, then I would recommend DrawText method.

    Though I am not sure if this is the best way to do things, however, I have used this and it seems to work for me...

    Here you will have to set a font, and this could be one of the "SymbolFont" or "TitleFont" or etc... so depending on the device and resolution, it will automatically choose the appropriate size.

    const CFont *font=CEikonEnv::Static()->TitleFont(); // here you could use other font types also
    gc.UseFont(font);

    // calculate the TPoint based on the height and width of the text in current font....

    gc.DrawText(textToDraw, TPoint(xPoint, yPoint));


    gc.DiscardFont();

    this way if you choose Title font, it will be equivalent to the font shown on the Title of every app, and hence as in different resolutions the this font differs, your text font will also automatically differ...

    hope this helps !
    Amit Kankani
    Nokia Developer Champion

Similar Threads

  1. draw a graph in the screen
    By wask in forum Symbian
    Replies: 1
    Last Post: 2008-05-14, 09:40
  2. Need help to draw on idle screen
    By gigglie in forum Symbian
    Replies: 1
    Last Post: 2008-04-08, 10:22
  3. Intercepting text draw events
    By spaceart in forum Symbian
    Replies: 0
    Last Post: 2003-02-11, 17:56
  4. How to draw a long text into multiline text??
    By titoliu in forum Symbian
    Replies: 1
    Last Post: 2002-08-09, 11:15
  5. Replies: 0
    Last Post: 2002-05-17, 12:09

Posting Permissions

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