3
using System.Collections.Generic;
10
protected List<double> x, y;
11
protected List<Color> color;
14
protected double minX;
15
protected double minY;
16
protected double maxX;
17
protected double maxY;
18
protected bool firstStroke;
20
public virtual double X {
26
public virtual double Y {
32
public virtual double Height {
38
public virtual double Width {
44
public Gdk.Rectangle Bounds {
46
int w = (int)Math.Ceiling(style.Size);
49
Gdk.Rectangle rect = new Gdk.Rectangle();
50
rect.X = (int)minX - w;
51
rect.Y = (int)minY - w;
52
rect.Width = (int)(maxX - minX) + w2;
53
rect.Height = (int)(maxY - minY) + w2;
58
public virtual int Count {
64
public Stroke(Pen penStyle)
66
x = new List<double>();
67
y = new List<double>();
68
color = new List<Cairo.Color>();
69
style = penStyle.Clone();
78
public virtual void AddPoint(double x, double y)
83
public virtual Gdk.Rectangle AddPoint(double x, double y, double pressure)
85
Cairo.Color c = new Cairo.Color(
96
if(x < minX) minX = x;
97
else if(x > maxX) maxX = x;
98
if(y < minY) minY = y;
99
else if(y > maxY) maxY = y;
108
int w = (int)Math.Ceiling(style.Size);
111
if(this.x.Count > 1 && this.y.Count > 1) {
112
double oldX = this.x[this.x.Count - 2];
113
double oldY = this.y[this.y.Count - 2];
125
return new Gdk.Rectangle((int)oldX - w, (int)oldY - w,
126
(int)(x - oldX) + w2, (int)(y - oldY) + w2);
128
return new Gdk.Rectangle((int)x - w, (int)y - w, w2, w2);
131
public void Draw(Context cr, Gdk.Rectangle clip)
133
cr.LineWidth = style.Size;
135
for(int i = 1; i < count; i++) {
136
Gdk.Rectangle rect = new Gdk.Rectangle();
137
rect.X = (int)((x[i] < x[i-1]) ? x[i] : x[i-1]);
138
rect.Y = (int)((y[i] < y[i-1]) ? y[i] : y[i-1]);
139
rect.Width = (int)((x[i] < x[i-1]) ? x[i-1]-x[i] : x[i]-x[i-1]);
140
rect.Height = (int)((y[i] < y[i-1]) ? y[i-1]-y[i] : y[i]-y[i-1]);
142
if(clip.IntersectsWith(rect)) {
143
cr.MoveTo(x[i-1], y[i-1]);
144
cr.LineTo(x[i], y[i]);
146
LinearGradient g = new LinearGradient(x[i-1], y[i-1], x[i], y[i]);
147
g.AddColorStop(0.0, color[i-1]);
148
g.AddColorStop(1.0, color[i]);
156
public virtual void WriteXml(XmlTextWriter xml)
158
xml.WriteStartElement(null, "stroke", null);
160
xml.WriteAttributeString("left", minX.ToString());
161
xml.WriteAttributeString("top", minY.ToString());
162
xml.WriteAttributeString("right", maxX.ToString());
163
xml.WriteAttributeString("bottom", maxY.ToString());
167
xml.WriteEndElement();
170
protected virtual void WriteXmlPoints(XmlTextWriter xml)
172
for(int i = 0; i < count; i++) {
173
xml.WriteStartElement(null, "point", null);
174
xml.WriteAttributeString("x", x[i].ToString());
175
xml.WriteAttributeString("y", y[i].ToString());
176
xml.WriteEndElement();