Tuesday, October 20, 2009

Periodic task without using Active Objects

Sometimes you may want to call a function or do some task in regular interval without extending the class from CActive (i.e. You may want to show a informationNote on map - just like google maps does ;-)) . In that Situation it would be appropriate to a CPeriodic Object. Usage is trivial -
In the header file add:
CPeriodic* iTimer;

Use two functions which should look like following

/*Use this function whenever you have to start the time*/
void StartTimerL(TInt aStart, TInt aInterval)
{
if(iTimer)
{
delete iTimer;
iTimer = NULL;
}
iTimer = CPeriodic::NewL(EPriorityLow);
iTimer->Start(aStart, aInterval, TCallBack(TimerCallback, this));
}

/*This function will be called after the specified interval*/
TInt TimerCallback(TAny* aThis)
{
// Do whatever you have to do locally or you may call the following function
static_cast<>(aThis)->GlobalNoteProcessTimerEvent();
return 0;
}

/*Use this function to stop the timer*/
void CancelTimer()
{
iTimer->Cancel();
}

Thats it!!

Thursday, October 8, 2009

Transparent Animated GIF

I was trying to show an animated GIF over the maps as a blip to indicate user's position on the map. But I could not show a gif with transparent background. The gif background was shown to be white although the gif uimage had a transparent background. Then I changed a few lines of the tutorial and then it worked. The lines I have changed is as follows :

void CGifAnimatorContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
if(iIsVisible)
{
if(iGif_Reader)
{
if(iGif_Reader->Bitmap() && iGif_Reader->BitmapImg() && iGif_Reader->BitmapMsk())
{
if(iGif_Reader->Bitmap()->Handle() && iGif_Reader->BitmapImg()->Handle() && iGif_Reader->BitmapMsk()->Handle())
{
TSize gifSize = TSize(iGif_Reader->Bitmap()->SizeInPixels());
TSize screenSize = TSize(aRect.Size());
TRect tempRect = TRect(TPoint((screenSize.iWidth - gifSize.iWidth)/2 ,(screenSize.iHeight - gifSize.iHeight)/2),gifSize);
gc.DrawBitmapMasked(tempRect,iGif_Reader->BitmapImg(),
TRect(0, 0, iGif_Reader->BitmapImg()->SizeInPixels().iWidth, iGif_Reader->BitmapImg()->SizeInPixels().iHeight),
iGif_Reader->BitmapMsk(), EFalse);
//gc.DrawBitmapMasked
}
}
}
}

}

Just replace the original function with mine.