Ejemplo n.º 1
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));
			}
		}
	}
}
Ejemplo n.º 2
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;
}
// WaveformViewDialog message handlers
void WaveformViewDialog::OnPaint() {
  BufferredPaintDC dc(this);
  
  CRect rectTitle;
  GetDlgItem(IDC_PLACE_CAPTION)->GetWindowRect(&rectTitle);
  ScreenToClient(&rectTitle);
  dc.FillSolidRect(rectTitle, RGB(54, 133, 214));

  CRect waveformRect;
  GetDlgItem(IDC_PLACE_WAVEFORM)->GetWindowRect(&waveformRect);
  ScreenToClient(&waveformRect);
  dc.FillSolidRect(waveformRect, RGB(0, 0, 0));

  CFont *oldFont = dc.SelectObject(GuiResources::GetInstance()->GetFont(GuiResources::FONT_NORMAL));
  dc.SetTextColor(RGB(255, 255, 255));
  dc.SetBkMode(TRANSPARENT);
  CSize textSize = dc.GetTextExtent(_T("88888"));
  waveformRect.left += textSize.cx + 8;

  if (monitor_ != NULL && cashIndex_ != -1) {
    int cashCount = monitor_->Freeze();
    if (cashIndex_ < cashCount) {
      Cash *cash = monitor_->GetCash(cashIndex_);
      CPen penYellow(PS_SOLID, 1, RGB(255, 255, 0));
      CPen penGreen(PS_SOLID, 1, RGB(0, 255, 0));
      int count = cash->GetADCSampleCount(g_ADCChannels[channel_].id);      
      if (count > 0) {
        CString title;
        title.Format(_T("%s - %s"), (LPCTSTR)CA2T(cash->GetSN()), g_ADCChannels[channel_].name);
        labelTitle_.SetWindowText(title);

        const short *codes = cash->GetADCSampleCodes(g_ADCChannels[channel_].id);
        const short *values = cash->GetADCSampleValues(g_ADCChannels[channel_].id);
        
        // draw scaler
        __int64 sum = 0;
        short minValue = SHORT_MAX, maxValue = SHORT_MIN;
        for (int i = 0; i < count; i++) {
          if (values[i] < minValue) {
            minValue = values[i];
          }
          if (values[i] > maxValue) {
            maxValue = values[i];
          }
          sum += values[i];
        }
        CPen whitePen(PS_SOLID, 1, RGB(255, 255, 255));
        CPen *oldPen = dc.SelectObject(&whitePen);
        dc.MoveTo(waveformRect.left, waveformRect.top);
        dc.LineTo(waveformRect.left, waveformRect.bottom);
        
        int height = waveformRect.Height();
        int range = g_ADCChannels[channel_].maxValue - g_ADCChannels[channel_].minValue;
        // min
        CString label;
        int x = waveformRect.left - textSize.cx - 8;
        int y = waveformRect.bottom - (minValue - g_ADCChannels[channel_].minValue) * height / range;
        dc.MoveTo(waveformRect.left - 4, y);
        dc.LineTo(waveformRect.right, y);
        label.Format(_T("%d"), minValue);
        dc.TextOut(x, y - textSize.cy / 2, label);
        // center
        short median = (short)(sum / count);
        y = waveformRect.bottom - (median - g_ADCChannels[channel_].minValue) * height / range;
        dc.MoveTo(waveformRect.left - 4, y);
        dc.LineTo(waveformRect.right, y);
        label.Format(_T("%d"), median);
        dc.TextOut(x, y - textSize.cy / 2, label);
        // max
        y = waveformRect.bottom - (maxValue - g_ADCChannels[channel_].minValue) * height / range;
        dc.MoveTo(waveformRect.left - 4, y);
        dc.LineTo(waveformRect.right, y);
        label.Format(_T("%d"), maxValue);
        dc.TextOut(x, y - textSize.cy / 2, label);

        dc.SelectObject(oldPen);

        ::DrawWaveform(&dc, waveformRect, codes, codes[0], codes[count - 1], count, &penYellow);
        ::DrawWaveform(&dc, waveformRect, values, 
            g_ADCChannels[channel_].minValue, 
            g_ADCChannels[channel_].maxValue, count, &penGreen);
      }
    }
    monitor_->Unfreeze();
  }

  dc.SelectObject(oldFont);
}