1 /* === S Y N F I G ========================================================= */
2 /*! \file xorpattern.cpp
3 ** \brief Implementation of the "XOR Pattern" 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 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
35 #include "xorpattern.h"
37 #include <synfig/string.h>
38 #include <synfig/time.h>
39 #include <synfig/context.h>
40 #include <synfig/paramdesc.h>
41 #include <synfig/renddesc.h>
42 #include <synfig/surface.h>
43 #include <synfig/value.h>
44 #include <synfig/valuenode.h>
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 SYNFIG_LAYER_INIT(XORPattern);
53 SYNFIG_LAYER_SET_NAME(XORPattern,"xor_pattern");
54 SYNFIG_LAYER_SET_LOCAL_NAME(XORPattern,N_("XOR Pattern"));
55 SYNFIG_LAYER_SET_CATEGORY(XORPattern,N_("Other"));
56 SYNFIG_LAYER_SET_VERSION(XORPattern,"0.1");
57 SYNFIG_LAYER_SET_CVS_ID(XORPattern,"$Id$");
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 XORPattern::XORPattern():
64 Layer_Composite(1.0,Color::BLEND_COMPOSITE),
68 Layer::Vocab voc(get_param_vocab());
69 Layer::fill_static(voc);
73 XORPattern::set_param(const String & param, const ValueBase &value)
78 IMPORT_AS(origin,"pos");
80 return Layer_Composite::set_param(param,value);
84 XORPattern::get_param(const String & param)const
92 return Layer_Composite::get_param(param);
96 XORPattern::get_color(Context context, const Point &point)const
99 return context.get_color(point);
101 unsigned int a=(unsigned int)floor((point[0]-origin[0])/size[0]), b=(unsigned int)floor((point[1]-origin[1])/size[1]);
102 unsigned char rindex=(a^b);
103 unsigned char gindex=(a^(~b))*4;
104 unsigned char bindex=~(a^b)*2;
106 Color color((Color::value_type)rindex/(Color::value_type)255.0,
107 (Color::value_type)gindex/(Color::value_type)255.0,
108 (Color::value_type)bindex/(Color::value_type)255.0,
111 if(get_amount() == 1 && get_blend_method() == Color::BLEND_STRAIGHT)
114 return Color::blend(color,context.get_color(point),get_amount(),get_blend_method());
119 XORPattern::get_param_vocab()const
121 Layer::Vocab ret(Layer_Composite::get_param_vocab());
123 ret.push_back(ParamDesc("origin")
124 .set_local_name(_("Origin"))
126 ret.push_back(ParamDesc("size")
127 .set_local_name(_("Size"))
128 .set_origin("origin")
134 synfig::Layer::Handle
135 XORPattern::hit_check(synfig::Context context, const synfig::Point &getpos)const
137 // if we have a zero amount
138 if(get_amount()==0.0)
139 // then the click passes down to our context
140 return context.hit_check(getpos);
142 synfig::Layer::Handle tmp;
143 // if we are behind the context, and the click hits something in the context
144 if(get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(getpos)))
145 // then return the thing it hit in the context
148 // if we're using an 'onto' blend method and the click missed the context
149 if(Color::is_onto(get_blend_method()) && !(tmp=context.hit_check(getpos)))
150 // then it misses everything
153 // otherwise the click hit us, since we're the size of the whole plane
154 return const_cast<XORPattern*>(this);