示例#1
0
// Paint the background of the progress bar region
void
ProgressBar::paintBackground( CDC &dc )
{
    CBrush brshBackground;
    CPen penGray( PS_SOLID, 1, RGB (128, 128, 128) );
    CPen penWhite( PS_SOLID, 1, RGB (255, 255, 255) );

    VERIFY( brshBackground.CreateSolidBrush( ::GetSysColor (COLOR_BTNFACE) ) );

    dc.FillRect( m_bounds, &brshBackground );

    CPen *pOldPen = dc.SelectObject( &penGray );
    int xRight = m_bounds.left + m_bounds.Width() -1;
    int yBottom = m_bounds.top + m_bounds.Height() -1;
    {
        dc.MoveTo( m_bounds.left, m_bounds.top );
        dc.LineTo( xRight, m_bounds.top );

        dc.MoveTo( m_bounds.left, m_bounds.top );
        dc.LineTo( m_bounds.left, yBottom );
    }

    dc.SelectObject( &penWhite );
    {
        dc.MoveTo( xRight, m_bounds.top );
        dc.LineTo( xRight, yBottom );

        dc.MoveTo( m_bounds.left, yBottom );
        dc.LineTo( xRight, yBottom );
    }

    dc.SelectObject( pOldPen );
}
示例#2
0
文件: mybutton.cpp 项目: jimodb/codes
void MyButton::paintEvent(QPaintEvent *e){
	/*绘制按钮的形状*/
	QPainter  g(this);
	int w=width();
	int h=height();
	QPoint pTop(w/2,2);
	QPoint pBottom(w/2,h-2);
	QPoint pLeft(2,h/2);
	QPoint pRight(w-2,h/2);
	QColor cWhite(255,255,255);
	QColor cBlack(  0,  0,  0);
	QBrush bWhite(cWhite);
	QBrush bBlack(cBlack);
	QPen	 penWhite(bWhite,2);
	QPen	 penBlack(bBlack,2);
	
	
	/*白色*/
	g.setPen(penWhite);
	g.drawLine(pTop,pLeft);
	g.drawLine(pTop,pRight);
	/*黑色*/
	g.setPen(penBlack);
	g.drawLine(pBottom,pLeft);
	g.drawLine(pBottom,pRight);
}
示例#3
0
bool SingleVarStats::OperateModelGraphic(CMdlGraphicWnd &Wnd, CMdlGraphic &Grf)
{
	const COLORREF White = COLORREF(RGB(255,255,255));
	const COLORREF Black = COLORREF(RGB(0,0,0));
	const COLORREF Blue  = COLORREF(RGB(0,0,255));
	const COLORREF Cyan  = COLORREF(RGB(0,255,255));
	const COLORREF Red   = COLORREF(RGB(255,0,0));
	const COLORREF Green = COLORREF(RGB(0,255,0));
	switch (Wnd.m_eTask)
	{
	case MGT_Create:
		Wnd.m_pWnd->SetWindowPos(NULL, 0, 0, 200, 200, SWP_NOMOVE | SWP_NOZORDER);
		break;
	case MGT_Size:
		Wnd.m_pWnd->Invalidate();
		break;
	case MGT_Move:
		break;
	case MGT_EraseBkgnd:
		Wnd.m_bReturn = 0;
		break;
	case MGT_Paint:
		Wnd.m_pPaintDC->FillSolidRect(Wnd.m_ClientRect, Black);
		Wnd.m_pPaintDC->SetTextColor(Green);
		CPen penWhite(PS_SOLID, 0, White);
		CPen penGreen(PS_SOLID, 0, Green);
		CPen penRed(PS_SOLID, 0, Red);
		CBrush brushRed(Red);
		int nTextSize = Wnd.m_TextSize.y;
		int nBorderSpace = nTextSize;
		int nTextSpace = 4;
		int nAxesSpace = 4;
#if (_MSC_VER >= 1400)
		int nTopSpace = nBorderSpace + nTextSize;
		int nAxesLeft = nBorderSpace + nTextSize + nTextSpace + nAxesSpace;
#else
		int nTopSpace = nBorderSpace + nTextSize + nAxesSpace;
		int nAxesLeft = nBorderSpace + nAxesSpace;
#endif
		int nCheckSize = nAxesSpace - 1;
		int minSpace = 10;
		//Draw axes:
		int nAxesTop = nTopSpace,
			nAxesBottom = Wnd.m_ClientRect.bottom - (nBorderSpace + 2 * nTextSize + nTextSpace + nAxesSpace),
			nAxesRight = Wnd.m_ClientRect.right - (nBorderSpace);
		if (nAxesBottom - nAxesTop <= 0 || nAxesRight - nAxesLeft <= 0)
			break;
		POINT axes[] = { 
			{nAxesLeft, nAxesTop},
			{nAxesLeft, nAxesBottom},
			{nAxesRight, nAxesBottom} };
		CPen* oldPen = Wnd.m_pPaintDC->SelectObject(&penGreen);
		Wnd.m_pPaintDC->Polyline(axes, 3);
		int nArrowSize = 3;
		POINT ArrowTop[] = {
			{nAxesLeft, nAxesTop - nArrowSize},
			{nAxesLeft - nArrowSize, nAxesTop},
			{nAxesLeft + nArrowSize, nAxesTop},
			{nAxesLeft, nAxesTop - nArrowSize} };
		POINT ArrowSide[] = {
			{nAxesRight + nArrowSize, nAxesBottom},
			{nAxesRight, nAxesBottom - nArrowSize},
			{nAxesRight, nAxesBottom + nArrowSize},
			{nAxesRight + nArrowSize, nAxesBottom} };
		Wnd.m_pPaintDC->Polygon(ArrowTop, 4);
		Wnd.m_pPaintDC->Polygon(ArrowSide, 4);

		//Draw blocks, and % values above blocks.
		float blockWidth = (float)(nAxesRight - nAxesLeft) / (lHistoCount + 2);
		int MaxCount = 0;
		for (int i = 0; i < lHistoCount + 2; i++)
			if (pHistoBucketCounts[i] > MaxCount) MaxCount = pHistoBucketCounts[i];
		int FullScale = (int)(MaxCount * 1.1);
		if (FullScale < 1) FullScale = 1; //Avoid divide by zero errors.
		int nAxesHeight = nAxesBottom - nAxesTop;
		if (MaxCount > 0)
		{
			Wnd.m_pPaintDC->SelectObject(&penRed);
			CBrush* oldBrush = Wnd.m_pPaintDC->SelectObject(&brushRed);

			Wnd.m_pPaintDC->SetTextAlign(TA_BOTTOM | TA_CENTER);

			for (int i = 0; i < lHistoCount + 2; i++)
			{
				if (i == 1)	{
					Wnd.m_pPaintDC->SelectObject(&penWhite);
					Wnd.m_pPaintDC->SelectObject(oldBrush);
				}
				if (i == lHistoCount + 1) {
					Wnd.m_pPaintDC->SelectObject(&penRed);
					Wnd.m_pPaintDC->SelectObject(&brushRed);
				}
				Wnd.m_pPaintDC->Rectangle(
					nAxesLeft + (int)(i*blockWidth),		nAxesBottom - (nAxesHeight * pHistoBucketCounts[i]) / FullScale, 
					nAxesLeft + (int)((i+1)*blockWidth),	nAxesBottom);

				if (lRecordsSinceHistoReset > 0)
				{
					double d = 100.0 * pHistoBucketCounts[i] / lRecordsSinceHistoReset;
					int perc = d - (int)d < 0.5 ? (int) d : (int) d + 1;
					CString percent; percent.Format("%i%%", perc);
					Wnd.m_pPaintDC->TextOut(nAxesLeft + (int)((i + 0.5)*blockWidth), nAxesBottom - (nAxesHeight * pHistoBucketCounts[i]) / FullScale - 1, percent);
				}
			}
			
			Wnd.m_pPaintDC->SelectObject(&penWhite);
			Wnd.m_pPaintDC->SelectObject(oldBrush);
		}

		//Draw checks and axis values:
		double offset = 0, scale = 1;
		if (TagCnvFamily[nTagCnvUsed].Valid())
		{
			offset = TagCnvFamily[nTagCnvUsed].Offset();
			scale = TagCnvFamily[nTagCnvUsed].Scale();
		}

		Wnd.m_pPaintDC->SetTextAlign(TA_TOP | TA_CENTER);
		Wnd.m_pPaintDC->SelectObject(&penGreen);
		int lastLabel = 0;
		for (int i = 1; i < lHistoCount + 2; i++)
		{
			POINT Checkline[] = {
				{nAxesLeft + (int)(i * blockWidth), nAxesBottom},
				{nAxesLeft + (int)(i * blockWidth), nAxesBottom + nCheckSize}};
			Wnd.m_pPaintDC->Polyline(Checkline, 2);
			
			CString value;
			if (pHistoBucketBorders[i] < 100) //Because the %.2g formatting doesn't work like it should
				value.Format("%.2g", pHistoBucketBorders[i] * scale + offset);
			else if (pHistoBucketBorders[i] < 1E4)
				value.Format("%.0f", pHistoBucketBorders[i] * scale + offset);
			else
				value.Format("%.1e", pHistoBucketBorders[i] * scale + offset);

			if (nAxesLeft + (int)(i * blockWidth) - lastLabel > Wnd.m_pPaintDC->GetTextExtent(value).cx / 2 + minSpace)
			{
				Wnd.m_pPaintDC->TextOut(nAxesLeft + (int)(i * blockWidth), nAxesBottom + nAxesSpace, value);
				lastLabel = nAxesLeft + (int)(i * blockWidth) + Wnd.m_pPaintDC->GetTextExtent(value).cx / 2;
			}
		}
		Wnd.m_pPaintDC->TextOut(nAxesLeft + (int)((0.5) * blockWidth), nAxesBottom + nAxesSpace + nTextSize, "UR");
		Wnd.m_pPaintDC->TextOut(nAxesLeft + (int)((lHistoCount + 1.5) * blockWidth), nAxesBottom + nAxesSpace + nTextSize, "OR");

		//Draw labels:
		CString xLabel, yLabel;
		if (TagCnvFamily[nTagCnvUsed].Valid() && strcmp(TagCnvFamily[nTagCnvUsed].Name(), "") != 0)
			xLabel.Format("Value (%s)", TagCnvFamily[nTagCnvUsed].Name());
		else
			xLabel.Format("Value");

		yLabel.Format("Count");
		
		Wnd.m_pPaintDC->SetTextAlign(TA_BOTTOM | TA_CENTER);
		Wnd.m_pPaintDC->TextOut((nAxesLeft + nAxesRight) / 2, Wnd.m_ClientRect.bottom - nBorderSpace, xLabel);
		
#if (_MSC_VER >= 1400)
		int oldMode = Wnd.m_pPaintDC->SetGraphicsMode(GM_ADVANCED);
		XFORM rotation = {
			0, -1,
			1, 0,
			0, 0};
		XFORM identity = {
			1, 0,
			0, 1,
			0, 0};
		BOOL setTransformResult = Wnd.m_pPaintDC->SetWorldTransform(&rotation);

		Wnd.m_pPaintDC->SetTextAlign(TA_TOP | TA_CENTER);
		Wnd.m_pPaintDC->TextOut(-(nAxesTop + nAxesBottom) / 2, nBorderSpace, yLabel);
		Wnd.m_pPaintDC->SelectObject(oldPen);

		Wnd.m_pPaintDC->SetWorldTransform(&identity);
		Wnd.m_pPaintDC->SetGraphicsMode(oldMode);
#else
		Wnd.m_pPaintDC->SetTextAlign(TA_TOP | TA_LEFT);
		Wnd.m_pPaintDC->TextOut(nAxesLeft, nBorderSpace, yLabel);
#endif
	}
	return true;
}
示例#4
0
bool Splitter::OperateModelGraphic(CMdlGraphicWnd & Wnd, CMdlGraphic & Grf)
  {
  const COLORREF White = COLORREF(RGB(255,255,255));
  const COLORREF Black = COLORREF(RGB(0,0,0));
  const COLORREF Blue  = COLORREF(RGB(0,0,255));
  const COLORREF Cyan  = COLORREF(RGB(0,255,255));
  const COLORREF Red   = COLORREF(RGB(255,0,0));
  const COLORREF Green = COLORREF(RGB(0,255,0));

  switch (Wnd.m_eTask)
    {
    case MGT_Create:
      break;
    case MGT_Size:
      break;
    case MGT_Move:
      break;
    case MGT_EraseBkgnd:
      // Use Wnd.m_pDC;
      Wnd.m_bReturn = 0;// 1 if erased else 0
      break; 
    case MGT_Paint:
      {
      double Total=0;
      int IOCnt = FlwIOs.getCount();
      if (IOCnt==3)
        {
        double M1=FlwIOs[1].Stream.MassFlow();
        double M2=FlwIOs[2].Stream.MassFlow();
        double Split=(M1)/GTZ(M1+M2);

        int charwide = Wnd.m_TextSize.x;

        int y0 = Wnd.m_ClientRect.top;
        int y1 = Wnd.m_TextSize.y+1;
        int y2 = Wnd.m_ClientRect.bottom;
        int x0 = Wnd.m_ClientRect.left;
        int xSplit = (int)(Split*Wnd.m_ClientRect.right);
        int x2 = Wnd.m_ClientRect.right;
        int y3 = 0;
        if (!bDoPhaseSplit)
          {
          y3=y1;
          y1+=Wnd.m_TextSize.y;
          }

        Wnd.m_pPaintDC->FillSolidRect(CRect(x0,y1,xSplit,y2), Blue);
        Wnd.m_pPaintDC->FillSolidRect(CRect(xSplit,y1,x2,y2), Cyan);

        Wnd.m_pPaintDC->FillSolidRect(CRect(x0,y0,x2,y1), Black);
        Wnd.m_pPaintDC->SetTextColor(Green);
        CString S;
        if (!bDoPhaseSplit && fabs(Split-dRqdFracSplit)>0.001)
          S.Format("%.1f %% (Rqd:%.1f %%)", Split*100.0, dRqdFracSplit*100.0);
        else
          S.Format("%.1f %%", Split*100.0);
        Wnd.m_pPaintDC->TextOut(x0,y0,S);

        if (!bDoPhaseSplit)
          {
          CPen penWhite(PS_SOLID, 0, White);
          CPen * oldPen=Wnd.m_pPaintDC->SelectObject(&penWhite);
          CBrush brushRed(Red);
          CBrush * oldBrush=Wnd.m_pPaintDC->SelectObject(&brushRed);

          int xSplitRqd = (int)(dRqdFracSplit*Wnd.m_ClientRect.right);

          POINT Arrow[] = 
            {
              {xSplitRqd,            y1},
              {xSplitRqd-charwide/2, y3},
              {xSplitRqd+charwide/2, y3},
              {xSplitRqd,            y1},
            };
          Wnd.m_pPaintDC->Polygon(Arrow, sizeof(Arrow)/sizeof(Arrow[0]));

          Wnd.m_pPaintDC->SelectObject(oldPen);
          Wnd.m_pPaintDC->SelectObject(oldBrush);
          }
        }
      else
        {
        int y0 = Wnd.m_ClientRect.top;
        int y2 = Wnd.m_ClientRect.bottom;
        int x0 = Wnd.m_ClientRect.left;
        int x2 = Wnd.m_ClientRect.right;
        Wnd.m_pPaintDC->FillSolidRect(CRect(x0,y0,x2,y2), Black);
        Wnd.m_pPaintDC->SetTextColor(Green);
        CString S;
        S.Format("Not Connected");
        Wnd.m_pPaintDC->TextOut(x0,y0,S);
        }

      break;
      }
    case MGT_MouseMove:
      m_LBtnDn=(Wnd.m_MouseFlags & MK_LBUTTON);
      if (m_LBtnDn && !bDoPhaseSplit)
        {
        m_MousePt=Wnd.m_MousePt;
        dRqdFracSplit = (double)m_MousePt.x/Wnd.m_ClientRect.right;
        Wnd.m_pWnd->RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW);
        }
      break;
    case MGT_LButtonDown:
      m_LBtnDn=true;
      if (!bDoPhaseSplit)
        {
        m_MousePt=Wnd.m_MousePt;
        dRqdFracSplit = (double)m_MousePt.x/Wnd.m_ClientRect.right;
        Wnd.m_pWnd->RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW);
        }
      break;
    case MGT_LButtonUp:
      m_LBtnDn=false;
      break;
    case MGT_RButtonDown:
      m_RBtnDn=true;
      break;
    case MGT_RButtonUp:
      m_RBtnDn=false;
      break;
    }
  return true; 
  };
示例#5
0
void ComediScope::paintData(float** buffer) {
	QPainter paint( this );
	QPen penData[3]={QPen(Qt::blue,1),
			 QPen(Qt::green,1),
			 QPen(Qt::red,1)};
	QPen penWhite(Qt::white,2);
	int w = width();
	int h = height();
	if (eraseFlag) {
		paint.fillRect(0,0,w,h,QColor(255,255,255));
		eraseFlag = 0;
		xpos = 0;
	}
	num_channels=0;

	for(int n=0;n<nComediDevices;n++) {
		for(int i=0;i<channels_in_use;i++) {
			if (comediRecord->channel[n][i]->isActive()) {
				num_channels++;	
			}
		}
	}
	if (!num_channels) {
		return;
	}
	int base=h/num_channels;
	if(w <= 0 || h <= 0) 
		return;
	paint.setPen(penWhite);
	int xer=xpos+5;
	if (xer>=w) {
		xer=xer-w;
	}
	paint.drawLine(xer,0,
		       xer,h);
	int act=1;
	for(int n=0;n<nComediDevices;n++) {
		float minV = crange[n]->min;
		float maxV = crange[n]->max;
		float dy=(float)base/(float)(maxV-minV);
		for(int i=0;i<channels_in_use;i++) {
			if (comediRecord->
			    channel[n][i]->
			    isActive()) {
				paint.setPen(penData[act%3]);
				float gain=comediRecord->gain[n][i]->getGain();
				float value = buffer[n][i] * gain;
				int yZero=base*act-(int)((0-minV)*dy);
				int yTmp=base*act-(int)((value-minV)*dy);
				ypos[n][i][xpos+1]=yTmp;
				paint.drawLine(xpos,ypos[n][i][xpos],
					       xpos+1,ypos[n][i][xpos+1]);
				if (xpos%2) {
					paint.drawPoint(xpos,yZero);
				}
				if ((xpos+2)==w) {
					ypos[n][i][0]=yTmp;
				}
				act++;
			}
		}
	}
	xpos++;
	if ((xpos+1)>=w) {
		xpos=0;
	}
}