X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fcontrol.cpp;h=eee0f1523e98256604ca4e0213669134a555c4d1;hb=4c43f46e8fae246416726c9efb71cf5e984d2e08;hp=8ddcdd772cf2af96cc7e7f51f42e978edebe87cd;hpb=999ca92aa9ee10585c0b2094d84364159253982f;p=libs%2Fgui.git diff --git a/source/input/control.cpp b/source/input/control.cpp index 8ddcdd7..eee0f15 100644 --- a/source/input/control.cpp +++ b/source/input/control.cpp @@ -1,11 +1,3 @@ -/* $Id$ - -This file is part of libmspgbase -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include #include #include "control.h" #include "device.h" @@ -29,8 +21,10 @@ std::string ControlSource::str() const { if(type==BUTTON) return dev->get_button_name(index); - else if(type==AXIS_POS || type==AXIS_NEG) - return dev->get_axis_name(index); + else if(type==AXIS_POS) + return dev->get_axis_name(index)+" +"; + else if(type==AXIS_NEG) + return dev->get_axis_name(index)+" -"; else if(type==NONE) return "None"; @@ -54,36 +48,30 @@ Control::Control(Device &d, ControlSrcType t, unsigned i): connect_signals(); } -Control::Control(const Control &c): - trackable(c), - src(c.src), - capture_dev(0) +void Control::capture(Device &d) { - connect_signals(); + notify_callbacks(); + capture_dev = &d; + capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press)); + capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion)); } -Control &Control::operator=(const Control &c) +void Control::cancel_capture() { notify_callbacks(); - src=c.src; - capture_dev=0; + capture_dev = 0; connect_signals(); - - return *this; } -void Control::capture(Device &d) +void Control::set_source(Device &d, ControlSrcType t, unsigned i) { - notify_callbacks(); - capture_dev=&d; - capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press)); - capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion)); + set_source(ControlSource(d, t, i)); } -void Control::cancel_capture() +void Control::set_source(const ControlSource &s) { notify_callbacks(); - capture_dev=0; + src = s; connect_signals(); } @@ -101,8 +89,6 @@ void Control::connect_signals() case AXIS_NEG: src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion)); break; - default: - throw Exception("Invalid source in Control"); } } @@ -110,12 +96,12 @@ void Control::button_press(unsigned i) { if(capture_dev) { - src.dev=capture_dev; - src.type=BUTTON; - src.index=i; + src.dev = capture_dev; + src.type = BUTTON; + src.index = i; notify_callbacks(); - capture_dev=0; + capture_dev = 0; connect_signals(); signal_capture_complete.emit(); } @@ -133,20 +119,20 @@ void Control::axis_motion(unsigned i, float v, float r) { if(capture_dev) { - ControlSrcType type=NONE; - if(v<-src.dev->get_axis_threshold()) - type=AXIS_NEG; - else if(v>src.dev->get_axis_threshold()) - type=AXIS_POS; + ControlSrcType type = NONE; + if(v<-0.9) + type = AXIS_NEG; + else if(v>0.9) + type = AXIS_POS; if(type!=NONE) { - src.dev=capture_dev; - src.type=type; - src.index=i; + src.dev = capture_dev; + src.type = type; + src.index = i; notify_callbacks(); - capture_dev=0; + capture_dev = 0; connect_signals(); signal_capture_complete.emit(); }