Esempio n. 1
0
        public RectangleF Selection(ICanvas canvas)
        {
            Rectangle screenRect = ScreenRect();

            if (screenRect.IsEmpty)
            {
                return(RectangleF.Empty);
            }
            return(ScreenUtils.ToUnitNormalized(canvas, screenRect));
        }
Esempio n. 2
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");
        }