Пример #1
0
        /// <summary>
        /// 在画布按照snappoint重画
        /// </summary>
        /// <param name="snappoint"></param>
        void RepaintSnappoint(ISnapPoint snappoint)
        {
            if (snappoint == null)
            {
                return;
            }
            CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);

            snappoint.Draw(dc);
            dc.Graphics.Dispose();
            dc.Dispose();
        }        /// <summary>
Пример #2
0
        }        /// <summary>

        /// 在画布按照IDrawObject重画
        /// </summary>
        /// <param name="obj"></param>
        void RepaintObject(IDrawObject obj)
        {
            if (obj == null)
            {
                return;
            }
            CanvasWrapper dc             = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
            RectangleF    invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(dc, obj.GetBoundingRect(dc)));

            obj.Draw(dc, invalidaterect);
            dc.Graphics.Dispose();
            dc.Dispose();
        }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            CommonTools.Tracing.StartTrack(Program.TracePaint);
            ClearPens();
            e.Graphics.SmoothingMode = m_smoothingMode;
            CanvasWrapper dc = new CanvasWrapper(this, e.Graphics, ClientRectangle);
            Rectangle cliprectangle = e.ClipRectangle;
            if (m_staticImage == null)
            {
                cliprectangle = ClientRectangle;
                m_staticImage = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
                m_staticDirty = true;
            }
            RectangleF r = ScreenUtils.ToUnitNormalized(dc, cliprectangle);
            if (float.IsNaN(r.Width) || float.IsInfinity(r.Width))
            {
                r = ScreenUtils.ToUnitNormalized(dc, cliprectangle);
            }
            if (m_staticDirty)
            {
                m_staticDirty = false;
                CanvasWrapper dcStatic = new CanvasWrapper(this, Graphics.FromImage(m_staticImage), ClientRectangle);
                dcStatic.Graphics.SmoothingMode = m_smoothingMode;
                m_model.BackgroundLayer.Draw(dcStatic, r);
                if (m_model.GridLayer.Enabled)
                    m_model.GridLayer.Draw(dcStatic, r);

                PointF nullPoint = ToScreen(new UnitPoint(0, 0));
                dcStatic.Graphics.DrawLine(Pens.Blue, nullPoint.X - 10, nullPoint.Y, nullPoint.X + 10, nullPoint.Y);
                dcStatic.Graphics.DrawLine(Pens.Blue, nullPoint.X, nullPoint.Y - 10, nullPoint.X, nullPoint.Y + 10);

                ICanvasLayer[] layers = m_model.Layers;
                for (int layerindex = layers.Length - 1; layerindex >= 0; layerindex--)
                {
                    if (layers[layerindex] != m_model.ActiveLayer && layers[layerindex].Visible)
                        layers[layerindex].Draw(dcStatic, r);
                }
                if (m_model.ActiveLayer != null)
                    m_model.ActiveLayer.Draw(dcStatic, r);

                dcStatic.Dispose();
            }
            e.Graphics.DrawImage(m_staticImage, cliprectangle, cliprectangle, GraphicsUnit.Pixel);

            foreach (IDrawObject drawobject in m_model.SelectedObjects)
                drawobject.Draw(dc, r);

            if (m_newObject != null)
                m_newObject.Draw(dc, r);

            if (m_snappoint != null)
                m_snappoint.Draw(dc);

            if (m_selection != null)
            {
                m_selection.Reset();
                m_selection.SetMousePoint(e.Graphics, this.PointToClient(Control.MousePosition));
            }
            if (m_moveHelper.IsEmpty == false)
                m_moveHelper.DrawObjects(dc, r);

            if (m_nodeMoveHelper.IsEmpty == false)
                m_nodeMoveHelper.DrawObjects(dc, r);
            dc.Dispose();
            ClearPens();
            CommonTools.Tracing.EndTrack(Program.TracePaint, "OnPaint complete");
        }
Пример #4
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (m_selection != null)
            {
                Graphics dc = Graphics.FromHwnd(Handle);
                m_selection.SetMousePoint(dc, new PointF(e.X, e.Y));
                dc.Dispose();
                return;
            }

            if (m_commandType == eCommandType.pan && e.Button == MouseButtons.Left)
            {
                m_dragOffset.X = -(m_mousedownPoint.X - e.X);
                m_dragOffset.Y = -(m_mousedownPoint.Y - e.Y);
                m_lastCenterPoint = CenterPointUnit();
                DoInvalidate(true);
            }
            UnitPoint mousepoint;
            UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y));
            if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false)
            {
                Rectangle invalidaterect = Rectangle.Empty;
                ISnapPoint newsnap = null;
                mousepoint = GetMousePoint();
                if (RunningSnapsEnabled)
                    newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null);
                if (newsnap == null)
                    newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null);
                if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType()))
                {
                    invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect));
                    invalidaterect.Inflate(2, 2);
                    RepaintStatic(invalidaterect); // remove old snappoint
                    m_snappoint = newsnap;
                }
                if (m_commandType == eCommandType.move)
                    Invalidate(invalidaterect);

                if (m_snappoint == null)
                    m_snappoint = newsnap;
            }
            m_owner.SetPositionInfo(unitpoint);
            m_owner.SetSnapInfo(m_snappoint);

            //UnitPoint mousepoint;
            if (m_snappoint != null)
                mousepoint = m_snappoint.SnapPoint;
            else
                mousepoint = GetMousePoint();

            if (m_newObject != null)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper)));
                invalidaterect.Inflate(2, 2);
                RepaintStatic(invalidaterect);

                m_newObject.OnMouseMove(m_canvaswrapper, mousepoint);
                RepaintObject(m_newObject);
            }
            if (m_snappoint != null)
                RepaintSnappoint(m_snappoint);

            if (m_moveHelper.HandleMouseMoveForMove(mousepoint))
                Refresh(); //Invalidate();

            RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint);
            if (rNoderect != RectangleF.Empty)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect));
                RepaintStatic(invalidaterect);

                CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
                dc.Graphics.Clip = new Region(ClientRectangle);
                //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect);
                m_nodeMoveHelper.DrawObjects(dc, rNoderect);
                if (m_snappoint != null)
                    RepaintSnappoint(m_snappoint);

                dc.Graphics.Dispose();
                dc.Dispose();
            }
        }
Пример #5
0
 void RepaintSnappoint(ISnapPoint snappoint)
 {
     if (snappoint == null)
         return;
     CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
     snappoint.Draw(dc);
     dc.Graphics.Dispose();
     dc.Dispose();
 }
Пример #6
0
 void RepaintObject(IDrawObject obj)
 {
     if (obj == null)
         return;
     CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
     RectangleF invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(dc, obj.GetBoundingRect(dc)));
     obj.Draw(dc, invalidaterect);
     dc.Graphics.Dispose();
     dc.Dispose();
 }
Пример #7
0
        /// <summary>
        /// 鼠标移动事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (m_selection != null)
            {
                Graphics dc = Graphics.FromHwnd(Handle);
                m_selection.SetMousePoint(dc, new PointF(e.X, e.Y));
                dc.Dispose();
                return;
            }

            if (m_commandType == eCommandType.pan && e.Button == MouseButtons.Left)            //如果选择pan(移动画布),切按住鼠标左键
            {
                m_dragOffset.X    = -(m_mousedownPoint.X - e.X);
                m_dragOffset.Y    = -(m_mousedownPoint.Y - e.Y);
                m_lastCenterPoint = CenterPointUnit();
                DoInvalidate(true);
            }
            UnitPoint mousepoint;
            UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y));

            if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false)            //如果使绘制或者移动或节点移动或节点移动为空
            {
                Rectangle  invalidaterect = Rectangle.Empty;
                ISnapPoint newsnap        = null;
                mousepoint = GetMousePoint();
                if (RunningSnapsEnabled)
                {
                    newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null);
                }
                if (newsnap == null)
                {
                    newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null);
                }
                if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType()))                //绘图时点击左键生成节点
                {
                    Console.WriteLine("canvas 688");
                    invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect));
                    invalidaterect.Inflate(2, 2);
                    RepaintStatic(invalidaterect);                     // remove old snappoint
                    m_snappoint = newsnap;
                }
                if (m_commandType == eCommandType.move)//使用移动工具时,重画图像
                {
                    Invalidate(invalidaterect);
                }

                if (m_snappoint == null)
                {
                    m_snappoint = newsnap;
                }
            }
            m_owner.SetPositionInfo(unitpoint);          //给出绘制信息
            m_owner.SetSnapInfo(m_snappoint);            //给出绘制信息


            //UnitPoint mousepoint;
            if (m_snappoint != null)
            {
                mousepoint = m_snappoint.SnapPoint;
            }
            else
            {
                mousepoint = GetMousePoint();
            }

            if (m_newObject != null)            //如果不为空则重画*
            {
                //MessageBox.Show(m_newObject.ToString());
                //Console.WriteLine(m_newObject.ToString());
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper)));
                invalidaterect.Inflate(2, 2);
                RepaintStatic(invalidaterect);
                m_newObject.OnMouseMove(m_canvaswrapper, mousepoint);
                RepaintObject(m_newObject);
            }
            if (m_snappoint != null)            //如果不为空则重画
            {
                RepaintSnappoint(m_snappoint);
            }

            if (m_moveHelper.HandleMouseMoveForMove(mousepoint))                        //重绘
            {
                Refresh();                                                              //Invalidate();
            }
            RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint); //坐标获取

            if (rNoderect != RectangleF.Empty)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect)); //坐标转换
                RepaintStatic(invalidaterect);                                                                                  //重绘
                CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
                dc.Graphics.Clip = new Region(ClientRectangle);
                //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect);
                m_nodeMoveHelper.DrawObjects(dc, rNoderect);
                if (m_snappoint != null)
                {
                    RepaintSnappoint(m_snappoint);                    //重绘
                }
                dc.Graphics.Dispose();
                dc.Dispose();
            }
        }
Пример #8
0
        /// <summary>
        /// 响应消息
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            CommonTools.Tracing.StartTrack(Program.TracePaint); //TracePaint=1
            ClearPens();                                        //清空画笔
            e.Graphics.SmoothingMode = m_smoothingMode;
            CanvasWrapper dc            = new CanvasWrapper(this, e.Graphics, ClientRectangle);
            Rectangle     cliprectangle = e.ClipRectangle;

            if (m_staticImage == null)
            {
                cliprectangle = ClientRectangle;
                m_staticImage = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
                m_staticDirty = true;
            }
            RectangleF r = ScreenUtils.ToUnitNormalized(dc, cliprectangle);

            if (float.IsNaN(r.Width) || float.IsInfinity(r.Width))
            {
                r = ScreenUtils.ToUnitNormalized(dc, cliprectangle);
            }
            if (m_staticDirty)
            {
                m_staticDirty = false;
                CanvasWrapper dcStatic = new CanvasWrapper(this, Graphics.FromImage(m_staticImage), ClientRectangle);
                dcStatic.Graphics.SmoothingMode = m_smoothingMode;
                m_model.BackgroundLayer.Draw(dcStatic, r);
                if (m_model.GridLayer.Enabled)
                {
                    m_model.GridLayer.Draw(dcStatic, r);
                }
                PointF nullPoint = ToScreen(new UnitPoint(0, 0));
                dcStatic.Graphics.DrawLine(Pens.Blue, nullPoint.X - 10, nullPoint.Y, nullPoint.X + 10, nullPoint.Y);
                dcStatic.Graphics.DrawLine(Pens.Blue, nullPoint.X, nullPoint.Y - 10, nullPoint.X, nullPoint.Y + 10);

                ICanvasLayer[] layers = m_model.Layers;                //线条粗细颜色
                for (int layerindex = layers.Length - 1; layerindex >= 0; layerindex--)
                {
                    if (layers[layerindex] != m_model.ActiveLayer && layers[layerindex].Visible)
                    {
                        layers[layerindex].Draw(dcStatic, r);
                    }
                }
                if (m_model.ActiveLayer != null)
                {
                    m_model.ActiveLayer.Draw(dcStatic, r);
                }

                dcStatic.Dispose();
            }
            e.Graphics.DrawImage(m_staticImage, cliprectangle, cliprectangle, GraphicsUnit.Pixel);

            foreach (IDrawObject drawobject in m_model.SelectedObjects)
            {
                drawobject.Draw(dc, r);
            }

            if (m_newObject != null)
            {
                m_newObject.Draw(dc, r);
            }

            if (m_snappoint != null)
            {
                m_snappoint.Draw(dc);
            }

            if (m_selection != null)
            {
                m_selection.Reset();
                m_selection.SetMousePoint(e.Graphics, this.PointToClient(Control.MousePosition));
            }
            if (m_moveHelper.IsEmpty == false)
            {
                m_moveHelper.DrawObjects(dc, r);
            }

            if (m_nodeMoveHelper.IsEmpty == false)
            {
                m_nodeMoveHelper.DrawObjects(dc, r);
            }
            dc.Dispose();
            ClearPens();
            CommonTools.Tracing.EndTrack(Program.TracePaint, "OnPaint complete");
        }
Пример #9
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (m_selection != null)
            {
                Graphics dc = Graphics.FromHwnd(Handle);
                m_selection.SetMousePoint(dc, new PointF(e.X, e.Y));
                dc.Dispose();
                return;
            }

            if (m_commandType == eCommandType.pan &&
                (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle))
            {
                m_dragOffset.X    = -(m_mousedownPoint.X - e.X);
                m_dragOffset.Y    = -(m_mousedownPoint.Y - e.Y);
                m_lastCenterPoint = CenterPointUnit();
                DoInvalidate(true);
            }
            UnitPoint mousepoint;
            UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y));

            if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false)
            {
                Rectangle  invalidaterect = Rectangle.Empty;
                ISnapPoint newsnap        = null;
                mousepoint = GetMousePoint();
                if (RunningSnapsEnabled)
                {
                    newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null);
                }
                if (newsnap == null)
                {
                    newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null);
                }
                if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType()))
                {
                    invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect));
                    invalidaterect.Inflate(2, 2);
                    RepaintStatic(invalidaterect);                     // remove old snappoint
                    m_snappoint = newsnap;
                }
                if (m_commandType == eCommandType.move)
                {
                    Invalidate(invalidaterect);
                }

                if (m_snappoint == null)
                {
                    m_snappoint = newsnap;
                }
            }
            m_owner.SetPositionInfo(unitpoint);
            m_owner.SetSnapInfo(m_snappoint);

            //UnitPoint mousepoint;
            if (m_snappoint != null)
            {
                mousepoint = m_snappoint.SnapPoint;
            }
            else
            {
                mousepoint = GetMousePoint();
            }

            if (m_newObject != null)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper)));
                invalidaterect.Inflate(2, 2);
                RepaintStatic(invalidaterect);

                m_newObject.OnMouseMove(m_canvaswrapper, mousepoint);
                RepaintObject(m_newObject);
            }
            if (m_snappoint != null)
            {
                RepaintSnappoint(m_snappoint);
            }

            if (m_moveHelper.HandleMouseMoveForMove(mousepoint))
            {
                Refresh();                 //Invalidate();
            }
            RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint);

            if (rNoderect != RectangleF.Empty)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect));
                RepaintStatic(invalidaterect);

                CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
                dc.Graphics.Clip = new Region(ClientRectangle);
                //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect);
                m_nodeMoveHelper.DrawObjects(dc, rNoderect);
                if (m_snappoint != null)
                {
                    RepaintSnappoint(m_snappoint);
                }

                dc.Graphics.Dispose();
                dc.Dispose();
            }
        }