X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fsynfigapp%2Finputdevice.cpp;h=874fb190af97bfafc520876514e4d33795b067ca;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=4a513a63767d005f92625b4df99c2f64a639aa87;hpb=76a7c3b0f43528c603c597cb733f704cba4f83c1;p=synfig.git diff --git a/synfig-studio/trunk/src/synfigapp/inputdevice.cpp b/synfig-studio/trunk/src/synfigapp/inputdevice.cpp index 4a513a6..874fb19 100644 --- a/synfig-studio/trunk/src/synfigapp/inputdevice.cpp +++ b/synfig-studio/trunk/src/synfigapp/inputdevice.cpp @@ -80,24 +80,67 @@ public: value=strprintf("%i",(int)input_device->get_blend_method()); return true; } - if(key=="color") + if(key=="outline_color") { - Color c(input_device->get_foreground_color()); + Color c(input_device->get_outline_color()); value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a()); return true; } - if(key=="bgcolor") + if(key=="fill_color") { - Color c(input_device->get_background_color()); + Color c(input_device->get_fill_color()); value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a()); return true; } + if(key=="mode") + { + get_mode_value(value); + return true; + } + if(key=="axes") + { + get_axes_value(value); + return true; + } + if(key=="keys") + { + get_keys_value(value); + return true; + } return Settings::get_value(key, value); } + void get_mode_value(synfig::String & value) const + { + if (input_device->get_mode() == InputDevice::MODE_SCREEN) + value = "screen"; + else if (input_device->get_mode() == InputDevice::MODE_WINDOW) + value = "window"; + else + value = "disabled"; + } + + void get_axes_value(synfig::String & value) const + { + vector axes = input_device->get_axes(); + value = strprintf("%u", axes.size()); + vector::const_iterator itr; + for (itr = axes.begin(); itr != axes.end(); itr++) + value += strprintf(" %u", (unsigned int) *itr); + } + + void get_keys_value(synfig::String & value) const + { + vector keys = input_device->get_keys(); + value = strprintf("%u", keys.size()); + vector::const_iterator itr; + for (itr = keys.begin(); itr != keys.end(); itr++) + value += strprintf(" %u %u", itr->keyval, itr->modifiers); + } + virtual bool set_value(const synfig::String& key,const synfig::String& value) { if(key=="state") @@ -120,35 +163,107 @@ public: input_device->set_blend_method(Color::BlendMethod(atoi(value.c_str()))); return true; } - if(key=="color") + if(key=="outline_color") { float r=0,g=0,b=0,a=1; if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a)) return false; - input_device->set_foreground_color(synfig::Color(r,g,b,a)); + input_device->set_outline_color(synfig::Color(r,g,b,a)); return true; } - if(key=="bgcolor") + if(key=="fill_color") { float r=0,g=0,b=0,a=1; if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a)) return false; - input_device->set_background_color(synfig::Color(r,g,b,a)); + input_device->set_fill_color(synfig::Color(r,g,b,a)); + return true; + } + if(key=="mode") + { + set_mode_value(value); + return true; + } + if(key=="axes") + { + set_axes_value(value); + return true; + } + if(key=="keys") + { + set_keys_value(value); return true; } return Settings::set_value(key, value); } + void set_mode_value(const synfig::String & value) + { + InputDevice::Mode mode; + if (value == "screen") + mode = InputDevice::MODE_SCREEN; + else if (value == "window") + mode = InputDevice::MODE_WINDOW; + else + mode = InputDevice::MODE_DISABLED; + + input_device->set_mode(mode); + } + + void set_axes_value(const synfig::String & value) + { + std::vector axes; + + unsigned pos = value.find(' ', 0); + if (pos < value.size()) { + int num_axes = atoi(value.substr(0, pos).c_str()); + axes.resize(num_axes); + + for (int axis = 0; axis < num_axes; axis++) { + int last = pos; + pos = value.find(' ', pos + 1); + axes[axis] = InputDevice::AxisUse(atoi(value.substr(last, pos).c_str())); + } + } + + input_device->set_axes(axes); + } + + void set_keys_value(const synfig::String & value) + { + std::vector keys; + + unsigned pos = value.find(' ', 0); + if (pos < value.size()) { + int num_keys = atoi(value.substr(0, pos).c_str()); + keys.resize(num_keys); + + for (int key = 0; key < num_keys; key++) { + int last = pos; + pos = value.find(' ', pos + 1); + keys[key].keyval = (unsigned int) atol(value.substr(last, pos).c_str()); + last = pos; + pos = value.find(' ', pos + 1); + keys[key].modifiers = (unsigned int) atol(value.substr(last, pos).c_str()); + } + } + + input_device->set_keys(keys); + } + virtual KeyList get_key_list()const { KeyList ret(Settings::get_key_list()); - ret.push_back("color"); - ret.push_back("bgcolor"); + ret.push_back("outline_color"); + ret.push_back("fill_color"); ret.push_back("state"); ret.push_back("bline_width"); ret.push_back("blend_method"); ret.push_back("opacity"); + ret.push_back("mode"); + ret.push_back("axes"); + ret.push_back("keys"); return ret; } }; @@ -160,36 +275,14 @@ public: InputDevice::InputDevice(const synfig::String id_, Type type_): id_(id_), type_(type_), - state_((type_==TYPE_PEN)?"sketch":"normal"), - foreground_color_(Color::black()), - background_color_(Color::white()), + state_((type_==TYPE_PEN)?"draw":"normal"), + outline_color_(Color::black()), + fill_color_(Color::white()), bline_width_(Distance(1,Distance::SYSTEM_POINTS)), opacity_(1.0f), - blend_method_(Color::BLEND_COMPOSITE) + blend_method_(Color::BLEND_COMPOSITE), + mode_(MODE_DISABLED) { - switch(type_) - { - case TYPE_MOUSE: - state_="normal"; - break; - - case TYPE_PEN: - state_="draw"; - break; - - case TYPE_ERASER: - state_="normal"; - break; - - case TYPE_CURSOR: - state_="normal"; - break; - - default: - state_="normal"; - break; - } - device_settings=new DeviceSettings(this); Main::settings().add_domain(device_settings,"input_device."+id_); }