예제 #1
0
void CGameDlg::DrawTipLine(Vertex asvPath[MAX_SAVED_VERTEX_NUM],int nVexnum)
{
	
	CClientDC dc(this);
	CPen penLine(PS_SOLID,2,RGB(0,255,0));
	CPen* pOldPen = dc.SelectObject(&penLine);
	
	for(int i = 0 ; i<nVexnum-1; i++)
	{
		dc.MoveTo(m_ptGameTop.x + asvPath[i].col*m_sizeElem.cx + m_sizeElem.cx/2,
		m_ptGameTop.y+asvPath[i].row*m_sizeElem.cy+m_sizeElem.cy/2);
	dc.LineTo(m_ptGameTop.x + asvPath[i+1].col*m_sizeElem.cx+m_sizeElem.cx/2,
		m_ptGameTop.y+asvPath[i+1].row*m_sizeElem.cy+m_sizeElem.cy/2);
	}
	Combo();
	dc.SelectObject(pOldPen);

}
예제 #2
0
void CSimplePanelDlg::DrawBk()
{
	CDC* pDC = GetDC();

	CRect rc;
	GetClientRect(&rc);

	int nHeight = m_pImLineBK->GetHeight();
	int nWidth = m_pImLineBK->GetWidth();

	CEsayMemDC* pmemDC = new CEsayMemDC(*pDC, rc);
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);

	Gdiplus::Graphics gr(pmemDC->GetDC());
	gr.FillRectangle(&brush, rc.left, rc.top, rc.Width(), rc.Height());

	//顶部文字
	Gdiplus::SolidBrush brushBkWord(Gdiplus::Color(149,158,168));
	std::wstring str = L"第一辆车";

	Gdiplus::PointF pointFBkWord(60+nWidth, 0);
	Gdiplus::RectF rectBkWord(pointFBkWord, Gdiplus::SizeF(145, 46));
	Gdiplus::Font fontBkWord(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatBkWord;
	stringFormatBkWord.SetAlignment(Gdiplus::StringAlignmentFar);
	stringFormatBkWord.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	str = L"第二辆车";

	pointFBkWord.X = 60 + nWidth + 145;
	rectBkWord.X = pointFBkWord.X;
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	str = L"第一辆车";

	pointFBkWord.X = 60 + nWidth*2 + 145 * 2+ 100 + 10;
	rectBkWord.X = pointFBkWord.X;
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	str = L"第二辆车";

	pointFBkWord.X = 60 + nWidth * 2 + 145 * 3+ 100 + 10;
	rectBkWord.X = pointFBkWord.X;
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	//底部分割线
	Gdiplus::SolidBrush brushLine(Gdiplus::Color(215, 215, 215));
	Gdiplus::Pen penLine(&brushLine, 1);

	gr.DrawLine(&penLine, Gdiplus::Point(rc.left, rc.bottom-1), Gdiplus::Point(rc.right, rc.bottom-1));

	//中间竖线
	Gdiplus::SolidBrush brushLineM(Gdiplus::Color(215, 215, 215));
	Gdiplus::Pen penLineM(&brushLineM, 2);

	gr.DrawLine(&penLineM, Gdiplus::Point(541, rc.top + 46), Gdiplus::Point(541, rc.top + nHeight*3 + 64));
	pmemDC->BltMem(*pDC);

	delete pmemDC;

	ReleaseDC(pDC);
}
예제 #3
0
void MyGraph::DrawSeriesLineStacked(CDC& dc) const
{
	VALIDATE;
	ASSERT_VALID(&dc);
	_ASSERTE(m_bStackedGraph);

	int nSeriesCount = (int)m_olMyGraphSeries.GetCount();

	CArray<int> stackAccumulator;
	stackAccumulator.SetSize(nSeriesCount);

	CArray<CPoint> polygon;
	// Special case: if we only have single series, make polygon
	// a bar instead of one pixel line.
	polygon.SetSize(nSeriesCount==1 ? 4 : nSeriesCount * 2);

	// How much space does each series get?
	int nSeriesSpace(0);
	if (m_saLegendLabels.GetSize()) {
		nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) /
			nSeriesCount;
	}
	else {
		nSeriesSpace = m_nXAxisWidth / nSeriesCount;
	}

	int nMaxDataValue(GetMaxDataValue());
	nMaxDataValue = max(nMaxDataValue, 1);
	double dYScaling = double(m_nYAxisHeight) / nMaxDataValue;

	// Iterate the groups.
	for (int nGroup = 0; nGroup < GetMaxSeriesSize(); nGroup++) {

		// Build objects.
		COLORREF crGroup(m_dwaColors.GetAt(nGroup));
		CBrush br(crGroup);
		CBrush* pBrushOld = dc.SelectObject(&br);
		ASSERT_VALID(pBrushOld);
		// For polygon outline, use average of this and previous color, and darken it.
		COLORREF crPrevGroup(nGroup > 0 ? m_dwaColors.GetAt(nGroup-1) : crGroup);
		COLORREF crOutline = RGB(
			(GetRValue(crGroup)+GetRValue(crPrevGroup))/3,
			(GetGValue(crGroup)+GetGValue(crPrevGroup))/3,
			(GetBValue(crGroup)+GetBValue(crPrevGroup))/3);
		CPen penLine(PS_SOLID, 1, crOutline);
		CPen* pPenOld = dc.SelectObject(&penLine);
		ASSERT_VALID(pPenOld);

		// Construct bottom part of polygon from current stack accumulator
		for (int nPolyBottom = 0; nPolyBottom < nSeriesCount; ++nPolyBottom) {
			CPoint ptLoc;
			ptLoc.x = m_ptOrigin.x + (((nPolyBottom + 1) * nSeriesSpace) - (nSeriesSpace / 2));
			double dLineHeight((stackAccumulator[nPolyBottom]) * dYScaling);
			ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight);

			if (nSeriesCount > 1) {
				polygon[nSeriesCount-nPolyBottom-1] = ptLoc;
			} else {
				// special case: when there's one series, make polygon a bar
				polygon[0] = CPoint(ptLoc.x-GAP_PIXELS/2, ptLoc.y);
				polygon[1] = CPoint(ptLoc.x+GAP_PIXELS/2, ptLoc.y);
			}
		}

		// Iterate the series, construct upper part of polygon and upadte stack accumulator
		POSITION pos(m_olMyGraphSeries.GetHeadPosition());
		for (int nSeries = 0; nSeries < nSeriesCount; ++nSeries) {

			MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos);
			ASSERT_VALID(pSeries);

			CPoint ptLoc;
			ptLoc.x = m_ptOrigin.x + (((nSeries + 1) * nSeriesSpace) -
				(nSeriesSpace / 2));
			double dLineHeight((pSeries->GetData(nGroup) + stackAccumulator[nSeries]) * dYScaling);
			ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight);
			if (nSeriesCount > 1) {
				polygon[nSeriesCount+nSeries] = ptLoc;
			} else {
				// special case: when there's one series, make polygon a bar
				polygon[2] = CPoint(ptLoc.x+GAP_PIXELS/2, ptLoc.y);
				polygon[3] = CPoint(ptLoc.x-GAP_PIXELS/2, ptLoc.y);
			}

			stackAccumulator[nSeries] += pSeries->GetData(nGroup);
		}

		// Draw polygon
		VERIFY(dc.Polygon(polygon.GetData(), (int)polygon.GetSize()));

		VERIFY(dc.SelectObject(pPenOld));
		penLine.DeleteObject();
		VERIFY(dc.SelectObject(pBrushOld));
		br.DeleteObject();
	}
}
예제 #4
0
파일: Terrain.cpp 프로젝트: prohan91/zyGrib
//---------------------------------------------------------
// paintEvent
//---------------------------------------------------------
void Terrain::paintEvent(QPaintEvent * /*event*/)
{
    QPainter pnt(this);
    QColor transp;
    int r = 100;
    if (!isResizing || !firstDrawingIsDone)
    {
		firstDrawingIsDone = true;
        // Draw the map and the GRIB data
        QCursor oldcursor = cursor();
        setCursor(Qt::WaitCursor);
        
        switch (currentFileType) {
			case DATATYPE_GRIB :
			case DATATYPE_MBLUE :
				drawer->draw_GSHHS_and_GriddedData 
						(pnt, mustRedraw, isEarthMapValid, proj, griddedPlot);
				break;
			case DATATYPE_IAC :
				drawer->draw_GSHHS_and_IAC 
						(pnt, mustRedraw, isEarthMapValid, proj, iacPlot);
				break;
			default :
				drawer->draw_GSHHS (pnt, mustRedraw, isEarthMapValid, proj);
        }
		
        setCursor(oldcursor);
		isEarthMapValid = true;
		mustRedraw = false;
		pleaseWait = false;
        
        if (selX0!=selX1 && selY0!=selY1) {
            // Draw the rectangle of the selected zone
            pnt.setPen(selectColor);
            transp = QColor(r,r,r, 80);
            pnt.setBrush(transp);
            int x0,y0, x1,y1;
            proj->map2screen(selX0, selY0, &x0, &y0);
            proj->map2screen(selX1, selY1, &x1, &y1);
            pnt.drawRect(x0, y0, x1-x0, y1-y0);
            
            if (showOrthodromie)
            {
                QPen penLine(QColor(Qt::white));
                penLine.setWidthF(1.6);
                pnt.setPen(penLine);
                draw_Orthodromie(pnt);
            }
        }
    }
    else {
        switch (currentFileType) {
			case DATATYPE_GRIB :
			case DATATYPE_MBLUE :
				drawer->draw_GSHHS_and_GriddedData 
						(pnt, false, true, proj, griddedPlot);
				break;
			case DATATYPE_IAC :
				drawer->draw_GSHHS_and_IAC 
						(pnt, false, true, proj, iacPlot);
				break;
			default :
				drawer->draw_GSHHS (pnt, mustRedraw, isEarthMapValid, proj);
        }
	}
    
    if (mustShowSpecialZone) {
		if (specialZoneX0!=specialZoneX1 && specialZoneY0!=specialZoneY1) {
			pnt.setPen(QColor(Qt::white));
			r = 80;
			transp = QColor(r,r,r, 50);
			pnt.setBrush(transp);
			int x0,y0, x1,y1;
			proj->map2screen(specialZoneX0, specialZoneY0, &x0, &y0);
			proj->map2screen(specialZoneX1, specialZoneY1, &x1, &y1);
			pnt.drawRect(x0, y0, x1-x0, y1-y0);
		}
    }
    
    if (pleaseWait) {
        // Write the message "please wait..." on the map
        QFont fontWait = Font::getFont(FONT_MapWait);
        QFontMetrics fmet(fontWait);
        pnt.setPen(QColor(Qt::white));
        r = 80;
        transp = QColor(r,r,r, 80);
        pnt.setFont(fontWait);
        pnt.setBrush(transp);
        QString txt = tr("  Please wait...  ");
        QRect rect = fmet.boundingRect(txt);

        rect.moveTo(20,20);
        pnt.drawRect(rect);
        pnt.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter , txt);
    }
}
예제 #5
0
void MyGraph::DrawSeriesLine(CDC& dc) const
{
	VALIDATE;
	ASSERT_VALID(&dc);
	_ASSERTE(!m_bStackedGraph);

	// Iterate the groups.
	CPoint ptLastLoc(0,0);
	int dataLastLoc(0);

	for (int nGroup = 0; nGroup < GetMaxSeriesSize(); nGroup++) {

		// How much space does each series get (includes inter series space)?
		int nSeriesSpace(0);

		if (m_saLegendLabels.GetSize()) {

			nSeriesSpace = (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)) /
				(int)m_olMyGraphSeries.GetCount();
		}
		else {
			nSeriesSpace = m_nXAxisWidth / (int)m_olMyGraphSeries.GetCount();
		}

		// Determine width of bars.
		int nMaxSeriesSize(GetMaxSeriesSize());
		nMaxSeriesSize = max(nMaxSeriesSize, 1);
		int nBarWidth(nSeriesSpace / nMaxSeriesSize);

		if (1 < m_olMyGraphSeries.GetCount()) {
			nBarWidth = (int) ((double) nBarWidth * INTERSERIES_PERCENT_USED);
		}

		// This is the width of the largest series (no inter series space).
		//int nMaxSeriesPlotSize(GetMaxSeriesSize() * nBarWidth);

		// Iterate the series.
		POSITION pos(m_olMyGraphSeries.GetHeadPosition());

		// Build objects.
		COLORREF crLine(m_dwaColors.GetAt(nGroup));
		CBrush br(crLine);
		CBrush* pBrushOld = dc.SelectObject(&br);
		ASSERT_VALID(pBrushOld);
		CPen penLine(PS_SOLID, 1, crLine);
		CPen* pPenOld = dc.SelectObject(&penLine);
		ASSERT_VALID(pPenOld);

		for (int nSeries = 0; nSeries < m_olMyGraphSeries.GetCount(); ++nSeries) {

			MyGraphSeries* pSeries = m_olMyGraphSeries.GetNext(pos);
			ASSERT_VALID(pSeries);

			// Get x and y location of center of ellipse.
			CPoint ptLoc(0,0);

			ptLoc.x = m_ptOrigin.x + (((nSeries + 1) * nSeriesSpace) -
				(nSeriesSpace / 2));

			int nMaxDataValue(GetMaxDataValue());
			nMaxDataValue = max(nMaxDataValue, 1);
			double dLineHeight(pSeries->GetData(nGroup) * m_nYAxisHeight /
				double(nMaxDataValue));

			ptLoc.y = (int) ((double) m_ptOrigin.y - dLineHeight);


			// Draw line back to last data member.
			if (nSeries > 0 && (pSeries->GetData(nGroup)!=0 || dataLastLoc != 0)) {

				dc.MoveTo(ptLastLoc.x, ptLastLoc.y - 1);
				VERIFY(dc.LineTo(ptLoc.x - 1, ptLoc.y - 1));
			}

			// Now draw ellipse.
			CRect rcEllipse(ptLoc.x - 3, ptLoc.y - 3, ptLoc.x + 3, ptLoc.y + 3);
			if(pSeries->GetData(nGroup)!=0){
				VERIFY(dc.Ellipse(rcEllipse));
			}
			if (m_olMyGraphSeries.GetCount() < 40)
			{
				pSeries->SetTipRegion(nGroup, rcEllipse);
			}

			// Save last pt and data
			ptLastLoc = ptLoc;
			dataLastLoc = pSeries->GetData(nGroup);
		}
		VERIFY(dc.SelectObject(pPenOld));
		penLine.DeleteObject();
		VERIFY(dc.SelectObject(pBrushOld));
		br.DeleteObject();
	}

	int nMaxDataValue = max(GetMaxDataValue(), 1);
	double barTop = m_ptOrigin.y - (double)m_nYAxisHeight *
		(GetAverageDataValue() / (double)nMaxDataValue);
	dc.MoveTo(m_ptOrigin.x, barTop);
	VERIFY(dc.LineTo(m_ptOrigin.x + (m_nXAxisWidth - m_rcLegend.Width() - (GAP_PIXELS * 2)), barTop));
}