/NerdSharp.Net_Studio/NerdSharp_UberNet/Science/Comp_Sci/StudioComponents/Widgets/OtherControls/ArcReadout.xaml.cs
C# | 283 lines | 232 code | 32 blank | 19 comment | 13 complexity | c1285cc00a5456aefbb1c3307db47e84 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using T = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.Utils.Trigonometry;
- using M = System.Math;
- using Graph = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.TypeLibrary.Graphs_ChartsWidgets.Utils;
-
- namespace NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Comp_Sci.StudioComponents.Widgets.OtherControls
- {
- /// <summary>
- /// Interaction logic for ArcReadout.xaml
- /// </summary>
- public partial class ArcReadout : UserControl
- {
- public ArcReadout()
- {
- InitializeComponent();
- }
-
- public enum ArcType { Ellipse, Arc }
-
- private ArcType renderType = ArcType.Ellipse;
-
- public ArcType RenderType
- {
- get { return renderType; }
- set
- {
- renderType = value;
- Render();
- }
- }
-
- private double width = 50;
-
- public double Width1
- {
- get { return width; }
- set
- {
- width = value;
- mainGrid.Width = value;
- this.width = value;
- Render();
- }
- }
-
- private double height = 50;
-
- public double Height1
- {
- get { return height; }
- set
- {
- height = value;
- mainGrid.Height = value;
- this.height = value;
- Render();
- }
- }
-
- private Brush brush = new RadialGradientBrush(Colors.BlueViolet, Colors.CadetBlue);
-
- public Brush Brush
- {
- get { return brush; }
- set
- {
- brush = value;
- if (backgroundObj != null)
- {
- backgroundObj.Fill = brush;
- }
- }
- }
-
- public Brush BackGroundBrush
- {
- get { return mainGrid.Background; }
- set { mainGrid.Background = value; }
- }
-
- public enum Marks { Numbers, TickMarks }
-
- private int AmountOfMainMarks = 12;
-
- private int fontSize = 10;
-
- private double startTheta = 270;
-
- private List<Line> lines = null;
-
- public List<Line> Lines
- {
- get { return lines; }
- set
- {
- lines = value;
- RenderLines();
- }
- }
-
- private Shape backgroundObj = null;
-
- private List<Brush> SegmentedBrushes = null;
-
- public List<Brush> SegmentedBrushes1
- {
- get { return SegmentedBrushes; }
- set { SegmentedBrushes = value; }
- }
-
- private void Render()
- {
- mainGrid.Children.Clear();
- mainGrid.Width = this.width;
- mainGrid.Height = this.height;
- if (renderType == ArcType.Arc)
- {
- //creates all the objects need to render the arc
-
- Path path = new Path();
- backgroundObj = path;
- //main arcSegement
- ArcSegment meterArc = new ArcSegment();
- PathGeometry arcGeom = new PathGeometry();
- PathFigure arcPathFigure = new PathFigure();
- //extrasegments
- ArcSegment meterArc1 = new ArcSegment();
- LineSegment lineSeg0 = new LineSegment();
- LineSegment lineSeg1 = new LineSegment();
- //adds parts together
- arcGeom.Figures.Add(arcPathFigure);
-
- path.Data = arcGeom;
- //sets properties
- path.Stroke = new SolidColorBrush(Colors.Black);
- path.StrokeThickness = 1.5;
- path.Fill = brush;
- path.StrokeThickness = 2;
- arcPathFigure.IsFilled = true;
- arcPathFigure.IsFilled = true;
- arcPathFigure.StartPoint = new Point(0, this.Height1/2);
- meterArc.Point = new Point(this.Width1, this.Height1 / 2);
- meterArc.RotationAngle = 20;
- meterArc.Size = new Size(20, 20);
- meterArc.SweepDirection = SweepDirection.Clockwise;
- meterArc.IsSmoothJoin = true;
- meterArc.IsStroked = true;
- arcPathFigure.Segments.Add(meterArc);
- //set properties of others
- lineSeg0.Point = new Point(meterArc.Point.X - 5, meterArc.Point.Y + 8);
- arcPathFigure.Segments.Add(lineSeg0);
- meterArc1.Point = new Point(5, (this.Height1 / 2) + 5);
- meterArc1.Size = meterArc.Size;
- meterArc1.RotationAngle = 20;
- meterArc1.SweepDirection = SweepDirection.Counterclockwise;
- meterArc1.IsStroked = true;
- meterArc1.IsStroked = true;
- arcPathFigure.Segments.Add(meterArc1);
- lineSeg1.Point = new Point(arcPathFigure.StartPoint.X, arcPathFigure.StartPoint.Y);
- arcPathFigure.Segments.Add(lineSeg1);
- mainGrid.Children.Add(path);
- //renders the arcSegemted in Color
- if (SegmentedBrushes != null)
- {
- Point previousPoint = new Point(arcPathFigure.StartPoint.X, arcPathFigure.StartPoint.Y);
- for (int i = 0; i < SegmentedBrushes.Count; i++)
- {
- Path colorSegmentPath = new Path();
- colorSegmentPath.Fill = SegmentedBrushes[i];
- mainGrid.Children.Add(colorSegmentPath);
- }
- }
- RenderTickMarks();
- }
- else if (renderType == ArcType.Ellipse)
- {
- Ellipse elip = new Ellipse();
- this.backgroundObj = elip;
- elip.Stroke = new SolidColorBrush(Colors.Black);
- elip.StrokeThickness = 1;
- elip.Width = this.width;
- elip.Height = this.height;
- elip.Fill = this.brush;
- mainGrid.Children.Add(elip);
- RenderNumbers(elip);
- }
- }
-
- private void ReSizeControl()
- {
-
- }
-
- private Thickness[] RenderMarks(double theta, double radius)
- {
- List<Thickness> thicknesses = new List<Thickness>();
-
- return thicknesses.ToArray();
- }
-
- private void RenderTickMarks()
- {
- double theta = 180;
- double radius = this.mainGrid.Height / 2;
- for (int i = 0; i < AmountOfMainMarks; i++)
- {
- theta += theta / AmountOfMainMarks;
- Line einLine = new Line();
- einLine.Stroke = new SolidColorBrush(Colors.Orange);
- einLine.StrokeThickness = 2;
- double x = T.X(theta, radius);
- double y = T.Y(theta, radius);
- Point startPoint =
- Graph.FromGraphToScreen(Width1, Height1, new Point(x, y));
- einLine.X1 = startPoint.X;
- einLine.Y1 = startPoint.Y;
- einLine.X2 = einLine.X1;
- einLine.Y2 = einLine.Y2 + 5;
- mainGrid.Children.Add(einLine);
- }
- }
-
- private void RenderLines()
- {
- if (this.backgroundObj is Ellipse)
- {
- Ellipse elip = (Ellipse)backgroundObj;
- foreach (Line item in lines)
- {
- mainGrid.Children.Add(item);
- }
- }
- }
-
- private void RenderNumbers(Ellipse element)
- {
- //renders the numbers
- double angleDivision = 360 / 12;
- double theta = startTheta;
- double radius = (element.Width / 2) - 15;
- //debug
- string debug = "";
- for (int i = 0; i < AmountOfMainMarks; i++)
- {
- //rounds the numbers for numeric saftey
- theta += angleDivision;
- Thickness einThickness = new Thickness();
- //gets positions in terms of a four quadrant graph
- double x = T.X(theta, radius);
- double y = T.Y(theta, radius);
-
- //conversion from stardard grpahing points
- Point labelPoint = Graph.FromGraphToScreen(element.ActualWidth,
- element.ActualHeight, new Point(x, y));
- einThickness.Left = labelPoint.X + (element.Width / 3);
- einThickness.Top = labelPoint.Y + (element.Height / 3);
- //used to bring points into the clock
- //debug += x.ToString() + "," + y.ToString() + " ; ";
-
- Label hour = new Label();
- hour.Margin = einThickness;
- hour.FontSize = this.fontSize;
- hour.Foreground = new SolidColorBrush(Colors.Black);
- hour.Content = (i + 1).ToString();
- mainGrid.Children.Add(hour);
- }
- //debug
- //MessageBox.Show(debug);
- }
- }
- }