PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/NerdSharp.Net_Studio/NerdSharp_UberNet/Science/Comp_Sci/StudioComponents/Widgets/OtherControls/ArcLabel.xaml.cs

https://bitbucket.org/pastageek/scide-cad-scilife
C# | 82 lines | 69 code | 8 blank | 5 comment | 1 complexity | d7bcf903a235206da06341d21e833e03 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using M = System.Math;
  15. using T = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.Utils.Trigonometry;
  16. using Grp = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.TypeLibrary.Graphs_ChartsWidgets.Utils;
  17. namespace NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Comp_Sci.StudioComponents.Widgets.OtherControls
  18. {
  19. /// <summary>
  20. /// Interaction logic for ArcLabel.xaml
  21. /// </summary>
  22. public partial class ArcLabel : UserControl
  23. {
  24. public ArcLabel()
  25. {
  26. InitializeComponent();
  27. }
  28. private string labelText = "Hi";
  29. public string LabelText
  30. {
  31. get { return labelText; }
  32. set
  33. {
  34. labelText = value;
  35. RenderArcLabel();
  36. }
  37. }
  38. private double radius = 20;
  39. public double Radius
  40. {
  41. get { return radius; }
  42. set
  43. {
  44. radius = value;
  45. RenderArcLabel();
  46. }
  47. }
  48. private void RenderArcLabel()
  49. {
  50. mainGrid.Children.Clear();
  51. string debug = "";
  52. char[] chars = this.labelText.ToCharArray();
  53. //chars.Reverse();
  54. double degDivisions = 180 / chars.Length;
  55. for (int i = 0 ; i < chars.Length; i++)
  56. {
  57. double theta = 180 + (degDivisions * i);
  58. Label txt = new Label();
  59. Thickness placement = new Thickness();
  60. Point grph = new Point(M.Cos(T.degreesToRadians(theta)) * radius,
  61. M.Sin(T.degreesToRadians(theta)) * radius);
  62. Point location = Grp.FromGraphToScreen(radius * 2, radius * 2, grph);
  63. placement.Top = location.Y;
  64. placement.Left = location.X;
  65. txt.Margin = placement;
  66. txt.FontSize = 8;
  67. txt.Content = chars[i].ToString();
  68. txt.Foreground = new SolidColorBrush(Colors.Black);
  69. mainGrid.Children.Add(txt);
  70. //debug += location.ToString() + ";";
  71. }
  72. }
  73. }
  74. }