Example #1
0
        public void DrawCircle(IflPoint c, double r, bool fill = false)
        {
            Graphics g         = this;
            Point    scrCenter = viewportToScreen(c);
            flPoint  scrRadii  = scaleToScreen(new flPoint(r, r));

            System.Drawing.Rectangle boundingRec = new System.Drawing.Rectangle(
                (int)Math.Round(scrCenter.X - scrRadii.X), (int)Math.Round(scrCenter.Y - scrRadii.Y),
                (int)Math.Round(2 * scrRadii.X), (int)Math.Round(2 * scrRadii.Y));
            g.DrawEllipse(CurrentPen as Pen, boundingRec);
            if (fill)
            {
                g.FillEllipse(CurrentBrush as Brush, boundingRec);
            }

            // flPoint[] circle = new flPoint[circularTessellation];
            // flPoint[] quarterCircle = new flPoint[circularTessellation/4];
            // double deltaAngle = (2 * Math.PI) / circularTessellation;
            // // first half quadrent
            // for (int idx = 0; idx < circularTessellation / 8; idx++)
            // {
            //     double angle = (deltaAngle * idx) + (deltaAngle/2);
            //     double x = Math.Sin(angle) * r;
            //     double y = Math.Cos(angle) * r;
            //     quarterCircle[idx] = new flPoint(x, y);
            //     circle[idx] = quarterCircle[idx].Translate(c);
            // }
            // //DrawPolygon(g, circle);
            // // second half quadrent
            // for (int idx = 0; idx < circularTessellation / 8; idx++)
            // {
            //     quarterCircle[idx + circularTessellation / 8] =
            //         new flPoint(quarterCircle[(circularTessellation / 8) - idx - 1].Y,
            //                     quarterCircle[(circularTessellation / 8) - idx - 1].X);
            //     circle[idx + circularTessellation / 8] = quarterCircle[idx + circularTessellation / 8].Translate(c);
            // }
            // //DrawPolygon(g, circle);
            // // second quadrant
            // for (int idx = 0; idx < circularTessellation / 4; idx++)
            // {
            //     circle[idx + circularTessellation / 4] = quarterCircle[circularTessellation / 4 - idx - 1].Scale(1, -1).Translate(c);
            // }
            // //DrawPolygon(g, circle);
            // // third quadrent
            // for (int idx = 0; idx < circularTessellation / 4; idx++)
            // {
            //     circle[idx + circularTessellation / 2] = quarterCircle[idx].Scale(-1, -1).Translate(c);
            // }
            // //DrawPolygon(g, circle);
            //// fourth quadrent
            // for (int idx = 0; idx < circularTessellation / 4; idx++)
            // {
            //     circle[idx + ((circularTessellation * 3) / 4)] = quarterCircle[circularTessellation / 4 - idx - 1].Scale(-1, 1).Translate(c);
            // }
            // DrawPolygon(g, circle);
        }
Example #2
0
        private flPoint scaleToScreen(Size s)
        {
            //return p;

            flPoint value = new flPoint();

            value.X = (szScreen.X * s.Width) / szViewport.X;
            value.Y = ((szScreen.Y * s.Height) / szViewport.Y);

            return(value);
        }
Example #3
0
        private flPoint scaleToScreen(flPoint p)
        {
            //return p;

            flPoint value = new flPoint();

            value.X = (int)Math.Round((szScreen.X * p.X) / szViewport.X);
            value.Y = (int)Math.Round((szScreen.Y * p.Y) / szViewport.Y);

            return(value);
        }
Example #4
0
        public void DrawPoint(IflPoint p)
        {
            Graphics g         = this;
            Point    scrCenter = viewportToScreen(p);
            flPoint  scrRadii  = scaleToScreen(new flPoint(.5, .5));

            System.Drawing.Rectangle boundingRec = new System.Drawing.Rectangle(
                (int)Math.Round(scrCenter.X - scrRadii.X), (int)Math.Round(scrCenter.Y - scrRadii.Y),
                (int)Math.Round(2 * scrRadii.X), (int)Math.Round(2 * scrRadii.Y));
            //g.DrawEllipse(CurrentPen as Pen, boundingRec);
            g.FillEllipse(CurrentBrush as Brush, boundingRec);
        }
Example #5
0
        public Canvas()
        {
            InitializeComponent();

            //this.Paint += new PaintEventHandler(Canvas_Paint);

            szViewport = new flPoint(110, 110);
            szScreen   = new flPoint(-1, -1);
            ptViewport = new flPoint(55, 55);

            CurrentPen   = Pens.Black;
            CurrentBrush = Brushes.LightGray;
        }
Example #6
0
        private void Canvas_SizeChanged(object sender, EventArgs e)
        {
            Size sz = this.Size;

            // force a square aspect ratio for now
            if (sz.Height > sz.Width)
            {
                sz.Height = sz.Width;
            }
            else
            {
                sz.Width = sz.Height;
            }
            szScreen = new flPoint(sz);

            Invalidate();
        }
Example #7
0
        public void Canvas_Paint(Object sender, PaintEventArgs e)
        {
            try
            {
                _graphics = e.Graphics;

                if (szScreen.X <= 0 || szScreen.Y <= 0)
                {
                    Size sz = this.Size;
                    // force a square aspect ratio for now
                    if (sz.Height > sz.Width)
                    {
                        sz.Height = sz.Width;
                    }
                    else
                    {
                        sz.Width = sz.Height;
                    }
                    szScreen = new flPoint(sz);
                }

                DrawGrid(e.Graphics);

                foreach (IDrawingObject o in ObjectList.Values)
                {
                    o.Draw(this);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "OOPS!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //               _graphics = null;
            }
        }
Example #8
0
 public Line(Point p1, Point p2)
 {
     P1 = new flPoint(p1); P2 = new flPoint(p2);
 }
Example #9
0
 public Circle(flPoint center, double radius, bool fill = false)
 {
     Center = center;
     Radius = radius;
     Fill   = fill;
 }