Ejemplo n.º 1
0
    void SImageMaskWnd::MakeCacheApha(ISkinObj *pSkin)
    {
        SASSERT(m_bmpMask && m_bmpCache);
        CAutoRefPtr<IRenderTarget> pRTDst;
        GETRENDERFACTORY->CreateRenderTarget(&pRTDst,0,0);
        CAutoRefPtr<IRenderObj> pOldBmp;
        pRTDst->SelectObject(m_bmpCache,&pOldBmp);
        CRect rc(CPoint(0,0),m_bmpCache->Size());
        pSkin->Draw(pRTDst,&rc,0);
        pRTDst->SelectObject(pOldBmp);
        
        //从mask的指定channel中获得alpha通道
        LPBYTE pBitCache = (LPBYTE)m_bmpCache->LockPixelBits();
        LPBYTE pBitMask = (LPBYTE)m_bmpMask->LockPixelBits();
        LPBYTE pDst = pBitCache;
        LPBYTE pSrc = pBitMask + m_iMaskChannel;
        int nPixels = m_bmpCache->Width()*m_bmpCache->Height();
        for(int i=0;i<nPixels;i++)
        {
            BYTE byAlpha = *pSrc;
            pSrc += 4;

            *pDst++ = ((*pDst) * byAlpha)>>8;//做premutiply
            *pDst++ = ((*pDst) * byAlpha)>>8;//做premutiply
            *pDst++ = ((*pDst) * byAlpha)>>8;//做premutiply
            *pDst++ = byAlpha;
        }
        m_bmpCache->UnlockPixelBits(pBitCache);
        m_bmpMask->UnlockPixelBits(pBitMask);
    }
Ejemplo n.º 2
0
void SMenuODWnd::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
    if(lpMeasureItemStruct->CtlType != ODT_MENU) return;

    SMenuItemData *pdmmi=(SMenuItemData*)lpMeasureItemStruct->itemData;
    if(pdmmi)
    {
        //menu item
        lpMeasureItemStruct->itemHeight = m_nItemHei;
        lpMeasureItemStruct->itemWidth = m_szIcon.cx+m_nIconMargin*2;

        CAutoRefPtr<IRenderTarget> pRT;
        GETRENDERFACTORY->CreateRenderTarget(&pRT,0,0);
        CAutoRefPtr<IFont> oldFont;
        pRT->SelectObject(m_hFont,(IRenderObj**)&oldFont);
        SIZE szTxt;
        pRT->MeasureText(pdmmi->itemInfo.strText,pdmmi->itemInfo.strText.GetLength(),&szTxt);
        lpMeasureItemStruct->itemWidth += szTxt.cx+m_nTextMargin*2;
        pRT->SelectObject(oldFont);
    }
    else
    {
        // separator
        lpMeasureItemStruct->itemHeight = m_pSepSkin?m_pSepSkin->GetSkinSize().cy:3;
        lpMeasureItemStruct->itemWidth=0;
    }

}
Ejemplo n.º 3
0
void SQrCtrl::MakeCacheApha( ISkinObj *pSkin, IBitmap *_pBitCache, IBitmap *_pBitMask )
{
	CAutoRefPtr<IRenderTarget> pRTDst;
	GETRENDERFACTORY->CreateRenderTarget(&pRTDst, 0, 0);
	CAutoRefPtr<IRenderObj> pOldBmp;
	pRTDst->SelectObject(_pBitCache, &pOldBmp);
	CRect rc(CPoint(0, 0), _pBitCache->Size());
	pSkin->Draw(pRTDst, &rc, 0);
	CAutoRefPtr<IBitmap> bmp;
	GETRENDERFACTORY->CreateBitmap(&bmp);
	if (m_QrRect.IsRectEmpty())
	{
		bmp = _pBitMask;
	}
	else
	{
		bmp->Init(m_QrRect.Width(),	m_QrRect.Height());
		pRTDst->SelectObject(bmp, NULL);
		CRect rcSrc(CPoint(0, 0), _pBitMask->Size());
		rc = CRect(CPoint(0, 0), bmp->Size());
		pRTDst->DrawBitmapEx(rc, _pBitMask, rcSrc, MAKELONG(EM_STRETCH, m_fl));
		pRTDst->SelectObject(pOldBmp);
	}


	int nDesLinePixels = _pBitCache->Width();
	int nDesRowPixels = _pBitCache->Height();
	int nline = bmp->Height();
	int nRow = bmp->Width();
	if ((nDesRowPixels < nRow + m_QrRect.top) || (nDesLinePixels < nline + m_QrRect.left))
		return;
	LPDWORD pBitCache = (LPDWORD)_pBitCache->LockPixelBits();
	LPDWORD pBitMask = (LPDWORD)bmp->LockPixelBits();
	LPDWORD pDst = pBitCache;
	LPDWORD pSrc = pBitMask;
	LPDWORD pLine = pDst + m_QrRect.top * nDesLinePixels;
	for (int line = 0; line < nline; line++)
	{
		LPDWORD pLineData = pLine + m_QrRect.left;
		for (int row = 0; row < nRow; row++)
		{
			LPBYTE byAlpha = (LPBYTE)(pSrc + row);
			if (byAlpha[3] == 0)
			{
				LPDWORD pByteAlpha = (pLineData + row);
				*pByteAlpha =RGBA(0,0,0,0);
			}
		}
		pSrc += nRow;
		pLine += nDesLinePixels;
	}
	_pBitCache->UnlockPixelBits(pBitCache);
	bmp->UnlockPixelBits(pBitMask);
}
Ejemplo n.º 4
0
    RECT SCaret::Draw(IRenderTarget *pRT,int x, int y,BOOL bErase)
    {
        SWindow * pOwner = SWindowMgr::GetWindow(m_owner);
        SASSERT(pOwner);
        SASSERT(pOwner->IsFocusable());
        
        CAutoRefPtr<IRenderTarget> pRTCaret;
        GETRENDERFACTORY->CreateRenderTarget(&pRTCaret,0,0);
        pRTCaret->SelectObject(m_bmpCaret);

        CSize szCaret = m_bmpCaret->Size();
        CRect rcCaret(CPoint(x,y),szCaret);
        CRect rcWnd = pOwner->GetClientRect();
        SWindow *pWnd = pOwner->GetParent();
        while(pWnd)
        {
            CRect rcLimit = pWnd->GetClientRect();
            rcWnd = rcWnd & rcLimit;
            pWnd = pWnd->GetParent();
        }
        pOwner->GetContainer()->FrameToHost(rcWnd);
        CRect rcCaretShow = rcCaret & rcWnd;
        
        pRT->BitBlt(&rcCaretShow,pRTCaret,rcCaretShow.left - rcCaret.left,rcCaretShow.top - rcCaret.top,DSTINVERT);
        return rcCaretShow;
    }
Ejemplo n.º 5
0
void SMenuODWnd::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
    CRect rcItem=lpDrawItemStruct->rcItem;
    rcItem.MoveToXY(0,0);
    SMenuItemData *pdmmi=(SMenuItemData*)lpDrawItemStruct->itemData;

    HDC dc(lpDrawItemStruct->hDC);
    CAutoRefPtr<IRenderTarget> pRT;
    GETRENDERFACTORY->CreateRenderTarget(&pRT,rcItem.Width(),rcItem.Height());

    if(pdmmi)
    {
        MENUITEMINFO mii= {sizeof(MENUITEMINFO),MIIM_FTYPE,0};
        HMENU menuPopup=pdmmi->hMenu;
        GetMenuItemInfo(menuPopup,pdmmi->nID,FALSE,&mii);

        BOOL bDisabled = lpDrawItemStruct->itemState & ODS_GRAYED;
        BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
        BOOL bChecked = lpDrawItemStruct->itemState & ODS_CHECKED;
        BOOL bRadio = mii.fType&MFT_RADIOCHECK;
        m_pItemSkin->Draw(pRT,rcItem,bSelected?1:0);    //draw background

        //draw icon
        CRect rcIcon;
        rcIcon.left=rcItem.left+m_nIconMargin;
        rcIcon.right=rcIcon.left+m_szIcon.cx;
        rcIcon.top=rcItem.top+(rcItem.Height()-m_szIcon.cy)/2;
        rcIcon.bottom=rcIcon.top+m_szIcon.cy;
        if(bChecked)
        {
            if(m_pCheckSkin)
            {
                m_pCheckSkin->Draw(pRT,rcIcon,bRadio?1:0);
            }
        }
        else if(pdmmi->itemInfo.iIcon!=-1 && m_pIconSkin)
        {
            m_pIconSkin->Draw(pRT,rcIcon,pdmmi->itemInfo.iIcon);
        }
        rcItem.left=rcIcon.right+m_nIconMargin;

        //draw text
        CRect rcTxt=rcItem;
        rcTxt.DeflateRect(m_nTextMargin,0);

        COLORREF crOld=pRT->SetTextColor(bDisabled?m_crTxtGray:(bSelected?m_crTxtSel:m_crTxtNormal));


        CAutoRefPtr<IFont> oldFont;
        pRT->SelectObject(m_hFont,(IRenderObj**)&oldFont);
        pRT->DrawText(pdmmi->itemInfo.strText,pdmmi->itemInfo.strText.GetLength(),&rcTxt,DT_SINGLELINE|DT_VCENTER|DT_LEFT);
        pRT->SelectObject(oldFont);

        pRT->SetTextColor(crOld);

        if(bSelected && m_pItemSkin->GetStates()>2)
        {
            //draw select mask
            CRect rcItem=lpDrawItemStruct->rcItem;
            rcItem.MoveToXY(0,0);
            m_pItemSkin->Draw(pRT,rcItem,2);
        }
    }
    else  //if(strcmp("sep",pXmlItem->Value())==0)
    {
        m_pItemSkin->Draw(pRT,rcItem,0);    //draw back
        if(m_pIconSkin)
        {
            rcItem.left += m_pIconSkin->GetSkinSize().cx+m_nIconMargin*2;
        }

        if(m_pSepSkin)
            m_pSepSkin->Draw(pRT,&rcItem,0);
        else
        {
            CAutoRefPtr<IPen> pen1,pen2,oldPen;
            pRT->CreatePen(PS_SOLID,RGBA(196,196,196,255),1,&pen1);
            pRT->CreatePen(PS_SOLID,RGBA(255,255,255,255),1,&pen2);
            pRT->SelectObject(pen1,(IRenderObj**)&oldPen);
            POINT pts[2]={{rcItem.left,rcItem.top},{rcItem.right,rcItem.top}};
            pRT->DrawLines(pts,2);
            pRT->SelectObject(pen2);
            pts[0].y++,pts[1].y++;
            pRT->DrawLines(pts,2);
            pRT->SelectObject(oldPen);
        }
    }
    rcItem=lpDrawItemStruct->rcItem;
    
    HDC hmemdc=pRT->GetDC(0);
    BitBlt(dc,rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),hmemdc,0,0,SRCCOPY);
    pRT->ReleaseDC(hmemdc);
}