示例#1
0
文件: progbar.cpp 项目: vata/xarino
void CProgressBar::DoPaint(CDC* pDC)
// Paints the bar, assuming that the background has already been cleared to grey.
// The bar has a percentage display on the left, followed by a progress bar
// which is sized to fit the available space up to a maximum of MAXBARWIDTH pixels
// If there is enough room, the current Job Description will also be displayed, to
// the right of the bar.
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDC);

	CControlBar::DoPaint(pDC);      // draw border

	CRect rect;
	GetClientRect(rect);
	CalcInsideRect(rect);

	ASSERT(m_hFont != NULL);
	CFont *OurFont = CHECKFONT(CFont::FromHandle(m_hFont));		// Get a CFont* for this HFONT
	CFont *OldFont = CHECKFONT(pDC->SelectObject(OurFont));

	rect.InflateRect(-CX_BORDER, -CY_BORDER);

	CString PercentText("00%");							// Generate %age string
	if (CurrentPercent > 0 && CurrentPercent < 100)
	{
		if (CurrentPercent > 9)
			PercentText.SetAt(0, (CurrentPercent / 10) + '0');
		PercentText.SetAt(1, (CurrentPercent % 10) + '0');
	}

	pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));		// Draw %age string
	pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));
	pDC->SetBkMode(OPAQUE);
	SetTextAlign(pDC->m_hDC, TA_LEFT | TA_BOTTOM);
	pDC->TextOut(rect.left, rect.bottom, PercentText);

	CSize TextSize = pDC->GetTextExtent(PercentText, 3);

	INT32 BarStart = rect.left + TextSize.cx + 4;			// Calc bar position, size
	INT32 WindowEnd = rect.right - 4;
	INT32 BarWidth = WindowEnd - BarStart;
	
	if (BarWidth < 10) return;		// Not enough room to do a bar!

	if (BarWidth > MAXBARWIDTH) BarWidth = MAXBARWIDTH;

	if (JobDescription != NULL && WindowEnd - BarStart > MAXBARWIDTH + 64)
	{	// If enough room for some text, add the job description
		CString OutText = TEXT(*JobDescription);

		rect.left = BarStart + BarWidth + 4;
		rect.right = WindowEnd;
		pDC->TextOut(rect.left, rect.bottom, OutText);
	}

	CHECKFONT(pDC->SelectObject(OldFont));	// Restore previous font 

	rect.left = BarStart;				// Finally, calc and paint the bar,,,
	rect.right = BarStart+BarWidth;
	rect.bottom -= m_FontDescent - 2;	// Line up bar bottom with text baseline
	Paint3dPlinth(pDC, &rect, FALSE);
	
	BarWidth -= 4;						// Bar is 2 pixels inside plinth rectangle
	rect.left = BarStart + 2;
	rect.top += 2;
	rect.bottom -= 2;
	rect.right = rect.left + (INT32) (((WORD)BarWidth * (WORD)CurrentPercent) / 100);

	CBrush BlueBrush(RGB(0,0,255));
	pDC->FillRect(rect, &BlueBrush);
}
示例#2
0
void CNodeChart::DrawBarChart(CDC *pDC)
{
	if(m_dTotal < 0.000001)
	{
	AfxMessageBox("error in drawing bar chart.");
	return;
	}

	int iValues	= m_ChartValues.GetSize();
	int iColors	= MAX_PIE_SIZE;
	CString str;

	CRect rect = m_DrawRect;
	CRect reBar;

	CNSChartValue* pTmp;

    double t = 1.0L;
	if(m_dMax >= 1.0L)
	{
		str.Format("%.0f",m_dMax);
		int d = 1;
		for(int i = 0;i<str.GetLength()-1;i++) d*=10;
		t = max((((double)str.GetAt(0)-48)+1)*d,m_dMax);
	}else
	{
	t = m_dMax;
	}
	
	rect.DeflateRect(40,30,20,20);
	
	CRect rcBar;
	rcBar.left   =  5; 
	rcBar.right  = rcBar.left + 30; 
	rcBar.top    = 25;
	rcBar.bottom = rcBar.top + 15;
	int i = rect.Height();

	CFont *oldFont = pDC->SelectObject(&m_txtFont);

	pDC->MoveTo(rect.left - 7,rect.top);
	pDC->LineTo(rect.left + 7,rect.top);
	
	str.Format((t<1.0)?("%.1f"):("%.0f"),t);
	pDC->DrawText(str,rcBar,DT_RIGHT);
	
	pDC->MoveTo(rect.left - 5,rect.top + i/4);
	pDC->LineTo(rect.left + 5,rect.top + i/4);

	pDC->MoveTo(rect.left - 7,rect.top + i/2);
	pDC->LineTo(rect.left + 7,rect.top + i/2);
	
	str.Format((t<1.0)?("%.1f"):("%.0f"),t/2);
	rcBar.top    = rect.top + (int)(i/2);
	rcBar.bottom = rcBar.top + 15;
	pDC->DrawText(str,rcBar,DT_RIGHT);

	pDC->MoveTo(rect.left - 5,rect.top + i*3/4);
	pDC->LineTo(rect.left + 5,rect.top + i*3/4);

	rcBar = rect;
	rcBar.DeflateRect(0,10,0,0);

	pDC->MoveTo(rect.left  -15, rect.bottom);
	pDC->LineTo(rect.right +15, rect.bottom);

	pDC->MoveTo(rect.left , rect.top    -15);
	pDC->LineTo(rect.left , rect.bottom +15);

	int scale = rcBar.Width()/iValues;
	int height = rcBar.Height();
	CRect tmpRect;
	
	for ( i = 0; i < iValues; i++ )
	{
		pTmp = m_ChartValues.GetAt(i);
		rcBar.left  = rect.left + scale*i + 2;
		rcBar.right = rcBar.left + max(1,scale - 4);
		rcBar.top = (rcBar.bottom - (long)(pTmp->m_dValue*height/t));
		rcBar.bottom = rect.bottom+1;

		//Drawing bar's

		CBrush BlueBrush(RGB(0, 0, 255));
		pDC->SelectObject(BlueBrush);
		pDC->Rectangle(rcBar);

		//Drawing top text percents
		tmpRect = rcBar;
		tmpRect.bottom = tmpRect.top - 1;
		tmpRect.top = tmpRect.bottom - 15;

		if(m_bShowPercentage)
			str.Format("%.1f%%",100*pTmp->m_dValue/m_dTotal);
		else
		{
			if(m_bIntegerValue)
				str.Format("%5d",(int)(pTmp->m_dValue));
			else
				str.Format("%5.2f",pTmp->m_dValue);
		}

		
		if(m_iCurSel == i)
		{
			CFont *tmpFont = pDC->SelectObject(&m_boldFont);			
			pDC->DrawText(str,tmpRect,DT_BOTTOM|DT_CENTER);
			pDC->SelectObject(tmpFont);
		}else{
			pDC->DrawText(str,tmpRect,DT_BOTTOM|DT_CENTER);
		} 

/*
		//Drawing bar text values
		tmpRect.top    = rcBar.top + 2;
		tmpRect.bottom = tmpRect.top + 15;
		str.Format((t<1.0)?("%.1f"):("%.0f"),pTmp->m_dValue);
		pDC->Rectangle(tmpRect);
		tmpRect.top += 1;
		pDC->DrawText(str,tmpRect,DT_BOTTOM|DT_CENTER);
*/

		//Drawing bottom text labels
		tmpRect.top		= rcBar.bottom + 2;
		tmpRect.bottom  = tmpRect.top + 15;
		pDC->DrawText(pTmp->m_sLabel,tmpRect,DT_CENTER);
	}

	pDC->SelectObject(oldFont);
}
void CDBPickView::DrawWaveforms()
	{
	CWaitCursor wc;

	this->pRTDisplay->Critical.Lock();

	RECT rc;
    CDC MemDC;
    CDC *pDC=GetDC();
	CBitmap Bitmap1;

	CalculateWindowsSize();


	rc.left=rc.top=0;
	rc.right=MaxX;
	rc.bottom=MaxY;

    Bitmap1.CreateCompatibleBitmap(pDC,rc.right,rc.bottom);
    MemDC.CreateCompatibleDC(pDC);
	ReleaseDC(pDC);

    CBitmap *poldBMP=MemDC.SelectObject(&Bitmap1);

    CBrush WhiteBrush(RGB(255,255,255));
    CBrush GrayBrush(RGB(192,192,192));
    CBrush BlueBrush(RGB(0,0,128));

    CPen WhitePen(PS_SOLID,1,RGB(255,255,255));
	CPen DarkPen(PS_SOLID,1,RGB(0,0,0));
    CPen BluePen(PS_SOLID,1,RGB(0,0,255));
    CPen YellowPen(PS_SOLID,1,RGB(255,255,0));

    CPen WhitePen2(PS_SOLID,2,RGB(255,255,255));
    CPen GrayPen2(PS_SOLID,2,RGB(128,128,128));


    CPen   *oldPen=MemDC.GetCurrentPen();
    CFont  *oldFont=MemDC.GetCurrentFont();
    CBrush *oldBrush=MemDC.GetCurrentBrush();


	MemDC.SetBkMode(TRANSPARENT);

	MemDC.FillRect(&rc, &BlueBrush);
	MemDC.SelectObject(CFont::FromHandle((HFONT)GetStockObject(ANSI_VAR_FONT)));

	MemDC.SelectObject(&DarkPen);
	MemDC.MoveTo(0,0);		
	MemDC.LineTo(0,MaxY);

	DrawTimePanel(&MemDC);

	for(int i=0; i<WaveformInfo.GetSize(); ++i)
		{
		DrawWindow(i,&MemDC);
		}



    MemDC.SelectObject(poldBMP);
    MemDC.SelectObject(oldPen);
    MemDC.SelectObject(oldBrush);
    MemDC.SelectObject(oldFont);
	MemDC.DeleteDC();
	this->pRTDisplay->Critical.Unlock();

	ScreenBitmapCriticalSection.Lock();
    if(Bitmap.m_hObject!=NULL) 
		{
		Bitmap.DeleteObject();
		}
	HGDIOBJ pBmp=Bitmap1.Detach();
	Bitmap.Attach(pBmp);
	ScreenBitmapCriticalSection.Unlock();

	InvalidateRect(NULL,FALSE);

	}
void CDBPickView::DrawWindow(int nWindow, CDC *pDC)
	{

    CBrush WhiteBrush(RGB(255,255,255));
    CBrush GrayBrush(RGB(192,192,192));
    CBrush BlueBrush(RGB(0,0,128));

    CPen WhitePen(PS_SOLID,1,RGB(255,255,255));
	CPen DarkPen(PS_SOLID,1,RGB(0,0,0));
    CPen BluePen(PS_SOLID,1,RGB(0,0,255));
    CPen YellowPen(PS_SOLID,1,RGB(255,255,0));


	int xw1=WaveformInfo[nWindow]->xw1;
	int xw2=WaveformInfo[nWindow]->xw2;
	int yw1=WaveformInfo[nWindow]->yw1;
	int yw2=WaveformInfo[nWindow]->yw2;

	int x1=WaveformInfo[nWindow]->x1;
	int x2=WaveformInfo[nWindow]->x2;
	int y1=WaveformInfo[nWindow]->y1;
	int y2=WaveformInfo[nWindow]->y2;



	long amin=WaveformInfo[nWindow]->amin;
	long amax=WaveformInfo[nWindow]->amax;



    CPen   *oldPen=pDC->GetCurrentPen();
    CFont  *oldFont=pDC->GetCurrentFont();
    CBrush *oldBrush=pDC->GetCurrentBrush();



	CRect rc(xw1, MaxY-yw2, xw2, MaxY-yw1);
	pDC->FillRect(&rc, &BlueBrush);

	pDC->SelectObject(&DarkPen);

//***********************************************************

	pDC->SelectObject(&WhitePen);

	pDC->MoveTo(xw1,MaxY-yw2);		
	pDC->LineTo(xw2,MaxY-yw2);

	pDC->MoveTo(xw1,MaxY-yw2);		
	pDC->LineTo(xw1,MaxY-yw1);

	pDC->MoveTo(xw1+1,MaxY-yw2);		
	pDC->LineTo(xw1+1,MaxY-yw1);


	pDC->SelectObject(&DarkPen);

	pDC->MoveTo(xw2,MaxY-yw1);		
	pDC->LineTo(xw2,MaxY-yw2);

	pDC->MoveTo(xw2,MaxY-yw1);		
	pDC->LineTo(xw1,MaxY-yw1);


	pDC->SelectObject(&DarkPen);

	pDC->MoveTo(xw1+WindowInfoXsize,MaxY-yw1);		
	pDC->LineTo(xw1+WindowInfoXsize,MaxY-yw2);

	pDC->SelectObject(&WhitePen);

	pDC->MoveTo(xw1+WindowInfoXsize+1,MaxY-yw1);		
	pDC->LineTo(xw1+WindowInfoXsize+1,MaxY-yw2);

	pDC->MoveTo(xw1+WindowInfoXsize+2,MaxY-yw1);		
	pDC->LineTo(xw1+WindowInfoXsize+2,MaxY-yw2);

//*************************************************************
//      Draw Ampl (Y) Axis
//

	CRect rc1(xw1, MaxY-yw2, xw1+WindowInfoXsize-1, MaxY-yw1);
	pDC->FillRect(&rc1, &GrayBrush);


	pDC->SelectObject(&DarkPen);
	pDC->SetTextColor(RGB(0,0,0));

	pDC->MoveTo(xw1+WindowInfoXsize-8,MaxY-(yw1+8));		
	pDC->LineTo(xw1+WindowInfoXsize-8,MaxY-(yw2-8));

	pDC->MoveTo(xw1+WindowInfoXsize-8,MaxY-(yw1+8));
	pDC->LineTo(xw1+WindowInfoXsize-8+4,MaxY-(yw1+8));

	pDC->MoveTo(xw1+WindowInfoXsize-8,MaxY-(yw2-8));
	pDC->LineTo(xw1+WindowInfoXsize-8+4,MaxY-(yw2-8));

	pDC->SelectObject(&WhitePen);

	{
	RECT rcText;
	char cText[64];
	sprintf(cText,"%d",amax);

	CRect rcc1(xw1,MaxY-(yw2-8),xw1+WindowInfoXsize-8-2, MaxY-(yw2-8-13));

	pDC->DrawText(cText,rcc1,DT_RIGHT);

	sprintf(cText,"%d",amin);
	GetTextRectangle(cText, rcText);

	CRect rcc2(xw1,MaxY-(yw1+8+13),xw1+WindowInfoXsize-8-2, MaxY-(yw1-8));
	pDC->DrawText(cText,rcc2,DT_RIGHT);

	CRect rcc3(xw1+5,(MaxY-yw2),xw1+WindowInfoXsize-8-2, (MaxY-yw1));
	sprintf(cText,"%s::%s",WaveformInfo[nWindow]->StaName, WaveformInfo[nWindow]->ChanName);
	pDC->DrawText(cText,rcc3,	DT_VCENTER|DT_SINGLELINE );

	}

//**************************************************************

	int nXferBlocks=this->pRTDisplay->WaveformInfo[nWindow]->xferData.GetSize();
	double ttt=-1.;
	double dSpS=WaveformInfo[nWindow]->dSpS;

	pDC->SelectObject(&YellowPen);

	for(int j=0; j<nXferBlocks; ++j)
		{
		CDataBlock *xfd=this->pRTDisplay->WaveformInfo[nWindow]->xferData[j];
		double t1packet=this->pRTDisplay->WaveformInfo[nWindow]->xferData[j]->beg;
		double t2packet=this->pRTDisplay->WaveformInfo[nWindow]->xferData[j]->end;
		int nsamp=this->pRTDisplay->WaveformInfo[nWindow]->xferData[j]->nsamp;


		for(int k=0; k<nsamp; ++k)
			{
			long a=this->pRTDisplay->WaveformInfo[nWindow]->xferData[j]->data[k];
			double tt=t1packet+(1./dSpS)*k;
			int x,y;

			if(tt<t1) continue;
			if(tt>t2) break;

			x=(int)((tt-t1)*(x2-x1)/(t2-t1)+x1);

			if(a>amax) a=amax;
			if(a<amin) a=amin;

			y=(a-amin)*(y2-y1)/(amax-amin)+y1;
			y=MaxY-y;
			if(tt-ttt>1.1/dSpS)
				{
				pDC->MoveTo(x,y);		
				}
			else
				{
				pDC->LineTo(x,y);		
				}
			ttt=tt;
			}
		}
	DrawGaps(nWindow,pDC);
    pDC->SelectObject(oldPen);
    pDC->SelectObject(oldBrush);
    pDC->SelectObject(oldFont);

	}
void CPreview::DrawPreviewBitmap()
	{
	if(!bContinue) return;


	MaxX=width();
	MaxY=height();
	QPixmap tmpBitmap(MaxX, MaxY);
	QPainter DC(&tmpBitmap);
	QRect rc=rect();

	x1=4;
	x2=MaxX-4;
	y1=4;
	y2=MaxY-4;

	xw1=1;
	xw2=MaxX;
	yw1=0;
	yw2=MaxY;


    QBrush WhiteBrush(QColor(255,255,255));
    QBrush GrayBrush(QColor(192,192,192));
    QBrush BlueBrush(QColor(0,0,255));

    QPen WhitePen(QColor(255,255,255));
	QPen DarkPen(QColor(0,0,0));
    QPen BluePen(QColor(0,0,255));
    QPen YellowPen(QColor(255,255,0));
    QPen WhitePen2(QColor(255,255,255),2);
    QPen GrayPen2(QColor(128,128,128),2);


//********************************************************************
	DC.setPen(BluePen);
	DC.fillRect(rc, BlueBrush);
//	DC.SelectObject(CFont::FromHandle((HFONT)GetStockObject(ANSI_VAR_FONT)));


	int xl=(int)((pDisplay->t1 - pDisplay->tB1)*(x2-x1)/(pDisplay->tB2-pDisplay->tB1)+x1+0.5);
	int xr=(int)((pDisplay->t2 - pDisplay->tB1)*(x2-x1)/(pDisplay->tB2-pDisplay->tB1)+x1+0.5);

	DC.setPen(WhitePen2);

	DC.moveTo(xw1,MaxY-yw2);		
	DC.lineTo(xw2,MaxY-yw2);

	DC.moveTo(xw1,MaxY-yw2);		
	DC.lineTo(xw1,MaxY-yw1);

	DC.setPen(GrayPen2);

	DC.moveTo(xw2,MaxY-yw1);		
	DC.lineTo(xw2,MaxY-yw2);

	DC.moveTo(xw2,MaxY-yw1);		
	DC.lineTo(xw1,MaxY-yw1);

	DrawWaveform(DC);
	
	DC.setPen(WhitePen2);
	DC.moveTo(xl,MaxY-y1);		
	DC.lineTo(xr,MaxY-y1);
	DC.lineTo(xr,MaxY-y2);		
	DC.lineTo(xl,MaxY-y2);		
	DC.lineTo(xl,MaxY-y1);		


//********************************************************************

	ScreenBitmapCriticalSection.lock();
	Bitmap=tmpBitmap;
	bDrawBitmap=TRUE;
	ScreenBitmapCriticalSection.unlock();
	repaint(FALSE);
	}