My Project
ShapeArrow.cs
查看本檔案說明文件.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.IO;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using System.Windows;
9 using System.Windows.Media;
10 using System.Windows.Shapes;
11 
12 namespace ShapeLib.VShape
13 {
14  public class ShapeArrow : ShapeObj
15  {
16 
17 
18  public override System.Collections.ArrayList getMenuItem()
19  {
20 
21  ArrayList ret = new ArrayList();
22 
23  shapeUI ui = new shapeUI();
24  ui.label = "Arrow";
25  System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
26  Stream myStream = myAssembly.GetManifestResourceStream("ShapeLib.icons.arrow.png");
27  ui.image = new System.Drawing.Bitmap(myStream);
28 
29 
30 
31  ui.belong = "Shapes";
32  ui.click = this.btn_Click;
33  ret.Add(ui);
34 
35  return ret;
36  //throw new NotImplementedException();
37  }
38 
39 
40 
41  public override void DrawShape(gView gv, gPath data, Boolean bfirst)
42  {
43 
44  if (bfirst)
45  {
46  shapeLib.Data.Status = "rest";
47  shapeLib.Data.bfirst = false;
48 
49  double num1 = Math.Atan2((data.controlBtn4.X - data.controlBtn1.X), (data.controlBtn4.Y - data.controlBtn1.Y));
50  double num2 = 0.5;
51  double num3 = 6.0;
52  Point point1 = new Point();
53  Point point2 = new Point();
54  Point point3 = new Point();
55  point1.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 - num2)));
56  point1.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 - num2)));
57  point2.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 + num2)));
58  point2.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 + num2)));
59  point3.X = point1.X - (point1.X - point2.X) / 2;
60  point3.Y = point1.Y - (point1.Y - point2.Y) / 2;
61  Polyline myArr = new Polyline();
62 
63  // //如果要繪製中心顏色,可開啟這段
64 
65  myArr.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
66  //myArr.Width = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
67  //myArr.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
68  PointCollection Points = new PointCollection();
69 
70  Points.Add(data.controlBtn1);
71  Points.Add(point3);
72  Points.Add(point1);
73  Points.Add(data.controlBtn4);
74  Points.Add(point2);
75  Points.Add(point3);
76 
77 
78  myArr.Points = new PointCollection(Points);
79  // myArr.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
80  myArr.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
81  myArr.VerticalAlignment = VerticalAlignment.Center;
82  myArr.StrokeThickness = shapeLib.Data.strokeT;
83  myArr.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
84  myArr.MouseEnter += data.myLine_MouseEnter;
85  myArr.MouseLeave += data.myLine_MouseLeave;
86  // myLine.MouseEnter += data.myLine_MouseEnter;
87  // myLine.MouseLeave += data.myLine_MouseLeave;
88  shapeLib.Data.mygrid.Children.Add(myArr);
89  gv.baseShape.Add(myArr);
90  // currPath.setDrawShape( myArr);
91 
92  }
93  else
94  {
95  Polyline myArr = (Polyline)gv.baseShape[0];// =(Line) currPath.getDrawShape();
96  PointCollection Points = new PointCollection();
97  double num1 = Math.Atan2((data.controlBtn4.X - data.controlBtn1.X), (data.controlBtn4.Y - data.controlBtn1.Y));
98  double num2 =0.5;
99  double num3= 6.0;
100  Point point1 = new Point();
101  Point point2 = new Point();
102  Point point3 = new Point();
103  point1.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 - num2)));
104  point1.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 - num2)));
105  point2.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 + num2)));
106  point2.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 + num2)));
107  point3.X = point1.X - (point1.X - point2.X) / 2;
108  point3.Y = point1.Y - (point1.Y - point2.Y) / 2;
109 
110  Points.Add(data.controlBtn1);
111  Points.Add(point3);
112  Points.Add(point1);
113  Points.Add(data.controlBtn4);
114  Points.Add(point2);
115  Points.Add(point3);
116  myArr.Points = new PointCollection(Points);
117  // myLine.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
118 
119 
120 
121  }
122  }
123 
124  public override void DisplayControlPoints(gView gv, gPath data)
125  {
126  if (gv.controlShape.Count == 0)
127  {
128  double num1 = Math.Atan2((data.controlBtn4.X - data.controlBtn1.X), (data.controlBtn4.Y - data.controlBtn1.Y));
129  double num2 = 0.5;
130  double num3 = 6.0;
131  Point point1 = new Point();
132  Point point2 = new Point();
133  Point point3 = new Point();
134  point1.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 - num2)));
135  point1.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 - num2)));
136  point2.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 + num2)));
137  point2.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 + num2)));
138  point3.X = point1.X - (point1.X - point2.X) / 2;
139  point3.Y = point1.Y - (point1.Y - point2.Y) / 2;
140  Polyline myArr = new Polyline();
141 
142  // //如果要繪製中心顏色,可開啟這段
143  myArr.Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 255, 255));
144  //myArr.Width = Math.Abs(data.controlBtn4.X - data.controlBtn1.X);
145  //myArr.Height = Math.Abs(data.controlBtn4.Y - data.controlBtn1.Y);
146  PointCollection Points = new PointCollection();
147 
148  Points.Add(data.controlBtn1);
149  Points.Add(point3);
150  Points.Add(point1);
151  Points.Add(data.controlBtn4);
152  Points.Add(point2);
153  Points.Add(point3);
154 
155 
156  myArr.Points = new PointCollection(Points);
157  // myArr.Margin = new Thickness(data.controlBtn1.X, data.controlBtn1.Y, 0, 0);
158  myArr.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
159  myArr.VerticalAlignment = VerticalAlignment.Center;
160  myArr.StrokeThickness = shapeLib.Data.strokeT;
161  myArr.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
162  myArr.MouseEnter += data.myLine_MouseEnter;
163  myArr.MouseLeave += data.myLine_MouseLeave;
164  // myLine.MouseEnter += data.myLine_MouseEnter;
165  // myLine.MouseLeave += data.myLine_MouseLeave;
166  shapeLib.Data.mygrid.Children.Add(myArr);
167  // currPath.setDrawShape( myArr);
168  gv.controlShape.Add(myArr);
169 
170  }
171 
172  else
173  {
174  Polyline myArr = (Polyline)gv.controlShape[0];// =(Line) currPath.getDrawShape();
175  PointCollection Points = new PointCollection();
176  double num1 = Math.Atan2((data.controlBtn4.X - data.controlBtn1.X), (data.controlBtn4.Y - data.controlBtn1.Y));
177  double num2 = 0.5;
178  double num3 = 6.0;
179  Point point1 = new Point();
180  Point point2 = new Point();
181  Point point3 = new Point();
182  point1.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 - num2)));
183  point1.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 - num2)));
184  point2.X = data.controlBtn4.X - ((num3 * Math.Sin(num1 + num2)));
185  point2.Y = data.controlBtn4.Y - ((num3 * Math.Cos(num1 + num2)));
186  point3.X = point1.X - (point1.X - point2.X) / 2;
187  point3.Y = point1.Y - (point1.Y - point2.Y) / 2;
188 
189  Points.Add(data.controlBtn1);
190  Points.Add(point3);
191  Points.Add(point1);
192  Points.Add(data.controlBtn4);
193  Points.Add(point2);
194  Points.Add(point3);
195  myArr.Points = new PointCollection(Points);
196  }
197 
198  }
199  }
200 }
static GModel Data
Definition: shapeLib.cs:42
RibbonControlEventHandler click
Definition: ShapeObj.cs:49
override void DisplayControlPoints(gView gv, gPath data)
Definition: ShapeArrow.cs:124
string belong
判斷按下Button控制項
Definition: ShapeObj.cs:53
System.Windows.Point controlBtn4
Definition: GraphDoc.cs:256
某一類的形狀.包含UI 的界面,繪製方式.更新方式.新增方式
Definition: ShapeObj.cs:59
void myLine_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
Definition: GraphDoc.cs:392
void myLine_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
Definition: GraphDoc.cs:427
override System.Collections.ArrayList getMenuItem()
覆寫System.Collections.ArrayList
Definition: ShapeArrow.cs:18
定義一個UI項目
Definition: ShapeObj.cs:42
List< Shape > baseShape
Definition: gView.cs:12
System.Windows.Point controlBtn1
Definition: GraphDoc.cs:253
void myLine_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
Definition: GraphDoc.cs:435
void btn_Click(object sender, RibbonControlEventArgs e)
UI 點選
Definition: ShapeObj.cs:107
System.Drawing.Image image
Definition: ShapeObj.cs:46
List< Shape > controlShape
Definition: gView.cs:13
override void DrawShape(gView gv, gPath data, Boolean bfirst)
依data 繪製,如果是第一次畫要新建shape, 更新的話只要更新最後一點
Definition: ShapeArrow.cs:41