os/graphics/windowing/windowserver/test/HNDLODR.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Demonstration handwriting class
    15 // 
    16 //
    17 
    18 #include "HNDLODR.H"
    19 
    20 
    21 /*RHandWritingAnim*/
    22 
    23 TInt RHandWritingAnim::Construct(const RWsSprite& aDevice)
    24 	{
    25 	TPtrC8 des(NULL,0);
    26 	return RAnim::Construct(aDevice,0,des);
    27 	}
    28 
    29 void RHandWritingAnim::Activate()
    30 	{
    31 	Command(EHwOpActivate);
    32 	}
    33 
    34 void RHandWritingAnim::Deactivate()
    35 	{
    36 	Command(EHwOpDeactivate);
    37 	}
    38 
    39 TInt RHandWritingAnim::SpriteMaskChange(TBool aUsingSeparateMask)
    40 	{
    41 	TPckgBuf<TBool> param;
    42 	param()=aUsingSeparateMask;
    43 	return CommandReply(EHwOpSpriteMask,param);
    44 	}
    45 
    46 void RHandWritingAnim::SetDrawData(const THandwritingDrawData& aDrawData)
    47 	{
    48 	TPckgBuf<THandwritingDrawData> param;
    49 	param()=aDrawData;
    50 	Command(EHwOpSetDrawData,param);
    51 	}
    52 
    53 TInt RHandWritingAnim::GetLastGeneratedCharacter()
    54 	{
    55 	return CommandReply(EHwOpGetLastChar);
    56 	}
    57 
    58 
    59 /*CHandWriting*/
    60 
    61 CHandWriting::CHandWriting(RWsSession& aSession)
    62 	:iSession(aSession), iAnimDll(aSession), iAnim(iAnimDll), iSprite(aSession)
    63 	{}
    64 
    65 void CHandWriting::ConstructL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask)
    66 	//
    67 	//This function should be called with the correct screen size and 
    68 	//the handle of any group window that will be around as long as the handwriting is required
    69 	//
    70 	{
    71 	CreateSpriteL(aScreenSize,aGroup,aUseSeparateMask);
    72 	LoadDllL();
    73 	}
    74 
    75 void CHandWriting::CreateSpriteL(TSize aScreenSize,RWindowGroup& aGroup,TBool aUseSeparateMask)
    76 	{
    77 	TInt color,gray;		//Unused variables
    78 	TDisplayMode mode=iSession.GetDefModeMaxNumColors(color,gray);
    79 	iBitmap=new(ELeave) CFbsBitmap();
    80 	User::LeaveIfError(iBitmap->Create(aScreenSize,mode));
    81 	TSpriteMember member;
    82 	member.iMaskBitmap=iBitmap;
    83 	if (aUseSeparateMask)
    84 		{
    85 		iMaskBitmap=new(ELeave) CFbsBitmap();
    86 		User::LeaveIfError(iMaskBitmap->Create(aScreenSize,mode));
    87 		member.iMaskBitmap=iMaskBitmap;
    88 		}
    89 	User::LeaveIfError(iSprite.Construct(aGroup,TPoint(),ESpriteNoChildClip|ESpriteNoShadows));
    90 	FillInSpriteMember(member);
    91 	iSprite.AppendMember(member);
    92 	}
    93 
    94 void CHandWriting::LoadDllL()
    95 	{
    96 	_LIT(DllName,"HandAnim.DLL");
    97 	TInt err=iAnimDll.Load(DllName);
    98 	if (err==KErrNone)
    99 		err=iAnim.Construct(iSprite);
   100 	if (err==KErrNone)
   101 		{
   102 		iAnim.Activate();
   103 		iActive=ETrue;
   104 		}
   105 	User::LeaveIfError(err);
   106 	}
   107 
   108 CHandWriting::~CHandWriting()
   109 	{
   110 	delete iBitmap;
   111 	delete iMaskBitmap;
   112 	iSprite.Close();
   113 	iAnimDll.Close();
   114 	}
   115 
   116 void CHandWriting::SetMaskL(TBool aUseSeparateMask)
   117 	{
   118 	if ((iMaskBitmap!=NULL)==aUseSeparateMask)
   119 		return;
   120 	TSpriteMember member;
   121 	FillInSpriteMember(member);
   122 	if (aUseSeparateMask)
   123 		{
   124 		iMaskBitmap=new(ELeave) CFbsBitmap();
   125 		member.iMaskBitmap=iMaskBitmap;
   126 		}
   127 	else
   128 		{
   129 		member.iMaskBitmap=iBitmap;
   130 		}
   131 	if (iActive)
   132 		iAnim.Deactivate();
   133 	iSprite.UpdateMember(1,member);
   134 	TInt err=iAnim.SpriteMaskChange(aUseSeparateMask);
   135 	if (err<0)
   136 		{
   137 		if (aUseSeparateMask)
   138 			{
   139 			delete iMaskBitmap;
   140 			iMaskBitmap=NULL;
   141 			member.iMaskBitmap=iBitmap;
   142 			}
   143 		else
   144 			{
   145 			member.iMaskBitmap=iMaskBitmap;
   146 			}
   147 		iSprite.UpdateMember(1,member);
   148 		}
   149 	else if (!aUseSeparateMask)
   150 		{
   151 		delete iMaskBitmap;
   152 		iMaskBitmap=NULL;
   153 		}
   154 	if (iActive)
   155 		iAnim.Activate();
   156 	User::LeaveIfError(err);
   157 	}
   158 
   159 void CHandWriting::ToggleStatus()
   160 	{
   161 	if (iActive)
   162 		iAnim.Deactivate();
   163 	else
   164 		iAnim.Activate();
   165 	iActive=!iActive;
   166 	}
   167 
   168 void CHandWriting::FillInSpriteMember(TSpriteMember& aMember)
   169 	{
   170 	aMember.iBitmap=iBitmap;
   171 	aMember.iInvertMask=ETrue;		//Must be inverted
   172 	aMember.iDrawMode=CGraphicsContext::EDrawModePEN;		//Ignored when using mask
   173 	aMember.iOffset=TPoint();		//Must be 0,0
   174 	aMember.iInterval=0;		//Not used as only one TSpriteMember in sprite
   175 	}