00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mouseAndKeyboard.h"
00020 #include "mouseData.h"
00021 #include "buttonHandle.h"
00022 #include "buttonEvent.h"
00023 #include "dataNodeTransmit.h"
00024 #include "graphicsWindow.h"
00025
00026 TypeHandle MouseAndKeyboard::_type_handle;
00027
00028
00029
00030
00031
00032
00033 MouseAndKeyboard::
00034 MouseAndKeyboard(GraphicsWindow *window, int device, const string &name) :
00035 DataNode(name),
00036 _window(window),
00037 _device(device)
00038 {
00039 _pixel_xy_output = define_output("pixel_xy", EventStoreVec2::get_class_type());
00040 _xy_output = define_output("xy", EventStoreVec2::get_class_type());
00041 _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
00042
00043 _pixel_xy = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
00044 _xy = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
00045 _button_events = new ButtonEventList;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055 void MouseAndKeyboard::
00056 set_source(GraphicsWindow *window, int device) {
00057 _window = window;
00058 _device = device;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 void MouseAndKeyboard::
00075 do_transmit_data(const DataNodeTransmit &, DataNodeTransmit &output) {
00076 if (_window->has_button_event(_device)) {
00077
00078 _button_events->clear();
00079 while (_window->has_button_event(_device)) {
00080 ButtonEvent be = _window->get_button_event(_device);
00081 _button_events->add_event(be);
00082 }
00083 output.set_data(_button_events_output, EventParameter(_button_events));
00084 }
00085
00086 if (_window->has_pointer(_device)) {
00087 const MouseData &mdata = _window->get_mouse_data(_device);
00088
00089 if (mdata._in_window) {
00090
00091 _pixel_xy->set_value(LPoint2f(mdata._xpos, mdata._ypos));
00092 output.set_data(_pixel_xy_output, EventParameter(_pixel_xy));
00093
00094 WindowProperties properties = _window->get_properties();
00095 int w = properties.get_x_size();
00096 int h = properties.get_y_size();
00097
00098
00099 float xf = (float)(2 * mdata._xpos) / (float)w - 1.0f;
00100 float yf = 1.0f - (float)(2 * mdata._ypos) / (float)h;
00101
00102 _xy->set_value(LPoint2f(xf, yf));
00103 output.set_data(_xy_output, EventParameter(_xy));
00104 }
00105 }
00106 }