Example #1
0
        /// <summary>
        /// Draws CAD 2D Drawing Panel
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void draw(CADSpriteBatch spriteBatch)
        {
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Background Color
            //
            spriteBatch.LayerDepth = this.ldBackRectangle;
            spriteBatch.drawRectangle(this.Left, this.Top, this.Width, this.Height, this.BackgroundColor);

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Grid
            //
            spriteBatch.LayerDepth = this.ldGrid;

            // Vertical
            decimal x = 0;

            while (x <= DocSizeMmX)
            {
                int xd = (int)(x * this.RatioDotsPerMm);
                spriteBatch.drawLine(
                    this.Left + xd - this.DocViewXOffset,
                    this.Top - this.DocViewYOffset,
                    this.DocSizeDotsY,
                    this.getGridColor(),
                    true
                    );
                x = x + this.gridStepMm;
            }

            // Horizontal
            decimal y = 0;

            while (y <= DocSizeMmY)
            {
                int yd = (int)(y * this.RatioDotsPerMm);
                spriteBatch.drawLine(
                    this.Left - this.DocViewXOffset,
                    this.Top + yd - this.DocViewYOffset,
                    this.DocSizeDotsX,
                    this.getGridColor()
                    );
                y = y + this.gridStepMm;
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Document Content
            //

            // Draw Shapes
            spriteBatch.LayerDepth = this.ldContentShapes;
            foreach (Shape p in this.File.Shapes)
            {
                if (this.Toolbox.SelectTool.Elements.Contains(p))
                {
                    // Selected Point
                    this.drawShape(spriteBatch, p, Color.Red);
                }
                else
                {
                    this.drawShape(spriteBatch, p, Color.LightGreen);
                }
            }

            // Draw Points
            spriteBatch.LayerDepth = this.ldContentPoints;
            foreach (Point2D p in this.File.Points)
            {
                if (this.Toolbox.SelectTool.Elements.Contains(p))
                {
                    // Selected Point
                    this.drawPoint(spriteBatch, p, Color.Red);
                    spriteBatch.DrawString(
                        this.FontCanvas,
                        (this.Toolbox.SelectTool.Elements.IndexOf(p) + 1).ToString(),
                        this.pointToLocation(p) + new Vector2(5, 5),
                        Color.Red
                        );
                }
                else
                {
                    this.drawPoint(spriteBatch, p, Color.White);
                }
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Machine Location
            //
            spriteBatch.LayerDepth = this.ldMachinePosition;
            if (this.Machine != null && this.TextureMachineTool != null)
            {
                Vector2 spv = this.pointToLocation(this.Machine.Position);
                spriteBatch.Draw(
                    this.TextureMachineTool,
                    new Vector2(spv.X - 12, spv.Y - 12),
                    null,
                    null,
                    new Vector2(0, 0),
                    0f,
                    null,
                    Color.White,
                    SpriteEffects.None,
                    spriteBatch.LayerDepth
                    );
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Cursor Point
            //
            spriteBatch.LayerDepth = this.ldCursor;
            if (this.isCanvasHovered() || this.isCanvasPushed())
            {
                Point2D p           = this.mouseCursorToPoint(this.Mouse.CurrentState);
                string  description = String.Format("X:{0},Y:{1}", p.X, p.Y);
                Point2D sp          = this.getNearestSnapPoint(p);

                if (this.Toolbox.SelectedTool.GetType() == typeof(PointTool))
                {
                    this.drawPoint(spriteBatch, sp, Color.Green);
                }

                string snapDesc = String.Format("X:{0},Y:{1}", sp.X, sp.Y);

                spriteBatch.DrawString(
                    this.FontCanvas,
                    description,
                    new Vector2(this.Mouse.CurrentState.X + 20, this.Mouse.CurrentState.Y),
                    Color.Red,
                    0f,
                    new Vector2(0, 0),
                    new Vector2(1, 1),
                    SpriteEffects.None,
                    spriteBatch.LayerDepth
                    );

                spriteBatch.DrawString(
                    this.FontCanvas,
                    snapDesc,
                    new Vector2(this.Mouse.CurrentState.X + 20, this.Mouse.CurrentState.Y + 20),
                    Color.Green,
                    0f,
                    new Vector2(0, 0),
                    new Vector2(1, 1),
                    SpriteEffects.None,
                    spriteBatch.LayerDepth
                    );
            }

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            // Draw Scroll Bars
            //
            spriteBatch.LayerDepth = this.ldScrollBars;
            // - Vertical Scroll Bar
            if (this.VerticalScrollVisible)
            {
                scrollBarVertical.draw(spriteBatch);
            }

            // - Horizontal Scroll Bar
            if (this.HorizontalScrollVisible)
            {
                scrollBarHorizontal.draw(spriteBatch);
            }
        }
Example #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Init SpriteBatch
            //spriteBatch.Begin( SpriteSortMode.Deferred,null,SamplerState.LinearWrap);
            spriteBatch.Begin();
            spriteBatch.gameTime = gameTime;
            spriteBatch.mouse    = Mouse.GetState();

            // Draw CadPanel
            cadPanel.draw(spriteBatch);


            // Draw around CAD Panel

            spriteBatch.drawRectangle(
                0,
                0,
                this.config.windowSizeX,
                cadPanel.Top,
                Color.SandyBrown
                );

            spriteBatch.drawRectangle(
                0,
                cadPanel.Top,
                cadPanel.Left,
                this.config.windowSizeY - this.cadPanel.Top,
                Color.SandyBrown
                );

            spriteBatch.drawRectangle(
                this.cadPanel.Left + this.cadPanel.Width,
                this.cadPanel.Top,
                this.config.windowSizeX - this.cadPanel.Width - this.cadPanel.Left,
                this.config.windowSizeY - this.cadPanel.Top,
                Color.SandyBrown
                );

            spriteBatch.drawRectangle(
                this.cadPanel.Left,
                this.cadPanel.Top + this.cadPanel.Height,
                this.cadPanel.Left + this.cadPanel.Width,
                this.config.windowSizeY - (this.cadPanel.Top + this.cadPanel.Height),
                Color.SandyBrown
                );


            // Draw Button
            btnXup.draw(spriteBatch);
            btnDrillPoints.draw(spriteBatch);
            btnDrillShapes.draw(spriteBatch);
            btnGoToOrigin.draw(spriteBatch);
            btnClearPoints.draw(spriteBatch);
            sbManualSpeed.draw(spriteBatch);

            // Draw Machine
            machine.draw(spriteBatch);

            // Draw Toolbox
            toolbox.draw(spriteBatch);

            // Draw Cursor
            spriteBatch.drawCrosshair();

            spriteBatch.End();

            base.Draw(gameTime);
        }