Draw() 공개 메소드

public Draw ( Graphics g, PointF offset, float zoom ) : void
g System.Drawing.Graphics
offset System.Drawing.PointF
zoom float
리턴 void
예제 #1
0
        // Do not remove this commented block. Written due research. More correct relocate behavior while zoom //Yury
        //if (e.Graphics.VisibleClipBounds.Width > canvas.X + canvas.Width && canvas.X < 0 && canvas.Width < e.Graphics.VisibleClipBounds.Width)
        //    canvas.X = 0;
        //if (e.Graphics.VisibleClipBounds.Width < canvas.X + canvas.Width && canvas.Width < e.Graphics.VisibleClipBounds.Width)
        //    canvas.X = (int)(e.Graphics.VisibleClipBounds.Width - canvas.Width);
        //if (e.Graphics.VisibleClipBounds.Height > canvas.Y + canvas.Height && canvas.Y < 0 && canvas.Height < e.Graphics.VisibleClipBounds.Height)
        //    canvas.Y = 0;
        //if (e.Graphics.VisibleClipBounds.Height < canvas.Y + canvas.Height && canvas.Height < e.Graphics.VisibleClipBounds.Height)
        //    canvas.Y = (int)(e.Graphics.VisibleClipBounds.Height - canvas.Height);

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            //e.Graphics.DrawString(string.Format("x:{0} y:{1}", _offsetX, _offsetY), new Font("Arial", 12), new SolidBrush(Color.White), 300, 300);
            //e.Graphics.DrawString(string.Format("X:{0} Y:{1} Width:{2} Height:{3}", _scrollAreaWidth, _scrollAreaHeight, AutoScrollPosition.X, AutoScrollPosition.Y), new Font("Arial", 12), new SolidBrush(Color.White), 40, 40);
            //e.Graphics.DrawString(string.Format("x:{0} y:{1}", MousePosition.X, MousePosition.Y), new Font("Arial", 12), new SolidBrush(Color.White), 40, 40);

            RectangleF canvas = GetCanvas();

            AutoScrollMinSize = new Size((int)(canvas.Width), (int)(canvas.Height));
            UpdateBounds();
            AutoScrollMargin = new Size();
            if (canvas.Width <= ClientSize.Width && canvas.Height <= ClientSize.Height)
            {
                AutoScrollPosition       = new Point(0, 0);
                AutoScroll               = false;
                HorizontalScroll.Visible = false;
                VerticalScroll.Visible   = false;
                HScroll = false;
                VScroll = false;
            }
            else
            {
                AutoScroll = true;
            }

            e.Graphics.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
            canvas = GetCanvas();

            _currentDelta = GetDeltaForCanvas(canvas);
            PointF offset = PictureOffset;

            canvas.Offset(offset);

            var delta = _currentDelta;

            using (Brush br = new SolidBrush(CustomBackColor))
            {
                e.Graphics.FillRectangle(br, new RectangleF(canvas.X + delta.X, canvas.Y + delta.Y, canvas.Width, canvas.Height));
            }

            foreach (var primitive in _allPainting)
            {
                DrawPrimitive(primitive, e.Graphics, _zoom, new PointF(offset.X + delta.X, offset.Y + delta.Y));
            }

            if (_currentPrimitive != null)
            {
                DrawPrimitive(_currentPrimitive, e.Graphics, _zoom, new PointF(offset.X + delta.X, offset.Y + delta.Y));
            }

            if (_shapeControl.Primitive != null)
            {
                _shapeControl.Primitive = _shapeControl.Primitive;
                _shapeControl.Draw(e.Graphics, new PointF(offset.X + delta.X, offset.Y + delta.Y), _zoom);
            }

            var property = FindPorpertyControl();

            if (property != null)
            {
                property.Zoom = (int)(_zoom * 100);
            }

            NormalizeEx();

            UpdatePropertyControlPosition();
        }