Reset() 공개 메소드

public Reset ( ) : void
리턴 void
예제 #1
0
        /// <summary>
        /// Gets the tab path.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>GraphicsPath.</returns>
        private GraphicsPath GetTabPath(int index)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.Reset();

            Rectangle rect = this.GetTabRect(index);

            switch (Alignment)
            {
            case TabAlignment.Top:

                break;

            case TabAlignment.Bottom:

                break;

            case TabAlignment.Left:

                break;

            case TabAlignment.Right:

                break;
            }

            path.AddLine(rect.Left, rect.Top, rect.Left, rect.Bottom + 1);
            path.AddLine(rect.Left, rect.Top, rect.Right, rect.Top);
            path.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom + 1);
            path.AddLine(rect.Right, rect.Bottom + 1, rect.Left, rect.Bottom + 1);

            return(path);
        }
예제 #2
0
        public Analyzer(double meanX, double meanY, GraphicsPath path)
        {
            Counters = new RunningCount[Enum.GetValues(typeof(AnalysisMetric)).Length];

            foreach(AnalysisMetric metric in Enum.GetValues(typeof(AnalysisMetric)))
                Counters[(int)metric] = new RunningCount(metric);

            MeanX = meanX;
            MeanY = meanY;

            path.Flatten();

            using(GraphicsPathIterator PathIterator = new GraphicsPathIterator(path))
            {
                using(GraphicsPath Subpath = new GraphicsPath())
                {
                    Paths = new List<PointF[]>();

                    bool Closed;

                    while(PathIterator.NextSubpath(Subpath, out Closed) > 0)
                    {
                        Paths.Add(Subpath.PathPoints);
                        Subpath.Reset();
                    }
                }
            }
        }
예제 #3
0
        private System.Drawing.Drawing2D.GraphicsPath GetPath(int index)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.Reset();

            Rectangle rect = this.GetTabRect(index);

            if (index == 0)
            {
                path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + rect.Height, rect.Top + 2);
                path.AddLine(rect.Left + rect.Height + 4, rect.Top, rect.Right - 3, rect.Top);
                path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
            }
            else
            {
                if (index == this.SelectedIndex)
                {
                    path.AddLine(rect.Left + 1, rect.Top + 5, rect.Left + 4, rect.Top + 2);
                    path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
                    path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
                    path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left + 1, rect.Bottom + 1);
                }
                else
                {
                    path.AddLine(rect.Left, rect.Top + 6, rect.Left + 4, rect.Top + 2);
                    path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
                    path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
                    path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left, rect.Bottom + 1);
                }
            }
            return(path);
        }
        public static void WarpPath(GraphicsPath path, PointF[] destPoints, RectangleF srcRect, Matrix matrix = null, WarpMode warpMode = WarpMode.Perspective, float flatness = 0.25f)
        {
            if (path.PointCount == 0)
                return;

            path.Flatten(matrix, flatness);

            var pathData = path.PathData;
            var pnts = path.PathPoints;

            var srcPoints = new PointF[] { new PointF(srcRect.Left, srcRect.Top),
                new PointF(srcRect.Right, srcRect.Top),
                new PointF(srcRect.Left, srcRect.Bottom),
                new PointF(srcRect.Right, srcRect.Bottom) };

            var count = pnts.Length;
            float x1, y1;
            int i;

            if (warpMode == WarpMode.Perspective)
            {
                CalcProjectiveXformCoeffs(srcPoints, destPoints, out coeffs);

                for (i = 0; i < count; i++)
                {
                    x1 = pnts[i].X;
                    y1 = pnts[i].Y;

                    var factor = 1.0f / (coeffs[6] * x1 + coeffs[7] * y1 + 1.0f);
                    pnts[i].X = (float)(factor * (coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2]));
                    pnts[i].Y = (float)(factor * (coeffs[3] * x1 + coeffs[4] * y1 + coeffs[5]));
                }
            }
            else
            {
                CalcBilinearXformCoeffs(srcPoints, destPoints, out coeffs);

                for (i = 0; i < count; i++)
                {
                    x1 = pnts[i].X;
                    y1 = pnts[i].Y;

                    pnts[i].X = (float)(coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2] * x1 * y1 + coeffs[3]);
                    pnts[i].Y = (float)(coeffs[4] * x1 + coeffs[5] * y1 + coeffs[6] * x1 * y1 + coeffs[7]);
                }

            }

            GraphicsPath warpedPath = new GraphicsPath(pnts, pathData.Types);
            if (warpedPath != null)
            {
                FillMode fm = path.FillMode;
                path.Reset();
                path.FillMode = fm;

                path.AddPath(warpedPath, true);
                warpedPath.Dispose();
            }
        }
예제 #5
0
        /// <summary>
        /// Gets the tab path.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>GraphicsPath.</returns>
        private GraphicsPath GetTabPath(int index)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.Reset();
            Rectangle rect = this.GetTabRect(index);

            switch (Alignment)
            {
            case TabAlignment.Top:

                break;

            case TabAlignment.Bottom:

                break;

            case TabAlignment.Left:

                break;

            case TabAlignment.Right:

                break;
            }
            int PaddingTop = 10;

            Point P_LeftTop     = new Point(rect.Left + 7, rect.Top + PaddingTop);
            Point P_LeftBottom  = new Point(rect.Left + 1, rect.Bottom);
            Point P_RightTop    = new Point(rect.Right - 7, rect.Top + PaddingTop);
            Point P_RightBottom = new Point(rect.Right - 1, rect.Bottom);

            Point P_Control1 = new Point(rect.Left + 3, rect.Top + PaddingTop);
            Point P_Control2 = new Point(rect.Left + 2, rect.Bottom - rect.Height / 2);

            Point P_Control3 = new Point(rect.Right - 3, rect.Top + PaddingTop);
            Point P_Control4 = new Point(rect.Right - 2, rect.Bottom - rect.Height / 2);

            //path.AddLine(rect.Left + 15, rect.Top, rect.Left + 2, rect.Bottom + 1);
            //path.AddLine(rect.Left + 15, rect.Top, rect.Right - 15, rect.Top);
            //path.AddLine(rect.Right - 15, rect.Top, rect.Right - 2, rect.Bottom + 1);
            //path.AddLine(rect.Right - 2, rect.Bottom, rect.Left + 2, rect.Bottom);
            path.AddBezier(P_LeftTop, P_Control1, P_Control2, P_LeftBottom);
            path.AddLine(P_LeftBottom, P_RightBottom);
            path.AddBezier(P_RightBottom, P_Control4, P_Control3, P_RightTop);
            //path.AddBezier(P_RightTop, P_Control3, P_Control4, P_RightBottom);
            path.AddLine(P_RightTop, P_LeftTop);



            //int diameter = 2 * 10;

            //path.AddArc(new Rectangle(new Point(rect.Left + 5, rect.Top), new Size(diameter, diameter)), 180, 60);
            //path.AddArc(new Rectangle(new Point(rect.Right - 15 - diameter, rect.Top - diameter), new Size(diameter, diameter)), 0, 60);
            path.CloseFigure();
            //return GetRoundedRectPath(rect, 15);
            return(path);
        }
예제 #6
0
        private GraphicsPath GetPath(int index)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.Reset();

            Rectangle rect = this.GetTabRect(index);

            switch (Alignment)
            {
            case TabAlignment.Top:

                break;

            case TabAlignment.Bottom:

                break;

            case TabAlignment.Left:

                break;

            case TabAlignment.Right:

                break;
            }

            /* if (index == 0)*/
            {
                path.AddLine(rect.Left + 1, rect.Top + 1, rect.Left + 1, rect.Top + 1);
                path.AddLine(rect.Left + 1, rect.Top + 1, rect.Right, rect.Top + 1);
                path.AddLine(rect.Right, rect.Top + 1, rect.Right, rect.Bottom);
                path.AddLine(rect.Right, rect.Bottom, rect.Left + 1, rect.Bottom);
            }

            /*else
             * {
             *  if (index == this.SelectedIndex)
             *  {
             *      path.AddLine(rect.Left - 1, rect.Top, rect.Left - 1, rect.Top);
             *      path.AddLine(rect.Left - 1, rect.Top, rect.Right, rect.Top);
             *      path.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom);
             *      path.AddLine(rect.Right, rect.Bottom + 1, rect.Left - 1, rect.Bottom + 1);
             *  }
             *  else
             *  {
             *      path.AddLine(rect.Left - 1, rect.Top, rect.Left - 1, rect.Top);
             *      path.AddLine(rect.Left - 1, rect.Top, rect.Right, rect.Top);
             *      path.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom);
             *      path.AddLine(rect.Right, rect.Bottom + 1, rect.Left - 1, rect.Bottom + 1);
             *  }
             * }*/
            return(path);
        }
예제 #7
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //if (scythians.Count <= 2) return;
            GraphicsPath path = new GraphicsPath();
            Pen pen = new Pen(Color.Black, 3F);
            foreach(KeyValuePair<int, List<PointF>> list in scythians)
            {
                path.AddLines(list.Value.ToArray());
                path.CloseFigure();
                e.Graphics.DrawPath(pen, path);
                e.Graphics.DrawString(list.Key.ToString() + " год", Font, Brushes.Maroon, list.Value[0].X+50, list.Value[0].Y);
                path.Reset();
                pen.Color = Color.FromArgb(pen.Color.R + 10, pen.Color.G + 10, pen.Color.G + 10);
            }

            path.Reset();
            pen.Color = Color.Red;
            pen.Width = 5;
            path.AddLines(scythians[trackBar1.Value].ToArray());
            path.CloseFigure();
            e.Graphics.DrawPath(pen, path);
        }
        public static void RenderArcScaleNumbers(
                                                    this Graphics graphics, 
                                                    Rectangle ClientRectangle, 
                                                    Font Font,
                                                    Color ForeColor,
                                                    FontBound.BoundDef FontBound, 
                                                    Point Center, 
                                                    Int32 Radius, 
                                                    Single MinimumValue,
                                                    Single MaximumValue, 
                                                    String Format,                                                     
                                                    Int32 StartScaleLine,
                                                    Single MajorStepValue,
                                                    Int32 ArcStart,
                                                    Int32 ArcSweep, 
                                                    ArcOriantationTypeEnum Orientation
            )
        {
            using (var graphicsPath = new GraphicsPath()) {
                graphics.SetClip(ClientRectangle);

                Single countValue = 0;
                Int32 counter1 = 0;
                while (countValue <= (MaximumValue - MinimumValue)) {
                    graphics.ResetTransform();
                    graphicsPath.Reset();

                    var valueText = (MinimumValue + countValue).ToString(Format);
                    var boundingBox = graphics.MeasureString(valueText, Font, -1, StringFormat.GenericTypographic);

                    if (Orientation != ArcOriantationTypeEnum.Horizontal) {
                        graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        graphics.RotateTransform(90.0F + ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue));
                    }

                    graphics.TranslateTransform(
                                                    (Single)(Center.X + Radius * Math.Cos((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue)) * Math.PI / 180.0f)),
                                                    (Single)(Center.Y + Radius * Math.Sin((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue)) * Math.PI / 180.0f)),
                                                    System.Drawing.Drawing2D.MatrixOrder.Append
                                               );

                    if (counter1 >= StartScaleLine - 1)
                        graphics.DrawString(valueText, Font, new SolidBrush(ForeColor), -boundingBox.Width / 2, -FontBound.Y1 - (FontBound.Y2 - FontBound.Y1 + 1) / 2, StringFormat.GenericTypographic);

                    countValue += MajorStepValue;
                    counter1++;

                    graphics.ResetTransform();
                }
            }
        }
예제 #9
0
        public override void DrawGraphics(Graphics destination)
        {
            DrawGraphics();

            using (var gfxPath = new GraphicsPath())
            using (var brush = Style.CreateBrush())
            using (var pen = Style.CreatePen())
            {
                gfxPath.Reset();
                gfxPath.AddLine(Edges[0].Points[0], Edges[0].Points[1]);
                gfxPath.AddLine(Edges[1].Points[0], Edges[1].Points[1]);
                gfxPath.AddLine(Edges[2].Points[0], Edges[2].Points[1]);
                gfxPath.AddLine(Edges[3].Points[0], Edges[3].Points[1]);

                destination.FillPath(brush, gfxPath);
                //destination.DrawPath(pen, gfxPath);
            }

            EditablegeometryCue.DrawGeometry(destination);
        }
        private static void ArcRenderRange(this Graphics Graphics, Rectangle ClientRectangle, Point Center, Int32 ArcStart, Int32 ArcSweep, Single MinimumValue, Single MaximumValue, ArcRangeDef Range)
        {
            Graphics.SetClip(ClientRectangle);
            Graphics.SmoothingMode = SmoothingMode.HighQuality;
            Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            using (var graphicsPath = new GraphicsPath()) {
                if (Range.EndValue > Range.StartValue && Range.Enabled) {
                    var rangeStartAngle = ArcStart + (Range.StartValue - MinimumValue) * ArcSweep / (MaximumValue - MinimumValue);
                    var rangeSweepAngle = (Range.EndValue - Range.StartValue) * ArcSweep / (MaximumValue - MinimumValue);
                    graphicsPath.Reset();
                    graphicsPath.AddPie(new Rectangle(Center.X - Range.OuterRadius, Center.Y - Range.OuterRadius, 2 * Range.OuterRadius, 2 * Range.OuterRadius), rangeStartAngle, rangeSweepAngle);
                    graphicsPath.Reverse();
                    graphicsPath.AddPie(new Rectangle(Center.X - Range.InnerRadius, Center.Y - Range.InnerRadius, 2 * Range.InnerRadius, 2 * Range.InnerRadius), rangeStartAngle, rangeSweepAngle);
                    graphicsPath.Reverse();
                    Graphics.SetClip(graphicsPath);
                    using (var solidBrush = new SolidBrush(Range.ForeColor)) {
                        Graphics.FillPie(solidBrush, new Rectangle(Center.X - Range.OuterRadius, Center.Y - Range.OuterRadius, 2 * Range.OuterRadius, 2 * Range.OuterRadius), rangeStartAngle, rangeSweepAngle);
                    }
                }
            }
        }
예제 #11
0
		/// <summary>
		/// Produces DXF output for Flowchart shape
		/// </summary>
		/// <param name="rect">Bounding Rectangle</param>
		/// <param name="ShapeStyle">Flowchart shape style</param>
		/// <param name="st">ElementTemplate reference if shape is complex null otherwise</param>
		/// <param name="crLine">Line color</param>
		/// <param name="RA">Rotation angle</param>
		/// <param name="dash">DashStyle</param>
		/// <param name="LineWidth">Line width ( not used)</param>
		/// <param name="Offset">Offset if it's necessary</param>
		/// <param name="WCS2UCS">if true conversion for world-coordinate to user-coordinate is required</param>
		/// <param name="gr">GraphicsPath to be assigned</param>
		/// <param name="result">>DXF output string</param>
		/// <returns>true if successfull otherwise false</returns>
		public bool Shape2Str( RectangleF rect, BoxStyle ShapeStyle, ElementTemplate[] st, 
			Color crLine, float RA,  DashStyle dash, Single LineWidth, 
			float Offset, bool WCS2UCS, ref GraphicsPath gr, ref string result )
		{
			
			float X	= 0, Y = 0,	X1 = 0,	Y1 = 0,
				X2 = 0,	Y2 = 0,	X3 = 0,	Y3 = 0;
			bool DisableStringOutput = false;
			PointF[] pts = null;
			bool bOk = false;
			string PathPart = "";
			GraphicsPath gr_temp = new GraphicsPath(FillMode.Winding);

			try
			{
		
				if ( gr == null )
					throw new Exception("Empty Graphics Path reference passed");
						

				DisableStringOutput = ( result == null );
			
				// Detecting box's style
				switch (ShapeStyle)
				{
		
					case BoxStyle.Rectangle:
						gr.AddRectangle(rect);
						break;
					case BoxStyle.Ellipse:
						gr.AddEllipse(rect.X,rect.Y,rect.Width,	rect.Height);
						break;
					case BoxStyle.RoundedRectangle:
						gr = Utilities.getRoundRect(rect.X,	rect.Y,	rect.Width,	rect.Height,10);
						break;
					case BoxStyle.Delay:
						gr.AddRectangle(rect);
						break;
					case BoxStyle.Rhombus:
		
						pts = new PointF[4] {new PointF((rect.Left	+ rect.Right) /	2, rect.Top - Offset),
												new PointF(Math.Max(rect.Right, rect.Left) + Offset, (rect.Top	+ rect.Bottom) / 2),
												new PointF((rect.Left	+ rect.Right) /	2,	Math.Max(rect.Bottom, rect.Top) + Offset),
												new PointF(rect.Left - Offset,(rect.Top	+ rect.Bottom) / 2)};
		
									
						gr.AddPolygon(pts);
									
					
						break;
					case BoxStyle.Shape:  // if shape is complex then processing all its elements
						

						if (st  ==	null)
							throw new Exception("Empty shape reference in the complex shape");

						

						foreach	(ElementTemplate et	in st )
						{
							switch ( et.getClassId())
							{
								case 28: // If shape element is arc
						
									ArcTemplate	at =  et as	ArcTemplate;
									double rx = 0, ry = 0 , cx = 0, cy = 0;
					
									rx = rect.Width * (at.Bounds.Width/200);
									ry = rect.Height * (at.Bounds.Height/200);

									cx = rect.X + rect.Width*(at.Bounds.X/100) + rx;
									cy = rect.Y + rect.Height*(at.Bounds.Y/100) + ry;

									gr.AddArc((float) (cx - rx), (float) ( cy - ry) , (float) rx*2, (float) ry*2, at.StartAngle ,at.SweepAngle);

									float StartAngle =  180 + at.StartAngle + (360 - at.SweepAngle) - RA, EndAngle =  StartAngle + at.SweepAngle;

									if ( rx != ry )
									{
										

										float iAngleC = 0;
										double majorx = 0, majory = 0;
									
										
										if (at.StartAngle<0)
											iAngleC = 360 - Math.Abs(at.StartAngle);
										else
											iAngleC = at.StartAngle;


										majorx = (rx < ry) ? 0 : rx;
										majory = (rx < ry) ? ry : 0; 
										
									
										if (( iAngleC >=0 ) && (iAngleC<90))
										{
										
											majorx*=-1;
											majory*=-1;
										}
										else if (( iAngleC >=90 ) && (iAngleC<180))
										{
										
								
										}
										else if (( iAngleC >=180 ) && (iAngleC<270))
										{
								
										
											majorx*=-1;
											majory*=-1;
											
										}
										else if (( iAngleC >=270 ) && (iAngleC<=360))
										{
								
										}
										
									

										
										StartAngle =  at.StartAngle + RA;
										EndAngle =  StartAngle + at.SweepAngle;
										
										if ((at.SweepAngle>=270) && (at.SweepAngle<360))
										{
											if ( ry > rx )
										{
												StartAngle = at.StartAngle + RA + 90 + ( 360 - at.SweepAngle);
												EndAngle = at.StartAngle + RA + 90;
											}
											
										} 
										else if (at.SweepAngle>=180)
										{
											if (ry>rx)
											{
												StartAngle-=90;
												EndAngle-=90;
											}
										
											
										}
										
										
	
										
										
										PathPart = String.Format(provider, "  0\nELLIPSE\n  100\nAcDbEntity\n{0:HAN}  8\n{5}\n  62\n{6:ACI}\n 100\nAcDbEllipse\n  10\n{0:U}\n  20\n{1:U}\n  11\n{7:U}\n  21\n{8:U}\n  40\n{9:U}\n  41\n{3:U}\n  42\n{4:U}\n",
											cx, m_FlowChart.DocExtents.Height - cy,0, (StartAngle*Math.PI)/180 , (EndAngle*Math.PI)/180, SHAPE_LAYER, crLine, majorx , majory , (rx < ry) ? rx/ry : ry/rx);
									}
									else
									{
										
										PathPart = String.Format(provider, "  0\nARC\n  100\nAcDbEntity\n{0:HAN}  8\n{5}\n  62\n{6:ACI}\n 100\nAcDbCircle\n  10\n{0:U}\n  20\n{1:U}\n  40\n{2:U}\n  100\nAcDbArc\n  50\n{3}\n  51\n{4}\n",
											cx, m_FlowChart.DocExtents.Height - cy,rx, StartAngle , EndAngle, SHAPE_LAYER, crLine);
									}

									break;
								case 29: // If shape element is bezier curve

									BezierTemplate	bt =  et as	BezierTemplate;

									X =	rect.X	+ rect.Width * (bt.Coordinates[0]/100);
									Y =	rect.Y	+  rect.Height*	(bt.Coordinates[1]/100);

									X1 = rect.X	 + rect.Width *	(bt.Coordinates[2]/100);
									Y1 = rect.Y	 +	rect.Height* (bt.Coordinates[3]/100);

									X2 = rect.X	 + rect.Width *	(bt.Coordinates[4]/100);
									Y2 = rect.Y	 + rect.Height*	(bt.Coordinates[5]/100);

									X3 = rect.X	 + rect.Width *	(bt.Coordinates[6]/100);
									Y3 = rect.Y	 + rect.Height*	(bt.Coordinates[7]/100);

									
									gr_temp.Reset();
									gr_temp.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3);
									gr.AddBezier(X,Y,X1,Y1,X2,Y2,X3,Y3);
									
									// Applying rotation if it's necessary
									pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp);

									gr_temp.Flatten();
									PointF[] pts2 = gr_temp.PathData.Points.Clone() as PointF[];
									
									PathPart = String.Format(provider, "0\nPOLYLINE\n{0:HAN}   100\nAcDbEntity\n8\n{0}\n  62\n{1:ACI}\n  100\nAcDb2dPolyline\n  66\n1\n  70\n4\n  75\n6\n{2}{3}0\nSEQEND\n  100\nAcDbEntity\n{0:HAN}", 
										SHAPE_LAYER,
										crLine, 
										Pt2String(pts,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 16),
										Pt2String(pts2,crLine,SHAPE_LAYER,DxLineType.ltVertex, dash, 8));

									break;
								case 30:  // If shape element is line


									LineTemplate lt	= et as	LineTemplate;
					
									X1 = rect.X	+ rect.Width * (lt.Coordinates[0]/100);
									Y1 = rect.Y	+ rect.Height* (lt.Coordinates[1]/100);

									X2 = rect.X	+ rect.Width * (lt.Coordinates[2]/100);
									Y2 = rect.Y	+ rect.Height* (lt.Coordinates[3]/100);
									
									gr_temp.Reset();
									gr_temp.AddLine(X1,Y1,X2,Y2);
									gr.AddLine(X1,Y1,X2,Y2);
									
									// Applying rotation if it's necessary
									pts = RotatePoints(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), gr_temp);
									PathPart = Pt2String(pts, crLine,SHAPE_LAYER,DxLineType.ltSingle,DashStyle.Solid, 1);
									break;
							}

							result+=PathPart;
						}
						break;
					default:
						gr.AddRectangle(rect);
						break;

				}


			
				// Converting shapes coordinates from UCS to WSC
				TranslateCoords(RA , new PointF(rect.X + rect.Width/2,rect.Y + rect.Height/2), WCS2UCS, ref gr);
				
				gr.Flatten();

				// If string output is required producing DXF string
				if (!DisableStringOutput)
				{
					if ( result=="" )
					{
						pts = gr.PathPoints.Clone() as PointF[];
						result = Pt2String(pts, crLine, SHAPE_LAYER, DxLineType.ltClosedSingle, dash, LineWidth);
					}
					
				}
				
				bOk = true;
			}
			catch (	Exception ex)
			{

				Trace.WriteLine(String.Format("{0} error {1}\n","Box2Str",ex.Message));
				bOk = false;
			}

			return bOk;
		}
예제 #12
0
        private void DrawUpDown(Graphics graphics)
        {
            Color backColor = Parent != null ? Parent.BackColor : MetroPaint.BackColor.Form(Theme);

            Rectangle borderRect = new Rectangle();
            WinApi.GetClientRect(scUpDown.Handle, ref borderRect);

            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            graphics.Clear(backColor);

            using (Brush b = new SolidBrush(MetroPaint.BorderColor.TabControl.Normal(Theme)))
            {
                GraphicsPath gp = new GraphicsPath(FillMode.Winding);
                PointF[] pts = { new PointF(6, 6), new PointF(16, 0), new PointF(16, 12) };
                gp.AddLines(pts);

                graphics.FillPath(b, gp);

                gp.Reset();

                PointF[] pts2 = { new PointF(borderRect.Width - 15, 0), new PointF(borderRect.Width - 5, 6), new PointF(borderRect.Width - 15, 12) };
                gp.AddLines(pts2);

                graphics.FillPath(b, gp);

                gp.Dispose();
            }
        }
예제 #13
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            if ((Width < 10) || (Height < 10))
            {
                return;
            }

            if (drawGaugeBackground)
            {
                drawGaugeBackground = false;

                FindFontBounds();

                gaugeBitmap = new Bitmap(Width, Height, pe.Graphics);
                Graphics ggr = Graphics.FromImage(gaugeBitmap);
                ggr.FillRectangle(new SolidBrush(BackColor), ClientRectangle);

                if (BackgroundImage!=null)
                {
                    switch (BackgroundImageLayout)
                    {
                        case ImageLayout.Center:
                            ggr.DrawImageUnscaled(BackgroundImage, Width / 2 - BackgroundImage.Width / 2, Height / 2 - BackgroundImage.Height / 2);
                            break;
                        case ImageLayout.None:
                            ggr.DrawImageUnscaled(BackgroundImage, 0, 0);
                            break;
                        case ImageLayout.Stretch:
                            ggr.DrawImage(BackgroundImage, 0, 0, Width, Height);
                            break;
                        case ImageLayout.Tile:
                            Int32 pixelOffsetX = 0;
                            Int32 pixelOffsetY = 0;
                            while (pixelOffsetX < Width)
                            {
                                pixelOffsetY = 0;
                                while (pixelOffsetY < Height)
                                {
                                    ggr.DrawImageUnscaled(BackgroundImage, pixelOffsetX, pixelOffsetY);
                                    pixelOffsetY += BackgroundImage.Height;
                                }
                                pixelOffsetX += BackgroundImage.Width;
                            }
                            break;
                        case ImageLayout.Zoom:
                            if ((Single)(BackgroundImage.Width / Width) < (Single)(BackgroundImage.Height / Height))
                            {
                                ggr.DrawImage(BackgroundImage, 0, 0, Height, Height);
                            }
                            else
                            {
                                ggr.DrawImage(BackgroundImage, 0, 0, Width, Width);
                            }
                            break;
                    }
                }

                ggr.SmoothingMode = SmoothingMode.HighQuality;
                ggr.PixelOffsetMode = PixelOffsetMode.HighQuality;

                GraphicsPath gp = new GraphicsPath();
                Single rangeStartAngle;
                Single rangeSweepAngle;
                for (Int32 counter= 0; counter<NUMOFRANGES; counter++)
                {
                    if (m_RangeEndValue[counter] > m_RangeStartValue[counter]
                    && m_RangeEnabled[counter])
                    {
                        rangeStartAngle = m_BaseArcStart + (m_RangeStartValue[counter] - m_MinValue) * m_BaseArcSweep / (m_MaxValue - m_MinValue);
                        rangeSweepAngle = (m_RangeEndValue[counter] - m_RangeStartValue[counter]) * m_BaseArcSweep / (m_MaxValue - m_MinValue);
                        gp.Reset();
                        gp.AddPie(new Rectangle(m_Center.X - m_RangeOuterRadius[counter], m_Center.Y - m_RangeOuterRadius[counter], 2 * m_RangeOuterRadius[counter], 2 * m_RangeOuterRadius[counter]), rangeStartAngle, rangeSweepAngle);
                        gp.Reverse();
                        gp.AddPie(new Rectangle(m_Center.X - m_RangeInnerRadius[counter], m_Center.Y - m_RangeInnerRadius[counter], 2 * m_RangeInnerRadius[counter], 2 * m_RangeInnerRadius[counter]), rangeStartAngle, rangeSweepAngle);
                        gp.Reverse();
                        ggr.SetClip(gp);
                        ggr.FillPie(new SolidBrush(m_RangeColor[counter]), new Rectangle(m_Center.X - m_RangeOuterRadius[counter], m_Center.Y - m_RangeOuterRadius[counter], 2 * m_RangeOuterRadius[counter], 2 * m_RangeOuterRadius[counter]), rangeStartAngle, rangeSweepAngle);
                    }
                }

                ggr.SetClip(ClientRectangle);
                if (m_BaseArcRadius > 0)
                {
                    ggr.DrawArc(new Pen(m_BaseArcColor, m_BaseArcWidth), new Rectangle(m_Center.X - m_BaseArcRadius, m_Center.Y - m_BaseArcRadius, 2 * m_BaseArcRadius, 2 * m_BaseArcRadius), m_BaseArcStart, m_BaseArcSweep);
                }

                String valueText = "";
                SizeF boundingBox;
                Single  countValue= 0;
                Int32 counter1  = 0;
                while (countValue <= (m_MaxValue - m_MinValue))
                {
                    valueText = (m_MinValue + countValue).ToString(m_ScaleNumbersFormat);
                    ggr.ResetTransform();
                    boundingBox = ggr.MeasureString(valueText, Font, -1, StringFormat.GenericTypographic);

                    gp.Reset();
                    gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMajorOuterRadius, m_Center.Y - m_ScaleLinesMajorOuterRadius, 2 * m_ScaleLinesMajorOuterRadius, 2 * m_ScaleLinesMajorOuterRadius));
                    gp.Reverse();
                    gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMajorInnerRadius, m_Center.Y - m_ScaleLinesMajorInnerRadius, 2 * m_ScaleLinesMajorInnerRadius, 2 * m_ScaleLinesMajorInnerRadius));
                    gp.Reverse();
                    ggr.SetClip(gp);

                    ggr.DrawLine(new Pen(m_ScaleLinesMajorColor, m_ScaleLinesMajorWidth),
                    (Single)(Center.X),
                    (Single)(Center.Y),
                    (Single)(Center.X + 2 * m_ScaleLinesMajorOuterRadius * Math.Cos((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue)) * Math.PI / 180.0)),
                    (Single)(Center.Y + 2 * m_ScaleLinesMajorOuterRadius * Math.Sin((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue)) * Math.PI / 180.0)));

                    gp.Reset();
                    gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorOuterRadius, m_Center.Y - m_ScaleLinesMinorOuterRadius, 2 * m_ScaleLinesMinorOuterRadius, 2 * m_ScaleLinesMinorOuterRadius));
                    gp.Reverse();
                    gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorInnerRadius, m_Center.Y - m_ScaleLinesMinorInnerRadius, 2 * m_ScaleLinesMinorInnerRadius, 2 * m_ScaleLinesMinorInnerRadius));
                    gp.Reverse();
                    ggr.SetClip(gp);

                    if (countValue < (m_MaxValue - m_MinValue))
                    {
                        for (Int32 counter2= 1; counter2<=m_ScaleLinesMinorNumOf; counter2++)
                        {
                            if (((m_ScaleLinesMinorNumOf % 2) == 1) && ((Int32)(m_ScaleLinesMinorNumOf / 2) + 1 == counter2))
                            {
                                gp.Reset();
                                gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesInterOuterRadius, m_Center.Y - m_ScaleLinesInterOuterRadius, 2 * m_ScaleLinesInterOuterRadius, 2 * m_ScaleLinesInterOuterRadius));
                                gp.Reverse();
                                gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesInterInnerRadius, m_Center.Y - m_ScaleLinesInterInnerRadius, 2 * m_ScaleLinesInterInnerRadius, 2 * m_ScaleLinesInterInnerRadius));
                                gp.Reverse();
                                ggr.SetClip(gp);

                                ggr.DrawLine(new Pen(m_ScaleLinesInterColor, m_ScaleLinesInterWidth),
                                (Single)(Center.X),
                                (Single)(Center.Y),
                                (Single)(Center.X + 2 * m_ScaleLinesInterOuterRadius * Math.Cos((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue) + counter2 * m_BaseArcSweep / (((Single)((m_MaxValue - m_MinValue) / m_ScaleLinesMajorStepValue)) * (m_ScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)),
                                (Single)(Center.Y + 2 * m_ScaleLinesInterOuterRadius * Math.Sin((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue) + counter2 * m_BaseArcSweep / (((Single)((m_MaxValue - m_MinValue) / m_ScaleLinesMajorStepValue)) * (m_ScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)));

                                gp.Reset();
                                gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorOuterRadius, m_Center.Y - m_ScaleLinesMinorOuterRadius, 2 * m_ScaleLinesMinorOuterRadius, 2 * m_ScaleLinesMinorOuterRadius));
                                gp.Reverse();
                                gp.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorInnerRadius, m_Center.Y - m_ScaleLinesMinorInnerRadius, 2 * m_ScaleLinesMinorInnerRadius, 2 * m_ScaleLinesMinorInnerRadius));
                                gp.Reverse();
                                ggr.SetClip(gp);
                            }
                            else
                            {
                                ggr.DrawLine(new Pen(m_ScaleLinesMinorColor, m_ScaleLinesMinorWidth),
                                (Single)(Center.X),
                                (Single)(Center.Y),
                                (Single)(Center.X + 2 * m_ScaleLinesMinorOuterRadius * Math.Cos((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue) + counter2 * m_BaseArcSweep / (((Single)((m_MaxValue - m_MinValue) / m_ScaleLinesMajorStepValue)) * (m_ScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)),
                                (Single)(Center.Y + 2 * m_ScaleLinesMinorOuterRadius * Math.Sin((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue) + counter2 * m_BaseArcSweep / (((Single)((m_MaxValue - m_MinValue) / m_ScaleLinesMajorStepValue)) * (m_ScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)));
                            }
                        }
                    }

                    ggr.SetClip(ClientRectangle);

                    if (m_ScaleNumbersRotation != 0)
                    {
                        ggr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        ggr.RotateTransform(90.0F + m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue));
                    }

                    ggr.TranslateTransform((Single)(Center.X + m_ScaleNumbersRadius * Math.Cos((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue)) * Math.PI / 180.0f)),
                                           (Single)(Center.Y + m_ScaleNumbersRadius * Math.Sin((m_BaseArcStart + countValue * m_BaseArcSweep / (m_MaxValue - m_MinValue)) * Math.PI / 180.0f)),
                                           System.Drawing.Drawing2D.MatrixOrder.Append);

                    if (counter1 >= ScaleNumbersStartScaleLine - 1)
                    {
                        ggr.DrawString(valueText, Font, new SolidBrush(m_ScaleNumbersColor), -boundingBox.Width / 2, -fontBoundY1 - (fontBoundY2 - fontBoundY1 + 1) / 2, StringFormat.GenericTypographic);
                    }

                    countValue += m_ScaleLinesMajorStepValue;
                    counter1 ++;
                }

                ggr.ResetTransform();
                ggr.SetClip(ClientRectangle);

                if (m_ScaleNumbersRotation != 0)
                {
                   ggr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                }

                for (Int32 counter= 0; counter<NUMOFCAPS; counter++)
                {
                    if (m_CapText[counter] != "")
                    {
                       ggr.DrawString(m_CapText[counter], Font, new SolidBrush(m_CapColor[counter]), m_CapPosition[counter].X, m_CapPosition[counter].Y, StringFormat.GenericTypographic);
                    }
                }
            }

            pe.Graphics.DrawImageUnscaled(gaugeBitmap, 0, 0);
            pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            pe.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            Single brushAngle = (Int32)(m_BaseArcStart + (m_value - m_MinValue) * m_BaseArcSweep / (m_MaxValue - m_MinValue)) % 360;
            Double needleAngle= brushAngle * Math.PI / 180;

            switch(m_NeedleType)
            {
                case 0:
                    PointF[] points=new PointF[3];
                    Brush brush1 = Brushes.White;
                    Brush brush2 = Brushes.White;
                    Brush brush3 = Brushes.White;
                    Brush brush4 = Brushes.White;

                    Brush brushBucket = Brushes.White;
                    Int32 subcol = (Int32)(((brushAngle + 225) % 180) * 100 / 180);
                    Int32 subcol2 = (Int32)(((brushAngle + 135) % 180) * 100 / 180);

                    pe.Graphics.FillEllipse(new SolidBrush(m_NeedleColor2), Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                    switch(m_NeedleColor1)
                    {
                        case NeedleColorEnum.Gray:
                            brush1 = new SolidBrush(Color.FromArgb(80 + subcol, 80 + subcol, 80 + subcol));
                            brush2 = new SolidBrush(Color.FromArgb(180 - subcol, 180 - subcol, 180 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(80 + subcol2, 80 + subcol2, 80 + subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(180 - subcol2, 180 - subcol2, 180 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Gray, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                        case NeedleColorEnum.Red:
                            brush1 = new SolidBrush(Color.FromArgb(145 + subcol, subcol, subcol));
                            brush2 = new SolidBrush(Color.FromArgb(245 - subcol, 100 - subcol, 100 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(145 + subcol2, subcol2, subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(245 - subcol2, 100 - subcol2, 100 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Red, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                        case NeedleColorEnum.Green:
                            brush1 = new SolidBrush(Color.FromArgb(subcol, 145 + subcol, subcol));
                            brush2 = new SolidBrush(Color.FromArgb(100 - subcol, 245 - subcol, 100 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(subcol2, 145 + subcol2, subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(100 - subcol2, 245 - subcol2, 100 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Green, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                        case NeedleColorEnum.Blue:
                            brush1 = new SolidBrush(Color.FromArgb(subcol, subcol, 145 + subcol));
                            brush2 = new SolidBrush(Color.FromArgb(100 - subcol, 100 - subcol, 245 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(subcol2, subcol2, 145 + subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(100 - subcol2, 100 - subcol2, 245 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Blue, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                        case NeedleColorEnum.Magenta:
                            brush1 = new SolidBrush(Color.FromArgb(subcol, 145 + subcol, 145 + subcol));
                            brush2 = new SolidBrush(Color.FromArgb(100 - subcol, 245 - subcol, 245 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(subcol2, 145 + subcol2, 145 + subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(100 - subcol2, 245 - subcol2, 245 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Magenta, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                        case NeedleColorEnum.Violet:
                            brush1 = new SolidBrush(Color.FromArgb(145 + subcol, subcol, 145 + subcol));
                            brush2 = new SolidBrush(Color.FromArgb(245 - subcol, 100 - subcol, 245 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(145 + subcol2, subcol2, 145 + subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(245 - subcol2, 100 - subcol2, 245 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Violet, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                        case NeedleColorEnum.Yellow:
                            brush1 = new SolidBrush(Color.FromArgb(145 + subcol, 145 + subcol, subcol));
                            brush2 = new SolidBrush(Color.FromArgb(245 - subcol, 245 - subcol, 100 - subcol));
                            brush3 = new SolidBrush(Color.FromArgb(145 + subcol2, 145 + subcol2, subcol2));
                            brush4 = new SolidBrush(Color.FromArgb(245 - subcol2, 245 - subcol2, 100 - subcol2));
                            pe.Graphics.DrawEllipse(Pens.Violet, Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
                            break;
                    }

                    if (Math.Floor((Single)(((brushAngle + 225) % 360) / 180.0)) == 0)
                    {
                        brushBucket = brush1;
                        brush1 = brush2;
                        brush2 = brushBucket;
                    }

                    if (Math.Floor((Single)(((brushAngle + 135) % 360) / 180.0)) == 0)
                    {
                        brush4 = brush3;
                    }

                    points[0].X = (Single)(Center.X + m_NeedleRadius * Math.Cos(needleAngle));
                    points[0].Y =(Single)( Center.Y + m_NeedleRadius * Math.Sin(needleAngle));
                    points[1].X = (Single)(Center.X - m_NeedleRadius / 20 * Math.Cos(needleAngle));
                    points[1].Y = (Single)(Center.Y - m_NeedleRadius / 20 * Math.Sin(needleAngle));
                    points[2].X = (Single)(Center.X - m_NeedleRadius / 5 * Math.Cos(needleAngle) + m_NeedleWidth * 2 * Math.Cos(needleAngle + Math.PI / 2));
                    points[2].Y = (Single)(Center.Y - m_NeedleRadius / 5 * Math.Sin(needleAngle) + m_NeedleWidth * 2 * Math.Sin(needleAngle + Math.PI / 2));
                    pe.Graphics.FillPolygon(brush1, points);

                    points[2].X = (Single)(Center.X - m_NeedleRadius / 5 * Math.Cos(needleAngle) + m_NeedleWidth * 2 * Math.Cos(needleAngle - Math.PI / 2));
                    points[2].Y = (Single)(Center.Y - m_NeedleRadius / 5 * Math.Sin(needleAngle) + m_NeedleWidth * 2 * Math.Sin(needleAngle - Math.PI / 2));
                    pe.Graphics.FillPolygon(brush2, points);

                    points[0].X = (Single)(Center.X - (m_NeedleRadius / 20 - 1) * Math.Cos(needleAngle));
                    points[0].Y = (Single)(Center.Y - (m_NeedleRadius / 20 - 1) * Math.Sin(needleAngle));
                    points[1].X = (Single)(Center.X - m_NeedleRadius / 5 * Math.Cos(needleAngle) + m_NeedleWidth * 2 * Math.Cos(needleAngle + Math.PI / 2));
                    points[1].Y = (Single)(Center.Y - m_NeedleRadius / 5 * Math.Sin(needleAngle) + m_NeedleWidth * 2 * Math.Sin(needleAngle + Math.PI / 2));
                    points[2].X = (Single)(Center.X - m_NeedleRadius / 5 * Math.Cos(needleAngle) + m_NeedleWidth * 2 * Math.Cos(needleAngle - Math.PI / 2));
                    points[2].Y = (Single)(Center.Y - m_NeedleRadius / 5 * Math.Sin(needleAngle) + m_NeedleWidth * 2 * Math.Sin(needleAngle - Math.PI / 2));
                    pe.Graphics.FillPolygon(brush4, points);

                    points[0].X = (Single)(Center.X - m_NeedleRadius / 20 * Math.Cos(needleAngle));
                    points[0].Y = (Single)(Center.Y - m_NeedleRadius / 20 * Math.Sin(needleAngle));
                    points[1].X = (Single)(Center.X + m_NeedleRadius * Math.Cos(needleAngle));
                    points[1].Y = (Single)(Center.Y + m_NeedleRadius * Math.Sin(needleAngle));

                    pe.Graphics.DrawLine(new Pen(m_NeedleColor2), Center.X, Center.Y, points[0].X, points[0].Y);
                    pe.Graphics.DrawLine(new Pen(m_NeedleColor2), Center.X, Center.Y, points[1].X, points[1].Y);
                    break;
                case 1:
                    Point startPoint=new Point((Int32)(Center.X - m_NeedleRadius / 8 * Math.Cos(needleAngle)),
                                               (Int32)(Center.Y - m_NeedleRadius / 8 * Math.Sin(needleAngle)));
                    Point endPoint=new Point((Int32)(Center.X + m_NeedleRadius * Math.Cos(needleAngle)),
                                             (Int32)(Center.Y + m_NeedleRadius * Math.Sin(needleAngle)));

                    pe.Graphics.FillEllipse(new SolidBrush(m_NeedleColor2), Center.X - m_NeedleWidth * 3, Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);

                    switch(m_NeedleColor1)
                    {
                        case NeedleColorEnum.Gray:
                            pe.Graphics.DrawLine(new Pen(Color.DarkGray, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.DarkGray, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                        case NeedleColorEnum.Red:
                            pe.Graphics.DrawLine(new Pen(Color.Red, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.Red, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                        case NeedleColorEnum.Green:
                            pe.Graphics.DrawLine(new Pen(Color.Green, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.Green, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                        case NeedleColorEnum.Blue:
                            pe.Graphics.DrawLine(new Pen(Color.Blue, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.Blue, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                        case NeedleColorEnum.Magenta:
                            pe.Graphics.DrawLine(new Pen(Color.Magenta, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.Magenta, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                        case NeedleColorEnum.Violet:
                            pe.Graphics.DrawLine(new Pen(Color.Violet, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.Violet, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                        case NeedleColorEnum.Yellow:
                            pe.Graphics.DrawLine(new Pen(Color.Yellow, m_NeedleWidth), Center.X, Center.Y, endPoint.X, endPoint.Y);
                            pe.Graphics.DrawLine(new Pen(Color.Yellow, m_NeedleWidth), Center.X, Center.Y, startPoint.X, startPoint.Y);
                            break;
                    }
                    break;
            }
        }
예제 #14
0
		private void DrawSurface(IGraphics g, bool onScreen, Style style)
		{
			// Update graphical objects
			backgroundBrush.Color = style.CommentBackColor;
			borderPen.Color = style.CommentBorderColor;
			borderPen.Width = style.CommentBorderWidth;
			if (style.IsCommentBorderDashed)
				borderPen.DashPattern = borderDashPattern;
			else
				borderPen.DashStyle = DashStyle.Solid;

			// Create shape pattern
			GraphicsPath path = new GraphicsPath();
			path.AddLine(Left, Top, Right - PaddingSize, Top);
			path.AddLine(Right, Top + PaddingSize, Right, Bottom);
			path.AddLine(Right, Bottom, Left, Bottom);
			path.CloseFigure();

			// Draw shadow first
			if ((!onScreen || !IsSelected) && !style.ShadowOffset.IsEmpty)
			{
				shadowBrush.Color = style.ShadowColor;
				g.TranslateTransform(style.ShadowOffset.Width, style.ShadowOffset.Height);
				g.FillPath(shadowBrush, path);
				g.TranslateTransform(-style.ShadowOffset.Width, -style.ShadowOffset.Height);
			}

			// Draw borders & background
			g.FillPath(backgroundBrush, path);
			g.DrawPath(borderPen, path);

			// Draw earmark
			path.Reset();
			path.AddLine(Right - PaddingSize, Top, Right - PaddingSize, Top + PaddingSize);
			path.AddLine(Right - PaddingSize, Top + PaddingSize, Right, Top + PaddingSize);
			g.DrawPath(borderPen, path);

			path.Dispose();
		}
        /// <summary>
        /// The calc width via draw.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private static int CalcWidthViaDraw(string text, MakeBitmapParameter parameter)
        {
            // text = HtmlUtil.RemoveHtmlTags(text, true).Trim();
            text = text.Trim();
            var path = new GraphicsPath();
            var sb = new StringBuilder();
            int i = 0;
            bool isItalic = false;
            bool isBold = parameter.SubtitleFontBold;
            const float top = 5f;
            bool newLine = false;
            float left = 1.0f;
            float leftMargin = left;
            int newLinePathPoint = -1;
            Color c = parameter.SubtitleColor;
            var colorStack = new Stack<Color>();
            var lastText = new StringBuilder();
            var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near };
            var bmp = new Bitmap(parameter.ScreenWidth, 200);
            var g = Graphics.FromImage(bmp);

            g.CompositingQuality = CompositingQuality.HighSpeed;
            g.SmoothingMode = SmoothingMode.HighSpeed;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            Font font = SetFont(parameter, parameter.SubtitleFontSize);
            while (i < text.Length)
            {
                if (text.Substring(i).StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
                {
                    float addLeft = 0;
                    int oldPathPointIndex = path.PointCount;
                    if (oldPathPointIndex < 0)
                    {
                        oldPathPointIndex = 0;
                    }

                    if (sb.Length > 0)
                    {
                        lastText.Append(sb);
                        TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    }

                    if (path.PointCount > 0)
                    {
                        var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                        for (int k = oldPathPointIndex; k < list.Length; k++)
                        {
                            if (list[k].X > addLeft)
                            {
                                addLeft = list[k].X;
                            }
                        }
                    }

                    if (path.PointCount == 0)
                    {
                        addLeft = left;
                    }
                    else if (addLeft < 0.01)
                    {
                        addLeft = left + 2;
                    }

                    left = addLeft;

                    DrawShadowAndPath(parameter, g, path);
                    var p2 = new SolidBrush(c);
                    g.FillPath(p2, path);
                    p2.Dispose();
                    path.Reset();
                    path = new GraphicsPath();
                    sb = new StringBuilder();

                    int endIndex = text.Substring(i).IndexOf('>');
                    if (endIndex < 0)
                    {
                        i += 9999;
                    }
                    else
                    {
                        string fontContent = text.Substring(i, endIndex);
                        if (fontContent.Contains(" color="))
                        {
                            string[] arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (arr.Length > 0)
                            {
                                string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
                                try
                                {
                                    colorStack.Push(c); // save old color
                                    if (fontColor.StartsWith("rgb("))
                                    {
                                        arr = fontColor.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
                                    }
                                    else
                                    {
                                        c = ColorTranslator.FromHtml(fontColor);
                                    }
                                }
                                catch
                                {
                                    c = parameter.SubtitleColor;
                                }
                            }
                        }

                        i += endIndex;
                    }
                }
                else if (text.Substring(i).StartsWith("</font>", StringComparison.OrdinalIgnoreCase))
                {
                    if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
                    {
                        if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                        {
                            string t = sb.ToString();
                            sb.Clear();
                            sb.Append(' ');
                            sb.Append(t);
                        }

                        float addLeft = 0;
                        int oldPathPointIndex = path.PointCount - 1;
                        if (oldPathPointIndex < 0)
                        {
                            oldPathPointIndex = 0;
                        }

                        if (sb.Length > 0)
                        {
                            if (lastText.Length > 0 && left > 2)
                            {
                                left -= 1.5f;
                            }

                            lastText.Append(sb);

                            TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                        }

                        if (path.PointCount > 0)
                        {
                            var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                            for (int k = oldPathPointIndex; k < list.Length; k++)
                            {
                                if (list[k].X > addLeft)
                                {
                                    addLeft = list[k].X;
                                }
                            }
                        }

                        if (addLeft < 0.01)
                        {
                            addLeft = left + 2;
                        }

                        left = addLeft;

                        DrawShadowAndPath(parameter, g, path);
                        g.FillPath(new SolidBrush(c), path);
                        path.Reset();
                        sb = new StringBuilder();
                        if (colorStack.Count > 0)
                        {
                            c = colorStack.Pop();
                        }

                        if (left >= 3)
                        {
                            left -= 2.5f;
                        }
                    }

                    i += 6;
                }
                else if (text.Substring(i).StartsWith("<i>", StringComparison.OrdinalIgnoreCase))
                {
                    if (sb.Length > 0)
                    {
                        lastText.Append(sb);
                        TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    }

                    isItalic = true;
                    i += 2;
                }
                else if (text.Substring(i).StartsWith("</i>", StringComparison.OrdinalIgnoreCase) && isItalic)
                {
                    if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                    {
                        string t = sb.ToString();
                        sb.Clear();
                        sb.Append(' ');
                        sb.Append(t);
                    }

                    lastText.Append(sb);
                    TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    isItalic = false;
                    i += 3;
                }
                else if (text.Substring(i).StartsWith("<b>", StringComparison.OrdinalIgnoreCase))
                {
                    if (sb.Length > 0)
                    {
                        lastText.Append(sb);
                        TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    }

                    isBold = true;
                    i += 2;
                }
                else if (text.Substring(i).StartsWith("</b>", StringComparison.OrdinalIgnoreCase) && isBold)
                {
                    if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                    {
                        string t = sb.ToString();
                        sb.Clear();
                        sb.Append(' ');
                        sb.Append(t);
                    }

                    lastText.Append(sb);
                    TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    isBold = false;
                    i += 3;
                }
                else
                {
                    sb.Append(text[i]);
                }

                i++;
            }

            if (sb.Length > 0)
            {
                TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
            }

            DrawShadowAndPath(parameter, g, path);
            g.FillPath(new SolidBrush(c), path);
            g.Dispose();

            var nbmp = new NikseBitmap(bmp);
            nbmp.CropTransparentSidesAndBottom(0, true);
            bmp.Dispose();
            font.Dispose();
            sf.Dispose();
            return nbmp.Width;
        }
예제 #16
0
 private void btn_Clear_Click(object sender, EventArgs e)
 {
     pictureBox1.CreateGraphics().Clear(Color.White);
     mousePath.Reset();
 }
예제 #17
0
            private void ImageBack2(GraphicsPath gp, Graphics ggr, ImagePaint imgp)
            {
                float countValue = 0;
                var counter1 = 0;
                while (countValue <= (mMaxValue - mMinValue))
                {
                    var valueText = (mMinValue + countValue).ToString(mScaleNumbersFormat);
                    ggr.ResetTransform();
                    var boundingBox = ggr.MeasureString(valueText, imgp.Font, -1, StringFormat.GenericTypographic);

                    gp.Reset();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMajorOuterRadius,
                                                mCenter.Y - mScaleLinesMajorOuterRadius,
                                                2 * mScaleLinesMajorOuterRadius, 2 * mScaleLinesMajorOuterRadius));
                    gp.Reverse();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMajorInnerRadius,
                                                mCenter.Y - mScaleLinesMajorInnerRadius,
                                                2 * mScaleLinesMajorInnerRadius, 2 * mScaleLinesMajorInnerRadius));
                    gp.Reverse();
                    ggr.SetClip(gp);

                    ggr.DrawLine(new Pen(mScaleLinesMajorColor, mScaleLinesMajorWidth),
                                 (Center.X), (Center.Y),
                                 (Single)
                                 (Center.X +
                                  2 * mScaleLinesMajorOuterRadius *
                                  Math.Cos((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI /
                                           180.0)),
                                 (Single)
                                 (Center.Y +
                                  2 * mScaleLinesMajorOuterRadius *
                                  Math.Sin((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI /
                                           180.0)));

                    gp.Reset();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorOuterRadius,
                                                mCenter.Y - mScaleLinesMinorOuterRadius,
                                                2 * mScaleLinesMinorOuterRadius, 2 * mScaleLinesMinorOuterRadius));
                    gp.Reverse();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorInnerRadius,
                                                mCenter.Y - mScaleLinesMinorInnerRadius,
                                                2 * mScaleLinesMinorInnerRadius, 2 * mScaleLinesMinorInnerRadius));
                    gp.Reverse();
                    ggr.SetClip(gp);

                    ImageBack3(countValue, gp, ggr, imgp);

                    if (mScaleNumbersRotation != 0)
                    {
                        ggr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        ggr.RotateTransform(90.0F + mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue));
                    }
                    ggr.TranslateTransform(
                        (Single)
                        (Center.X +
                         mScaleNumbersRadius *
                         Math.Cos((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI / 180.0f)),
                        (Single)
                        (Center.Y +
                         mScaleNumbersRadius *
                         Math.Sin((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI / 180.0f)),
                        MatrixOrder.Append);

                    if (counter1 >= ScaleNumbersStartScaleLine - 1)
                    {
                        ggr.DrawString(valueText, imgp.Font, new SolidBrush(mScaleNumbersColor), -boundingBox.Width / 2,
                                       -fontBoundY1 - (fontBoundY2 - fontBoundY1 + 1) / 2,
                                       StringFormat.GenericTypographic);
                    }

                    countValue += mScaleLinesMajorStepValue;
                    counter1++;
                }
                ggr.ResetTransform();
                ggr.SetClip(imgp.ClientRectangle);
            }
예제 #18
0
            public void ImageBack3(Single countValue, GraphicsPath gp, Graphics ggr, ImagePaint imgp)
            {
                if (countValue < (mMaxValue - mMinValue))
                {
                    for (var counter2 = 1; counter2 <= mScaleLinesMinorNumOf; counter2++)
                    {
                        if (((mScaleLinesMinorNumOf % 2) == 1) &&
                            ((mScaleLinesMinorNumOf / 2) + 1 == counter2))
                        {
                            gp.Reset();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesInterOuterRadius,
                                                        mCenter.Y - mScaleLinesInterOuterRadius,
                                                        2 * mScaleLinesInterOuterRadius,
                                                        2 * mScaleLinesInterOuterRadius));
                            gp.Reverse();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesInterInnerRadius,
                                                        mCenter.Y - mScaleLinesInterInnerRadius,
                                                        2 * mScaleLinesInterInnerRadius,
                                                        2 * mScaleLinesInterInnerRadius));
                            gp.Reverse();
                            ggr.SetClip(gp);

                            ggr.DrawLine(new Pen(mScaleLinesInterColor, mScaleLinesInterWidth),
                                         (Center.X),
                                         (Center.Y),
                                         (Single)
                                         (Center.X +
                                          2 * mScaleLinesInterOuterRadius *
                                          Math.Cos((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)),
                                         (Single)
                                         (Center.Y +
                                          2 * mScaleLinesInterOuterRadius *
                                          Math.Sin((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)));

                            gp.Reset();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorOuterRadius,
                                                        mCenter.Y - mScaleLinesMinorOuterRadius,
                                                        2 * mScaleLinesMinorOuterRadius,
                                                        2 * mScaleLinesMinorOuterRadius));
                            gp.Reverse();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorInnerRadius,
                                                        mCenter.Y - mScaleLinesMinorInnerRadius,
                                                        2 * mScaleLinesMinorInnerRadius,
                                                        2 * mScaleLinesMinorInnerRadius));
                            gp.Reverse();
                            ggr.SetClip(gp);
                        }
                        else
                        {
                            ggr.DrawLine(new Pen(mScaleLinesMinorColor, mScaleLinesMinorWidth),
                                         (Center.X),
                                         (Center.Y),
                                         (Single)
                                         (Center.X +
                                          2 * mScaleLinesMinorOuterRadius *
                                          Math.Cos((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)),
                                         (Single)
                                         (Center.Y +
                                          2 * mScaleLinesMinorOuterRadius *
                                          Math.Sin((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)));
                        }
                    }
                }
                ggr.SetClip(imgp.ClientRectangle);
            }
예제 #19
0
파일: Grouper.cs 프로젝트: gburca/DreamBeam
        /// <summary>This method will paint the group title.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintGroupText(System.Drawing.Graphics g)
        {
            //Check if string has something-------------
            if (this.GroupTitle == string.Empty)
            {
                return;
            }
            //------------------------------------------

            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            SizeF StringSize  = g.MeasureString(this.GroupTitle, this.Font);
            Size  StringSize2 = StringSize.ToSize();

            if (this.GroupImage != null)
            {
                StringSize2.Width += 18;
            }
            int ArcWidth  = this.RoundCorners;
            int ArcHeight = this.RoundCorners;

            int ArcX1 = 20;
            int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1);
            int ArcY1 = 0;

            if (!this.V_TitleBorder)
            {
                ArcY1 = 9;
            }
            int ArcY2 = 24 - (ArcHeight + 1);

            if (V_TinyMode)
            {
                ArcY1 = 0;
                ArcY2 = 14 - (ArcHeight + 1);
            }

            System.Drawing.Drawing2D.GraphicsPath path  = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Drawing2D.GraphicsPath path2 = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush            = new SolidBrush(this.BorderColor);
            System.Drawing.Pen   BorderPen = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             TextColorBrush  = new SolidBrush(this.ForeColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle);        // Top Left
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle);        //Top Right
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle);        //Bottom Right
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);         //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------

            //Create Rounded Rectangle Path------

            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle);            // Top Left
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle);            //Top Right
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle);            //Bottom Right
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);             //Bottom Left
            path.CloseAllFigures();
            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (this.PaintGroupBox)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
                {
                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundBrush, path);
                    //-----------------------------------
                }
                else
                {
                    BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundGradientBrush, path);
                    //-----------------------------------
                }
            }
            //-----------------------------------

            //Paint Borded-----------------------
            if (this.V_TitleBorder)
            {
                g.DrawPath(BorderPen, path);
            }
            //-----------------------------------

            //Paint Text-------------------------
            int CustomStringWidth = (this.GroupImage != null) ? 44 : 28;

            if (V_TinyMode)
            {
                g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 0);
            }
            else
            {
                g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5);
            }
            //-----------------------------------

            //Draw GroupImage if there is one----
            if (this.GroupImage != null)
            {
                g.DrawImage(this.GroupImage, 28, 4, 16, 16);
            }
            //-----------------------------------
            if (!this.V_TitleBorder)
            {
                path2.AddLine(ArcX1, ArcY1 - 2, ArcX1, ArcY1 + 5);
                g.DrawPath(BorderPen, path2);
                path2.Reset();
                path2.AddLine(ArcX2, ArcY1 - 2, ArcX2, ArcY1 + 5);
                g.DrawPath(BorderPen, path2);
            }
            //Destroy Graphic Objects------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (TextColorBrush != null)
            {
                TextColorBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
            //-----------------------------------
        }
예제 #20
0
            //画刻度
            private void ImageBack1(GraphicsPath gp, Graphics ggr, ImagePaint imgp)
            {
                for (var counter = 0; counter < mRangeEndValue.Length; counter++)
                {
                    if (!(mRangeEndValue[counter] > mRangeStartValue[counter]) || !mRangeEnabled[counter])
                    {
                        continue;
                    }

                    var rangeStartAngle = mBaseArcStart +(mRangeStartValue[counter] - mMinValue) * mBaseArcSweep /(mMaxValue - mMinValue);
                    var rangeSweepAngle = (mRangeEndValue[counter] - mRangeStartValue[counter]) * mBaseArcSweep / (mMaxValue - mMinValue);
                    gp.Reset();
                    gp.AddPie(
                        new Rectangle(mCenter.X - mRangeOuterRadius[counter],
                                      mCenter.Y - mRangeOuterRadius[counter], 2 * mRangeOuterRadius[counter],
                                      2 * mRangeOuterRadius[counter]), rangeStartAngle, rangeSweepAngle);
                    gp.Reverse();
                    gp.AddPie(
                        new Rectangle(mCenter.X - mRangeInnerRadius[counter],
                                      mCenter.Y - mRangeInnerRadius[counter], 2 * mRangeInnerRadius[counter],
                                      2 * mRangeInnerRadius[counter]), rangeStartAngle, rangeSweepAngle);
                    gp.Reverse();
                    ggr.SetClip(gp);
                    //填充
                    ggr.FillPie(new SolidBrush(mRangeColor[counter]),
                                new Rectangle(mCenter.X - mRangeOuterRadius[counter],
                                              mCenter.Y - mRangeOuterRadius[counter],
                                              2 * mRangeOuterRadius[counter], 2 * mRangeOuterRadius[counter]),
                                rangeStartAngle, rangeSweepAngle);
                }
                ggr.SetClip(imgp.ClientRectangle);

                if (mBaseArcRadius > 0)
                {
                    ggr.DrawArc(new Pen(mBaseArcColor, mBaseArcWidth),
                                new Rectangle(mCenter.X - mBaseArcRadius, mCenter.Y - mBaseArcRadius,
                                              2 * mBaseArcRadius, 2 * mBaseArcRadius), mBaseArcStart, mBaseArcSweep);
                }
            }
예제 #21
0
    //---------------------------------------------------------------------

    private void GenerateAustPlusRandomEllipses(int count)
    {
      subjects.Clear();
      //load map of Australia from resource ...
      Assembly _assembly = Assembly.GetExecutingAssembly();
      using (BinaryReader polyStream = new BinaryReader(_assembly.GetManifestResourceStream("GuiDemo.aust.bin")))
      {
        int polyCnt = polyStream.ReadInt32();
        for (int i = 0; i < polyCnt; ++i)
        {
          int vertCnt = polyStream.ReadInt32();
          Polygon pg = new Polygon(vertCnt);
          for (int j = 0; j < vertCnt; ++j)
          {
            float x = polyStream.ReadSingle() * scale;
            float y = polyStream.ReadSingle() * scale;
            pg.Add(new IntPoint((int)x, (int)y));
          }
          subjects.Add(pg);
        }
      }
      clips.Clear();
      Random rand = new Random();
      using (GraphicsPath path = new GraphicsPath())
      {
        const int ellipse_size = 100, margin = 10;
        for (int i = 0; i < count; ++i)
        {
          int w = pictureBox1.ClientRectangle.Width - ellipse_size - margin * 2;
          int h = pictureBox1.ClientRectangle.Height - ellipse_size - margin * 2 - statusStrip1.Height;

          int x = rand.Next(w) + margin;
          int y = rand.Next(h) + margin;
          int size = rand.Next(ellipse_size - 20) + 20;
          path.Reset();
          path.AddEllipse(x, y, size, size);
          path.Flatten();
          Polygon clip = new Polygon(path.PathPoints.Count());
          foreach (PointF p in path.PathPoints)
            clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
          clips.Add(clip);
        }
      }
    }
예제 #22
0
        private static void drawTitle(Graphics g, TitleBufferElement title, double scaleFactor, BoundingRectangle viewBox)
        {
            using (Font f = title.Style.GetFont())
                using (SolidBrush fontBrush = new SolidBrush(title.Style.Color))
                {
                    SizeF size = g.MeasureString(title.Title, f, new PointF(0, 0), _titleStringFormat);
                    ICoordinate originPoint = PlanimetryEnvironment.NewCoordinate((title.Box.V1.X + title.Box.V2.X) / 2, title.Box.V2.Y);

                    using (GraphicsPath path = new GraphicsPath())
                    {
                        if (title.IsSimple)
                        {
                            path.AddString(title.Title,
                                           f.FontFamily,
                                           (int)f.Style,
                                           f.Size,
                                           new PointF((float)((originPoint.X - viewBox.MinX) * scaleFactor),
                                                      (float)((viewBox.MaxY - originPoint.Y) * scaleFactor)),
                                           _titleStringFormat);

                            if (title.Style.UseOutline)
                                using (Pen pen = new Pen(_titleOutlineColor, title.Style.OutlineSize))
                                {
                                    pen.MiterLimit = 1;
                                    g.DrawPath(pen, path);
                                }
                            g.FillPath(fontBrush, path);
                        }
                        else
                        {
                            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                            if (title.Style.UseOutline)
                                using (Pen pen = new Pen(_titleOutlineColor, title.Style.OutlineSize))
                                {
                                    pen.MiterLimit = 1;
                                    foreach (FollowingTitleElement element in title.FollowingTitle.Elements)
                                    {
                                        g.TranslateTransform(element.TranslationPoint.X, element.TranslationPoint.Y);
                                        g.RotateTransform(element.RotationAngle);

                                        path.Reset();
                                        path.AddString(element.Substring, f.FontFamily, (int)f.Style, f.Size, element.TitleOrigin, StringFormat.GenericTypographic);
                                        g.DrawPath(pen, path);
                                        g.ResetTransform();
                                    }
                                }

                            using (Brush b = new SolidBrush(title.Style.Color))
                                foreach (FollowingTitleElement element in title.FollowingTitle.Elements)
                                {
                                    g.TranslateTransform(element.TranslationPoint.X, element.TranslationPoint.Y);
                                    g.RotateTransform(element.RotationAngle);

                                    path.Reset();
                                    path.AddString(element.Substring, f.FontFamily, (int)f.Style, f.Size, element.TitleOrigin, StringFormat.GenericTypographic);
                                    g.FillPath(fontBrush, path);
                                    g.ResetTransform();
                                }
                        }
                    }
                }
        }
예제 #23
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if ((!this.picturePanel.firstload && (this.SVGDocument != null)))
            {
                SizeF ef1 = this.picturePanel.GridSize;
                float single1 = ef1.Height;
                float single2 = ef1.Width;
                Point point1 = this.picturePanel.PointToView(new Point(e.X, e.Y));
                this.picturePanel.ToolTip(point1.X.ToString() + "," + point1.Y.ToString(), 0);
                this.picturePanel.InvadatePosLine();
                if (((this.picturePanel.ShowGuides && !this.picturePanel.lockGuides) && (e.Button == MouseButtons.None)) && (OperationFunc.IsSelectOperation(this.currentOperation) || OperationFunc.IsTransformOperation(this.currentOperation)))
                {
                    this.oldindex = 0;
                    foreach (RefLine line1 in this.picturePanel.RefLines)
                    {
                        if ((line1.Hori && (Math.Abs(point1.Y - line1.Pos) < 2)) || (!line1.Hori && (Math.Abs(point1.X - line1.Pos) < 2)))
                        {
                            this.hori = line1.Hori;
                            this.oldPoint = base.PointToClient(Control.MousePosition);
                            this.Cursor = SpecialCursors.DragInfoCursor;
                            this.picturePanel.ToolTip("�ƶ�������϶������ߣ��ϳ�������ɾ��������", 1);
                            return;
                        }
                        this.oldindex++;
                    }
                    this.oldindex = -1;
                }
                if (((this.picturePanel.ShowGuides && !this.picturePanel.lockGuides) && ((e.Button == MouseButtons.Left) && this.mousedown)) && (((this.oldindex >= 0) && (this.oldindex < this.picturePanel.RefLines.Count)) && (OperationFunc.IsSelectOperation(this.currentOperation) || OperationFunc.IsTransformOperation(this.currentOperation))))
                {
                    if (this.hori)
                    {
                        this.win32.hdc = this.win32.W32GetDC(base.Handle);
                        this.win32.W32SetROP2(7);
                        GraphicsPath path1 = new GraphicsPath();
                        path1.AddLine(new PointF(0f, (float) this.oldPoint.Y), new PointF((float) base.Width, (float) this.oldPoint.Y));
                        this.win32.W32PolyDraw(path1);
                        this.oldPoint = this.picturePanel.PointToView(base.PointToClient(Control.MousePosition));
                        if (this.picturePanel.SnapToGrid)
                        {
                            int num1 = (int) ((this.oldPoint.X + (single2/2f))/single2);
                            int num2 = (int) ((this.oldPoint.Y + (single1/2f))/single1);
                            this.oldPoint = new Point((int) (num1*single2), (int) (num2*single1));
                        }
                        this.oldPoint = Point.Round(this.picturePanel.PointToSystem(new PointF((float) this.oldPoint.X, (float) this.oldPoint.Y)));
                        path1.Reset();
                        path1.AddLine(new PointF(0f, (float) this.oldPoint.Y), new PointF((float) base.Width, (float) this.oldPoint.Y));
                        this.win32.W32PolyDraw(path1);
                        this.win32.ReleaseDC();
                        path1.Dispose();
                    }
                    else
                    {
                        this.win32.hdc = this.win32.W32GetDC(base.Handle);
                        this.win32.W32SetROP2(7);
                        GraphicsPath path2 = new GraphicsPath();
                        path2.AddLine(new PointF((float) this.oldPoint.X, 0f), new PointF((float) this.oldPoint.X, (float) base.Height));
                        this.win32.W32PolyDraw(path2);
                        this.oldPoint = this.picturePanel.PointToView(base.PointToClient(Control.MousePosition));
                        if (this.picturePanel.SnapToGrid)
                        {
                            int num3 = (int) ((this.oldPoint.X + (single2/2f))/single2);
                            int num4 = (int) ((this.oldPoint.Y + (single1/2f))/single1);
                            this.oldPoint = new Point((int) (num3*single2), (int) (num4*single1));
                        }
                        this.oldPoint = Point.Round(this.picturePanel.PointToSystem(new PointF((float) this.oldPoint.X, (float) this.oldPoint.Y)));
                        path2.Reset();
                        path2.AddLine(new PointF((float) this.oldPoint.X, 0f), new PointF((float) this.oldPoint.X, (float) base.Height));
                        this.win32.W32PolyDraw(path2);
                        this.win32.ReleaseDC();
                        path2.Dispose();
                    }
                }
                else if (this.editingOperation != null)
                {
                    if(moving)return;
                    DateTime time1 =DateTime.Now;

                    moving =true;
                    this.editingOperation.OnMouseMove(e);

                    moving =false;
                    DateTime time2 =DateTime.Now;

                    TimeSpan ts=time2-time1;

                    this.picturePanel.ToolTip(ts.ToString(), 1);
                }
            }
        }
예제 #24
0
        private Bitmap GenerateImageFromTextWithStyle(string text)
        {
            const bool subtitleFontBold = false;
            bool subtitleAlignLeft = comboBoxHAlign.SelectedIndex == 0;

            // remove styles for display text (except italic)
            text = RemoveSubStationAlphaFormatting(text);
            text = text.Replace("<b>", string.Empty);
            text = text.Replace("</b>", string.Empty);
            text = text.Replace("<B>", string.Empty);
            text = text.Replace("</B>", string.Empty);
            text = text.Replace("<u>", string.Empty);
            text = text.Replace("</u>", string.Empty);
            text = text.Replace("<U>", string.Empty);
            text = text.Replace("</U>", string.Empty);

            Font font;
            try
            {
                font = new Font(_subtitleFontName, _subtitleFontSize, FontStyle.Regular);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                font = new Font(FontFamily.Families[0].Name, _subtitleFontSize);
            }
            var bmp = new Bitmap(400, 200);
            var g = Graphics.FromImage(bmp);

            SizeF textSize = g.MeasureString("Hj!", font);
            var lineHeight = (textSize.Height * 0.64f);

            textSize = g.MeasureString(HtmlUtil.RemoveHtmlTags(text), font);
            g.Dispose();
            bmp.Dispose();
            int sizeX = (int)(textSize.Width * 0.8) + 40;
            int sizeY = (int)(textSize.Height * 0.8) + 30;
            if (sizeX < 1)
                sizeX = 1;
            if (sizeY < 1)
                sizeY = 1;
            bmp = new Bitmap(sizeX, sizeY);
            g = Graphics.FromImage(bmp);

            var lefts = new List<float>();
            foreach (var line in HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagItalic, HtmlUtil.TagFont).SplitToLines())
            {
                if (subtitleAlignLeft)
                    lefts.Add(5);
                else
                    lefts.Add((float)(bmp.Width - g.MeasureString(line, font).Width * 0.8 + 15) / 2);
            }

            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.CompositingQuality = CompositingQuality.HighQuality;

            var sf = new StringFormat();
            sf.Alignment = StringAlignment.Near;
            sf.LineAlignment = StringAlignment.Near;// draw the text to a path
            var path = new GraphicsPath();

            // display italic
            var sb = new StringBuilder();
            int i = 0;
            bool isItalic = false;
            float left = 5;
            if (lefts.Count > 0)
                left = lefts[0];
            float top = 5;
            bool newLine = false;
            int lineNumber = 0;
            float leftMargin = left;
            bool italicFromStart = false;
            int newLinePathPoint = -1;
            Color c = _subtitleColor;
            var colorStack = new Stack<Color>();
            var lastText = new StringBuilder();
            while (i < text.Length)
            {
                if (text.Substring(i).StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
                {
                    float addLeft = 0;
                    int oldPathPointIndex = path.PointCount;
                    if (oldPathPointIndex < 0)
                        oldPathPointIndex = 0;

                    if (sb.Length > 0)
                    {
                        TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    }
                    if (path.PointCount > 0)
                    {
                        PointF[] list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                        for (int k = oldPathPointIndex; k < list.Length; k++)
                        {
                            if (list[k].X > addLeft)
                                addLeft = list[k].X;
                        }
                    }
                    if (addLeft == 0)
                        addLeft = left + 2;
                    left = addLeft;

                    if (_borderWidth > 0)
                        g.DrawPath(new Pen(_borderColor, _borderWidth), path);
                    g.FillPath(new SolidBrush(c), path);
                    path.Reset();
                    path = new GraphicsPath();
                    sb = new StringBuilder();

                    int endIndex = text.Substring(i).IndexOf('>');
                    if (endIndex < 0)
                    {
                        i += 9999;
                    }
                    else
                    {
                        string fontContent = text.Substring(i, endIndex);
                        if (fontContent.Contains(" color="))
                        {
                            var arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (arr.Length > 0)
                            {
                                string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
                                try
                                {
                                    colorStack.Push(c); // save old color
                                    if (fontColor.StartsWith("rgb("))
                                    {
                                        arr = fontColor.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
                                    }
                                    else
                                    {
                                        c = ColorTranslator.FromHtml(fontColor);
                                    }
                                }
                                catch
                                {
                                    c = _subtitleColor;
                                }
                            }
                        }
                        i += endIndex;
                    }
                }
                else if (text.Substring(i).StartsWith("</font>", StringComparison.OrdinalIgnoreCase))
                {
                    if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
                    {
                        if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                        {
                            string t = sb.ToString();
                            sb.Clear();
                            sb.Append(' ');
                            sb.Append(t);
                        }

                        float addLeft = 0;
                        int oldPathPointIndex = path.PointCount - 1;
                        if (oldPathPointIndex < 0)
                            oldPathPointIndex = 0;
                        if (sb.Length > 0)
                        {
                            TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                        }
                        if (path.PointCount > 0)
                        {
                            PointF[] list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                            for (int k = oldPathPointIndex; k < list.Length; k++)
                            {
                                if (list[k].X > addLeft)
                                    addLeft = list[k].X;
                            }
                        }
                        if (addLeft == 0)
                            addLeft = left + 2;
                        left = addLeft;

                        if (_borderWidth > 0)
                            g.DrawPath(new Pen(_borderColor, _borderWidth), path);
                        g.FillPath(new SolidBrush(c), path);
                        path.Reset();
                        //path = new GraphicsPath();
                        sb = new StringBuilder();
                        if (colorStack.Count > 0)
                            c = colorStack.Pop();
                    }
                    i += 6;
                }
                else if (text.Substring(i).StartsWith("<i>", StringComparison.OrdinalIgnoreCase))
                {
                    italicFromStart = i == 0;
                    if (sb.Length > 0)
                    {
                        TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    }
                    isItalic = true;
                    i += 2;
                }
                else if (text.Substring(i).StartsWith("</i>", StringComparison.OrdinalIgnoreCase) && isItalic)
                {
                    if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                    {
                        string t = sb.ToString();
                        sb.Clear();
                        sb.Append(' ');
                        sb.Append(t);
                    }
                    TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    isItalic = false;
                    i += 3;
                }
                else if (text.Substring(i).StartsWith(Environment.NewLine))
                {
                    TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);

                    top += lineHeight;
                    newLine = true;
                    i += Environment.NewLine.Length - 1;
                    lineNumber++;
                    if (lineNumber < lefts.Count)
                    {
                        leftMargin = lefts[lineNumber];
                        left = leftMargin;
                    }
                    if (isItalic)
                        italicFromStart = true;
                }
                else
                {
                    sb.Append(text[i]);
                }
                i++;
            }
            if (sb.Length > 0)
                TextDraw.DrawText(font, sf, path, sb, isItalic, subtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
            sf.Dispose();

            if (_borderWidth > 0)
                g.DrawPath(new Pen(_borderColor, _borderWidth), path);
            g.FillPath(new SolidBrush(c), path);
            g.Dispose();
            var nbmp = new NikseBitmap(bmp);
            nbmp.CropTransparentSidesAndBottom(2, true);
            return nbmp.GetBitmap();
        }
예제 #25
0
        private void draw_me()
        {
            using (GraphicsPath winShape = new GraphicsPath())
            {
                //get the (resized) rectangle to draw our Yin-Yang
                rc = this.ClientRectangle;

                shape = new Region(winShape);
                //Add ellipse
                winShape.AddEllipse(this.ClientRectangle);

                //start with making the outer circle region
                shape.Union(winShape);
                //rectangle for the inner circle
                rc = new Rectangle(rc.X + border, rc.Y + border,
                    rc.Size.Width - 2 * border, rc.Size.Height - 2 * border);
                //remove old stuff
                winShape.Reset();
                //add inner circle
                winShape.AddEllipse(rc);
                //exclude inner circle
                shape.Exclude(winShape);
                //add Yang to the region
                int yang_x = rc.Width / 4 + border;
                int yang_y = border;
                int yang_height = rc.Height / 2;
                int yang_width = rc.Width / 2;

                Rectangle yang = new Rectangle(yang_x, yang_y, yang_width, yang_height);
                winShape.Reset();
                winShape.AddEllipse(yang);
                shape.Union(winShape);
                //add left side
                rc = this.ClientRectangle;
                winShape.Reset();
                winShape.AddArc(rc, 90, 180);
                shape.Union(winShape);
                //add the small top circle
                int dot_height = yang.Height * 1 / 6;
                int dot_width = yang.Width * 1 / 6;
                int top_dot_x = yang.X + yang_width / 2 - dot_width / 2;
                int top_dot_y = yang.Y + yang_height / 2 - dot_height / 2;
                Rectangle top_dot = new Rectangle(top_dot_x, top_dot_y, dot_width, dot_height);
                winShape.Reset();
                winShape.AddEllipse(top_dot);
                shape.Exclude(winShape);
                //exclude/remove Yin(lower circle)
                rc = new Rectangle(rc.X + border, rc.Y + border,
                    rc.Size.Width - 2 * border, rc.Size.Height - 2 * border);
                int yin_x = rc.Width / 4 + border;
                int yin_y = rc.Height / 2+ border;
                int yin_height = rc.Height / 2;
                int yin_width = rc.Width / 2;
                yang = new Rectangle(yin_x, yin_y, yin_width, yin_height);
                winShape.Reset();
                winShape.AddEllipse(yang);
                shape.Exclude(winShape);
                //add/union bottom dot
                int bot_dot_x = yang.X + yang.Width / 2 - dot_width / 2;
                int bot_dot_y = yang.Y + yang.Height / 2 - dot_height / 2;
                Rectangle bot_dot = new Rectangle(bot_dot_x, bot_dot_y, dot_width, dot_height);
                winShape.Reset();
                winShape.AddEllipse(bot_dot);
                shape.Union(winShape);

                //UPDATE NEW SHAPE !
                if (isYin)
                {
                    RotateRegion(shape, 180);
                    this.Region = shape;
                }
                else
                    this.Region = shape;
            }
        }
        /// <summary>
        /// The generate image from text with style inner.
        /// </summary>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="Bitmap"/>.
        /// </returns>
        private static Bitmap GenerateImageFromTextWithStyleInner(MakeBitmapParameter parameter)
        {
            string text = parameter.P.Text;

            text = RemoveSubStationAlphaFormatting(text);

            text = text.Replace("<I>", "<i>");
            text = text.Replace("</I>", "</i>");
            text = HtmlUtil.FixInvalidItalicTags(text);

            text = text.Replace("<B>", "<b>");
            text = text.Replace("</B>", "</b>");

            // no support for underline
            text = HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagUnderline);

            Font font = null;
            Bitmap bmp = null;
            try
            {
                font = SetFont(parameter, parameter.SubtitleFontSize);
                var lineHeight = parameter.LineHeight; // (textSize.Height * 0.64f);

                SizeF textSize;
                using (var bmpTemp = new Bitmap(1, 1))
                using (var g = Graphics.FromImage(bmpTemp))
                {
                    textSize = g.MeasureString(HtmlUtil.RemoveHtmlTags(text), font);
                }

                int sizeX = (int)(textSize.Width * 1.8) + 150;
                int sizeY = (int)(textSize.Height * 0.9) + 50;
                if (sizeX < 1)
                {
                    sizeX = 1;
                }

                if (sizeY < 1)
                {
                    sizeY = 1;
                }

                if (parameter.BackgroundColor != Color.Transparent)
                {
                    var nbmpTemp = new NikseBitmap(sizeX, sizeY);
                    nbmpTemp.Fill(parameter.BackgroundColor);
                    bmp = nbmpTemp.GetBitmap();
                }
                else
                {
                    bmp = new Bitmap(sizeX, sizeY);
                }

                // align lines with gjpqy, a bit lower
                var lines = text.SplitToLines();
                int baseLinePadding = 13;
                if (parameter.SubtitleFontSize < 30)
                {
                    baseLinePadding = 12;
                }

                if (parameter.SubtitleFontSize < 25)
                {
                    baseLinePadding = 9;
                }

                if (lines.Length > 0)
                {
                    var lastLine = lines[lines.Length - 1];
                    if (lastLine.Contains(new[] { 'g', 'j', 'p', 'q', 'y', ',', 'ý', 'ę', 'ç', 'Ç' }))
                    {
                        var textNoBelow = lastLine.Replace('g', 'a').Replace('j', 'a').Replace('p', 'a').Replace('q', 'a').Replace('y', 'a').Replace(',', 'a').Replace('ý', 'a').Replace('ę', 'a').Replace('ç', 'a').Replace('Ç', 'a');
                        baseLinePadding -= (int)Math.Round(TextDraw.MeasureTextHeight(font, lastLine, parameter.SubtitleFontBold) - TextDraw.MeasureTextHeight(font, textNoBelow, parameter.SubtitleFontBold));
                    }
                    else
                    {
                        baseLinePadding += 1;
                    }

                    if (baseLinePadding < 0)
                    {
                        baseLinePadding = 0;
                    }
                }

                // TODO: Better baseline - test http://bobpowell.net/formattingtext.aspx
                // float baselineOffset=font.SizeInPoints/font.FontFamily.GetEmHeight(font.Style)*font.FontFamily.GetCellAscent(font.Style);
                // float baselineOffsetPixels = g.DpiY/72f*baselineOffset;
                // baseLinePadding = (int)Math.Round(baselineOffsetPixels);
                var lefts = new List<float>();
                if (text.Contains("<font", StringComparison.OrdinalIgnoreCase) || text.Contains("<i>", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (string line in text.SplitToLines())
                    {
                        var lineNoHtml = HtmlUtil.RemoveOpenCloseTags(line, HtmlUtil.TagItalic, HtmlUtil.TagFont);
                        if (parameter.AlignLeft)
                        {
                            lefts.Add(5);
                        }
                        else if (parameter.AlignRight)
                        {
                            lefts.Add(bmp.Width - CalcWidthViaDraw(lineNoHtml, parameter) - 15); // calculate via drawing+crop
                        }
                        else
                        {
                            lefts.Add((float)((bmp.Width - CalcWidthViaDraw(lineNoHtml, parameter) + 5.0) / 2.0)); // calculate via drawing+crop
                        }
                    }
                }
                else
                {
                    foreach (var line in HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagItalic, HtmlUtil.TagFont).SplitToLines())
                    {
                        if (parameter.AlignLeft)
                        {
                            lefts.Add(5);
                        }
                        else if (parameter.AlignRight)
                        {
                            lefts.Add(bmp.Width - (TextDraw.MeasureTextWidth(font, line, parameter.SubtitleFontBold) + 15));
                        }
                        else
                        {
                            lefts.Add((float)((bmp.Width - TextDraw.MeasureTextWidth(font, line, parameter.SubtitleFontBold) + 15) / 2.0));
                        }
                    }
                }

                var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near };

                using (var g = Graphics.FromImage(bmp))
                {
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                    if (parameter.SimpleRendering)
                    {
                        if (text.StartsWith("<font ", StringComparison.Ordinal) && Utilities.CountTagInText(text, "<font") == 1)
                        {
                            parameter.SubtitleColor = Utilities.GetColorFromFontString(text, parameter.SubtitleColor);
                        }

                        text = HtmlUtil.RemoveHtmlTags(text, true); // TODO: Perhaps check single color...
                        var brush = new SolidBrush(parameter.BorderColor);
                        int x = 3;
                        const int y = 3;
                        sf.Alignment = StringAlignment.Near;
                        if (parameter.AlignLeft)
                        {
                            sf.Alignment = StringAlignment.Near;
                        }
                        else if (parameter.AlignRight)
                        {
                            sf.Alignment = StringAlignment.Far;
                            x = parameter.ScreenWidth - 5;
                        }
                        else
                        {
                            sf.Alignment = StringAlignment.Center;
                            x = parameter.ScreenWidth / 2;
                        }

                        bmp = new Bitmap(parameter.ScreenWidth, sizeY);

                        Graphics surface = Graphics.FromImage(bmp);
                        surface.CompositingQuality = CompositingQuality.HighSpeed;
                        surface.InterpolationMode = InterpolationMode.Default;
                        surface.SmoothingMode = SmoothingMode.HighSpeed;
                        surface.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                        for (int j = 0; j < parameter.BorderWidth; j++)
                        {
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y + 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y + 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y + 1 + j }, sf);

                            surface.DrawString(text, font, brush, new PointF { X = x - j, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j, Y = y + 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j + 1, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j + 1, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j + 1, Y = y + 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j - 1, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j - 1, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j - 1, Y = y + 1 + j }, sf);

                            surface.DrawString(text, font, brush, new PointF { X = x - j, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j, Y = y + 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j + 1, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j + 1, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j + 1, Y = y + 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j - 1, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j - 1, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - j - 1, Y = y + 1 - j }, sf);

                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y + 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y + 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y + 1 - j }, sf);

                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j, Y = y + 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j + 1, Y = y + 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y - 1 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y - 0 + j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + j - 1, Y = y + 1 + j }, sf);

                            surface.DrawString(text, font, brush, new PointF { X = x, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x, Y = y + 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + 1, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + 1, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x + 1, Y = y + 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - 1, Y = y - 1 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - 1, Y = y - 0 - j }, sf);
                            surface.DrawString(text, font, brush, new PointF { X = x - 1, Y = y + 1 - j }, sf);
                        }

                        brush.Dispose();
                        brush = new SolidBrush(parameter.SubtitleColor);
                        surface.CompositingQuality = CompositingQuality.HighQuality;
                        surface.SmoothingMode = SmoothingMode.HighQuality;
                        surface.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        surface.DrawString(text, font, brush, new PointF { X = x, Y = y }, sf);
                        surface.Dispose();
                        brush.Dispose();
                    }
                    else
                    {
                        var path = new GraphicsPath();
                        var sb = new StringBuilder();
                        bool isItalic = false;
                        bool isBold = parameter.SubtitleFontBold;
                        float left = 5;
                        if (lefts.Count > 0)
                        {
                            left = lefts[0];
                        }

                        float top = 5;
                        bool newLine = false;
                        int lineNumber = 0;
                        float leftMargin = left;
                        int newLinePathPoint = -1;
                        Color c = parameter.SubtitleColor;
                        var colorStack = new Stack<Color>();
                        var lastText = new StringBuilder();
                        int numberOfCharsOnCurrentLine = 0;
                        for (var i = 0; i < text.Length; i++)
                        {
                            if (text.Substring(i).StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
                            {
                                float addLeft = 0;
                                int oldPathPointIndex = path.PointCount;
                                if (oldPathPointIndex < 0)
                                {
                                    oldPathPointIndex = 0;
                                }

                                if (sb.Length > 0)
                                {
                                    lastText.Append(sb);
                                    TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                                }

                                if (path.PointCount > 0)
                                {
                                    var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                                    for (int k = oldPathPointIndex; k < list.Length; k++)
                                    {
                                        if (list[k].X > addLeft)
                                        {
                                            addLeft = list[k].X;
                                        }
                                    }
                                }

                                if (path.PointCount == 0)
                                {
                                    addLeft = left;
                                }
                                else if (addLeft < 0.01)
                                {
                                    addLeft = left + 2;
                                }

                                left = addLeft;

                                DrawShadowAndPath(parameter, g, path);
                                var p2 = new SolidBrush(c);
                                g.FillPath(p2, path);
                                p2.Dispose();
                                path.Reset();
                                path = new GraphicsPath();
                                sb = new StringBuilder();

                                int endIndex = text.Substring(i).IndexOf('>');
                                if (endIndex < 0)
                                {
                                    i += 9999;
                                }
                                else
                                {
                                    string fontContent = text.Substring(i, endIndex);
                                    if (fontContent.Contains(" color="))
                                    {
                                        string[] arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                                        if (arr.Length > 0)
                                        {
                                            string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
                                            try
                                            {
                                                colorStack.Push(c); // save old color
                                                if (fontColor.StartsWith("rgb(", StringComparison.Ordinal))
                                                {
                                                    arr = fontColor.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                                    c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
                                                }
                                                else
                                                {
                                                    c = ColorTranslator.FromHtml(fontColor);
                                                }
                                            }
                                            catch
                                            {
                                                c = parameter.SubtitleColor;
                                            }
                                        }
                                    }

                                    i += endIndex;
                                }
                            }
                            else if (text.Substring(i).StartsWith("</font>", StringComparison.OrdinalIgnoreCase))
                            {
                                if (text.Substring(i).ToLower().Replace("</font>", string.Empty).Length > 0)
                                {
                                    if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                                    {
                                        string t = sb.ToString();
                                        sb.Clear();
                                        sb.Append(' ');
                                        sb.Append(t);
                                    }

                                    float addLeft = 0;
                                    int oldPathPointIndex = path.PointCount - 1;
                                    if (oldPathPointIndex < 0)
                                    {
                                        oldPathPointIndex = 0;
                                    }

                                    if (sb.Length > 0)
                                    {
                                        if (lastText.Length > 0 && left > 2)
                                        {
                                            left -= 1.5f;
                                        }

                                        lastText.Append(sb);

                                        TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                                    }

                                    if (path.PointCount > 0)
                                    {
                                        var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                                        for (int k = oldPathPointIndex; k < list.Length; k++)
                                        {
                                            if (list[k].X > addLeft)
                                            {
                                                addLeft = list[k].X;
                                            }
                                        }
                                    }

                                    if (addLeft < 0.01)
                                    {
                                        addLeft = left + 2;
                                    }

                                    left = addLeft;

                                    DrawShadowAndPath(parameter, g, path);
                                    g.FillPath(new SolidBrush(c), path);
                                    path.Reset();
                                    sb = new StringBuilder();
                                    if (colorStack.Count > 0)
                                    {
                                        c = colorStack.Pop();
                                    }

                                    if (left >= 3)
                                    {
                                        left -= 2.5f;
                                    }
                                }

                                i += 6;
                            }
                            else if (text.Substring(i).StartsWith("<i>", StringComparison.OrdinalIgnoreCase))
                            {
                                if (sb.Length > 0)
                                {
                                    lastText.Append(sb);
                                    TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                                }

                                isItalic = true;
                                i += 2;
                            }
                            else if (text.Substring(i).StartsWith("</i>", StringComparison.OrdinalIgnoreCase) && isItalic)
                            {
                                if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                                {
                                    string t = sb.ToString();
                                    sb.Clear();
                                    sb.Append(' ');
                                    sb.Append(t);
                                }

                                lastText.Append(sb);
                                TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                                isItalic = false;
                                i += 3;
                            }
                            else if (text.Substring(i).StartsWith("<b>", StringComparison.OrdinalIgnoreCase))
                            {
                                if (sb.Length > 0)
                                {
                                    lastText.Append(sb);
                                    TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                                }

                                isBold = true;
                                i += 2;
                            }
                            else if (text.Substring(i).StartsWith("</b>", StringComparison.OrdinalIgnoreCase) && isBold)
                            {
                                if (lastText.EndsWith(' ') && !sb.StartsWith(' '))
                                {
                                    string t = sb.ToString();
                                    sb.Clear();
                                    sb.Append(' ');
                                    sb.Append(t);
                                }

                                lastText.Append(sb);
                                TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                                isBold = false;
                                i += 3;
                            }
                            else if (text.Substring(i).StartsWith(Environment.NewLine, StringComparison.Ordinal))
                            {
                                lastText.Append(sb);
                                TextDraw.DrawText(font, sf, path, sb, isItalic, isBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);

                                top += lineHeight;
                                newLine = true;
                                i += Environment.NewLine.Length - 1;
                                lineNumber++;
                                if (lineNumber < lefts.Count)
                                {
                                    leftMargin = lefts[lineNumber];
                                    left = leftMargin;
                                }

                                numberOfCharsOnCurrentLine = 0;
                            }
                            else
                            {
                                if (numberOfCharsOnCurrentLine != 0 || text[i] != ' ')
                                {
                                    sb.Append(text[i]);
                                    numberOfCharsOnCurrentLine++;
                                }
                            }
                        }

                        if (sb.Length > 0)
                        {
                            TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                        }

                        DrawShadowAndPath(parameter, g, path);
                        g.FillPath(new SolidBrush(c), path);
                    }
                }

                sf.Dispose();

                var nbmp = new NikseBitmap(bmp);
                if (parameter.BackgroundColor == Color.Transparent)
                {
                    nbmp.CropTransparentSidesAndBottom(baseLinePadding, true);
                    nbmp.CropTransparentSidesAndBottom(2, false);
                }
                else
                {
                    nbmp.CropSidesAndBottom(4, parameter.BackgroundColor, true);
                    nbmp.CropTop(4, parameter.BackgroundColor);
                }

                if (nbmp.Width > parameter.ScreenWidth)
                {
                    parameter.Error = "#" + parameter.P.Number.ToString(CultureInfo.InvariantCulture) + ": " + nbmp.Width.ToString(CultureInfo.InvariantCulture) + " > " + parameter.ScreenWidth.ToString(CultureInfo.InvariantCulture);
                }

                if (parameter.Type3D == 1)
                {
                    // Half-side-by-side 3D
                    Bitmap singleBmp = nbmp.GetBitmap();
                    Bitmap singleHalfBmp = ScaleToHalfWidth(singleBmp);
                    singleBmp.Dispose();
                    var sideBySideBmp = new Bitmap(parameter.ScreenWidth, singleHalfBmp.Height);
                    int singleWidth = parameter.ScreenWidth / 2;
                    int singleLeftMargin = (singleWidth - singleHalfBmp.Width) / 2;

                    using (Graphics gSideBySide = Graphics.FromImage(sideBySideBmp))
                    {
                        gSideBySide.DrawImage(singleHalfBmp, singleLeftMargin + parameter.Depth3D, 0);
                        gSideBySide.DrawImage(singleHalfBmp, singleWidth + singleLeftMargin - parameter.Depth3D, 0);
                    }

                    nbmp = new NikseBitmap(sideBySideBmp);
                    if (parameter.BackgroundColor == Color.Transparent)
                    {
                        nbmp.CropTransparentSidesAndBottom(2, true);
                    }
                    else
                    {
                        nbmp.CropSidesAndBottom(4, parameter.BackgroundColor, true);
                    }
                }
                else if (parameter.Type3D == 2)
                {
                    // Half-Top/Bottom 3D
                    nbmp = Make3DTopBottom(parameter, nbmp);
                }

                return nbmp.GetBitmap();
            }
            finally
            {
                if (font != null)
                {
                    font.Dispose();
                }

                if (bmp != null)
                {
                    bmp.Dispose();
                }
            }
        }
예제 #27
0
파일: Form1.cs 프로젝트: sverreeh/clipper
        //------------------------------------------------------------------------------
        private static void DrawButtons(Graphics graphics, MultiPath mp, bool small = false)
        {
            if (mp == null || mp.Count == 0) return;
              GraphicsPath gpath = new GraphicsPath(FillMode.Alternate);
              SolidBrush midBrush, startBrush, endBrush;
              Pen pen;
              if (small)
              {
            midBrush = new SolidBrush(MakeColor(0xFFFFAAAA));
            startBrush = new SolidBrush(MakeColor(0xFFFFAAAA));
            endBrush = new SolidBrush(MakeColor(0xFFFFAAAA));
            pen = new Pen(MakeColor(0xFF660000), 1.0f);
              }
              else
              {
            midBrush = new SolidBrush(MakeColor(0x20808080));
            startBrush = new SolidBrush(MakeColor(0x9980FF80));
            endBrush = new SolidBrush(MakeColor(0x99FA8072));
            pen = new Pen(Color.Black, 1.0f);
              }
              foreach (MultiPathSegment mps in mp)
              {
            int len = mps.Count;
            if (len == 0) continue;

            for (int j = 0; j < len; ++j)
            {
              PointF[] btnPts = MakeButton(mps[j], small);
              gpath.AddPolygon(btnPts);
            }
            graphics.FillPath(midBrush, gpath);
            graphics.DrawPath(pen, gpath);
            gpath.Reset();
              }

              //draw the start button a shade of green ...
              if (mp.Count > 0 && mp[0].Count > 0)
              {
            gpath.AddPolygon(MakeButton(mp[0][0], small));
            graphics.FillPath(startBrush, gpath);

            MultiPathSegment mps = mp[mp.Count - 1];
            //draw the end button a shade of red ...
            if (mps.index > 0 || mps.Count > 1)
            {
              gpath.Reset();
              gpath.AddPolygon(MakeButton(mps[mps.Count -1], small));
              graphics.FillPath(endBrush, gpath);
            }
              }

              //clean-up
              midBrush.Dispose();
              startBrush.Dispose();
              endBrush.Dispose();
              pen.Dispose();
              gpath.Dispose();
        }
        private void DrawCursor()
        {
            _lower = 0f;
            float bandpassOffset;
            var bandpassWidth = 0f;
            var cursorWidth = Math.Max((_filterBandwidth + _filterOffset) * _xIncrement, 2);
            var xCarrier = (float) ClientRectangle.Width / 2 + (_frequency - _displayCenterFrequency) * _xIncrement;

            switch (_bandType)
            {
                case BandType.Upper:
                    bandpassOffset = _filterOffset * _xIncrement;
                    bandpassWidth = cursorWidth - bandpassOffset;
                    _lower = xCarrier + bandpassOffset;
                    break;

                case BandType.Lower:
                    bandpassOffset = _filterOffset * _xIncrement;
                    bandpassWidth = cursorWidth - bandpassOffset;
                    _lower = xCarrier - bandpassOffset - bandpassWidth;
                    break;

                case BandType.Center:
                    _lower = xCarrier - cursorWidth / 2;
                    bandpassWidth = cursorWidth;
                    break;
            }
            _upper = _lower + bandpassWidth;

            using (var transparentBackground = new SolidBrush(Color.FromArgb(80, Color.DarkGray)))
            using (var redPen = new Pen(Color.Red))
            using (var graphics = Graphics.FromImage(_buffer))
            using (var fontFamily = new FontFamily("Arial"))
            using (var path = new GraphicsPath())
            using (var outlinePen = new Pen(Color.Black))
            {
                if (_enableFilter && cursorWidth < ClientRectangle.Width)
                {
                    var carrierPen = redPen;
                    carrierPen.Width = CarrierPenWidth;
                    graphics.FillRectangle(transparentBackground, (int) _lower + 1, 0, (int) bandpassWidth, ClientRectangle.Height);
                    if (xCarrier >= AxisMargin && xCarrier <= ClientRectangle.Width - AxisMargin)
                    {
                        graphics.DrawLine(carrierPen, xCarrier, 0f, xCarrier, ClientRectangle.Height);
                    }
                }
                if (_markPeaks && _spectrumWidth > 0)
                {
                    var windowSize = (int) bandpassWidth;
                    windowSize = Math.Max(windowSize, 10);
                    windowSize = Math.Min(windowSize, _scaledSpectrum.Length);
                    PeakDetector.GetPeaks(_scaledSpectrum, _peaks, windowSize);
                    var yIncrement = (ClientRectangle.Height - 2 * AxisMargin) / (float) byte.MaxValue;
                    for (var i = 0; i < _peaks.Length; i++)
                    {
                        if (_peaks[i])
                        {
                            var y = (int) (ClientRectangle.Height - AxisMargin - _scaledSpectrum[i] * yIncrement);
                            var x = i + AxisMargin;
                            graphics.DrawEllipse(Pens.Yellow, x - 5, y - 5, 10, 10);
                        }
                    }
                }

                if (_hotTrackNeeded && _trackingX >= AxisMargin && _trackingX <= ClientRectangle.Width - AxisMargin &&
                    _trackingY >= AxisMargin && _trackingY <= ClientRectangle.Height - AxisMargin)
                {
                    if (_scaledSpectrum != null && !_changingFrequency && !_changingCenterFrequency && !_changingBandwidth)
                    {
                        var index = _trackingX - AxisMargin;
                        if (_useSnap)
                        {
                            // Todo: snap the index
                        }
                        if (index > 0 && index < _scaledSpectrum.Length)
                        {
                            graphics.DrawLine(redPen, _trackingX, 0, _trackingX, ClientRectangle.Height);
                        }
                    }
                    string fstring;
                    if (_changingFrequency)
                    {
                        fstring = "VFO = " + GetFrequencyDisplay(_frequency);
                    }
                    else if (_changingBandwidth)
                    {
                        fstring = "BW = " + GetFrequencyDisplay(_filterBandwidth);
                    }
                    else if (_changingCenterFrequency)
                    {
                        fstring = "Center Freq. = " + GetFrequencyDisplay(_centerFrequency);
                    }
                    else
                    {
                        fstring = string.Format("{0}\r\n{1:0.##}dB", GetFrequencyDisplay(_trackingFrequency), _trackingPower);
                    }

                    path.AddString(fstring, fontFamily, (int)FontStyle.Regular, TrackingFontSize, Point.Empty, StringFormat.GenericTypographic);
                    var stringSize = path.GetBounds();
                    var currentCursor = Cursor.Current;
                    var xOffset = _trackingX + 15.0f;
                    var yOffset = _trackingY + (currentCursor == null ? DefaultCursorHeight : currentCursor.Size.Height) - 8.0f;
                    xOffset = Math.Min(xOffset, ClientRectangle.Width - stringSize.Width - 5);
                    yOffset = Math.Min(yOffset, ClientRectangle.Height - stringSize.Height - 5);
                    path.Reset();
                    path.AddString(fstring, fontFamily, (int)FontStyle.Regular, TrackingFontSize, new Point((int)xOffset, (int)yOffset), StringFormat.GenericTypographic);
                    var smoothingMode = graphics.SmoothingMode;
                    var interpolationMode = graphics.InterpolationMode;
                    graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    outlinePen.Width = 2;
                    graphics.DrawPath(outlinePen, path);
                    graphics.FillPath(Brushes.White, path);
                    graphics.SmoothingMode = smoothingMode;
                    graphics.InterpolationMode = interpolationMode;
                }
            }
        }
        public static void RenderArcScaleLines(
                                                    this Graphics Graphics, Rectangle ClientRectangle, Point Center,
                                                    Int32 MinorTickOuterRadius, Int32 MinorTickInnerRadius, Int32 MinorTickWidth, Color MinorTickForeColor, Int32 MinorNumOfTicks,
                                                    Int32 IntermediateTickOuterRadius, Int32 IntermediateTickInnerRadius, Int32 IntermediateTickWidth, Color IntermediateTickForeColor,
                                                    Int32 MajorTickOuterRadius, Int32 MajorTickInnerRadius, Int32 MajorTickWidth, Color MajorTickForeColor, Single MajorStepValue,
                                                    Single MinimumValue, Single MaximumValue,
                                                    Int32 ArcStart, Int32 ArcSweep
            )
        {
            using (var graphicsPath = new GraphicsPath()) {
                var renderMajorScale = true;
                var renderIntermediateScale = true;
                var renderMinorScale = true;

                Graphics.SetClip(ClientRectangle);
                Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                Single countValue = 0;
                Int32 counter1 = 0;
                while (countValue <= (MaximumValue - MinimumValue)) {

                    graphicsPath.Reset();
                    if (renderMajorScale) {
                        graphicsPath.AddEllipse(new Rectangle(Center.X - MajorTickOuterRadius, Center.Y - MajorTickOuterRadius, 2 * MajorTickOuterRadius, 2 * MajorTickOuterRadius));
                        graphicsPath.Reverse();
                        graphicsPath.AddEllipse(new Rectangle(Center.X - MajorTickInnerRadius, Center.Y - MajorTickInnerRadius, 2 * MajorTickInnerRadius, 2 * MajorTickInnerRadius));
                        graphicsPath.Reverse();
                    }
                    Graphics.SetClip(graphicsPath);

                    using (var pen = new Pen(MajorTickForeColor, MajorTickWidth)) {
                        Graphics.DrawLine(
                                            pen,
                                            (Single)(Center.X),
                                            (Single)(Center.Y),
                                            (Single)(Center.X + 2 * MajorTickOuterRadius * Math.Cos((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue)) * Math.PI / 180.0)),
                                            (Single)(Center.Y + 2 * MajorTickOuterRadius * Math.Sin((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue)) * Math.PI / 180.0))
                                         );
                    }

                    graphicsPath.Reset();
                    if (renderMinorScale) {
                        graphicsPath.AddEllipse(new Rectangle(Center.X - MinorTickOuterRadius, Center.Y - MinorTickOuterRadius, 2 * MinorTickOuterRadius, 2 * MinorTickOuterRadius));
                        graphicsPath.Reverse();
                        graphicsPath.AddEllipse(new Rectangle(Center.X - MinorTickInnerRadius, Center.Y - MinorTickInnerRadius, 2 * MinorTickInnerRadius, 2 * MinorTickInnerRadius));
                        graphicsPath.Reverse();
                    }
                    Graphics.SetClip(graphicsPath);

                    if (countValue < (MaximumValue - MinimumValue)) {
                        for (var index = 1; index <= MinorNumOfTicks; index++) {
                            if (((MinorNumOfTicks % 2) == 1) && ((Int32)(MinorNumOfTicks / 2) + 1 == index)) {

                                graphicsPath.Reset();
                                if (renderIntermediateScale) {
                                    graphicsPath.AddEllipse(new Rectangle(Center.X - IntermediateTickOuterRadius, Center.Y - IntermediateTickOuterRadius, 2 * IntermediateTickOuterRadius, 2 * IntermediateTickOuterRadius));
                                    graphicsPath.Reverse();
                                    graphicsPath.AddEllipse(new Rectangle(Center.X - IntermediateTickInnerRadius, Center.Y - IntermediateTickInnerRadius, 2 * IntermediateTickInnerRadius, 2 * IntermediateTickInnerRadius));
                                    graphicsPath.Reverse();
                                }
                                Graphics.SetClip(graphicsPath);

                                using (var pen = new Pen(IntermediateTickForeColor, IntermediateTickWidth)) {
                                    Graphics.DrawLine(
                                                        pen,
                                                        (Single)(Center.X),
                                                        (Single)(Center.Y),
                                                        (Single)(Center.X + 2 * IntermediateTickOuterRadius * Math.Cos((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue) + index * ArcSweep / (((Single)((MaximumValue - MinimumValue) / MajorStepValue)) * (MinorNumOfTicks + 1))) * Math.PI / 180.0)),
                                                        (Single)(Center.Y + 2 * IntermediateTickOuterRadius * Math.Sin((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue) + index * ArcSweep / (((Single)((MaximumValue - MinimumValue) / MajorStepValue)) * (MinorNumOfTicks + 1))) * Math.PI / 180.0))
                                                      );
                                }

                                graphicsPath.Reset();
                                if (renderMinorScale) {
                                    graphicsPath.AddEllipse(new Rectangle(Center.X - MinorTickOuterRadius, Center.Y - MinorTickOuterRadius, 2 * MinorTickOuterRadius, 2 * MinorTickOuterRadius));
                                    graphicsPath.Reverse();
                                    graphicsPath.AddEllipse(new Rectangle(Center.X - MinorTickInnerRadius, Center.Y - MinorTickInnerRadius, 2 * MinorTickInnerRadius, 2 * MinorTickInnerRadius));
                                    graphicsPath.Reverse();
                                }
                                Graphics.SetClip(graphicsPath);

                            } else {
                                using (var pen = new Pen(MinorTickForeColor, MinorTickWidth)) {
                                    Graphics.DrawLine(
                                                        pen,
                                                        (Single)(Center.X),
                                                        (Single)(Center.Y),
                                                        (Single)(Center.X + 2 * MinorTickOuterRadius * Math.Cos((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue) + index * ArcSweep / (((Single)((MaximumValue - MinimumValue) / MajorStepValue)) * (MinorNumOfTicks + 1))) * Math.PI / 180.0)),
                                                        (Single)(Center.Y + 2 * MinorTickOuterRadius * Math.Sin((ArcStart + countValue * ArcSweep / (MaximumValue - MinimumValue) + index * ArcSweep / (((Single)((MaximumValue - MinimumValue) / MajorStepValue)) * (MinorNumOfTicks + 1))) * Math.PI / 180.0))
                                                     );
                                }
                            }
                        }
                    }

                    countValue += MajorStepValue;
                    counter1++;
                }
            }
            Graphics.ResetTransform();
        }
예제 #30
0
        public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
        {
            if (Hidden) return;
            base.Draw(g, worldRect, canvasRect);
            var pen = new Pen(LineColor ?? ForeColor, LineWidth);
            var brush = new SolidBrush(BackColor);
            var path = new GraphicsPath();
            var path2 = new GraphicsPath();
            pen.Alignment = PenAlignment.Center;
            if (LineDashStyle.HasValue)
                pen.DashStyle = LineDashStyle.Value;
            else
                pen.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), LineStyle.ToString());
            if (pen.DashStyle == DashStyle.Custom)
                pen.DashPattern = dashPattern;

            var markerPen = new Pen(ColorMarker);

            // измерить расстояние между маркерами в пикселях
            var markerSpanPointsView = MarkerSpanPoints;
            if (MinPixelsBetweenMarkers > 0)
            {
                for (var i = 0; i < 10; i++)
                {
                    var sizeUnit = Conversion.WorldToScreen(new SizeD(markerSpanPointsView, 0), worldRect, canvasRect);
                    if (sizeUnit.Width >= MinPixelsBetweenMarkers) break;
                    markerSpanPointsView *= markerSpanPointsMultiplier;
                }
            }

            using (pen)
            {
                using (brush)
                {
                    using (path)
                    {
                        using (path2)
                        {
                            using (markerPen)
                            {
                                PointF tf;
                                PointF tf2;
                                if (Data.BarCount > 0)
                                {
                                    tf =
                                        (PointF)
                                        Conversion.WorldToScreen(
                                            new PointD(Data.StartIndex,
                                                       Data[Data.StartIndex]), worldRect, canvasRect);

                                    path2.AddLine(tf.X, canvasRect.Bottom, tf.X, tf.Y);
                                }
                                // разлиновать
                                if (Data.StartIndex < Data.LastIndex && markerSpanPointsView > 0)
                                {
                                    for (var i = Data.StartIndex; i <= Data.LastIndex; i += markerSpanPointsView)
                                    {
                                        var pointTop = (PointF) Conversion.WorldToScreen(
                                                                    new PointD(
                                                                        i + ShiftX,
                                                                        0),
                                                                    worldRect, canvasRect);
                                        pointTop.Y = canvasRect.Top;
                                        var pointBottom = new PointF(pointTop.X, canvasRect.Bottom);
                                        g.DrawLine(markerPen, pointTop, pointBottom);
                                    }
                                }

                                // построить график
                                var startIndex = Math.Max(Data.StartIndex, (int)Chart.StockPane.WorldRect.Left);
                                var endIndex = Math.Min(Data.LastIndex, (int) Chart.StockPane.WorldRect.Right);

                                for (var i = startIndex + 1; i <= endIndex; i++)
                                {
                                    if (double.IsNaN(Data[i - 1]) || double.IsNaN(Data[i]))
                                    {
                                        g.DrawPath(pen, path);
                                        path.Reset();
                                        continue;
                                    }
                                    tf =
                                        (PointF)
                                        Conversion.WorldToScreen(
                                            new PointD((i - 1 - 1) + ShiftX,
                                                       Data[i - 1]),
                                            worldRect,
                                            canvasRect);
                                    tf2 =
                                        (PointF)
                                        Conversion.WorldToScreen(new PointD(i - 1 + ShiftX,
                                                                            Data[i]), worldRect, canvasRect);

                                    path2.AddLine(tf, tf2);
                                    path.AddLine(tf, tf2);
                                }
                                if (Data.BarCount > 0)
                                {
                                    if (Data[Data.LastIndex] != double.NaN)
                                    {
                                       tf2 =
                                            (PointF)
                                            Conversion.WorldToScreen(
                                                new PointD(Data.LastIndex,
                                                           Data[Data.LastIndex]), worldRect, canvasRect);
                                        path2.AddLine(tf2.X, tf2.Y, tf2.X, canvasRect.Bottom);
                                    }
                                }
                                try
                                {
                                    if (!Transparent)
                                        g.FillPath(brush, path2);
                                    if (DrawShadow)
                                        DrawShadowPath(path, g);
                                    g.DrawPath(pen, path);
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #31
0
파일: TempCtrl.cs 프로젝트: kaaLabs15/LoRa
 protected void FillCylinder(Graphics g, RectangleF ctrl, Brush fillBrush, Color outlineColor)
 {
     RectangleF rect1 = new RectangleF(ctrl.X, ctrl.Y - 5f, ctrl.Width, 5f);
     RectangleF rect2 = new RectangleF(ctrl.X, ctrl.Bottom - 5f, ctrl.Width, 5f);
     Pen pen = new Pen(outlineColor);
     GraphicsPath path = new GraphicsPath();
     path.AddArc(rect1, 0.0f, 180f);
     path.AddArc(rect2, 180f, -180f);
     path.CloseFigure();
     g.FillPath(fillBrush, path);
     g.DrawPath(pen, path);
     path.Reset();
     path.AddEllipse(rect1);
     g.FillPath(fillBrush, path);
     g.DrawPath(pen, path);
 }
예제 #32
0
        /// <summary>创建验证码图片</summary>
        /// <param name="verifyCodeImageInfo">验证码图片信息</param>
        public void CreateVerifyCodeImage(VerifyCodeImageInfo verifyCodeImageInfo)
        {
            int textLength = verifyCodeImageInfo.Text.Length;
            if(textLength == 0 || verifyCodeImageInfo.ImageWidth == 0 || verifyCodeImageInfo.ImageHeight == 0) return;

            using(Bitmap img = new Bitmap(verifyCodeImageInfo.ImageWidth, verifyCodeImageInfo.ImageHeight, PixelFormat.Format32bppArgb))
            {
                using(GraphicsPath p = new GraphicsPath())
                {
                    using(Graphics g = Graphics.FromImage(img))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.Clear(verifyCodeImageInfo.BackgroundColor);

                        int charSize = (int)(Math.Min(verifyCodeImageInfo.ImageHeight, (int)(verifyCodeImageInfo.ImageWidth / textLength)) * 0.8);
                        PointF charPoint = new PointF();
                        int halfCharSize = (int)(charSize * 0.5f);
                        int paddingHeight = (int)(verifyCodeImageInfo.ImageHeight * 0.8) - charSize;

                        using(Matrix matrix = new Matrix())
                        {
                            using(Pen pen = new Pen(Color.Empty))
                            {
                                using(StringFormat format = new StringFormat())
                                {
                                    format.Alignment = StringAlignment.Near;
                                    format.LineAlignment = StringAlignment.Near;
                                    FontFamily f;
                                    for(int i = 0; i < textLength; i++)
                                    {
                                        charPoint.X = (float)(i * charSize + Utils.Rand((int)(charSize * 0.2f), (int)(charSize * 0.8f)));
                                        charPoint.Y = (float)Utils.Rand(2, paddingHeight);

                                        p.Reset();
                                        float fs = charSize * Utils.Rand(80, 120) * 0.01f;
                                        f = GetFontFamily(verifyCodeImageInfo.Fonts);
                                        p.AddString(verifyCodeImageInfo.Text[i].ToString(), f, 0, fs, new Point(0, 0), format);

                                        matrix.Reset();
                                        matrix.RotateAt((float)Utils.Rand(-60, 60), new PointF(charPoint.X + halfCharSize, charPoint.Y + halfCharSize));
                                        matrix.Translate(charPoint.X, charPoint.Y);
                                        p.Transform(matrix);

                                        pen.Color = GetTextColor(verifyCodeImageInfo.RandomTextColor, verifyCodeImageInfo.TextColor);
                                        pen.Width = Utils.Rand(1, 2);
                                        g.DrawPath(pen, p);
                                        g.DrawBezier(pen,
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                            Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                            Utils.Rand(verifyCodeImageInfo.ImageHeight));
                                    }
                                }
                                pen.Color = GetTextColor(verifyCodeImageInfo.RandomTextColor, verifyCodeImageInfo.TextColor);
                                pen.Width = Utils.Rand(1, 2);
                                g.DrawBezier(pen,
                                    Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                    0,
                                    Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                    Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                    Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                    Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                    Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                    verifyCodeImageInfo.ImageHeight);
                                pen.Width = Utils.Rand(1, 2);
                                pen.Color = GetTextColor(verifyCodeImageInfo.RandomTextColor, verifyCodeImageInfo.TextColor);
                                g.DrawBezier(pen,
                                    0,
                                    Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                    Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                    Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                    Utils.Rand(verifyCodeImageInfo.ImageWidth),
                                    Utils.Rand(verifyCodeImageInfo.ImageHeight),
                                    verifyCodeImageInfo.ImageWidth,
                                    Utils.Rand(verifyCodeImageInfo.ImageHeight));
                            }
                        }
                    }
                }
                verifyCodeImageInfo.ImageData = img.Clone() as Image;
            }
        }
예제 #33
0
        //---------------------------------------------------------------------------
        private void DrawBitmap(bool justClip = false)
        {
            if (!justClip)
            {
                if (rbTest2.Checked)
                    GenerateAustPlusRandomEllipses((int)nudCount.Value);
                else
                    GenerateRandomPolygon((int)nudCount.Value);
            }

            Cursor.Current = Cursors.WaitCursor;
            Graphics newgraphic;
            newgraphic = Graphics.FromImage(mybitmap);
            newgraphic.SmoothingMode = SmoothingMode.AntiAlias;
            newgraphic.Clear(Color.White);

            GraphicsPath path = new GraphicsPath();
            if (rbNonZero.Checked) path.FillMode = FillMode.Winding;

            //draw subjects ...
            foreach (Polygon pg in subjects)
            {
                PointF[] pts = PolygonToPointFArray(pg, scale);
                path.AddPolygon(pts);
                pts = null;
            }
            Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
            SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));
            newgraphic.FillPath(myBrush, path);
            newgraphic.DrawPath(myPen, path);
            path.Reset();

            //draw clips ...
            if (rbNonZero.Checked) path.FillMode = FillMode.Winding;
            foreach (Polygon pg in clips)
            {
                PointF[] pts = PolygonToPointFArray(pg, scale);
                path.AddPolygon(pts);
                pts = null;
            }
            myPen.Color = Color.FromArgb(196, 0xF9, 0xBE, 0xA6);
            myBrush.Color = Color.FromArgb(127, 0xFF, 0xE0, 0xE0);
            newgraphic.FillPath(myBrush, path);
            newgraphic.DrawPath(myPen, path);

            //do the clipping ...
            if ((clips.Count > 0 || subjects.Count > 0) && !rbNone.Checked)
            {
                Polygons solution2 = new Polygons();
                Clipper c = new Clipper();
                c.AddPolygons(subjects, PolyType.ptSubject);
                c.AddPolygons(clips, PolyType.ptClip);
                exSolution.Clear();
                solution.Clear();
                bool succeeded = c.Execute(GetClipType(), solution, GetPolyFillType(), GetPolyFillType());
                if (succeeded)
                {
                    myBrush.Color = Color.Black;
                    path.Reset();

                    //It really shouldn't matter what FillMode is used for solution
                    //polygons because none of the solution polygons overlap.
                    //However, FillMode.Winding will show any orientation errors where
                    //holes will be stroked (outlined) correctly but filled incorrectly  ...
                    path.FillMode = FillMode.Winding;

                    //or for something fancy ...
                    if (nudOffset.Value != 0)
                        solution2 = Clipper.OffsetPolygons(solution, (double)nudOffset.Value * scale, JoinType.jtMiter);
                    else
                        solution2 = new Polygons(solution);
                    foreach (Polygon pg in solution2)
                    {
                        PointF[] pts = PolygonToPointFArray(pg, scale);
                        if (pts.Count() > 2)
                            path.AddPolygon(pts);
                        pts = null;
                    }
                    myBrush.Color = Color.FromArgb(127, 0x66, 0xEF, 0x7F);
                    myPen.Color = Color.FromArgb(255, 0, 0x33, 0);
                    myPen.Width = 1.0f;
                    newgraphic.FillPath(myBrush, path);
                    newgraphic.DrawPath(myPen, path);

                    //now do some fancy testing ...
                    Font f = new Font("Arial", 8);
                    SolidBrush b = new SolidBrush(Color.Navy);
                    double subj_area = 0, clip_area = 0, int_area = 0, union_area = 0;
                    c.Clear();
                    c.AddPolygons(subjects, PolyType.ptSubject);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2) subj_area += Clipper.Area(pg);
                    c.Clear();
                    c.AddPolygons(clips, PolyType.ptClip);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2) clip_area += Clipper.Area(pg);
                    c.AddPolygons(subjects, PolyType.ptSubject);
                    c.Execute(ClipType.ctIntersection, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2) int_area += Clipper.Area(pg);
                    c.Execute(ClipType.ctUnion, solution2, GetPolyFillType(), GetPolyFillType());
                    foreach (Polygon pg in solution2) union_area += Clipper.Area(pg);

                    StringFormat lftStringFormat = new StringFormat();
                    lftStringFormat.Alignment = StringAlignment.Near;
                    lftStringFormat.LineAlignment = StringAlignment.Near;
                    StringFormat rtStringFormat = new StringFormat();
                    rtStringFormat.Alignment = StringAlignment.Far;
                    rtStringFormat.LineAlignment = StringAlignment.Near;
                    Rectangle rec = new Rectangle(pictureBox1.ClientSize.Width - 108,
                        pictureBox1.ClientSize.Height - 116, 104, 106);
                    newgraphic.FillRectangle(new SolidBrush(Color.FromArgb(196, Color.WhiteSmoke)), rec);
                    newgraphic.DrawRectangle(myPen, rec);
                    rec.Inflate(new Size(-2, 0));
                    newgraphic.DrawString("Areas", f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 14));
                    newgraphic.DrawString("subj: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((subj_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 12));
                    newgraphic.DrawString("clip: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((clip_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 12));
                    newgraphic.DrawString("intersect: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((int_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 12));
                    newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("s + c - i: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString(((subj_area + clip_area - int_area) / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("union: ", f, b, rec, lftStringFormat);
                    newgraphic.DrawString((union_area / 100000).ToString("0,0"), f, b, rec, rtStringFormat);
                    rec.Offset(new Point(0, 10));
                    newgraphic.DrawString("---------", f, b, rec, rtStringFormat);
                } //end if succeeded
            } //end if something to clip

            pictureBox1.Image = mybitmap;
            newgraphic.Dispose();
            Cursor.Current = Cursors.Default;
        }
예제 #34
0
        private System.Drawing.Drawing2D.GraphicsPath GetPath(int index)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.Reset();

            Rectangle rect = this.GetTabRect(index);

            if (index == 0)
            {
                path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + rect.Height, rect.Top + 2);
                path.AddLine(rect.Left + rect.Height + 4, rect.Top, rect.Right - 3, rect.Top);
                path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
            }
            else
            {
                if (index == this.SelectedIndex)
                {
                    path.AddLine(rect.Left + 5 - rect.Height, rect.Bottom + 1, rect.Left + 4, rect.Top + 2);
                    path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
                    path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
                    path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left + 5 - rect.Height, rect.Bottom + 1);
                }
                else
                {
                    path.AddLine(rect.Left, rect.Top + 6, rect.Left + 4, rect.Top + 2);
                    path.AddLine(rect.Left + 8, rect.Top, rect.Right - 3, rect.Top);
                    path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Bottom + 1);
                    path.AddLine(rect.Right - 1, rect.Bottom + 1, rect.Left, rect.Bottom + 1);
                }
            }
            return path;
        }
예제 #35
0
        private void paint(TreeMapNode n, Graphics g, int level)
        {
            if (n.IsLeaf)
            {
                RectangleF rect = new RectangleF((float)n.getX(), (float)n.getY(), (float)n.getWidth(), (float)n.getHeight());
                if (rect.Width > 0 && rect.Height > 0)
                {
                    gp.Reset();
                    gp.AddEllipse(rect.Left - rect.Width / 4, rect.Top - rect.Height / 4, rect.Width + 2 * rect.Width / 4,
                                  rect.Height + 2 * rect.Height / 4);
                    PathGradientBrush pgb = new PathGradientBrush(gp);
                    pgb.CenterColor = Color.White;
                    string ext = Path.GetExtension(n.getLabel()).TrimStart('.');
                    if (extensions.ContainsKey(ext.ToLower()))
                    {
                        pgb.SurroundColors = new Color[] { (Color)extensions[ext.ToLower()] };
                    }
                    else
                    {
                        Color c = Color.FromKnownColor((KnownColor)((int)KnownColor.ForestGreen + extensions.Count));
                        extensions[ext.ToLower()] = c;
                        pgb.SurroundColors        = new Color[] { c };
                    }
                    pgb.CenterPoint = new PointF(rect.Left + rect.Width / 4, rect.Top + rect.Height / 2);

                    g.FillRectangle(pgb, rect);
                    pgb.Dispose();

                    string label     = Path.GetFileName(n.getLabel());
                    SizeF  labelSize = g.MeasureString(label, f, (int)rect.Width);

                    if (rect.Width > 1 && rect.Height > 1 && File.Exists(n.getLabel()))
                    {
                        if (n.Icon == null)
                        {
                            n.Icon = Icon.ExtractAssociatedIcon(n.getLabel());
                        }
                        if (rect.Width >= n.Icon.Width && rect.Height >= n.Icon.Height + labelSize.Height)
                        {
                            Rectangle iconRect = new Rectangle((int)rect.Left + (int)rect.Width / 2 - n.Icon.Width / 2,
                                                               (int)rect.Top + (int)rect.Height / 2 - n.Icon.Height / 2 - (int)labelSize.Height / 2, n.Icon.Width, n.Icon.Height);
                            if (clipBoard == n && cutClipboard)
                            {
                                ImageAttributes ia = new ImageAttributes();
                                ia.SetGamma(0.3F);
                                g.DrawImage(n.Icon.ToBitmap(), iconRect, 0, 0, n.Icon.Width, n.Icon.Height, GraphicsUnit.Pixel, ia);
                            }
                            else
                            {
                                g.DrawIconUnstretched(n.Icon, iconRect);
                            }
                            Region clip = g.Clip;
                            g.Clip = new Region(rect);
                            g.DrawString(label, f, Brushes.Black, new RectangleF(rect.Left + rect.Width / 2 - labelSize.Width / 2,
                                                                                 rect.Top + rect.Height / 2 - labelSize.Height / 2 + iconRect.Height / 2, labelSize.Width, labelSize.Height));
                            g.Clip = clip;
                        }
                        else
                        {
                            double ratio = Math.Min(rect.Width / n.Icon.Width, rect.Height / n.Icon.Height);
                            if (clipBoard == n && cutClipboard)
                            {
                                ImageAttributes ia = new ImageAttributes();
                                ia.SetGamma(0.3F);
                                g.DrawImage(n.Icon.ToBitmap(), new Rectangle((int)Math.Round(rect.Left + rect.Width / 2 - n.Icon.Width * ratio / 2),
                                                                             (int)Math.Round(rect.Top + rect.Height / 2 - n.Icon.Height * ratio / 2),
                                                                             (int)Math.Round(n.Icon.Width * ratio), (int)Math.Round(n.Icon.Height * ratio)), 0, 0, n.Icon.Width, n.Icon.Height,
                                            GraphicsUnit.Pixel, ia);
                            }
                            else
                            {
                                g.DrawIcon(n.Icon, new Rectangle((int)Math.Round(rect.Left + rect.Width / 2 - n.Icon.Width * ratio / 2),
                                                                 (int)Math.Round(rect.Top + rect.Height / 2 - n.Icon.Height * ratio / 2),
                                                                 (int)Math.Round(n.Icon.Width * ratio), (int)Math.Round(n.Icon.Height * ratio)));
                            }
                        }
                    }
                }
            }
            else if (level > 1)
            {
                RectangleF rect = new RectangleF((float)n.getX(), (float)n.getY(), (float)n.getWidth(), (float)n.getHeight());
                if (rect.Width > 0 && rect.Height > 0)
                {
                    gp.Reset();
                    gp.AddEllipse(rect.Left - rect.Width / 4, rect.Top - rect.Height / 4, rect.Width + 2 * rect.Width / 4,
                                  rect.Height + 2 * rect.Height / 4);
                    PathGradientBrush pgb = new PathGradientBrush(gp);
                    pgb.CenterColor    = Color.White;
                    pgb.SurroundColors = new Color[] { Color.YellowGreen };
                    pgb.CenterPoint    = new PointF(rect.Left + rect.Width / 4, rect.Top + rect.Height / 2);

                    g.FillRectangle(pgb, rect);
                    pgb.Dispose();

                    string label     = Path.GetFileName(n.getLabel());
                    SizeF  labelSize = g.MeasureString(label, f);
                    Region clip      = g.Clip;
                    g.Clip = new Region(rect);
                    g.DrawString(label, f, Brushes.Black, new RectangleF(rect.Left + rect.Width / 2 - labelSize.Width / 2,
                                                                         rect.Top + rect.Height / 2 - labelSize.Height / 2, labelSize.Width, labelSize.Height));
                    g.Clip = clip;
                }
            }
            if (depthLevel == 0 || level < depthLevel)
            {
                foreach (TreeMapNode child in n.Nodes)
                {
                    paint(child, g, level + 1);
                }
            }
        }
예제 #36
0
        //---------------------------------------------------------------------
        private void GenerateAustPlusRandomEllipses(int count)
        {
            subjects.Clear();
            //load map of Australia from resource ...
            _assembly = Assembly.GetExecutingAssembly();
            polyStream = _assembly.GetManifestResourceStream("GuiDemo.aust.bin");
            int len = (int)polyStream.Length;
            byte[] b = new byte[len];
            polyStream.Read(b, 0, len);
            int polyCnt = BitConverter.ToInt32(b, 0);
            int k = 4;
            for (int i = 0; i < polyCnt; ++i)
            {
                int vertCnt = BitConverter.ToInt32(b, k);
                k += 4;
                Polygon pg = new Polygon(vertCnt);
                for (int j = 0; j < vertCnt; ++j)
                {
                    float x = BitConverter.ToSingle(b, k) * scale;
                    float y = BitConverter.ToSingle(b, k + 4) * scale;
                    k += 8;
                    pg.Add(new IntPoint((int)x, (int)y));
                }
                subjects.Add(pg);
            }

            clips.Clear();
            Random rand = new Random();
            GraphicsPath path = new GraphicsPath();
            Point pt = new Point();

            const int ellipse_size = 100, margin = 10;
            for (int i = 0; i < count; ++i)
            {
                int w = pictureBox1.ClientRectangle.Width - ellipse_size - margin *2;
                int h = pictureBox1.ClientRectangle.Height - ellipse_size - margin * 2 - statusStrip1.Height;

                pt.X = rand.Next(w) + margin;
                pt.Y = rand.Next(h) + margin;
                int size = rand.Next(ellipse_size - 20) + 20;
                path.Reset();
                path.AddEllipse(pt.X, pt.Y, size, size);
                path.Flatten();
                Polygon clip = new Polygon(path.PathPoints.Count());
                foreach (PointF p in path.PathPoints)
                    clip.Add(new IntPoint((int)(p.X * scale), (int)(p.Y * scale)));
                clips.Add(clip);
            }
        }
예제 #37
0
        private void DrawCursor()
        {
            _lower = 0f;
            float bandpassOffset;
            var bandpassWidth = 0f;
            var cursorWidth = Math.Max((_filterBandwidth + _filterOffset) * _xIncrement, 2);
            var xCarrier = (float) ClientRectangle.Width / 2 + (_frequency - _displayCenterFrequency) * _xIncrement;

            switch (_bandType)
            {
                case BandType.Upper:
                    bandpassOffset = _filterOffset * _xIncrement;
                    bandpassWidth = cursorWidth - bandpassOffset;
                    _lower = xCarrier + bandpassOffset;
                    break;

                case BandType.Lower:
                    bandpassOffset = _filterOffset * _xIncrement;
                    bandpassWidth = cursorWidth - bandpassOffset;
                    _lower = xCarrier - bandpassOffset - bandpassWidth;
                    break;

                case BandType.Center:
                    _lower = xCarrier - cursorWidth / 2;
                    bandpassWidth = cursorWidth;
                    break;
            }
            _upper = _lower + bandpassWidth;

            using (var transparentBrush = new SolidBrush(Color.FromArgb(80, Color.DarkGray)))
            using (var hotTrackPen = new Pen(Color.Red))
            using (var carrierPen = new Pen(Color.Red))
            using (var fontFamily = new FontFamily("Arial"))
            using (var path = new GraphicsPath())
            using (var outlinePen = new Pen(Color.Black))
            {
                carrierPen.Width = CarrierPenWidth;
                if (cursorWidth < ClientRectangle.Width)
                {
                    _graphics2.FillRectangle(transparentBrush, (int) _lower + 1, 0, (int) bandpassWidth, ClientRectangle.Height);
                    if (xCarrier >= AxisMargin && xCarrier <= ClientRectangle.Width - AxisMargin)
                    {
                        _graphics2.DrawLine(carrierPen, xCarrier, 0, xCarrier, ClientRectangle.Height);
                    }
                }
                if (_trackingX >= AxisMargin && _trackingX <= ClientRectangle.Width - AxisMargin)
                {
                    if (!_changingFrequency && !_changingCenterFrequency && !_changingBandwidth)
                    {
                        _graphics2.DrawLine(hotTrackPen, _trackingX, 0, _trackingX, ClientRectangle.Height);
                    }

                    string fstring;
                    if (_changingFrequency)
                    {
                        fstring = "VFO = " + SpectrumAnalyzer.GetFrequencyDisplay(_frequency);
                    }
                    else if (_changingBandwidth)
                    {
                        fstring = "BW = " + SpectrumAnalyzer.GetFrequencyDisplay(_filterBandwidth);
                    }
                    else if (_changingCenterFrequency)
                    {
                        fstring = "Center Freq. = " + SpectrumAnalyzer.GetFrequencyDisplay(_centerFrequency);
                    }
                    else
                    {
                        fstring = SpectrumAnalyzer.GetFrequencyDisplay(_trackingFrequency);
                    }

                    path.AddString(fstring, fontFamily, (int) FontStyle.Regular, TrackingFontSize, Point.Empty, StringFormat.GenericTypographic);
                    var stringSize = path.GetBounds();
                    var currentCursor = Cursor.Current;
                    var xOffset = _trackingX + 15.0f;
                    var yOffset = _trackingY + (currentCursor == null ? SpectrumAnalyzer.DefaultCursorHeight : currentCursor.Size.Height) - 8.0f;
                    xOffset = Math.Min(xOffset, ClientRectangle.Width - stringSize.Width - 5);
                    yOffset = Math.Min(yOffset, ClientRectangle.Height - stringSize.Height - 5);
                    path.Reset();
                    path.AddString(fstring, fontFamily, (int) FontStyle.Regular, TrackingFontSize, new Point((int) xOffset, (int) yOffset), StringFormat.GenericTypographic);
                    var smoothingMode = _graphics2.SmoothingMode;
                    var interpolationMode = _graphics2.InterpolationMode;
                    _graphics2.SmoothingMode = SmoothingMode.AntiAlias;
                    _graphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    outlinePen.Width = 2;
                    _graphics2.DrawPath(outlinePen, path);
                    _graphics2.FillPath(Brushes.White, path);
                    _graphics2.SmoothingMode = smoothingMode;
                    _graphics2.InterpolationMode = interpolationMode;
                }
            }
        }