×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    35

    DrawText with variables

    Wondering if there is a way, or rather, what the best way is to draw text with variables. The DrawText() function from CGraphicsContext doesn't seem to to allow for specifiers like printf for example. Let's say i wanted to have a variable where the specifier is in the code below, would i have to draw it next to it, using a different function?

    _LIT(KExampleText,"Number: %d\n");
    iBmpGc->DrawText(KExampleText,pos);

    cheers

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: DrawText with variables

    i suggest using a buffer to prepare the text to be displayed 1st.

  3. #3
    Super Contributor
    Join Date
    May 2004
    Posts
    2,265

    Re: DrawText with variables

    Quote Originally Posted by Sufo View Post
    Wondering if there is a way, or rather, what the best way is to draw text with variables. The DrawText() function from CGraphicsContext doesn't seem to to allow for specifiers like printf for example. Let's say i wanted to have a variable where the specifier is in the code below, would i have to draw it next to it, using a different function?

    _LIT(KExampleText,"Number: %d\n");
    iBmpGc->DrawText(KExampleText,pos);

    cheers
    Hi,

    Code:
    TInt value = 3;
    TBuf<32> buf; // it is not good to use a magic number here
    buf.Format(KExampleText, value); // "Number: 3\n"
    iBmpGc->DrawText(KExampleText, pos);
    Regards

    Ziteng Chen

  4. #4
    Registered User
    Join Date
    Aug 2012
    Posts
    1

    Re: DrawText with variables

    Try this code:

    TBuf<32> buf;
    for (i=0;i<7;i++) {
    box = TRect(32,i*32,64,(i+1)*32);
    gc.DrawRoundRect(box,TSize(8,8));
    buf.Format(_L("%i"),i+1);
    gc.DrawText(buf,box,24,CGraphicsContext::ECenter,0);
    }

    It works fine!

Similar Threads

  1. Debugging in emulator - IDE has greyed out variables, functions
    By mratnam in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 3
    Last Post: 2009-06-12, 05:25
  2. Problems With Variables
    By kev_Makaveli in forum Mobile Java General
    Replies: 1
    Last Post: 2009-04-27, 21:46
  3. C++ Symbols class(), class()->,class. ????
    By PACALA_BA in forum Symbian C++
    Replies: 7
    Last Post: 2008-09-15, 20:57
  4. global variables and GCCE
    By tmfelser in forum Symbian C++
    Replies: 2
    Last Post: 2007-06-12, 10:37
  5. Set variables on first visit
    By Nokia_Archive in forum Browsing and Mark-ups
    Replies: 2
    Last Post: 2002-05-14, 20:50

Posting Permissions

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