zoukankan      html  css  js  c++  java
  • (3)一步一步开发一个简单CAD之画线

    (1)为了画线,则必需有一个存储实体的内存,同时为了实现捡选的功能,还必需存储一个捡选用的内存区

    用以下两个模版类实现,做为文档类的成员函数

    public://设定两个集合,选择集和实体集,同一个图形要么在选择集,要么在实体集
      CTypedPtrArray<CObArray, CSolid*>m_solid;
      CTypedPtrArray<CObArray, CSolid*>m_select;

    各种命令实际上是对这两个类的操作

    (2)为了画线,必需一个画线的命令类如下

    class CCreateLine : public CComand
    {
    public:
     CCreateLine();
     virtual ~CCreateLine();
    public:

        void OnLButtonDown(UINT nFlags,  CPosition pos);
        void OnMouseMove(UINT nFlags,  CPosition pos);
        void OnRButtonDown(UINT nFlags,  CPosition pos);

     
    private:
        CPosition m_begin;
     CPosition m_end;
     CEraseLine m_erase_line;//这个是像皮筋类

    };

    CCreateLine::CCreateLine()
    {
        m_nStep = 1;
     c_Refresh = g_Refresh;

    }

    CCreateLine::~CCreateLine()
    {

    }

    void CCreateLine::OnLButtonDown(UINT nFlags,  CPosition pos)
    {


     
       switch(m_nStep)
       {
     
       case 1://输出提示信息
       {
        
         CPosition center = pos;
          g_pDoc->DrawFlag(TRUE, pos, &center);//画标记,这个是为了实现捕捉功能
     
         m_end = m_begin = center;
     

        m_nStep++;
         m_erase_line.SetBegin(pos); //八个方向,并且如果在指定范围内,得到按下的点的坐标.实现像皮筋类
         break;
        
       }
        
        case 2:
       {

       CPosition center2 = pos;
        g_pDoc->DrawFlag(TRUE, pos, &center2);//画标记作用,画出矩形标记,center2取出替代值
       
       m_erase_line.SetBegin(pos);
             CDC *pDC = g_pView->GetDC();
           CLine *line = new CLine(m_begin, center2);
             line->DrawSolid(pDC, Normal);
             g_pDoc->m_solid.Add(line);
             m_nStep = 1;
           g_pView->ReleaseDC(pDC);

      }
       default:
          break;
      }
     
      
    }

    void CCreateLine::OnMouseMove(UINT nFlags,  CPosition pos)
    {


        CPosition center2;
         g_pDoc->DrawFlag(TRUE, pos, &center2);
        m_erase_line.SetEnd(pos);


       
    }

    void CCreateLine::OnRButtonDown(UINT nFlags,  CPosition pos)
    {

     m_erase_line.SetCancle(pos);//取消像皮筋
    }

  • 相关阅读:
    Http协议状态码总结
    ES6中的let和const
    Swiper-轮播图
    HTML5动画API—— requestAnimationFrame
    神奇的 conic-gradient 圆锥渐变
    最流行的5个前端框架对比
    jQuery适用技巧笔记整合
    PHP中的面向对象OOP中的魔术方法
    居中
    (function($){})(jQuery)
  • 原文地址:https://www.cnblogs.com/lizhengjin/p/1289210.html
Copyright © 2011-2022 走看看