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_STRAIGHT),
71 XORPattern::set_param(const String & param, const ValueBase &value)
76 IMPORT_AS(origin,"pos");
78 return Layer_Composite::set_param(param,value);
82 XORPattern::get_param(const String & param)const
90 return Layer_Composite::get_param(param);
94 XORPattern::get_color(Context context, const Point &point)const
97 return context.get_color(point);
99 unsigned int a=(unsigned int)floor((point[0]-origin[0])/size[0]), b=(unsigned int)floor((point[1]-origin[1])/size[1]);
100 unsigned char rindex=(a^b);
101 unsigned char gindex=(a^(~b))*4;
102 unsigned char bindex=~(a^b)*2;
104 Color color((Color::value_type)rindex/(Color::value_type)255.0,
105 (Color::value_type)gindex/(Color::value_type)255.0,
106 (Color::value_type)bindex/(Color::value_type)255.0,
109 if(get_amount() == 1 && get_blend_method() == Color::BLEND_STRAIGHT)
112 return Color::blend(color,context.get_color(point),get_amount(),get_blend_method());
117 XORPattern::get_param_vocab()const
119 Layer::Vocab ret(Layer_Composite::get_param_vocab());
121 ret.push_back(ParamDesc("origin")
122 .set_local_name(_("Origin"))
124 ret.push_back(ParamDesc("size")
125 .set_local_name(_("Size"))
126 .set_origin("origin")
132 synfig::Layer::Handle
133 XORPattern::hit_check(synfig::Context context, const synfig::Point &getpos)const
135 // if we have a zero amount
136 if(get_amount()==0.0)
137 // then the click passes down to our context
138 return context.hit_check(getpos);
140 synfig::Layer::Handle tmp;
141 // if we are behind the context, and the click hits something in the context
142 if(get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(getpos)))
143 // then return the thing it hit in the context
146 // if we're using an 'onto' blend method and the click missed the context
147 if(Color::is_onto(get_blend_method()) && !(tmp=context.hit_check(getpos)))
148 // then it misses everything
151 // otherwise the click hit us, since we're the size of the whole plane
152 return const_cast<XORPattern*>(this);