~ted/ubuntu/lucid/tomboy/with-patch

« back to all changes in this revision

Viewing changes to Tomboy/Addins/Sketching/Stroke.cs

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-01-15 11:32:52 UTC
  • mfrom: (1.1.31 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080115113252-p59wg7nqkl6vcg7a
Tags: 0.9.4-0ubuntu1
* New upstream release (LP: #181798)
  - Fix crash during note deletion 
  - Fix null reference exception 
  - Fix mnemonics in sync preferences dialog 
  - Fix fuse mount timeout for sync 
  - New port option for SSH sync 
  - New multi-select notes support in Search All Notes window
  - New config dialog for Insert Timestamp Add-in 
  - New gconf preference, middle-click paste on Tomboy icon
  - New gconf preference, disable ESC closing notes 
  - New paragraph within a bullet with SHIFT + ENTER
  - New bug numbers as links in Export to HTML 
  - New notebook notes can be created off notebook's context menu.
  - New sketching add-in (still incomplete, --enable-sketching)
  - New "Unfiled Notes" item to notebook list 
  - New drag note to "Unfiled Notes" to remove from notebook 
 * debian/tomboy.menu: updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Xml;
 
3
using System.Collections.Generic;
 
4
using Cairo;
 
5
 
 
6
namespace VirtualPaper
 
7
{
 
8
    public class Stroke
 
9
    {
 
10
        protected List<double> x, y;
 
11
        protected List<Color> color;
 
12
        protected Pen style;
 
13
        protected int count;
 
14
        protected double minX;
 
15
        protected double minY;
 
16
        protected double maxX;
 
17
        protected double maxY;
 
18
        protected bool firstStroke;
 
19
 
 
20
        public virtual double X {
 
21
            get {
 
22
                return minX;
 
23
            }
 
24
        }
 
25
 
 
26
        public virtual double Y {
 
27
            get {
 
28
                return minY;
 
29
            }
 
30
        }
 
31
 
 
32
        public virtual double Height {
 
33
            get {
 
34
                return maxY - minY;
 
35
            }
 
36
        }
 
37
 
 
38
        public virtual double Width {
 
39
            get {
 
40
                return maxX - minX;
 
41
            }
 
42
        }
 
43
 
 
44
        public Gdk.Rectangle Bounds {
 
45
            get {
 
46
                int w = (int)Math.Ceiling(style.Size);
 
47
                int w2 = w*2;
 
48
 
 
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;
 
54
                return rect;
 
55
            }
 
56
        }
 
57
        
 
58
        public virtual int Count {
 
59
            get {
 
60
                return count;
 
61
            }
 
62
        }
 
63
 
 
64
        public Stroke(Pen penStyle)
 
65
        {
 
66
            x = new List<double>();
 
67
            y = new List<double>();
 
68
            color = new List<Cairo.Color>();
 
69
            style = penStyle.Clone();
 
70
            count = 0;
 
71
            minX = 0;
 
72
            minY = 0;
 
73
            maxX = 0;
 
74
            maxY = 0;
 
75
            firstStroke = false;
 
76
        }
 
77
 
 
78
        public virtual void AddPoint(double x, double y)
 
79
        {
 
80
            AddPoint(x, y, 1.0);
 
81
        }
 
82
 
 
83
        public virtual Gdk.Rectangle AddPoint(double x, double y, double pressure)
 
84
        {
 
85
            Cairo.Color c = new Cairo.Color(
 
86
                style.Color.R,
 
87
                style.Color.G,
 
88
                style.Color.B,
 
89
                pressure);
 
90
            this.x.Add(x);
 
91
            this.y.Add(y);
 
92
            this.color.Add(c);
 
93
            count++;
 
94
 
 
95
            if(firstStroke) {
 
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;
 
100
            } else {
 
101
                minX = x;
 
102
                maxX = x;
 
103
                minY = y;
 
104
                maxY = y;
 
105
                firstStroke = true;
 
106
            }
 
107
 
 
108
            int w = (int)Math.Ceiling(style.Size);
 
109
            int w2 = w*2;
 
110
 
 
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];
 
114
                if(x < oldX) {
 
115
                    double temp = oldX;
 
116
                    oldX = x;
 
117
                    x = temp;
 
118
                }
 
119
                if(y < oldY) {
 
120
                    double temp = oldY;
 
121
                    oldY = y;
 
122
                    y = temp;
 
123
                }
 
124
 
 
125
                return new Gdk.Rectangle((int)oldX - w, (int)oldY - w,
 
126
                    (int)(x - oldX) + w2, (int)(y - oldY) + w2);
 
127
            }
 
128
            return new Gdk.Rectangle((int)x - w, (int)y - w, w2, w2);
 
129
        }
 
130
 
 
131
        public void Draw(Context cr, Gdk.Rectangle clip)
 
132
        {
 
133
            cr.LineWidth = style.Size;
 
134
 
 
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]);
 
141
 
 
142
                if(clip.IntersectsWith(rect)) {
 
143
                    cr.MoveTo(x[i-1], y[i-1]);
 
144
                    cr.LineTo(x[i], y[i]);
 
145
 
 
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]);
 
149
 
 
150
                    cr.Pattern = g;
 
151
                    cr.Stroke();
 
152
                }
 
153
            }
 
154
        }
 
155
 
 
156
        public virtual void WriteXml(XmlTextWriter xml)
 
157
        {
 
158
            xml.WriteStartElement(null, "stroke", null);
 
159
 
 
160
            xml.WriteAttributeString("left", minX.ToString());
 
161
            xml.WriteAttributeString("top", minY.ToString());
 
162
            xml.WriteAttributeString("right", maxX.ToString());
 
163
            xml.WriteAttributeString("bottom", maxY.ToString());
 
164
 
 
165
            WriteXmlPoints(xml);
 
166
 
 
167
            xml.WriteEndElement();
 
168
        }
 
169
 
 
170
        protected virtual void WriteXmlPoints(XmlTextWriter xml)
 
171
        {
 
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();
 
177
            }
 
178
        }
 
179
    }
 
180
}