⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scalablescreendrawingengine.cpp

📁 一个界面绘图的例子
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        }
    else
        {
        bitmapBackground = iBackground;
        }

    if(iUseScrolling)
        {
        TSize size = bitmapBackground->SizeInPixels();
        aBc->BitBlt(TPoint(0, 0), bitmapBackground,
            TRect(size.iWidth - iScrollOffset, 0, size.iWidth, size.iHeight));

        aBc->BitBlt(TPoint(iScrollOffset, 0), bitmapBackground,
            TRect(0, 0, size.iWidth - iScrollOffset, size.iHeight));
        }
    else
        {
        aBc->BitBlt(TPoint(0, 0), bitmapBackground);
        }

    // Snowflakes
    if(!iHideSnow)
        {
        for (TInt i=0;i</*1*/ NUMBER_OF_FLAKES;i++)
            {
            TPoint loc = TPoint(iSnowflakes[i].iPos.iX,iSnowflakes[i].iPos.iY);

            // These CustomBitBlit calls draw always to back buffer even if double buffer
            // is disabled, so when disabled the flakes won't show.
            if (iSnowflakes[i].iSize /*1*/)
                {
                // Uncomment this and comment out the next CustomBitBlit() call
                // if GDI blitting is needed.
                /*aBc->BitBltMasked (loc,
                                   iSnowflakeBig,
                                   iSnowflakeBig->SizeInPixels(),
                                   iSnowflakeBig_mask,
                                   ETrue);*/
                CustomBitBlit(loc, iVirtualScreen, iSnowflakeBig, iSnowflakeBig_mask);
                }
            else
                {
                // Uncomment this and comment out the next CustomBitBlit() call
                // if GDI blitting is needed.
                /*aBc->BitBltMasked (loc,
                                   iSnowflakeSmall,
                                   iSnowflakeSmall->SizeInPixels(),
                                   iSnowflakeSmall_mask,
                                   ETrue);*/
                CustomBitBlit(loc, iVirtualScreen, iSnowflakeSmall, iSnowflakeSmall_mask);
                }
            }
        }

    // Scrolling stars at the top
    if(!iHideStars)
        {
        TSize size = iIconSelector2->SizeInPixels();
        for(TInt c = 1; c < iPixTwipsRot.iPixelSize.iWidth / size.iWidth; c++)
            {
            aBc->BitBltMasked(TPoint(c * size.iWidth - iScrollOffsetStars, 0), iIconSelector2, size,
                                   iIconSelector2_mask, ETrue);
            }
        }

    // Draw menu

    // The menu is draws using fonts, which is not so fast.
    // Press '#' to switch menu off and see how the frame rate
    // increases a few units.
    if(!iHideMenu)
        {
        const CAknLayoutFont* font = AknLayoutUtils::LayoutFontFromId(EAknLogicalFontPrimaryFont);
        aBc->UseFont((CFont*) font);
        aBc->SetPenColor(TRgb(0x00EE00));
        CFbsFont* f = (CFbsFont*) font;
        TInt textWidth = f->TextWidthInPixels(KMenuText);
        TInt height = f->HeightInPixels();
        TInt yPos = (iPixTwipsRot.iPixelSize.iHeight - (KNumberOfMenuLines - 1) * height) / 2;
        TInt xPos = (iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2;
        aBc->DrawText(KMenuText, TPoint(xPos, yPos));

        // Selector top position
        TSize size = iIconSelector->SizeInPixels();
        TInt yPosSelector = yPos;
        TInt xPosSelector = xPos - size.iWidth;

        // Menu choices
        aBc->SetPenColor(TRgb(0x33ffCC));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleDoubleBuffer);
        aBc->DrawText(KMenuTextToggleDoubleBuffer, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleIcons);
        aBc->DrawText(KMenuTextToggleIcons, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleAnchor);
        aBc->DrawText(KMenuTextToggleAnchor, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleBackground);
        aBc->DrawText(KMenuTextToggleBackground, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleScroll);
        aBc->DrawText(KMenuTextToggleScroll, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleOrientation);
        aBc->DrawText(KMenuTextToggleOrientation, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        yPos = yPos + height;
        textWidth = f->TextWidthInPixels(KMenuTextToggleSnow);
        aBc->DrawText(KMenuTextToggleSnow, TPoint((iPixTwipsRot.iPixelSize.iWidth - textWidth) / 2, yPos));

        aBc->DiscardFont();

        // Menu selector
        if(iUseBitmapIcons)
            {
            aBc->BitBltMasked(TPoint(xPosSelector, yPosSelector + (iIxSelection * height)),
                                       iIconSelector,
                                       iIconSelector->SizeInPixels(),
                                       iIconSelector_mask,
                                       ETrue);
            }
        else
            {
            aBc->BitBltMasked(TPoint(xPosSelector, yPosSelector + (iIxSelection * height)),
                                       iIconSelector2,
                                       iIconSelector2->SizeInPixels(),
                                       iIconSelector2_mask,
                                       ETrue);

            aBc->BitBltMasked(TPoint(iPixTwipsRot.iPixelSize.iWidth - xPosSelector -
                iIconSelector2->SizeInPixels().iWidth, yPosSelector + (iIxSelection * height)),
                                       iIconSelector2,
                                       iIconSelector2->SizeInPixels(),
                                       iIconSelector2_mask,
                                       ETrue);
            }
        }

    // Soft-button icons
    if(!iHideCBA)
        {
        
        TSize size = iIconExit->SizeInPixels();

#ifdef EKA2        
        // Landscape, buttons right
		if(AknLayoutUtils::CbaLocation() == AknLayoutUtils::EAknCbaLocationRight)
        {
          if(iUseAnchors) 
            {
            // Icons' position is relative to screen size, and their position is limited to the
            // screen edges if there is not enough room.
            TPoint posMenu;
            TPoint posExit;

            posMenu.iY = Min(iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6),
                            iPixTwipsRot.iPixelSize.iHeight - size.iHeight);
            posMenu.iX = iPixTwipsRot.iPixelSize.iWidth - (iPixTwipsRot.iPixelSize.iWidth / 6);

            posExit.iY = Max(iPixTwipsRot.iPixelSize.iHeight / 6 - size.iHeight, 0);
            posExit.iX = iPixTwipsRot.iPixelSize.iWidth - (iPixTwipsRot.iPixelSize.iWidth / 6);

            aBc->BitBlt(posExit, iIconExit);
            aBc->BitBlt(posMenu, iIconMenu);
            }
          else
            {
            // Icon position is fixed to another object (the screen borders in this case)
            aBc->BitBlt(TPoint( iPixTwipsRot.iPixelSize.iWidth - size.iWidth,
            	 0), iIconExit);
            aBc->BitBlt(TPoint(iPixTwipsRot.iPixelSize.iWidth - size.iWidth,
            		 iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconMenu);
            }           
        }
        
        // Landscape, buttons left
		if(AknLayoutUtils::CbaLocation() == AknLayoutUtils::EAknCbaLocationLeft)
        {
          if(iUseAnchors)
            {
            // Icons' position is relative to screen size, and their position is limited to the
            // screen edges if there is not enough room.
            TPoint posMenu;
            TPoint posExit;

            posExit.iY = Min(iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6),
                            iPixTwipsRot.iPixelSize.iHeight - size.iHeight);
            posExit.iX = Max(iPixTwipsRot.iPixelSize.iWidth / 6 - size.iWidth, 0);

            posMenu.iY = Max(iPixTwipsRot.iPixelSize.iHeight / 6 - size.iHeight, 0);
            posMenu.iX = posExit.iX;

            aBc->BitBlt(posExit, iIconExit);
            aBc->BitBlt(posMenu, iIconMenu);
            }
          else
            {
            // Icon position is fixed to another object (the screen borders in this case)
            aBc->BitBlt(TPoint(0,iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconExit);
            aBc->BitBlt(TPoint(0,0), iIconMenu);
            }           
        }
        
		// Portrait
        if(AknLayoutUtils::CbaLocation() == AknLayoutUtils::EAknCbaLocationBottom)
        {
          if(iUseAnchors)
            {
            // Icons' position is relative to screen size, and their position is limited to the
            // screen edges if there is not enough room.
            TPoint posMenu;
            TPoint posExit;

            posExit.iX = Min(iPixTwipsRot.iPixelSize.iWidth - (iPixTwipsRot.iPixelSize.iWidth / 3),
                            iPixTwipsRot.iPixelSize.iWidth - size.iWidth);
            posExit.iY = iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6);

            posMenu.iX = Max(iPixTwipsRot.iPixelSize.iWidth / 3 - size.iWidth, 0);
            posMenu.iY = iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6);

            aBc->BitBlt(posExit, iIconExit);
            aBc->BitBlt(posMenu, iIconMenu);
            }
        else
            {
            // Icon position is fixed to another object (the screen borders in this case)
            
            aBc->BitBlt(TPoint(iPixTwipsRot.iPixelSize.iWidth - size.iWidth,
                iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconExit);
            aBc->BitBlt(TPoint(0, iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconMenu);
            }
          
        }
#else //not EKA2, CbaLocation not available
		//Portrait, buttons at screen bottom

		
		if( iPixTwipsRot.iPixelSize.iWidth < iPixTwipsRot.iPixelSize.iHeight)
			{
			if(iUseAnchors)
				{
				// Icons' position is relative to screen size, and their position is limited to the
				// screen edges if there is not enough room.
				TPoint posMenu;
				TPoint posExit;

				posExit.iX = Min(iPixTwipsRot.iPixelSize.iWidth - (iPixTwipsRot.iPixelSize.iWidth / 3),
                            iPixTwipsRot.iPixelSize.iWidth - size.iWidth);
				posExit.iY = iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6);

				posMenu.iX = Max(iPixTwipsRot.iPixelSize.iWidth / 3 - size.iWidth, 0);
				posMenu.iY = iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6);

				aBc->BitBlt(posExit, iIconExit);
				aBc->BitBlt(posMenu, iIconMenu);
				}
			else
				{
				// Icon position is fixed to another object (the screen borders in this case)
            
				aBc->BitBlt(TPoint(iPixTwipsRot.iPixelSize.iWidth - size.iWidth,
                iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconExit);
				aBc->BitBlt(TPoint(0, iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconMenu);
				}
			}
		//Landscape, buttons on right	
		if( iPixTwipsRot.iPixelSize.iWidth > iPixTwipsRot.iPixelSize.iHeight)
			{
			if(iUseAnchors)
            {
            // Icons' position is relative to screen size, and their position is limited to the
            // screen edges if there is not enough room.
            TPoint posMenu;
            TPoint posExit;

            posMenu.iY = Min(iPixTwipsRot.iPixelSize.iHeight - (iPixTwipsRot.iPixelSize.iHeight / 6),
                            iPixTwipsRot.iPixelSize.iHeight - size.iHeight);
            posMenu.iX = Max(iPixTwipsRot.iPixelSize.iWidth / 6 - size.iWidth, 0);

            posExit.iY = Max(iPixTwipsRot.iPixelSize.iHeight / 6 - size.iHeight, 0);
            posExit.iX = posMenu.iX;

            aBc->BitBlt(posExit, iIconExit);
            aBc->BitBlt(posMenu, iIconMenu);
            }
          else
            {
            // Icon position is fixed to another object (the screen borders in this case)
            aBc->BitBlt(TPoint(0,iPixTwipsRot.iPixelSize.iHeight - size.iHeight), iIconMenu);
            aBc->BitBlt(TPoint(0,0), iIconExit);
            }
			}
#endif //EKA2 
        }
        


    // Draw double buffer indicator and FPS
    const CAknLayoutFont* font = AknLayoutUtils::LayoutFontFromId(EAknLogicalFontPrimarySmallFont);
    aBc->UseFont((CFont*) font);
    aBc->SetPenColor(TRgb(0x0000FF));

    aBc->DrawText(iFpsText, TPoint(0, ((CFbsFont*)font)->HeightInPixels()));
    aBc->DiscardFont();
    }

void CScalableScreenDrawingEngine::DrawScreenDoubleBuffer () const
    {
    // Draw to backbuffer
    DrawScreen(iBC);

    // Copy backbuffer to screen
    // BitBlt performs color-depth conversion so we don't need to worry about it.
    iGc->BitBlt(TPoint(0, 0), iVirtualScreen);
    }

// Custom blitting routine for copying a bitmap to a position in another bitmap, with optional mask
void CScalableScreenDrawingEngine::CustomBitBlit(TPoint aDestPoint, CFbsBitmap* aDest, CFbsBitmap* aSource, CFbsBitmap* aMask) const
    {
    __ASSERT_ALWAYS(aDest->DisplayMode() == aSource->DisplayMode(), User::Panic(_L("BMP MODE"), KErrCorrupt));

#ifdef EKA2
    aSource->LockHeap();
    aDest->LockHeap();
#endif//EKA2

    TUint8* pDataLineMask = NULL;
    TInt strideMask = 0;

    if(aMask)
        {
        __ASSERT_ALWAYS(aMask->DisplayMode() == EGray2, User::Panic(_L("MASK MODE"), KErrCorrupt));
        aMask->LockHeap();
        pDataLineMask = (TUint8*) aMask->DataAddress();
        strideMask = CFbsBitmap::ScanLineLength(aMask->SizeInPixels().iWidth, aMask->DisplayMode());
        }

    TUint8* pDataLineSource = (TUint8*) aSource->DataAddress();
    TUint8* pDataLineDest = (TUint8*) aDest->DataAddress();

    TSize sizeSource = aSource->SizeInPixels();
    TSize sizeDest = aDest->SizeInPixels();

    // Width in bytes
    TInt strideSource = CFbsBitmap::ScanLineLength(sizeSource.iWidth, aSource->DisplayMode());
    TInt strideDest = CFbsBitmap::ScanLineLength(sizeDest.iWidth, aDest->DisplayMode());

    // Bytes per pixel in target bitmap
    TInt bpp = strideDest / aDest->SizeInPixels().iWidth;

    // Calculate dimensions of the copied area, we know that pixel-depth is 16-bits and mask is 1-bit
    TInt lines;     // The number of lines we are going to copy
    TInt pixels;    // The number of pixels per line
    TInt maskPixelXInit;

    if(aDestPoint.iY >= 0)
        {
        pDataLineDest = pDataLineDest + (bpp * aDestPoint.iX) + (aDestPoint.iY * strideDest);
        lines = Min(sizeSource.iHeight, sizeDest.iHeight - aDestPoint.iY);
        }
    else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -