×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    52

    How to redraw text over bitmap

    Hello,

    I'm new to the Symbian graphics API and was wondering if someone can offer some insight to my problem. I have an application that loads a bitmap as the background and then displays text over the bitmap. The text is updated every 1-3 seconds and I'm currently redrawing the bitmap too. What I'd like to do is draw the bitmap once and only update the text.

    As you can guess my application flickers every time a redraw is done. This is because I clear the screen and display the bitmap/text frequently. I just want the text to update if possible. My draw method looks like:

    CWindowGc& gc = SystemGc();
    gc.Clear();
    TRect rect = Rect();
    gc.BitBlt(Rect().iTl,iBackground);
    gc.DrawRect(rect);

    _LIT(KFont, "SwissA");
    CFont* font;
    TFontSpec myFontSpec(KFont, 12);
    CGraphicsDevice* screenDevice = iCoeEnv->ScreenDevice();
    screenDevice->GetNearestFontInTwips(font,myFontSpec);
    gc.UseFont(font);

    gc.DrawText(*iText1, TPoint(134, 46));
    gc.DrawText(*iText2, TPoint(134, 70));
    gc.DrawText(*iText3, TPoint(93, 101));
    gc.DrawText(*iText4, TPoint(93, 125));
    gc.DiscardFont();

    Can anyone provide me with some suggestions on how to resolve this problem? Thanks in advance for any insight you can offer.

    Best Regards,
    Dennis

  2. #2
    Registered User
    Join Date
    May 2004
    Location
    Finland
    Posts
    14
    Have you tried a simple flag.

    in header file you put
    TBool iIsBackgroundDrawed;

    and set it false in default constructor.

    In ConstructL() you just call
    DrawNow(); //and
    iIsBackgroundDrawed = ETrue;

    In Draw- method you make an if- sentence

    CWindowGc& gc = SystemGc();
    if( !iIsBackgroundDrawed )
    {
    gc.Clear();
    TRect rect = Rect();
    gc.BitBlt(Rect().iTl,iBackground);
    gc.DrawRect(rect);
    }

    _LIT(KFont, "SwissA");
    CFont* font;
    TFontSpec myFontSpec(KFont, 12);
    CGraphicsDevice* screenDevice = iCoeEnv->ScreenDevice();
    screenDevice->GetNearestFontInTwips(font,myFontSpec);
    gc.UseFont(font);

    gc.DrawText(*iText1, TPoint(134, 46));
    gc.DrawText(*iText2, TPoint(134, 70));
    gc.DrawText(*iText3, TPoint(93, 101));
    gc.DrawText(*iText4, TPoint(93, 125));
    gc.DiscardFont();

    It might work or it will leave text area blank! Try it and tell what it did!

    Antti

  3. #3
    Nokia Developer Expert
    Join Date
    Apr 2003
    Location
    Finland
    Posts
    425
    Hello,

    That is a kind of architecture problem on the application. You should implement the Draw method so it only updates the part of application view which is needed to update.

    E.g. if there is 3 text objects and text 1 is changes you should not ask system to update whole screen, instead the part where text object 1 lies. This is not easy task but if you are patient you can do that.

    So define a class which contains member for the text and when you change that text it will calculate the rect what is needed to display that rect. Then ask framework to update only that part of view rect.

    Inside Draw method you should detect area of text1 is asked to draw and somethig like this is needed:
    Code:
    private:
        CFbsBitmap* iImageBitmap;
    <...>
    void CMyAboutControl::Draw(const TRect& aRect) const
    {
        CWindowGc& gc = SystemGc();
        // Test is text 1 is asked to draw...Intersects method from SDK
        if ( aRect.Intersects( text_object1->imageRect()  ) )
        {
            // define which part of area to re-draw
            imageRect.Intersection( aRect );
            // background image
            gc.UseBrushPattern( iImageBitmap );
            gc.SetPenStyle( CGraphicsContext::ENullPen );
            gc.SetBrushStyle( CGraphicsContext::EPatternedBrush );
            // Draw bitmap to the are where text lies
            gc.DrawRect( imageRect );
            // draw new text above bitmap
            gc.DrawText(... text_object1->Text());
            gc.DiscardBrushPattern();
        }
        // And so on all object throw...
    ...hope this helps but sure there is lot issues to be considered.

    Br V

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    52
    Thank you for the responses and I will test these shortly. I will post my results here and let you know how it goes!

    Thanks again,
    Dennis

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    52
    Antti,

    I tried your solution and it blanked out the screen with a white background and show the text. But the text didn't update, I'm calling for a screen refresh every three seconds. I'm going to see if I can try veskola's solution and I'll follow up with the results.

    Thanks,
    Dennis

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    9
    i have a problem with drawing text over picture.

Posting Permissions

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