1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: main.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
49 using namespace synfigapp;
51 /* === M A C R O S ========================================================= */
53 /* === S T A T I C S ======================================================= */
55 static etl::reference_counter synfigapp_ref_count_(0);
56 static synfigapp::Action::Main* action_main;
58 static Color foreground_;
59 static Color background_;
60 static Gradient gradient_;
61 static bool gradient_default_colors_;
63 static synfig::Distance bline_width_;
65 static Color::BlendMethod blend_method_;
68 static synfigapp::InputDevice::Handle selected_input_device_;
69 static list<synfigapp::InputDevice::Handle> input_devices_;
71 trivial<sigc::signal<void> > signal_foreground_color_changed_;
72 trivial<sigc::signal<void> > signal_background_color_changed_;
73 trivial<sigc::signal<void> > signal_gradient_changed_;
74 trivial<sigc::signal<void> > signal_bline_width_changed_;
75 trivial<sigc::signal<void> > signal_blend_method_changed_;
76 trivial<sigc::signal<void> > signal_opacity_changed_;
77 trivial<sigc::signal<void> > signal_interpolation_changed_;
79 trivial<Settings> settings_;
81 static synfig::Waypoint::Interpolation interpolation_;
83 /* === P R O C E D U R E S ================================================= */
85 /* === M E T H O D S ======================================================= */
87 synfigapp::Main::Main(const synfig::String &basepath,ProgressCallback *cb):
88 synfig::Main(basepath,cb),
89 ref_count_(synfigapp_ref_count_)
91 if(ref_count_.count())
94 synfigapp_ref_count_.reset();
95 ref_count_=synfigapp_ref_count_;
97 // Add initialization after this point
98 action_main=new synfigapp::Action::Main();
100 settings_.construct();
102 signal_foreground_color_changed_.construct();
103 signal_background_color_changed_.construct();
104 signal_gradient_changed_.construct();
105 signal_opacity_changed_.construct();
106 signal_blend_method_changed_.construct();
107 signal_interpolation_changed_.construct();
109 set_foreground_color(Color::black());
110 set_background_color(Color::white());
111 set_gradient_default_colors();
112 set_bline_width(Distance(1,Distance::SYSTEM_POINTS));
114 set_blend_method(Color::BLEND_COMPOSITE);
117 synfigapp::Main::~Main()
120 if(!synfigapp_ref_count_.unique())
122 synfigapp_ref_count_.detach();
124 // Add deinitialization after this point
128 selected_input_device_=0;
129 input_devices_.clear();
131 settings_.destruct();
132 signal_foreground_color_changed_.destruct();
133 signal_background_color_changed_.destruct();
134 signal_gradient_changed_.destruct();
136 signal_opacity_changed_.destruct();
137 signal_blend_method_changed_.destruct();
138 signal_interpolation_changed_.destruct();
142 synfigapp::Main::settings()
148 synfigapp::Main::signal_foreground_color_changed()
150 return signal_foreground_color_changed_;
154 synfigapp::Main::signal_background_color_changed()
156 return signal_background_color_changed_;
160 synfigapp::Main::signal_gradient_changed()
162 return signal_gradient_changed_;
166 synfigapp::Main::signal_bline_width_changed()
168 return signal_bline_width_changed_;
172 synfigapp::Main::signal_blend_method_changed()
174 return signal_blend_method_changed_;
178 synfigapp::Main::signal_opacity_changed()
180 return signal_opacity_changed_;
184 synfigapp::Main::signal_interpolation_changed()
186 return signal_interpolation_changed_;
190 synfigapp::Main::get_foreground_color()
196 synfigapp::Main::get_background_color()
201 const synfig::Gradient&
202 synfigapp::Main::get_gradient()
208 synfigapp::Main::get_opacity()
213 synfig::Color::BlendMethod
214 synfigapp::Main::get_blend_method()
216 return blend_method_;
220 synfigapp::Main::set_foreground_color(synfig::Color color)
223 signal_foreground_color_changed()();
224 if(selected_input_device_)
225 selected_input_device_->set_foreground_color(foreground_);
226 if(gradient_default_colors_)
228 gradient_=Gradient(foreground_,background_);
229 signal_gradient_changed()();
234 synfigapp::Main::set_background_color(synfig::Color color)
237 signal_background_color_changed()();
239 if(selected_input_device_)
240 selected_input_device_->set_background_color(background_);
242 if(gradient_default_colors_)
244 gradient_=Gradient(foreground_,background_);
245 signal_gradient_changed()();
250 synfigapp::Main::set_gradient(synfig::Gradient gradient)
253 gradient_default_colors_=false;
254 signal_gradient_changed()();
258 synfigapp::Main::set_gradient_default_colors()
260 gradient_default_colors_=true;
261 gradient_=Gradient(foreground_,background_);
262 signal_gradient_changed()();
266 synfigapp::Main::color_swap()
268 const Color tmp(foreground_);
269 foreground_=background_;
272 if(selected_input_device_)
274 selected_input_device_->set_foreground_color(foreground_);
275 selected_input_device_->set_background_color(background_);
278 signal_foreground_color_changed()();
279 signal_background_color_changed()();
281 if(gradient_default_colors_)
283 gradient_=Gradient(foreground_,background_);
284 signal_gradient_changed()();
288 synfig::Waypoint::Interpolation
289 synfigapp::Main::get_interpolation()
291 return interpolation_;
296 synfigapp::Main::set_interpolation(synfig::Waypoint::Interpolation x)
298 if(interpolation_!=x)
302 signal_interpolation_changed();
306 const synfig::Distance&
307 synfigapp::Main::get_bline_width()
313 synfigapp::Main::set_bline_width(synfig::Distance x)
320 if(selected_input_device_)
321 selected_input_device_->set_bline_width(x);
323 signal_bline_width_changed()();
328 synfigapp::Main::set_opacity(synfig::Real x)
331 if(selected_input_device_)
332 selected_input_device_->set_opacity(opacity_);
333 signal_opacity_changed()();
337 synfigapp::Main::set_blend_method(synfig::Color::BlendMethod x)
340 if(selected_input_device_)
341 selected_input_device_->set_blend_method(x);
342 signal_blend_method_changed()();
347 synfigapp::Main::add_input_device(const synfig::String id, InputDevice::Type type)
349 input_devices_.push_back(new InputDevice(id,type));
350 return input_devices_.back();
354 synfigapp::Main::find_input_device(const synfig::String id)
356 list<InputDevice::Handle>::iterator iter;
357 for(iter=input_devices_.begin();iter!=input_devices_.end();++iter)
358 if((*iter)->get_id()==id)
364 synfigapp::Main::select_input_device(const synfig::String id)
366 InputDevice::Handle input_device(find_input_device(id));
369 if(!select_input_device(input_device))
375 synfigapp::Main::select_input_device(InputDevice::Handle input_device)
377 assert(input_device);
379 synfig::info("Input device changed to \"%s\"",input_device->get_id().c_str());
381 selected_input_device_=input_device;
383 set_bline_width(input_device->get_bline_width());
384 set_foreground_color(input_device->get_foreground_color());
385 set_opacity(input_device->get_opacity());
386 set_blend_method(input_device->get_blend_method());
392 synfigapp::Main::get_selected_input_device()
394 return selected_input_device_;
398 synfigapp::Main::set_state(synfig::String state)
400 if(selected_input_device_)
401 selected_input_device_->set_state(state);