RotateTransform() public method

public RotateTransform ( float angle ) : void
angle float
return void
Esempio n. 1
0
 public override void Draw(Graphics g)
 {
     g.RotateTransform((float)-mRotation);
     Point[] p = new Point[]{mImgSec.Location};
     g.Transform.TransformPoints(p);
     if(g.Transform != new System.Drawing.Drawing2D.Matrix() && p[0] == mImgSec.Location)
         throw new OperationCanceledException("Ellipse.Draw: the rotation of the array affects the referenced items in that array: fix");
     g.FillEllipse(new SolidBrush(this.mImgSec.MedianCol), new System.Drawing.Rectangle(p[0], new Size((int)mEllWidth, (int)mEllHeight)));
     g.RotateTransform((float)mRotation);
     base.Draw(g);
 }
Esempio n. 2
0
 public void Draw(Graphics g)
 {
     float dL = length / 2.0f;
     float dW = width / 2.0f;
     g.TranslateTransform(x + dL, y + dW);
     g.RotateTransform(angle);
     g.TranslateTransform(-dL, -dW);
     g.DrawRectangle(new Pen(Color.Black), 0, 0, length, width);
     g.TranslateTransform(dL, dW);
     g.RotateTransform(-angle);
     g.TranslateTransform(-x - dL, -y - dW);
 }
        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
        }
Esempio n. 4
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();
            }
         }
      }
Esempio n. 5
0
        public override void OnRender(Graphics g)
        {
            System.Drawing.Drawing2D.Matrix temp = g.Transform;
            g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
            g.RotateTransform(-MainMap.Bearing);

            try
            {
                g.RotateTransform(bearing);
            }
            catch { }

            g.DrawImageUnscaled(icon, icon.Width / -2, icon.Height / -2);

            g.Transform = temp;
        }
Esempio n. 6
0
        private void DrawRobot(Robot r, Graphics g)
        {
            var frame = (Math.Abs(r.Steps / (int)(0.02 * BPS)) + int.MaxValue / 2) % 8;
            g.TranslateTransform((float)r.X, (float)r.Y);
            g.RotateTransform((float)r.Angle);
            g.DrawImage(RobotImage, new Rectangle(-16, -16, 32, 32), new Rectangle(0 + 32 * frame, 0, 32, 32), GraphicsUnit.Pixel);
            g.RotateTransform((float)r.CannonAngle);
            g.DrawImage(CannonImage, new Rectangle(-7, -7, 24, 14));
            g.RotateTransform(-(float)r.CannonAngle);
            g.RotateTransform(-(float)r.Angle);

            //g.FillPolygon(Brushes.LightGray, new[] {
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-12f)),
            //    new PointF((float)Math.Round(15f), (float)Math.Round(-12f)),
            //    new PointF((float)Math.Round(15f), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            //});
            g.FillPolygon(Brushes.Red, new[] {
                new PointF((float)Math.Round(-15f), (float)Math.Round(-12f)),
                new PointF((float)Math.Round(-15f + 30 * Math.Max(0, r.HP)), (float)Math.Round(-12f)),
                new PointF((float)Math.Round(-15f + 30 * Math.Max(0, r.HP)), (float)Math.Round(-9f)),
                new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            });
            //g.FillPolygon(Brushes.Blue, new[] {
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f + 30 * Math.Max(0, 1 - (double)r.FireCooldown / GameState.FIRE_COOLDOWN)), (float)Math.Round(-9f)),
            //    new PointF((float)Math.Round(-15f + 30 * Math.Max(0, 1 - (double)r.FireCooldown / GameState.FIRE_COOLDOWN)), (float)Math.Round(-7f)),
            //    new PointF((float)Math.Round(-15f), (float)Math.Round(-7f)),
            //});

            g.TranslateTransform(-(float)r.X, -(float)r.Y);
        }
Esempio n. 7
0
		public void Draw (Graphics graphics, Route route, bool atEnd)
		{
			if (graphics == null) return;
			if (route == null) return;
			GraphicsState state = graphics.Save();
			float direction = 0;
			PointF pos = default(PointF);
			if (atEnd)
			{
				pos = route.GetEndPoint();
				direction = ConvertDirection(route.GetEndDirection());
			}
			else
			{
				pos = route.GetStartPoint();
				direction = ConvertDirection(route.GetStartDirection());
			}
			
			// In matrix math, the correct way is to put rotation BEFORE
			// translation. However, the simple transformation maethods of
			// GDI+ works in "Prepend" mode, which reverses the order of
			// operations.
			graphics.TranslateTransform(pos.X, pos.Y);
			graphics.RotateTransform(direction);
			
			Paint(graphics);
			graphics.Restore(state);
		}
Esempio n. 8
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text
            labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Esempio n. 9
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 ();
 }
Esempio n. 10
0
            public override void OnRender(Graphics g)
            {
                double width = (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0)) * 1000.0);
                double height = (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), Overlay.Control.FromLocalToLatLng(Overlay.Control.Height, 0)) * 1000.0);
                double m2pixelwidth = Overlay.Control.Width / width;
                double m2pixelheight = Overlay.Control.Height / height;


                Matrix temp = g.Transform;
                g.TranslateTransform(LocalPosition.X + RectHeight, LocalPosition.Y + RectWidth);
                g.RotateTransform(-Overlay.Control.Bearing);

                
                base.OnRender(g);
                if (RectHeight == 0 || Overlay.Control == null)
                    return;

                // if we have drawn it, then keep that color
                if (!initcolor.HasValue)
                    Color = Color.White;

                //wprad = 300;

                // undo autochange in mouse over
                // if (Pen.Color == Color.Blue)
                // Pen.Color = Color.White;
                

                //GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * RectWidth * 2)), LocalPosition.Y);// MainMap.FromLatLngToLocal(wpradposition);
                GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * RectWidth)), (int)(LocalPosition.Y - (m2pixelheight * RectHeight)));// MainMap.FromLatLngToLocal(wpradposition);

                double direction = LandingDirection;

                //mine
                int x = Offset.X - (int)(Math.Abs(loc.X - (int)LocalPosition.X) / 2);
                int y = Offset.Y - (int)(Math.Abs(loc.Y - (int)LocalPosition.Y) / 2);
                int widtharc = (int)Math.Abs(loc.X - LocalPosition.X);
                int heightarc = (int)Math.Abs(loc.Y - LocalPosition.Y);
                
                if (widtharc > 0)
                {
                    try
                    {
                        g.RotateTransform((int)LandingDirection);
                    }
                    catch { }

                    //draw circle
                    //g.DrawArc(Pen, new System.Drawing.Rectangle(x, y, widtharc, heightarc), 0, 360);
                    //g.FillPie(new SolidBrush(Color.FromArgb(25, FillColor)), x, y, widtharc, heightarc, 0, 360);

                    g.DrawRectangle(Pen, x, y, RectWidth * (int)m2pixelwidth, RectHeight * (int)m2pixelheight);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(25, FillColor)), x, y, RectWidth * (int)m2pixelwidth, RectHeight * (int)m2pixelheight);

                    g.Transform = temp;
                                   
                }
            }
Esempio n. 11
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);
        }
Esempio n. 12
0
        private void DrawBullet(Bullet b, Graphics g)
        {
            if (b.Exploding && b.ExplosionTick > .5 * BPS) return;

            var frame = (Math.Abs(b.ExplosionTick / (int)(.5 / 16 * BPS)) + int.MaxValue / 2) % 16;
            g.TranslateTransform((float)b.X, (float)b.Y);
            if (b.Exploding)
            {
                g.DrawImage(ExplosionImage, new Rectangle(-12, -12, 24, 24),
                    new Rectangle(0 + 24 * (frame % 4), 0 + 24 * (frame / 4), 24, 24), GraphicsUnit.Pixel);
            }
            else
            {
                g.RotateTransform((float)b.Angle);
                g.DrawImage(BulletImage, new Rectangle(-2, -2, 13, 5));
                g.RotateTransform(-(float)b.Angle);
            }
            g.TranslateTransform(-(float)b.X, -(float)b.Y);
        }
Esempio n. 13
0
        public void paint(Graphics g)
        {
            int Xpos = (int)(xpos * frmKeyboard.width);
            int Ypos = (int)(ypos * frmKeyboard.height);
            int size = frmKeyboard.height / 10;

            g.TranslateTransform(Xpos,Ypos);
            g.RotateTransform((float)(angle/Math.PI*180.0f));
            g.TranslateTransform(-1*Xpos,-1*Ypos);

            g.FillRectangle(black, new Rectangle(Xpos-size/2,Ypos-size/2,size,size));

            g.TranslateTransform(Xpos,Ypos);
            g.RotateTransform(-1*(float)(angle/Math.PI*180.0f));
            g.TranslateTransform(-1*Xpos,-1*Ypos);

            Font font =  new Font("Arial", 10.0f);
            g.DrawString(fiducial_id+"",font, white, new PointF(Xpos-10,Ypos-10));
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
        public void Render(Graphics g)
        {
            if (finish != null)
            {
                Matrix m = g.Transform;
                g.TranslateTransform((float)(state.Position.X / CarModel.MM_PER_PIXEL + CarModel.OFFSET_X), (float)(state.Position.Y / CarModel.MM_PER_PIXEL + CarModel.OFFSET_Y));
                g.RotateTransform((float)(state.Angle * 180 / Math.PI + 90));               
                g.DrawImage(finish, new Point((int)(-finish.Width / 1.5), (int)(-finish.Height / 1.5)));
                g.Transform = m;
            }


            if ((selinside != 0) || (seloutside != 0))
            {
                Pen p = new Pen(Color.Black, 1);
                int x = (int)(state.Position.X / CarModel.MM_PER_PIXEL + CarModel.OFFSET_X);
                int y = (int)(state.Position.Y / CarModel.MM_PER_PIXEL + CarModel.OFFSET_Y);
                int r = finish.Width / 2;
                int x2 = (int)(state.Position.X / CarModel.MM_PER_PIXEL + CarModel.OFFSET_X);
                int y2 = (int)(state.Position.Y / CarModel.MM_PER_PIXEL + CarModel.OFFSET_Y);
                int r2 = finish.Width / 2 + OUT_WIDTH;                               

                if (selinside == 1)
                {
                    Pen p2 = new Pen(Color.FromArgb(64,255,255,255), r);
                    g.DrawEllipse(p2, x - r/2, y - r/2, r, r);
                }
                if (seloutside == 1)
                {
                    int w = r2-r;
                    Pen p2 = new Pen(Color.FromArgb(64, 255, 255, 255), w);
                    g.DrawEllipse(p2, x2 - r2 + w / 2, y2 - r2 + w / 2, 2 * r2 - w, 2 * r2 - w);
                }

                g.DrawEllipse(p, x - r, y - r, 2 * r, 2 * r);
                g.DrawEllipse(p, x2 - r2, y2 - r2, 2 * r2, 2 * r2);

                if (selinside == 2)
                {
                    Pen p2 = new Pen(Color.FromArgb(64, 255, 255, 255), r);
                    g.DrawEllipse(p2, x - r / 2, y - r / 2, r, r);
                    p = new Pen(Color.White, 4);
                    g.DrawEllipse(p, x - r, y - r, 2 * r, 2 * r);
                }
                if (seloutside == 2)
                {
                    int w = r2 - r;
                    Pen p2 = new Pen(Color.FromArgb(64, 255, 255, 255), w);                    
                    g.DrawEllipse(p2, x2 - r2 + w / 2, y2 - r2 + w / 2, 2 * r2 - w, 2 * r2 - w);
                    p = new Pen(Color.White, 4);
                    g.DrawEllipse(p, x2 - r2, y2 - r2, 2 * r2, 2 * r2);
                }
            }
        }
        private void DrawElement(Graphics g, Act2DMapLayoutObject.Element e)
        {
            var bitmap = file.CreateBitmapForResource(e.resourceID);
            if (bitmap == null) return;

            g.TranslateTransform(e.x, e.y);
            g.TranslateTransform(bitmap.Width * 0.5f, bitmap.Height * 0.5f);
            g.RotateTransform(e.rotate);
            g.ScaleTransform(e.scale_x, e.scale_y);
            g.TranslateTransform(-bitmap.Width * 0.5f, -bitmap.Height * 0.5f);
            g.DrawImage(bitmap, new PointF(0.0f, 0.0f));
        }
Esempio n. 17
0
        private void TestDraw(Graphics g, bool flip, bool rotate)
        {
            Matrix matrix = g.Transform;

            if (flip) g.ScaleTransform(1, -1);
            if (rotate) g.RotateTransform(90);

            g.DrawRectangle(Pens.Red, 16, 32, 100, 40);
            g.DrawString("Testing 1234567890", Font, Brushes.Red, 24, 48);

            g.Transform = matrix;
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public void DrawTile(Graphics graph)
        {
            var pointsByColors = this.GetAllBordersPoints();

            var containerState = graph.BeginContainer();
            graph.RotateTransform(90 * (int)this.Rotation);

            this.DrawPoints(graph, pointsByColors);
            this.DrawText(graph);

            graph.EndContainer(containerState);
        }
Esempio n. 20
0
		public void Render(Graphics graphics, int tileIndex, int x, int y, Color tint, float rotate = 0)
		{
			var imageAttrs = new ImageAttributes();
			var m = new ColorMatrix(new float[][] {
				new float[] {tint.R / 255.0f, 0, 0, 0, 0 },
				new float[] {0, tint.G / 255.0f, 0, 0, 0 },
				new float[] {0, 0, tint.B / 255.0f, 0, 0 },
				new float[] {0, 0, 0, tint.A / 255.0f, 0 },
				new float[] {0, 0, 0, 0, 1 }
			});
			imageAttrs.SetColorMatrix(m);

			var tileBitmap = new Bitmap(Width, Height); // isolate the tile into it's own bitmap for rotation
			using (var g2 = Graphics.FromImage(tileBitmap))
			{
				g2.DrawImage(_bitmap, 0, 0, _tiles[tileIndex], GraphicsUnit.Pixel);
			}
			graphics.RotateTransform(OpenTK.MathHelper.DegreesToRadians(rotate));
			graphics.DrawImage(tileBitmap, new Rectangle(x, y, Width, Height), 0, 0, Width, Height, GraphicsUnit.Pixel, imageAttrs);
			graphics.RotateTransform(OpenTK.MathHelper.DegreesToRadians(-rotate));
		}
Esempio n. 21
0
        /// <summary>
        /// Apply the rotation
        /// </summary>
        /// <param name="p_g">Graphic object</param>
        /// <param name="p_point">Location where to draw object</param>
        /// <param name="p_bitmap">Reference to bitmap to draw on</param>
        public virtual void ApplyAlteration(Graphics p_g, Point p_point, ref Bitmap p_bitmap)
        {
            p_g.TranslateTransform((float)(p_point.X), (float)(p_point.Y));

            // Rotate desired degrees
            p_g.RotateTransform((float)rotation * -1);

            // Move the origin back to where it belongs while it is rotated
            p_g.TranslateTransform((float)(p_point.X) * -1, (float)(p_point.Y) * -1);

            rotation += angle;
            if (rotation > 360) rotation -= 360;
        }
        public override void Draw(RectangleF dirtyRect)
        {
            Graphics g = new Graphics();
            // Create a pen object:
            Pen aPen = new Pen(Color.Blue, 4);

            // Set line caps and dash style:
            aPen.StartCap = LineCap.Flat;
            aPen.EndCap = LineCap.ArrowAnchor;
            aPen.DashStyle = DashStyle.Dot;
            aPen.DashOffset = 50;

            //g.ScaleTransform(4,4);
            //draw straight line:
            g.DrawLine(aPen, 50, 30, 200, 30);
            // define point array to draw a curve:
            Point point1 = new Point(50, 200);
            Point point2 = new Point(100, 75);
            Point point3 = new Point(150, 60);
            Point point4 = new Point(200, 160);
            Point point5 = new Point(250, 250);
            Point[] Points ={ point1, point2, point3, point4, point5};
            g.DrawCurve(aPen, Points);

            aPen.Dispose();
            //g.Dispose();

            //Text rotation:
            RectangleF ClientRectangle = dirtyRect;
            string s = "A simple text string";

            Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y,
                                           (int)ClientRectangle.Width, (int)ClientRectangle.Height);
            drawingRectangle = new Rectangle(rect.Location, rect.Size);
            Size sz = new Size(rect.Width, rect.Height);
            var font = new Font("Arialss",14.0f,FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
            SizeF stringSize = g.MeasureString(s, font);
            Point Middle = new Point(sz.Width / 30,
                                    sz.Height / 2 - (int)stringSize.Height / 2);
            g.DrawLine(Pens.Black, new Point(0, rect.Height/2), new Point(rect.Width, rect.Height/2));
            g.DrawLine(Pens.Black, new Point(rect.Width / 2, 0), new Point(rect.Width / 2, rect.Height));
            g.TranslateTransform(Middle.X, Middle.Y);
            g.RotateTransform (-90);
            //StringFormat format = new StringFormat(StringFormatFlags.NoClip);
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            //format.LineAlignment = StringAlignment.Center;
            g.DrawString (s, font, Brushes.Black, 0, 0, format);

            g.Dispose();
        }
Esempio n. 23
0
    private static System.Drawing.Bitmap RotateImg
        (System.Drawing.Bitmap bmp, float angle)
    {
        angle = angle % 360;
        if (angle > 180)
        {
            angle -= 360;
        }
        float sin = (float)Math.Abs(Math.Sin(angle *
                                             Math.PI / 180.0));                  // this function takes radians
        float cos          = (float)Math.Abs(Math.Cos(angle * Math.PI / 180.0)); // this one too
        float newImgWidth  = sin * bmp.Height + cos * bmp.Width;
        float newImgHeight = sin * bmp.Width + cos * bmp.Height;
        float originX      = 0f;
        float originY      = 0f;

        if (angle > 0)
        {
            if (angle <= 90)
            {
                originX = sin * bmp.Height;
            }
            else
            {
                originX = newImgWidth;
                originY = newImgHeight - sin * bmp.Width;
            }
        }
        else
        {
            if (angle >= -90)
            {
                originY = sin * bmp.Width;
            }
            else
            {
                originX = newImgWidth - sin * bmp.Height;
                originY = newImgHeight;
            }
        }
        System.Drawing.Bitmap newImg =
            new System.Drawing.Bitmap((int)newImgWidth, (int)newImgHeight);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newImg);
        g.Clear(System.Drawing.Color.White);
        g.TranslateTransform(originX, originY); // offset the origin to our calculated values
        g.RotateTransform(angle);               // set up rotate
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
        g.DrawImageUnscaled(bmp, 0, 0);         // draw the image at 0, 0
        g.Dispose();
        return(newImg);
    }
Esempio n. 24
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();
        }
Esempio n. 25
0
 public override void OnRender(Graphics g)
 {
    //g.DrawRectangle(Pen, new System.Drawing.Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height));
    {
       g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);
       var c = g.BeginContainer();
       {                 
          g.RotateTransform(Bearing - Overlay.Control.Bearing);            
          g.ScaleTransform(Scale, Scale);
          
          g.FillPolygon(Fill, Arrow);               
       }                                                                
       g.EndContainer(c);
       g.TranslateTransform(-ToolTipPosition.X, -ToolTipPosition.Y);
    }
 }
Esempio n. 26
0
        public static void DrawReverseString( Graphics g, string drawText, Font drawFont, Rectangle drawRect, Brush drawBrush, StringFormat drawFormat )
        {
            GraphicsContainer container = g.BeginContainer();

              // The text will be rotated around the origin (0,0) and so needs moving
              // back into position by using a transform
              g.TranslateTransform(drawRect.Left * 2 + drawRect.Width,
            drawRect.Top * 2 + drawRect.Height);

              // Rotate the text by 180 degress to reverse the direction
              g.RotateTransform(180);

              // Draw the string as normal and let then transforms do the work
              g.DrawString(drawText, drawFont, drawBrush, drawRect, drawFormat);

              g.EndContainer(container);
        }
Esempio n. 27
0
            public void Draw(Graphics g)
            {
                //Location corresponds to the center of this image...
                var copyt = g.Transform;

                g.TranslateTransform(Location.X, Location.Y);
                double useangle = (float)(Angle * (180d / Math.PI));
                Debug.Print("useangle:" + useangle);
                g.RotateTransform((float)(useangle));

                g.TranslateTransform((float)-DrawImage.Width / 2, (float)-DrawImage.Height / 2);

                //draw the image at 0,0...
                g.DrawImage(DrawImage, 0, 0,DrawSize.Width,DrawSize.Height);
                //reset the transform.
                g.Transform = copyt;
            }
Esempio n. 28
0
 public void Draw(Graphics g)
 {
     var deltaX = position.X + size.Width / 2;
     var deltaY = position.Y + size.Height / 2;
     g.TranslateTransform(deltaX, deltaY);
     g.RotateTransform(this.transformation.Angle);
     g.TranslateTransform(-deltaX, -deltaY);
     g.DrawImage(this.bitmap, position.X, position.Y, this.size.Width, this.size.Height);
     if (this.Hovered)
     {
         g.DrawRectangle(borderPen, position.X, position.Y, this.size.Width, this.size.Height);
     }
     if (this.Selected)
     {
         g.DrawRectangle(Pens.Orange, position.X, position.Y, this.size.Width, this.size.Height);
     }
     g.ResetTransform();
 }
Esempio n. 29
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();
        }
Esempio n. 30
0
 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();
 }
        /// <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);
            }
        }
Esempio n. 32
0
    /// <summary>
    /// 以逆时针为方向对图像进行旋转
    /// </summary>
    /// <param name="b">位图流</param>
    /// <param name="angle">旋转角度[0,360](前台给的)</param>
    /// <returns></returns>
    protected 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 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("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        return(dsImage);
    }
Esempio n. 33
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);
    }
Esempio n. 34
0
 protected void Page_Load(object sender, System.EventArgs e)
 {
     try
     {
         base.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
         string text = Globals.CreateVerifyCode(4);
         int    num  = 45;
         int    num2 = text.Length * 20;
         System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(num2 - 3, 40);
         System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
         graphics.Clear(System.Drawing.Color.AliceBlue);
         graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Gray, 0f), 0, 0, bitmap.Width - 1, bitmap.Height - 3);
         System.Random      random = new System.Random();
         System.Drawing.Pen pen    = new System.Drawing.Pen(System.Drawing.Color.LightGray, 0f);
         for (int i = 0; i < 50; i++)
         {
             int x = random.Next(0, bitmap.Width);
             int y = random.Next(0, bitmap.Height);
             graphics.DrawRectangle(pen, x, y, 1, 1);
         }
         char[] array = text.ToCharArray();
         System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.NoClip);
         stringFormat.Alignment     = System.Drawing.StringAlignment.Center;
         stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
         System.Drawing.Color[] array2 = new System.Drawing.Color[]
         {
             System.Drawing.Color.Black,
             System.Drawing.Color.Red,
             System.Drawing.Color.DarkBlue,
             System.Drawing.Color.Green,
             System.Drawing.Color.Brown,
             System.Drawing.Color.DarkCyan,
             System.Drawing.Color.Purple,
             System.Drawing.Color.DarkGreen
         };
         for (int j = 0; j < array.Length; j++)
         {
             int num3 = random.Next(7);
             random.Next(4);
             System.Drawing.Font  font  = new System.Drawing.Font("Microsoft Sans Serif", 17f, System.Drawing.FontStyle.Bold);
             System.Drawing.Brush brush = new System.Drawing.SolidBrush(array2[num3]);
             System.Drawing.Point point = new System.Drawing.Point(14, 11);
             float num4 = (float)random.Next(-num, num);
             graphics.TranslateTransform((float)point.X, (float)point.Y);
             graphics.RotateTransform(num4);
             graphics.DrawString(array[j].ToString(), font, brush, 1f, 10f, stringFormat);
             graphics.RotateTransform(-num4);
             graphics.TranslateTransform(2f, (float)(-(float)point.Y));
         }
         System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
         bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Gif);
         base.Response.ClearContent();
         base.Response.ContentType = "image/gif";
         base.Response.BinaryWrite(memoryStream.ToArray());
         graphics.Dispose();
         bitmap.Dispose();
     }
     catch
     {
     }
 }
        /// <summary>
        /// Draw the figure frame with axis labels, ticks, etc.
        /// Style it similar to how ClampFit displays ABF files.
        /// </summary>
        public Bitmap Render()
        {
            // prepare colors and fonts
            Font         font_axis_labels     = new Font("arial", 9, FontStyle.Regular);
            Font         font_title           = new Font("arial", 12, FontStyle.Bold);
            StringFormat string_format_center = new StringFormat();

            string_format_center.Alignment = StringAlignment.Center;
            StringFormat string_format_right = new StringFormat();

            string_format_right.Alignment = StringAlignment.Far;

            // prepare pens
            Pen penAxis = new Pen(color_axis_text);
            Pen penGrid = new Pen(color_grid);

            penGrid.DashPattern = new float[] { 4, 4 };

            // fill the whole canvas with the default background color
            gfx.Clear(color_figure_background);

            // fill the background of the data area
            gfx.FillRectangle(new SolidBrush(color_data_background), data_rectangle);

            // draw a highlight color on the far left
            gfx.FillRectangle(new SolidBrush(color_data_highlight), new Rectangle(0, 0, 30, figure_height - data_pad_bottom));

            // vertical axis label (complicated becasue it's rotated)
            string axis_label_y      = "Analog Input 0\n(pA)";
            SizeF  axis_label_y_size = gfx.MeasureString(axis_label_y, font_axis_labels);

            gfx.RotateTransform(-90);
            gfx.DrawString(axis_label_y, font_axis_labels, new SolidBrush(Color.Black), new Point(-(figure_height - data_pad_bottom) / 2, 1), string_format_center);
            gfx.ResetTransform();

            // title
            gfx.DrawString("ScottPlot Does Amazing Things", font_title, new SolidBrush(color_axis_text), new Point(figure_width / 2, data_pad_top / 2 - 8), string_format_center);

            // horizontal axis label
            gfx.DrawString("Time (ms)", font_axis_labels, new SolidBrush(color_axis_text), new Point(figure_width / 2, figure_height - data_pad_bottom / 2), string_format_center);

            // horizontal axis
            foreach (double tickValX in TickGen(axis_X1, axis_X2, data_width))
            {
                int tickPx = (int)((tickValX - axis_X1) * (double)this.pixels_per_unit_X) + data_pos_left;
                gfx.DrawLine(penGrid, new Point(tickPx, data_pos_top), new Point(tickPx, data_pos_bottom));
                gfx.DrawLine(penAxis, new Point(tickPx, data_pos_bottom), new Point(tickPx, data_pos_bottom + 3));
                string tickLabel = TickString(tickValX, this.axis_X2 - this.axis_X1);
                gfx.DrawString(tickLabel, font_axis_labels, new SolidBrush(color_axis_text), new Point(tickPx, data_pos_bottom + 8), string_format_center);
            }

            // vertical axis
            foreach (double tickValY in TickGen(axis_Y1, axis_Y2, data_height))
            {
                int tickPx = data_pos_bottom - (int)((tickValY - axis_Y1) * (double)this.pixels_per_unit_Y);
                gfx.DrawLine(penGrid, new Point(data_pos_left, tickPx), new Point(data_pos_right, tickPx));
                gfx.DrawLine(penAxis, new Point(data_pos_left - 3, tickPx), new Point(data_pos_left, tickPx));
                string tickLabel = TickString(tickValY, this.axis_Y2 - this.axis_Y1);
                gfx.DrawString(tickLabel, font_axis_labels, new SolidBrush(color_axis_text), new Point(data_pos_left - 3, tickPx - 8), string_format_right);
            }

            // draw a black line around the data area
            gfx.DrawRectangle(penAxis, data_pos_left, data_pos_top, data_width, data_height);

            return(this.bitmap);
        }
Esempio n. 36
0
        private void DrawingSlash(System.Drawing.Graphics g, System.Drawing.Rectangle r, FarPoint.Win.Spread.Appearance appearance, Slash Slash)
        {
            using (Brush brush = new SolidBrush(appearance.ForeColor))
            {
                g.SmoothingMode     = SmoothingMode.HighQuality;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                Brush BackColorBrush = new SolidBrush(appearance.BackColor);
                g.FillRectangle(BackColorBrush, r);
                BackColorBrush.Dispose();

                Pen myPen = new System.Drawing.Pen(Color.Black);

                int   count = 0;
                float Angle, radians;
                int   rightX, rightY;

                Slash    slash  = Slash;
                string[] sArray = slash.Text.Split('|');
                if (sArray.Length != 0)
                {
                    count = sArray.Length - 1;
                }
                int sum = count + 1;

                if (slash.RotationStyle == RotationStyle.Counterclockwise)
                {
                    if (count == 1)
                    {
                        g.DrawLine(myPen, r.X, r.Y + r.Height, r.X + r.Width, r.Y);
                    }
                    else if (count == 2)
                    {
                        g.DrawLine(myPen, r.X, r.Y + r.Height, r.X + (2.0f / 3) * r.Width, r.Y);
                        g.DrawLine(myPen, r.X, r.Y + r.Height, r.X + r.Width, r.Y + (1.0f / 3) * r.Height);
                    }
                    else if (count > 2)
                    {
                        float height;
                        for (int j = 1; j <= count; j++)
                        {
                            Angle  = (90 / sum) * j;
                            height = r.Width / (float)(Math.Tan(Angle * Math.PI / 180.0f));
                            rightX = r.X + r.Width;
                            rightY = r.Y + (int)height;

                            g.DrawLine(myPen, r.X, r.Y, rightX, rightY);
                        }
                    }

                    for (int i = 0; i < sArray.Length; i++)
                    {
                        if (i == 0)
                        {
                            Rectangle _rect = new Rectangle(r.X, r.Y, Convert.ToInt32(((sum - count + 1.0f) / sum) * (r.Width / sum)), Convert.ToInt32(count * 1.0 / sum * r.Height));
                            g.DrawString(sArray[i], appearance.Font, brush, _rect, strFormat);
                        }
                        else if (i == sArray.Length - 1)
                        {
                            Rectangle _rect = new Rectangle(Convert.ToInt32(r.X + (1.0f / sum) * r.Width), Convert.ToInt32(r.Y + r.Height - 1.0f / sum * r.Height), Convert.ToInt32((sum - count * 1.0f) * r.Width / sum), Convert.ToInt32((sum - count * 1.0f) / sum * r.Height));
                            g.DrawString(sArray[i], appearance.Font, brush, _rect, strFormat);
                        }
                        else
                        {
                            if (count == 2)
                            {
                                radians = Convert.ToSingle(Math.Atan(r.Height * 1.0 / r.Width));
                                Angle   = Convert.ToSingle(radians * 180 / Math.PI);
                            }
                            else
                            {
                                Angle = (1 + 2 * i) * (45.0f / (count + 1));
                            }

                            g.TranslateTransform(r.X + 3, r.Y + r.Height - 7);
                            g.RotateTransform(-(float)Angle);
                            g.DrawString(sArray[i], appearance.Font, brush, r.Width / 3f, 0);
                            g.ResetTransform();
                        }
                    }
                }
                else
                {
                    if (count == 1)
                    {
                        g.DrawLine(myPen, r.X, r.Y, r.X + r.Width, r.Y + r.Height);
                    }
                    else if (count == 2)
                    {
                        g.DrawLine(myPen, r.X, r.Y, r.X + (2.0f / 3) * r.Width, r.Y + r.Height);
                        g.DrawLine(myPen, r.X, r.Y, r.X + r.Width, r.Y + (2.0f / 3) * r.Height);
                    }
                    else if (count > 2)
                    {
                        float height;
                        for (int j = 1; j <= count; j++)
                        {
                            Angle  = (90 / sum) * j;
                            height = r.Width / (float)(Math.Tan(Angle * Math.PI / 180.0f));
                            rightX = r.X + r.Width;
                            rightY = r.Y + (int)height;

                            g.DrawLine(myPen, r.X, r.Y, rightX, rightY);
                        }
                    }

                    for (int i = 0; i < sArray.Length; i++)
                    {
                        if (i == 0)
                        {
                            Rectangle _rect = new Rectangle(Convert.ToInt32(r.X + r.Width / sum * 1.0), r.Y, Convert.ToInt32(count * r.Width / sum * 1.0), Convert.ToInt32(((sum - count + 1.0f) / sum) * (r.Height / sum)));
                            g.DrawString(sArray[i], appearance.Font, brush, _rect, strFormat);
                        }
                        else if (i == sArray.Length - 1)
                        {
                            Rectangle _rect = new Rectangle(r.X, Convert.ToInt32(r.Y + r.Height / sum * 1.0), Convert.ToInt32((sum - count + 1.0f) * r.Width / sum / sum), Convert.ToInt32(count * 1.0 * r.Height / sum));
                            g.DrawString(sArray[i], appearance.Font, brush, _rect, strFormat);
                        }
                        else
                        {
                            if (count == 2)
                            {
                                radians = Convert.ToSingle(Math.Atan(r.Height * 1.0 / r.Width));
                                Angle   = Convert.ToSingle(radians * 180 / Math.PI);
                            }
                            else
                            {
                                Angle = (1 + 2 * i) * (45 / (count + 1));
                            }

                            g.TranslateTransform(r.X + 3, r.Y - 4);
                            g.RotateTransform((float)Angle);
                            g.DrawString(sArray[i], appearance.Font, brush, r.Width / 2.8f, 0);
                            g.ResetTransform();
                        }
                    }
                }

                myPen.Dispose();
            }
        }
Esempio n. 37
0
        /// <summary>
        /// Renders a point to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="point">Point to render</param>
        /// <param name="symbol">Symbol to place over point</param>
        /// <param name="symbolscale">The amount that the symbol should be scaled. A scale of '1' equals to no scaling</param>
        /// <param name="offset">Symbol offset af scale=1</param>
        /// <param name="rotation">Symbol rotation in degrees</param>
        /// <param name="map">Map reference</param>
        public static void DrawPoint(System.Drawing.Graphics g, SharpMap.Geometries.Point point, System.Drawing.Bitmap symbol, float symbolscale, System.Drawing.PointF offset, float rotation, SharpMap.Map map)
        {
            if (point == null)
            {
                return;
            }
            if (symbol == null) //We have no point style - Use a default symbol
            {
                symbol = defaultsymbol;
            }
            if (point.UseCustomSymbol)
            {
                symbol = point.Symbol;
            }
            System.Drawing.PointF pp = SharpMap.Utilities.Transform.WorldtoMap(point, map);
            if (float.IsPositiveInfinity(pp.X) || float.IsPositiveInfinity(pp.Y))
            {
                return;
            }
            if (rotation != 0 && rotation != float.NaN)
            {
                g.TranslateTransform(pp.X, pp.Y);
                g.RotateTransform(rotation);
                g.TranslateTransform(-symbol.Width / 2, -symbol.Height / 2);
                if (symbolscale == 1f)
                {
                    g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));
                }
                else
                {
                    float width  = symbol.Width * symbolscale;
                    float height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                }
                g.Transform = map.MapTransform;
            }
            else
            {
                if (symbolscale == 1f)
                {
                    if (point.UseColor)
                    {
                        SolidBrush sBrush = new SolidBrush(point.Color);
                        g.FillRectangle(sBrush, (int)(pp.X - 5 + offset.X), (int)(pp.Y - 5 + offset.Y), 10, 10);
                        g.DrawRectangle(new Pen(Color.Orange), (int)(pp.X - 5 + offset.X), (int)(pp.Y - 5 + offset.Y), 10, 10);
                    }
                    else
                    {
                        g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));
                    }
                }
                else
                {
                    if (point.UseColor && !point.UseCustomSymbol)
                    {
                        SolidBrush sBrush = new SolidBrush(point.Color);
                        g.FillRectangle(sBrush, (int)(pp.X - 5 + offset.X), (int)(pp.Y - 5 + offset.Y), 10, 10);
                        g.DrawRectangle(new Pen(Color.Orange), (int)(pp.X - 5 + offset.X), (int)(pp.Y - 5 + offset.Y), 10, 10);
                    }
                    else if (point.UseColor && point.UseCustomSymbol)
                    {
                        Bitmap transformedSymbol = ConvertBitmapColor(Color.Red, point.Color, symbol);

                        float width  = symbol.Width * symbolscale;
                        float height = symbol.Height * symbolscale;
                        g.DrawImage(transformedSymbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                    }

                    else
                    {
                        float width  = symbol.Width * symbolscale;
                        float height = symbol.Height * symbolscale;
                        g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                    }
                }
            }
        }
Esempio n. 38
0
        public System.Drawing.Bitmap GetNew(System.Drawing.Bitmap pMarqueeData)
        {
            System.Drawing.Bitmap result;
            lock (this.StaticBitmap)
            {
                lock (this.ledSub.LastDrawn)
                {
                    switch (this.ledEdge.Mode)
                    {
                    case LedEdgeMode.Static:
                    {
                        System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(this.StaticBitmap);
                        System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
                        graphics.DrawImage(pMarqueeData, new System.Drawing.Point(this.ledEdge.Height, this.ledEdge.Height));
                        result = bitmap;
                        break;
                    }

                    case LedEdgeMode.Clockwise:
                    case LedEdgeMode.CounterClockwise:
                    {
                        if (this.circularCount >= this.circular)
                        {
                            this.circularCount = 0m;
                        }
                        if (this.circularCount <= -1m)
                        {
                            this.circularCount = this.circular;
                        }
                        System.Drawing.Bitmap   bitmap2   = new System.Drawing.Bitmap(this.AlphaBitmap);
                        System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap2);
                        graphics2.Clear(System.Drawing.Color.Green);
                        if (this.circularCount == 0m)
                        {
                            graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Point(0, 0));
                        }
                        else
                        {
                            graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Point((int)this.circularCount, 0));
                            graphics2.DrawImage(this.EdgeBitmap, new System.Drawing.Rectangle(0, 0, (int)this.circularCount, this.ledEdge.Height), new System.Drawing.Rectangle(this.EdgeBitmap.Width - (int)this.circularCount, 0, (int)this.circularCount, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
                        }
                        bitmap2 = this.SetCornerAlpha(bitmap2);
                        System.Drawing.Bitmap   bitmap3   = new System.Drawing.Bitmap(this.subSize.Width, this.subSize.Height);
                        System.Drawing.Graphics graphics3 = System.Drawing.Graphics.FromImage(bitmap3);
                        graphics3.DrawImage(bitmap2, new System.Drawing.Point(0, 0));
                        graphics3.TranslateTransform(0f, 0f);
                        graphics3.RotateTransform(90f);
                        graphics3.DrawImage(bitmap2, new System.Drawing.Rectangle(0, -this.subSize.Width, this.subSize.Height, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width, -1, this.subSize.Height, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
                        graphics3.DrawImage(bitmap2, new System.Drawing.Rectangle(0, -this.subSize.Width, this.subSize.Height, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width, 0, this.subSize.Height, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
                        graphics3.RotateTransform(90f);
                        graphics3.DrawImage(bitmap2, new System.Drawing.Rectangle(-this.subSize.Width, -this.subSize.Height, this.subSize.Width, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width + this.subSize.Height, -1, this.subSize.Width, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
                        graphics3.RotateTransform(90f);
                        graphics3.DrawImage(bitmap2, new System.Drawing.Rectangle(-this.subSize.Height, 0, this.subSize.Height, this.ledEdge.Height), new System.Drawing.Rectangle(this.subSize.Width * 2 + this.subSize.Height, 0, this.subSize.Height, this.ledEdge.Height), System.Drawing.GraphicsUnit.Pixel);
                        graphics3.RotateTransform(90f);
                        lock (this.ledSub.LastDrawn)
                        {
                            lock (this.ledEdge)
                            {
                                graphics3.DrawImage(pMarqueeData, new System.Drawing.Point(this.ledEdge.Height, this.ledEdge.Height));
                            }
                        }
                        this.circularCount -= this.ledEdge.Speed / 5m;
                        result              = bitmap3;
                        break;
                    }

                    case LedEdgeMode.Blink:
                        this.flashCount += this.ledEdge.Speed;
                        if (this.flashCount >= 200)
                        {
                            this.flashCount = 0;
                        }
                        if (this.flashCount >= 100)
                        {
                            System.Drawing.Bitmap   bitmap4   = new System.Drawing.Bitmap(this.StaticBitmap);
                            System.Drawing.Graphics graphics4 = System.Drawing.Graphics.FromImage(bitmap4);
                            graphics4.DrawImage(pMarqueeData, new System.Drawing.Point(this.ledEdge.Height, this.ledEdge.Height));
                            result = bitmap4;
                        }
                        else
                        {
                            System.Drawing.Bitmap   bitmap5   = new System.Drawing.Bitmap(this.StaticBitmap.Width, this.StaticBitmap.Height);
                            System.Drawing.Graphics graphics5 = System.Drawing.Graphics.FromImage(bitmap5);
                            graphics5.DrawImage(pMarqueeData, new System.Drawing.Point(this.ledEdge.Height, this.ledEdge.Height));
                            result = bitmap5;
                        }
                        break;

                    default:
                        result = null;
                        break;
                    }
                }
            }
            return(result);
        }
Esempio n. 39
0
 partial void RotateTransformImp(float degrees)
 {
     g.RotateTransform(degrees);
 }
Esempio n. 40
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);
        }
Esempio n. 41
0
        private void PaintTrape(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);

            double lBankRun     = gHeight * _sideslope;
            double lWidthBottom = gWidth - 2 * lBankRun;

            Point UL = new Point(xPt, yPt);
            Point BL = new Point((int)(xPt + lBankRun), (int)(yPt + gHeight));
            Point BR = new Point((int)(xPt + lBankRun + lWidthBottom), (int)(yPt + gHeight));
            Point UR = new Point((int)(xPt + gWidth), yPt);

            g.DrawLine(myPen, UL, BL);
            g.DrawLine(myPen, BL, BR);
            g.DrawLine(myPen, BR, UR);

            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();
        }
Esempio n. 42
0
        private void PaintEllipse(System.Drawing.Graphics g)
        {
            System.Drawing.Pen myPen;
            myPen = new System.Drawing.Pen(_color);

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

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

            double upperLeftPtX = (this.Width - gWidth) / 2;
            double upperLeftPtY = (this.Height - gHeight) / 2;

            double upperRightPtX = upperLeftPtX + gWidth;
            double controlX      = upperLeftPtX + (gWidth / 2);
            double controlY      = upperLeftPtY + gHeight;

            double lRad         = (Math.Pow(gHeight, 2.0) + Math.Pow(gWidth / 2.0, 2.0)) / (2 * gHeight);
            double lDropToChord = lRad - gHeight;
            double lStartAngle  = Math.Atan2(lDropToChord, gWidth / 2) * 180 / Math.PI;
            double lSweepAngle  = 180 - 2 * lStartAngle;

            //Rectangle lRect = new Rectangle((int)upperLeftPtX, (int)upperLeftPtY, (int)gWidth, (int)gHeight);
            double    lNewUpperLeftPtX = (upperLeftPtX + gWidth / 2) - lRad;
            double    lNewUpperLeftPtY = upperLeftPtY - lRad - lDropToChord;
            double    lNewHeight       = gHeight + lRad + lDropToChord;
            Rectangle lRect            = new Rectangle((int)lNewUpperLeftPtX, (int)lNewUpperLeftPtY, (int)(lRad * 2), (int)lNewHeight);

            //g.DrawRectangle(myPen, lRect);
            g.DrawArc(myPen, lRect, (float)lStartAngle, (float)lSweepAngle);

            //System.Drawing.Drawing2D.GraphicsPath lArc = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Alternate);
            //lArc.AddArc(lRect, 0, 180);
            //g.DrawPath(myPen, lArc);

            myPen.Color     = Color.Black;
            myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            g.DrawLine(myPen, (int)upperLeftPtX, (int)upperLeftPtY, (int)upperRightPtX, (int)upperLeftPtY);
            g.DrawLine(myPen, (float)controlX, (float)upperLeftPtY, (float)controlX, (float)gHeight);

            String     w = _width.ToString() + "(width)";
            int        xWidthDrawText = (int)gWidth / 2;
            Font       lblFont        = new Font(System.Drawing.FontFamily.GenericSerif, 9);
            SolidBrush lblBrush       = new SolidBrush(Color.Black);

            //g.DrawString(w, lblFont, lblBrush, upperLeftPtX + xWidthDrawText - 5, upperLeftPtY + 10);
            g.DrawString(w, lblFont, lblBrush, (float)(upperLeftPtX + gWidth / 4), (float)(upperLeftPtY + 5));

            String d = _depth.ToString() + " (depth)";
            //g.DrawString(d, lblFont, lblBrush, xDepth, yDepth);
            var textSize = TextRenderer.MeasureText(d, lblFont);

            g.TranslateTransform((float)(upperLeftPtX + gWidth / 2 + textSize.Height + 2), (float)(upperLeftPtY + 8));
            g.RotateTransform(90f);
            g.DrawString(d, lblFont, lblBrush, this.DisplayRectangle);
            g.ResetTransform();
        }
Esempio n. 43
0
        /// <summary>
        /// 以逆时针为方向对图像进行旋转,处理成功后会覆盖原有图片
        /// </summary>
        /// <param name="file_path">文件相对路径</param>
        /// <param name="angle">旋转角度[0,360]</param>
        /// <returns></returns>
        public static void ImageRotate(string file_path, int angle)
        {
            //文件拓展名
            string ext = GetFileExt(file_path);

            Image  img_temp = Image.FromFile(GetMapPath(file_path));
            Bitmap b        = new Bitmap(img_temp);

            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();
            img_temp.Dispose();
            dsImage.Save(GetMapPath(file_path), GetImageFormat(ext));
            GC.Collect();//强制回收
            ////旋转后图片提及会变大,这里进行压缩
            //ImgThumbnail ya = new ImgThumbnail();
            ////临时文件名
            //string file_path_io = GetMapPath(file_path);
            //string fileExt = IOHelper.GetFileExt(file_path_io);
            //string guid = Guid.NewGuid().ToString();
            //string file_path_server = file_path.Substring(0, file_path.LastIndexOf("/")) + "/";
            //Hashtable hash = IOHelper.GetImageWidthHeight(file_path_io);
            //string saveTempName = guid + "_temp." + fileExt;
            //if (ya.Thumbnail(file_path_io, IOHelper.GetMapPath(file_path_server + saveTempName), TypeHelper.ObjectToInt(hash["w"]), TypeHelper.ObjectToInt(hash["h"]), 20, ImgThumbnail.ImgThumbnailType.H))
            //{
            //    //压缩成功,删掉大文件
            //    IOHelper.DeleteIOFile(file_path_io);
            //    //把新文件进行改名
            //    System.IO.File.Move(IOHelper.GetMapPath(file_path_server + saveTempName), file_path_io); //给文件改名
            //}
            //else
            //{
            //    IOHelper.WriteLogs("图片压缩失败");
            //}
        }
Esempio n. 44
0
        /// <summary>
        /// 创建验证图片
        /// </summary>
        /// <param name="Width">宽度</param>
        /// <param name="Height">高度</param>
        /// <param name="VerifyCode">验证码值</param>
        /// <returns></returns>
        public static byte[] CreateVerifyGif(string VerifyCode, int Width, int Height)
        {
            int randAngle = 45;             //随机转动角度
            int mapWidth  = (int)(VerifyCode.Length * 16) > Width ? (int)(VerifyCode.Length * 16) : Width;
            int mapHeight = Height > 24 ? Height : 24;

            System.Drawing.Bitmap   map   = new System.Drawing.Bitmap(mapWidth, mapHeight);                                  //创建图片背景
            System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(map);
            graph.Clear(System.Drawing.Color.AliceBlue);                                                                     //清除画面,填充背景
            graph.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Black, 0), 0, 0, map.Width - 1, map.Height - 1); //画一个边框
            //graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//模式

            Random rand = new Random();

            //背景噪点生成
            System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.LightGray, 0);
            for (int i = 0; i < 50; i++)
            {
                int x = rand.Next(0, map.Width);
                int y = rand.Next(0, map.Height);
                graph.DrawRectangle(blackPen, x, y, 1, 1);
            }


            //验证码旋转,防止机器识别
            char[] chars = VerifyCode.ToCharArray();            //拆散字符串成单字符数组

            //文字距中
            System.Drawing.StringFormat format = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.NoClip);
            format.Alignment     = System.Drawing.StringAlignment.Center;
            format.LineAlignment = System.Drawing.StringAlignment.Center;

            //定义颜色
            System.Drawing.Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };
            //定义字体
            string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };

            for (int i = 0; i < chars.Length; i++)
            {
                int cindex = rand.Next(c.Length);
                int findex = rand.Next(font.Length);

                Font  f = new System.Drawing.Font(font[findex], 14, System.Drawing.FontStyle.Bold);               //字体样式(参数2为字体大小)
                Brush b = new System.Drawing.SolidBrush(c[cindex]);

                Point dot = new Point(14, 14);
                //graph.DrawString(dot.X.ToString(),fontstyle,new SolidBrush(Color.Black),10,150);//测试X坐标显示间距的
                float angle = rand.Next(-randAngle, randAngle);        //转动的度数

                graph.TranslateTransform(dot.X, dot.Y);                //移动光标到指定位置
                graph.RotateTransform(angle);
                graph.DrawString(chars[i].ToString(), f, b, 1, 1, format);
                //graph.DrawString(chars[i].ToString(),fontstyle,new SolidBrush(Color.Blue),1,1,format);
                graph.RotateTransform(-angle);                //转回去
                graph.TranslateTransform(-2, -dot.Y);         //移动光标到指定位置,每个字符紧凑显示,避免被软件识别
            }
            //生成图片
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            map.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            graph.Dispose();
            map.Dispose();

            return(ms.ToArray());
        }
Esempio n. 45
0
        /// <summary>
        /// Draw the header
        /// </summary>
        /// <param name="g">Graphic object being drawn to</param>
        /// <param name="rect">Size of the area to draw</param>
        private void DrawHeader(System.Drawing.Graphics g, System.Drawing.Rectangle rect)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            Rectangle headerRect;

            LinearGradientMode mode = Orientation == Orientation.Horizontal ?
                                      LinearGradientMode.Vertical : LinearGradientMode.Horizontal;

            if (Collapsed)
            {
                headerRect = new Rectangle(0, 0, Width - 1, Height - 1);

                using (LinearGradientBrush aGB = new LinearGradientBrush(headerRect, CollapsedColorFrom, CollapsedColorTo, mode))
                    g.FillRectangle(aGB, headerRect);
            }
            else
            {
                headerRect = new Rectangle(0, 0,
                                           Orientation == Orientation.Horizontal ? Width - 1 : CollapsedSize - 1,
                                           Orientation == Orientation.Horizontal ? CollapsedSize - 1 : Height - 1);

                using (LinearGradientBrush aGB = new LinearGradientBrush(headerRect, ExpandColorFrom, ExpandColorTo, mode))
                    g.FillRectangle(aGB, headerRect);
            }

            //
            Image expandCollapsIndicator = Collapsed ? ExpandImage : CollapseImage;
            int   imageOffset            = 10;

            // draw image
            if (expandCollapsIndicator != null)
            {
                // where will the image be located
                Point imageLocation;

                if (Orientation == System.Windows.Forms.Orientation.Horizontal)
                {
                    imageOffset  += expandCollapsIndicator.Width;
                    imageLocation = new Point(Width - (expandCollapsIndicator.Width + 10),
                                              (CollapsedSize - expandCollapsIndicator.Height) / 2);
                    headerRect = new Rectangle(headerRect.Left, headerRect.Top,
                                               headerRect.Right - imageOffset, headerRect.Bottom);
                }
                else
                {
                    imageOffset  += expandCollapsIndicator.Height;
                    imageLocation = new Point((CollapsedSize - expandCollapsIndicator.Height) / 2, 10);
                    headerRect    = new Rectangle(headerRect.Left, headerRect.Top + imageOffset,
                                                  headerRect.Right, headerRect.Bottom - imageOffset);
                }

                // draw images if they are set
                g.DrawImage(expandCollapsIndicator, imageLocation);
            }

            // draw text
            SolidBrush   fntBrush = new SolidBrush(HeaderForeColor);
            StringFormat format   = new StringFormat();

            format.Alignment     = HeaderTextAlign;
            format.LineAlignment = StringAlignment.Center;
            format.Trimming      = StringTrimming.EllipsisWord;

            if (Orientation == Orientation.Vertical)
            {
                format.FormatFlags = StringFormatFlags.DirectionVertical;
                g.TranslateTransform(headerRect.Right, headerRect.Bottom + headerRect.Top, MatrixOrder.Prepend);
                g.RotateTransform(180);
            }

            if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
            {
                format.FormatFlags = format.FormatFlags | StringFormatFlags.DirectionRightToLeft;
            }

            g.DrawString(HeaderText, HeaderFont, fntBrush, headerRect, format);

            if (Orientation == Orientation.Vertical)
            {
                g.ResetTransform();
            }
        }
Esempio n. 46
0
 public void rotate(float angle)
 {
     dg.RotateTransform(angle);
 }
Esempio n. 47
0
        public static System.IO.MemoryStream GenerateCheckCode(out string checkCode)
        {
            checkCode = string.Empty;
            System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml("#1AE61A");
            char[] array = new char[]
            {
                '2',
                '3',
                '4',
                '5',
                '6',
                '8',
                '9',
                'A',
                'B',
                'C',
                'D',
                'E',
                'F',
                'G',
                'H',
                'J',
                'K',
                'L',
                'M',
                'N',
                'P',
                'R',
                'S',
                'T',
                'W',
                'X',
                'Y'
            };
            System.Random random = new System.Random();
            for (int i = 0; i < 4; i++)
            {
                checkCode += array[random.Next(array.Length)];
            }
            int width = 85;

            System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(width, 30);
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
            System.Random           random2  = new System.Random(System.DateTime.Now.Millisecond);
            System.Drawing.Brush    brush    = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(4683611));
            graphics.Clear(System.Drawing.ColorTranslator.FromHtml("#EBFDDF"));
            using (System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat())
            {
                stringFormat.Alignment     = System.Drawing.StringAlignment.Center;
                stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
                stringFormat.FormatFlags   = System.Drawing.StringFormatFlags.NoWrap;
                System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
                float num  = -25f;
                float num2 = 0f;
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                for (int i = 0; i < checkCode.Length; i++)
                {
                    int num3 = random2.Next(20, 24);
                    System.Drawing.Font  font  = ImageHelper.CreateFont(IOHelper.GetMapPath("/fonts/checkCode.ttf"), (float)num3, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
                    System.Drawing.SizeF sizeF = graphics.MeasureString(checkCode[i].ToString(), font);
                    matrix.RotateAt((float)random2.Next(-15, 10), new System.Drawing.PointF(num + sizeF.Width / 2f, num2 + sizeF.Height / 2f));
                    graphics.Transform = matrix;
                    graphics.DrawString(checkCode[i].ToString(), font, System.Drawing.Brushes.Green, new System.Drawing.RectangleF(num, num2, (float)bitmap.Width, (float)bitmap.Height), stringFormat);
                    num  += sizeF.Width * 3f / 5f;
                    num2 += 0f;
                    graphics.RotateTransform(0f);
                    matrix.Reset();
                    font.Dispose();
                }
            }
            System.Drawing.Pen     pen          = new System.Drawing.Pen(System.Drawing.Color.Black, 0f);
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            System.IO.MemoryStream result;
            try
            {
                bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                result = memoryStream;
            }
            finally
            {
                bitmap.Dispose();
                graphics.Dispose();
            }
            return(result);
        }