GraphHaveData.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:3k
源码类别:
P2P编程
开发平台:
Visual C++
- // GraphHaveData.cpp: implementation of the CGraphHaveData class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "testbt.h"
- #include "GraphHaveData.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CGraphHaveData::CGraphHaveData()
- {
- m_lPenWidth = 1;
- m_rc = CRect (0, 0, 100, 100);
- m_pParent = 0;
- }
- CGraphHaveData::~CGraphHaveData()
- {
- }
- BOOL CGraphHaveData::Create(CRect rc, CWnd* pParent)
- {
- m_pParent = pParent;
- m_rc = rc;
- return TRUE;
- }
- void CGraphHaveData::SetData(const vector<bool>& vData)
- {
- // m_vData = (const vector<long>& )vData;
- m_vData.clear();
- for (int i=0; i<vData.size(); i++)
- {
- m_vData.push_back((long)vData[i]);
- }
- OnSizeChange();
- if (!m_pParent)
- {
- ASSERT(false);
- return;
- }
- // CClientDC dc(m_pParent);
- // Draw(dc);
- }
- void CGraphHaveData::SetData(const vector<long>& vData)
- {
- m_vData = vData;
- OnSizeChange();
- if (!m_pParent)
- {
- ASSERT(false);
- return;
- }
- CClientDC dc(m_pParent);
- Draw(dc);
- }
- void CGraphHaveData::SetSize(CRect rc)
- {
- m_rc = rc;
- OnSizeChange();
- if (!m_pParent) return;
- CClientDC dc(m_pParent);
- Draw(dc);
- }
- void CGraphHaveData::OnSizeChange()
- {
- m_vShowData.clear();
- int iCount = m_vData.size();
- if (!iCount || m_rc.Width() <= 0) return;
- long lSubCount = 1;
- m_lPenWidth = 1;
- long lOffset = 0;
- long lItemCount = 0;
- if (iCount <= m_rc.Width())
- {
- lItemCount = iCount;
- m_lPenWidth = m_rc.Width() / iCount;
- if (m_rc.Width() % iCount)
- lOffset = (m_rc.Width() - (m_rc.Width() % iCount))/ (m_rc.Width() % iCount);
- }
- else
- {
- lItemCount = m_rc.Width();
- lSubCount = iCount / m_rc.Width();
- // if (iCount % rc.Width())
- // lSubCount++;
- }
- int iLeft = 0;
- for (int i=0; i<lItemCount; i++)
- {
- long lValue = 1;
- for (int j=0; j<lSubCount; j++)
- {
- long inx = i*lSubCount + j;
- if (m_vData[inx] == 0)
- {
- lValue = 0;
- break;
- }
- if (m_vData[inx] == 2)
- lValue = 2;
- }
- m_vShowData.push_back(lValue);
- if (lOffset && i % lOffset == 0)
- {
- m_vShowData.push_back(lValue);
- }
- }
- }
- void CGraphHaveData::Draw(CDC& dc, CPoint ptOffset)
- {
- CRect rc = m_rc;
- rc.OffsetRect(ptOffset);
- for (int i=0;i<m_vShowData.size(); i++)
- {
- COLORREF col = RGB(10, 36, 106);
- if (m_vShowData[i] == 2)
- col = RGB(249, 152, 111);
- else if (m_vShowData[i] == 0)
- col = RGB(255, 255, 255);
- if (m_lPenWidth <= 1)
- {
- CPen curPen;
- curPen.CreatePen(PS_SOLID, m_lPenWidth, col);
- CPen* pOldPen = dc.SelectObject(&curPen);
- dc.MoveTo(rc.left + i * m_lPenWidth, rc.top );
- dc.LineTo(rc.left + i * m_lPenWidth, rc.bottom );
- dc.SelectObject(pOldPen);
- }
- else
- {
- CRect rcFill = CRect(rc.left + i * m_lPenWidth, rc.top, rc.left + (i+1) * m_lPenWidth, rc.bottom);
- // rcFill.DeflateRect(1, 1);
- dc.FillRect(rcFill, &CBrush(col));
- // dc.Draw3dRect(rc.left + i * m_lPenWidth, rc.top, m_lPenWidth, rc.Height(), col,RGB(0,0,0));
- }
- }
- dc.Draw3dRect(rc, RGB(0,0,0), RGB(0,0,0));
- }