Use LinkableValueNode members functions when possible in the derived valuenodes.
[synfig.git] / synfig-core / src / synfig / target.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file target.cpp
3 **      \brief Target Class Implementation
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **  Copyright (c) 2010 Diego Barrios Romero
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29
30 #include "target.h"
31 #include "string.h"
32 #include "canvas.h"
33 #include "target_null.h"
34 #include "target_null_tile.h"
35 #include "targetparam.h"
36
37 using namespace synfig;
38 using namespace etl;
39 using namespace std;
40
41 synfig::Target::Book* synfig::Target::book_;
42 synfig::Target::ExtBook* synfig::Target::ext_book_;
43
44 static synfig::Gamma* default_gamma_;
45
46 /* === P R O C E D U R E S ================================================= */
47
48 bool
49 Target::subsys_init()
50 {
51         book_=new synfig::Target::Book();
52         ext_book_=new synfig::Target::ExtBook();
53 //! \todo Do not hard core gamma to 2.2
54         default_gamma_=new synfig::Gamma(1.0/2.2);
55
56         // At least one target must be available.
57         book()["null"].factory =
58                 reinterpret_cast<synfig::Target::Factory>(&Target_Null::create);
59         book()["null"].filename = "null";
60         book()["null"].target_param = TargetParam();
61         ext_book()["null"]="null";
62
63         book()["null-tile"].factory =
64                 reinterpret_cast<synfig::Target::Factory>(&Target_Null_Tile::create);
65         book()["null-tile"].filename = "null-tile";
66         book()["null-tile"].target_param = TargetParam();
67         ext_book()["null-tile"]="null-tile";
68
69         return true;
70 }
71
72 bool
73 Target::subsys_stop()
74 {
75         delete book_;
76         delete ext_book_;
77         delete default_gamma_;
78         return true;
79 }
80
81 Target::Book&
82 Target::book()
83 {
84         return *book_;
85 }
86
87 Target::ExtBook&
88 Target::ext_book()
89 {
90         return *ext_book_;
91 }
92
93
94 /* === M E T H O D S ======================================================= */
95
96 Target::Target():
97         quality_(4),
98         gamma_(*default_gamma_),
99         remove_alpha(false),
100         avoid_time_sync_(false)
101 {
102 }
103
104 void
105 synfig::Target::set_canvas(etl::handle<Canvas> c)
106 {
107         canvas=c;
108         RendDesc desc=canvas->rend_desc();
109         set_rend_desc(&desc);
110 }
111
112
113 Target::Handle
114 Target::create(const String &name, const String &filename,
115                            synfig::TargetParam params)
116 {
117         if(!book().count(name))
118                 return handle<Target>();
119
120         return Target::Handle(book()[name].factory(filename.c_str(), params));
121 }