Building custom widgets with the Zinzala SDK - page 11

Because several button states may have changed, we simply redraw them all:

// render all the buttons Render(kButtonsCount); } }

As you have noticed, this method does not check the logic of state changes. The derived class or whoever else called this method, is responsible for this check.

If you would like to see the complete source code of the cDConsoleView class, here's the header and the C++ file.

4. Using cMyConsoleView

In order to test the console class we just created, we are going to derive it and implement the button pressed callbacks. Then, we will assemble a simple test application.

Derivation

Here's the declaration of the class cMyConsoleView:

class cMyConsoleView : public cDConsoleView { public: static cMyConsoleView *NewL(cDSkin &aSkin); void Reset(); protected: void PlayPressed(tBool aActive); void PausePressed(tBool aActive); void StopPressed(tBool aActive); void FwdPressed(tBool aActive); void BwdPressed(tBool aActive); protected: cMyConsoleView(); };

No surprise here. The class will implement the callback for each button of the console.

The method NewL() needs to be re-implemented, even though it is already in the base class:

cMyConsoleView::cMyConsoleView() : cDConsoleView() { } cMyConsoleView *cMyConsoleView::NewL(cDSkin &aSkin) { cMyConsoleView *lView = new cMyConsoleView(); cMyConsoleView::VerifyLC(lView); lView->ConstructL(aSkin); sCleanupStack::PopL(lView); return lView; }

The implementation of NewL() is very close to the one we have in the base class. In fact, such methods are always very similar, since their purpose is to create a new object and construct it. The method NewL() from the base class is not really necessary because it is very unlikely that someone will want to use that class without deriving it, but you never know ... :)

I have added the method Reset() to the class. Its purpose is to reset the console to its stopped state:

void cMyConsoleView::Reset() { SetState(eStopped); }

Our implementation of the button callbacks that will be presented, is as simple as it can get. Real world implementations will likely be a bit more complex, although they will perform the same basic actions as here, such as changing the console state:

void cMyConsoleView::PlayPressed(tBool aActive) { if(aActive) SetState(ePlaying); } void cMyConsoleView::PausePressed(tBool aActive) { if(aActive) { if(GetState() != ePaused) SetState(ePaused); else SetState(ePlaying); } } void cMyConsoleView::StopPressed(tBool aActive) { if(aActive) SetState(eStopped); } void cMyConsoleView::FwdPressed(tBool aActive) { if(aActive) { if(GetState() != eForward) SetState(eForward); else SetState(ePlaying); } } void cMyConsoleView::BwdPressed(tBool aActive) { if(aActive) { if(GetState() != eBackward) SetState(eBackward); else SetState(ePlaying); } }

If you would like to see the complete source code of the cMyConsoleView class, here's the header and the C++ file.

Window and Application

Now that we have implemented the console class and specialized it, we can move on to the window and application. We will also have a look at the main of the test program.

cDWindow

Here's the window declaration from DWindow.h:

class cDWindow : public cWindow { public: static cDWindow *NewL(cSettings *aSettings,cDSkin &aSkin); virtual ~cDWindow(); protected: void Ready(); bool CloseRequested(); protected: cDWindow(cSettings *aSettings); void ConstructL(cDSkin &aSkin); private: cSettings* iSettings; cMyConsoleView* iConsole; };

The cSettings class provides access to the application specific settings, which will be saved and restored each time the application runs. We will save in it the position of the window on screen. This is not a requirement for any window or application with the Zinzala SDK, but rather a personal preference. I prefer that my window always appears at the last place I left it.

Print version

All content © 2004-2007, hexaZen - Vancouver BC, Canada