os/graphics/windowing/windowserver/test/tlib/TLSPRITE.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1996-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 // Base classes used for building window server test code
    15 // 
    16 //
    17 
    18 #include <e32std.h>
    19 #include <w32std.h>
    20 #include <e32svr.h>
    21 #include "testbase.h"
    22 
    23 EXPORT_C TSpriteCreateParams::TSpriteCreateParams(TSize aSize,TPoint aOffset,CTSpriteBase::TSpriteDrawFunction aDrawFunc,
    24 								TAny *aDrawFuncParam,TBool aMask,CGraphicsContext::TDrawMode aDrawMode) :
    25 	iSize(aSize),
    26 	iOffset(aOffset),
    27 	iDrawFunc(aDrawFunc),
    28 	iDrawFuncParam(aDrawFuncParam),
    29 	iMask(aMask),
    30 	iDrawMode(aDrawMode),
    31 	iInterval(0)
    32 	{}
    33 
    34 EXPORT_C TSpriteCreateParams::TSpriteCreateParams() :
    35 	iDrawFunc(NULL),
    36 	iDrawMode(CGraphicsContext::EDrawModePEN),
    37 	iInterval(0)
    38 	{}
    39 
    40 void CTSpriteBase::CreateBitmapL(CFbsBitmap *&aBitmap, CFbsBitmapDevice *&aBitmapDevice, TSpriteCreateParams *aParams, TBool aDoMask)
    41 	{
    42 	if (aBitmap==NULL)
    43 		{
    44 		aBitmap=new(ELeave) CFbsBitmap();
    45 		User::LeaveIfError(aBitmap->Create(aParams->iSize,EGray4));
    46 		}
    47 	aBitmapDevice=CFbsBitmapDevice::NewL(aBitmap);
    48 	CFbsBitGc *gc=CFbsBitGc::NewL();
    49 	gc->Activate(aBitmapDevice);
    50 	aParams->iDrawFunc(gc,0,aParams->iSize,aDoMask,aParams->iDrawFuncParam);
    51 	delete gc;
    52 	}
    53 
    54 EXPORT_C void CTSpriteBase::RedrawL(CFbsBitmap *&aBitmap, CFbsBitmap *&aMaskBitmap, TSpriteCreateParams *aParams)
    55 	{
    56 	CFbsBitmapDevice *bitmapDevice=NULL;
    57 	TRAPD(err,CreateBitmapL(aBitmap,bitmapDevice,aParams,EFalse));
    58 	if (err==KErrNone)
    59 		{
    60 		delete bitmapDevice;
    61 		bitmapDevice=NULL;
    62 		if (aMaskBitmap)
    63 			{
    64 			TRAP(err,CreateBitmapL(aMaskBitmap,bitmapDevice,aParams,ETrue));
    65 			delete bitmapDevice;
    66 			}
    67 		SpriteBase().UpdateMember(0);
    68 		}
    69 	User::LeaveIfError(err);
    70 	}
    71 
    72 EXPORT_C void CTSpriteBase::UpdateL(TInt aIndex, TSpriteCreateParams *aParams)
    73 	{
    74 	CFbsBitmap *bitmap=NULL;
    75 	CFbsBitmapDevice *bitmapDevice=NULL;
    76 	TRAPD(err,CreateBitmapL(bitmap,bitmapDevice,aParams,EFalse));
    77 	if (err==KErrNone)
    78 		{
    79 		delete bitmapDevice;
    80 		bitmapDevice=NULL;
    81 		CFbsBitmap *mask=NULL;
    82 		if (aParams->iMask)
    83 			TRAP(err,CreateBitmapL(mask,bitmapDevice,aParams,ETrue));
    84 		if (err==KErrNone)
    85 			{
    86 			TSpriteMember sprite;
    87 			sprite.iBitmap=bitmap;
    88 			sprite.iMaskBitmap=mask;
    89 			sprite.iInvertMask=EFalse;
    90 			sprite.iDrawMode=aParams->iDrawMode;
    91 			sprite.iInterval=aParams->iInterval;
    92 			sprite.iOffset=aParams->iOffset;
    93 			err=SpriteBase().UpdateMember(aIndex,sprite);
    94 			}
    95 		delete mask;
    96 		}
    97 	delete bitmap;
    98 	delete bitmapDevice;
    99 	User::LeaveIfError(err);
   100 	}
   101 
   102 EXPORT_C CTSprite::CTSprite(RWsSession &aWs) : iSprite(aWs)
   103 	{
   104 	}
   105 
   106 EXPORT_C CTSprite::~CTSprite()
   107 	{
   108 	iSprite.Close();
   109 	}
   110 
   111 EXPORT_C RWsSpriteBase &CTSprite::SpriteBase()
   112 	{
   113 	return(iSprite);
   114 	}
   115 
   116 EXPORT_C RWsSprite &CTSprite::Sprite()
   117 	{
   118 	return(iSprite);
   119 	}
   120 
   121 EXPORT_C void CTSprite::ConstructL(RWindowTreeNode &aWindow, const TPoint &aPos, TInt aCount, TSpriteCreateParams *aParams, TInt aFlags)
   122 	{
   123 	User::LeaveIfError(iSprite.Construct(aWindow,aPos,aFlags));
   124 	for(TInt index=0;index<aCount;index++,aParams++)
   125 		{
   126 		CFbsBitmap *bitmap=NULL;
   127 		CFbsBitmap *mask=NULL;
   128 		CFbsBitmapDevice *bitmapDevice=NULL;
   129 		TRAPD(err,CreateBitmapL(bitmap,bitmapDevice,aParams,EFalse));
   130 		if (err==KErrNone)
   131 			{
   132 			delete bitmapDevice;
   133 			bitmapDevice=NULL;
   134 			if (aParams->iMask)
   135 				TRAP(err,CreateBitmapL(mask,bitmapDevice,aParams,ETrue));
   136 			if (err==KErrNone)
   137 				{
   138 				TSpriteMember sprite;
   139 				sprite.iBitmap=bitmap;
   140 				sprite.iMaskBitmap=mask;
   141 				sprite.iInvertMask=EFalse;
   142 				sprite.iDrawMode=aParams->iDrawMode;
   143 				sprite.iOffset=aParams->iOffset;
   144 				sprite.iInterval=aParams->iInterval;
   145 				err=iSprite.AppendMember(sprite);
   146 				}
   147 			}
   148 		delete mask;
   149 		delete bitmap;
   150 		delete bitmapDevice;
   151 		User::LeaveIfError(err);
   152 		}
   153 	User::LeaveIfError(iSprite.Activate());
   154 	}
   155 
   156 EXPORT_C CTPointerCursor::CTPointerCursor(RWsSession &aWs) : iCursor(aWs)
   157 	{
   158 	}
   159 
   160 EXPORT_C CTPointerCursor::~CTPointerCursor()
   161 	{
   162 	iCursor.Close();
   163 	}
   164 
   165 EXPORT_C RWsSpriteBase &CTPointerCursor::SpriteBase()
   166 	{
   167 	return(iCursor);
   168 	}
   169 
   170 EXPORT_C RWsPointerCursor &CTPointerCursor::PointerCursor()
   171 	{
   172 	return(iCursor);
   173 	}
   174 
   175 EXPORT_C void CTPointerCursor::ConstructL(TInt aFlags)
   176 	{
   177 	User::LeaveIfError(iCursor.Construct(aFlags));
   178 	TSpriteMember sprite;
   179 	sprite.iBitmap=NULL;
   180 	User::LeaveIfError(iCursor.AppendMember(sprite));
   181 	}
   182 
   183 EXPORT_C void CTPointerCursor::ConstructL(TInt aCount, TSpriteCreateParams *aParams, TInt aFlags)
   184 	{
   185 	CFbsBitmap *bitmap=NULL;
   186 	CFbsBitmap *mask=NULL;
   187 	TRAPD(err,ConstructL(aCount, aParams, aFlags, bitmap, mask));
   188 	delete bitmap;
   189 	delete mask;
   190 	User::LeaveIfError(err);
   191 	}
   192 
   193 EXPORT_C void CTPointerCursor::ConstructL(TInt aCount, TSpriteCreateParams *aParams, TInt aFlags, CFbsBitmap *&aBitmap, CFbsBitmap *&aMaskBitmap)
   194 	{
   195 	User::LeaveIfError(iCursor.Construct(aFlags));
   196 	for(TInt index=0;index<aCount;index++,aParams++)
   197 		{
   198 		CFbsBitmapDevice *bitmapDevice=NULL;
   199 		TRAPD(err,CreateBitmapL(aBitmap,bitmapDevice,aParams,EFalse));
   200 		if (err==KErrNone)
   201 			{
   202 			delete bitmapDevice;
   203 			bitmapDevice=NULL;
   204 			if (aParams->iMask)
   205 				TRAP(err,CreateBitmapL(aMaskBitmap,bitmapDevice,aParams,ETrue));
   206 			if (err==KErrNone)
   207 				{
   208 				TSpriteMember sprite;
   209 				sprite.iBitmap=aBitmap;
   210 				sprite.iMaskBitmap=aMaskBitmap;
   211 				sprite.iInvertMask=EFalse;
   212 				sprite.iDrawMode=aParams->iDrawMode;
   213 				sprite.iInterval=aParams->iInterval;
   214 				sprite.iOffset=aParams->iOffset;
   215 				err=iCursor.AppendMember(sprite);
   216 				}
   217 			}
   218 		delete bitmapDevice;
   219 		bitmapDevice=NULL;
   220 		User::LeaveIfError(err);
   221 		}
   222 	User::LeaveIfError(iCursor.Activate());
   223 	}