コード例 #1
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
 public void DrawLine(Vector2 from, Vector2 to, Color color, DrawingSpace space = DrawingSpace.World)
 {
     VertexPositionColor[] vertices = new VertexPositionColor[2];
     vertices[0] = new VertexPositionColor(new Vector3(from.X, from.Y, 0), color);
     vertices[1] = new VertexPositionColor(new Vector3(to.X, to.Y, 0), color);
     DrawVertices(vertices, PrimitiveType.LineList, vertices.Length, space);
 }
コード例 #2
0
        public static void GetEntityByHandle()
        {
            Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager
                                      .StartTransaction();
            string handle = "188"; // Usually the handle assigned to the first object drawn in AutoCAD 2010.

            try
            {
                Entity entity = DrawingSpace.GetEntityByHandle(handle, transaction, OpenMode.ForWrite);

                if (entity != null)
                {
                    entity.Color = Color.FromColorIndex(ColorMethod.ByAci, 3);
                    transaction.Commit();
                }
            }

            catch (System.Exception)
            {
                throw;
            }

            finally
            {
                transaction.Dispose();
            }
        }
コード例 #3
0
        public static void GeDouble()
        {
            PromptStatus status    = new PromptStatus();
            double       userInput = DrawingSpace.GetDouble("Input double:", ref status, false);

            Editor command = Application.DocumentManager.MdiActiveDocument.Editor;

            command.WriteMessage("Result: " + userInput);
        }
コード例 #4
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
 public void DrawCircle(Vector2 position, float radius, Color color, DrawingSpace space = DrawingSpace.World)
 {
     VertexPositionColor[] vertices = new VertexPositionColor[CircleSmoothness + 1];
     for (int i = 0; i <= CircleSmoothness; i++)
     {
         float x = position.X + (radius * _circleCosTable[i]);
         float y = position.Y + (radius * _circleSinTable[i]);
         vertices[i] = new VertexPositionColor(new Vector3(x, y, 0.0f), color);
     }
     DrawVertices(vertices, PrimitiveType.LineStrip, CircleSmoothness, space);
 }
コード例 #5
0
        public static void AddEntityWithTransaction()
        {
            Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager
                                      .StartTransaction();
            Line line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0));

            DrawingSpace.AddEntity(line, transaction);

            // Since the transaction is still open we can continue to manipulate the object
            // and get access to properties that are set only after adding it to the database.
            line.Color = Color.FromColorIndex(ColorMethod.ByAci, 1);
            transaction.Commit();
        }
コード例 #6
0
ファイル: SpriteOptions.cs プロジェクト: Robertk92/ChessAI
 public SpriteOptions(
     SpriteSortMode spriteSortMode,
     BlendState blendState,
     SamplerState samplerState,
     DepthStencilState depthStencilState,
     RasterizerState rasterizerState,
     Effect effect, DrawingSpace space,
     Matrix transformMatrix)
 {
     _spriteSortMode    = spriteSortMode;
     _blendState        = blendState;
     _drawingSpace      = space;
     _samplerState      = samplerState;
     _depthStencilState = depthStencilState;
     _rasterizerState   = rasterizerState;
     _effect            = effect;
     _transformMatrix   = transformMatrix;
     _drawOrder         = 0;
 }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button2_Checked(object sender, RoutedEventArgs e)
        {
            using (DrawingContext dc = _grid.RenderOpen())
            {
                // vertical.
                dc.DrawLine(_gridPen, new Point(0, 40), new Point(301, 40));
                dc.DrawLine(_gridPen, new Point(0, 80), new Point(301, 80));
                dc.DrawLine(_gridPen, new Point(0, 120), new Point(301, 120));
                dc.DrawLine(_gridPen, new Point(0, 160), new Point(301, 160));

                // horizontal.
                dc.DrawLine(_gridPen, new Point(60, 0), new Point(60, 201));
                dc.DrawLine(_gridPen, new Point(120, 0), new Point(120, 201));
                dc.DrawLine(_gridPen, new Point(180, 0), new Point(180, 201));
                dc.DrawLine(_gridPen, new Point(240, 0), new Point(240, 201));

                DrawingSpace.AddVisual(_grid);
            }
        }
コード例 #8
0
        public static void GetEntity()
        {
            Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager
                                      .StartTransaction();
            PromptStatus status = new PromptStatus();
            Entity       entity = DrawingSpace.GetEntity("Select object:", ref status, transaction,
                                                         OpenMode.ForWrite);

            // The status lets us know if the user actually selected something or cancelled.
            if (status == PromptStatus.OK)
            {
                entity.Color = Color.FromColorIndex(ColorMethod.ByAci, 2);
                transaction.Commit();
            }
            else
            {
                transaction.Dispose();
            }
        }
コード例 #9
0
        public static void GetString()
        {
            PromptStatus status    = new PromptStatus();
            string       userInput = DrawingSpace.GetString("Input string:", ref status, true);

            if (status == PromptStatus.OK)
            {
                Editor command = Application.DocumentManager.MdiActiveDocument.Editor;

                if (userInput != "")
                {
                    command.WriteMessage("You wrote: " + userInput);
                }
                else
                {
                    command.WriteMessage("No input");
                }
            }
        }
コード例 #10
0
        public static void GetKeyword()
        {
            PromptStatus status = new PromptStatus();

            string[] keywords  = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
            string   userInput = DrawingSpace.GetKeyword("Select a day:", ref status, keywords);

            Editor command = Application.DocumentManager.MdiActiveDocument.Editor;

            if (status == PromptStatus.OK)
            {
                if (userInput != "")
                {
                    command.WriteMessage("You selected: " + userInput);
                }
            }
            else
            {
                command.WriteMessage("No selection");
            }
        }
コード例 #11
0
        public static void GetSelection()
        {
            Transaction transaction = HostApplicationServices.WorkingDatabase.TransactionManager
                                      .StartTransaction();
            PromptStatus       status    = new PromptStatus();
            DBObjectCollection selection = DrawingSpace.GetSelection("Select objects:", ref status,
                                                                     transaction, OpenMode.ForWrite);

            // Another way of dealing with the canceling of the operation or empty selection.
            if (status != PromptStatus.OK)
            {
                transaction.Dispose();
                return;
            }

            foreach (Entity entity in selection)
            {
                entity.Color = Color.FromColorIndex(ColorMethod.ByAci, 4);
            }

            transaction.Commit();
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        private void _DrawShape()
        {
            List <Point> points = _CalculatePoints();

            DrawingVisual visual = new DrawingVisual();

            using (DrawingContext dc = visual.RenderOpen())
            {
                if (points.Count > 0)
                {
                    Point start = points[0];
                    foreach (Point p in points)
                    {
                        dc.DrawLine(_pen, start, p);
                        start = p;
                    }
                }

                DrawingSpace.DeleteVisual(_visual);
                _visual = visual;
                DrawingSpace.AddVisual(_visual);
            }
        }
コード例 #13
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
        public void DrawRect(Rectangle rect, Color color, DrawingSpace space = DrawingSpace.World)
        {
            VertexPositionColor[] vertices = new VertexPositionColor[8];

            Vector2 topLeft     = new Vector2(rect.X, rect.Y);
            Vector2 topRight    = new Vector2(rect.X + rect.Width, rect.Y);
            Vector2 bottomLeft  = new Vector2(rect.X, rect.Y + rect.Height);
            Vector2 bottomRight = new Vector2(rect.X + rect.Width, rect.Y + rect.Height);

            vertices[0] = new VertexPositionColor(new Vector3(topLeft.X, topLeft.Y, 0), color);
            vertices[1] = new VertexPositionColor(new Vector3(topRight.X, topRight.Y, 0), color);

            vertices[2] = new VertexPositionColor(new Vector3(topRight.X, topRight.Y, 0), color);
            vertices[3] = new VertexPositionColor(new Vector3(bottomRight.X, bottomRight.Y, 0), color);

            vertices[4] = new VertexPositionColor(new Vector3(bottomRight.X, bottomRight.Y, 0), color);
            vertices[5] = new VertexPositionColor(new Vector3(bottomLeft.X, bottomLeft.Y, 0), color);

            vertices[6] = new VertexPositionColor(new Vector3(bottomLeft.X, bottomLeft.Y, 0), color);
            vertices[7] = new VertexPositionColor(new Vector3(topLeft.X, topLeft.Y, 0), color);

            DrawVertices(vertices, PrimitiveType.LineList, vertices.Length, space);
        }
コード例 #14
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
        public void DrawText(Vector2 position, string text, Color color, float scale, DrawingSpace space = DrawingSpace.World)
        {
            Matrix matrix = Matrix.Identity;

            if (space == DrawingSpace.World)
            {
                matrix = MGTK.Instance.LoadedScene.ActiveCamera != null ? MGTK.Instance.LoadedScene.ActiveCamera.Matrix : Matrix.Identity;
            }

            _spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.AlphaBlend,
                SamplerState.PointClamp,
                DepthStencilState.None,
                RasterizerState.CullCounterClockwise,
                null, matrix);
            Vector2 size = _font.MeasureString(text);

            _spriteBatch.DrawString(_font, text, position, color, 0.0f, new Vector2(size.X / 2, size.Y / 2), scale, SpriteEffects.None, 0.0f);
            _spriteBatch.End();
        }
コード例 #15
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
        public void DrawVertices(VertexPositionColor[] vertices, PrimitiveType primType, int primCount, DrawingSpace space)
        {
            if (vertices.Length > MaxVerticesPerCall)
            {
                _vertexBuffer.Dispose();
                _vertexBuffer = new VertexBuffer(_device, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly);
            }

            _vertexBuffer.SetData(vertices);

            Camera2D camera = MGTK.Instance.LoadedScene.ActiveCamera;
            Matrix   matrix = camera != null ? camera.Matrix : Matrix.Identity;

            _basicEffect.View       = space == DrawingSpace.World ? matrix : Matrix.Identity;
            _basicEffect.Projection = Matrix.CreateOrthographicOffCenter(
                0, MGTK.Instance.Graphics.GraphicsDevice.Viewport.Width,
                MGTK.Instance.Graphics.GraphicsDevice.Viewport.Height, 0, 0, 1);

            _basicEffect.VertexColorEnabled = true;

            _device.SetVertexBuffer(_vertexBuffer);

            foreach (EffectPass pass in _basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                _device.DrawPrimitives(primType, 0, primCount);
            }
        }
コード例 #16
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
        public void DrawToSpriteBatch(Texture2D texture, Vector2 position, Rectangle sourceRect, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects spriteEffects, float layer, DrawingSpace space = DrawingSpace.World)
        {
            Matrix matrix = Matrix.Identity;

            if (space == DrawingSpace.World)
            {
                matrix = MGTK.Instance.LoadedScene.ActiveCamera != null ? MGTK.Instance.LoadedScene.ActiveCamera.Matrix : Matrix.Identity;
            }

            _spriteBatch.Begin(
                SpriteSortMode.Immediate,
                BlendState.Additive,
                SamplerState.LinearClamp,
                DepthStencilState.None,
                RasterizerState.CullCounterClockwise,
                null, matrix);
            _spriteBatch.Draw(texture, position, sourceRect, color, rotation, origin, scale, spriteEffects, layer);
            _spriteBatch.End();
        }
コード例 #17
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
 public void DrawFilledRect(Vector2 position, Vector2 size, Color color, DrawingSpace space = DrawingSpace.World)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
 public void DrawFilledCircle(Vector2 position, int radius, Color color, DrawingSpace space = DrawingSpace.World)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
 public void DrawRect(Vector2 position, Vector2 size, Color color, DrawingSpace space = DrawingSpace.World)
 {
     DrawRect(new Rectangle(position.ToPoint(), size.ToPoint()), color, space);
 }
コード例 #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button2_Unchecked(object sender, RoutedEventArgs e)
 {
     DrawingSpace.DeleteVisual(_grid);
 }
コード例 #21
0
        public static void AddEntity()
        {
            Line line = new Line(new Point3d(0, 0, 0), new Point3d(1, 1, 0));

            DrawingSpace.AddEntity(line);
        }
コード例 #22
0
ファイル: DebugDrawer.cs プロジェクト: Robertk92/ChessAI
 public void DrawText(Vector2 position, string text, Color color, DrawingSpace space = DrawingSpace.World)
 {
     DrawText(position, text, color, 1.0f, space);
 }
コード例 #23
0
 public static void AddLayer()
 {
     DrawingSpace.AddLayer("1");
 }
コード例 #24
0
 private void ClearBTTN_Click(object sender, EventArgs e)
 {
     DrawingSpace.CreateGraphics().Clear(Color.Cyan);
 }
コード例 #25
0
        private void DrawBTTN_Click(object sender, EventArgs e)
        {
            Bitmap   bmp = new Bitmap(DrawingSpace.Width, DrawingSpace.Height);
            Graphics g   = Graphics.FromImage(bmp);

            g.Clear(Color.White);


            Point a1 = new Point(440, 230), a2 = new Point(400, 250),
                  a3 = new Point(370, 250), a4 = new Point(334, 225),
                  a5 = new Point(320, 200), a6 = new Point(318, 180), a7 = new Point(340, 165),
                  a8 = new Point(335, 172), a9 = new Point(355, 180), a10 = new Point(340, 190),
                  a11 = new Point(375, 180), a12 = new Point(330, 165), a13 = new Point(380, 130),
                  a14 = new Point(355, 165), a15 = new Point(395, 170), a16 = new Point(385, 190),
                  a17 = new Point(415, 175), a18 = new Point(410, 160), a19 = new Point(396, 145),
                  a20 = new Point(430, 160), a21 = new Point(430, 175), a22 = new Point(415, 190),
                  a23 = new Point(445, 180), a24 = new Point(440, 165), a25 = new Point(438, 160),
                  a26 = new Point(460, 170), a27 = new Point(465, 215);

            Pen pen_for_bezier = new Pen(Color.Red, 2.0F);

            Point[] array_for_bezier =
            {
                a1,  a2,  a3,  a4,
                a5,  a6,  a7,
                a8,  a9,  a10,
                a11, a12, a13,
                a14, a15, a16,
                a17, a18, a19,
                a20, a21, a22,
                a23, a24, a25,
                a26, a27, a1
            };
            g.DrawBeziers(pen_for_bezier, array_for_bezier);


            Rectangle body = new Rectangle(150, 100, 70, 50),

                      left_arm = new Rectangle(137, 105, 11, 40), right_arm = new Rectangle(223, 105, 11, 40),

                      l_a_c_t = new Rectangle(137, 100, 10, 10), l_a_c_b = new Rectangle(137, 140, 10, 10),

                      r_a_c_t = new Rectangle(223, 100, 10, 10), r_a_c_b = new Rectangle(223, 140, 10, 10),

                      left_leg = new Rectangle(170, 150, 11, 30), right_leg = new Rectangle(190, 150, 11, 30),

                      llc = new Rectangle(170, 175, 10, 10), rlc = new Rectangle(190, 175, 10, 10),

                      white_space = new Rectangle(147, 97, 80, 70), head_rect = new Rectangle(150, 70, 70, 56),

                      left_eye = new Rectangle(165, 80, 5, 5), right_eye = new Rectangle(200, 80, 5, 5);

            Pen p = new Pen(Color.GreenYellow, 3.0F);



            //168, 75; 161, 55
            //201, 75; 208, 55
            g.FillEllipse(Brushes.GreenYellow, head_rect);
            g.FillRectangle(Brushes.White, white_space);

            g.FillEllipse(Brushes.White, left_eye);
            g.FillEllipse(Brushes.White, right_eye);

            g.DrawLine(p, 168, 75, 159, 59);
            g.DrawLine(p, 201, 75, 210, 59);

            g.FillEllipse(Brushes.GreenYellow, l_a_c_t);
            g.FillEllipse(Brushes.GreenYellow, l_a_c_b);

            g.FillEllipse(Brushes.GreenYellow, r_a_c_t);
            g.FillEllipse(Brushes.GreenYellow, r_a_c_b);

            g.FillEllipse(Brushes.GreenYellow, llc);
            g.FillEllipse(Brushes.GreenYellow, rlc);

            g.FillRectangle(Brushes.GreenYellow, body);

            g.FillRectangle(Brushes.GreenYellow, left_arm);
            g.FillRectangle(Brushes.GreenYellow, right_arm);

            g.FillRectangle(Brushes.GreenYellow, left_leg);
            g.FillRectangle(Brushes.GreenYellow, right_leg);

            g.DrawString("Testing the methods", SystemFonts.DefaultFont, Brushes.Black, 337.0F, 205.0F);

            DrawingSpace.CreateGraphics().DrawImage(bmp, 0, 0);
            bmp.Dispose();
            g.Dispose();
        }
コード例 #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button1_Unchecked(object sender, RoutedEventArgs e)
 {
     _dispatcherTimer.Stop();
     NoSignalLabel.Visibility = Visibility.Visible;
     DrawingSpace.DeleteVisual(_visual);
 }