예제 #1
0
void CPeerLink::BlockRead( bool bBlock )
{
    if (bBlock && (GetHandleMask() & READ_MASK))
    {
        RemoveHandleMask(READ_MASK);
        return;
    }

    if (!bBlock && !(GetHandleMask() & READ_MASK))
    {
        SetHandleMask(READ_MASK);
    }
}
예제 #2
0
int CRectTracker::HitTestHandles(CPoint point) const
{
	CRect rect;
	UINT mask = GetHandleMask();

	// see if hit anywhere inside the tracker
	GetTrueRect(&rect);
	if (!rect.PtInRect(point))
		return hitNothing;  // totally missed

	// see if we hit a handle
	for (int i = 0; i < 8; ++i)
	{
		if (mask & (1<<i))
		{
			GetHandleRect((TrackerHit)i, &rect);
			if (rect.PtInRect(point))
				return (TrackerHit)i;
		}
	}

	// last of all, check for non-hit outside of object, between resize handles
	if ((m_nStyle & hatchedBorder) == 0)
	{
		CRect rect = m_rect;
		rect.NormalizeRect();
		if ((m_nStyle & dottedLine|solidLine) != 0)
			rect.InflateRect(+1, +1);
		if (!rect.PtInRect(point))
			return hitNothing;  // must have been between resize handles
	}
	return hitMiddle;   // no handle hit, but hit object (or object border)
}
예제 #3
0
void CPeerLink::BlockWrite( bool bBlock )
{
    if (!bBlock)
    {
        if (m_strSendBuffer.size() > 0 && !m_bCanWrite)
        {
            if (!(GetHandleMask() & WRITE_MASK))
            {
                SetHandleMask(WRITE_MASK);
            }
        }
        return;
    }

    if (bBlock && (GetHandleMask() & WRITE_MASK))
    {
        RemoveHandleMask(WRITE_MASK);
    }
}
예제 #4
0
void LeoRectTracker::Draw(CDC* pDC) 
{

	CPen penBrown(PS_SOLID,1, RGB(192,110,0));
	CPen penGreen(PS_SOLID,2, RGB(0,192,0));
	CPen* pOldPen;
	// draw lines    // 边框颜色
	if ((m_nStyle & (dottedLine|solidLine)) != 0)
	{
		if (m_nStyle & dottedLine)
		{

			pOldPen = pDC->SelectObject(&penGreen);

		}
		else
		{
			pOldPen = pDC->SelectObject(&penBrown);
		}
		CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
		pDC->Rectangle(&m_rect);

		//画中心点
		SIZE size = {2,2};
		CRect centerRect(m_rect.CenterPoint(), size);
		pDC->FillSolidRect(centerRect,RGB(255,125,0));
	}



	// draw resize handles    // 八个黑角的颜色
	if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
	{
		UINT mask = GetHandleMask();
		CRect rect;
		for (int i = 0; i < 8; ++i)
		{
			if (mask & (1<<i))
			{
				GetHandleRect((TrackerHit)i, &rect);
				pDC->FillSolidRect(rect, RGB(125,125,0));    // RGB(0, 0, 0));
			}
		}
	}
}
예제 #5
0
void CRectTracker::Draw(CDC* pDC) const
{
	// set initial DC state
	VERIFY(pDC->SaveDC() != 0);
	pDC->SetMapMode(MM_TEXT);
	pDC->SetViewportOrg(0, 0);
	pDC->SetWindowOrg(0, 0);

	// get normalized rectangle
	CRect rect = m_rect;
	rect.NormalizeRect();

	CPen* pOldPen = NULL;
	CBrush* pOldBrush = NULL;
	CGdiObject* pTemp;
	int nOldROP;

	// draw lines
	if ((m_nStyle & (dottedLine|solidLine)) != 0)
	{
		if (m_nStyle & dottedLine)
			pOldPen = pDC->SelectObject(CPen::FromHandle(blackDottedPen));
		else
			pOldPen = (CPen*)pDC->SelectStockObject(BLACK_PEN);
		pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
		nOldROP = pDC->SetROP2(R2_COPYPEN);
		rect.InflateRect(+1, +1);   // borders are one pixel outside
		pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);
		pDC->SetROP2(nOldROP);
	}

	// if hatchBrush is going to be used, need to unrealize it
	if ((m_nStyle & (hatchInside|hatchedBorder)) != 0)
		UnrealizeObject(hatchBrush);

	// hatch inside
	if ((m_nStyle & hatchInside) != 0)
	{
		pTemp = pDC->SelectStockObject(NULL_PEN);
		if (pOldPen == NULL)
			pOldPen = (CPen*)pTemp;
		pTemp = pDC->SelectObject(CBrush::FromHandle(hatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(TRANSPARENT);
#ifndef _MAC
		nOldROP = pDC->SetROP2(R2_MASKNOTPEN);
#else _MAC
		nOldROP = pDC->SetROP2(R2_MERGENOTPEN);
#endif // _MAC
		pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom);
		pDC->SetROP2(nOldROP);
	}

	// draw hatched border
	if ((m_nStyle & hatchedBorder) != 0)
	{
		pTemp = pDC->SelectObject(CBrush::FromHandle(hatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(OPAQUE);
		CRect rectTrue;
		GetTrueRect(&rectTrue);
		pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(),
			rect.top-rectTrue.top, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.bottom,
			rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left,
			rect.Height(), 0x000F0001 /* Pn */);
		pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right,
			rect.Height(), 0x000F0001 /* Pn */);
	}

	// draw resize handles
	if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
	{
		UINT mask = GetHandleMask();
		for (int i = 0; i < 8; ++i)
		{
			if (mask & (1<<i))
			{
				GetHandleRect((TrackerHit)i, &rect);
				pDC->FillSolidRect(rect, RGB(0, 0, 0));
			}
		}
	}

	// cleanup pDC state
	if (pOldPen != NULL)
		pDC->SelectObject(pOldPen);
	if (pOldBrush != NULL)
		pDC->SelectObject(pOldBrush);
	VERIFY(pDC->RestoreDC(-1));
}
예제 #6
0
int CPeerLink::DoRead( long long llCount )
{
    int nReadCount = 0;
    char *pBuff = new char [RECV_BUFFER_SIZE];

    for (; nReadCount < llCount; )
    {
        int nReadSize = RECV_BUFFER_SIZE;
        if (nReadSize > llCount - nReadCount)
        {
            nReadSize = llCount - nReadCount;
        }

        int nRet = recv(GetHandle(), pBuff, nReadSize, 0);
        if (nRet == 0)
        {
            CloseLink();
            delete [] pBuff;
            return nReadCount;
        }

        if (nRet == -1)
        {
            int nErrCode = WSAGetLastError();
            if (nErrCode == WSAEWOULDBLOCK)
            {
                m_bCanRead = false;
                break;
            }

            if (nErrCode == WSAEINTR)
            {
                continue;
            }

            CloseLink();
            delete [] pBuff;
            return nReadCount;
        }

        if (nRet > 0)
        {
            nReadCount += nRet;
            m_nDownloadCount += nRet;
            m_pPeerManager->GetTorrentTask()->AddDownloadCount(nRet);

            m_strRecvBuffer.append((const char *)pBuff, nRet);
        }
    }

    delete [] pBuff;

    ProcRecvData();

    if (m_bCanRead)
    {
        if (GetHandleMask() & READ_MASK)
        {
            RemoveHandleMask(READ_MASK);
        }
    }
    else
    {
        if (!(GetHandleMask() & READ_MASK))
        {
            SetHandleMask(READ_MASK);
        }
    }

    return nReadCount;
}
예제 #7
0
int CPeerLink::DoWrite( long long llCount )
{
    int nSendCount = 0;
    if (m_nPeerState == PS_ESTABLISHED)
    {
        for (; (m_strSendBuffer.size() > 0) && (nSendCount < llCount); )
        {
            int nSendSize = m_strSendBuffer.size();
            if (nSendSize > llCount)
            {
                nSendSize = llCount;
            }
            
            int nRet = send(GetHandle(), m_strSendBuffer.data(), nSendSize, 0);
            
            if (nRet == -1)
            {
                int nErrCode = WSAGetLastError();
                if (nErrCode == WSAEINTR || nErrCode == WSAEWOULDBLOCK )
                {
                    m_bCanWrite = false;
                }
                else
                {
                    CloseLink();
                    return nSendCount;
                }

                break;
            }

            nSendCount += nRet;
            m_nUploadCount += nRet;
            m_pPeerManager->GetTorrentTask()->AddUploadCount(nRet);

            m_strSendBuffer.erase(0, nRet);
            if (m_strSendBuffer.size() == 0)
            {
                OnSendComplete();
                break;
            }
        }
    }

    if (m_bCanWrite)
    {
        if (GetHandleMask() & WRITE_MASK)
        {
            RemoveHandleMask(WRITE_MASK);
        }
    }
    else
    {
        if (!(GetHandleMask() & WRITE_MASK))
        {
            SetHandleMask(WRITE_MASK);
        }
    }

    return nSendCount;
}
예제 #8
0
void CColorRectTracker::Draw(CDC* pDC)
{
	// set initial DC state
	VERIFY(pDC->SaveDC() != 0);
	pDC->SetMapMode(MM_TEXT);
	pDC->SetViewportOrg(0, 0);
	pDC->SetWindowOrg(0, 0);

	// get normalized rectangle
	CRect rect = m_rect;
	rect.NormalizeRect();

	CPen* pOldPen = NULL;
	CBrush* pOldBrush = NULL;
	CGdiObject* pTemp;
	int nOldROP;
	
	CPoint ptCenter = rect.CenterPoint();
	int nCrossHairWH = rect.Width() < rect.Height() ? rect.Width()/4 : rect.Height()/4;
	if (nCrossHairWH > 20) nCrossHairWH = 20;
	if (nCrossHairWH < 4) nCrossHairWH = 0;

	// draw lines
	if ((m_nStyle & (dottedLine|solidLine)) != 0)
	{
		rect.InflateRect(+1, +1);   // borders are one pixel outside
		pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
		nOldROP = pDC->SetROP2(R2_COPYPEN);

		pOldPen = pDC->SelectObject( &m_WhiteBoldPen );
		pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);
		
		if (nCrossHairWH > 0)
		{
			pDC->MoveTo(ptCenter.x-nCrossHairWH/2, ptCenter.y);
			pDC->LineTo(ptCenter.x+nCrossHairWH/2, ptCenter.y);
			pDC->MoveTo(ptCenter.x, ptCenter.y-nCrossHairWH/2);
			pDC->LineTo(ptCenter.x, ptCenter.y+nCrossHairWH/2);
		}
		
		if (m_nStyle & dottedLine)
			pDC->SelectObject(CPen::FromHandle(_afxBlackDottedPen));
		else
			pDC->SelectStockObject(BLACK_PEN);
		pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);

		if (nCrossHairWH > 0)
		{
			pDC->MoveTo(ptCenter.x-nCrossHairWH/2, ptCenter.y);
			pDC->LineTo(ptCenter.x+nCrossHairWH/2, ptCenter.y);
			pDC->MoveTo(ptCenter.x, ptCenter.y-nCrossHairWH/2);
			pDC->LineTo(ptCenter.x, ptCenter.y+nCrossHairWH/2);
		}

		pDC->SetROP2(nOldROP);
	}

	// if hatchBrush is going to be used, need to unrealize it
	if ((m_nStyle & (hatchInside|hatchedBorder)) != 0)
		UnrealizeObject(_afxHatchBrush);

	// hatch inside
	if ((m_nStyle & hatchInside) != 0)
	{
		pTemp = pDC->SelectStockObject(NULL_PEN);
		if (pOldPen == NULL)
			pOldPen = (CPen*)pTemp;
		pTemp = pDC->SelectObject(CBrush::FromHandle(_afxHatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(TRANSPARENT);
		nOldROP = pDC->SetROP2(R2_MASKNOTPEN);
		pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom);
		pDC->SetROP2(nOldROP);
	}

	// draw hatched border
	if ((m_nStyle & hatchedBorder) != 0)
	{
		pTemp = pDC->SelectObject(CBrush::FromHandle(_afxHatchBrush));
		if (pOldBrush == NULL)
			pOldBrush = (CBrush*)pTemp;
		pDC->SetBkMode(OPAQUE);
		CRect rectTrue;
		GetTrueRect(&rectTrue);
		pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(),
			rect.top-rectTrue.top, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.bottom,
			rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */);
		pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left,
			rect.Height(), 0x000F0001 /* Pn */);
		pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right,
			rect.Height(), 0x000F0001 /* Pn */);
	}

	// draw resize handles
	if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
	{
		UINT mask = GetHandleMask();
		for (int i = 0; i < 8; ++i)
		{
			if (mask & (1<<i))
			{
				GetHandleRect((TrackerHit)i, &rect);
				rect.InflateRect( +1, +1, +1, +1 );
				pDC->FillSolidRect(rect, RGB(0xff, 0xff, 0xff));
				rect.DeflateRect( +1, +1, +1, +1 );
				pDC->FillSolidRect(rect, RGB(0, 0, 0));
			}
		}
	}

	// cleanup pDC state
	if (pOldPen != NULL)
		pDC->SelectObject(pOldPen);
	if (pOldBrush != NULL)
		pDC->SelectObject(pOldBrush);
	VERIFY(pDC->RestoreDC(-1));
}