Use lower_case "xor_pattern" in .sif files rather than "XORPattern".
[synfig.git] / synfig-core / trunk / src / modules / lyr_std / xorpattern.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file xorpattern.cpp
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 **
21 ** === N O T E S ===========================================================
22 **
23 ** ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include "xorpattern.h"
35
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>
44
45 #endif
46
47 /* === M A C R O S ========================================================= */
48
49 /* === G L O B A L S ======================================================= */
50
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$");
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 XORPattern::XORPattern():
63         pos(0.125,0.125),
64         size(0.25,0.25)
65 {
66 }
67
68 bool
69 XORPattern::set_param(const String & param, const ValueBase &value)
70 {
71         IMPORT(pos);
72         IMPORT(size);
73         return false;
74 }
75
76 ValueBase
77 XORPattern::get_param(const String & param)const
78 {
79         EXPORT(pos);
80         EXPORT(size);
81
82         EXPORT_NAME();
83         EXPORT_VERSION();
84
85         return ValueBase();
86 }
87
88 Color
89 XORPattern::get_color(Context context, const Point &point)const
90 {
91         unsigned int a=(unsigned int)floor((point[0]+pos[0])/size[0]), b=(unsigned int)floor((point[1]+pos[1])/size[1]);
92         unsigned char rindex=(a^b);
93         unsigned char gindex=(a^(~b))*4;
94         unsigned char bindex=~(a^b)*2;
95
96         return Color((Color::value_type)rindex/(Color::value_type)255.0,
97                                  (Color::value_type)gindex/(Color::value_type)255.0,
98                                  (Color::value_type)bindex/(Color::value_type)255.0,
99                                  1.0);
100 }
101
102 Layer::Vocab
103 XORPattern::get_param_vocab()const
104 {
105         Layer::Vocab ret;
106
107         ret.push_back(ParamDesc("pos")
108                 .set_local_name(_("Offset"))
109         );
110         ret.push_back(ParamDesc("size")
111                 .set_local_name(_("Size"))
112                 .set_origin("pos")
113         );
114
115         return ret;
116 }