Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_05 / synfig-core / src / modules / lyr_std / xorpattern.cpp
1 /*! ========================================================================
2 ** Synfig
3 ** Template File
4 ** $Id: xorpattern.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
5 **
6 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **
8 **      This package is free software; you can redistribute it and/or
9 **      modify it under the terms of the GNU General Public License as
10 **      published by the Free Software Foundation; either version 2 of
11 **      the License, or (at your option) any later version.
12 **
13 **      This package is distributed in the hope that it will be useful,
14 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
15 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 **      General Public License for more details.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "xorpattern.h"
32
33 #include <synfig/string.h>
34 #include <synfig/time.h>
35 #include <synfig/context.h>
36 #include <synfig/paramdesc.h>
37 #include <synfig/renddesc.h>
38 #include <synfig/surface.h>
39 #include <synfig/value.h>
40 #include <synfig/valuenode.h>
41
42 #endif
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 SYNFIG_LAYER_INIT(XORPattern);
49 SYNFIG_LAYER_SET_NAME(XORPattern,"XORPattern");
50 SYNFIG_LAYER_SET_LOCAL_NAME(XORPattern,_("XOR Pattern"));
51 SYNFIG_LAYER_SET_CATEGORY(XORPattern,_("Other"));
52 SYNFIG_LAYER_SET_VERSION(XORPattern,"0.1");
53 SYNFIG_LAYER_SET_CVS_ID(XORPattern,"$Id: xorpattern.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 XORPattern::XORPattern():
60         pos(0.125,0.125),
61         size(0.25,0.25)
62 {
63 }
64         
65 bool
66 XORPattern::set_param(const String & param, const ValueBase &value)
67 {
68         IMPORT(pos);
69         IMPORT(size);
70         return false;
71 }
72
73 ValueBase
74 XORPattern::get_param(const String & param)const
75 {
76         EXPORT(pos);
77         EXPORT(size);
78         
79         EXPORT_NAME();
80         EXPORT_VERSION();
81                 
82         return ValueBase();     
83 }
84
85 Color
86 XORPattern::get_color(Context context, const Point &point)const
87 {
88         unsigned int a=(unsigned int)floor((point[0]+pos[0])/size[0]), b=(unsigned int)floor((point[1]+pos[1])/size[1]);
89         unsigned char rindex=(a^b);
90         unsigned char gindex=(a^(~b))*4;
91         unsigned char bindex=~(a^b)*2;
92
93         return Color((Color::value_type)rindex/(Color::value_type)255.0,(Color::value_type)gindex/(Color::value_type)255.0,(Color::value_type)bindex/(Color::value_type)255.0,1.0);
94 }
95         
96 Layer::Vocab
97 XORPattern::get_param_vocab()const
98 {
99         Layer::Vocab ret;
100         
101         ret.push_back(ParamDesc("pos")
102                 .set_local_name(_("Offset"))
103         );
104         ret.push_back(ParamDesc("size")
105                 .set_local_name(_("Size"))
106                 .set_origin("pos")
107         );
108         
109         return ret;
110 }