My Project
eraser.cs
查看本檔案說明文件.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7 using System.Windows;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Shapes;
11 
12 
13 namespace ShapeLib.VShape
14 {
16  {
17  public override System.Collections.ArrayList getMenuItem()
18  {
19 
20  ArrayList ret = new ArrayList();
21 
22  shapeUI ui = new shapeUI();
23  ui.label = "Pen";
24 
25  System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
26  System.IO.Stream myStream = myAssembly.GetManifestResourceStream("ShapeLib.icons.eraser.png");
27  ui.image = new System.Drawing.Bitmap(myStream);
28 
29  ui.belong = "Tools";
30  ui.click = this.btn_Click;
31  ret.Add(ui);
32 
33  return ret;
34  //throw new NotImplementedException();
35  }
36 
37  double B0(double u)
38  {
39  return (1 - u) * (1 - u) * (1 - u) / 6;
40  }
41 
42  double B1(double u)
43  {
44  return (3 * u * u * u - 6 * u * u + 4) / 6;
45  }
46  double B2(double u)
47  {
48  return (-3 * u * u * u + 3 * u * u + 3 * u + 1) / 6;
49  }
50  double B3(double u)
51  {
52  return u * u * u / 6;
53  }
54 
55 
56  Point[] myarr = new Point[6];
57 
58  int m = 6, extra, count = 0;
59  int MAX_STEPS = 1000;
60 
61 
62  public override void DrawShape(gView gv, gPath data, Boolean bfirst)
63  {
64 
65  if (count == 0)
66  {
67  myarr[3] = data.controlBtn1;
68  Path myPath = new System.Windows.Shapes.Path();
69  PathGeometry geometry = (PathGeometry)myPath.Data;
70  shapeLib.Data.mygrid.Children.Add(myPath);
71  gv.baseShape.Add(myPath);
72  count++;
73  }
74  else
75  {
76 
77 
78  if (bfirst)
79  {
80  shapeLib.Data.Status = "rest";
81  shapeLib.Data.bfirst = false;
82  BezierSegment bezier = new BezierSegment();
83  PathFigure figure = new PathFigure();
84 
85 
86 
87  for (int a = 0; a < 4; a++)
88  {
89  if ((3 - a) > 0)
90  {
91  myarr[2 - a] = myarr[3 - a];
92  }
93  else
94  myarr[a] = data.controlBtn1;
95 
96  }
97 
98  for (int i = 0; i < m - 3; i++)
99  {
100  if (i == m - 4)
101  {
102  extra = 1;
103  }
104  else
105  extra = 0;
106  for (int j = 0; j < MAX_STEPS + extra; j++)
107  {
108 
109  double u = j / MAX_STEPS;
110  double Qx = B0(u) * myarr[i].X +
111  B1(u) * myarr[i + 1].X +
112  B2(u) * myarr[i + 2].X +
113  B3(u) * myarr[i + 3].X;
114 
115  double Qy = B0(u) * myarr[i].Y +
116  B1(u) * myarr[i + 1].Y +
117  B2(u) * myarr[i + 2].Y +
118  B3(u) * myarr[i + 3].Y;
119 
120  myarr[i].X = Qx;
121  myarr[i].Y = Qy;
122 
123  }
124 
125  }
126  //figure.StartPoint = myarr[0];
127  //bezier.Point1 = myarr[1];
128  //bezier.Point2 = data.controlBtn4;
129  //bezier.Point3 = myarr[3];
130 
131  figure.Segments.Add(bezier);
132  PathGeometry geometry = new PathGeometry();
133  geometry.Figures.Add(figure);
134 
135  //myPath.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(curve_MouseLeftButtonDown);
136  SolidColorBrush mySolidColorBrush = new SolidColorBrush();
137  // Describes the brush's color using RGB values.
138  // Each value has a range of 0-255.
139 
140  Path myPath = new System.Windows.Shapes.Path();
141  myPath.Stroke = new SolidColorBrush(Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
142  myPath.StrokeThickness = data.state.strokeT;
143  /*myPath.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
144  myPath.MouseEnter += data.myLine_MouseEnter;
145  myPath.MouseLeave += data.myLine_MouseLeave; */
146  myPath.Data = geometry;
147  shapeLib.Data.mygrid.Children.Add(myPath);
148  gv.baseShape.Add(myPath);
149 
150 
151 
152 
153  }
154  else
155  {
156 
157  Path myPath = (Path)gv.baseShape[0];// =(Line) currPath.getDrawShape();
158  PathGeometry geometry = (PathGeometry)myPath.Data;
159  if (geometry != null)
160  {
161  BezierSegment bs = (BezierSegment)geometry.Figures[0].Segments[0];
162 
163  geometry.Figures[0].StartPoint = myarr[0];
164  bs.Point1 = myarr[1];
165  bs.Point2 = data.controlBtn4;
166  bs.Point3 = myarr[3];
167  }
168 
169 
170  }
171 
172  }
173 
174  }
175  }
176 
177 
178  }
179 
double B0(double u)
Definition: eraser.cs:37
static GModel Data
Definition: shapeLib.cs:42
RibbonControlEventHandler click
Definition: ShapeObj.cs:49
double B1(double u)
Definition: eraser.cs:42
string belong
判斷按下Button控制項
Definition: ShapeObj.cs:53
double B3(double u)
Definition: eraser.cs:50
double B2(double u)
Definition: eraser.cs:46
System.Windows.Point controlBtn4
Definition: GraphDoc.cs:256
定義一個UI項目
Definition: ShapeObj.cs:42
List< Shape > baseShape
Definition: gView.cs:12
System.Windows.Point controlBtn1
Definition: GraphDoc.cs:253
void btn_Click(object sender, RibbonControlEventArgs e)
UI 點選
Definition: ShapeObj.cs:107
override void DrawShape(gView gv, gPath data, Boolean bfirst)
依data 繪製,如果是第一次畫要新建shape, 更新的話只要更新最後一點
Definition: eraser.cs:62
override System.Collections.ArrayList getMenuItem()
覆寫System.Collections.ArrayList
Definition: eraser.cs:17
System.Drawing.Image image
Definition: ShapeObj.cs:46