1 /* === S Y N F I G ========================================================= */
2 /*! \file checkerboard.cpp
3 ** \brief Implementation of the "Checkerboard" layer
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "checkerboard.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 #include <synfig/segment.h>
47 using namespace synfig;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 SYNFIG_LAYER_INIT(CheckerBoard);
56 SYNFIG_LAYER_SET_NAME(CheckerBoard,"checker_board");
57 SYNFIG_LAYER_SET_LOCAL_NAME(CheckerBoard,N_("Checkerboard"));
58 SYNFIG_LAYER_SET_CATEGORY(CheckerBoard,N_("Geometry"));
59 SYNFIG_LAYER_SET_VERSION(CheckerBoard,"0.1");
60 SYNFIG_LAYER_SET_CVS_ID(CheckerBoard,"$Id$");
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 CheckerBoard::CheckerBoard():
67 Layer_Composite (1.0,Color::BLEND_STRAIGHT),
68 color (Color::black()),
69 origin (Point(0.125,0.125)),
70 size (Point(0.25,0.25))
73 set_blend_method(Color::BLEND_STRAIGHT);
77 CheckerBoard::point_test(const synfig::Point& getpos)const
79 int val=((int)((getpos[0]-origin[0])/size[0])+(int)((getpos[1]-origin[1])/size[1]));
80 if(getpos[0]-origin[0] < 0.0)
82 if(getpos[1]-origin[1] < 0.0)
88 CheckerBoard::set_param(const String ¶m, const ValueBase &value)
90 IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) {
91 set_blend_method(Color::BLEND_ALPHA_OVER);
92 color.set_a(1); } else transparent_color_ = true; } });
96 IMPORT_AS(origin,"pos");
97 IMPORT_AS(origin[0],"pos[0]");
98 IMPORT_AS(origin[1],"pos[1]");
100 return Layer_Composite::set_param(param,value);
104 CheckerBoard::get_param(const String ¶m)const
112 return Layer_Composite::get_param(param);
116 CheckerBoard::get_param_vocab()const
118 Layer::Vocab ret(Layer_Composite::get_param_vocab());
120 ret.push_back(ParamDesc("color")
121 .set_local_name(_("Color"))
122 .set_description(_("Color of checkers"))
124 ret.push_back(ParamDesc("origin")
125 .set_local_name(_("Origin"))
127 ret.push_back(ParamDesc("size")
128 .set_local_name(_("Size"))
129 .set_description(_("Size of checkers"))
130 .set_origin("origin")
136 synfig::Layer::Handle
137 CheckerBoard::hit_check(synfig::Context context, const synfig::Point &getpos)const
139 if(get_amount()!=0.0 && point_test(getpos))
141 synfig::Layer::Handle tmp;
142 if(get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(getpos)))
144 if(Color::is_onto(get_blend_method()) && !(tmp=context.hit_check(getpos)))
146 return const_cast<CheckerBoard*>(this);
149 return context.hit_check(getpos);
153 CheckerBoard::get_color(Context context, const Point &getpos)const
155 if(get_amount()!=0.0 && point_test(getpos))
157 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
160 return Color::blend(color,context.get_color(getpos),get_amount(),get_blend_method());
163 return Color::blend(Color::alpha(),context.get_color(getpos),get_amount(),get_blend_method());
167 CheckerBoard::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
169 SuperCallback supercb(cb,0,9500,10000);
171 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
178 const Point tl(renddesc.get_tl());
180 const int w(surface->get_w());
181 const int h(surface->get_h());
182 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
184 Surface::alpha_pen apen(surface->begin());
186 apen.set_alpha(get_amount());
187 apen.set_blend_method(get_blend_method());
188 apen.set_value(color);
190 for(y=0,pos[1]=tl[1];y<h;y++,apen.inc_y(),apen.dec_x(x),pos[1]+=ph)
191 for(x=0,pos[0]=tl[0];x<w;x++,apen.inc_x(),pos[0]+=pw)
195 // Mark our progress as finished
196 if(cb && !cb->amount_complete(10000,10000))