Example #1
0
        /**
         * @brief 화면에서 마우스를 이동하는 이벤트의 Handler
         * @author 박성식
         * @date 2016-11-12
         * @remark 선택 도형 좌표 표시 가능하도록 수정
         * @param sender 사용되지 않음
         * @param e Mouse 이벤트에 대한 정보
         * @code
         *  int x = e.X;
         *  int y = e.Y;
         *  //박성식 161112
         *  //선택 도형 좌표 표시 가능하도록 수정
         *  Figure f = doc.findFigureByPoint(x, y);
         *  if (f != null && f.getVectorElementAt(0) is Rect)
         *  {
         *      Rect r = f.getVectorElementAt(0) as Rect;
         *      lblPosition.Text = (string.Format("X:{0},Y:{1}", r.getLeft(), r.getTop()));
         *  }
         *  else
         *      lblPosition.Text = "";
         *
         *  if (this.Capture == false)
         *      return;
         *
         *  switch (doc.getCurrentTool())
         *              {
         *      case FIGURE.ARROW:
         *          if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) doc.setIsMultSel(true);
         *          else doc.setIsMultSel(false);
         *          if (doc.getIsMultSel() == false)
         *          {
         *              if (doc.getCurrentFigure() != null)
         *              {
         *                  // 한번만 수행되도록한다.
         *                  if (isChanged == false)
         *                  {
         *                      doc.pushStack();
         *                      isChanged = true;
         *                  }
         *
         *                  // 이전의 드래그 되었던 좌표에서 얼마만큼 이동했는지를 구하여
         *                  // 그만 큼 이동시킨다.
         *                  doc.getCurrentFigure().move(x - drag_off_x, y - drag_off_y);
         *
         *                  // 현재의 좌표를 저장시켜 둔다.
         *                  drag_off_x = x;
         *                  drag_off_y = y;
         *
         *                  // 스택에 넣기위해 true로 바꾼다.
         *
         *              }
         *          }
         *          else
         *          {
         *              if (doc.getFigListSize() > 0)
         *              {
         *                  if (isChanged == false)
         *                  {
         *                      doc.pushStack();
         *                      isChanged = true;
         *                  }
         *                  //멀티케이스 인 경우 리스트에 저장된 애들을 모두 움직임
         *                  for (int i = 0; i < doc.getFigListSize(); i++)
         *                  {
         *                      doc.getCurrentFigure(i).move(x - drag_off_x, y - drag_off_y);
         *                  }
         *                  drag_off_x = x;
         *                  drag_off_y = y;
         *              }
         *          }
         *                              break;
         *      case FIGURE.SELECT:
         *          if (doc.getIsMultSel())
         *          {
         *              if (isChanged == false)
         *              {
         *                  isChanged = true;
         *              }
         *              //멀티케이스 인 경우 리스트에 저장된 애들을 모두 움직임
         *              for (int i = 0; i < doc.getFigListSize(); i++)
         *              {
         *                  doc.getCurrentFigure(i).move(x - drag_off_x, y - drag_off_y);
         *              }
         *              drag_off_x = x;
         *              drag_off_y = y;
         *          }
         *          else
         *          {
         *              Rect rt = (Rect)doc.getCurrentFigure().getVectorElementAt(0);
         *              rt.setRight(x);
         *              rt.setBottom(y);
         *          }
         *          break;
         *      // line, rectangle, oval 등은 드래그 동안 끝점만 바꿔주면 된다.
         *      case FIGURE.LINE:
         *                      case FIGURE.RECT:
         *                      case FIGURE.OVAL:
         *          doc.setIsMultSel(false);
         *          Rect pt = (Rect)doc.getCurrentFigure().getVectorElementAt(0);
         *                              pt.setRight(x);
         *                              pt.setBottom(y);
         *                              break;
         *                              // free line은 드래그 동안에 좌표를 계속 추가시켜준다.
         *                      case FIGURE.FREELINE:
         *          doc.setIsMultSel(false);
         *          doc.getCurrentFigure().add(x, y);
         *                              break;
         *                      case FIGURE.POLYLINE:
         *                              break;
         *                              // curve도 line, rectangle, oval과 비슷하나 normal을 호출한다. 즉 one, two값이
         *                              // 1/3, 2/3 에 위치하도록 바꿔준다.
         *                              //
         *                              //case FIGURE.CURVE:
         *                              //	CurveFigure c = (CurveFigure)figure;
         *                              //	c.setEnd(x,y);
         *                              //	c.setNormal();
         *                              //	break;
         *                              //
         *                      case FIGURE.TEXT:
         *                              break;
         *      case FIGURE.ERASE:
         *          doc.setIsMultSel(false);
         *          doc.allFiguresNotSelected();
         *          // 모든 객체에서 눌려진 좌표에 해당되는 객체를 찾는다.
         *          doc.setCurrentFigure(doc.findFigureByPoint(x, y));
         *          if (doc.getCurrentFigure() != null)
         *          {
         *              doc.removeObject(doc.getCurrentFigure());
         *          }
         *          break;
         *      default:
         *                              break;
         *              }
         *              doc.UpdateAllViews();
         * @endcode
         */
        protected void MouseMoveHandler(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            /**
             * @brief 화면 이동 시작
             * @author 장한결([email protected])
             * @date 2019-04-30
             */
            if (zoomControl.mouse_R_down)
            {
                zoomControl.Moving_screen(x, y);
                pictureBox.Invalidate();
            }

            /**
             * @brief Zoom In/Out 상태에서 그림을 그릴 때, 화면의 좌표를 실제 좌표로 연산
             * @author 장한결
             * @date 2019-04-30
             */
            //**************************//
            x = zoomControl.Real_X(x);  //
            y = zoomControl.Real_Y(y);  //
            //**************************//

            //박성식 161112
            //선택 도형 좌표 표시 가능하도록 수정
            if (pushedFigure != null && pushedFigure.getVectorElementAt(0) is Rect)
            {
                Rect r = pushedFigure.getVectorElementAt(0) as Rect;
                lblPosition.Text = (string.Format("X:{0},Y:{1}", r.getLeft(), r.getTop()));
            }
            else
            {
                lblPosition.Text = "";
            }

            if (this.Capture == false)
            {
                return;
            }

            Pos movedInAbsoluteSystem = new Pos(x - drag_off_x, y - drag_off_y).InverseRelativeClone(doc.magnificationRatio, doc.screenPos);

            switch (doc.getCurrentTool())
            {
            case FIGURE.ARROW:
                if (e.Button == MouseButtons.Left && ModifierKeys == Keys.Control)
                {
                    doc.setIsMultSel(true);
                }
                else
                {
                    doc.setIsMultSel(false);
                }
                if (doc.getIsMultSel() == false)
                {
                    if (doc.getCurrentFigure() != null)
                    {
                        // 한번만 수행되도록한다.
                        if (isChanged == false)
                        {
                            doc.makeSnapshot();
                            isChanged = true;
                        }

                        // 이전의 드래그 되었던 좌표에서 얼마만큼 이동했는지를 구하여
                        // 그만 큼 이동시킨다.
                        doc.getCurrentFigure().moveAndResize(movedInAbsoluteSystem.x, movedInAbsoluteSystem.y);

                        // 현재의 좌표를 저장시켜 둔다.
                        drag_off_x = x;
                        drag_off_y = y;
                    }
                }
                else
                {
                    if (doc.getDrawingFiguresCount() > 0)
                    {
                        if (isChanged == false)
                        {
                            doc.makeSnapshot();
                            isChanged = true;
                        }
                        //멀티케이스 인 경우 리스트에 저장된 애들을 모두 움직임
                        for (int i = 0; i < doc.getDrawingFiguresCount(); i++)
                        {
                            doc.getCurrentFigure(i).moveAndResize(movedInAbsoluteSystem.x, movedInAbsoluteSystem.y);
                        }
                        drag_off_x = x;
                        drag_off_y = y;
                    }
                }
                break;

            case FIGURE.BOX:
                if (doc.getIsMultSel())
                {
                    if (isChanged == false)
                    {
                        isChanged = true;
                    }
                    //멀티케이스 인 경우 리스트에 저장된 애들을 모두 움직임
                    for (int i = 0; i < doc.getDrawingFiguresCount(); i++)
                    {
                        doc.getCurrentFigure(i).moveAndResize(movedInAbsoluteSystem.x, movedInAbsoluteSystem.y);
                    }
                    drag_off_x = x;
                    drag_off_y = y;
                }
                else
                {
                    Rect rt = (Rect)doc.getCurrentFigure().getVectorElementAt(0);
                    rt.setRight(x);
                    rt.setBottom(y);
                }
                break;

            // line, rectangle, oval 등은 드래그 동안 끝점만 바꿔주면 된다.
            case FIGURE.LINE:
            case FIGURE.RECT:
            case FIGURE.OVAL:
                doc.setIsMultSel(false);
                Rect pt = (Rect)doc.getCurrentFigure().getVectorElementAt(0);
                pt.setRight(x);
                pt.setBottom(y);
                break;

            // free line은 드래그 동안에 좌표를 계속 추가시켜준다.
            case FIGURE.FREELINE:
                doc.setIsMultSel(false);
                doc.getCurrentFigure().add(x, y);
                break;

            case FIGURE.POLYLINE:
                break;

            // curve도 line, rectangle, oval과 비슷하나 normal을 호출한다. 즉 one, two값이
            // 1/3, 2/3 에 위치하도록 바꿔준다.
            //
            //case FIGURE.CURVE:
            //	CurveFigure c = (CurveFigure)figure;
            //	c.setEnd(x,y);
            //	c.setNormal();
            //	break;
            //
            case FIGURE.TEXT:
                break;

            case FIGURE.ERASE:
                doc.setIsMultSel(false);
                doc.deselectAll();
                // 모든 객체에서 눌려진 좌표에 해당되는 객체를 찾는다.
                doc.refreshDrawingFigure(doc.findFigureAt(x, y));
                if (doc.getCurrentFigure() != null)
                {
                    doc.removeOriginalFigure(doc.getCurrentFigure());
                }
                break;

            default:
                break;
            }
            doc.UpdateAllViews();
        }
Example #2
0
 /**
  * @brief 좌표만 존재하는 0길이 사각형 생성자
  * @author 불명(김민규 담당)
  * @date 불명(2017-1-17 확인)
  */
 public Rect(Pos point)
 {
     left = right = point.x;
     top  = bottom = point.y;
 }
 public RectFigure(Pos p1, Pos p2, Color color) : base(p1, p2, color)
 {
 }
 public RectFigure(Pos p1, Pos p2) : base(p1, p2)
 {
 }
        /**
         * @brief 객체가 x,y좌표와 충돌하는가를 검사한다. 객체를 선택하려고 할 때 호출된다.
         */
        public override Boolean checkHitAndSetSelectType(Pos posInRelativeSystem)
        {
            Rect r = (Rect)getVectorElementAt(0);

            // left top
            Rect r2 = new Rect(r.getLeft(), r.getTop(), r.getLeft(), r.getTop());

            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.LEFT_TOP);
                return(true);
            }

            // left middle
            r2 = new Rect(r.getLeft(), r.getTop() + r.getHeight() / 2,
                          r.getLeft(), r.getTop() + r.getHeight() / 2);
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.LEFT_MIDDLE);
                return(true);
            }

            // left bottom
            r2 = new Rect(r.getLeft(), r.getBottom(),
                          r.getLeft(), r.getBottom());
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.LEFT_BOTTOM);
                return(true);
            }

            // middle top
            r2 = new Rect(r.getLeft() + r.getWidth() / 2, r.getTop(),
                          r.getLeft() + r.getWidth() / 2, r.getTop());
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.MIDDLE_TOP);
                return(true);
            }

            // middle bottom
            r2 = new Rect(r.getLeft() + r.getWidth() / 2, r.getBottom(),
                          r.getLeft() + r.getWidth() / 2, r.getBottom());
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.MIDDLE_BOTTOM);
                return(true);
            }
            // right top
            r2 = new Rect(r.getRight(), r.getTop(), r.getRight(), r.getTop());
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.RIGHT_TOP);
                return(true);
            }

            // right middle
            r2 = new Rect(r.getRight(), r.getTop() + r.getHeight() / 2,
                          r.getRight(), r.getTop() + r.getHeight() / 2);
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.RIGHT_MIDDLE);
                return(true);
            }


            // right bottom
            r2 = new Rect(r.getRight(), r.getBottom(), r.getRight(), r.getBottom());
            r2.inflateRect(3, 3);
            if (r2.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y))
            {
                setSelectType(SELECTTYPE.RIGHT_BOTTOM);
                return(true);
            }

            setSelectType(SELECTTYPE.MOVE);
            return(r.isHitPoint(posInRelativeSystem.x, posInRelativeSystem.y));
        }
 /**
  * @brief color요소를 다룬다.
  */
 public LineFigure(Pos x1, Pos x2, Color color) : base(x1, x2, color)
 {
 }
 /**
  * @brief noncolor요소를 다룬다.
  */
 public LineFigure(Pos x1, Pos x2) : base(x1, x2)
 {
 }