sl@0: // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Demonstration handwriting class sl@0: // sl@0: // sl@0: sl@0: #include "HNDLODR.H" sl@0: sl@0: sl@0: /*RHandWritingAnim*/ sl@0: sl@0: TInt RHandWritingAnim::Construct(const RWsSprite& aDevice) sl@0: { sl@0: TPtrC8 des(NULL,0); sl@0: return RAnim::Construct(aDevice,0,des); sl@0: } sl@0: sl@0: void RHandWritingAnim::Activate() sl@0: { sl@0: Command(EHwOpActivate); sl@0: } sl@0: sl@0: void RHandWritingAnim::Deactivate() sl@0: { sl@0: Command(EHwOpDeactivate); sl@0: } sl@0: sl@0: TInt RHandWritingAnim::SpriteMaskChange(TBool aUsingSeparateMask) sl@0: { sl@0: TPckgBuf param; sl@0: param()=aUsingSeparateMask; sl@0: return CommandReply(EHwOpSpriteMask,param); sl@0: } sl@0: sl@0: void RHandWritingAnim::SetDrawData(const THandwritingDrawData& aDrawData) sl@0: { sl@0: TPckgBuf param; sl@0: param()=aDrawData; sl@0: Command(EHwOpSetDrawData,param); sl@0: } sl@0: sl@0: TInt RHandWritingAnim::GetLastGeneratedCharacter() sl@0: { sl@0: return CommandReply(EHwOpGetLastChar); sl@0: } sl@0: sl@0: sl@0: /*CHandWriting*/ sl@0: sl@0: CHandWriting::CHandWriting(RWsSession& aSession) sl@0: :iSession(aSession), iAnimDll(aSession), iAnim(iAnimDll), iSprite(aSession) sl@0: {} sl@0: sl@0: void CHandWriting::ConstructL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask) sl@0: // sl@0: //This function should be called with the correct screen size and sl@0: //the handle of any group window that will be around as long as the handwriting is required sl@0: // sl@0: { sl@0: CreateSpriteL(aScreenSize,aGroup,aUseSeparateMask); sl@0: LoadDllL(); sl@0: } sl@0: sl@0: void CHandWriting::CreateSpriteL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask) sl@0: { sl@0: TInt color,gray; //Unused variables sl@0: TDisplayMode mode=iSession.GetDefModeMaxNumColors(color,gray); sl@0: iBitmap=new(ELeave) CFbsBitmap(); sl@0: User::LeaveIfError(iBitmap->Create(aScreenSize,mode)); sl@0: TSpriteMember member; sl@0: member.iMaskBitmap=iBitmap; sl@0: if (aUseSeparateMask) sl@0: { sl@0: iMaskBitmap=new(ELeave) CFbsBitmap(); sl@0: User::LeaveIfError(iMaskBitmap->Create(aScreenSize,mode)); sl@0: member.iMaskBitmap=iMaskBitmap; sl@0: } sl@0: User::LeaveIfError(iSprite.Construct(aGroup,TPoint(),ESpriteNoChildClip|ESpriteNoShadows)); sl@0: FillInSpriteMember(member); sl@0: iSprite.AppendMember(member); sl@0: } sl@0: sl@0: void CHandWriting::LoadDllL() sl@0: { sl@0: _LIT(DllName,"HandAnim.DLL"); sl@0: TInt err=iAnimDll.Load(DllName); sl@0: if (err==KErrNone) sl@0: err=iAnim.Construct(iSprite); sl@0: if (err==KErrNone) sl@0: { sl@0: iAnim.Activate(); sl@0: iActive=ETrue; sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: CHandWriting::~CHandWriting() sl@0: { sl@0: delete iBitmap; sl@0: delete iMaskBitmap; sl@0: iSprite.Close(); sl@0: iAnimDll.Close(); sl@0: } sl@0: sl@0: void CHandWriting::SetMaskL(TBool aUseSeparateMask) sl@0: { sl@0: if ((iMaskBitmap!=NULL)==aUseSeparateMask) sl@0: return; sl@0: TSpriteMember member; sl@0: FillInSpriteMember(member); sl@0: if (aUseSeparateMask) sl@0: { sl@0: iMaskBitmap=new(ELeave) CFbsBitmap(); sl@0: member.iMaskBitmap=iMaskBitmap; sl@0: } sl@0: else sl@0: { sl@0: member.iMaskBitmap=iBitmap; sl@0: } sl@0: if (iActive) sl@0: iAnim.Deactivate(); sl@0: iSprite.UpdateMember(1,member); sl@0: TInt err=iAnim.SpriteMaskChange(aUseSeparateMask); sl@0: if (err<0) sl@0: { sl@0: if (aUseSeparateMask) sl@0: { sl@0: delete iMaskBitmap; sl@0: iMaskBitmap=NULL; sl@0: member.iMaskBitmap=iBitmap; sl@0: } sl@0: else sl@0: { sl@0: member.iMaskBitmap=iMaskBitmap; sl@0: } sl@0: iSprite.UpdateMember(1,member); sl@0: } sl@0: else if (!aUseSeparateMask) sl@0: { sl@0: delete iMaskBitmap; sl@0: iMaskBitmap=NULL; sl@0: } sl@0: if (iActive) sl@0: iAnim.Activate(); sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: void CHandWriting::ToggleStatus() sl@0: { sl@0: if (iActive) sl@0: iAnim.Deactivate(); sl@0: else sl@0: iAnim.Activate(); sl@0: iActive=!iActive; sl@0: } sl@0: sl@0: void CHandWriting::FillInSpriteMember(TSpriteMember& aMember) sl@0: { sl@0: aMember.iBitmap=iBitmap; sl@0: aMember.iInvertMask=ETrue; //Must be inverted sl@0: aMember.iDrawMode=CGraphicsContext::EDrawModePEN; //Ignored when using mask sl@0: aMember.iOffset=TPoint(); //Must be 0,0 sl@0: aMember.iInterval=0; //Not used as only one TSpriteMember in sprite sl@0: }