Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                if (mBitmap != null)
                {
                    e.Graphics.DrawImage(mBitmap, 0, 0, Width, Height);
                }

                if (Core != null)
                {
                    PointF p = TranslatePoint(mLastWPos.ToPointF());
                    e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                    using (Pen px = GetPen(ColorScheme.PreviewCross, 2f))
                    {
                        e.Graphics.DrawLine(px, (int)p.X, (int)p.Y - 5, (int)p.X, (int)p.Y - 5 + 10);
                        e.Graphics.DrawLine(px, (int)p.X - 5, (int)p.Y, (int)p.X - 5 + 10, (int)p.Y);
                    }

                    using (Brush b = GetBrush(ColorScheme.PreviewText))
                    {
                        Rectangle r = ClientRectangle;
                        r.Inflate(-5, -5);
                        StringFormat sf = new StringFormat();

                        //  II | I
                        // ---------
                        // III | IV
                        GrblFile.CartesianQuadrant q = Core != null && Core.LoadedFile != null ? Core.LoadedFile.Quadrant : GrblFile.CartesianQuadrant.Unknown;
                        sf.Alignment     = q == GrblFile.CartesianQuadrant.II || q == GrblFile.CartesianQuadrant.III ? StringAlignment.Near : StringAlignment.Far;
                        sf.LineAlignment = q == GrblFile.CartesianQuadrant.III || q == GrblFile.CartesianQuadrant.IV ? StringAlignment.Far : StringAlignment.Near;

                        String position = string.Format("X: {0:0.000} Y: {1:0.000}", Core != null ? mLastMPos.X : 0, Core != null ? mLastMPos.Y : 0);

                        if (Core != null && (mLastWPos.Z != 0 || mLastMPos.Z != 0 || forcez))
                        {
                            position = position + string.Format(" Z: {0:0.000}", mLastMPos.Z);
                        }

                        if (Core != null && Core.WorkingOffset != GPoint.Zero)
                        {
                            position = position + "\n" + string.Format("X: {0:0.000} Y: {1:0.000}", Core != null ? mLastWPos.X : 0, Core != null ? mLastWPos.Y : 0);
                        }

                        if (Core != null && Core.WorkingOffset != GPoint.Zero && (mLastWPos.Z != 0 || mLastMPos.Z != 0 || forcez))
                        {
                            position = position + string.Format(" Z: {0:0.000}", mLastWPos.Z);
                        }

                        if (mCurF != 0 || mCurS != 0 || mFSTrig)
                        {
                            mFSTrig = true;
                            String fs = string.Format("F: {0:00000.##} S: {1:000.##}", Core != null ? mCurF : 0, Core != null ? mCurS : 0);
                            position = position + "\n" + fs;
                        }

                        e.Graphics.DrawString(position, Font, b, r, sf);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("GrblPanel Paint", ex);
            }
        }