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 foreground_;
61 static Color background_;
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_foreground_color_changed_;
74 trivial<sigc::signal<void> > signal_background_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);
105 action_main=new synfigapp::Action::Main();
107 settings_.construct();
109 signal_foreground_color_changed_.construct();
110 signal_background_color_changed_.construct();
111 signal_gradient_changed_.construct();
112 signal_opacity_changed_.construct();
113 signal_blend_method_changed_.construct();
114 signal_interpolation_changed_.construct();
116 set_foreground_color(Color::black());
117 set_background_color(Color::white());
118 set_gradient_default_colors();
119 set_bline_width(Distance(1,Distance::SYSTEM_POINTS));
121 set_blend_method(Color::BLEND_COMPOSITE);
124 synfigapp::Main::~Main()
127 if(!synfigapp_ref_count_.unique())
129 synfigapp_ref_count_.detach();
131 // Add deinitialization after this point
135 selected_input_device_=0;
136 input_devices_.clear();
138 settings_.destruct();
139 signal_foreground_color_changed_.destruct();
140 signal_background_color_changed_.destruct();
141 signal_gradient_changed_.destruct();
143 signal_opacity_changed_.destruct();
144 signal_blend_method_changed_.destruct();
145 signal_interpolation_changed_.destruct();
149 synfigapp::Main::settings()
155 synfigapp::Main::signal_foreground_color_changed()
157 return signal_foreground_color_changed_;
161 synfigapp::Main::signal_background_color_changed()
163 return signal_background_color_changed_;
167 synfigapp::Main::signal_gradient_changed()
169 return signal_gradient_changed_;
173 synfigapp::Main::signal_bline_width_changed()
175 return signal_bline_width_changed_;
179 synfigapp::Main::signal_blend_method_changed()
181 return signal_blend_method_changed_;
185 synfigapp::Main::signal_opacity_changed()
187 return signal_opacity_changed_;
191 synfigapp::Main::signal_interpolation_changed()
193 return signal_interpolation_changed_;
197 synfigapp::Main::get_foreground_color()
203 synfigapp::Main::get_background_color()
208 const synfig::Gradient&
209 synfigapp::Main::get_gradient()
215 synfigapp::Main::get_opacity()
220 synfig::Color::BlendMethod
221 synfigapp::Main::get_blend_method()
223 return blend_method_;
227 synfigapp::Main::set_foreground_color(synfig::Color color)
230 signal_foreground_color_changed()();
231 if(selected_input_device_)
232 selected_input_device_->set_foreground_color(foreground_);
233 if(gradient_default_colors_)
235 gradient_=Gradient(foreground_,background_);
236 signal_gradient_changed()();
241 synfigapp::Main::set_background_color(synfig::Color color)
244 signal_background_color_changed()();
246 if(selected_input_device_)
247 selected_input_device_->set_background_color(background_);
249 if(gradient_default_colors_)
251 gradient_=Gradient(foreground_,background_);
252 signal_gradient_changed()();
257 synfigapp::Main::set_gradient(synfig::Gradient gradient)
260 gradient_default_colors_=false;
261 signal_gradient_changed()();
265 synfigapp::Main::set_gradient_default_colors()
267 gradient_default_colors_=true;
268 gradient_=Gradient(foreground_,background_);
269 signal_gradient_changed()();
273 synfigapp::Main::color_swap()
275 const Color tmp(foreground_);
276 foreground_=background_;
279 if(selected_input_device_)
281 selected_input_device_->set_foreground_color(foreground_);
282 selected_input_device_->set_background_color(background_);
285 signal_foreground_color_changed()();
286 signal_background_color_changed()();
288 if(gradient_default_colors_)
290 gradient_=Gradient(foreground_,background_);
291 signal_gradient_changed()();
295 synfig::Waypoint::Interpolation
296 synfigapp::Main::get_interpolation()
298 return interpolation_;
303 synfigapp::Main::set_interpolation(synfig::Waypoint::Interpolation x)
305 if(interpolation_!=x)
309 signal_interpolation_changed();
313 const synfig::Distance&
314 synfigapp::Main::get_bline_width()
320 synfigapp::Main::set_bline_width(synfig::Distance x)
327 if(selected_input_device_)
328 selected_input_device_->set_bline_width(x);
330 signal_bline_width_changed()();
335 synfigapp::Main::set_opacity(synfig::Real x)
338 if(selected_input_device_)
339 selected_input_device_->set_opacity(opacity_);
340 signal_opacity_changed()();
344 synfigapp::Main::set_blend_method(synfig::Color::BlendMethod x)
347 if(selected_input_device_)
348 selected_input_device_->set_blend_method(x);
349 signal_blend_method_changed()();
354 synfigapp::Main::add_input_device(const synfig::String id, InputDevice::Type type)
356 input_devices_.push_back(new InputDevice(id,type));
357 return input_devices_.back();
361 synfigapp::Main::find_input_device(const synfig::String id)
363 list<InputDevice::Handle>::iterator iter;
364 for(iter=input_devices_.begin();iter!=input_devices_.end();++iter)
365 if((*iter)->get_id()==id)
371 synfigapp::Main::select_input_device(const synfig::String id)
373 InputDevice::Handle input_device(find_input_device(id));
376 if(!select_input_device(input_device))
382 synfigapp::Main::select_input_device(InputDevice::Handle input_device)
384 assert(input_device);
386 // synfig::info("Input device changed to \"%s\"",input_device->get_id().c_str());
388 selected_input_device_=input_device;
390 set_bline_width(input_device->get_bline_width());
391 set_foreground_color(input_device->get_foreground_color());
392 set_opacity(input_device->get_opacity());
393 set_blend_method(input_device->get_blend_method());
399 synfigapp::Main::get_selected_input_device()
401 return selected_input_device_;
405 synfigapp::Main::set_state(synfig::String state)
407 if(selected_input_device_)
408 selected_input_device_->set_state(state);