public AddPie ( Rectangle rect, float startAngle, float sweepAngle ) : void | ||
rect | Rectangle | |
startAngle | float | |
sweepAngle | float | |
return | void |
public override GraphicsPath getGraphicsPathNoOffsetRoute() { GraphicsPath path = new GraphicsPath(); RectangleF rect = getRect(); try { path.AddPie(rect.X, rect.Y, rect.Width, rect.Height, StartAngle, EndAngle); } catch (Exception ex) { rect.X = _X + _XAdd; rect.Y = _Y + _YAdd; rect.Width = 10; rect.Height = 10; path.AddPie(rect.X, rect.Y, rect.Width, rect.Height, StartAngle, EndAngle); ////ClsErrorFile.WriteLine("这里是一个扇形出现参数错误,异常处理是构造一个默认宽和高都是10,角度为0和90的扇形", ex); //throw; //throw; } return path; //return base.getGraphicsPath(); }
private void CalculateSegments() { Rectangle rctFull = new Rectangle(0, 0, this.Width, this.Height); Rectangle rctInner = new Rectangle(((this.Width * 7) / 30), ((this.Height * 7) / 30), (this.Width - ((this.Width * 14) / 30)), (this.Height - ((this.Height * 14) / 30))); System.Drawing.Drawing2D.GraphicsPath pthInnerBackground = null; // Create 12 segment pieces for (int intCount = 0; intCount < 12; intCount++) { segmentPaths[intCount] = new System.Drawing.Drawing2D.GraphicsPath(); // We subtract 90 so that the starting segment is at 12 o'clock segmentPaths[intCount].AddPie(rctFull, (intCount * 30) - 90, 25); } // Create the center circle cut-out pthInnerBackground = new System.Drawing.Drawing2D.GraphicsPath(); pthInnerBackground.AddPie(rctInner, 0, 360); innerBackgroundRegion = new Region(pthInnerBackground); //graph.FillRegion(new SolidBrush(BackColor), innerBackgroundRegion); }
protected override void UpdatePath() { InternalPath = new GraphicsPath(); InternalPath.AddPie(this.Left, this.Top, this.Width, this.Height, this.StartAngle, this.SweepAngle); Matrix mtx = new Matrix(); mtx.RotateAt(this.Rotation, InternalRotationBasePoint); InternalPath.Transform(mtx); }
public new bool ContainsPoint(float X, float Y) { GraphicsPath Path = new GraphicsPath(); Path.StartFigure(); if (TypeShape == Nows.Ellip) Path.AddEllipse(Rectan); else Path.AddPie(Rectan.X, Rectan.Y, Rectan.Width, Rectan.Height, startAngle, sweepAngle); Path.CloseFigure(); return Path.IsVisible(X, Y); }
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); } } } }
private void timer1_Tick(object sender, EventArgs e) { if (fi > 180 || fi < 10) dir *= -1; fi += dir * 2; drawDiv(); GraphicsPath path = new GraphicsPath(); path.AddPie((WIDTH - (MAXDIV)) / 2, BASELINE - (((MAXDIV)) / 2), (MAXDIV), (MAXDIV), -fi, 10); PathGradientBrush brush = new PathGradientBrush(path); brush.CenterPoint = new PointF(WIDTH-(WIDTH / 2 - (int)(Math.Cos(Deg2Rad((dir>0)?fi:fi-10)) * (MAXDIV / 2))), BASELINE - (int)(Math.Sin(Deg2Rad((dir>0)?fi:fi-10)) * (MAXDIV / 2))); brush.SurroundColors = new Color[] { Color.FromArgb(0, 0, 255, 0) }; brush.CenterColor = Color.FromArgb(255, 0, 255, 0); radarGraphic.FillPath(brush, path); radarGraphic.FillRectangle(Brushes.Black, 0, BASELINE, WIDTH, HEIGHT - BASELINE); radarScreen.Invalidate(); path.Dispose(); brush.Dispose(); }
protected override void OnResize(EventArgs e) { base.OnResize(e); GraphicsPath path = new GraphicsPath(); path.AddEllipse(this.ClientRectangle); // ��ä�� ��� #if PIE path.AddPie(this.ClientRectangle, 0, 90); #endif // �ﰢ�� ��� #if Triple Point[] point = new Point[3]; point[0].X = this.ClientRectangle.Right - this.ClientRectangle.Width / 2; point[0].Y = this.ClientRectangle.Top; point[1].X = this.ClientRectangle.Left; point[1].Y = this.ClientRectangle.Bottom; point[2].X = this.ClientRectangle.Right; point[2].Y = this.ClientRectangle.Bottom; path.AddPolygon(point); #endif this.Region = new Region(path); }
public void Flatten_Pie () { GraphicsPath path = new GraphicsPath (); path.AddPie (0, 0, 100, 100, 30, 30); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); CompareFlats (path, clone); }
public void GetBounds_NullNull_Pie () { GraphicsPath gp = new GraphicsPath (); gp.AddPie (10, 10, 100, 100, 30, 45); CheckPieBounds (gp.GetBounds (null, null)); gp.Dispose (); }
public void GetBounds_MatrixEmpty_Pie () { GraphicsPath gp = new GraphicsPath (); gp.AddPie (10, 10, 100, 100, 30, 45); CheckPieBounds (gp.GetBounds (new Matrix ())); gp.Dispose (); }
private void DrawChart(ref Graphics g, Theme _Theme, Matrix mTransMatrix, RectangleF CurExt, bool bSearch, float PtX, float PtY, ref string LayerId, ref string AreaId, ref GraphicsPath gPath) { #region "-- local Variables --" int i; Brush[] BrIS = new Brush[(_Theme.IndicatorColor.Length * _Theme.SubgroupFillStyle.Length)]; StringFormat _StringFormat = new StringFormat(); _StringFormat.Alignment = StringAlignment.Center; _StringFormat.LineAlignment = StringAlignment.Center; _StringFormat.FormatFlags = StringFormatFlags.NoClip; for (i = 0; i <= _Theme.SubgroupFillStyle.Length - 1; i++) { BrIS[i] = new SolidBrush(Color.FromArgb(int.Parse(_Theme.SubgroupFillStyle[i]))); } int VisibleTimePeriods = 0; int SpCnt = 0; // ChartSeriesNames (Subgroup / Source) visible count. int TotalBarColumns = 0; // Totol Bar columns to draw for ONE Area int BarCtr = 0; int TimeVisibleCtr = 0; // TimePeriod Counter for visible TimePeriods. int LineCtr = 0; float ColumnGap = 0; // Distance between Column Charts of two consecutive TimePeriods double UnitWidth; decimal MaxData = _Theme.Maximum; float MapTop = m_FullExtent.Top; Font TextFont = null; // maximum limit for Text Size of chart data value. Brush ChartDataLabelBrush = null; Font ChartAxisLabelFont = null; Brush ChartAxisLabelBrush = null; float TextFontSize = 6.2F; // Text size for Chart data value. decimal DataValue = 0; PointF Pt = new PointF(); PointF[] Pts = new PointF[] { Pt }; PointF[] PtData = new PointF[1]; PointF[] LeaderPts = new PointF[2]; Pen PnLeader = new Pen(_Theme.ChartLeaderColor, _Theme.ChartLeaderWidth); PointF Centroid = new PointF(0, 0); GraphicsPath gpShp = new GraphicsPath(); AreaInfo _AreaInfo; string[] DataArr; Hashtable ChartData = null; // Collection of TimePeriod wise delimited DataValue for multiple Subgroup/Source string ChartMRD = string.Empty; bool DataFoundForTimePeriod = false; //-- Pie variables float StartAngle = 0; // Start angle for first Pie section , starting from 0 degree in clockwise direction float PieAngle = 0; float PieDiameter = 0; float PieMinDiameter = 0; float PieMaxDiameter = 0; decimal DataValueSum = 0; // sum RectangleF ChartExtent = new RectangleF(); // Applicable for Pie & Line Chart // Line variables PointF LineStartPoint = new PointF(); PointF LineEndPoint = new PointF(); PointF[] LinePoints = new PointF[2]; object[] LineSubgroupPoints = null; // Line points for visible Subgroup for any TimePeriod float LineChartYAxisLenght = 0F; float LineThickness = (float)_Theme.ChartLineThickness; bool AxisDrawn = false; // indicates whether X, Y Axis are drawn one time. PointF AxisPoint1 = new PointF(); PointF AxisPoint2 = new PointF(); PointF[] AxisPoints = new PointF[2]; decimal LineMaxDataValue = 0; PnLeader.DashStyle = _Theme.ChartLeaderStyle; #endregion //-- visible series - Subgroups / Sources string[] ChartVisibleSeries; if (_Theme.ChartSeriestype == ChartSeriesType.Subgroup) { ChartVisibleSeries = _Theme.SubgroupVisible; } else { ChartVisibleSeries = _Theme.SourceVisible; } //- Count Visible Series (either Subgroup Or Sources) for (i = 0; i <= ChartVisibleSeries.Length - 1; i++) { if (ChartVisibleSeries[i] == "1") SpCnt += 1; } //-- Set TextFont Size on the basis of Map's Current Extent if (CurExt.Width < 40 && CurExt.Width >= 25) { TextFontSize = 7; } else if (CurExt.Width < 25) { TextFontSize = 8; } //TextFont = new Font(_Theme.LabelFont.Name, TextFontSize); //-- Set Font used to render Data Value & Chart Axis Labels CustomLabelSetting labelSetting = _Theme.ChartDataLabelSettings; if (labelSetting == null) { labelSetting = new CustomLabelSetting(); } TextFont = labelSetting.LabelFont; ChartDataLabelBrush = new SolidBrush(labelSetting.LabelColor); labelSetting = _Theme.ChartAxisLabelSettings; if (labelSetting == null) { labelSetting = new CustomLabelSetting(); } ChartAxisLabelFont = labelSetting.LabelFont; ChartAxisLabelBrush = new SolidBrush(labelSetting.LabelColor); //*** Bugfix / Enhancement 02 May 2006 Controling chart width //*** Bugfix / Enhancement 15 Jun 2006 Controling chart width //*** Set the unit width to 1/20th of the Screen width. //*** If there are multiple subgroup that should be accomodated then they should be accomodated within unit width //*** Set Width of Bars based on FullExtentWidth(/) + Subgroup Count(\) + Chart Size(/) UnitWidth = ((m_FullExtent.Width) / (SpCnt * 20)) * Math.Pow(1.5, _Theme.ChartWidth - 10); //UnitWidth = ((m_FullExtent.Width) / (50)) + ((float)_Theme.ChartWidth / 20); //Exponential Rise (_Theme.ChartWidth / 10) ' //UnitWidth = (1 / SpCnt) * (_Theme.ChartWidth / 10) '*** Set Width of Bars based on FullExtentWidth(/) + Subgroup Count(\) + Chart Size(/) ColumnGap = (float)((UnitWidth * 0.5) * (_Theme.ColumnsGap)); Theme _ATheme = m_Themes.GetActiveTheme(); bool bLayerVisibility; Shape _Shape; //Polygon : Polyline : Point if (SpCnt > 0) { // and calculate the PieDiameter (Max & Min) on the basis of Map FullExtent. // Maximum PieDiameter is kept at 1/5 th of FullExtent. if (_Theme.ChartType != ChartType.Column) { if ((PieMaxDiameter < m_FullExtent.Height / 5F) || (PieMaxDiameter < m_FullExtent.Width / 5F)) { //- max if (m_FullExtent.Height > m_FullExtent.Width) { PieMaxDiameter = (m_FullExtent.Width) / 5F; } else { PieMaxDiameter = (m_FullExtent.Height) / 5F; } //- Validate Maximum Piediameter shoukd be > 3F if (PieMaxDiameter < 3F) { PieMaxDiameter = 3F; } //- Mimimum PieDiameter is Kept 1/3rd of Maximim. PieMinDiameter = PieMaxDiameter * 0.3F; } //-- Maximum Diameter must be less than Total Extent / 5 if ((PieMaxDiameter > CurExt.Width / 4)) { PieMaxDiameter = CurExt.Width / 4; //- Mimimum PieDiameter is Kept 1/3rd of Maximim. PieMinDiameter = PieMaxDiameter * 0.3F; } } //*** If all subgroup are unchecked then no need of rendering foreach (Layer Lyr in Layers) { //--Reset Chart variables StartAngle = 0; PieAngle = 0; DataValueSum = 0; AxisDrawn = false; VisibleTimePeriods = 0; //Traverse Layers collection if ((_ATheme == null)) { bLayerVisibility = Lyr.Visible; } else { if (_ATheme.LayerVisibility[Lyr.ID] == null) { bLayerVisibility = false; } else { bLayerVisibility = (bool)_ATheme.LayerVisibility[Lyr.ID]; } } if (Lyr.LayerType == ShapeType.Polygon & bLayerVisibility == true & Lyr.Extent.IntersectsWith(CurExt)) { // Render layer only if it lies within current map extent Hashtable ht = Lyr.GetRecords(Lyr.LayerPath + "\\" + Lyr.ID); IDictionaryEnumerator dicEnumerator = ht.GetEnumerator(); while (dicEnumerator.MoveNext()) { //Traverse Shapes _Shape = (Shape)dicEnumerator.Value; //--Check AreaID exists in AreaIndexes. AND AreaID should NOT be excluded explicitly. if (_Theme.AreaIndexes.ContainsKey(_Shape.AreaId) && _Theme.ExcludeAreaIDs.Contains(_Shape.AreaId) == false) { _AreaInfo = (AreaInfo)_Theme.AreaIndexes[_Shape.AreaId]; //-- get ChartData and ChartMRDData. ChartData = _AreaInfo.ChartData; ChartMRD = _AreaInfo.ChartMostRecentData; //*** Get Shape Centroid if (_Theme.ModifiedCharts.ContainsKey(Lyr.ID + "_" + _Shape.AreaId)) { //*** Get Modified Centroid for Nudged Chart Centroid = (PointF)_Theme.ModifiedCharts[Lyr.ID + "_" + _Shape.AreaId]; //*** Draw Leader Line for Nudged Chart if atleast one subgroup bar is visible if (SpCnt > 0 & _Theme.ChartLeaderVisible == true) { LeaderPts[0] = Centroid; if (Lyr.LayerType == ShapeType.Polygon) { LeaderPts[1] = _Shape.Centroid; } else if (Lyr.LayerType == ShapeType.Point) { LeaderPts[1] = (PointF)_Shape.Parts[0]; } mTransMatrix.TransformPoints(LeaderPts); g.DrawLine(PnLeader, LeaderPts[0], LeaderPts[1]); } } else { //*** Get default Shape Centroid if (Lyr.LayerType == ShapeType.Polygon) { Centroid = _Shape.Centroid; } else if (Lyr.LayerType == ShapeType.Point) { Centroid = (PointF)_Shape.Parts[0]; } } //--Reset Chart variables AxisDrawn = false; VisibleTimePeriods = 0; DataValueSum = 0; TimeVisibleCtr = 0; StartAngle = 0; PieAngle = 0; #region "-- Set Pie / Line Chart Extent " //-- Get X, Y position & Diameter of Pie Circle / Extent for Line Chart . if (_Theme.ChartType == ChartType.Pie || _Theme.ChartType == ChartType.Line) { //-- Pie drawn should be fitted in the Area. // so reduce the Area of Pie to 40% of Total Area Extent ChartExtent = _Shape.Extent; ChartExtent.Width = ChartExtent.Width * 0.5F; ChartExtent.Height = ChartExtent.Height * 0.5F; //-- Set the Pie Diameter according to layer's width and height if (_Theme.PieAutoSize) //|| (!(_Theme.PieAutoSize) & _Theme.PieSize <= 0)) { //-- If Shape Area is very small i.e. < Minumum Diameter set, // then if (ChartExtent.Width < PieMinDiameter || ChartExtent.Height < PieMinDiameter) { PieDiameter = PieMinDiameter; } else if (ChartExtent.Width > PieMaxDiameter && ChartExtent.Height > PieMaxDiameter) { //If PieDiameter is too high i.e. > Maximum Diameter set, PieDiameter = PieMaxDiameter; } else if (ChartExtent.Height < ChartExtent.Width) { if (ChartExtent.Height * 0.9 < PieMinDiameter) { PieDiameter = PieMinDiameter; } else { PieDiameter = ChartExtent.Height * 0.9F; //PieDiameter = PieRectExtent.Height * 0.5F + (1 - PieRectExtent.Height / PieRectExtent.Width); } } else { if (ChartExtent.Width * 0.9 < PieMinDiameter) { PieDiameter = PieMinDiameter; } else { PieDiameter = ChartExtent.Width * 0.9F; //PieDiameter = PieRectExtent.Height * 0.5F + (1 - PieRectExtent.Height / PieRectExtent.Width); } //PieDiameter = PieRectExtent.Width * 0.5F + (1 - PieRectExtent.Width / PieRectExtent.Height); } //-- Multiply by Auto size Factor value. PieDiameter *= _Theme.PieAutoSizeFactor; } else if (_Theme.PieSize > 0) { //-- Fixed size of each pie is started at minium from curExtent / 12 PieMaxDiameter = CurExt.Height / 12; //-- Then add (PieSize / 10) to it. PieDiameter = (PieMaxDiameter) * (1 + (float)_Theme.PieSize / 10); } ChartExtent.Width = PieDiameter; ChartExtent.Height = PieDiameter; if (_Theme.ModifiedCharts.ContainsKey(Lyr.ID + "_" + _Shape.AreaId)) { //-- IF Chart is nudged then keep Pie center on Centroid. ChartExtent.X = Centroid.X - PieDiameter * 0.5F; ChartExtent.Y = Centroid.Y - PieDiameter * 0.5F; } else { //else, Keep pie center little displaced from Centroid towards downwards ChartExtent.X = Centroid.X - PieDiameter * 0.6F; ChartExtent.Y = Centroid.Y - PieDiameter * 0.7F; } if (_Theme.ChartType == ChartType.Line) { ChartExtent.Y = Centroid.Y - ChartExtent.Height * 0.1F; ChartExtent.Height = PieDiameter; ChartExtent.Width = ChartExtent.Height * 1.4F; } } #endregion //- Get Visible TimePeriods (used in calculating X-Axis length) foreach (string KeyTimePeriod in ChartData.Keys) { if ((bool)_Theme.ChartTimePeriods[KeyTimePeriod] == true) { //- Count TimePeriods only if DataValue exists for visible Subgroups string[] TempDataArr = ChartData[KeyTimePeriod].ToString().Split(','); for (i = 0; i < TempDataArr.Length; i++) { if (string.IsNullOrEmpty(TempDataArr[i]) == false) { if (ChartVisibleSeries[i] == "1") { VisibleTimePeriods++; break; } } } } } if (VisibleTimePeriods == 0 || _Theme.DisplayChartMRD) { VisibleTimePeriods = 1; } //--Total bar column to draw for single Area. (Total Subroups * Total TimePeriod) TotalBarColumns = VisibleTimePeriods * SpCnt; BarCtr = 0; LineSubgroupPoints = new object[ChartVisibleSeries.Length]; // holds line Points drawn //-- Loop TimePeriods for Column OR Line chart. Column/ Line will be plotted for each TimePeriod foreach (string TimePeriodKey in _Theme.ChartTimePeriods.Keys) { if (string.IsNullOrEmpty(TimePeriodKey.ToString()) == false) { //-- Check TimePeriod visibiliy and visibleTime < 2 for LineChart if (!(_Theme.ChartType == ChartType.Line && VisibleTimePeriods < 2)) { //-- Check if TimePeriod visibilty is ON, And ChartData must have data against timePeriod if ((_Theme.ChartTimePeriods[TimePeriodKey.ToString()] == true && ChartData.ContainsKey(TimePeriodKey)) || _Theme.DisplayChartMRD) { if (TimeVisibleCtr < VisibleTimePeriods) { TimeVisibleCtr++; } LineCtr = 0; DataValueSum = 0; DataFoundForTimePeriod = false; //-- If MRD for Chart is ON, Get mostRecent DataValues if (_Theme.DisplayChartMRD) { DataArr = ChartMRD.Split(','); } else //IF MRD is Off, get TimePeriodwise DataValues. { DataArr = ChartData[TimePeriodKey].ToString().Split(','); } //-- Get sum of all dataValues, will be used in PieChart, LineChart // sum for only visible subgroups for (i = 0; i < DataArr.Length; i++) { if (string.IsNullOrEmpty(DataArr[i]) == false) { decimal decVal = Convert.ToDecimal(DataArr[i], CultureInfo.InvariantCulture.NumberFormat); if (decVal > 0 && ChartVisibleSeries[i] == "1") { DataFoundForTimePeriod = true; //-- Indicates that some Data is found for visible Subgroup //-- Round DataValues decVal = Math.Round(decVal, _Theme.RoundDecimals); DataArr[i] = decVal.ToString().Replace(",", "."); DataValueSum += decVal; } } } // -- Get maximum DataValue for LineChart if (_Theme.ChartType == ChartType.Line) { if (_Theme.DisplayChartMRD) { LineMaxDataValue = this.GetMaximumChartDataValue(DataArr); } else { LineMaxDataValue = this.GetMaximumChartDataValue(ChartData); } LineMaxDataValue *= 1.3M; } int j = 0; //*** Counter for Visible Series (subgroup / Sources) for (i = 0; i <= _Theme.SubgroupFillStyle.Length - 1; i++) { if (ChartVisibleSeries[i] == "1" && DataFoundForTimePeriod) { BarCtr++; //This is Nth Bar Column drawing (after increment) try { if (DataArr[i] == "") { DataValue = 0; } else { DataValue = Convert.ToDecimal(Conversion.Val(DataArr[i]), CultureInfo.InvariantCulture.NumberFormat); //DataValue = (decimal)Microsoft.VisualBasic.Conversion.Val(DataArr[i]); //Cdbl } //-- If DataValue is NOT Zero, NOT Pie chart if (DataArr[i] != "" && DataValueSum != 0) { #region "-- Column --" if (_Theme.ChartType == ChartType.Column) { Pt = Centroid; if (_Theme.ModifiedCharts.ContainsKey(Lyr.ID + "_" + _Shape.AreaId)) { Pt.X = Pt.X + ((BarCtr - 1) * (float)UnitWidth) + (ColumnGap * (TimeVisibleCtr - 1)); } else { //-Chart Mid point should coincide with the Centroid of Shape //- get Totol width of Column Chart , and get mid point of chart float ChartWidth = (float)(UnitWidth * TotalBarColumns) + ((VisibleTimePeriods - 1) * ColumnGap); Pt.X = Pt.X - ChartWidth / 2F + ((BarCtr - 1) * (float)UnitWidth) + (ColumnGap * (TimeVisibleCtr - 1)); //Pt.Y = Pt.Y + (_Shape.Extent.Height) / 20; Pt.Y = Pt.Y - (CurExt.Height) / 40; } Pts = new PointF[4]; Pts[0] = Pt; //1st Pt.X = Pt.X + (float)UnitWidth; Pts[1] = Pt; //2nd //*** Bugfix / Enhancement 15 Jun 2006 Controling Chart Height //*** Set Height of Bars based on FullExtentWidth(/) + DataValue(\) + Chart Size(/) Pt.Y = Pt.Y + (float)((m_FullExtent.Height / 2) * (float)(DataValue / MaxData) * Math.Pow(1.5, _Theme.ChartSize - 10)); // exponential rise (_Theme.ChartSize / 10)) //--AXIS X & Y //-- First Draw the X for Column Chart. //-- Axis should be drawn only first time. // Axis for Column to be drawn only for multiple TimePeriods. gpShp.Reset(); if (AxisDrawn == false && _Theme.DisplayChartMRD == false) { //--Get Origin of Axis to be drawn, starting near first Column bar. //- Get coordinates of First Column bar AxisPoint1 = Centroid; if (_Theme.ModifiedCharts.ContainsKey(Lyr.ID + "_" + _Shape.AreaId)) { } else { //-Chart Mid point should coincide with the Centroid of Shape //- get Totol width of Column Chart , and get mid point of chart float ChartWidth = (float)(UnitWidth * TotalBarColumns) + ((VisibleTimePeriods - 1) * ColumnGap); AxisPoint1.X = AxisPoint1.X - ChartWidth / 2F; AxisPoint1.Y = Pts[0].Y; } //-- Adding Axis buffer AxisPoint1.X = AxisPoint1.X - ((float)UnitWidth / 6F); AxisPoint1.Y = AxisPoint1.Y; AxisPoint2.X = AxisPoint1.X + ((float)UnitWidth * TotalBarColumns) + (ColumnGap * (VisibleTimePeriods - 1)) + ((float)UnitWidth / 3F); AxisPoint2.Y = AxisPoint1.Y; // X Axis if (_Theme.ShowChartAxis) { //gpShp.AddLine(AxisPoint1, AxisPoint2); AxisPoints[0] = AxisPoint1; AxisPoints[1] = AxisPoint2; mTransMatrix.TransformPoints(AxisPoints); g.DrawLine(new Pen(new SolidBrush(_Theme.ChartAxisColor), 1), AxisPoints[0], AxisPoints[1]); } AxisDrawn = true; AxisPoint1.X += (float)UnitWidth / 6F; AxisPoint2.X -= 0.1F; } if (Pt.Y > MapTop) { // ReDimStatement not supported in C#, so Pts array is copied into new array PtsTemp PointF[] PtsTemp = new PointF[7]; //PtsTemp[] is resized as desired Array.Copy(Pts, PtsTemp, Math.Min(Pts.Length, PtsTemp.Length)); Pts = PtsTemp; // PtsTemp elements are copied back into Pts[] Pt.Y = MapTop - 2 * (float)UnitWidth; Pts[2] = Pt; //3rd Pt.X = Pt.X - (float)UnitWidth / 4; Pts[3] = Pt; //4rd Pt.Y = Pt.Y - (float)UnitWidth / 4; Pt.X = Pt.X - (float)UnitWidth / 4; Pts[4] = Pt; //5th Pt.Y = MapTop - 2 * (float)UnitWidth; Pts[5] = Pt; //6th Pt.X = Pt.X - (float)UnitWidth / 2; Pts[6] = Pt; //7th //gpShp.Reset(); gpShp.AddPolygon(Pts); //*** Set Bar Break Array.Clear(Pts, 0, 7); Pt.Y = Pt.Y + (float)UnitWidth / 4; Pts[0] = Pt; Pt.X = Pt.X + (float)UnitWidth / 2; Pts[1] = Pt; Pt.Y = Pt.Y + (float)UnitWidth / 4; Pt.X = Pt.X + (float)UnitWidth / 4; Pts[2] = Pt; Pt.Y = Pt.Y - (float)UnitWidth / 4; Pts[3] = Pt; Pt.X = Pt.X + (float)UnitWidth / 4; Pts[4] = Pt; Pt.Y = MapTop - (float)UnitWidth; Pts[5] = Pt; Pt.X = Pt.X - (float)UnitWidth; Pts[6] = Pt; //gpShp.AddPolygon(Pts); } else { Pts[2] = Pt; //3rd Pt.X = Pt.X - (float)UnitWidth; Pts[3] = Pt; //4th //gpShp.Reset(); //gpShp.AddPolygon(Pts); } //-- Add Bar polygon gpShp.AddPolygon(Pts); } #endregion #region "-- LINE --" if (_Theme.ChartType == ChartType.Line) { LineCtr++; //-- First Draw the X, Y axis for Line Chart. //-- Axis should be drawn only first time. gpShp.Reset(); if (AxisDrawn == false && VisibleTimePeriods > 1) { // X Axis AxisPoint1 = new PointF(ChartExtent.Left, ChartExtent.Top); AxisPoint2 = new PointF(ChartExtent.Left + ChartExtent.Width, ChartExtent.Top); if (_Theme.ShowChartAxis) { //gpShp.AddLine(AxisPoint1, AxisPoint2); AxisPoints[0] = AxisPoint1; AxisPoints[1] = AxisPoint2; mTransMatrix.TransformPoints(AxisPoints); g.DrawLine(new Pen(new SolidBrush(_Theme.ChartAxisColor), 1), AxisPoints[0], AxisPoints[1]); } // Y Axis AxisPoint2 = new PointF(ChartExtent.Left, ChartExtent.Top + ChartExtent.Height); if (_Theme.ShowChartAxis) { //gpShp.AddLine(AxisPoint1, AxisPoint2); AxisPoints[0] = AxisPoint1; AxisPoints[1] = AxisPoint2; mTransMatrix.TransformPoints(AxisPoints); g.DrawLine(new Pen(new SolidBrush(_Theme.ChartAxisColor), 1), AxisPoints[0], AxisPoints[1]); } // Get Y Axis height LineChartYAxisLenght = ChartExtent.Height; // - Get horizontal distance between two consecutive points UnitWidth = ChartExtent.Width / (VisibleTimePeriods + 1); // -- Set Start Point same as LineStartPoint = new PointF(ChartExtent.Left + (float)(UnitWidth * TimeVisibleCtr), ChartExtent.Top + (float)(DataValue / LineMaxDataValue) * LineChartYAxisLenght); AxisDrawn = true; } //-- Draw Points for given DataValue LineEndPoint = new PointF(ChartExtent.Left + (float)(UnitWidth * TimeVisibleCtr), ChartExtent.Top + (float)(DataValue / LineMaxDataValue) * LineChartYAxisLenght); if (LineSubgroupPoints[i] != null) { //-- Join Line from previous Point to New Point //- In first loop, line will start from origin LineStartPoint = (PointF)LineSubgroupPoints[i]; //PointF[] Line = { LineStartPoint, LineEndPoint, new PointF(LineEndPoint.X, LineEndPoint.Y - 0.02F), new PointF(LineStartPoint.X, LineStartPoint.Y - 0.02F) }; //gpShp.AddPolygon(Line); LinePoints = new PointF[] { LineStartPoint, LineEndPoint }; mTransMatrix.TransformPoints(LinePoints); g.DrawLine(new Pen(BrIS[i], LineThickness), LinePoints[0], LinePoints[1]); } //-- Draw a dot circle on Point float PointDiameter = CurExt.Height / 400; gpShp.AddEllipse(LineEndPoint.X - PointDiameter, LineEndPoint.Y - PointDiameter, PointDiameter * 2, PointDiameter * 2); //- Set End point as Starting point for next Point to draw. LineSubgroupPoints[i] = LineEndPoint; } #endregion #region "-- PIE --" else if (_Theme.ChartType == ChartType.Pie) { if (!(string.IsNullOrEmpty(DataArr[i])) && DataValue > -1 && DataValueSum > 0) { //--Increment Start Angle for next Pie in loop StartAngle += PieAngle; if (j == SpCnt - 1) { PieAngle = 360 - StartAngle; } else { PieAngle = (int)(DataValue / DataValueSum * 360); // (decimal.Parse(DataArr[i]) } gpShp.Reset(); //gpShp.AddPie((int)(PieRectExtent.X + PieRectExtent.Width * 0.5), (int)(PieRectExtent.Y + PieRectExtent.Height * 0.4), (int)(PieRectExtent.Height * 0.5), (int)(PieRectExtent.Height * 0.5), StartAngle, PieAngle); //gpShp.AddPie((int)(PieRectExtent.X), (int)PieRectExtent.Y, (int)PieRectExtent.Width , (int)PieRectExtent.Height, StartAngle, PieAngle); if (StartAngle == 0 && PieAngle == 360) { gpShp.AddEllipse(ChartExtent); } else { gpShp.AddPie(ChartExtent.X, ChartExtent.Y, ChartExtent.Width, ChartExtent.Height, StartAngle, PieAngle); } } } #endregion #region "-- Draw Chart Shape --" //*** Draw Column or Pie, or Line Chart gpShp.Transform(mTransMatrix); if (bSearch) { if (gpShp.IsVisible(PtX, PtY)) { AreaId = _Shape.AreaId; LayerId = Lyr.ID; } if (_Theme.ChartType == ChartType.Column) { gPath.AddPolygon(Pts); } else if (_Theme.ChartType == ChartType.Line) { gPath.AddRectangle(ChartExtent); } else if (_Theme.ChartType == ChartType.Pie) { gPath.AddPie(ChartExtent.X, ChartExtent.Y, ChartExtent.Width, ChartExtent.Height, StartAngle, PieAngle); } } else { g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; //PathGradientBrush LBrush = new PathGradientBrush(gpShp); //LBrush.SurroundColors = new Color[] { Color.Red, Color.Green, Color.Blue }; // LBrush.CenterColor = Color.Gray; g.FillPath(BrIS[i], gpShp); //LBrush //LBrush.Dispose(); if (_Theme.ChartType == ChartType.Pie) { //-- In case of Pie, draw shape border with gray g.DrawPath(Pens.DarkGray, gpShp); } else { g.DrawPath(Pens.Black, gpShp); } //*** Draw Data Value // Draw data Value if DataValueSum is >0 OR ( visible TimePeriods >= 2 in Line Chart) if (!(string.IsNullOrEmpty(DataArr[i])) && (_Theme.DisplayChartData == true && DataValueSum != 0) && (!(_Theme.ChartType == ChartType.Line && VisibleTimePeriods < 2))) { //--DataValue Label's X, Y position switch (_Theme.ChartType) { case ChartType.Column: Pt.X = Pt.X + (float)UnitWidth / 2; Pt.Y = Pt.Y; // + 0.4F; break; case ChartType.Pie: //--Label's X, Y position will be calculated // on the basis of StartAngle & PieAngle of next subsequent Pie. if (!(string.IsNullOrEmpty(DataArr[i])) && DataValue > -1 && DataValueSum > 0) { //- X double angle; angle = Math.PI * (StartAngle + (PieAngle / 2)) / 180.0; double p = Math.Cos(angle); Pt.X = (float)(((ChartExtent.Left + ChartExtent.Right) / 2) + (ChartExtent.Width / 1.7) * p); //-Y p = Math.Sin(angle); Pt.Y = (float)(((ChartExtent.Top + ChartExtent.Bottom) / 2) + (ChartExtent.Height / 1.7) * p); } break; case ChartType.Line: Pt = LineEndPoint; Pt.Y += CurExt.Height / 100; //- Drawing dataValue at some distance from actual plotted point. break; } PtData[0] = Pt; mTransMatrix.TransformPoints(PtData); //g.DrawString(DataValue.ToString(), TextFont, SystemBrushes.WindowText, PtData[0], _StringFormat); //-- Draw Data Value with orientation this.DrawString(g, DataValue.ToString(), true, TextFont, ChartDataLabelBrush, PtData[0], _Theme.ChartDataLabelSettings.YOffset, _StringFormat, _Theme.ChartDataLabelSettings.TextOrientationAngle); } } Pts = null; #endregion } } catch (Exception ex) { Console.Write(ex.Message); } j += 1; } //Subgroup Visibility }// Subgroups loop ends here. //BarCtr++; // Bar counter increment to give gap between two timeSeries } #region "-- Draw TimePeriod in X Axis--" //-- Draw TimePeriod Text in X- Axis (Applicable in Column & Line) if (!(_Theme.DisplayChartMRD) && _Theme.ShowChartAxis && ChartData.Contains(TimePeriodKey) && _Theme.ChartTimePeriods[TimePeriodKey] == true && SpCnt > 0 && _Theme.ChartType != ChartType.Pie) { if (DataValueSum != 0) { if (_Theme.ChartType == ChartType.Column) { //Pt.X = AxisPoint1.X + ((float)UnitWidth * SpCnt * TimeCtr) + (float)UnitWidth; Pt.X = AxisPoint1.X + ((float)UnitWidth * (TimeVisibleCtr - 1) * SpCnt) + (ColumnGap * (TimeVisibleCtr - 1)) + (float)UnitWidth * 0.5F * SpCnt; Pt.Y = AxisPoint1.Y - (CurExt.Height / 90); PtData[0] = Pt; mTransMatrix.TransformPoints(PtData); } else if (_Theme.ChartType == ChartType.Line && VisibleTimePeriods > 1) { PtData[0].X = LineEndPoint.X; PtData[0].Y = AxisPoint1.Y - (CurExt.Height / 70); mTransMatrix.TransformPoints(PtData); } //g.DrawString(TimePeriodKey.ToString(), ChartAxisLabelFont, ChartAxisLabelBrush, PtData[0], _StringFormat); //-- Draw Data Value with orientation this.DrawString(g, TimePeriodKey.ToString(), false, ChartAxisLabelFont, ChartAxisLabelBrush, PtData[0], _Theme.ChartAxisLabelSettings.YOffset, _StringFormat, _Theme.ChartAxisLabelSettings.TextOrientationAngle); } } if (((_Theme.DisplayChartMRD) && _Theme.ChartType == ChartType.Column) || (_Theme.ChartType == ChartType.Pie)) { break; // in MRD case, only Only Most recent dataValue for Subgroup/ Source series will be plotted in Column chart } #endregion } } } // TimePeriod Loop ends //For each subgroup if (bSearch) { if (AreaId != "") { gPath.Transform(mTransMatrix); return; } //TODO dispose objects //TODO case when same areaid might belong to multiple layers else { gPath.Reset(); } } } //Non Missing data Shapes } //Traverse Shapes } //Extent-Visibility-Type } //Traverse Layers collection } //*** Dispose //gPath = New GraphicsPath _Shape = null; // Pt = null; for (i = 0; i <= BrIS.Length - 1; i++) { BrIS[i].Dispose(); } PnLeader.Dispose(); }
public void AddPie_Float () { GraphicsPath gp = new GraphicsPath (); gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4); CheckPie (gp); }
public void AddPie_Rect () { GraphicsPath gp = new GraphicsPath (); gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4); CheckPie (gp); }
public override void Draw( Graphics g, GraphPane pane, int pos, float scaleFactor ) { if ( pane.Chart._rect.Width <= 0 && pane.Chart._rect.Height <= 0 ) { _slicePath = null; } else { CalcRectangle( g, pane, scaleFactor, pane.Chart._rect ); _slicePath = new GraphicsPath(); if ( !_isVisible ) return; RectangleF tRect = _boundingRectangle; if ( tRect.Width >= 1 && tRect.Height >= 1 ) { SmoothingMode sMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.AntiAlias; _slicePath.AddPie( tRect.X, tRect.Y, tRect.Width, tRect.Height, -StartAngle, -SweepAngle ); float avgAngle = 90 - ((SweepAngle/2) + StartAngle); RectangleF gradientrect = new RectangleF(tRect.X-10, tRect.Y-10, tRect.Width+20, tRect.Height+20); using (LinearGradientBrush linearBrush = new LinearGradientBrush(gradientrect, RegionColorStart, RegionColorEnd, avgAngle)) { using (Pen regionPen = new Pen(linearBrush, pane.GasGaugeRegionWidth)) { g.DrawArc(regionPen, tRect.X, tRect.Y, tRect.Width, tRect.Height, -StartAngle, -SweepAngle); } } if ( this.Border.IsVisible ) { using (Pen borderPen = _border.GetPen(pane, scaleFactor)) { g.DrawPie(borderPen, tRect.X, tRect.Y, tRect.Width, tRect.Height, -StartAngle, -SweepAngle); } } //draw labels for the region limits if (pane.HasLabel || HasLabel) { double absmax = 0; double absmin = MinValue; foreach (object gg in pane.CurveList) { if (gg is GasGaugeRegion) { GasGaugeRegion ggr = (GasGaugeRegion)gg; if (absmax < ggr.MaxValue) absmax = ggr.MaxValue; if (absmin > ggr.MinValue) absmin = ggr.MinValue; } } DrawLabelValue(pane, (StartAngle + SweepAngle), ref m_LabelMin, MinValue); DrawLabelValue(pane, StartAngle, ref m_LabelMax, MaxValue); } else { if (m_LabelMin != null) m_LabelMin.IsVisible = false; if (m_LabelMax != null) m_LabelMax.IsVisible = false; } g.SmoothingMode = sMode; } } }
private void AddPie3(Graphics g) { // Create a pie slice of a circle using the AddPie method. GraphicsPath myPath = new GraphicsPath(); myPath.AddPie(new Rectangle(20, 20, 70, 70), -45, 90); // Draw the path to the screen. Pen myPen = new Pen(Color.Black, 2); g.DrawPath(myPen, myPath); }
public void FillPie(Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) { using (var path = new GraphicsPath()) { path.AddPie(x, y, width, height, startAngle, sweepAngle); FillPath(brush, path); } }
public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle) { using (var path = new GraphicsPath()) { path.AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); FillPath(brush, path); } }
public void DrawPie(Pen pen, RectangleF rect, float startAngle, float sweepAngle) { using (var path = new GraphicsPath()) { path.AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); DrawPath(pen, path); } }
private void DrawFilledArc(Graphics grp, Color color, int startAngle) { grp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Rectangle main = this.ClientRectangle; // If there is no region to be drawn, then this method terminates itself if (main.Width - (2*this._ringThickness) < 1 || main.Height -(2*this._ringThickness) <= 1) return; // Calculates the region that will be filled GraphicsPath outerPath = new GraphicsPath(); outerPath.AddPie (main, startAngle, this.PieAngle); Rectangle sub = new Rectangle(main.X+this._ringThickness, main.Y+this._ringThickness, main.Width-(2*this._ringThickness), main.Height-(2*this._ringThickness)); GraphicsPath innerPath = new GraphicsPath(); innerPath.AddPie (sub, startAngle-1, this.PieAngle+2); System.Drawing.Region mainRegion = new Region (outerPath); System.Drawing.Region subRegion = new Region (innerPath); mainRegion.Exclude (subRegion); // Fill that region grp.FillRegion (new SolidBrush (color), mainRegion); }
public void StartClose_AddPie () { GraphicsPath path = new GraphicsPath (); path.AddLine (1, 1, 2, 2); path.AddPie (10, 10, 10, 10, 90, 180); path.AddLine (10, 10, 20, 20); byte[] types = path.PathTypes; // check first types Assert.AreEqual (0, types[0], "start/Line"); Assert.AreEqual (0, types[2], "start/Pie"); // check last types // libgdiplus draws pie by ending with a line (not a curve) section Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie"); Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2"); Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2"); }
[Category ("NotWorking")] // the output differs from GDI+ and libgdiplus public void Reverse_Pie () { using (GraphicsPath gp = new GraphicsPath ()) { gp.AddPie (1, 2, 3, 4, 10, 20); PointF[] bp = gp.PathPoints; byte[] expected = new byte[] { 0, 3, 3, 3, 129 }; gp.Reverse (); PointF[] ap = gp.PathPoints; byte[] at = gp.PathTypes; int count = gp.PointCount; Assert.AreEqual (bp.Length, count, "PointCount"); for (int i = 0; i < count; i++) { Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ()); Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ()); } } }
/// <summary> /// Do all rendering associated with this <see cref="GasGaugeRegion"/> item to the specified /// <see cref="Graphics"/> device. This method is normally only /// called by the Draw method of the parent <see cref="ZedGraph.CurveList"/> /// collection object. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="pos">Not used for rendering GasGaugeNeedle</param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public override void Draw(Graphics g, GraphPane pane, int pos, float scaleFactor) { if (pane.Chart._rect.Width <= 0 && pane.Chart._rect.Height <= 0) { _slicePath = null; } else { CalcRectangle(g, pane, scaleFactor, pane.Chart._rect); _slicePath = new GraphicsPath(); if (!_isVisible) return; RectangleF tRect = _boundingRectangle; if (tRect.Width >= 1 && tRect.Height >= 1) { SmoothingMode sMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.AntiAlias; _slicePath.AddPie(tRect.X, tRect.Y, tRect.Width, tRect.Height, -0.0f, -180.0f); g.FillPie(Fill.MakeBrush(_boundingRectangle), tRect.X, tRect.Y, tRect.Width, tRect.Height, -StartAngle, -SweepAngle); if (this.Border.IsVisible) { Pen borderPen = _border.GetPen(pane, scaleFactor); g.DrawPie(borderPen, tRect.X, tRect.Y, tRect.Width, tRect.Height, -0.0f, -180.0f); borderPen.Dispose(); } g.SmoothingMode = sMode; } } }
public void AddPie_Int () { GraphicsPath gp = new GraphicsPath (); gp.AddPie (1, 1, 2, 2, Pi4, Pi4); CheckPie (gp); }
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; } }
protected void OnDisplayChange(int horizontal, int vertical) { this.Width = horizontal; int baseWidth = this.ClientSize.Width; // 786 m_barrageArray[0].m_point = new Point(baseWidth - 100, 120); m_barrageArray[1].m_point = new Point(baseWidth - 50, 170); m_barrageArray[2].m_point = new Point(baseWidth - 100, 220); m_barrageArray[3].m_point = new Point(baseWidth - 150, 170); m_buttonArray[0].m_point = new Point(baseWidth - 150, 50); m_buttonArray[1].m_point = new Point(baseWidth - 80, 50); m_buttonArray[2].m_point = new Point(220, 50); m_buttonArray[3].m_point = new Point(baseWidth - 220, 50); m_buttonArray[4].m_point = new Point(-450, -50); m_buttonArray[5].m_point = new Point(210, 240); m_buttonArray[6].m_point = new Point(-550, -50); m_buttonArray[7].m_point = new Point(baseWidth - 210, 240); m_crossArray[0].m_point = new Point(100, 100); m_crossArray[1].m_point = new Point(150, 150); m_crossArray[2].m_point = new Point(100, 200); m_crossArray[3].m_point = new Point(50, 150); m_stickArray[0].m_point = new Point(300, 150); m_stickArray[0].m_home = new Point(300, 150); m_stickArray[1].m_point = new Point(baseWidth - 300, 150); m_stickArray[1].m_home = new Point(baseWidth - 300, 150); m_soundState.m_point = new Point(baseWidth / 2 + 40, 240); m_softKeyboard.m_point = new Point(baseWidth / 2 - 40, 240); //m_dqxMove.m_point = new Point(baseWidth / 2, 50); this.Button1.Location = new System.Drawing.Point(2, 2); this.Button2.Location = new System.Drawing.Point(baseWidth - 2 - 22, 2); if (m_ConfigForm != null) { m_ConfigForm.SetPostion(horizontal,vertical); } if (m_InfotmationForm != null) { m_InfotmationForm.SetPostion(horizontal, vertical); } m_path = new GraphicsPath(); m_path.FillMode = System.Drawing.Drawing2D.FillMode.Winding; m_path.AddRectangle(new Rectangle(0, 0, 48, 26)); m_path.AddRectangle(new Rectangle(this.Width - 26, 0, 26, 26)); m_path.AddEllipse(new Rectangle(baseWidth - 100 - 33, 120 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 50 - 33, 170 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 100 - 33, 220 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 150 - 33, 170 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 150 - 33, 50 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 80 - 33, 50 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(220 - 33, 50 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 220 - 33, 50 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(210 - 33, 240 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth - 210 - 33, 240 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(100 - 33, 100 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(150 - 33, 150 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(100 - 33, 200 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(50 - 33, 150 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth / 2 - 40 - 33, 240 - 33, 64, 64)); m_path.AddEllipse(new Rectangle(baseWidth / 2 + 40 - 33, 240 - 33, 64, 64)); m_path.AddPie(300 - (32 + 50), 150 - (32 + 50), 32 * 2, 32 * 2, 180, 90); m_path.AddPie(300 - (32 + 50), 150 + (50 - 32), 32 * 2, 32 * 2, 90, 90); m_path.AddPie(300 + 50 - 32, 150 - (32 + 50), 32 * 2, 32 * 2, 270, 90); m_path.AddPie(300 + 50 - 32, 150 + (50 - 32), 32 * 2, 32 * 2, 0, 90); m_path.AddRectangle(new Rectangle(300 - (32 + 50) + 32, 150 - (32 + 50), (32 + 50) * 2 - 64, (32 + 50) * 2)); m_path.AddRectangle(new Rectangle(300 - (32 + 50), 150 - (32 + 50) + 32, (32 + 50) * 2, (32 + 50) * 2 - 64)); m_path.AddPie(baseWidth - 300 - (32 + 50), 150 - (32 + 50), 32 * 2, 32 * 2, 180, 90); m_path.AddPie(baseWidth - 300 - (32 + 50), 150 + (50 - 32), 32 * 2, 32 * 2, 90, 90); m_path.AddPie(baseWidth - 300 + 50 - 32, 150 - (32 + 50), 32 * 2, 32 * 2, 270, 90); m_path.AddPie(baseWidth - 300 + 50 - 32, 150 + (50 - 32), 32 * 2, 32 * 2, 0, 90); m_path.AddRectangle(new Rectangle(baseWidth - 300 - (32 + 50) + 32, 150 - (32 + 50), (32 + 50) * 2 - 64, (32 + 50) * 2)); m_path.AddRectangle(new Rectangle(baseWidth - 300 - (32 + 50), 150 - (32 + 50) + 32, (32 + 50) * 2, (32 + 50) * 2 - 64)); }
/// <summary> /// Creates a GraphicsPath object and adds an arc to it with the specified arc values and closure type. /// </summary> /// <param name="ellipseBounds">A RectangleF structure that represents the rectangular bounds of the ellipse from which the arc is taken.</param> /// <param name="start">The starting angle of the arc measured in degrees.</param> /// <param name="extent">The angular extent of the arc measured in degrees.</param> /// <param name="arcType">The closure type for the arc.</param> /// <returns>Returns a new GraphicsPath object that contains the arc path.</returns> public static System.Drawing.Drawing2D.GraphicsPath CreateArc2D(System.Drawing.RectangleF ellipseBounds, float start, float extent, int arcType) { System.Drawing.Drawing2D.GraphicsPath arc2DPath = new System.Drawing.Drawing2D.GraphicsPath(); switch (arcType) { case OPEN: arc2DPath.AddArc(ellipseBounds, start * -1, extent * -1); break; case CLOSED: arc2DPath.AddArc(ellipseBounds, start * -1, extent * -1); arc2DPath.CloseFigure(); break; case PIE: arc2DPath.AddPie(ellipseBounds.X, ellipseBounds.Y, ellipseBounds.Width, ellipseBounds.Height, start * -1, extent * -1); break; default: break; } return arc2DPath; }
/// <summary> /// Do all rendering associated with this <see cref="PieItem"/> item to the specified /// <see cref="Graphics"/> device. This method is normally only /// called by the Draw method of the parent <see cref="ZedGraph.CurveList"/> /// collection object. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="ZedGraph.GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="pos">Not used for rendering Pies</param>param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="ZedGraph.GraphPane"/> object using the /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public override void Draw( Graphics g, GraphPane pane, int pos, float scaleFactor ) { if ( pane.Chart._rect.Width <= 0 && pane.Chart._rect.Height <= 0 ) { //pane.PieRect = RectangleF.Empty; _slicePath = null; } else { //pane.PieRect = CalcPieRect( g, pane, scaleFactor, pane.ChartRect ); CalcPieRect( g, pane, scaleFactor, pane.Chart._rect ); _slicePath = new GraphicsPath(); if ( !_isVisible ) return; RectangleF tRect = _boundingRectangle; if ( tRect.Width >= 1 && tRect.Height >= 1 ) { SmoothingMode sMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.AntiAlias; Fill tFill = _fill; Border tBorder = _border; if ( this.IsSelected ) { tFill = Selection.Fill; tBorder = Selection.Border; } using ( Brush brush = tFill.MakeBrush( _boundingRectangle ) ) { g.FillPie( brush, tRect.X, tRect.Y, tRect.Width, tRect.Height, this.StartAngle, this.SweepAngle ); //add GraphicsPath for hit testing _slicePath.AddPie( tRect.X, tRect.Y, tRect.Width, tRect.Height, this.StartAngle, this.SweepAngle ); if ( this.Border.IsVisible ) { using ( Pen borderPen = tBorder.GetPen( pane, scaleFactor ) ) { g.DrawPie( borderPen, tRect.X, tRect.Y, tRect.Width, tRect.Height, this.StartAngle, this.SweepAngle ); } } if ( _labelType != PieLabelType.None ) DrawLabel( g, pane, tRect, scaleFactor ); //brush.Dispose(); } g.SmoothingMode = sMode; } } }
static private GraphicsPath Pie () { GraphicsPath path = new GraphicsPath (); path.AddPie (20, 20, 200, 200, 60, 120); return path; }
//画刻度 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); } }
protected override System.Drawing.Bitmap PlotarGráfico(int width, int height, System.Collections.IDictionary props) { Bitmap bmp; // Imagem a ser construída PointF centro; // Centro do gráfico float raio; // Raio da pizza PointF posição; // Posição do gráfico float ânguloY; // Ângulo/Y float porcentoY; // 100/Y bool[] porcentagens;// Quais valores tem sua porcentagem escrita porcentagens = new bool[dados.Length]; // Construir imagem bmp = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(bmp)) { g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; if (props["limparFundo"] != null) g.FillRectangle((Brush)props["limparFundo"], 0, 0, bmp.Width, bmp.Height); // Determinar o centro centro = new PointF(width / 2, height / 2); // Determinar o raio raio = DeterminarRaioPizza(g, width, height, props); // Determinan a posição do gráfico posição = new PointF(centro.X - raio / 2, centro.Y - raio / 2); // Calcular ângulo por valores e porcentagem double soma = 0; foreach (double[] vetor in dados) foreach (double valor in vetor) soma += valor; ânguloY = (float)(360 / soma); porcentoY = (float)(100 / soma); // Desenhar o gráfico float ânguloAtual = 0; for (int seq = 0; seq < dados.Length; seq++) { float valor = (float)SomaValores(dados[seq]); float ânguloValor = ânguloY * valor; // Colorir fundo g.FillPie( (Brush)props["seqBrush" + seq.ToString()], posição.X, posição.Y, raio, raio, ânguloAtual, ânguloValor); // Desenhar borda g.DrawPie( new Pen(Color.Black, 1.5f), posição.X, posição.Y, raio, raio, ânguloAtual, ânguloValor); // Área para desenho System.Drawing.Drawing2D.GraphicsPath área = new GraphicsPath(); área.AddPie(posição.X, posição.Y, raio, raio, ânguloAtual, ânguloValor); g.Flush(System.Drawing.Drawing2D.FlushIntention.Flush); g.Clip = new Region(área); área.Dispose(); // Verificar se é possível escrever a porcentagem dentro da fatia string legenda; SizeF tamanhoLegenda; // Escrever legenda (porcentagem) legenda = Math.Round(porcentoY * valor).ToString() + "%"; tamanhoLegenda = g.MeasureString( legenda, (Font)props["legendaFont"]); PointF posiçãoLegenda; float legRaio = raio / 5 - 5; do { legRaio += 5; posiçãoLegenda = new PointF( (float)(centro.X + legRaio * Math.Cos(Math.PI * (ânguloAtual + ânguloValor / 2f) / 180) - tamanhoLegenda.Width / 2), (float)(centro.Y + legRaio * Math.Sin(Math.PI * (ânguloAtual + ânguloValor / 2f) / 180) - tamanhoLegenda.Height / 2)); } while (legRaio < raio - espaçamento - Math.Max(tamanhoLegenda.Width, tamanhoLegenda.Height) && tamanhoLegenda.Width >= Distância(centro.X + legRaio * Math.Cos(Math.PI * ânguloAtual / 180) - tamanhoLegenda.Width / 2, centro.X + legRaio * Math.Sin(Math.PI * ânguloAtual / 180) - tamanhoLegenda.Width / 2, centro.X + legRaio * Math.Cos(Math.PI * (ânguloAtual + ânguloValor) / 180) - tamanhoLegenda.Width / 2, centro.X + legRaio * Math.Sin(Math.PI * (ânguloAtual + ânguloValor) / 180) - tamanhoLegenda.Width / 2)); if (legRaio < raio - espaçamento - Math.Max(tamanhoLegenda.Width, tamanhoLegenda.Height)) g.DrawString( legenda, (Font)props["legendaFont"], (Brush)props["legendaBrush"], posiçãoLegenda); // Escrever descrição (legenda da seqüência) RectangleF regiãoExclusão = new RectangleF(posiçãoLegenda, tamanhoLegenda); legenda = this.legendas[seq]; if (legenda.Length > 8 && legenda.IndexOf(' ') > 0) { string[] palavras = legenda.Split(' '); int cnt; legenda = palavras[0]; cnt = legenda.Length; for (int i = 1; i < palavras.Length; i++) { cnt += palavras[i].Length; legenda += (cnt > 10 ? '\n' : ' ') + palavras[i]; } } tamanhoLegenda = g.MeasureString( legenda, (Font)props["descriçãoFont"]); RectangleF região; do { legRaio += 10; posiçãoLegenda = new PointF( (float)(centro.X + legRaio * Math.Cos(Math.PI * (ânguloAtual + ânguloValor / 2) / 180) - tamanhoLegenda.Width / 2), (float)(centro.Y + legRaio * Math.Sin(Math.PI * (ânguloAtual + ânguloValor / 2) / 180) - tamanhoLegenda.Height / 2)); região = new RectangleF(posiçãoLegenda, tamanhoLegenda); } while (legRaio < raio + espaçamento && regiãoExclusão.IntersectsWith(região)); if (legRaio < raio - espaçamento - Math.Max(tamanhoLegenda.Width, tamanhoLegenda.Height)) g.DrawString( legenda, (Font)props["descriçãoFont"], (Brush)props["descriçãoBrush"], posiçãoLegenda); g.Flush(System.Drawing.Drawing2D.FlushIntention.Flush); g.Clip = new Region(); // Acrescentar ângulo ânguloAtual += ânguloValor; } } return bmp; }
public override GraphicsPath GetGraphicsPath(int left, int top) { GraphicsPath p = new GraphicsPath(); p.AddPie(left, top, Width, Height, StartAngle, SweepAngle); return p; }
public override void AddToGraphicsPath(System.Drawing.Drawing2D.GraphicsPath path) { path.AddPie(rect, startAngle, sweepAngle); }