Пример #1
0
void EdgeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
    QWidget* widget /* = nullptr */)
{
    // Draw the emphasis line
    if (m_emphasised) {
        painter->setPen(m_emphPen);
        painter->drawLine(m_line);
    }

    // draw the line
    //QBrush b(QColor(18, 228, 18));
    QBrush b(QColor(0, 199, 255));
    QPen p(b, LineWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
    painter->setPen(p);
    painter->drawLine(m_line);

    // Draw the label
    QRectF rcLabel(m_labelRect);
    QPointF ptLabel(m_line.pointAt(0.5f));
    if ((m_line.dx() * m_line.dy()) < 0) {
        ptLabel += QPointF(-EdgeItem::LabelOffset,
            -EdgeItem::LabelOffset);
        rcLabel.moveBottomRight(ptLabel);
    } else {
        ptLabel += QPointF(EdgeItem::LabelOffset,
            -EdgeItem::LabelOffset);
        rcLabel.moveBottomLeft(ptLabel);
    }
    painter->setFont(m_font);
    painter->drawText(rcLabel, QString("%1").arg(m_weight));

    // draw the arrow head
    if (m_arrowhead) {
        QPolygonF arrowHead;
        arrowHead.append(QPointF(-ArrowHeight / 2,  ArrowBase / 2));
        arrowHead.append(QPointF( ArrowHeight / 2,  0.0f));
        arrowHead.append(QPointF(-ArrowHeight / 2, -ArrowBase / 2));
        QTransform trans;
        trans.translate(m_line.x2 (), m_line.y2 ());
        trans.rotate(-m_line.angle ());
        painter->setPen(Qt::NoPen);
        painter->setBrush(QBrush(Qt::blue));
        painter->setTransform(trans, true);
        painter->drawPolygon(arrowHead);
    }
}
Пример #2
0
void CACListWnd::DrawItem(CDC *pDC, long m_lItem, long width) {
  long y = m_lItem - m_lTopIndex;
  CRect rcLabel(2, y * m_ItemHeight, width, (y + 1) * m_ItemHeight);

  pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));

  if (m_lItem == m_lSelItem) {
    rcLabel.left = 0;
    pDC->FillSolidRect(rcLabel, ::GetSysColor(COLOR_HIGHLIGHT));
    pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
    rcLabel.left = 2;
  }

  if (m_PrefixChar)
    m_DisplayStr = m_PrefixChar + m_DisplayList[m_lItem];
  else
    m_DisplayStr = m_DisplayList[m_lItem];

  pDC->DrawText(m_DisplayStr, -1, rcLabel, DT_LEFT | DT_SINGLELINE |
                                               DT_NOPREFIX | DT_VCENTER |
                                               DT_END_ELLIPSIS);
}
Пример #3
0
void CStatisticDlg::DrawVariogram(CDC* pDC, CRect& rc, std::vector<float>& vecMean, std::vector<std::vector<float>>& vecVariogram, std::vector<drawParam>& vecParam, std::vector<float>& vecStandDeviation)
{
	if (rc.IsRectEmpty())
		return;
	pDC->FillSolidRect(rc, RGB(255, 255, 255));

	///////////////////////////////////////////////////////
	if (vecVariogram.empty())
		return;
	//CPen* pFrameLine = new CPen(PS_SOLID, 1, RGB(0, 0, 0));
	//CPen* pOldPen = pDC->SelectObject(pFrameLine);
	CFont* pOldFont = pDC->SelectObject(m_pFont);
	COLORREF oldColor = pDC->SetTextColor(RGB(0, 0, 0));

	CRect rcVariogram(rc);

	LOGFONT lf;
	m_pFont->GetLogFont(&lf);

	rcVariogram.DeflateRect(abs(lf.lfHeight), abs(lf.lfHeight), abs(lf.lfHeight), abs(lf.lfHeight));

	CRect rcLabel(rc);
	rcLabel.left = rcVariogram.left;
	rcLabel.bottom = rcLabel.top + abs(lf.lfHeight) + 2;
	// draw label --- height width channel datatype?
	CString strLabel;
	strLabel.Format(_T("height:%d, width:%d, channel:%d"), m_pImage->m_data.rows, m_pImage->m_data.cols, m_pImage->m_data.channels());
	pDC->DrawText(strLabel, rcLabel, DT_SINGLELINE|DT_LEFT);
	// draw single band, calculate rc first
	int iSize = vecVariogram.size();
	std::vector<CRect> rcBand;

	int iWidth = rcVariogram.Width() / 2;
	int iHeight = rcVariogram.Height() / 2;
	CRect rc1, rc2, rc3, rc4;
	rc1 = rcVariogram;
	rc1.DeflateRect(1, 1, 1, 1);
	rc1.bottom = rc1.top + iHeight;
	rc1.right = rc1.left + iWidth;

	rc2 = rc1;
	rc2.MoveToX(rc1.right + 1);

	rc3 = rc1;
	rc3.MoveToY(rc1.bottom + 1);

	rc4 = rc3;
	rc4.MoveToX(rc3.right + 1);
	rcBand.push_back(rc1);
	//pDC->FillSolidRect(rc1, RGB(255, 0, 0));
	rcBand.push_back(rc2);
	//pDC->FillSolidRect(rc2, RGB(0, 255, 0));
	rcBand.push_back(rc3);
	//pDC->FillSolidRect(rc3, RGB(0, 0, 255));
	rcBand.push_back(rc4);
	//pDC->FillSolidRect(rc4, RGB(0, 0, 0));
	for (int i = 0; i < iSize; i++)
	{
		// calculate rc to be continued...
		DrawVariogram(pDC, rcBand[i], i, vecMean[i], vecStandDeviation[i], vecVariogram[i], vecParam[i]);
	}

	//for (int i = 0; i < (int)m_pImage->m_mean.size(); i++)
	//{
	//	CString str;
	//	if (i != m_pImage->m_mean.size() - 1)
	//		str.Format(_T("%.3f, "), m_pImage->m_mean[i]);
	//	else
	//		str.Format(_T("%.3f"), m_pImage->m_mean[i]);

	//	strLabel += str;
	//}
	

	//CRect rcX, rcY, rcLabel;
	////pDC->FillSolidRect(rcLabel, RGB(255, 0, 0));

	//rcY.left = 0;
	//rcY.top = rcLabel.bottom + 1;
	//rcY.right = rcLabel.left - 1;
	//rcY.bottom = rcVariogram.bottom - 1;
	////pDC->FillSolidRect(rcY, RGB(255, 0, 0));

	//rcX.left = rcVariogram.left + 1;
	//rcX.top = rcVariogram.bottom + 1;
	//rcX.bottom = rc.bottom - 1;
	//rcX.right = rcVariogram.right - 1;
	////pDC->FillSolidRect(rcX, RGB(255, 0, 0));

	//// draw label --- height width channel meanvalue
	//CString strLabel;
	//strLabel.Format(_T("height:%d, width:%d, channel:%d, mean value:"), m_pImage->m_data.rows, m_pImage->m_data.cols, m_pImage->m_data.channels());
	//for (int i = 0; i < (int)m_pImage->m_mean.size(); i++)
	//{
	//	CString str;
	//	if (i != m_pImage->m_mean.size() - 1)
	//		str.Format(_T("%.3f, "), m_pImage->m_mean[i]);
	//	else
	//		str.Format(_T("%.3f"), m_pImage->m_mean[i]);

	//	strLabel += str;
	//}
	//pDC->DrawText(strLabel, rcLabel, DT_SINGLELINE|DT_LEFT);
	//// draw Y --- 5
	//float f = rcY.Height() / (float)5.0;
	//CRect rcTemp = rcY;
	//rcTemp.bottom = (int)(rcTemp.top + f);
	//for (int i = 0; i < 5; i++)
	//{
	//	CString str;
	//	str.Format(_T("%.3f"), dp.fMax *(1 -  i / 5.0));
	//	pDC->DrawText(str, rcTemp, DT_SINGLELINE|DT_RIGHT);
	//	rcTemp.top += f;
	//	rcTemp.bottom += f;
	//}
	//// draw X --- 5
	//f = rcX.Width() / (float)5.0;
	//rcTemp = rcX;
	//for (int i = 0; i <= 5; i++)
	//{
	//	CString str;
	//	str.Format(_T("%d"), (int)(dp.iMax * i / 5.0));
	//	pDC->DrawText(str, rcTemp, DT_SINGLELINE|DT_LEFT);
	//	rcTemp.left += f;
	//	rcTemp.right += f;
	//}
	//// draw Variogram
	//pDC->MoveTo(rcVariogram.left, rcVariogram.top);
	//
	//pDC->LineTo(rcVariogram.left, rcVariogram.bottom);

	//pDC->LineTo(rcVariogram.right, rcVariogram.bottom);

	//int iHeight = rcVariogram.Height() - 2;
	//int iWidth = rcVariogram.Width() - 2;
	//std::map<int, float>::iterator iter = mapVariogram.begin();
	//int iCount = (int)mapVariogram.size();

	//CPoint ptStart;
	//ptStart.x = rcVariogram.left + (int)(iter->first * (float)iWidth / (float)iCount);
	//ptStart.y = rcVariogram.bottom - (int)(iter->second * (float)iHeight / dp.fMax);

	//pDC->MoveTo(ptStart);
	//while (iter != mapVariogram.end())
	//{
	//	CPoint pt;
	//	pt.x = rcVariogram.left + (int)(iter->first * (float)iWidth / (float)iCount);
	//	pt.y = rcVariogram.bottom - (int)(iter->second * (float)iHeight / dp.fMax);
	//	pDC->LineTo(pt);
	//	iter++;
	//}


	pDC->SelectObject(pOldFont);
	//pDC->SelectObject(pOldPen);
	pDC->SetTextColor(oldColor);
	//delete pFrameLine;
}
Пример #4
0
void COXGridHeader::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	if (m_UxTheme.IsUxThemeLoaded())
	{
		HTHEME hTheme = m_UxTheme.GetWindowTheme(m_hWnd);
		if (hTheme != NULL)
		{

			// Draw the item background
			int iState = HIS_NORMAL;
			if (lpDrawItemStruct->itemState == ODS_SELECTED)
				iState = HIS_PRESSED;
			else
			{
				POINT ptCursor;
				::GetCursorPos(&ptCursor);
				ScreenToClient(&ptCursor);
				CRect rectItem(lpDrawItemStruct->rcItem);
				if (rectItem.PtInRect(ptCursor))
					iState = HIS_HOT;
			}
			m_UxTheme.DrawThemeBackground(hTheme,
				lpDrawItemStruct->hDC,
				HP_HEADERITEM,
				iState,
				&lpDrawItemStruct->rcItem,
				NULL);

			BOOL bDrawArrow;
			if (m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol)
				bDrawArrow = TRUE;
			else
				bDrawArrow = FALSE;


			// Get the column text and format	
			TCHAR buf[256];	
			HD_ITEM hditem;	
			hditem.mask = HDI_TEXT | HDI_FORMAT;	
			hditem.pszText = buf;
			hditem.cchTextMax = 255;	
			GetItem( lpDrawItemStruct->itemID, &hditem );

			RECT rectText = lpDrawItemStruct->rcItem;
			rectText.left += 9;
			rectText.right -= 9;

			// Determine format for drawing column label
			UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | 
				DT_VCENTER | DT_END_ELLIPSIS ;
			UINT uArrowFormat = DT_SINGLELINE | DT_VCENTER;
			if( hditem.fmt & HDF_CENTER)
			{
				uFormat |= DT_CENTER;
				uArrowFormat |= DT_RIGHT;
				if (bDrawArrow)
					rectText.right -= 12;
			}
			else if( hditem.fmt & HDF_RIGHT)
			{
				uFormat |= DT_RIGHT;
				uArrowFormat |= DT_LEFT;
				if (bDrawArrow)
					rectText.left += 12;
			}
			else
			{
				uFormat |= DT_LEFT;
				uArrowFormat |= DT_RIGHT;
				if (bDrawArrow)
					rectText.right -= 12;
			}

			m_UxTheme.DrawThemeText(hTheme,
				lpDrawItemStruct->hDC,
				HP_HEADERITEM,
				HIS_NORMAL,
				buf,
				-1,
				uFormat,
				0,
				&rectText);

			// Draw the Sort arrow	
			if (bDrawArrow)	
			{
				CDC dc;
				dc.Attach(lpDrawItemStruct->hDC);
				int nSavedDC = dc.SaveDC();
				CFont fontMarlett;
				fontMarlett.CreatePointFont(120, _T("Marlett"));
				dc.SelectObject(&fontMarlett);
				dc.SetBkMode(TRANSPARENT);
				dc.SetTextColor(RGB(128, 128, 128));

				CRect rectArrow = lpDrawItemStruct->rcItem;
				rectArrow.DeflateRect(5, 0, 5, 0);

				if (m_nSortOrder == 1)
					dc.DrawText(_T("5"), -1, &rectArrow, uArrowFormat);
				else
					dc.DrawText(_T("6"), -1, &rectArrow, uArrowFormat);

				// Restore dc	
				dc.RestoreDC(nSavedDC);
				// Detach the dc before returning	
				dc.Detach();
			}
			return;
		}
	}

	CDC dc;
	dc.Attach( lpDrawItemStruct->hDC );	
	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );	
	// Save DC
	int nSavedDC = dc.SaveDC();
	// Set clipping region to limit drawing within column	
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );	
	dc.SelectObject( &rgn );
	rgn.DeleteObject(); 
	// Draw the background
	CBrush brush(::GetSysColor(COLOR_3DFACE));
	dc.FillRect(rcLabel,&brush);	
	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2;
	// Get the column text and format	
	TCHAR buf[256];	
	HD_ITEM hditem;	
	hditem.mask = HDI_TEXT | HDI_FORMAT;	
	hditem.pszText = buf;
	hditem.cchTextMax = 255;	
	GetItem( lpDrawItemStruct->itemID, &hditem );
	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | 
		DT_VCENTER | DT_END_ELLIPSIS ;	
	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;	
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	// Adjust the rect if the mouse button is pressed on it
	if( lpDrawItemStruct->itemState == ODS_SELECTED )	
	{		
		rcLabel.left++;
		rcLabel.top += 2;		
		rcLabel.right++;	
	}
	// Adjust the rect further if Sort arrow is to be displayed
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )	
	{
		rcLabel.right -= 3 * offset;	
	}
	rcLabel.left += offset;
	rcLabel.right -= offset;	
	// Draw column label
	if( rcLabel.left < rcLabel.right )
		dc.DrawText(buf,-1,rcLabel, uFormat);
	// Draw the Sort arrow	
	if( m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol )	
	{
		CRect rcIcon( lpDrawItemStruct->rcItem );
		// Set up pens to use for drawing the triangle
		CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
		CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = dc.SelectObject( &penLight );		
		if( m_nSortOrder==1 )		
		{
			// Draw triangle pointing upwards
			dc.MoveTo( rcIcon.right - 2*offset, offset-1);
			dc.LineTo( rcIcon.right - 3*offset/2, rcIcon.bottom - offset );
			dc.LineTo( rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset );
			dc.MoveTo( rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1 );
			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 2*offset, offset-2);		
		}
		else		
		{
			// Draw triangle pointing downwords
			dc.MoveTo( rcIcon.right - 3*offset/2, offset-1);
			dc.LineTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1 );
			dc.MoveTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset );
			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 5*offset/2-1, offset -1 );
			dc.LineTo( rcIcon.right - 3*offset/2, offset -1);		
		}
		// Restore the pen
		dc.SelectObject( pOldPen );	
	}	
	// Restore dc	
	dc.RestoreDC( nSavedDC );
	// Detach the dc before returning	
	dc.Detach();
}
Пример #5
0
void CCJFlatHeaderCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDC dc;

	dc.Attach( lpDrawItemStruct->hDC );
	
	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );
	
	// Save DC
	int nSavedDC = dc.SaveDC();
	
	// Set clipping region to limit drawing within column
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );
	dc.SelectObject( &rgn );
	rgn.DeleteObject();
	
	// Draw the background
	dc.FillRect(rcLabel, &CBrush(::GetSysColor(COLOR_3DFACE)));
	dc.SetBkMode(TRANSPARENT);

	// Get the column text and format
	TCHAR buf[256];
	HD_ITEM hditem;
	
	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = buf;
	hditem.cchTextMax = 255;
	
	GetItem( lpDrawItemStruct->itemID, &hditem );
	
	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP 
		| DT_VCENTER | DT_END_ELLIPSIS ;
	
	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	
	// Adjust the rect if the mouse button is pressed on it
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rcLabel.left++;
		rcLabel.top += 2;
		rcLabel.right++;
	}
	
	// Adjust the rect further if Sort arrow is to be displayed
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
	{
		rcLabel.right -= 3 * m_nOffset;
	}
	
	rcLabel.left += m_nOffset;
	rcLabel.right -= m_nOffset;

	// Draw column label
	if( rcLabel.left < rcLabel.right )
	{
		if (m_bBoldFont) {
			dc.SelectObject(&m_HeaderFont);
		}
		dc.DrawText(buf,-1,rcLabel, uFormat);
	}

	// Draw the Sort arrow
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
	{
		CRect rcIcon( lpDrawItemStruct->rcItem );
		
		// Set up pens to use for drawing the triangle
		CPen penLite(PS_SOLID, 1, ::GetSysColor(COLOR_3DHILIGHT));
		CPen penShad(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = dc.SelectObject( &penLite );
		
		if( m_bSortAsc )
		{
			// Draw triangle pointing upwards
			dc.MoveTo( rcIcon.right - 2*m_nOffset, m_nOffset-1);
			dc.LineTo( rcIcon.right - 3*m_nOffset/2, rcIcon.bottom - m_nOffset );
			dc.LineTo( rcIcon.right - 5*m_nOffset/2-2, rcIcon.bottom - m_nOffset );
			dc.MoveTo( rcIcon.right - 5*m_nOffset/2-1, rcIcon.bottom - m_nOffset-1 );
			
			dc.SelectObject( &penShad );
			dc.LineTo( rcIcon.right - 2*m_nOffset, m_nOffset-2);
		}
		else
		{
			// Draw triangle pointing downwords
			dc.MoveTo( rcIcon.right - 3*m_nOffset/2, m_nOffset-1);
			dc.LineTo( rcIcon.right - 2*m_nOffset-1, rcIcon.bottom - m_nOffset + 1 );
			dc.MoveTo( rcIcon.right - 2*m_nOffset-1, rcIcon.bottom - m_nOffset );
			
			dc.SelectObject( &penShad );
			dc.LineTo( rcIcon.right - 5*m_nOffset/2-1, m_nOffset -1 );
			dc.LineTo( rcIcon.right - 3*m_nOffset/2, m_nOffset -1);
		}
		
		// Restore the pen
		dc.SelectObject( pOldPen );
	}

	// Restore dc
	dc.RestoreDC( nSavedDC );
	
	// Detach the dc before returning
	dc.Detach();
}
void CKadContactHistogramCtrl::OnPaint()
{
	CPaintDC dc(this);

	CRect rcClnt;
	GetClientRect(&rcClnt);
	if (rcClnt.IsRectEmpty())
		return;
	dc.FillSolidRect(rcClnt, GetSysColor(COLOR_WINDOW));
	COLORREF crOldTextColor = dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));

	CFont* pOldFont = dc.SelectObject(&m_fontLabel);
	if (!m_bInitializedFontMetrics)
	{
		TEXTMETRIC tm;
		dc.GetTextMetrics(&tm);
		// why is 'tm.tmMaxCharWidth' and 'tm.tmAveCharWidth' that wrong?
		CRect rcLabel;
		dc.DrawText(_T("888"), 3, &rcLabel, DT_CALCRECT);
		m_iMaxNumLabelWidth = rcLabel.Width();
		if (m_iMaxNumLabelWidth <= 0)
			m_iMaxNumLabelWidth = 3*8;
		m_iMaxLabelHeight = tm.tmHeight;
		if (m_iMaxLabelHeight <= 0)
			m_iMaxLabelHeight = 8;
		m_bInitializedFontMetrics = true;
	}

	int iLeftBorder = 1 + m_iMaxNumLabelWidth + 3;
	int iRightBorder = 8;
	int iTopBorder = m_iMaxLabelHeight;
	int iBottomBorder = m_iMaxLabelHeight;

	int iBaseLineX = iLeftBorder;
	int iBaseLineY = rcClnt.bottom - iBottomBorder;
	UINT uHistWidth = rcClnt.Width() - iLeftBorder - iRightBorder;
	if (uHistWidth > ARRSIZE(m_aHist))
		uHistWidth = ARRSIZE(m_aHist);
	else if (uHistWidth == 0) {
		dc.SelectObject(pOldFont);
		dc.SetTextColor(crOldTextColor);
		return;
	}
	UINT uHistHeight = rcClnt.Height() - iTopBorder - iBottomBorder;
	if (uHistHeight == 0) {
		dc.SelectObject(pOldFont);
		dc.SetTextColor(crOldTextColor);
		return;
	}

	int i = 0;
	UINT uMax = m_aHist[i++];
	while (i < ARRSIZE(m_aHist))
	{
		if (m_aHist[i] > uMax)
			uMax = m_aHist[i];
		i++;
	}

	//Lets take the average. This will keep the cluster of closest contacts from
	//streching the graph too far..
	uMax /= ARRSIZE(m_aHist);
	if (uMax < 15)
		uMax = 15/*uHistHeight*/;

	UINT uLabels = uHistHeight / (m_iMaxLabelHeight + m_iMaxLabelHeight/2);
	if (uLabels == 0){
		dc.SelectObject(pOldFont);
		dc.SetTextColor(crOldTextColor);
		return;
	}
	UINT uStep = ((uMax / uLabels + 5) / 10) * 10;
	if (uStep < 5)
		uStep = 5;

	CPen* pOldPen = dc.SelectObject(&m_penAxis);

	dc.MoveTo(iBaseLineX, rcClnt.top + iTopBorder);
	dc.LineTo(iBaseLineX, iBaseLineY);
	dc.LineTo(iBaseLineX + uHistWidth, iBaseLineY);

	dc.SelectObject(&m_penAux);
	for (UINT s = 0; s <= uMax; s += uStep)
	{
		int y = iBaseLineY - (uHistHeight * s) / uMax;
		int iLabelY = y - m_iMaxLabelHeight/2;
		CRect rcLabel(1, iLabelY, 1 + m_iMaxNumLabelWidth, iLabelY + m_iMaxLabelHeight);
		if (s > 0)
		{
			dc.MoveTo(iBaseLineX - 2, y);
			dc.LineTo(iBaseLineX + uHistWidth, y);
		}

		TCHAR szLabel[12];
		int iLabelLen = _stprintf(szLabel, _T("%u"), s);
		dc.DrawText(szLabel, iLabelLen, rcLabel, DT_RIGHT /*| DT_NOCLIP*/);
	}

	CRect rcLabel(rcClnt);
	rcLabel.left = iBaseLineX;
	rcLabel.bottom = m_iMaxLabelHeight;
	dc.DrawText(m_strYaxis, m_strYaxis.GetLength(), &rcLabel, DT_LEFT | DT_TOP | DT_NOCLIP);

	rcLabel = rcClnt;
	rcLabel.top = rcClnt.bottom - m_iMaxLabelHeight + 1;
	dc.DrawText(m_strXaxis, m_strXaxis.GetLength(), &rcLabel, DT_RIGHT | DT_BOTTOM | DT_NOCLIP);

	int iLastHx = -1;
	for (UINT x = 0; x < uHistWidth; x++)
	{
		int hx = (x * ARRSIZE(m_aHist)) / uHistWidth;
		UINT hv = m_aHist[hx];
		iLastHx++;
		while (iLastHx < hx)
			hv += m_aHist[iLastHx++];

		if (hv > uMax)
		{
			dc.SelectObject(&m_penAxis);
			hv = uMax;
		}
		else
			dc.SelectObject(&m_penHist);

		if (hv)
		{
			dc.MoveTo(iBaseLineX + x, iBaseLineY - 1);
			UINT uHistVal = (hv * uHistHeight) / uMax;
			dc.LineTo(iBaseLineX + x, iBaseLineY - 1 - uHistVal - 1);
		}
	}

	dc.SelectObject(pOldPen);
	dc.SelectObject(pOldFont);
	dc.SetTextColor(crOldTextColor);
}
Пример #7
0
void CNewHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC dc;

	dc.Attach( lpDrawItemStruct->hDC );

	// Save DC
	int nSavedDC = dc.SaveDC();

/*	if(m_RTL)
	{
		dc.SetViewportOrg(0, 0);
		dc.SetMapMode(MM_TEXT);
	}
*/
	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );

/*	CTLFrame *pFrame = (CTLFrame *)GetParent();

	CRect m_clientRect;
	pFrame->m_tree.GetClientRect(&m_clientRect);

	if(m_RTL)
	{
		int left = rcLabel.left;
		int right = rcLabel.right;

		rcLabel.left = m_clientRect.Width() - right;
		rcLabel.right = m_clientRect.Width() - left;
	}
*/
	// Set clipping region to limit drawing within column
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );
	dc.SelectObject( &rgn );
	rgn.DeleteObject();

	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2;


	// Draw image from image list

	// Get the column text and format
	TCHAR buf[256];
	HD_ITEM hditem;
	
	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = buf;
	hditem.cchTextMax = 255;

	GetItem( lpDrawItemStruct->itemID, &hditem );

	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP 
						| DT_VCENTER | DT_END_ELLIPSIS ;

	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;

	if(!(uFormat & DT_RIGHT))
	{
		// Adjust the rect if the mouse button is pressed on it
		if( lpDrawItemStruct->itemState == ODS_SELECTED )
		{
			rcLabel.left++;
			rcLabel.top += 2;
			rcLabel.right++;
		}

		rcLabel.left += offset;
		rcLabel.right -= offset;

		// Draw column label
		if( rcLabel.left < rcLabel.right )
			dc.DrawText(buf,-1,rcLabel, uFormat);
	}


	int imageIndex;
	if (m_pImageList && 
		m_mapImageIndex.Lookup( lpDrawItemStruct->itemID, imageIndex ) )
	{
		if( imageIndex != -1 )
		{
			if(uFormat & DT_RIGHT)
			// draw to the left of the label
				m_pImageList->Draw(&dc, imageIndex, 
						CPoint( rcLabel.left + offset,offset/3 ),
						ILD_TRANSPARENT );
			else
			// draw to the right
				m_pImageList->Draw(&dc, imageIndex, 
						CPoint( rcLabel.right - dc.GetTextExtent(_T(buf), 1 ).cx*2,offset/3 ),
						ILD_TRANSPARENT );


			// Now adjust the label rectangle
			IMAGEINFO imageinfo;
			if( m_pImageList->GetImageInfo( imageIndex, &imageinfo ) )
			{
				rcLabel.left += offset/2 + 
					imageinfo.rcImage.right - imageinfo.rcImage.left;
			}
		}
	}

	if(uFormat & DT_RIGHT)
	{
		// Adjust the rect if the mouse button is pressed on it
		if( lpDrawItemStruct->itemState == ODS_SELECTED )
		{
			rcLabel.left++;
			rcLabel.top += 2;
			rcLabel.right++;
		}

		rcLabel.left += offset;
		rcLabel.right -= offset;

		// Draw column label
		if( rcLabel.left < rcLabel.right )
			dc.DrawText(buf,-1,rcLabel, uFormat);
	}

/*	if(m_RTL)
	{
		dc.SetViewportOrg(m_clientRect.Width(), 0);
		CSize ext = dc.GetViewportExt();
		ext.cx = ext.cx > 0 ? -ext.cx : ext.cx;

		dc.SetMapMode(MM_ANISOTROPIC);
		dc.SetViewportExt(ext);
	}
*/
	// Restore dc
	dc.RestoreDC( nSavedDC );

	// Detach the dc before returning
	dc.Detach();
}