ResetTransform() public method

public ResetTransform ( ) : void
return void
Example #1
0
 public void draw(System.Drawing.Graphics g)
 {
     g.TranslateTransform(this.x, this.y);
     g.RotateTransform(rotation);
     g.DrawImage(canon, (0 - canon.Width / 2), (0 - canon.Height / 2), canon.Width, canon.Height);
     g.ResetTransform();
 }
Example #2
0
        public draw_image(System.Drawing.Graphics g, System.Reflection.Assembly myAssembly, String embeded_img_name, int x, int y, int width, int height, int rotation = 0, bool back_transperency = false)
        {
            Stream myStream = myAssembly.GetManifestResourceStream("test_LD." + embeded_img_name);
            Bitmap img      = new Bitmap(myStream);

            if (rotation != 0)
            {
                int moveX = img.Width / 2 + x;
                int moveY = img.Height / 2 + y;
                g.TranslateTransform(moveX, moveY);
                g.RotateTransform(rotation);
                g.TranslateTransform(-moveX, -moveY);
                if (back_transperency == false)
                {
                    g.FillRectangle(Brushes.White, x, y, width, height);
                }
                g.DrawImage(img, x, y, width, height);
                g.ResetTransform();
            }
            else
            {
                if (back_transperency == false)
                {
                    g.FillRectangle(Brushes.White, x, y, width, height);
                }
                g.DrawImage(img, x, y, width, height);
            }
        }
Example #3
0
      private void RenderSymbols( Graphics g )
      {
         float radius = _textureSize / 2 * 0.84f;
         float centerX = _textureSize / 2;
         float centerY = _textureSize / 2;
         var symbols = GetSymbols();

         using ( var font = new Font( "Meroitic - Hieroglyphics", _fontSize, FontStyle.Bold ) )
         {
            for ( int index = 0; index < _symbolCount; index++ )
            {
               char character = symbols[index];
               float arc = 360f / _symbolCount;
               float thetaDegrees = arc * index;
               float thetaRadians = AsRadians( thetaDegrees );

               var characterSize = MeasureCharacter( g, font, character );
               var centerPoint = new PointF( centerX - characterSize.Width / 2, centerY - characterSize.Height / 2 );

               float x = centerX + (float) Math.Cos( thetaRadians ) * radius;
               float y = centerY + (float) Math.Sin( thetaRadians ) * radius;

               g.TranslateTransform( x, y );
               g.RotateTransform( thetaDegrees + 90 );

               g.TranslateTransform( -x, -y );
               g.TranslateTransform( -( characterSize.Width / 2 ), -( characterSize.Height / 2 ) );

               g.DrawString( character.ToString(), font, _greenBrush, x, y );
               g.ResetTransform();
            }
         }
      }
        public override void OnRender(Graphics g)
        {
            #if !PocketPC
             if(!Bearing.HasValue)
             {
            g.DrawImageUnscaled(Resources.shadow50, LocalPosition.X, LocalPosition.Y);
             }
             g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

             if(Bearing.HasValue)
             {
            g.RotateTransform(Bearing.Value - Overlay.Control.Bearing);
            g.FillPolygon(Brushes.Lime, Arrow);
             }

             g.ResetTransform();

             if(!Bearing.HasValue)
             {
            g.DrawImageUnscaled(Resources.bigMarkerGreen, LocalPosition.X, LocalPosition.Y);
             }
            #else
            DrawImageUnscaled(g, Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            DrawImageUnscaled(g, Resources.marker, LocalPosition.X, LocalPosition.Y);
            #endif
        }
Example #5
0
        public static bool DrawTextImage(
            ITextStrategy strategy,
            System.Drawing.Bitmap image,
            System.Drawing.Point offset,
            TextContext textContext,
            Matrix mat)
        {
            if (strategy == null || image == null || textContext == null)
            {
                return(false);
            }

            bool bRet = false;

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image))
            {
                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                graphics.Transform = mat;

                bRet = strategy.DrawString(graphics,
                                           textContext.fontFamily,
                                           textContext.fontStyle,
                                           textContext.nfontSize,
                                           textContext.pszText,
                                           new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                                           textContext.strFormat);

                graphics.ResetTransform();
            }

            return(bRet);
        }
Example #6
0
        public static Bitmap Rotate(Image b, int angle)
        {
            //弧度转换
            double radian = angle * System.Math.PI / 180.0;
            double cos    = System.Math.Cos(radian);
            double sin    = System.Math.Sin(radian);
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
            int W = (int)(System.Math.Max(System.Math.Abs(w * cos - h * sin), System.Math.Abs(w * cos + h * sin)));
            int H = (int)(System.Math.Max(System.Math.Abs(w * sin - h * cos), System.Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            g.Dispose();
            //dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            return(dsImage);
        }
Example #7
0
        public static System.Drawing.Bitmap GenMask(
            ITextStrategy strategy,
            int width,
            int height,
            System.Drawing.Point offset,
            TextContext textContext,
            Matrix mat)
        {
            if (strategy == null || textContext == null)
            {
                return(null);
            }

            System.Drawing.Bitmap pBmp = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(pBmp))
            {
                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                graphics.Transform = mat;

                strategy.DrawString(graphics,
                                    textContext.fontFamily,
                                    textContext.fontStyle,
                                    textContext.nfontSize,
                                    textContext.pszText,
                                    new System.Drawing.Point(textContext.ptDraw.X + offset.X, textContext.ptDraw.Y + offset.Y),
                                    textContext.strFormat);

                graphics.ResetTransform();
            }

            return(pBmp);
        }
Example #8
0
        /// <summary>
        /// Here we will show editor
        /// </summary>
        public void ShowEditor(Graphics gc, Rectangle clipRect)
        {
            gc.ResetTransform();
            gc.FillRectangle(Brushes.LightGray, clipRect);
            // draw Report
            //project.PrepareDraw(0, 0, 0, 0, 0, gc, clipRect);
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            project.CurrentReportPage.Viewer.UpdateValues(clipRect);
            project.CurrentReportPage.MakeViewMatrix(clipRect);

            project.CurrentReportPage.MakeDrawMatrix(mat);
            project.CurrentReportPage.Draw(gc, clipRect);
            // draw commands

            // draw page boundries
            /*gc.DrawLine(Pens.Black, 100, 100, clipRect.Width - 100, 100);
            gc.DrawLine(Pens.Black, 100, 100, 100, clipRect.Height-100);
            gc.DrawLine(Pens.Black, 100, clipRect.Height-100, clipRect.Width - 100, clipRect.Height-100);
            gc.DrawLine(Pens.Black, clipRect.Width-100, 100, clipRect.Width - 100, clipRect.Height-100);*/

            // draw items on page

            // draw gray mask
            //gc.FillRectangle(Brushes.LightGray, 0, 0, 99, clipRect.Height);
            //gc.FillRectangle(Brushes.LightGray, 0, 0, clipRect.Width, 99);
            //gc.FillRectangle(Brushes.LightGray, clipRect.Width-99, 0, clipRect.Width, clipRect.Height);
            //gc.FillRectangle(Brushes.LightGray, 0, clipRect.Height-99, clipRect.Width, clipRect.Height);
        }
Example #9
0
        public static Image GetRotateImage(this Image img, float angle)
        {
            angle = angle % 360;//弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = img.Width;
            int h = img.Height;
            int W = 80; // (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = 80; //(int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Image dsImage = new Bitmap(W, H, img.PixelFormat);

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage))
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
                g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //计算偏移量
                Point Offset = new Point((W - w) / 2, (H - h) / 2);
                //构造图像显示区域:让图像的中心与窗口的中心点一致
                Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
                Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
                g.TranslateTransform(center.X, center.Y);
                g.RotateTransform(360 - angle);
                //恢复图像在水平和垂直方向的平移
                g.TranslateTransform(-center.X, -center.Y);
                g.DrawImage(img, rect);
                //重至绘图的所有变换
                g.ResetTransform();
                g.Save();
            }
            return(dsImage);
        }
Example #10
0
        public void Draw(Graphics g, Player player)
        {
            if (ShootingPoints.Count > 0)
            {
                try
                {
                    g.DrawCurve(shootingPen, ShootingPoints.ToArray());
                    g.TranslateTransform(1, 0);
                    g.DrawCurve(shootingPen1, ShootingPoints.ToArray());
                    g.ResetTransform();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Shot.cs-Draw-EXCEPTION :  {0}", e.Message);
                }
                //STRELKA
                Point lastOne = (Point)ShootingPoints[ShootingPoints.Count-1];
                trianglePoints = new Point[3];

                trianglePoints[0] = new Point(lastOne.X - 2, lastOne.Y - 10);
                trianglePoints[1] = new Point(lastOne.X - 8, lastOne.Y + 2);
                trianglePoints[2] = new Point(lastOne.X + 4, lastOne.Y + 2);

                g.FillPolygon(new SolidBrush(Color.Black), trianglePoints);
                trianglePoints = new Point[3];
            }
        }
        public void Draw(Graphics g)
        {
            g.ResetTransform();

            var rnd = new Random();
            g.TranslateTransform((float)rnd.NextDouble() * g.VisibleClipBounds.Width, (float)rnd.NextDouble() * g.VisibleClipBounds.Height / 2f);
            g.DrawString(text, new Font("Comic Sans", 14), new SolidBrush(Color.Black), 0,0);
        }
Example #12
0
 public override void onManagedDraw(Graphics graphics)
 {
     graphics.TranslateTransform (this.CenterX, this.CenterY);
     graphics.RotateTransform (90 + this.Angle / (float)Math.PI * 180);
     graphics.TranslateTransform (-this.CenterX, -this.CenterY);
     base.onManagedDraw (graphics);
     graphics.ResetTransform ();
 }
Example #13
0
 public override void Draw(Graphics gr)
 {
     gr.TranslateTransform(location.X, location.Y);
     gr.DrawPath(pen, path);
     if (!string.IsNullOrEmpty(text))
         gr.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, textRect, StringFormat.GenericDefault);
     gr.ResetTransform();
 }
Example #14
0
        public override void Draw(Graphics gfx, Point offset)
        {
            gfx.TranslateTransform(offset.X, offset.Y);

            if (Points.Count > 1)
                gfx.DrawCurve(pen, Points.ToArray());

            gfx.ResetTransform();
        }
Example #15
0
        public override void Draw(Graphics g, List<Matrix> listMatrix)
        {
            //单位一定要是MM。
            g.PageUnit = GraphicsUnit.Millimeter;

            //定义画笔
            Pen _myPen = new Pen(PenColor, _penWidth);
            _myPen.DashStyle = PenDashStyle;

            GraphicsPath path = base.getGraphicsPath();//首先取得没有偏移但有旋转的路径

            //再反转这个个变换
            listMatrix.Reverse();

            if ((listMatrix != null) && (listMatrix.Count > 0))//只有数量大于0才能做如下的
            {
                for (int i = 0; i < listMatrix.Count; i++)
                {
                    path.Transform((Matrix)listMatrix[i]);

                }
            }

            //如下这个就是画边界
            try
            {

                g.DrawPath(_myPen, path);

            }
            catch (Exception ex)
            {
                ////ClsErrorFile.WriteLine(ex);
                //throw;
            }

            //throw new NotImplementedException();
            if (_isFill)
            {
                try
                {

                    g.FillPath(new SolidBrush(_FillColor), path);

                }
                catch (Exception ex)
                {
                    ////ClsErrorFile.WriteLine(ex);
                    //throw;
                }

            }

            g.ResetTransform();
            //base.Draw(g, arrlistMatrix);
        }
Example #16
0
        public override void Draw(Graphics g, GraphPane pane)
        {
            SizeF size;
            PointF pos;
            float x, y1, y2, y3;
            string label;

            //Draw Axis Title
            if (mTitle.Visible) {
                using (Brush brush = new SolidBrush(mTitle.Color)) {
                    if (mTitle.Orientation == Orientation.Vertical) {
                        g.RotateTransform(-90);
                        g.TranslateTransform(-mPane.ClientRectangle.Height, 0);
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mTitle.Padding, mRect.Left + mRect.Width / 2 - size.Height / 2);
                        g.DrawString(mTitle.Text, mTitle.Font, brush, pos);
                        g.ResetTransform();
                    } else {
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mRect.Left + (mRect.Width / 2 - size.Width / 2), mRect.Top + mTitle.Padding);
                        if (mLabels.Visible) pos.Y += (mLabels.Font.Height + (mLabels.Padding * 2));
                        g.DrawString(mTitle.Text, mTitle.Font, brush, pos);

                    }
                }
            }

            //Draw Minor Gridlines and Marks
            y1 = mRect.Top - mMinorMark.Size;
            y2 = mRect.Top;
            for (double dx = Minimum; dx <= Maximum; dx += mMinorStep) {
                x = mRect.X + (float)((dx - mMinimum) * mScale);
                if (mMinorMark.Visible) g.DrawLine(mMinorMark.Pen, x, y1, x, y2);
            }

            //Draw Major Gridlines, Marks and Labels
            y1 = mRect.Top - mMajorMark.Size;
            y2 = mRect.Top;
            y3 = y2 + mLabels.Padding;
            using (Brush b = new SolidBrush(mLabels.Color)) {
                for (double dx = Minimum; dx <= Maximum; dx += mMajorStep) {
                    x = mRect.X + (float)((dx - mMinimum) * mScale);
                    if (mMajorMark.Visible) g.DrawLine(mMajorMark.Pen, x, y1, x, y2);
                    if (mLabels.Visible) {
                        label = FormatLabel(dx);
                        size = g.MeasureString(label, mLabels.Font);
                        x = x - size.Width / 2;
                        if (mPane.ClientRectangle.Contains(x, y3) && mPane.ClientRectangle.Contains(x + size.Width, y3 + size.Height))
                            g.DrawString(label, mLabels.Font, b, x, y3);
                    }
                }
            }

            //Draw The Axis
            g.DrawLine(mPen, mRect.Left, mRect.Top, mRect.Right, mRect.Top);
        }
 public override void Draw(Graphics gr, Point position, Range range)
 {
     foreach (Place p in range)
     {
         int time = (int)(DateTime.Now.TimeOfDay.TotalMilliseconds/2);
         int angle = (int)(time % 360L);
         int angle2 = (int)((time - (p.iChar - range.Start.iChar)*20) % 360L)*2;
         int x =  position.X + (p.iChar - range.Start.iChar) * range.tb.CharWidth;
         Range r = range.tb.GetRange(p, new Place(p.iChar+1, p.iLine));
         Point point = new Point(x, position.Y + (int)(5 + 5 * Math.Sin(Math.PI * angle2 / 180)));
         gr.ResetTransform();
         gr.TranslateTransform(point.X + range.tb.CharWidth / 2, point.Y +range.tb.CharHeight / 2);
         gr.RotateTransform(angle);
         gr.ScaleTransform(0.8f, 0.8f);
         gr.TranslateTransform(- range.tb.CharWidth / 2, -range.tb.CharHeight / 2);
         base.Draw(gr, new Point(0, 0), r);
     }
     gr.ResetTransform();
 }
Example #18
0
 public static void DrawRectangleRotated(Graphics g, Rectangle r, float angle, Pen pen)
 {
     using (Matrix m = new Matrix())
     {
         m.RotateAt(angle, new PointF(r.Left + (r.Width / 2), r.Top + (r.Height / 2)));
         g.Transform = m;
         g.DrawRectangle(pen, r);
         g.ResetTransform();
     }
 }
Example #19
0
        public override void Draw(Graphics g, GraphPane pane)
        {
            SizeF size;
            PointF pos;
            float y, x1, x2, x3;
            string label;

            //Draw Axis Title
            if (mTitle.Visible) {
                using (Brush b = new SolidBrush(mTitle.Color)) {
                    if (mTitle.Orientation == Orientation.Vertical) {
                        g.RotateTransform(-90);
                        g.TranslateTransform(-mRect.Height, 0);
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mRect.Height / 2 - size.Width / 2, mRect.Left + mTitle.Padding);
                        g.DrawString(mTitle.Text, mTitle.Font, b, pos);
                        g.ResetTransform();
                    } else {
                        size = g.MeasureString(mTitle.Text, mTitle.Font);
                        pos = new PointF(mRect.Left + mTitle.Padding, mRect.Height / 2 - size.Width / 2);
                        g.DrawString(mTitle.Text, mTitle.Font, b, pos);
                    }
                }
            }

            //Draw Minor Grid and Mark
            x1 = mRect.Right + mMinorMark.Size;
            x2 = x1 - mMinorMark.Size;
            for (double dy = Minimum; dy < Maximum; dy += mMinorStep) {
                y = mRect.Bottom - (float)((dy - mMinimum) * mScale);
                if (mMinorMark.Visible) g.DrawLine(mMinorMark.Pen, x1, y, x2, y);
            }

            //Draw Major Gridlines, Marks and Labels
            x1 = mRect.Right + mMajorMark.Size;
            x2 = x1 - mMajorMark.Size;

            using (Brush b = new SolidBrush(mLabels.Color)) {
                for (double dy = Minimum; dy <= Maximum; dy += mMajorStep) {
                    y = mRect.Bottom - (float)((dy - mMinimum) * mScale);
                    if (mMajorMark.Visible) g.DrawLine(mMajorMark.Pen, x1, y, x2, y);
                    if (mLabels.Visible) {
                        label = dy.ToString(mLabels.Format);
                        size = g.MeasureString(label, mLabels.Font);
                        y = y - size.Height / 2;
                        x3 = x2 - (size.Width + mLabels.Padding);
                        if (mPane.ClientRectangle.Contains(x3, y) && mPane.ClientRectangle.Contains(x3, y + size.Height))
                            g.DrawString(label, mLabels.Font, b, x3, y);
                    }
                }
            }

            //Draw The Axis
            g.DrawLine(mPen, mRect.Right, mRect.Top, mRect.Right, mRect.Bottom);
        }
 public void ResetTransform()
 {
     if (isD3D)
     {
         d3d.ResetTransform();
     }
     else
     {
         gdi.ResetTransform();
     }
 }
Example #21
0
        /*                          Implementation
         *  private void button1_Click(object sender, EventArgs e)
         *  {
         *      using (Graphics G = this.CreateGraphics())
         *          drawShadow(G, Color.Black, getRectPath(new Rectangle(111, 111, 222, 222)), 17);
         *  }
         *
         */
        #endregion

        /// <summary>
        /// Draw Shadow
        /// </summary>
        /// <param name="G">Graphics class to use</param>
        /// <param name="c">Color of the shadow</param>
        /// <param name="GP">Graphics Path or Path of the shadow</param>
        /// <param name="d">Integer to represent index of a color.</param>
        /// <param name="control">Control to implement the shadow.</param>
        public static void DrawShadow(this System.Drawing.Graphics G, Color c, GraphicsPath GP, int d, Control control)
        {
            Color[] colors = getColorVector(c, control.BackColor, d).ToArray();
            for (int i = 0; i < d; i++)
            {
                G.TranslateTransform(1f, 0.75f);             // <== shadow vector!
                using (Pen pen = new Pen(colors[i], 1.75f))  // <== pen width (*)
                    G.DrawPath(pen, GP);
            }
            G.ResetTransform();
        }
Example #22
0
        private void PaintTriangle(System.Drawing.Graphics g)
        {
            System.Drawing.Pen myPen;
            myPen           = new System.Drawing.Pen(_color);
            myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;

            //get suitable triangle dimensions
            double stepSize = 5;
            double gHeight  = this.Height - stepSize; //start out from height or depth
            double gWidth   = gHeight * _sideslope * 2.0;

            do
            {
                if (gWidth > this.Width)
                {
                    gHeight -= stepSize;
                    gWidth   = gHeight * _sideslope * 2.0;
                }
                else
                {
                    break;
                }
            } while (true);

            int xPt, yPt;

            xPt = (this.Width - (int)gWidth) / 2;
            yPt = (this.Height - (int)gHeight) / 2;

            float xPtMid = (float)(xPt + gWidth / 2);
            float yPtMid = (float)(yPt + gHeight);

            g.DrawLine(myPen, (float)xPt, (float)yPt, xPtMid, yPtMid);
            g.DrawLine(myPen, (float)(xPt + gWidth), (float)yPt, xPtMid, yPtMid);

            myPen.Color     = Color.Black;
            myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            //g.DrawLine(myPen, xPt, yPt, xPt + (int)gWidth, yPt);
            g.DrawLine(myPen, xPt + (int)(gWidth / 2), yPt, xPt + (int)(gWidth / 2), yPt + (int)gHeight);

            string     sSideSlope = _sideslope.ToString() + " (Side Slope H:V)";
            string     sDepth     = _depth.ToString() + " (Max. Depth)";
            Font       lblFont    = new Font(System.Drawing.FontFamily.GenericSerif, 9);
            SolidBrush lblBrush   = new SolidBrush(Color.Black);

            g.DrawString(sDepth, lblFont, lblBrush, (float)(xPt + gWidth / 2 + 1), (float)(yPt + gHeight / 2));
            float lRotateAng = (float)(Math.Atan2(1.0d, _sideslope) * (180 / Math.PI));

            g.TranslateTransform((float)(xPt + gWidth / 8 + 1), (float)(yPt + gWidth / 8 / 3 - 1));
            g.RotateTransform(lRotateAng);
            //g.DrawString(sSideSlope, lblFont, lblBrush, (float)(xPt + gWidth / 8), (float)(yPt + gWidth/8/3));
            g.DrawString(sSideSlope, lblFont, lblBrush, this.DisplayRectangle);
            g.ResetTransform();
        }
Example #23
0
        public void Draw(Graphics g)
        {
            g.ResetTransform();

            g.ScaleTransform(1 + (float)Math.Cos(angle/200f)/1f, 1+ (float)Math.Cos(angle/200f)/1f);
            g.TranslateTransform(g.VisibleClipBounds.Width / 2f, g.VisibleClipBounds.Height / 2f);

            angle += 10;
            g.RotateTransform(angle);

            g.DrawPolygon(new Pen(new SolidBrush(Color.Black), 3), vertices);
        }
Example #24
0
        private static void DrawWall(System.Drawing.Graphics g, PointF startingPoint, float size, float length, float rotation)
        {
            var point = startingPoint.FromTableCenter();

            length *= 2.12f;
            size   *= 0.28f;

            g.TranslateTransform(point.X, point.Y);
            g.RotateTransform(-rotation);
            g.FillRectangle(Brushes.DarkBlue, -size / 2.0f, -length, size, length);
            g.ResetTransform();
        }
Example #25
0
        public virtual void Draw(Graphics g, Tank t)
        {
            // TODO: Fill here

            Rectangle rect = new Rectangle((int)pos.X - width / 2, (int)pos.Y - height / 2, width, height);

            Matrix m = new Matrix();
            m.RotateAt((float)orientation, pos);

            g.FillRectangle(new SolidBrush(color), rect);
            g.ResetTransform();
        }
        public static void RotateRect(Graphics g, Rectangle r, float angle, Color color)
        {
            using (Matrix m = new Matrix())
            {
                m.RotateAt(angle, new PointF(r.Left + (r.Width / 2), r.Top + (r.Height / 2)));
                g.Transform = m;
                SolidBrush br = new SolidBrush(color);
                g.FillRectangle(br, r);

                g.ResetTransform();
            }
        }
Example #27
0
        public void Draw(Graphics g)
        {
            g.TranslateTransform(TranslationParameter.X, TranslationParameter.Y);
            //Draw board's border
            g.DrawRectangle(new Pen(Brushes.Gold, 5), playField);
            g.FillRectangle(new SolidBrush(Color.FromArgb(20, 20, 20)), playField);

            for (int i = 0; i < board.Count; i++)
                for (int j = 0; j < board.Count; j++)
                    board[i][j].Draw(g);

            g.ResetTransform();
        }
Example #28
0
 public void drawthisline(Graphics g,float zoom)
 {
     midpoint = new PointF((start.X + end.X) / 2, (start.Y + end.Y) / 2);
     g.DrawLine(line_pen, start.X*zoom,start.Y*zoom,end.X*zoom,end.Y*zoom);
     g.TranslateTransform(start.X*zoom, start.Y*zoom);
        //    m.Rotate((float)Math.Atan((start.Y - end.Y) / (start.X - end.Y)),MatrixOrder.Append);
     float degree=(float)((180/Math.PI)*Math.Atan((start.Y - end.Y) / (start.X - end.Y)));
     Console.WriteLine("Value of degree:"+degree);
     //.WriteLine("Distance is {0}", distanceinmetres.ToString("f2"));
     //g.RotateTransform(degree);
     g.DrawString(line_name+": "+(line_length*ImagePropertiesClass.scale_value).ToString("f2")+ImagePropertiesClass.scale_unit, new Font(FontFamily.GenericSerif, 10), Brushes.Black,new PointF(0,0));
     g.ResetTransform();
 }
Example #29
0
        private void PaintRectangle(System.Drawing.Graphics g)
        {
            System.Drawing.Pen myPen;
            myPen = new System.Drawing.Pen(_color);

            //get suitable rectangle dimensions
            double stepSize = 5;
            double gWidth   = this.Width - stepSize;
            double WtoH     = _width / _depth;
            double gHeight  = gWidth / WtoH;

            do
            {
                if (gHeight >= this.Height)
                {
                    gWidth -= stepSize;
                    gHeight = gWidth / WtoH;
                }
                else
                {
                    break;
                }
            } while (true);

            int xPt, yPt;

            xPt = (this.Width - (int)gWidth) / 2;
            yPt = (this.Height - (int)gHeight) / 2;
            g.DrawRectangle(myPen, xPt, yPt, (int)gWidth, (int)gHeight);

            myPen.Color = Color.Black;
            //myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            g.DrawLine(myPen, xPt, yPt, xPt + (int)gWidth, yPt);
            g.DrawLine(myPen, xPt + (int)(gWidth / 2), yPt, xPt + (int)(gWidth / 2), yPt + (int)gHeight);

            string     sWidth   = _width.ToString() + " (Top Width)";
            string     sDepth   = _depth.ToString() + " (Depth)";
            Font       lblFont  = new Font(System.Drawing.FontFamily.GenericSerif, 9);
            SolidBrush lblBrush = new SolidBrush(Color.Black);

            g.DrawString(sWidth, lblFont, lblBrush, (float)(xPt + gWidth / 4), (float)(yPt + 3));

            var textSize = TextRenderer.MeasureText(sDepth, lblFont);

            g.TranslateTransform((float)(xPt + gWidth / 2 + textSize.Height + 2), (float)(yPt + 8));
            g.RotateTransform(90f);
            //g.DrawString(sDepth, lblFont, lblBrush, (float)(xPt + gWidth / 2 + 1), (float)(yPt + gHeight / 2));
            g.DrawString(sDepth, lblFont, lblBrush, this.DisplayRectangle);
            g.ResetTransform();
        }
Example #30
0
        private static void DrawLines(System.Drawing.Graphics g, PointF startingPoint, float rotation, IList <Node> lines)
        {
            var point = startingPoint.FromTableCenter();

            foreach (var line in lines)
            {
                g.TranslateTransform(point.X, point.Y);
                g.RotateTransform(-rotation);

                DrawLine(g, line.Position.ToPointF(), (float)line.Scale.X, (float)line.Scale.Z, (float)line.Rotation.Y);

                g.ResetTransform();
            }
        }
		public void Build(Graphics g)
		{
            System.Drawing.Drawing2D.Matrix transform = g.Transform;
            try
            {
                g.ResetTransform();
                BuildPrivate(g);
            }
            finally
            {
                g.Transform = transform;
            }
            return;
        }
Example #32
0
        public void DrawColumn(Graphics g)
        {
            try {

                g.TranslateTransform(this.Position.X, this.Position.Y);

                //Draw each of the tiles
                _tiles.ForEach( uiTile => {
                    uiTile.DrawTile(g);
                });
            } finally {
                g.ResetTransform();
            }
        }
Example #33
0
        public static void RotateImage(Stream originalStream, string thumbnailPath, int angle)
        {
            Image originalImage = Image.FromStream(originalStream);

            angle = angle % 360;
            //弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = originalImage.Width;
            int h = originalImage.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(originalImage, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            try
            {
                dsImage.Save(thumbnailPath);
            }
            catch
            {
                throw;
            }
            finally
            {
                originalImage.Dispose();
                dsImage.Dispose();
                g.Dispose();
            }
        }
Example #34
0
        public override void Draw(System.Drawing.Graphics g)
        {
            if (IsVisible)
            {
                g.TranslateTransform(Location.X + 50, Location.Y + 50);

                g.DrawArc(new System.Drawing.Pen(new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * Animation), Color.Blue)), 8), new RectangleF(-50, -50, 100, 100), -90, Animation * 360);

                nearestItem = GetNearestItem();
                for (int i = 0; i < actions.Count; i++)
                {
                    g.RotateTransform(-360 * i / actions.Count);

                    g.TranslateTransform(100, 0);
                    g.RotateTransform(360 * i / actions.Count);
                    if (i != nearestItem)
                    {
                        g.ScaleTransform(0.75f, 0.75f);
                    }
                    Actions[i].Draw(g, Animation);
                    if (i != nearestItem)
                    {
                        g.ScaleTransform(1f / 0.75f, 1f / 0.75f);
                    }
                    g.RotateTransform(-360 * i / actions.Count);
                    g.TranslateTransform(-100, 0);
                    g.RotateTransform(360 * i / actions.Count);
                }
                float  angle           = Game.GetPointAngle(new Point(Convert.ToInt32(Location.X) + 50, Convert.ToInt32(Location.Y) + 50), Program.game.MousePosition);
                float  length          = Game.GetPointLength(new Point(Convert.ToInt32(Location.X) + 50, Convert.ToInt32(Location.Y) + 50), Program.game.MousePosition);
                PointF translateLength = Game.LengthDir(64, -angle);
                if (length > 50)
                {
                    g.TranslateTransform(translateLength.X, translateLength.Y);
                    g.RotateTransform(-angle);
                    g.TranslateTransform(-16, -16);
                    g.DrawImageUnscaledAndClipped(Properties.Resources.Arrow, new Rectangle(0, 0, Properties.Resources.Arrow.Width, Properties.Resources.Arrow.Height));
                    g.TranslateTransform(16, 16);
                    g.RotateTransform(angle);
                    g.TranslateTransform(-translateLength.X, -translateLength.Y);
                }
                //g.DrawImageUnscaledAndClipped()
                //g.DrawString(nearestItem.ToString(), new Font("Segoe UI", 14), Brushes.Blue, new PointF(0, 0));


                g.TranslateTransform(-Location.X, -Location.Y);
                g.ResetTransform();
            }
        }
        public void OnDraw(Graphics g)
        {
            if(!isMeasured && !string.IsNullOrEmpty(name))
            {
                isMeasured = true;
                measure = g.MeasureString(name, Game.GetFont());
            }

            g.TranslateTransform(position.X, position.Y);
            g.FillEllipse(Brushes.Red, -size.Width / 2, -size.Height / 2, size.Width, size.Height);

            float px = - (measure.Width / 2);
            g.DrawString(name, Game.GetFont(), Brushes.Black, px, (size.Height / 2) + 5);
            g.ResetTransform();
        }
Example #36
0
        public void RenderObject(System.Drawing.Graphics g)
        {
            g.SmoothingMode = SmoothingMode.HighQuality;
            using (Matrix m = new Matrix())
            {
                var angle = 110 - (msecs2deg(switchCurrentPos) - 28);
                m.RotateAt(angle, new PointF(boxXpos + c2p(g, 5.0), boxYpos));
                g.Transform = m;
                g.TranslateTransform(boxXpos, boxYpos);

                drawSwitchArm(g);
                g.ResetTransform();
            }
            drawLidArm(g, Pens.Black);

            drawBase(g, Pens.Black);

            using (Matrix m = new Matrix())
            {
                var angle = (msecs2deg(lidCurrentPos) - 11) * 0.5f;
                if (angle > startMoveLidAtDegree)
                {
                    angle -= startMoveLidAtDegree;
                }
                else
                {
                    angle = 0;
                }
                m.RotateAt(angle, new PointF(boxXpos + 600, boxYpos - 102));// 248));
                g.Transform = m;
                drawLid(g, Pens.Black);
                g.ResetTransform();
            }

            drawSwitch(g, switchState);
        }
Example #37
0
        /// <summary>
        /// 绘制续打区域
        /// </summary>
        /// <param name="g">图形绘制对象</param>
        /// <param name="ClipRectangle">剪切矩形</param>
        /// <param name="Position">续打位置</param>
        /// <param name="FillColor">填充色</param>
        protected void DrawJumpPrintArea(
            System.Drawing.Graphics g,
            System.Drawing.Rectangle ClipRectangle,
            int Position,
            System.Drawing.Color FillColor)
        {
            MultiPageTransform trans = (MultiPageTransform)this.myTransform;
            int pos = trans.UnTransformY(Position);

            if (pos >= 0)
            {
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                    0,
                    0,
                    this.ClientSize.Width,
                    pos);

                System.Drawing.Rectangle rect2 = ClipRectangle;
                if (ClipRectangle.IsEmpty)
                {
                    rect2 = rect;
                }
                else
                {
                    rect2 = System.Drawing.Rectangle.Intersect(rect, rect2);
                }
                if (!rect2.IsEmpty)
                {
                    g.ResetClip();
                    g.PageUnit = System.Drawing.GraphicsUnit.Pixel;
                    g.ResetTransform();
                    using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(FillColor))
                    {
                        g.FillRectangle(b, rect2);
                    }
                    using (System.Drawing.Pen p =
                               new System.Drawing.Pen(System.Drawing.Color.Blue, 2))
                    {
                        g.DrawLine(
                            p,
                            0,
                            rect.Bottom - 1,
                            this.ClientSize.Width,
                            rect.Bottom - 1);
                    }
                }
            }
        }
Example #38
0
        } // end of Crop

        /// <summary>
        /// 以逆时针方向为正方向对图像进行旋转
        /// </summary>
        /// <param name="b">位图流</param>
        /// <param name="angle">旋转角度[0, 360]</param>
        /// <returns></returns>
        public Bitmap Rotate(Bitmap b, int angle)
        {
            angle = angle % 360;

            // 弧度转化
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);

            // 原图宽高
            int w = b.Width;
            int h = b.Height;

            // 新图的宽高
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));

            // 目标位图,即旋转后的图
            Bitmap dstImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dstImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // 偏移量
            Point offset = new Point((W - w) / 2, (H - h) / 2);

            // 构造图像显示区域:让图像的中心点与窗口的中心点一致
            Rectangle rect   = new Rectangle(offset.X, offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            // 以图像的中心点旋转
            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);

            // 恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);

            // 绘制旋转后的结果图
            g.DrawImage(b, rect);

            // 重置绘图的所有变换
            g.ResetTransform();

            g.Save();

            return(dstImage);
        } // end of Rotate
Example #39
0
        void DrawRobot(Graphics g, Point loc)
        {
            var brush = Brushes.Teal;
            g.TranslateTransform(loc.X + CellLength / 2, loc.Y + CellLength / 2);
            g.RotateTransform(robot.KnownHeading);		//We draw for straight up - a heading of zero.
            g.TranslateTransform(-CellLength / 2, -CellLength / 2);

            g.FillEllipse(brush, 1, 1, CellLength - 2, CellLength - 2);
            //Draw a rectangle in back of the robot
            g.FillRectangle(brush, 1, 1 + CellLength / 2, CellLength - 2, CellLength / 2 - 1);

            //Draw a yellow line near the front of the circle portion
            g.DrawLine(Pens.Yellow, CellLength / 3, CellLength / 4, 2 * CellLength / 3, CellLength / 4);

            g.ResetTransform();
        }
Example #40
0
        public Image RotateImg(Image b, float angle)
        {
            //Bitmap bmpsource=new Bitmap(img);
            //Bitmap bmpsrc=new Bitmap(bmpsource.Width,bmpsource.Height);
            //Rectangle rect = new Rectangle(0, 0, bmpsource.Width, bmpsource.Height);
            //Graphics g = Graphics.FromImage(bmpsource);
            //g.RotateTransform(angle);
            //g.DrawImage(bmpsrc,rect);
            //g.Dispose();
            ////MessageBox.Show("1");
            //return bmpsrc;
            angle = angle % 360;
            //弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            g.Dispose();
            //保存旋转后的图片
            b.Dispose();
            //dsImage.Save("FocusPoint.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            return(dsImage);
        }
        /// <summary>
        /// 图片旋转子函数
        /// </summary>
        /// <param name="b">源图片</param>
        /// <param name="angle">角度</param>
        /// <returns>(无返回值)</returns>
            public Image RotateImg(Image b, int angle)
            
        {
               angle = angle % 360;
               //弧度转换
               double radian = angle * Math.PI / 180.0;
               double cos    = Math.Cos(radian);
               double sin    = Math.Sin(radian);
               //原图的宽和高
               int w = b.Width;
               int h = b.Height;
               int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
               int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
               //目标位图
               Bitmap dsImage            = new Bitmap(W, H);
               System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
               g.InterpolationMode       = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
               g.SmoothingMode           = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
               //计算偏移量
               Point Offset = new Point((W - w) / 2, (H - h) / 2);
               //构造图像显示区域:让图像的中心与窗口的中心点一致
               Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
               Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
               g.TranslateTransform(center.X, center.Y);

               g.RotateTransform(360 - angle);

               //恢复图像在水平和垂直方向的平移
               g.TranslateTransform(-center.X, -center.Y);

               g.DrawImage(b, rect);

               //重至绘图的所有变换
               g.ResetTransform();

               g.Save();

               g.Dispose();

               //显示旋转后的图片
            b.Dispose();

            pictureBox4.Image = dsImage;
            return(dsImage);

              
        }
 //填充矩形(包括边缘如x为0,跨度为10,填充0-9)
 public static void fillRect(Graphics g, int x, int y, int width, int height, Color color, Rect limitRect)
 {
     if (width <= 0 || height <= 0 || g == null) return;
     g.ResetTransform();
     g.SetClip(new Rectangle(x - 1, y - 1, width + 2, height + 2));
     if (limitRect != null)
     {
         Rectangle rect = limitRect.rect;
         if (rect.Width > 0 && rect.Height > 0)
         {
             g.SetClip(rect, CombineMode.Intersect);
         }
     }
     Brush myBrush = new SolidBrush(color);
     g.FillRectangle(myBrush, x, y, width, height);
     myBrush.Dispose();
 }
Example #43
0
 private void drawAnt(Ant ant, Graphics g)
 {
     int x, y;
     toScreenCoords(ant.x, ant.y, out x, out y);
     SolidBrush brush = new SolidBrush(new Color[] { Color.DarkRed, Color.Black }[ant.color]);
     Matrix m = new Matrix();
     m.Translate(x + CELL_SIZE / 2, y + CELL_SIZE / 2);
     m.Rotate(60 * ant.direction);
     g.Transform = m;
     g.FillEllipse(brush,
         -5, -3, 10, 6);
     if (ant.hasFood)
     {
         Pen pen = new Pen(Color.Yellow);
         g.DrawRectangle(pen, 2, -1, 2, 2);
     }
     g.ResetTransform();
 }
Example #44
0
        private static void RenderBitmapPoint(Graphics graphics, Point point, IViewport viewport, SymbolStyle symbolStyle)
        {
            var symbol = new Bitmap(BitmapRegistry.Instance.Get(symbolStyle.BitmapId));
            var symbolscale = symbolStyle.SymbolScale;
            var offset = symbolStyle.SymbolOffset.ToGdi();
            var rotation = symbolStyle.SymbolRotation;
            var dest = ConvertPoint(viewport.WorldToScreen(point));

            var width = symbol.Width * symbolscale;
            var height = symbol.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            graphics.DrawImage(symbol, 0, 0, (float)width, (float)height);
            graphics.ResetTransform();
        }
        /// <summary>
        /// ワールド座標、回転を使ってレイヤーマップを生成
        /// </summary>
        /// <param name="g"></param>
        /// <param name="layer"></param>
        /// <param name="drawGuideLine"></param>
        /// <param name="fastDraw"></param>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        /// <param name="bUseView">View座標で描画(BMP出力時などはfalse)</param>
        private void DrawLayerToWorld(Graphics g, LayerData layer, bool drawGuideLine, bool fastDraw)
        {
            int ctrX = layer.MapBmp.Width / 2;
            int ctrY = layer.MapBmp.Height / 2;

            g.InterpolationMode = InterpolationMode.HighQualityBilinear;

            g.ResetTransform();
            //g.ScaleTransform((float)DrawMapScale, (float)DrawMapScale);
            g.TranslateTransform(-ctrX, -ctrY, MatrixOrder.Append);
            g.RotateTransform((float)layer.wAng, MatrixOrder.Append);
            g.TranslateTransform(ctrX + (int)layer.wX, ctrY + (int)layer.wY, MatrixOrder.Append);

            // View
            g.ScaleTransform(ViewScale, ViewScale, MatrixOrder.Append);
            g.TranslateTransform(ViewTransX, ViewTransY, MatrixOrder.Append);

            //g.DrawImageUnscaled(layer.MapBmp, 0, 0);
            if (fastDraw)
            {
                // 高速描画用トライアングル
                g.DrawPolygon(Pens.Red, layer.psLayerTriangle);
            }
            else
            {
                // 通常描画
                g.DrawImage(layer.MapBmp, 0, 0);
            }

            if (drawGuideLine)
            {
                // 枠線描画
                Rectangle rect = new Rectangle(0, 0, layer.MapBmp.Width - 1, layer.MapBmp.Height - 1);
                Pen colPen = Pens.Silver;

                if (layer.drawColor == colEditLayerPixel)
                {
                    colPen = new Pen(colEditLayerPixel);
                }
                g.DrawRectangle(colPen, rect);
            }
        }
Example #46
0
        /// <summary>
        /// 绘制选中区域 Add by wwj 2012-04-17
        /// </summary>
        /// <param name="g"></param>
        /// <param name="clipRectangle"></param>
        /// <param name="leftTopPoint"></param>
        /// <param name="rightBottomPoint"></param>
        /// <param name="FillColor"></param>
        protected void DrawSelectAreaPrint(System.Drawing.Graphics g, System.Drawing.Rectangle clipRectangle,
                                           Point leftTopPoint, Point rightBottomPoint, System.Drawing.Color FillColor)
        {
            MultiPageTransform trans = (MultiPageTransform)this.myTransform;

            //由于leftTopPoint代表鼠标按下的Location, rightBottomPoint代表鼠标弹起的location
            //所以需要重新调整leftTopPoint与rightBottomPoint的位置
            Point tempPoint = leftTopPoint;

            if (leftTopPoint.Y > rightBottomPoint.Y)
            {
                leftTopPoint     = rightBottomPoint;
                rightBottomPoint = tempPoint;
            }
            tempPoint = rightBottomPoint;
            if (leftTopPoint.X > rightBottomPoint.X)
            {
                rightBottomPoint.X = leftTopPoint.X;
                leftTopPoint.X     = tempPoint.X;
            }

            leftTopPoint     = trans.UnTransformPoint(leftTopPoint);
            rightBottomPoint = trans.UnTransformPoint(rightBottomPoint);

            if (true)//表示整行选中
            {
                leftTopPoint.X     = 0;
                rightBottomPoint.X = this.ClientSize.Width;
            }

            if (leftTopPoint != Point.Empty && rightBottomPoint != Point.Empty)
            {
                Rectangle rect = new Rectangle(leftTopPoint.X, leftTopPoint.Y, rightBottomPoint.X - leftTopPoint.X, rightBottomPoint.Y - leftTopPoint.Y);
                g.ResetClip();
                g.PageUnit = System.Drawing.GraphicsUnit.Pixel;
                g.ResetTransform();
                using (System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(FillColor))
                {
                    g.FillRectangle(b, rect);
                }
            }
        }
Example #47
0
 /// <summary>
 /// 以逆时针为方向对图像进行旋转
 /// </summary>
 /// <param name="b">位图流</param>
 /// <param name="angle">旋转角度[0,360](前台给的)</param>
 /// <param name="pathFile">保存后文件的绝对路径</param>
 /// <returns></returns>
 public static bool Rotate(Bitmap b, int angle, string pathFile)
 {
     try
     {
         angle = angle % 360;
         //弧度转换
         double radian = angle * Math.PI / 180.0;
         double cos    = Math.Cos(radian);
         double sin    = Math.Sin(radian);
         //原图的宽和高
         int w = b.Width;
         int h = b.Height;
         int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
         int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
         //目标位图
         Bitmap dsImage            = new Bitmap(W, H);
         System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
         g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
         g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         //计算偏移量
         Point Offset = new Point((W - w) / 2, (H - h) / 2);
         //构造图像显示区域:让图像的中心与窗口的中心点一致
         Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
         Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
         g.TranslateTransform(center.X, center.Y);
         g.RotateTransform(360 - angle);
         //恢复图像在水平和垂直方向的平移
         g.TranslateTransform(-center.X, -center.Y);
         g.DrawImage(b, rect);
         //重至绘图的所有变换
         g.ResetTransform();
         g.Save();
         g.Dispose();
         b.Dispose();
         dsImage.Save(pathFile, System.Drawing.Imaging.ImageFormat.Jpeg);
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
Example #48
0
        public static Bitmap RotateImg(Bitmap b, float angle)
        {
            angle = angle % 360;
            //弧度转换

            double radian = angle * Math.PI / 180.0;

            double cos = Math.Cos(radian);

            double sin = Math.Sin(radian);

            int w = b.Width;

            int h = b.Height;

            int W = w; //(int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));

            int H = h; //(int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));

            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;
            //计算偏移量
            PointF Offset = new PointF((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            RectangleF rect   = new RectangleF(Offset.X, Offset.Y, w, h);
            PointF     center = new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(angle);
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);
            g.ResetTransform();
            g.Save();
            g.Dispose();
            b.Dispose();
            return(dsImage);
        }
Example #49
0
        public override void OnRender(Graphics g) {

            if (!Bearing.HasValue && ImageShadow != null) {
                g.DrawImageUnscaled(ImageShadow, LocalPosition.X, LocalPosition.Y);
            }
            g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

            if (Bearing.HasValue) {
                //g.RotateTransform(Bearing.Value - Overlay.Control.Bearing);
                g.FillPolygon(Brushes.Lime, Arrow);
            }

            g.ResetTransform();

            if (!Bearing.HasValue && Image != null) {
                g.DrawImageUnscaled(Image, LocalPosition.X, LocalPosition.Y);
            }
            if (Image == null) {
                g.FillPolygon(Brushes.Lime, Arrow);
            }
        }
Example #50
0
        private static void RenderVectorPoint(Graphics graphics, Point point, IStyle style, IViewport viewport, StyleContext context)
        {
            var symbolStyle = ToSymbolStyle(style);
            if (symbolStyle.Fill == null) return;

            var symbolscale = symbolStyle.SymbolScale;
            var offset = symbolStyle.SymbolOffset.ToGdi();
            var rotation = symbolStyle.SymbolRotation;
            var dest = ConvertPoint(viewport.WorldToScreen(point));

            var width = symbolStyle.Width * symbolscale;
            var height = symbolStyle.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            DrawSymbol(graphics, symbolStyle, context);
            graphics.ResetTransform();
        }
Example #51
0
        private static void FinishDraw(System.Drawing.Bitmap bmp, System.Drawing.Graphics graphics, IntPtr hdc, IntPtr oldpen, int oldRop, IntPtr img, bool dash)
        {
            SetROP2(hdc, oldRop);

            var transform = graphics.Transform;

            graphics.ResetTransform(); //in case there is transform
            var outBmp = System.Drawing.Image.FromHbitmap(img);

            //CopyChannel(bmp, outBmp, ChannelARGB.Alpha, ChannelARGB.Alpha);
            graphics.Clear(Color.Transparent);
            graphics.DrawImage(outBmp, 0, 0); //draw the xored image on the bitmap
            graphics.Transform = transform;

            if (dash)
            {
                DeleteObject(SelectObject(hdc, oldpen)); //delete new pen (switch to oldpen)
            }
            DeleteObject(img);                           // Delete the GDI bitmap (important).
            DeleteObject(hdc);
        }
        public override void OnRender(Graphics g)
        {
            if (!Bearing.HasValue)
            {
                g.DrawImageUnscaled(global::Gipasoft.Stabili.UI.GeoLocation.Properties.Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            }
            g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

            if (Bearing.HasValue)
            {
                g.RotateTransform(Bearing.Value);
                g.FillPolygon(Brushes.Lime, Arrow);
            }

            g.ResetTransform();

            if (!Bearing.HasValue)
            {
                g.DrawImageUnscaled(global::Gipasoft.Stabili.UI.GeoLocation.Properties.Resources.stabile_large, LocalPosition.X, LocalPosition.Y);
            }
        }
Example #53
0
        public Image RototeImg(Image b, int angle)
        {
            angle = angle % 360;
            //弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);

            int w = b.Width;
            int h = b.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //计算偏移量

            Point     Offset = new Point((W - w) / 2, (H - h) / 2);
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);

            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);

            g.ResetTransform();
            g.Save();
            g.Dispose();

            b.Dispose();
            dsImage.Save("FocusPoint1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            return(dsImage);
        }
        public Image RotateImg(Image b, int angle)//旋转
        {
            angle = angle % 360;
            //弧度转换
            double radian = angle * Math.PI / 180.0;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            //目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //计算偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造图像显示区域:让图像的中心与窗口的中心点一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(angle);
            //恢复图像在水平和垂直方向的平移
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(b, rect);
            //重至绘图的所有变换
            g.ResetTransform();
            //g.Save();
            g.Dispose();
            //保存旋转后的图片
            //dsImage.Save(@"D:\img\" + Path.GetFileNameWithoutExtension(file) + "\\" + angle + ".png", System.Drawing.Imaging.ImageFormat.Png);
            return(dsImage);
        }
Example #55
0
    void DrawShapes()
    {
        SetTitle("Shapes & Brushes");

        var g = new Graphics(this);

        g.FillEllipse(Brushes.Red, 50, 50, 100, 100);
        g.DrawEllipse(Pens.Black, 50, 50, 100, 100);

        g.TranslateTransform(150, 150);
        g.RotateTransform(45);
        g.FillRectangle(Brushes.Yellow, 0, 0, 100, 100);
        g.ResetTransform();

        var rect = new RectangleF(200, 100, 200, 200);
        var lg   = new LinearGradientBrush(rect, Color.Red, Color.Blue, LinearGradientMode.Horizontal);

        g.FillEllipse(lg, rect);

        rect = new RectangleF(500, 100, 200, 200);
        lg   = new LinearGradientBrush(rect, Color.Red, Color.Blue, LinearGradientMode.Horizontal);
        lg.InterpolationColors = ColorBlends.Rainbow;
        g.FillRectangle(lg, rect);
    }
Example #56
0
        public static Image RotaImage(Image image, int angle)
        {
            angle = angle % 360;
            double radian = angle * Math.PI / 180;
            double cos    = Math.Cos(radian);
            double sin    = Math.Sin(radian);

            int w = image.Width;
            int h = image.Height;
            int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
            int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
            // 目标位图
            Bitmap dsImage = new Bitmap(W, H);

            System.Drawing.Graphics g = Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //偏移量
            Point Offset = new Point((W - w) / 2, (H - h) / 2);
            //构造显示区域 与元图像中心一致
            Rectangle rect   = new Rectangle(Offset.X, Offset.Y, w, h);
            Point     center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);

            g.TranslateTransform(center.X, center.Y);
            g.RotateTransform(360 - angle);
            //回复图形在水平垂直位置
            g.TranslateTransform(-center.X, -center.Y);
            g.DrawImage(image, rect);
            //重绘所有变换
            g.ResetTransform();
            //释放资源
            g.Save();
            g.Dispose();
            image.Dispose();
            return(dsImage);
        }
 public void OnDraw(Graphics g)
 {
     g.TranslateTransform(position.X, position.Y);
     g.FillRectangle(Brushes.Blue, -size.Width / 2, -size.Height / 2, size.Width, size.Height);
     g.ResetTransform();
 }
Example #58
0
        /// <summary>
        /// Override OnPaint method
        /// </summary>
        /// <param name="e">paint event argument</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;

            int hh = (int)Math.Round(Height / 2f);

            GraphicsToolkit.FillTriangle(g, 8, new Point(10, hh), GraphicsToolkit.TriangleDirection.Left,
                                         viewScroll > 0 ? SystemPens.WindowText : SystemPens.GrayText);

            int max = this.maxWidth - this.ClientRectangle.Width + rightPadding + 10;

            GraphicsToolkit.FillTriangle(g, 8, new Point(20, hh), GraphicsToolkit.TriangleDirection.Right,
                                         viewScroll < max ? SystemPens.WindowText : SystemPens.GrayText);

            var controlStyle = this.grid.ControlStyle;

            var borderPen        = this.resourceManager.GetPen(controlStyle[ControlAppearanceColors.SheetTabBorder]);
            var defaultTextBrush = this.resourceManager.GetBrush(this.ForeColor);

            Rectangle rect = new Rectangle(leftPadding, 0, ClientRectangle.Width - 4, ClientRectangle.Height - 2);

            #region Border
            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
            {
                switch (this.Position)
                {
                default:
                case SheetTabControlPosition.Top:
                    g.DrawLine(borderPen, 0, rect.Bottom - 1,
                               ClientRectangle.Right, rect.Bottom - 1);
                    break;

                case SheetTabControlPosition.Bottom:
                    g.DrawLine(borderPen, 0, rect.Top, ClientRectangle.Right, rect.Top);
                    break;
                }
            }
            #endregion

            g.SetClip(new Rectangle(ClientRectangle.Left + leftPadding, ClientRectangle.Top,
                                    ClientRectangle.Width - leftPadding - rightPadding, ClientRectangle.Height));

            g.TranslateTransform(-this.viewScroll, 0);

            using (var sf = new StringFormat(StringFormat.GenericTypographic)
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
            })
            {
                int textTopPadding = (this.ClientRectangle.Height - this.Font.Height) / 2;

                #region Unselected items

                for (int i = 0; i < tabs.Count; i++)
                {
                    var tab = this.tabs[i];
                    rect = tab.Bounds;

                    if (i != selectedIndex)
                    {
                        if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                        {
                            using (var bb = new SolidBrush(tab.BackgroundColor))
                            {
                                g.FillRectangle(bb, rect);
                            }
                        }

                        if (!tab.ForegroundColor.IsEmpty && tab.ForegroundColor.A > 0)
                        {
                            using (var fb = new SolidBrush(tab.ForegroundColor))
                            {
                                g.DrawString(tab.Title, this.Font, fb, rect, sf);
                            }
                        }
                        else
                        {
                            g.DrawString(tab.Title, this.Font, defaultTextBrush, rect, sf);
                        }

                        if (i > 0)
                        {
                            g.DrawLine(SystemPens.ControlDark, rect.Left, rect.Top + 4, rect.Left, rect.Bottom - 4);
                        }
                    }

                    if (rect.Left > maxWidth)
                    {
                        break;
                    }
                }

                #endregion

                #region Selected item

                if (this.selectedIndex >= 0 && this.selectedIndex < this.tabs.Count)
                {
                    var tab = this.tabs[this.selectedIndex];
                    rect = tab.Bounds;

                    if (rect.Right > this.viewScroll ||
                        rect.Left < this.maxWidth - this.viewScroll)
                    {
                        int x = rect.Left, x2 = rect.Right, y = 0, y2 = 0;

                        if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                        {
                            if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                            {
                                x++; x2--;
                            }

                            switch (this.Position)
                            {
                            default:
                            case SheetTabControlPosition.Top:
                                y = rect.Top; y2 = rect.Bottom;

                                if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                                {
                                    y++; y2--;
                                }

                                break;

                            case SheetTabControlPosition.Bottom:
                                y = rect.Bottom - 1; y2 = rect.Top;

                                if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                                {
                                    y--; y2++;
                                }

                                break;
                            }

                            // left and right
                            g.DrawLine(borderPen, rect.Left, y, rect.Left, y2);
                            g.DrawLine(borderPen, rect.Right, y, rect.Right, y2);
                        }

                        Brush selectedBackBrush = this.resourceManager.GetBrush(controlStyle[ControlAppearanceColors.SheetTabSelected]);
                        Brush selectedTextBrush = this.resourceManager.GetBrush(controlStyle[ControlAppearanceColors.SheetTabText]);

                        // top or bottom
                        switch (this.Position)
                        {
                        default:
                        case SheetTabControlPosition.Top:
                            var bgrectTop = new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 1, rect.Height - 1);

                            if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                            {
                                using (var bb = new SolidBrush(tab.BackgroundColor))
                                {
                                    g.FillRectangle(bb, bgrectTop);
                                }
                            }
                            else
                            {
                                g.FillRectangle(selectedBackBrush, bgrectTop);
                            }

                            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                            {
                                g.DrawLine(borderPen, x, rect.Top, x2, rect.Top);
                            }
                            break;

                        case SheetTabControlPosition.Bottom:

                            var bgrectBottom = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 1, rect.Height - 1);

                            if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                            {
                                using (var bb = new SolidBrush(tab.BackgroundColor))
                                {
                                    g.FillRectangle(bb, bgrectBottom);
                                }
                            }
                            else
                            {
                                g.FillRectangle(selectedBackBrush, bgrectBottom);
                            }

                            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                            {
                                g.DrawLine(borderPen, x, rect.Bottom - 1, x2, rect.Bottom - 1);
                            }
                            break;
                        }

                        if (this.BorderStyle != SheetTabBorderStyle.NoBorder && Shadow)
                        {
                            g.DrawLine(borderPen, rect.Right + 1, rect.Top + 2, rect.Right + 1, rect.Bottom - 1);
                        }

                        if (!tab.ForegroundColor.IsEmpty && tab.ForegroundColor.A > 0)
                        {
                            using (var fb = new SolidBrush(tab.ForegroundColor))
                            {
                                g.DrawString(tab.Title, this.Font, fb, rect, sf);
                            }
                        }
                        else
                        {
                            g.DrawString(tab.Title, this.Font, selectedTextBrush, rect, sf);
                        }
                    }
                }

                #endregion                 // Selected item
            }

            g.ResetClip();
            g.ResetTransform();

            if (this.NewButtonVisible)
            {
                g.DrawImage(addButtonHover ? newButtonImage : newButtonDisableImage,
                            new Rectangle(this.ClientRectangle.Width - 28, (this.ClientRectangle.Height - 16) / 2, 16, 16));
            }

            for (int i = 4; i < this.ClientRectangle.Height - 4; i += 4)
            {
                g.FillRectangle(SystemBrushes.ControlDark, new Rectangle(this.ClientRectangle.Right - 5, i, 2, 2));
            }

            if (this.movingHoverIndex >= 0 && this.movingHoverIndex <= this.tabs.Count &&
                this.movingHoverIndex != this.movingStartIndex)
            {
                Rectangle itemRect = GetItemBounds(this.movingHoverIndex >= this.tabs.Count ?
                                                   this.tabs.Count - 1 : this.movingHoverIndex);

                GraphicsToolkit.FillTriangle(g, 8, new Point(
                                                 (this.movingHoverIndex >= this.tabs.Count ? itemRect.Right : itemRect.Left) - this.viewScroll,
                                                 itemRect.Top + 4), GraphicsToolkit.TriangleDirection.Up);
            }

            base.OnPaint(e);
        }
Example #59
0
        //
        // CREATE GRADIENT PROFILE
        //
        /// <summary>Creates the route gradient profile.</summary>
        /// <returns>The route gradient profile as Bitmap.</returns>
        /// <param name="Width">The width of the bitmap to create.</param>
        /// <param name="Height">The height of the bitmap to create.</param>
        /// <param name="inGame"><c>true</c> = bitmap for in-game overlay | <c>false</c> = for standard window.</param>
        internal static Bitmap CreateRouteGradientProfile(int Width, int Height, bool inGame)
        {
            if (Program.CurrentRoute.Tracks[0].Elements.Length > 36 && Program.CurrentRoute.Stations.Length == 0)
            {
                // If we have track elements, but no stations, show a specific error message, rather
                // than the more generic one thrown later
                // NOTE: Will throw the generic error message on routes shorter than 900m with no stations
                throw new InvalidDataException(Translations.GetInterfaceString("errors_route_corrupt_nostations"));
            }
            // Track elements are assumed to be all of the same length, and this length
            // is used as measure unit, rather than computing the incremental track length
            // in any 'real world' unit (like m).

            // HORIZONTAL RANGE: find first and last used element based on stations
            int n, n0, n1;

            RouteRange(out n, out n0, out n1);
            // VERTICAL RANGE
            double y0 = double.PositiveInfinity, y1 = double.NegativeInfinity;

            for (int i = n0; i <= n1; i++)
            {
                double y = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Y;
                if (y < y0)
                {
                    y0 = y;
                }
                if (y > y1)
                {
                    y1 = y;
                }
            }
            if (y0 >= y1 - 1.0)
            {
                y0 = y1 - 1.0;
            }

            // allow for some padding around actual data
            double ox = LeftPad, oy = TopPad;
            double w = (double)(Width - (LeftPad + RightPad));
            double h = (double)(Height - (TopPad + BottomPad + TrackOffsPad));
            // horizontal and vertical scale
            double nd = w / (double)(n1 - n0);
            double yd = h / (double)(y1 - y0);
            // set total bitmap track position range; used by in-game profile to place
            // the current position of the trains; as the train positions are known as track positions,
            // actual track positions are needed here, rather than indices into the track element array.
            double minX = Program.CurrentRoute.Tracks[0].Elements[n0].StartingTrackPosition;
            double maxX = Program.CurrentRoute.Tracks[0].Elements[n1].StartingTrackPosition;
            double offX = ox * (maxX - minX) / w;

            lastGradientMinTrack = (int)(minX - offX);
            lastGradientMaxTrack = (int)(maxX + offX);

            // BITMAP (in-game display needs transparency)
            Bitmap b = new Bitmap(Width, Height,
                                  inGame ? System.Drawing.Imaging.PixelFormat.Format32bppArgb
                                        : System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            int mode = inGame ? 1 : 0;

            g.Clear(mapColors[mode].background);

            // BELOW SEA LEVEL
            {
                double y  = oy + (h - 0.5 * (double)(-Program.CurrentRoute.Atmosphere.InitialElevation - y0) * yd);
                double x0 = ox - (double)(0) * nd;
                double x1 = ox + (double)(n1 - n0) * nd;
                g.FillRectangle(mapColors[mode].belowSeaFill, (float)x0, (float)y, (float)x1, (float)(oy + h) - (float)y);
                g.DrawLine(mapColors[mode].belowSeaBrdr, (float)x0, (float)y, (float)x1, (float)y);
            }
            // GRADIENT PROFILE
            {
                n = n1 - n0 + 1;
                PointF[] p = new PointF[n + 2];
                p[0] = new PointF((float)ox, (float)(oy + h));
                for (int i = n0; i <= n1; i++)
                {
                    double x = ox + (double)(i - n0) * nd;
                    double y = oy + (h - 0.5 *
                                     (double)(Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Y - y0) * yd);
                    p[i - n0 + 1] = new PointF((float)x, (float)y);
                }
                p[n + 1] = new PointF((float)(ox + (double)(n - 1) * nd), (float)(oy + h));
                g.FillPolygon(mapColors[mode].elevFill, p);
                for (int i = 1; i < n; i++)
                {
                    g.DrawLine(mapColors[mode].elevBrdr, p[i], p[i + 1]);
                }
                g.DrawLine(mapColors[mode].elevBrdr, 0.0f, (float)(oy + h), (float)Width, (float)(oy + h));
            }
            // STATION NAMES
            {
                Font         f = new Font(FontFamily.GenericSansSerif, 12.0f, GraphicsUnit.Pixel);
                StringFormat m = new StringFormat();
                for (int i = n0; i <= n1; i++)
                {
                    for (int j = 0; j < Program.CurrentRoute.Tracks[0].Elements[i].Events.Length; j++)
                    {
                        if (Program.CurrentRoute.Tracks[0].Elements[i].Events[j] is StationStartEvent)
                        {
                            StationStartEvent e = (StationStartEvent)Program.CurrentRoute.Tracks[0].Elements[i].Events[j];
                            if (Program.CurrentRoute.Stations[e.StationIndex].Name != string.Empty)
                            {
                                bool stop = Program.CurrentRoute.Stations[e.StationIndex].PlayerStops();
                                if (Program.CurrentRoute.Stations[e.StationIndex].Name.IsJapanese())
                                {
                                    m.Alignment     = StringAlignment.Near;
                                    m.LineAlignment = StringAlignment.Near;
                                    double x = ox + (double)(i - n0) * nd;
                                    double y = oy + (h - 0.5 *
                                                     (double)(Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Y - y0) * yd);
                                    string t = Program.CurrentRoute.Stations[e.StationIndex].Name;
                                    float  tx = 0.0f, ty = (float)oy;
                                    for (int k = 0; k < t.Length; k++)
                                    {
                                        SizeF s = g.MeasureString(t.Substring(k, 1), f, 65536, StringFormat.GenericTypographic);
                                        if (s.Width > tx)
                                        {
                                            tx = s.Width;
                                        }
                                    }
                                    for (int k = 0; k < t.Length; k++)
                                    {
                                        g.DrawString(t.Substring(k, 1), f,
                                                     stop ? mapColors[mode].actNameText : mapColors[mode].inactNameText,
                                                     (float)x - 0.5f * tx, ty);
                                        SizeF s = g.MeasureString(t.Substring(k, 1), f, 65536, StringFormat.GenericTypographic);
                                        ty += s.Height;
                                    }
                                    g.DrawLine(stop ? mapColors[mode].actNameBrdr : mapColors[mode].inactNameBrdr,
                                               new PointF((float)x, ty + 4.0f), new PointF((float)x, (float)y));
                                }
                                else
                                {
                                    m.Alignment     = StringAlignment.Far;
                                    m.LineAlignment = StringAlignment.Near;
                                    double x = ox + (double)(i - n0) * nd;
                                    double y = oy + (h - 0.5 *
                                                     (double)(Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Y - y0) * yd);
                                    g.RotateTransform(-90.0f);
                                    g.TranslateTransform((float)x, (float)oy, System.Drawing.Drawing2D.MatrixOrder.Append);
                                    g.DrawString(Program.CurrentRoute.Stations[e.StationIndex].Name, f,
                                                 stop ? mapColors[mode].actNameText : mapColors[mode].inactNameText,
                                                 new PointF(0.0f, -5.0f), m);
                                    g.ResetTransform();
                                    SizeF s = g.MeasureString(Program.CurrentRoute.Stations[e.StationIndex].Name, f);
                                    g.DrawLine(stop ? mapColors[mode].actNameBrdr : mapColors[mode].inactNameBrdr,
                                               new PointF((float)x, (float)(oy + s.Width + 4)), new PointF((float)x, (float)y));
                                }
                            }
                        }
                    }
                }
            }
            // ROUTE MARKERS
            {
                Font         f  = new Font(FontFamily.GenericSansSerif, 10.0f, GraphicsUnit.Pixel);
                Font         fs = new Font(FontFamily.GenericSansSerif, 9.0f, GraphicsUnit.Pixel);
                StringFormat m  = new StringFormat
                {
                    Alignment     = StringAlignment.Far,
                    LineAlignment = StringAlignment.Center
                };
                System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture;
                int k = TrackOffDist * n / Width;
                if (k == 0)
                {
                    if (!inGame)
                    {
                        //If k is equal to zero, this generally means that the WithTrack section is missing from our routefile
                        //Adding zero to the loop control variable will also produce an infinite loop, so that's a bad idea too
                        throw new InvalidDataException(Translations.GetInterfaceString("errors_route_corrupt_withtrack"));
                    }

                    /*
                     * A route with a single station can somehow sometimes work OK in preview but not in-game
                     * Whilst the routefile is probably broken don't chuck the exception here as it takes down the loader
                     */
                    k = 1;
                }

                for (int i = n0; i <= n1; i += k)
                {
                    double x = ox + (double)(i - n0) * nd;
                    double y = (double)(Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Y - y0) * yd;
                    // track offset label
                    if (x < w)
                    {
                        string t = ((int)Math.Round(Program.CurrentRoute.Tracks[0].Elements[i].StartingTrackPosition)).ToString(Culture);
                        g.DrawString(t + "m", f, mapColors[mode].actNameText, (float)x, (float)(oy + h + TrackOffY));
                    }
                    // route height at track offset (with measure and vertical line)
                    {
                        y = oy + (h - 0.5 * y) + 2.0f;
                        string t = ((int)Math.Round(Program.CurrentRoute.Atmosphere.InitialElevation + Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Y)).ToString(Culture);
                        SizeF  s = g.MeasureString(t, fs);
                        if (y < oy + h - (double)s.Width - 10.0)
                        {
                            g.RotateTransform(-90.0f);
                            g.TranslateTransform((float)x, (float)y + 4.0f, System.Drawing.Drawing2D.MatrixOrder.Append);
                            g.DrawString(t + "m", fs, mapColors[mode].actNameText, 0.0f, 0.0f, m);
                            g.ResetTransform();
                            g.DrawLine(mapColors[mode].inactNameBrdr,
                                       (float)x, (float)(y + s.Width + 12.0), (float)x, (float)(oy + h));
                        }
                    }
                }
            }
            // finalize
            return(b);
        }
Example #60
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="PrintHead">是否打印页眉</param>
        /// <param name="PrintTail">是否打印页脚</param>
        public virtual void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = myPages.LeftMargin;
                TopMargin    = myPages.TopMargin;
                RightMargin  = myPages.RightMargin;
                BottomMargin = myPages.BottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);

            g.PageUnit = myDocument.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.bolDrawHead)
            {
                if (myPages.HeadHeight > 0)
                {
                    g.ResetTransform();
                    g.ResetClip();

                    ClipRect = new System.Drawing.Rectangle(0, 0, myPage.Width, myPages.HeadHeight);
                    g.TranslateTransform(LeftMargin, TopMargin);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawHead(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs(g, ClipRect);
                    //myDocument.RefreshView(e);
                }
                g.ResetClip();
                g.ResetTransform();
            }

            ClipRect = new System.Drawing.Rectangle(
                0,
                myPages.Top,
                myPage.Width,
                myPages.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.TranslateTransform(
                    LeftMargin,
                    TopMargin - myPage.Top + myPages.HeadHeight);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                //rect.Offset(-4, -100);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

//				System.Drawing.RectangleF rect2 = g.ClipBounds ;
//				if( rect.Top < rect2.Top )
//				{
//					float dy = rect2.Top - rect.Top ;
//					rect.Y = rect.Y - dy * 2 ;
//					rect.Height = rect.Height + dy * 4 ;
//				}
//				g.SetClip( rect );

                myDocument.DrawDocument(g, ClipRect);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.bolDrawFooter)
            {
                if (myPages.FooterHeight > 0)
                {
                    g.ResetClip();
                    g.ResetTransform();

                    ClipRect = new System.Drawing.Rectangle(
                        0,
                        myPages.DocumentHeight - myPages.FooterHeight,
                        myPage.Width,
                        myPages.FooterHeight);

                    int dy = 0;
                    if (UseMargin)
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight;
                    }
                    else
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight - myPages.TopMargin;
                    }
                    g.TranslateTransform(
                        LeftMargin,
                        dy);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawFooter(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                    //myDocument.RefreshView( e );
                }
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()