1 /* === S Y N F I G ========================================================= */
2 /*! \file synfigapp/main.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
35 #include <synfig/color.h>
36 #include <synfig/gradient.h>
38 #include <ETL/trivial>
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace synfigapp;
53 /* === M A C R O S ========================================================= */
55 /* === S T A T I C S ======================================================= */
57 static etl::reference_counter synfigapp_ref_count_(0);
58 static synfigapp::Action::Main* action_main;
60 static Color outline_;
62 static Gradient gradient_;
63 static bool gradient_default_colors_;
65 static synfig::Distance bline_width_;
67 static Color::BlendMethod blend_method_;
70 static synfigapp::InputDevice::Handle selected_input_device_;
71 static list<synfigapp::InputDevice::Handle> input_devices_;
73 trivial<sigc::signal<void> > signal_outline_color_changed_;
74 trivial<sigc::signal<void> > signal_fill_color_changed_;
75 trivial<sigc::signal<void> > signal_gradient_changed_;
76 trivial<sigc::signal<void> > signal_bline_width_changed_;
77 trivial<sigc::signal<void> > signal_blend_method_changed_;
78 trivial<sigc::signal<void> > signal_opacity_changed_;
79 trivial<sigc::signal<void> > signal_interpolation_changed_;
81 trivial<Settings> settings_;
83 static synfig::Waypoint::Interpolation interpolation_;
85 /* === P R O C E D U R E S ================================================= */
87 /* === M E T H O D S ======================================================= */
89 synfigapp::Main::Main(const synfig::String &basepath, synfig::ProgressCallback *cb):
90 synfig::Main(basepath,cb),
91 ref_count_(synfigapp_ref_count_)
93 if(ref_count_.count())
96 synfigapp_ref_count_.reset();
97 ref_count_=synfigapp_ref_count_;
99 // Add initialization after this point
102 bindtextdomain("synfigstudio", LOCALEDIR);
103 bind_textdomain_codeset("synfigstudio", "UTF-8");
106 action_main=new synfigapp::Action::Main();
108 settings_.construct();
110 signal_outline_color_changed_.construct();
111 signal_fill_color_changed_.construct();
112 signal_gradient_changed_.construct();
113 signal_opacity_changed_.construct();
114 signal_blend_method_changed_.construct();
115 signal_interpolation_changed_.construct();
117 set_outline_color(Color::black());
118 set_fill_color(Color::white());
119 set_gradient_default_colors();
120 set_bline_width(Distance(1,Distance::SYSTEM_POINTS));
122 set_blend_method(Color::BLEND_COMPOSITE);
125 synfigapp::Main::~Main()
128 if(!synfigapp_ref_count_.unique())
130 synfigapp_ref_count_.detach();
132 // Add deinitialization after this point
136 selected_input_device_=0;
137 input_devices_.clear();
139 settings_.destruct();
140 signal_outline_color_changed_.destruct();
141 signal_fill_color_changed_.destruct();
142 signal_gradient_changed_.destruct();
144 signal_opacity_changed_.destruct();
145 signal_blend_method_changed_.destruct();
146 signal_interpolation_changed_.destruct();
150 synfigapp::Main::settings()
156 synfigapp::Main::signal_outline_color_changed()
158 return signal_outline_color_changed_;
162 synfigapp::Main::signal_fill_color_changed()
164 return signal_fill_color_changed_;
168 synfigapp::Main::signal_gradient_changed()
170 return signal_gradient_changed_;
174 synfigapp::Main::signal_bline_width_changed()
176 return signal_bline_width_changed_;
180 synfigapp::Main::signal_blend_method_changed()
182 return signal_blend_method_changed_;
186 synfigapp::Main::signal_opacity_changed()
188 return signal_opacity_changed_;
192 synfigapp::Main::signal_interpolation_changed()
194 return signal_interpolation_changed_;
198 synfigapp::Main::get_outline_color()
204 synfigapp::Main::get_fill_color()
209 const synfig::Gradient&
210 synfigapp::Main::get_gradient()
216 synfigapp::Main::get_opacity()
221 synfig::Color::BlendMethod
222 synfigapp::Main::get_blend_method()
224 return blend_method_;
228 synfigapp::Main::set_outline_color(synfig::Color color)
231 signal_outline_color_changed()();
232 if(selected_input_device_)
233 selected_input_device_->set_outline_color(outline_);
234 if(gradient_default_colors_)
236 gradient_=Gradient(fill_,outline_);
237 signal_gradient_changed()();
242 synfigapp::Main::set_fill_color(synfig::Color color)
245 signal_fill_color_changed()();
247 if(selected_input_device_)
248 selected_input_device_->set_fill_color(fill_);
250 if(gradient_default_colors_)
252 gradient_=Gradient(fill_,outline_);
253 signal_gradient_changed()();
258 synfigapp::Main::set_gradient(synfig::Gradient gradient)
261 gradient_default_colors_=false;
262 signal_gradient_changed()();
266 synfigapp::Main::set_gradient_default_colors()
268 gradient_default_colors_=true;
269 gradient_=Gradient(fill_,outline_);
270 signal_gradient_changed()();
274 synfigapp::Main::color_swap()
276 const Color tmp(outline_);
280 if(selected_input_device_)
282 selected_input_device_->set_outline_color(outline_);
283 selected_input_device_->set_fill_color(fill_);
286 signal_outline_color_changed()();
287 signal_fill_color_changed()();
289 if(gradient_default_colors_)
291 gradient_=Gradient(fill_,outline_);
292 signal_gradient_changed()();
296 synfig::Waypoint::Interpolation
297 synfigapp::Main::get_interpolation()
299 return interpolation_;
304 synfigapp::Main::set_interpolation(synfig::Waypoint::Interpolation x)
306 if(interpolation_!=x)
310 signal_interpolation_changed();
314 const synfig::Distance&
315 synfigapp::Main::get_bline_width()
321 synfigapp::Main::set_bline_width(synfig::Distance x)
328 if(selected_input_device_)
329 selected_input_device_->set_bline_width(x);
331 signal_bline_width_changed()();
336 synfigapp::Main::set_opacity(synfig::Real x)
339 if(selected_input_device_)
340 selected_input_device_->set_opacity(opacity_);
341 signal_opacity_changed()();
345 synfigapp::Main::set_blend_method(synfig::Color::BlendMethod x)
348 if(selected_input_device_)
349 selected_input_device_->set_blend_method(x);
350 signal_blend_method_changed()();
355 synfigapp::Main::add_input_device(const synfig::String id, InputDevice::Type type)
357 input_devices_.push_back(new InputDevice(id,type));
358 return input_devices_.back();
362 synfigapp::Main::find_input_device(const synfig::String id)
364 list<InputDevice::Handle>::iterator iter;
365 for(iter=input_devices_.begin();iter!=input_devices_.end();++iter)
366 if((*iter)->get_id()==id)
372 synfigapp::Main::select_input_device(const synfig::String id)
374 InputDevice::Handle input_device(find_input_device(id));
377 if(!select_input_device(input_device))
383 synfigapp::Main::select_input_device(InputDevice::Handle input_device)
385 assert(input_device);
387 // synfig::info("Input device changed to \"%s\"",input_device->get_id().c_str());
389 selected_input_device_=input_device;
391 set_bline_width(input_device->get_bline_width());
392 set_outline_color(input_device->get_outline_color());
393 set_fill_color(input_device->get_fill_color());
394 set_opacity(input_device->get_opacity());
395 set_blend_method(input_device->get_blend_method());
401 synfigapp::Main::get_selected_input_device()
403 return selected_input_device_;
407 synfigapp::Main::set_state(synfig::String state)
409 if(selected_input_device_)
410 selected_input_device_->set_state(state);