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
9 ** Copyright (c) 2007 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,_("XOR Pattern"));
55 SYNFIG_LAYER_SET_CATEGORY(XORPattern,_("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 return Layer_Composite::set_param(param,value);
80 XORPattern::get_param(const String & param)const
88 return Layer_Composite::get_param(param);
92 XORPattern::get_color(Context context, const Point &point)const
95 return context.get_color(point);
97 unsigned int a=(unsigned int)floor((point[0]-pos[0])/size[0]), b=(unsigned int)floor((point[1]-pos[1])/size[1]);
98 unsigned char rindex=(a^b);
99 unsigned char gindex=(a^(~b))*4;
100 unsigned char bindex=~(a^b)*2;
102 Color color((Color::value_type)rindex/(Color::value_type)255.0,
103 (Color::value_type)gindex/(Color::value_type)255.0,
104 (Color::value_type)bindex/(Color::value_type)255.0,
107 if(get_amount() == 1 && get_blend_method() == Color::BLEND_STRAIGHT)
110 return Color::blend(color,context.get_color(point),get_amount(),get_blend_method());
115 XORPattern::get_param_vocab()const
117 Layer::Vocab ret(Layer_Composite::get_param_vocab());
119 ret.push_back(ParamDesc("pos")
120 .set_local_name(_("Offset"))
122 ret.push_back(ParamDesc("size")
123 .set_local_name(_("Size"))
130 synfig::Layer::Handle
131 XORPattern::hit_check(synfig::Context context, const synfig::Point &getpos)const
133 // if we have a zero amount
134 if(get_amount()==0.0)
135 // then the click passes down to our context
136 return context.hit_check(getpos);
138 synfig::Layer::Handle tmp;
139 // if we are behind the context, and the click hits something in the context
140 if(get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(getpos)))
141 // then return the thing it hit in the context
144 // if we're using an 'onto' blend method and the click missed the context
145 if(Color::is_onto(get_blend_method()) && !(tmp=context.hit_check(getpos)))
146 // then it misses everything
149 // otherwise the click hit us, since we're the size of the whole plane
150 return const_cast<XORPattern*>(this);