You Are Here:

Community: Blogs

 

Konstantine Voytenko's Forum Nokia Blog

GUI application with the BitmapBuffer

Carbider | 04 July, 2008 13:34

    In the previous post we've developed the RBitmapBuffer buffer class that holds a bitmap buffer (sources are available at the end of this post).

    Now we'll use this class in a simple Symbian UI application.
It can be tied to the Symbian applications in a many ways but we'll see the one that goes for "Hello World" sample provided with Carbide.c++ IDE.

So start the Carbide.c++ (I use the version 1.3). Create new project (File -> New -> Symbian OS C++ Project). Select the "3-rd Feature Ed. GUI Application".

The IDE will create the project with a list of items. The file of interest for us is a "..AppView.cpp" because it defines the behavior of ..AppView class that has an access to the screen.
Besides that file we, of course, need some others that establish the connections inside the program logic.

The full list is:
Listing 1.
sources:
src/..AppUi.cpp
src/..AppView.cpp
src/BitmapBuffer.cpp
src/BufferRenderer.cpp

headers:
inc/..AppUi.h
inc/..AppView.h
inc/BitmapBuffer.h
inc/BufferRenderer.h

The "BitmapBuffer" and "BufferRenderer" sources are available at the end of this post.

The ".." is the name of your project.

First let's go to the "..AppView.h" file.
We will add a new property to the ..AppView class. This property would be:
CBufferRendereriBufferRenderer;
It would store the image buffer and will be able to render it (draw on it).
To simplify the code we will make iBufferRenderer as public, for anyone can access it and draw something on it.

We'll also add one new method to the ..AppView class to output the buffer.
That is shown below (the file: "..AppView.cpp"):

Listing 2.
/**
 * Function will draw the image
 *
 */
void ..AppView::DrawImage(CWindowGc& aGc) const
{
    CFbsBitmap* bitmap = iBufferRenderer->getBitmapBuffer()      ;
    TSize       size     ( bitmap->SizeInPixels() )              ;
   
    aGc.BitBlt( TPoint(0,0), bitmap, TRect( TPoint(0,0), size ) ); // Draw
   
} // function

Also, we will append some code to the ..AppView's constructor, destructor and Draw() methods:

Listing 3.
// ------------- Constructor

void ..AppView::ConstructL(const TRect& aRect)
{
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
   
    // - - - - - - -
    // Appended code :
   
    // Get system metrics
    TInt  color, gray         ;
    TRect screenSize  (Rect());
    TDisplayMode displayMode =
    CCoeEnv::Static()->WsSession().GetDefModeMaxNumColors( color, gray );
   
    // Main - instantiate the Buffer Renderer object
    iBufferRenderer          = CBufferRenderer::NewL(displayMode, screenSize);
   
} // function

// ------------- Destructor

..AppView::~CBBufferEx_AppView()
{
    // - - - - - - -
    // Appended code :
   
    // Dealocate the memory for the Buffer Renderer object
    delete iBufferRenderer;
   
} // function

// ------------- AppView's Draw() method

void ..AppView::Draw(const TRect& /*aRect*/) const
{
    CWindowGc& gc = SystemGc();
    TRect drawRect(Rect());
    gc.Clear(drawRect);
   
    // - - - - - - -
    // Appended code :

    // Put the buffer on the screen
    DrawImage(gc);
   
} // function

Now, let's draw the rectangle on the phone screen when the user selects the 'Message' button from the options menu.
To do that, we will go to the "..AppUi.cpp" file and append the HandleCommandL() method with the code below:

Listing 4.
void ..AppUi::HandleCommandL(TInt aCommand)
{
    switch (aCommand)
    {
       
        //...  ommited for clarity

        case ECommand1:
            {
            //... 
           
            // - - - - - - -
            // Appended code :
           
            // Force to draw the rectangle
            iAppView->iBufferRenderer->drawRect(TRect(10, 10, 100, 100));
            }
            break;
           
           
        //... 
       
    } // switch
      
} // function

Don't forget to include the (#include "BufferRenderer.h") BufferRenderer to the "..AppView.h" file.

You also need to include this list of libraries to your mmp file:
Listing 5.
    fbscli.lib
    bitgdi.lib
    ws32.lib

The sources of "BitmapBuffer" and "BufferRenderer" classes are available in this zip file: ..BitmapBufferClassExample..zip


end

RSSComments

You must login to post comments. Login
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia