Initial attempt at i18n support using gettext
[synfig.git] / synfig-core / trunk / src / modules / mod_particle / plant.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file plant.cpp
3 **      \brief Template
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include <synfig/angle.h>
34 #include "plant.h"
35 #include <synfig/string.h>
36 #include <synfig/time.h>
37 #include <synfig/context.h>
38 #include <synfig/paramdesc.h>
39 #include <synfig/renddesc.h>
40 #include <synfig/surface.h>
41 #include <synfig/value.h>
42 #include <synfig/valuenode.h>
43
44 #include <ETL/calculus>
45 #include <ETL/bezier>
46 #include <ETL/hermite>
47 #include <vector>
48
49 #include <synfig/valuenode_bline.h>
50
51 #endif
52
53 using namespace etl;
54
55 /* === M A C R O S ========================================================= */
56
57 #define SAMPLES         300
58 #define ROUND_END_FACTOR        (4)
59 #define CUSP_THRESHOLD          (0.15)
60 #define NO_LOOP_COOKIE          synfig::Vector(84951305,7836658)
61 #define EPSILON                         (0.000000001)
62 #define CUSP_TANGENT_ADJUST     (0.025)
63
64 /* === G L O B A L S ======================================================= */
65
66 SYNFIG_LAYER_INIT(Plant);
67 SYNFIG_LAYER_SET_NAME(Plant,"plant");
68 SYNFIG_LAYER_SET_LOCAL_NAME(Plant,N_("Plant"));
69 SYNFIG_LAYER_SET_CATEGORY(Plant,N_("Other"));
70 SYNFIG_LAYER_SET_VERSION(Plant,"0.1");
71 SYNFIG_LAYER_SET_CVS_ID(Plant,"$Id$");
72
73 /* === P R O C E D U R E S ================================================= */
74
75 /* === M E T H O D S ======================================================= */
76
77
78 Plant::Plant():
79         split_angle(Angle::deg(10)),
80         gravity(0,-0.1),
81         velocity(0.3),
82         perp_velocity(0.0),
83         step(0.01),
84         sprouts(10)
85 {
86         bounding_rect=Rect::zero();
87         random_factor=0.2;
88         random.set_seed(time(NULL));
89
90         bline.push_back(BLinePoint());
91         bline.push_back(BLinePoint());
92         bline.push_back(BLinePoint());
93         bline[0].set_vertex(Point(0,1));
94         bline[1].set_vertex(Point(0,-1));
95         bline[2].set_vertex(Point(1,0));
96         bline[0].set_tangent(bline[1].get_vertex()-bline[2].get_vertex()*0.5f);
97         bline[1].set_tangent(bline[2].get_vertex()-bline[0].get_vertex()*0.5f);
98         bline[2].set_tangent(bline[0].get_vertex()-bline[1].get_vertex()*0.5f);
99         bline[0].set_width(1.0f);
100         bline[1].set_width(1.0f);
101         bline[2].set_width(1.0f);
102         bline_loop=true;
103         mass=(0.5);
104         splits=5;
105         drag=0.1;
106         size=0.015;
107         needs_sync_=true;
108         sync();
109         size_as_alpha=false;
110         reverse=true;
111 }
112
113 void
114 Plant::branch(int n,int depth,float t, float stunt_growth, synfig::Point position,synfig::Vector vel)const
115 {
116         float next_split((1.0-t)/(splits-depth)+t/*+random_factor*random(40+depth,t*splits,0,0)/splits*/);
117         for(;t<next_split;t+=step)
118         {
119                 vel[0]+=gravity[0]*step;
120                 vel[1]+=gravity[1]*step;
121                 vel*=(1.0-(drag)*step);
122                 position[0]+=vel[0]*step;
123                 position[1]+=vel[1]*step;
124
125                 particle_list.push_back(Particle(position, gradient(t)));
126                 if (particle_list.size() % 1000000 == 0)
127                         synfig::info("constructed %d million particles...", particle_list.size()/1000000);
128
129                 bounding_rect.expand(position);
130         }
131
132         if(t>=1.0-stunt_growth)return;
133
134         synfig::Real sin_v=synfig::Angle::cos(split_angle).get();
135         synfig::Real cos_v=synfig::Angle::sin(split_angle).get();
136
137         synfig::Vector velocity1(vel[0]*sin_v - vel[1]*cos_v + random_factor*random(Random::SMOOTH_COSINE, 30+n+depth, t*splits, 0.0f, 0.0f),
138                                                          vel[0]*cos_v + vel[1]*sin_v + random_factor*random(Random::SMOOTH_COSINE, 32+n+depth, t*splits, 0.0f, 0.0f));
139         synfig::Vector velocity2(vel[0]*sin_v + vel[1]*cos_v + random_factor*random(Random::SMOOTH_COSINE, 31+n+depth, t*splits, 0.0f, 0.0f),
140                                                         -vel[0]*cos_v + vel[1]*sin_v + random_factor*random(Random::SMOOTH_COSINE, 33+n+depth, t*splits, 0.0f, 0.0f));
141
142         Plant::branch(n,depth+1,t,stunt_growth,position,velocity1);
143         Plant::branch(n,depth+1,t,stunt_growth,position,velocity2);
144 }
145
146 void
147 Plant::calc_bounding_rect()const
148 {
149         std::vector<synfig::BLinePoint>::const_iterator iter,next;
150
151         bounding_rect=Rect::zero();
152
153         // Bline must have at least 2 points in it
154         if(bline.size()<2)
155                 return;
156
157         next=bline.begin();
158
159         if(bline_loop)
160                 iter=--bline.end();
161         else
162                 iter=next++;
163
164         for(;next!=bline.end();iter=next++)
165         {
166                 bounding_rect.expand(iter->get_vertex());
167                 bounding_rect.expand(next->get_vertex());
168                 bounding_rect.expand(iter->get_vertex()+iter->get_tangent2()*0.3333333333333);
169                 bounding_rect.expand(next->get_vertex()-next->get_tangent1()*0.3333333333333);
170                 bounding_rect.expand(next->get_vertex()+next->get_tangent2()*velocity);
171         }
172         bounding_rect.expand_x(gravity[0]);
173         bounding_rect.expand_y(gravity[1]);
174         bounding_rect.expand_x(size);
175         bounding_rect.expand_y(size);
176 }
177
178 void
179 Plant::sync()const
180 {
181         Mutex::Lock lock(mutex);
182         if (!needs_sync_) return;
183         time_t start_time; time(&start_time);
184         particle_list.clear();
185
186         bounding_rect=Rect::zero();
187
188         // Bline must have at least 2 points in it
189         if(bline.size()<2)
190         {
191                 needs_sync_=false;
192                 return;
193         }
194
195         std::vector<synfig::BLinePoint>::const_iterator iter,next;
196
197         etl::hermite<Vector> curve;
198
199         Real step(abs(this->step));
200
201         int seg(0);
202
203         next=bline.begin();
204
205         if(bline_loop)  iter=--bline.end(); // iter is the last  bline in the list; next is the first  bline in the list
206         else                    iter=next++;            // iter is the first bline in the list; next is the second bline in the list
207
208         // loop through the bline; seg counts the blines as we do so; stop before iter is the last bline in the list
209         for(;next!=bline.end();iter=next++,seg++)
210         {
211                 curve.p1()=iter->get_vertex();
212                 curve.t1()=iter->get_tangent2();
213                 curve.p2()=next->get_vertex();
214                 curve.t2()=next->get_tangent1();
215                 curve.sync();
216                 etl::derivative<etl::hermite<Vector> > deriv(curve);
217
218                 Real f;
219
220                 int i=0, branch_count = 0, steps = round_to_int(1.0/step);
221                 if (steps < 1) steps = 1;
222                 for(f=0.0;f<1.0;f+=step,i++)
223                 {
224                         Point point(curve(f));
225
226                         particle_list.push_back(Particle(point, gradient(0)));
227                         if (particle_list.size() % 1000000 == 0)
228                                 synfig::info("constructed %d million particles...", particle_list.size()/1000000);
229
230                         bounding_rect.expand(point);
231
232                         Real stunt_growth(random_factor * (random(Random::SMOOTH_COSINE,i,f+seg,0.0f,0.0f)/2.0+0.5));
233                         stunt_growth*=stunt_growth;
234
235                         if((((i+1)*sprouts + steps/2) / steps) > branch_count) {
236                                 Vector branch_velocity(deriv(f).norm()*velocity + deriv(f).perp().norm()*perp_velocity);
237
238                                 branch_velocity[0] += random_factor * random(Random::SMOOTH_COSINE, 1, f*splits, 0.0f, 0.0f);
239                                 branch_velocity[1] += random_factor * random(Random::SMOOTH_COSINE, 2, f*splits, 0.0f, 0.0f);
240
241                                 branch_count++;
242                                 branch(i, 0, 0,          // time
243                                            stunt_growth, // stunt growth
244                                            point, branch_velocity);
245                         }
246                 }
247         }
248
249         time_t end_time; time(&end_time);
250         if (end_time-start_time > 4)
251                 synfig::info("Plant::sync() constructed %d particles in %d seconds\n",
252                                          particle_list.size(), int(end_time-start_time));
253         needs_sync_=false;
254 }
255
256 bool
257 Plant::set_param(const String & param, const ValueBase &value)
258 {
259         if(param=="bline" && value.get_type()==ValueBase::TYPE_LIST)
260         {
261                 bline=value;
262                 bline_loop=value.get_loop();
263                 needs_sync_=true;
264
265                 return true;
266         }
267         if(param=="seed" && value.same_type_as(int()))
268         {
269                 random.set_seed(value.get(int()));
270                 needs_sync_=true;
271                 return true;
272         }
273         IMPORT_PLUS(split_angle,needs_sync_=true);
274         IMPORT_PLUS(gravity,needs_sync_=true);
275         IMPORT_PLUS(gradient,needs_sync_=true);
276         IMPORT_PLUS(velocity,needs_sync_=true);
277         IMPORT_PLUS(perp_velocity,needs_sync_=true);
278         IMPORT_PLUS(step,{
279                         needs_sync_ = true;
280                         if (step <= 0)
281                                 step=0.01; // user is probably clueless - give a good default
282                         else if (step < 0.00001)
283                                 step=0.00001; // 100K should be enough for anyone
284                         else if (step > 1)
285                                 step=1;
286                 });
287         IMPORT_PLUS(splits,{
288                         needs_sync_=true;
289                         if (splits < 1)
290                                 splits = 1;
291                 });
292         IMPORT_PLUS(sprouts,needs_sync_=true);
293         IMPORT_PLUS(random_factor,needs_sync_=true);
294         IMPORT_PLUS(drag,needs_sync_=true);
295         IMPORT(size);
296         IMPORT(size_as_alpha);
297         IMPORT(reverse);
298
299         return Layer_Composite::set_param(param,value);
300 }
301 /*
302 void
303 Plant::set_time(Context context, Time time)const
304 {
305         if(needs_sync==true)
306         {
307                 sync();
308                 needs_sync_=false;
309         }
310         //const_cast<Plant*>(this)->sync();
311         context.set_time(time);
312 }
313
314 void
315 Plant::set_time(Context context, Time time, Vector pos)const
316 {
317         if(needs_sync==true)
318         {
319                 sync();
320                 needs_sync_=false;
321         }
322         //const_cast<Plant*>(this)->sync();
323         context.set_time(time,pos);
324 }
325 */
326 ValueBase
327 Plant::get_param(const String& param)const
328 {
329         if(param=="seed")
330                 return random.get_seed();
331         EXPORT(bline);
332         EXPORT(split_angle);
333         EXPORT(gravity);
334         EXPORT(velocity);
335         EXPORT(perp_velocity);
336         EXPORT(step);
337         EXPORT(gradient);
338         EXPORT(splits);
339         EXPORT(sprouts);
340         EXPORT(random_factor);
341         EXPORT(drag);
342         EXPORT(size);
343
344         EXPORT(size_as_alpha);
345         EXPORT(reverse);
346
347         EXPORT_NAME();
348         EXPORT_VERSION();
349
350         return Layer_Composite::get_param(param);
351 }
352
353 Layer::Vocab
354 Plant::get_param_vocab()const
355 {
356         Layer::Vocab ret(Layer_Composite::get_param_vocab());
357
358         ret.push_back(ParamDesc("bline")
359                 .set_local_name(_("Vertices"))
360                 .set_description(_("A list of BLine Points"))
361                 //.set_origin("offset")
362                 //.set_scalar("width")
363         );
364
365         ret.push_back(ParamDesc("gradient")
366                 .set_local_name(_("Gradient"))
367                 .set_description(_("Gradient to be used for coloring the plant"))
368         );
369
370         ret.push_back(ParamDesc("split_angle")
371                 .set_local_name(_("Split Angle"))
372                 .set_description(_("Angle by which each split deviates from its parent"))
373         );
374
375         ret.push_back(ParamDesc("gravity")
376                 .set_local_name(_("Gravity"))
377                 .set_description(_("Direction in which the shoots tend to face"))
378                 .set_is_distance()
379         );
380
381         ret.push_back(ParamDesc("velocity")
382                 .set_local_name(_("Tangential Velocity"))
383                 .set_description(_("Amount to which shoots tend to grow along the tangent to the BLine"))
384         );
385
386         ret.push_back(ParamDesc("perp_velocity")
387                 .set_local_name(_("Perpendicular Velocity"))
388                 .set_description(_("Amount to which shoots tend to grow perpendicular to the tangent to the BLine"))
389         );
390
391         ret.push_back(ParamDesc("size")
392                 .set_local_name(_("Stem Size"))
393                 .set_description(_("Size of the stem"))
394                 .set_is_distance()
395         );
396
397         ret.push_back(ParamDesc("size_as_alpha")
398                 .set_local_name(_("Size As Alpha"))
399                 .set_description(_("If enabled, the alpha channel from the gradient is multiplied by the stem size, and an alpha of 1.0 is used when rendering"))
400         );
401
402         ret.push_back(ParamDesc("reverse")
403                 .set_local_name(_("Reverse"))
404                 .set_description(_("If enabled, render the plant in the opposite direction"))
405         );
406
407         ret.push_back(ParamDesc("step")
408                 .set_local_name(_("Step"))
409                 .set_description(_("Measure of the distance between points when rendering"))
410         );
411
412         ret.push_back(ParamDesc("seed")
413                 .set_local_name(_("Seed"))
414                 .set_description(_("Used to seed the pseudo-random number generator"))
415         );
416
417         ret.push_back(ParamDesc("splits")
418                 .set_local_name(_("Splits"))
419                 .set_description(_("Maximum number of times that each sprout can sprout recursively"))
420         );
421
422         ret.push_back(ParamDesc("sprouts")
423                 .set_local_name(_("Sprouts"))
424                 .set_description(_("Number of places that growth occurs on each bline section"))
425         );
426
427         ret.push_back(ParamDesc("random_factor")
428                 .set_local_name(_("Random Factor"))
429                 .set_description(_("Used to scale down all random effects.  Set to zero to disable randomness"))
430         );
431
432         ret.push_back(ParamDesc("drag")
433                 .set_local_name(_("Drag"))
434                 .set_description(_("Drag slows the growth"))
435         );
436
437         return ret;
438 }
439
440 bool
441 Plant::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
442 {
443         bool ret(context.accelerated_render(surface,quality,renddesc,cb));
444         if(is_disabled() || !ret)
445                 return ret;
446
447         Surface dest_surface;
448         dest_surface.set_wh(surface->get_w(),surface->get_h());
449         dest_surface.clear();
450
451         const Point     tl(renddesc.get_tl());
452         const Point br(renddesc.get_br());
453
454         const int       w(renddesc.get_w());
455         const int       h(renddesc.get_h());
456
457         const int       surface_width(surface->get_w());
458         const int       surface_height(surface->get_h());
459
460         // Width and Height of a pixel
461         const Real pw = (br[0] - tl[0]) / w;
462         const Real ph = (br[1] - tl[1]) / h;
463
464         if (isinf(pw) || isinf(ph))
465                 return true;
466
467         if(needs_sync_==true)
468                 sync();
469
470         if (particle_list.begin() != particle_list.end())
471         {
472                 std::vector<Particle>::iterator iter;
473                 Particle *particle;
474
475                 float radius(size*sqrt(1.0f/(abs(pw)*abs(ph))));
476
477                 int x1,y1,x2,y2;
478
479                 if (reverse)    iter = particle_list.end();
480                 else                    iter = particle_list.begin();
481
482                 while (true)
483                 {
484                         if (reverse)    particle = &(*(iter-1));
485                         else                    particle = &(*iter);
486
487                         float scaled_radius(radius);
488                         Color color(particle->color);
489                         if(size_as_alpha)
490                         {
491                                 scaled_radius*=color.get_a();
492                                 color.set_a(1);
493                         }
494
495                         // previously, radius was multiplied by sqrt(step)*12 only if
496                         // the radius came out at less than 1 (pixel):
497                         //   if (radius<=1.0f) radius*=sqrt(step)*12.0f;
498                         // seems a little arbitrary - does it help?
499
500                         // calculate the box that this particle will be drawn as
501                         float x1f=(particle->point[0]-tl[0])/pw-(scaled_radius*0.5);
502                         float x2f=(particle->point[0]-tl[0])/pw+(scaled_radius*0.5);
503                         float y1f=(particle->point[1]-tl[1])/ph-(scaled_radius*0.5);
504                         float y2f=(particle->point[1]-tl[1])/ph+(scaled_radius*0.5);
505                         x1=ceil_to_int(x1f);
506                         x2=ceil_to_int(x2f)-1;
507                         y1=ceil_to_int(y1f);
508                         y2=ceil_to_int(y2f)-1;
509
510                         // if the box isn't entirely off the canvas, draw it
511                         if(x1<=surface_width && y1<=surface_height && x2>=0 && y2>=0)
512                         {
513                                 float x1e=x1-x1f, x2e=x2f-x2, y1e=y1-y1f, y2e=y2f-y2;
514                                 // printf("x1e %.4f x2e %.4f y1e %.4f y2e %.4f\n", x1e, x2e, y1e, y2e);
515
516                                 // adjust the box so it's entirely on the canvas
517                                 if(x1<=0) { x1=0; x1e=0; }
518                                 if(y1<=0) { y1=0; y1e=0; }
519                                 if(x2>=surface_width)  { x2=surface_width;  x2e=0; }
520                                 if(y2>=surface_height) { y2=surface_height; y2e=0; }
521
522                                 int w(x2-x1), h(y2-y1);
523
524                                 Surface::alpha_pen surface_pen(dest_surface.get_pen(x1,y1),1.0f);
525                                 if(w>0 && h>0)
526                                         dest_surface.fill(color,surface_pen,w,h);
527
528                                 /* the rectangle doesn't cross any vertical pixel boundaries so we don't
529                                  * need to draw any top or bottom edges
530                                  */
531                                 if(x2<x1)
532                                 {
533                                         // case 1 - a single pixel
534                                         if(y2<y1)
535                                         {
536                                                 surface_pen.move_to(x2,y2);
537                                                 surface_pen.set_alpha((x2f-x1f)*(y2f-y1f));
538                                                 surface_pen.put_value(color);
539                                         }
540                                         // case 2 - a single vertical column of pixels
541                                         else
542                                         {
543                                                 surface_pen.move_to(x2,y1-1);
544                                                 if (y1e!=0)     // maybe draw top pixel
545                                                 {
546                                                         surface_pen.set_alpha(y1e*(x2f-x1f));
547                                                         surface_pen.put_value(color);
548                                                 }
549                                                 surface_pen.inc_y();
550                                                 surface_pen.set_alpha(x2f-x1f);
551                                                 for(int i=y1; i<y2; i++) // maybe draw pixels between
552                                                 {
553                                                         surface_pen.put_value(color);
554                                                         surface_pen.inc_y();
555                                                 }
556                                                 if (y2e!=0)     // maybe draw bottom pixel
557                                                 {
558                                                         surface_pen.set_alpha(y2e*(x2f-x1f));
559                                                         surface_pen.put_value(color);
560                                                 }
561                                         }
562                                 }
563                                 else
564                                 {
565                                         // case 3 - a single horizontal row of pixels
566                                         if(y2<y1)
567                                         {
568                                                 surface_pen.move_to(x1-1,y2);
569                                                 if (x1e!=0)     // maybe draw left pixel
570                                                 {
571                                                         surface_pen.set_alpha(x1e*(y2f-y1f));
572                                                         surface_pen.put_value(color);
573                                                 }
574                                                 surface_pen.inc_x();
575                                                 surface_pen.set_alpha(y2f-y1f);
576                                                 for(int i=x1; i<x2; i++) // maybe draw pixels between
577                                                 {
578                                                         surface_pen.put_value(color);
579                                                         surface_pen.inc_x();
580                                                 }
581                                                 if (x2e!=0)     // maybe draw right pixel
582                                                 {
583                                                         surface_pen.set_alpha(x2e*(y2f-y1f));
584                                                         surface_pen.put_value(color);
585                                                 }
586                                         }
587                                         // case 4 - a proper block of pixels
588                                         else
589                                         {
590                                                 if (x1e!=0)     // maybe draw left edge
591                                                 {
592                                                         surface_pen.move_to(x1-1,y1-1);
593                                                         if (y1e!=0)     // maybe draw top left pixel
594                                                         {
595                                                                 surface_pen.set_alpha(x1e*y1e);
596                                                                 surface_pen.put_value(color);
597                                                         }
598                                                         surface_pen.inc_y();
599                                                         surface_pen.set_alpha(x1e);
600                                                         for(int i=y1; i<y2; i++) // maybe draw pixels along the left edge
601                                                         {
602                                                                 surface_pen.put_value(color);
603                                                                 surface_pen.inc_y();
604                                                         }
605                                                         if (y2e!=0)     // maybe draw bottom left pixel
606                                                         {
607                                                                 surface_pen.set_alpha(x1e*y2e);
608                                                                 surface_pen.put_value(color);
609                                                         }
610                                                         surface_pen.inc_x();
611                                                 }
612                                                 else
613                                                         surface_pen.move_to(x1,y2);
614
615                                                 if (y2e!=0)     // maybe draw bottom edge
616                                                 {
617                                                         surface_pen.set_alpha(y2e);
618                                                         for(int i=x1; i<x2; i++) // maybe draw pixels along the bottom edge
619                                                         {
620                                                                 surface_pen.put_value(color);
621                                                                 surface_pen.inc_x();
622                                                         }
623                                                         if (x2e!=0)     // maybe draw bottom right pixel
624                                                         {
625                                                                 surface_pen.set_alpha(x2e*y2e);
626                                                                 surface_pen.put_value(color);
627                                                         }
628                                                         surface_pen.dec_y();
629                                                 }
630                                                 else
631                                                         surface_pen.move_to(x2,y2-1);
632
633                                                 if (x2e!=0)     // maybe draw right edge
634                                                 {
635                                                         surface_pen.set_alpha(x2e);
636                                                         for(int i=y1; i<y2; i++) // maybe draw pixels along the right edge
637                                                         {
638                                                                 surface_pen.put_value(color);
639                                                                 surface_pen.dec_y();
640                                                         }
641                                                         if (y1e!=0)     // maybe draw top right pixel
642                                                         {
643                                                                 surface_pen.set_alpha(x2e*y1e);
644                                                                 surface_pen.put_value(color);
645                                                         }
646                                                         surface_pen.dec_x();
647                                                 }
648                                                 else
649                                                         surface_pen.move_to(x2-1,y1-1);
650
651                                                 if (y1e!=0)     // maybe draw top edge
652                                                 {
653                                                         surface_pen.set_alpha(y1e);
654                                                         for(int i=x1; i<x2; i++) // maybe draw pixels along the top edge
655                                                         {
656                                                                 surface_pen.put_value(color);
657                                                                 surface_pen.dec_x();
658                                                         }
659                                                 }
660                                         }
661                                 }
662                         }
663
664                         if (reverse)
665                         {
666                                 if (--iter == particle_list.begin())
667                                         break;
668                         }
669                         else
670                         {
671                                 if (++iter == particle_list.end())
672                                         break;
673                         }
674                 }
675         }
676
677         Surface::alpha_pen pen(surface->get_pen(0,0),get_amount(),get_blend_method());
678         dest_surface.blit_to(pen);
679
680         return true;
681 }
682
683 Rect
684 Plant::get_bounding_rect(Context context)const
685 {
686         if(needs_sync_==true)
687                 sync();
688
689         if(is_disabled())
690                 return Rect::zero();
691
692         if(Color::is_onto(get_blend_method()))
693                 return context.get_full_bounding_rect() & bounding_rect;
694
695         //if(get_blend_method()==Color::BLEND_BEHIND)
696         //      return context.get_full_bounding_rect() | bounding_rect;
697         return bounding_rect;
698 }