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