コード例 #1
0
        public void CreatePredefinedPolygon(object par)
        {
            var numString = par as string;

            if (numString == null)
            {
                return;
            }
            int    number = int.Parse(numString);
            Random rnd    = new Random();

            byte[] colors = new byte[3];
            rnd.NextBytes(colors);

            var poly = new Polygon();

            if (number == 1)
            {
                poly.AddPoint(new DragablePoint(80, 60));
                poly.AddPoint(new DragablePoint(250, 30));
                poly.AddPoint(new DragablePoint(200, 150));
                poly.AddPoint(new DragablePoint(137, 197));
                poly.AddPoint(new DragablePoint(123, 256));
                poly.AddPoint(new DragablePoint(68, 200));
                poly.AddRelation(poly.Lines[0], poly.Lines[2], Relation.PARALLEL);
                poly.AddRelation(poly.Lines[1], poly.Lines[5], Relation.EQUALS);
                poly.FixRelations(poly.Points[0]);
            }
            else if (number == 2)
            {
                poly.AddPoint(new DragablePoint(464, 70));
                poly.AddPoint(new DragablePoint(521, 267));
                poly.AddPoint(new DragablePoint(344, 335));
                poly.AddPoint(new DragablePoint(434, 238));
                poly.AddPoint(new DragablePoint(400, 100));
                poly.AddPoint(new DragablePoint(300, 78));

                poly.AddRelation(poly.Lines[0], poly.Lines[3], Relation.PARALLEL);
                poly.AddRelation(poly.Lines[2], poly.Lines[5], Relation.EQUALS);
                poly.FixRelations(poly.Points[0]);
            }
            else
            {
                return;
            }
            poly.Color     = Color.FromRgb(colors[0], colors[1], colors[2]);
            poly.Name      = "Poly" + Polygons.Count.ToString();
            poly.Boundries = new Rect(0, 0, BitmapWidth, BitmapHeight);
            poly.RenderBitmap();
            AddPolygon(poly);
        }
コード例 #2
0
ファイル: Editor.cs プロジェクト: ficoos/Software-CG
        public Editor(Window wnd)
        {
            _gfx     = new Graphics(wnd.CreateRenderer());
            _objects = new List <IDrawable>();
            _l       = null;
            _gfx.Clear(Colors.White);
            _gfx.Commit();
            wnd.WindowResized += (
                object sender,
                WindowResizedEventArgs e
                ) => Render();


            wnd.MouseButtonDown += delegate(
                object sender,
                MouseButtonDownEventArgs e
                ) {
                switch (e.Button)
                {
                case MouseButton.Left:
                    if (_l == null)
                    {
                        _l = new Polygon(Colors.Black);
                        _l.AddPoint(new Point(e.X, e.Y));
                        this._objects.Add(_l);
                    }
                    _l.AddPoint(new Point(e.X, e.Y));
                    break;

                case MouseButton.Right:
                    _l = null;
                    break;
                }

                Render();
            };

            wnd.MouseMotion += delegate(object sender, MouseMotionEventArgs e) {
                if (_l == null || _l.Count == 0)
                {
                    return;
                }

                _l.RemovePoint();
                _l.AddPoint(new Point(e.X, e.Y));

                Render();
            };

            wnd.KeyDown += delegate(object sender, KeyDownEventArgs e) {
                switch (e.KeySym.scancode)
                {
                case SDL.SDL_Scancode.SDL_SCANCODE_ESCAPE:
                    _objects.Clear();
                    _l = null;
                    break;

                case SDL.SDL_Scancode.SDL_SCANCODE_A:
                    if (_gfx.LineAlgorithm == BresenhamLine.DrawLine)
                    {
                        _gfx.LineAlgorithm = DDALine.DrawLine;
                        Console.WriteLine("Line Algorithm: DDALine");
                    }
                    else if (_gfx.LineAlgorithm == DDALine.DrawLine)
                    {
                        _gfx.LineAlgorithm = null;
                        Console.WriteLine("Line Algorithm: Built In");
                    }
                    else
                    {
                        _gfx.LineAlgorithm = BresenhamLine.DrawLine;
                        Console.WriteLine("Line Algorithm: BresnhamLine");
                    }
                    break;
                }

                Render();
            };
        }