Beispiel #1
0
/**
 * Load svg element.
 */
CGulIcon* CFuiTheme::SvgIconL( TInt aElementId )
{
	CFbsBitmap* a = NULL;
	CFbsBitmap* b = NULL;
	
	TFileName svgFile;
	SvgFile( svgFile );
		
	AknIconUtils::CreateIconL( a, b, svgFile, aElementId, aElementId );
		
	CGulIcon* c = CGulIcon::NewL( a, b );
	
	AknIconUtils::PreserveIconData( c->Bitmap() );
	AknIconUtils::PreserveIconData( c->Mask() );
	
	TSize contentSize;
	AknIconUtils::GetContentDimensions( c->Bitmap(), contentSize );
	
	AknIconUtils::SetSize( c->Bitmap(), contentSize );
	AknIconUtils::SetSize( c->Mask(), contentSize );
	
	AknIconUtils::DestroyIconData( c->Bitmap() );
	AknIconUtils::DestroyIconData( c->Mask() );
	
	iElements.Append( c );
	
	return c;
}
static void DrawIconL(CWindowGc& aGc, CGulIcon& aIcon, const TJuikLayoutItem& aL, TBool aDoCenter=ETrue) 
{
	CALLSTACKITEMSTATIC_N(_CL(""), _CL("DrawIconL"));
	CFbsBitmap* bmp = aIcon.Bitmap();
	CFbsBitmap* mask = aIcon.Mask();
	
	aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
	// center 
	TInt bmpW = bmp->SizeInPixels().iWidth;
	TInt areaW = aL.Size().iWidth;
	
	TInt dx = 0;
	TInt dy = 0;
	if ( aDoCenter && bmpW < areaW )
		{
			dx = (areaW - bmpW) / 2;
		}


	TPoint tl = aL.TopLeft();
	tl += TPoint(dx,dy);
	TRect r(TPoint(0,0), bmp->SizeInPixels());
 	if ( mask )
 		{
 			aGc.BitBltMasked( tl, bmp, r, mask, ETrue);
 		}
 	else
 		{
			aGc.BitBlt( tl, bmp, r);
  		}
}
EXPORT_C void JuikIcons::SetIconSizeL( CGulIcon& aIcon, const TSize& aSize, TScaleMode aMode)
{
	CALLSTACKITEMSTATIC_N(_CL("JuikIcons"), _CL("SetIconSizeL"));
#ifdef __SCALABLEUI_VARIANT__
	
	AknIconUtils::SetSize( aIcon.Bitmap(), aSize, aMode);
	// no need to set mask size - it's automatically set
	
#else // not  __SCALABLEUI_VARIANT__
	
	// do nothing, non-svg icons have correct size when loaded

#endif //   __SCALABLEUI_VARIANT__
}
void CUiLoftAppView::InsertMyPictureL(TInt aPos)
	{
	CMyPicture* picture;
	// Create a CPicture derived class which will draw our image, depending this Size
	CGulIcon* icon = iIcons->At(iIcons->Count()-1);
	CFbsBitmap* bmp = icon->Bitmap();
	CFbsBitmap* mask = icon->Mask();
	picture = new( ELeave )CMyPicture(TSize(400, 400),*bmp, mask);
						
	CleanupStack::PushL(picture);
	// Prepare the Picture header, which will be instered into the Richtext
	TPictureHeader header;
	header.iPicture =TSwizzle<CPicture>(picture);
	iEditor->RichText()->InsertL( aPos,header); 
	CleanupStack::Pop(); // picture - Richtext take the ownership 
	}
Beispiel #5
0
/**
 * Load svg element and scale it to given size. 
 */
 CGulIcon* CFuiTheme::SvgIconL( TInt aElementId, const TSize& aSize )
{
	CFbsBitmap* a = NULL;
	CFbsBitmap* b = NULL;
	
	TFileName svgFile;
	SvgFile( svgFile );
		
	AknIconUtils::CreateIconL( a, b, svgFile, aElementId, aElementId );
	
	CGulIcon* c = CGulIcon::NewL( a, b );
	
	AknIconUtils::SetSize( c->Bitmap(), aSize, EAspectRatioNotPreserved );
	AknIconUtils::SetSize( c->Mask(), aSize, EAspectRatioNotPreserved );
	
	iElements.Append( c );
	
	return c;
}
void CCustomControlList::Draw(CBitmapContext& gc)
	{
	TInt x = iDrawPoint.iX + iDisplayPoint.iX;
	TInt x2 = iDrawPoint.iX + iDisplayPoint.iX + 16;
	TInt y;
	TInt dy = iDrawPoint.iY;
	for (TInt i=0; i<iList->Count(); i++)
		{
		if (dy < 0)
			{
			dy += iRowHeight;
			continue;
			}
		if (dy >= iDisplaySize.iHeight)
			{
			break;
			}
		y = dy + iDisplayPoint.iY;
		pListItemStruct item = (*iList)[i];
		CGulIcon* icon = (*iIcons)[item->iIconIndex];
		CFbsBitmap* bitmap = icon->Bitmap();
		gc.BitBlt(TPoint(x, y), bitmap);

		gc.UseFont(iFont);
		if (i!=iSelectIndex)
			{
			gc.SetPenColor(iTextColor);
			//			HBufC* text = item->iShowName;
			//			gc.DrawText(*(item->iShowName), TPoint(x2, y));
			}
		else
			{
			gc.SetPenColor(iSelectTextColor);
			//			HBufC* text = item->iShowName;
			//			gc.DrawText(*(item->iShowName), TPoint(x2, y));
			}
		y += iFontHeight;
		gc.DrawText(*(item->iShowName), TPoint(x2, y));
		gc.DiscardFont();

		dy += iRowHeight;
		}
	}
Beispiel #7
0
void CSpriteSet::RenderSprite(TInt aSpriteType, TInternalSpriteResizeMode aInternalSpriteResizeMode, const TSize& aSourceSize, const TSize& aSpriteSize)
	{
	const TInt sourceWidth = aSourceSize.iWidth;
	const TInt sourceHeight = aSourceSize.iHeight;
	const TInt spriteWidth = aSpriteSize.iWidth;
	const TInt spriteHeight = aSpriteSize.iHeight;
	const TInt numOfHorizAddedLines = spriteHeight-sourceHeight;
	const TInt numOfVertAddedLines = spriteWidth-sourceWidth;
	const TPoint posZeroZero(0,0);	// cached for repeated use
	CGulIcon* spriteSetMember = iSourceMembers[aSpriteType];
	CFbsBitmap* bitmapToUse = spriteSetMember->Bitmap();
	CFbsBitmap* maskToUse = spriteSetMember->Mask();
	TRect fromRect;
	TPoint toPoint;

	switch(aInternalSpriteResizeMode)
		{
	case EHSameVSame:
		{
		fromRect.SetRect(0,0,sourceWidth,sourceHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		break;
		}
	case EHSameVShrink:
		{
		const TInt halfSpriteHeight = spriteHeight/2;
		fromRect.SetRect(0,0,spriteWidth,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(0,sourceHeight - (halfSpriteHeight) - (spriteHeight%2),sourceWidth,sourceHeight);
		toPoint.SetXY(0,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		break;
		}
	case EHSameVStretch:
		{
		const TInt halfSourceHeight = sourceHeight/2;
		fromRect.SetRect(0,0,sourceWidth,halfSourceHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(0,halfSourceHeight,sourceWidth,sourceHeight);
		toPoint.SetXY(0,spriteHeight-(halfSourceHeight)-(sourceHeight%2));
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		for(TInt i = 0; i < numOfHorizAddedLines;i++)
			{
			fromRect.SetRect(0,halfSourceHeight,sourceWidth,(halfSourceHeight)+1);
			toPoint.SetXY(0,(halfSourceHeight)+i);
			iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
			iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
			}
		break;
		}
	case EHShrinkVSame:
		{
		const TInt halfSpriteWidth = spriteWidth/2;
		fromRect.SetRect(0,0,halfSpriteWidth,spriteHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSpriteWidth) - (spriteWidth%2),0,sourceWidth,sourceHeight);
		toPoint.SetXY(halfSpriteWidth,0);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		break;
		}
	case EHShrinkVShrink:
		{
		const TInt halfSpriteWidth = spriteWidth/2;
		const TInt halfSpriteHeight = spriteHeight/2;
		const TInt spriteHeightModTwo = spriteHeight%2;
		const TInt spriteWidthModTwo = spriteWidth%2;
		fromRect.SetRect(0,0,halfSpriteWidth,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSpriteWidth) - (spriteWidthModTwo),0,sourceWidth,halfSpriteHeight);
		toPoint.SetXY(halfSpriteWidth,0);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(0,sourceHeight - (halfSpriteHeight) - (spriteHeightModTwo),halfSpriteWidth,sourceHeight);
		toPoint.SetXY(0,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSpriteWidth) - (spriteWidthModTwo),sourceHeight - (halfSpriteHeight) - (spriteHeightModTwo),sourceWidth,sourceHeight);
		toPoint.SetXY(halfSpriteWidth,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		break;
		}
	case EHShrinkVStretch:
		{
		const TInt halfSourceHeight = sourceHeight/2;
		const TInt halfSpriteWidth = spriteWidth/2;
		const TInt sourceHeightModTwo = sourceHeight%2;
		const TInt spriteWidthModTwo = spriteWidth%2;
		fromRect.SetRect(0,0,halfSpriteWidth,halfSourceHeight);	
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSpriteWidth) - (spriteWidthModTwo),0,sourceWidth,halfSourceHeight);
		toPoint.SetXY(halfSpriteWidth,0);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(0,sourceHeight - (halfSourceHeight) - (sourceHeightModTwo),halfSpriteWidth,sourceHeight);
		toPoint.SetXY(0,spriteHeight - (halfSourceHeight) - (sourceHeightModTwo));
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSpriteWidth) - (spriteWidthModTwo),sourceHeight - (halfSourceHeight) - (sourceHeightModTwo),sourceWidth,sourceHeight);
		toPoint.SetXY(halfSpriteWidth,spriteHeight - (halfSourceHeight) - (sourceHeightModTwo));
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		for(TInt j = 0; j < numOfHorizAddedLines;j++)
			{
			fromRect.SetRect(0,spriteHeight - (halfSourceHeight) - (sourceHeightModTwo),spriteWidth,spriteHeight - (halfSourceHeight) - (sourceHeightModTwo)+1);
			toPoint.SetXY(0,(halfSourceHeight)+j);
			iMainFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			iMaskFbsBitGc->BitBlt(toPoint,iTargetMaskBitmap,fromRect);
			}
		break;
		}
	case EHStretchVSame:
		{
		const TInt halfSourceWidth = sourceWidth/2;
		fromRect.SetRect(0,0,halfSourceWidth,sourceHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(halfSourceWidth,0,sourceWidth,sourceHeight);
		toPoint.SetXY(spriteWidth-(halfSourceWidth)-(sourceWidth%2),0);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		for(TInt i = 0; i < numOfVertAddedLines;i++)
			{
			fromRect.SetRect(halfSourceWidth,0,(halfSourceWidth)+1,sourceHeight);
			toPoint.SetXY((halfSourceWidth)+i,0);
			iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
			iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
			}
		break;
		}
	case EHStretchVShrink:
		{
		const TInt halfSourceWidth = sourceWidth/2;
		const TInt halfSpriteHeight = spriteHeight/2;
		const TInt sourceWidthModTwo = sourceWidth%2;
		const TInt spriteHeightModTwo = spriteHeight%2;
		fromRect.SetRect(0,0,halfSourceWidth,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSourceWidth) - (sourceWidthModTwo),0,sourceWidth,halfSpriteHeight);
		toPoint.SetXY(spriteWidth - (halfSourceWidth) - (sourceWidthModTwo),0);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(0,sourceHeight - (halfSpriteHeight) - (spriteHeightModTwo),halfSourceWidth,sourceHeight);
		toPoint.SetXY(0,halfSpriteHeight);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(sourceWidth - (halfSourceWidth) - (sourceWidthModTwo),sourceHeight - (halfSpriteHeight) - (spriteHeightModTwo),sourceWidth,sourceHeight);
		toPoint.SetXY(spriteWidth - (halfSourceWidth) - (sourceWidthModTwo),halfSpriteHeight);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		for(TInt j = 0; j < numOfVertAddedLines;j++)
			{
			fromRect.SetRect(spriteWidth - (halfSourceWidth) - (sourceWidthModTwo),0,spriteWidth - (halfSourceWidth) - (sourceWidthModTwo)+1,spriteHeight);
			toPoint.SetXY((halfSourceWidth)+j,0);
			iMainFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			iMaskFbsBitGc->BitBlt(toPoint,iTargetMaskBitmap,fromRect);
			}
		break;
		}
	case EHStretchVStretch:
		{
		const TInt halfSourceWidth = sourceWidth/2;
		const TInt halfSourceHeight = sourceHeight/2;
		const TInt sourceWidthModTwo = sourceWidth%2;
		const TInt sourceHeightModTwo = sourceHeight%2;
		fromRect.SetRect(0,0,halfSourceWidth,halfSourceHeight);
		iMaskFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		iMainFbsBitGc->BitBlt(posZeroZero,maskToUse,fromRect);
		fromRect.SetRect(0,halfSourceHeight,halfSourceWidth,sourceHeight);
		toPoint.SetXY(0,spriteHeight-(halfSourceHeight)-(sourceHeightModTwo));
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		iMainFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(halfSourceWidth,0,sourceWidth,halfSourceHeight);
		toPoint.SetXY(spriteWidth-(halfSourceWidth)-(sourceWidthModTwo),0);
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		iMainFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		fromRect.SetRect(halfSourceWidth,halfSourceHeight,sourceWidth,sourceHeight);
		toPoint.SetXY(spriteWidth-(halfSourceWidth)-(sourceWidthModTwo),spriteHeight-(halfSourceHeight)-(sourceHeightModTwo));
		iMaskFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		iMainFbsBitGc->BitBlt(toPoint,maskToUse,fromRect);
		for(TInt h = 0; h < numOfVertAddedLines;h++)
			{
			fromRect.SetRect(spriteWidth-(halfSourceWidth)-(sourceWidthModTwo),0,spriteWidth-(halfSourceWidth)-(sourceWidthModTwo)+1,spriteHeight);
			toPoint.SetXY((halfSourceWidth)+h,0);
			iMainFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			iMaskFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			}
		for(TInt m = 0; m < numOfHorizAddedLines;m++)
			{
			fromRect.SetRect(0,spriteHeight-(halfSourceHeight)-(sourceHeightModTwo),spriteWidth,spriteHeight-(halfSourceHeight)-(sourceHeightModTwo)+1);
			toPoint.SetXY(0,(halfSourceHeight)+m);
			iMaskFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			}
		fromRect.SetRect(0,0,halfSourceWidth,halfSourceHeight);
		iMainFbsBitGc->BitBlt(posZeroZero,bitmapToUse,fromRect);
		fromRect.SetRect(0,halfSourceHeight,halfSourceWidth,sourceHeight);
		toPoint.SetXY(0,spriteHeight-(halfSourceHeight)-(sourceHeightModTwo));
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		fromRect.SetRect(halfSourceWidth,0,sourceWidth,halfSourceHeight);
		toPoint.SetXY(spriteWidth-(halfSourceWidth)-(sourceWidthModTwo),0);
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		fromRect.SetRect(halfSourceWidth,halfSourceHeight,sourceWidth,sourceHeight);
		toPoint.SetXY(spriteWidth-(halfSourceWidth)-(sourceWidthModTwo),spriteHeight-(halfSourceHeight)-(sourceHeightModTwo));
		iMainFbsBitGc->BitBlt(toPoint,bitmapToUse,fromRect);
		for(TInt j = 0; j < numOfVertAddedLines;j++)
			{
			fromRect.SetRect(spriteWidth-(halfSourceWidth)-(sourceWidthModTwo),0,spriteWidth-(halfSourceWidth)-(sourceWidthModTwo)+1,spriteHeight);
			toPoint.SetXY((halfSourceWidth)+j,0);
			iMainFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			}
		for(TInt i = 0; i < numOfHorizAddedLines;i++)
			{
			fromRect.SetRect(0,spriteHeight-(halfSourceHeight)-(sourceHeightModTwo),spriteWidth,spriteHeight-(halfSourceHeight)-(sourceHeightModTwo)+1);
			toPoint.SetXY(0,(halfSourceHeight)+i);
			iMainFbsBitGc->BitBlt(toPoint,iTargetBitmap,fromRect);
			}
		break;
		}
	default:
		Panic(EEgulPanicInvalidInternalSpriteResizeMode);
		break;
		}
	}
// ---------------------------------------------------------
// CDisconnectDlgDialog::PreLayoutDynInitL
// ---------------------------------------------------------
//
void CDisconnectDlgDialog::PreLayoutDynInitL()
    {
    CLOG_ENTERFN("CDisconnectDlgDialog::PreLayoutDynInitL");    
    
    CAknListQueryDialog::PreLayoutDynInitL();
    
    STATIC_CAST( CEikServAppUi*, 
                CCoeEnv::Static()->AppUi() )->SuppressAppSwitching( ETrue );
    
    CConnectionCArray* connArray = iConnModel->GetConnArray();

    // items: application and IAP names
    CDesCArrayFlat* items = new( ELeave )CDesCArrayFlat( connArray->Count() );
    CleanupStack::PushL( items );
    // icons: application icons
    CArrayPtr< CGulIcon >* icons = new( ELeave )CAknIconArray( 
                                                        connArray->Count() );
    CleanupStack::PushL( icons );

    CGulIcon* iconTemp = NULL;
    CGulIcon* icon = NULL;

    TInt count = connArray->Count();
    CLOG_WRITEF(_L( "count: %d" ), count );     

    // Get the info of every connection and initialize the list of dialog
    for( TInt i = 0; i < count; i++ )
        {
        CConnectionInfo* info = connArray->At( i );

        TBool useSharedIcon = EFalse;
        // Application and IAP name
        HBufC* listItem = HBufC::NewLC( KListItemTextBuf );
        TPtrC iap = info->GetIapNameL();
        
        TPtrC app = info->GetAppNameL( useSharedIcon ); 

        // Application icon
        iconTemp = info->GetAppIconL( useSharedIcon );
        icon = CGulIcon::NewL();
        icon->SetBitmapsOwnedExternally( ETrue );
        icon->SetBitmap( iconTemp->Bitmap() );
        icon->SetMask( iconTemp->Mask() );

        icons->AppendL( icon );

        listItem->Des().Format( KFormat, i, &iap, &app );
        items->AppendL( listItem->Des() );

        CleanupStack::PopAndDestroy( listItem ); // listItem
        }

    // set new item list
    SetItemTextArray( items );
    // set icon list
    SetIconArrayL( icons );
    // we don't have to take care of delete items
    SetOwnershipType( ELbmOwnsItemArray );

    CleanupStack::Pop( icons );
    CleanupStack::Pop( items );
    
    iExpiryTimer = CExpiryTimer::NewL( *this );
    iExpiryTimer->Start();

    CLOG_LEAVEFN("CDisconnectDlgDialog::PreLayoutDynInitL");
    }
Beispiel #9
0
/*
 * Landmark objects will make use of an SVG file for rendering (demo purposes)
 */
void CLMXObject::ConstructL()
{
    _LIT(KIconFile, "\\resource\\apps\\Landmarks_0x2002E1AF.mif");

    CGulIcon* icon = CreateIconL(KIconFile, EMbmLandmarks_0x2002e1afIcon, EMbmLandmarks_0x2002e1afIcon_mask);
    CleanupStack::PushL(icon);

    CFbsBitmap* bitmap = icon->Bitmap();    // Ownership NOT transferred
    CFbsBitmap* mask   = icon->Mask();      // Ownership NOT transferred

    // Always expect 16M bitmap to make conversion to GL_RGBA easier 
    if (bitmap->DisplayMode() != EColor16M)
    {
        bitmap = new(ELeave) CFbsBitmap;
        CleanupStack::PushL(bitmap);

        User::LeaveIfError(bitmap->Create(icon->Bitmap()->SizeInPixels(), EColor16M));

        CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
        CleanupStack::PushL(bitmapDevice);

        CFbsBitGc* bitmapContext = 0;
        User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
        CleanupStack::PushL(bitmapContext);

        bitmapContext->BitBlt(TPoint(0, 0), icon->Bitmap());

        CleanupStack::PopAndDestroy(2, bitmapDevice);

        icon->SetBitmap(bitmap);    // Ownership transferred

        CleanupStack::Pop(bitmap);
    }

    // Always expect 256 mask to make conversion to GL_RGBA easier 
    if (mask->DisplayMode() != EGray256)
    {
        mask = new(ELeave) CFbsBitmap;
        CleanupStack::PushL(mask);

        User::LeaveIfError(mask->Create(icon->Mask()->SizeInPixels(), EGray256));

        CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(mask);
        CleanupStack::PushL(bitmapDevice);

        CFbsBitGc* bitmapContext = 0;
        User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
        CleanupStack::PushL(bitmapContext);

        bitmapContext->BitBlt(TPoint(0, 0), icon->Mask());

        CleanupStack::PopAndDestroy(2, bitmapDevice);

        icon->SetMask(mask);    // Ownership transferred

        CleanupStack::Pop(mask);
    }

    // Now bitmap and mask point to either original or converted bitmaps, 
    // and ownership belongs to icon

    const TSize bitmapSize = bitmap->SizeInPixels();

    // sizeof(TUint32) == sizeof(RGBA)
    const TInt dataSize = bitmapSize.iWidth * bitmapSize.iHeight * sizeof(TUint32);
    TUint8* data = new(ELeave) TUint8[dataSize];

    // Perform copy and conversion from BGR(A) to RGB(A)
    bitmap->LockHeap();
    mask->LockHeap();

    // TODO: Alpha component removed, as it seems to be corrupted from
    // subsequent reads from SVG file

    TUint8* rgb = reinterpret_cast<TUint8*>(bitmap->DataAddress());
//    TUint8* alpha = reinterpret_cast<TUint8*>(mask->DataAddress());

    for(TInt i = 0, j = 0; i < dataSize; i += 4, j += 3)
    {
        data[i + 0] = rgb[j + 2];
        data[i + 1] = rgb[j + 1];
        data[i + 2] = rgb[j + 0];
        data[i + 3] = 0xc0; //alpha[i / 4];
    }

    // Generate OpenGL texture
    ::glGenTextures(1, &iTextureId); 
    ::glBindTexture(GL_TEXTURE_2D, iTextureId);

    ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmapSize.iWidth, bitmapSize.iHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

    mask->UnlockHeap();
    bitmap->UnlockHeap();

    delete data;

    CleanupStack::PopAndDestroy(icon);
}