1 /* === S Y N F I G ========================================================= */
2 /*! \file xorpattern.cpp
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "xorpattern.h"
36 #include <synfig/string.h>
37 #include <synfig/time.h>
38 #include <synfig/context.h>
39 #include <synfig/paramdesc.h>
40 #include <synfig/renddesc.h>
41 #include <synfig/surface.h>
42 #include <synfig/value.h>
43 #include <synfig/valuenode.h>
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 SYNFIG_LAYER_INIT(XORPattern);
52 SYNFIG_LAYER_SET_NAME(XORPattern,"xor_pattern");
53 SYNFIG_LAYER_SET_LOCAL_NAME(XORPattern,_("XOR Pattern"));
54 SYNFIG_LAYER_SET_CATEGORY(XORPattern,_("Other"));
55 SYNFIG_LAYER_SET_VERSION(XORPattern,"0.1");
56 SYNFIG_LAYER_SET_CVS_ID(XORPattern,"$Id$");
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 XORPattern::XORPattern():
63 Layer_Composite (1.0,Color::BLEND_STRAIGHT),
70 XORPattern::set_param(const String & param, const ValueBase &value)
75 return Layer_Composite::set_param(param,value);
79 XORPattern::get_param(const String & param)const
87 return Layer_Composite::get_param(param);
91 XORPattern::get_color(Context context, const Point &point)const
94 return context.get_color(point);
96 unsigned int a=(unsigned int)floor((point[0]-pos[0])/size[0]), b=(unsigned int)floor((point[1]-pos[1])/size[1]);
97 unsigned char rindex=(a^b);
98 unsigned char gindex=(a^(~b))*4;
99 unsigned char bindex=~(a^b)*2;
101 Color color((Color::value_type)rindex/(Color::value_type)255.0,
102 (Color::value_type)gindex/(Color::value_type)255.0,
103 (Color::value_type)bindex/(Color::value_type)255.0,
106 if(get_amount() == 1 && get_blend_method() == Color::BLEND_STRAIGHT)
109 return Color::blend(color,context.get_color(point),get_amount(),get_blend_method());
114 XORPattern::get_param_vocab()const
116 Layer::Vocab ret(Layer_Composite::get_param_vocab());
118 ret.push_back(ParamDesc("pos")
119 .set_local_name(_("Offset"))
121 ret.push_back(ParamDesc("size")
122 .set_local_name(_("Size"))
129 synfig::Layer::Handle
130 XORPattern::hit_check(synfig::Context context, const synfig::Point &getpos)const
132 // if we have a zero amount
133 if(get_amount()==0.0)
134 // then the click passes down to our context
135 return context.hit_check(getpos);
137 synfig::Layer::Handle tmp;
138 // if we are behind the context, and the click hits something in the context
139 if(get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(getpos)))
140 // then return the thing it hit in the context
143 // if we're using an 'onto' blend method and the click missed the context
144 if(Color::is_onto(get_blend_method()) && !(tmp=context.hit_check(getpos)))
145 // then it misses everything
148 // otherwise the click hit us, since we're the size of the whole plane
149 return const_cast<XORPattern*>(this);