1 /* === S Y N F I G ========================================================= */
2 /*! \file inputdevice.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 ======================================================= */
32 #include "inputdevice.h"
35 #include <ETL/stringf>
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
47 using namespace synfigapp;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 class DeviceSettings : public Settings
55 InputDevice* input_device;
57 DeviceSettings(InputDevice* input_device):
58 input_device(input_device) { }
61 virtual bool get_value(const synfig::String& key, synfig::String& value)const
65 value=input_device->get_state();
68 if(key=="bline_width")
70 value=strprintf("%s",input_device->get_bline_width().get_string().c_str());
75 value=strprintf("%f",(float)input_device->get_opacity());
78 if(key=="blend_method")
80 value=strprintf("%i",(int)input_device->get_blend_method());
85 Color c(input_device->get_foreground_color());
86 value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a());
92 Color c(input_device->get_background_color());
93 value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a());
98 return Settings::get_value(key, value);
101 virtual bool set_value(const synfig::String& key,const synfig::String& value)
105 input_device->set_state(value);
108 if(key=="bline_width")
110 input_device->set_bline_width(synfig::Distance(value));
115 input_device->set_opacity(atof(value.c_str()));
118 if(key=="blend_method")
120 input_device->set_blend_method(Color::BlendMethod(atoi(value.c_str())));
125 float r=0,g=0,b=0,a=1;
126 if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a))
128 input_device->set_foreground_color(synfig::Color(r,g,b,a));
133 float r=0,g=0,b=0,a=1;
134 if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a))
136 input_device->set_background_color(synfig::Color(r,g,b,a));
140 return Settings::set_value(key, value);
143 virtual KeyList get_key_list()const
145 KeyList ret(Settings::get_key_list());
146 ret.push_back("color");
147 ret.push_back("bgcolor");
148 ret.push_back("state");
149 ret.push_back("bline_width");
150 ret.push_back("blend_method");
151 ret.push_back("opacity");
156 /* === P R O C E D U R E S ================================================= */
158 /* === M E T H O D S ======================================================= */
160 InputDevice::InputDevice(const synfig::String id_, Type type_):
163 state_((type_==TYPE_PEN)?"sketch":"normal"),
164 foreground_color_(Color::black()),
165 background_color_(Color::white()),
166 bline_width_(Distance(1,Distance::SYSTEM_POINTS)),
168 blend_method_(Color::BLEND_COMPOSITE)
193 device_settings=new DeviceSettings(this);
194 Main::settings().add_domain(device_settings,"input_device."+id_);
197 InputDevice::~InputDevice()
199 Main::settings().remove_domain("input_device."+id_);
200 delete device_settings;
204 InputDevice::settings()
206 return *device_settings;
210 InputDevice::settings()const
212 return *device_settings;