1 #include "Painter.h"
2
3 namespace Upp {
4
ClearOp(const RGBA & color)5 void PaintingPainter::ClearOp(const RGBA& color)
6 {
7 Put(PAINTING_CLEAR);
8 Put(color);
9 }
10
MoveOp(const Pointf & p,bool rel)11 void PaintingPainter::MoveOp(const Pointf& p, bool rel)
12 {
13 Put(PAINTING_MOVE + rel);
14 Putf(p);
15 }
16
LineOp(const Pointf & p,bool rel)17 void PaintingPainter::LineOp(const Pointf& p, bool rel)
18 {
19 Put(PAINTING_LINE + rel);
20 Putf(p);
21 }
22
QuadraticOp(const Pointf & p1,const Pointf & p,bool rel)23 void PaintingPainter::QuadraticOp(const Pointf& p1, const Pointf& p, bool rel)
24 {
25 Put(PAINTING_QUADRATIC + rel);
26 Putf(p1);
27 Putf(p);
28 }
29
QuadraticOp(const Pointf & p,bool rel)30 void PaintingPainter::QuadraticOp(const Pointf& p, bool rel)
31 {
32 Put(PAINTING_QUADRATIC_S + rel);
33 Putf(p);
34 }
35
CubicOp(const Pointf & p1,const Pointf & p2,const Pointf & p,bool rel)36 void PaintingPainter::CubicOp(const Pointf& p1, const Pointf& p2, const Pointf& p, bool rel)
37 {
38 Put(PAINTING_CUBIC + rel);
39 Putf(p1);
40 Putf(p2);
41 Putf(p);
42 }
43
CubicOp(const Pointf & p2,const Pointf & p,bool rel)44 void PaintingPainter::CubicOp(const Pointf& p2, const Pointf& p, bool rel)
45 {
46 Put(PAINTING_CUBIC_S + rel);
47 Putf(p2);
48 Putf(p);
49 }
50
ArcOp(const Pointf & c,const Pointf & r,double angle,double sweep,bool rel)51 void PaintingPainter::ArcOp(const Pointf& c, const Pointf& r, double angle, double sweep, bool rel)
52 {
53 Put(PAINTING_ARC + rel);
54 Putf(c);
55 Putf(r);
56 Putf(angle);
57 Putf(sweep);
58 }
59
SvgArcOp(const Pointf & r,double xangle,bool large,bool sweep,const Pointf & p,bool rel)60 void PaintingPainter::SvgArcOp(const Pointf& r, double xangle, bool large, bool sweep, const Pointf& p, bool rel)
61 {
62 Put(PAINTING_SVGARC + rel);
63 Putf(r);
64 Putf(xangle);
65 Put(large);
66 Put(sweep);
67 Putf(p);
68 }
69
CloseOp()70 void PaintingPainter::CloseOp()
71 {
72 Put(PAINTING_CLOSE);
73 }
74
DivOp()75 void PaintingPainter::DivOp()
76 {
77 Put(PAINTING_DIV);
78 }
79
FillOp(const RGBA & color)80 void PaintingPainter::FillOp(const RGBA& color)
81 {
82 Put(PAINTING_FILL_SOLID);
83 Put(color);
84 }
85
FillOp(const Image & image,const Xform2D & transsrc,dword flags)86 void PaintingPainter::FillOp(const Image& image, const Xform2D& transsrc, dword flags)
87 {
88 Put(PAINTING_FILL_IMAGE);
89 Putf(transsrc);
90 Put(flags);
91 data.Add(image);
92 }
93
FillOp(const Pointf & p1,const RGBA & color1,const Pointf & p2,const RGBA & color2,int style)94 void PaintingPainter::FillOp(const Pointf& p1, const RGBA& color1, const Pointf& p2,
95 const RGBA& color2, int style)
96 {
97 Put(PAINTING_FILL_GRADIENT);
98 Putf(p1);
99 Put(color1);
100 Putf(p2);
101 Put(color2);
102 Put(style);
103 }
104
FillOp(const RGBA & color1,const RGBA & color2,const Xform2D & transsrc,int style)105 void PaintingPainter::FillOp(const RGBA& color1, const RGBA& color2, const Xform2D& transsrc, int style)
106 {
107 Put(PAINTING_FILL_GRADIENT_X);
108 Put(color1);
109 Put(color2);
110 Putf(transsrc);
111 Put(style);
112 }
113
FillOp(const Pointf & f,const RGBA & color1,const RGBA & color2,const Xform2D & transsrc,int style)114 void PaintingPainter::FillOp(const Pointf& f, const RGBA& color1, const RGBA& color2, const Xform2D& transsrc, int style)
115 {
116 Put(PAINTING_FILL_RADIAL_X);
117 Putf(f);
118 Put(color1);
119 Put(color2);
120 Putf(transsrc);
121 Put(style);
122 }
123
StrokeOp(double width,const Pointf & f,const RGBA & color1,const RGBA & color2,const Xform2D & transsrc,int style)124 void PaintingPainter::StrokeOp(double width, const Pointf& f, const RGBA& color1,
125 const RGBA& color2, const Xform2D& transsrc, int style)
126 {
127 Put(PAINTING_FILL_RADIAL_X);
128 Putf(width);
129 Putf(f);
130 Put(color1);
131 Put(color2);
132 Putf(transsrc);
133 Put(style);
134 }
135
136
FillOp(const Pointf & f,const RGBA & color1,const Pointf & p,double r,const RGBA & color2,int style)137 void PaintingPainter::FillOp(const Pointf& f, const RGBA& color1,
138 const Pointf& p, double r, const RGBA& color2, int style)
139 {
140 Put(PAINTING_FILL_RADIAL);
141 Putf(f);
142 Put(color1);
143 Putf(p);
144 Putf(r);
145 Put(color2);
146 Put(style);
147 }
148
StrokeOp(double width,const RGBA & color)149 void PaintingPainter::StrokeOp(double width, const RGBA& color)
150 {
151 Put(PAINTING_STROKE_SOLID);
152 Putf(width);
153 Put(color);
154 }
155
StrokeOp(double width,const Image & image,const Xform2D & transsrc,dword flags)156 void PaintingPainter::StrokeOp(double width, const Image& image,
157 const Xform2D& transsrc, dword flags)
158 {
159 Put(PAINTING_STROKE_IMAGE);
160 Putf(width);
161 Putf(transsrc);
162 Put(flags);
163 data.Add(image);
164 }
165
StrokeOp(double width,const Pointf & p1,const RGBA & color1,const Pointf & p2,const RGBA & color2,int style)166 void PaintingPainter::StrokeOp(double width, const Pointf& p1, const RGBA& color1,
167 const Pointf& p2, const RGBA& color2, int style)
168 {
169 Put(PAINTING_STROKE_GRADIENT);
170 Putf(width);
171 Putf(p1);
172 Put(color1);
173 Putf(p2);
174 Put(color2);
175 Put(style);
176 }
177
StrokeOp(double width,const RGBA & color1,const RGBA & color2,const Xform2D & transsrc,int style)178 void PaintingPainter::StrokeOp(double width, const RGBA& color1, const RGBA& color2,
179 const Xform2D& transsrc, int style)
180 {
181 Put(PAINTING_STROKE_GRADIENT_X);
182 Putf(width);
183 Put(color1);
184 Put(color2);
185 Putf(transsrc);
186 Put(style);
187 }
188
StrokeOp(double width,const Pointf & f,const RGBA & color1,const Pointf & p,double r,const RGBA & color2,int style)189 void PaintingPainter::StrokeOp(double width, const Pointf& f,
190 const RGBA& color1, const Pointf& p, double r,
191 const RGBA& color2, int style)
192 {
193 Put(PAINTING_STROKE_RADIAL);
194 Putf(width);
195 Putf(f);
196 Put(color1);
197 Putf(p);
198 Putf(r);
199 Put(color2);
200 Put(style);
201 }
202
ClipOp()203 void PaintingPainter::ClipOp()
204 {
205 Put(PAINTING_CLIP);
206 }
207
CharacterOp(const Pointf & p,int ch,Font fnt)208 void PaintingPainter::CharacterOp(const Pointf& p, int ch, Font fnt)
209 {
210 Put(PAINTING_CHARACTER);
211 Putf(p);
212 Put32(ch);
213 Put(fnt);
214 }
215
TextOp(const Pointf & p,const wchar * text,Font fnt,int n,const double * dx)216 void PaintingPainter::TextOp(const Pointf& p, const wchar *text, Font fnt, int n, const double *dx)
217 {
218 Put(PAINTING_TEXT);
219 Putf(p);
220 Put32(n);
221 Put((bool)dx);
222 Put(fnt);
223 for(int i = 0; i < n; i++) {
224 Put32(text[i]);
225 if(dx)
226 Putf(dx[i]);
227 }
228 }
229
ColorStopOp(double pos,const RGBA & color)230 void PaintingPainter::ColorStopOp(double pos, const RGBA& color)
231 {
232 Put(PAINTING_COLORSTOP);
233 Putf(pos);
234 Put(color);
235 }
236
ClearStopsOp()237 void PaintingPainter::ClearStopsOp()
238 {
239 Put(PAINTING_CLEARSTOPS);
240 }
241
OpacityOp(double o)242 void PaintingPainter::OpacityOp(double o)
243 {
244 Put(PAINTING_OPACITY);
245 Putf(o);
246 }
247
LineCapOp(int linecap)248 void PaintingPainter::LineCapOp(int linecap)
249 {
250 Put(PAINTING_LINECAP);
251 Put(linecap);
252 }
253
LineJoinOp(int linejoin)254 void PaintingPainter::LineJoinOp(int linejoin)
255 {
256 Put(PAINTING_LINEJOIN);
257 Put(linejoin);
258 }
259
MiterLimitOp(double l)260 void PaintingPainter::MiterLimitOp(double l)
261 {
262 Put(PAINTING_MITERLIMIT);
263 Putf(l);
264 }
265
EvenOddOp(bool evenodd)266 void PaintingPainter::EvenOddOp(bool evenodd)
267 {
268 Put(PAINTING_EVENODD);
269 Put(evenodd);
270 }
271
InvertOp(bool invert)272 void PaintingPainter::InvertOp(bool invert)
273 {
274 Put(PAINTING_INVERT);
275 Put(invert);
276 }
277
DashOp(const Vector<double> & dash,double start)278 void PaintingPainter::DashOp(const Vector<double>& dash, double start)
279 {
280 Put(PAINTING_DASH);
281 Put32(dash.GetCount());
282 for(int i = 0; i < dash.GetCount(); i++)
283 Putf(dash[i]);
284 Putf(start);
285 }
286
TransformOp(const Xform2D & m)287 void PaintingPainter::TransformOp(const Xform2D& m)
288 {
289 Put(PAINTING_TRANSFORM);
290 Putf(m);
291 }
292
BeginOp()293 void PaintingPainter::BeginOp()
294 {
295 Put(PAINTING_BEGIN);
296 }
297
EndOp()298 void PaintingPainter::EndOp()
299 {
300 Put(PAINTING_END);
301 }
302
BeginMaskOp()303 void PaintingPainter::BeginMaskOp()
304 {
305 Put(PAINTING_BEGINMASK);
306 }
307
BeginOnPathOp(double q,bool abs)308 void PaintingPainter::BeginOnPathOp(double q, bool abs)
309 {
310 Put(PAINTING_BEGINONPATH);
311 Putf(q);
312 Put(abs);
313 }
314
GetResult()315 Painting PaintingPainter::GetResult()
316 {
317 Painting p;
318 p.cmd = cmd.GetResult();
319 p.data = data;
320 p.size = size;
321 return p;
322 }
323
Create(double cx,double cy)324 void PaintingPainter::Create(double cx, double cy)
325 {
326 cmd.Create();
327 size.cx = cx;
328 size.cy = cy;
329 }
330
Create(Sizef sz)331 void PaintingPainter::Create(Sizef sz)
332 {
333 Create(sz.cx, sz.cy);
334 }
335
336 }
337