Example #1
0
        public static float CalculateShapeArea(ShapeBase shape)
        {
            float s = 0;

            if (shape.GetShapeType() == ShapeType.Ellipse)
            {
                var e = shape as Ellipse;
                s = (float) Math.PI*e.MinorAxis*e.MajorAxis;
            }
            else
            {
                var vetices = shape.Vertices.Clone();
                // Them p1 vao cuoi danh sach
                vetices.Add(vetices[0]);
                float x1 = vetices[0].X;
                float y1 = vetices[0].Y;
                for (int i = 1; i < vetices.Count; i++)
                {
                    float x2 = vetices[i].X;
                    float y2 = vetices[i].Y;
                    float dx = x2 - x1;
                    float dy = y2 - y1;
                    s += 0.5F*dx*(dy + 2*y1);

                    x1 = x2;
                    y1 = y2;
                }
            }

            return Math.Abs(s);
        }
Example #2
0
 public void Paint(ShapeBase shape)
 {
     using (var graph = Graphics.FromImage(_page.ImageBuffer))
     {
         graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
         _shapeDrawer.Draw(_viewport.WinToView(shape), graph);
     }
 }
Example #3
0
        public ShapeBase ViewToWin(ShapeBase shape)
        {
            var ret = shape.Clone();
            ret.Location = ViewToWin(shape.Location);
            ret.Size = ViewToWin(shape.Size);
            ret.OutlineWidth = ViewToWin(shape.OutlineWidth);

            for (int i = 0; i < shape.Vertices.Count; i++)
            {
                ret.Vertices[i].X = ViewToWin(shape.Vertices[i].X);
                ret.Vertices[i].Y = ViewToWin(shape.Vertices[i].Y);
            }

            return ret;
        }
Example #4
0
        public ShapeBase WinToView(ShapeBase shape)
        {
            if (shape == null)
                return null;

            var ret = shape.Clone();
            ret.Location = WinToView(shape.Location);
            ret.Size = WinToView(shape.Size);
            ret.OutlineWidth = WinToView(shape.OutlineWidth);

            for (int i = 0; i < shape.Vertices.Count; i++)
            {
                ret.Vertices[i].X = WinToView(shape.Vertices[i].X);
                ret.Vertices[i].Y = WinToView(shape.Vertices[i].Y);
            }

            return ret;
        }
Example #5
0
 public void Draw(ShapeBase shape, Graphics graphic)
 {
     if (shape == null)
         return;
     /* Draw shape*/
     switch (shape.GetShapeType())
     {
         case ShapeType.Line:
         case ShapeType.IsoscelesTriangle:
         case ShapeType.Oblong:
         case ShapeType.FreePencil:
         case ShapeType.Polygon:
             DrawPolygon((PolygonBase)shape, graphic);
             break;
         case ShapeType.Ellipse:
             DrawEllipse((Ellipse)shape, graphic);
             break;
     }
 }
Example #6
0
 public static Rectangle GetShapeBound(ShapeBase shape)
 {
     return new Rectangle(Point.Round(shape.Location), Size.Round(shape.Size));
 }
Example #7
0
 public static RectangleF GetShapeBoundF(ShapeBase shape)
 {
     return new RectangleF(shape.Location, shape.Size);
 }
Example #8
0
 public static Rectangle GetShapeBound(ShapeBase shape)
 {
     return(new Rectangle(Point.Round(shape.Location), Size.Round(shape.Size)));
 }
Example #9
0
 public static RectangleF GetShapeBoundF(ShapeBase shape)
 {
     return(new RectangleF(shape.Location, shape.Size));
 }
Example #10
0
        public DrawPad()
        {
            InitializeComponent();

            Zoom = 1;

            _shapeDrawer = new ShapeDrawer();
            _filler = new Filler();
            _drawingControl = new DrawingControl();
            _drawingControl.SetShapDrawer(_shapeDrawer);
            _drawingControl.ShapeCreated += DrawingControl_ShapeCreated;

            _textControl = new TextControl(gdiArea);
            _textControl.TextCreated += TextControl_TextCreated;
            _textControl.TextChanged += TextControl_TextChanged;

            _currentCommand = DrawPadCommand.None;
            _currentShape = null;

            _outlineWidth = 2F;
            _outlineColor = Color.Black;
            _outlineDash = DashStyle.Solid;
            _fillColor = Color.Transparent;
            _textFont = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 0);

            _shapeArea = 0;
        }
Example #11
0
        public void LoadShape(ShapeBase shape, Viewport viewport)
        {
            _shape = shape;
            _viewport = viewport;

            foreach (var ctrl in _controlPoints)
            {
                ctrl.LocationChanged -= Control_LocationChanged;
            }
            _controlPoints.Clear();

            foreach (var v in _shape.Vertices)
            {
                var control = new ControlPoint((int)Math.Round(v.X), (int)Math.Round(v.Y), null);
                control.LocationChanged += Control_LocationChanged;
                control.Tag = v;
                control.Cursor = Cursors.SizeAll;
                _controlPoints.Add(control);
            }

            if (_shape.GetShapeType() == ShapeType.Ellipse)
            {
                _controlPoints.Add(new ControlPoint((int) Math.Round(_shape.Location.X + _shape.Size.Width/2),
                    (int) Math.Round(_shape.Location.Y), null));

                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X + _shape.Size.Width),
                    (int)Math.Round(_shape.Location.Y + _shape.Size.Height/2), null));

                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X + _shape.Size.Width/2),
                    (int)Math.Round(_shape.Location.Y + _shape.Size.Height), null));

                _controlPoints.Add(new ControlPoint((int)Math.Round(_shape.Location.X),
                    (int)Math.Round(_shape.Location.Y + _shape.Size.Height/2), null));

            }
        }