WEB开发网
开发学院软件开发VC 一个工业控制管道流动控件的实现 阅读

一个工业控制管道流动控件的实现

 2010-07-11 20:44:38 来源:WEB开发网   
核心提示:剩下来的就是我们实现滑块的位置控制了,我们可以采用一个简单的实现方法,一个工业控制管道流动控件的实现(4),比如采用每个定时器到达的时候移动几个像素点的方法,通过向管道里面的滑块刘表传递下一个区域就可以了,宽等信息计算管道可以容纳的滑块数量和位置,void CFlowImpl::InitFlowUnit(){CRect

剩下来的就是我们实现滑块的位置控制了。我们可以采用一个简单的实现方法,比如采用每个定时器到达的时候移动几个像素点的方法,通过向管道里面的滑块刘表传递下一个区域就可以了。当这个区域处于滑出去的区域时候,我们自动销毁这个滑块对象,然后重新添加一个滑块对象到最开始的地方就可以了。 我们将在FlowImpl中定义一个CList<CFlowUnit *, CFlowUnit *> m_arrayFlowUnit;链表,然后在初始化的时候通过滑块的长,宽等信息计算管道可以容纳的滑块数量和位置。void CFlowImpl::InitFlowUnit()
{
  CRect rcUnit, rcClient;
  m_pOwer->GetClientRect(&rcClient);
  m_arrayFlowUnit.RemoveAll();
  if (m_pOwer->GetDirectionType() == LEFT_TO_RIGHT
    || m_pOwer->GetDirectionType() == RIGHT_TO_LEFT)
  {
    int nUnits = rcClient.Width() / (UNIT_WIDTH + UNIT_DISC);
    int nResidue = (rcClient.bottom - rcClient.top) % 2;
    int yCenter = (rcClient.bottom - rcClient.top) / 2;
    for (int i=0; i<nUnits; i++)
    {    
      rcUnit.SetRect(rcClient.left + i * (UNIT_WIDTH + UNIT_DISC),
        yCenter - UNIT_HEIGHT / 2,
        rcClient.left + i * (UNIT_WIDTH + UNIT_DISC) + UNIT_WIDTH,
        yCenter + UNIT_HEIGHT / 2 + nResidue);

      CFlowUnit *pFlowUnit = new CFlowUnit();
      pFlowUnit->SetRect(rcUnit);
      pFlowUnit->SetParentWnd(this);
      m_arrayFlowUnit.AddTail(pFlowUnit);
    }
  }
  else
  {
    int nUnits = rcClient.bottom / (UNIT_WIDTH + UNIT_DISC);
    int nResidue = (rcClient.right - rcClient.left) % 2;
    int xCenter = (rcClient.right - rcClient.left) / 2;
    for (int i=0; i<nUnits; i++)
    {    
      rcUnit.SetRect(xCenter - UNIT_HEIGHT / 2,
        rcClient.top + i * (UNIT_WIDTH + UNIT_DISC),
        xCenter + UNIT_HEIGHT / 2 + nResidue,
        rcClient.top + i * (UNIT_WIDTH + UNIT_DISC) + UNIT_WIDTH);

      CFlowUnit *pFlowUnit = new CFlowUnit();
      pFlowUnit->SetRect(rcUnit);
      pFlowUnit->SetParentWnd(this);
      m_arrayFlowUnit.AddTail(pFlowUnit);
    }
  }
}

然后通过定时器到达的时候动态计算链表滑块的每个对象的下一个要显示的CRect,然后进行管道背景刷新就可以完成了。

void CFlowImpl::CalculateFlowUnit()
{
  CRect rcClient;
  m_pOwer->GetClientRect(&rcClient);
  int xResidue = (rcClient.right - rcClient.left) % 2;
  int xCenter = (rcClient.right - rcClient.left) / 2;
  int yCenter = (rcClient.bottom - rcClient.top) / 2;
  int yResidue = (rcClient.bottom - rcClient.top) % 2;
  POSITION pos = m_arrayFlowUnit.GetHeadPosition();
  while (pos != NULL)
  {
    CFlowUnit *pFlowUnit = m_arrayFlowUnit.GetAt(pos);
    //从左至右
    if (m_pOwer->GetDirectionType() == LEFT_TO_RIGHT)
    {
      CRect rcUnit = pFlowUnit->GetRect();
      rcUnit.DeflateRect(UNIT_STEP, 0, -UNIT_STEP, 0);
      pFlowUnit->SetRect(rcUnit);

      if (rcUnit.left >= rcClient.right)
      {
        pFlowUnit = m_arrayFlowUnit.GetHead();

        CRect rcAddUnit;
        rcAddUnit.SetRect(pFlowUnit->GetRect().left - UNIT_DISC - UNIT_WIDTH,
         yCenter - UNIT_HEIGHT / 2,
         pFlowUnit->GetRect().left - UNIT_DISC,
         yCenter + UNIT_HEIGHT / 2 + yResidue);
        CFlowUnit *pAddFlowUnit = new CFlowUnit();
        pAddFlowUnit->SetRect(rcAddUnit);
        pAddFlowUnit->SetParentWnd(this);
        m_arrayFlowUnit.AddHead(pAddFlowUnit);

        m_arrayFlowUnit.RemoveAt(pos);
        break;
      }
    }
    //从右至左
    else if (m_pOwer->GetDirectionType() == RIGHT_TO_LEFT)
    {
      CRect rcUnit = pFlowUnit->GetRect();
      rcUnit.DeflateRect(-UNIT_STEP, 0, +UNIT_STEP, 0);
      pFlowUnit->SetRect(rcUnit);

      if (rcUnit.right <= rcClient.left)
      {
        pFlowUnit = m_arrayFlowUnit.GetTail();

        CRect rcAddUnit;
        rcAddUnit.SetRect(pFlowUnit->GetRect().right + UNIT_DISC,
         yCenter - UNIT_HEIGHT / 2,
         pFlowUnit->GetRect().right + UNIT_DISC + UNIT_WIDTH,
         yCenter + UNIT_HEIGHT / 2 + yResidue);
        CFlowUnit *pAddFlowUnit = new CFlowUnit();
        pAddFlowUnit->SetRect(rcAddUnit);
        pAddFlowUnit->SetParentWnd(this);
        m_arrayFlowUnit.AddTail(pAddFlowUnit);

        m_arrayFlowUnit.RemoveAt(pos);
        break;
      }
    }
    //从上至下
    else if (m_pOwer->GetDirectionType() == TOP_TO_BOTTOM)
    {
      CRect rcUnit = pFlowUnit->GetRect();
      rcUnit.DeflateRect(0, UNIT_STEP, 0, -UNIT_STEP);
      pFlowUnit->SetRect(rcUnit);

      if (rcUnit.top >= rcClient.bottom)
      {
        pFlowUnit = m_arrayFlowUnit.GetHead();

        CRect rcAddUnit;
        rcAddUnit.SetRect(xCenter - UNIT_HEIGHT / 2,
         pFlowUnit->GetRect().top - UNIT_DISC - UNIT_WIDTH,
         xCenter + UNIT_HEIGHT / 2 + xResidue,
         pFlowUnit->GetRect().top - UNIT_DISC);
        CFlowUnit *pAddFlowUnit = new CFlowUnit();
        pAddFlowUnit->SetRect(rcAddUnit);
        pAddFlowUnit->SetParentWnd(this);
        m_arrayFlowUnit.AddHead(pAddFlowUnit);

        m_arrayFlowUnit.RemoveAt(pos);
        break;
      }
    }
    //从下至上
    else if (m_pOwer->GetDirectionType() == BOTTOM_TO_TOP)
    {
      CRect rcUnit = pFlowUnit->GetRect();
      rcUnit.DeflateRect(0, -UNIT_STEP, 0, +UNIT_STEP);
      pFlowUnit->SetRect(rcUnit);

      if (rcUnit.bottom <= rcClient.top)
      {
        pFlowUnit = m_arrayFlowUnit.GetTail();

        CRect rcAddUnit;
        rcAddUnit.SetRect(xCenter - UNIT_HEIGHT / 2,
         pFlowUnit->GetRect().bottom + UNIT_DISC,
         xCenter + UNIT_HEIGHT / 2 + xResidue,
         pFlowUnit->GetRect().bottom + UNIT_DISC + UNIT_WIDTH);
        CFlowUnit *pAddFlowUnit = new CFlowUnit();
        pAddFlowUnit->SetRect(rcAddUnit);
        pAddFlowUnit->SetParentWnd(this);
        m_arrayFlowUnit.AddTail(pAddFlowUnit);

        m_arrayFlowUnit.RemoveAt(pos);
        break;
      }
    }
    m_arrayFlowUnit.GetNext(pos);
  }
}

上一页  1 2 3 4 5  下一页

Tags:一个 工业控制 管道

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接