moreupdates
[synfig.git] / synfig-core / trunk / 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 Robert B. Quattlebaum Jr.
7 **
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
11 **
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
16 **
17 ** === N O T E S ===========================================================
18 **
19 ** ========================================================================= */
20
21 /* === H E A D E R S ======================================================= */
22
23 #ifdef USING_PCH
24 #       include "pch.h"
25 #else
26 #ifdef HAVE_CONFIG_H
27 #       include <config.h>
28 #endif
29
30 #include "xorpattern.h"
31
32 #include <synfig/string.h>
33 #include <synfig/time.h>
34 #include <synfig/context.h>
35 #include <synfig/paramdesc.h>
36 #include <synfig/renddesc.h>
37 #include <synfig/surface.h>
38 #include <synfig/value.h>
39 #include <synfig/valuenode.h>
40
41 #endif
42
43 /* === M A C R O S ========================================================= */
44
45 /* === G L O B A L S ======================================================= */
46
47 SYNFIG_LAYER_INIT(XORPattern);
48 SYNFIG_LAYER_SET_NAME(XORPattern,"XORPattern");
49 SYNFIG_LAYER_SET_LOCAL_NAME(XORPattern,_("XOR Pattern"));
50 SYNFIG_LAYER_SET_CATEGORY(XORPattern,_("Other"));
51 SYNFIG_LAYER_SET_VERSION(XORPattern,"0.1");
52 SYNFIG_LAYER_SET_CVS_ID(XORPattern,"$Id: xorpattern.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 XORPattern::XORPattern():
59         pos(0.125,0.125),
60         size(0.25,0.25)
61 {
62 }
63         
64 bool
65 XORPattern::set_param(const String & param, const ValueBase &value)
66 {
67         IMPORT(pos);
68         IMPORT(size);
69         return false;
70 }
71
72 ValueBase
73 XORPattern::get_param(const String & param)const
74 {
75         EXPORT(pos);
76         EXPORT(size);
77         
78         EXPORT_NAME();
79         EXPORT_VERSION();
80                 
81         return ValueBase();     
82 }
83
84 Color
85 XORPattern::get_color(Context context, const Point &point)const
86 {
87         unsigned int a=(unsigned int)floor((point[0]+pos[0])/size[0]), b=(unsigned int)floor((point[1]+pos[1])/size[1]);
88         unsigned char rindex=(a^b);
89         unsigned char gindex=(a^(~b))*4;
90         unsigned char bindex=~(a^b)*2;
91
92         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);
93 }
94         
95 Layer::Vocab
96 XORPattern::get_param_vocab()const
97 {
98         Layer::Vocab ret;
99         
100         ret.push_back(ParamDesc("pos")
101                 .set_local_name(_("Offset"))
102         );
103         ret.push_back(ParamDesc("size")
104                 .set_local_name(_("Size"))
105                 .set_origin("pos")
106         );
107         
108         return ret;
109 }