00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "clientButtonDevice.h"
00017
00018 #include "indent.h"
00019
00020 TypeHandle ClientButtonDevice::_type_handle;
00021
00022
00023
00024
00025
00026
00027 ClientButtonDevice::
00028 ClientButtonDevice(ClientBase *client, const string &device_name):
00029 ClientDevice(client, get_class_type(), device_name)
00030 {
00031 _button_events = new ButtonEventList();
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 void ClientButtonDevice::
00045 set_button_state(int index, bool down) {
00046 ensure_button_index(index);
00047 nassertv(index >= 0 && index < (int)_buttons.size());
00048 _buttons[index]._state = down ? S_down : S_up;
00049
00050 ButtonHandle handle = _buttons[index]._handle;
00051 if (handle != ButtonHandle::none()) {
00052 _button_events->add_event(ButtonEvent(handle, down ? ButtonEvent::T_down : ButtonEvent::T_up));
00053 }
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 void ClientButtonDevice::
00065 ensure_button_index(int index) {
00066 nassertv(index >= 0);
00067
00068 _buttons.reserve(index + 1);
00069 while ((int)_buttons.size() <= index) {
00070 _buttons.push_back(ButtonState());
00071 }
00072 }
00073
00074
00075
00076
00077
00078
00079 void ClientButtonDevice::
00080 output(ostream &out) const {
00081 out << get_type() << " " << get_device_name() << " (";
00082 output_buttons(out);
00083 out << ")";
00084 }
00085
00086
00087
00088
00089
00090
00091 void ClientButtonDevice::
00092 write(ostream &out, int indent_level) const {
00093 indent(out, indent_level) << get_type() << " " << get_device_name() << ":\n";
00094 write_buttons(out, indent_level + 2);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 void ClientButtonDevice::
00104 output_buttons(ostream &out) const {
00105 bool any_buttons = false;
00106 Buttons::const_iterator bi;
00107 for (bi = _buttons.begin(); bi != _buttons.end(); ++bi) {
00108 const ButtonState &state = (*bi);
00109 if (state._state != S_unknown) {
00110 if (any_buttons) {
00111 out << ", ";
00112 }
00113 any_buttons = true;
00114 out << (int)(bi - _buttons.begin()) << "=";
00115 if (state._state == S_up) {
00116 out << "up";
00117 } else {
00118 out << "down";
00119 }
00120 }
00121 }
00122
00123 if (!any_buttons) {
00124 out << "no known buttons";
00125 }
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 void ClientButtonDevice::
00135 write_buttons(ostream &out, int indent_level) const {
00136 bool any_buttons = false;
00137 Buttons::const_iterator bi;
00138 for (bi = _buttons.begin(); bi != _buttons.end(); ++bi) {
00139 const ButtonState &state = (*bi);
00140 if (state._state != S_unknown) {
00141 any_buttons = true;
00142
00143 indent(out, indent_level)
00144 << (int)(bi - _buttons.begin()) << ". ";
00145
00146 if (state._handle != ButtonHandle::none()) {
00147 out << "(" << state._handle << ") ";
00148 }
00149
00150 if (state._state == S_up) {
00151 out << "up";
00152 } else {
00153 out << "down";
00154 }
00155 out << "\n";
00156 }
00157 }
00158
00159 if (!any_buttons) {
00160 indent(out, indent_level)
00161 << "(no known buttons)\n";
00162 }
00163 }