#include <EventWindow.h>
Inheritance diagram for gadget::EventWindow:

Public Types | |
| typedef std::vector< gadget::EventPtr > | EventQueue |
Public Methods | |
| EventWindow () | |
| virtual | ~EventWindow () |
| virtual std::string | getBaseType () |
| virtual vpr::ReturnStatus | writeObject (vpr::ObjectWriter *writer) |
| Write both mCurKeys and mCurEventQueueLock to a stream using the given ObjectWriter. More... | |
| virtual vpr::ReturnStatus | readObject (vpr::ObjectReader *reader) |
| Read mCurKeys and mCurEventQueueLock from a stream using the given ObjectReader. More... | |
| virtual bool | config (jccl::ConfigElementPtr element) |
| vpr::Interval | getSyncTime () |
| Get the interval that will be used for syncronization while only sharing keyboard data across the cluster. More... | |
| int | keyPressed (gadget::Keys keyId) |
| Is the given key pressed? More... | |
| bool | modifierOnly (gadget::Keys modKey) |
| Checks for the given modifier key pressed only. More... | |
| std::string | getKeyName (gadget::Keys keyId) |
| EventQueue | getEventQueue () |
| Returns a copy of the current queue of events for this window. More... | |
Public Attributes | |
| int | mCurKeys [gadget::LAST_KEY] |
| (0,*): Copy of keys for this frame that the user reads from between updates. More... | |
Protected Methods | |
| void | addEvent (gadget::EventPtr e) |
| Adds the given event object to the in-progress queue. More... | |
| void | updateEventQueue () |
| Copies the in-progress event queue into the current (i.e., user) queue and wipes out the in-progress queue. More... | |
Protected Attributes | |
| EventQueue | mCurEventQueue |
| Queue of events returned to users. More... | |
| vpr::Mutex | mCurEventQueueLock |
| EventQueue | mWorkingEventQueue |
| In-progress queue of events. More... | |
| vpr::Mutex | mWorkingEventQueueLock |
| vpr::Interval | mSyncTime |
| Holds an Interval that is syncrnized across the cluster. More... | |
Informally, an event window can be thought of as map of keys to number of times prseed since last update.
That is to say, that gadget::EventWindow counts the number of key presses between updates. Updates in Juggler occur once per frame.
Definition at line 67 of file EventWindow.h.
|
|
Definition at line 71 of file EventWindow.h. |
|
|
Definition at line 52 of file EventWindow.cpp. References mCurKeys.
|
|
|
Definition at line 75 of file EventWindow.h.
00076 {
00077 /* Do nothing. */ ;
00078 }
|
|
|
Reimplemented in gadget::InputMixer< Input, EventWindow >. Definition at line 64 of file EventWindow.cpp.
00065 {
00066 return "event_window";
00067 }
|
|
|
Write both mCurKeys and mCurEventQueueLock to a stream using the given ObjectWriter.
Reimplemented in gadget::InputMixer< Input, EventWindow >. Definition at line 72 of file EventWindow.cpp. References mCurEventQueue, mCurEventQueueLock, mCurKeys, gadget::MSG_DATA_EVENT_WINDOW, and mSyncTime.
00073 {
00074 writer->writeUint16(MSG_DATA_EVENT_WINDOW); // Write out the data type so that we can assert if reading in wrong place
00075
00076 writer->writeUint64(mSyncTime.getBaseVal());
00077
00078 // Write Current Keys to a stream using the given ObjectWriter
00079 writer->writeUint16(gadget::LAST_KEY);
00080 for ( unsigned int i = 0; i < gadget::LAST_KEY; ++i )
00081 {
00082 writer->writeUint32(mCurKeys[i]);
00083 }
00084
00085 // Write Events to a stream using the given ObjectWriter
00086 writer->writeUint16(mCurEventQueue.size());
00087
00088 // Lock the Queue of current events to serialize
00089 vpr::Guard<vpr::Mutex> cur_guard(mCurEventQueueLock);
00090
00091 // Serialize all events.
00092 for(unsigned i = 0; i<mCurEventQueue.size(); ++i)
00093 mCurEventQueue[i]->writeObject(writer);
00094
00095 return vpr::ReturnStatus::Succeed;
00096 }
|
|
|
Read mCurKeys and mCurEventQueueLock from a stream using the given ObjectReader.
Reimplemented in gadget::InputMixer< Input, EventWindow >. Definition at line 101 of file EventWindow.cpp. References addEvent, gadget::EventPtr, gadget::EventType, mCurKeys, gadget::MSG_DATA_EVENT_WINDOW, mSyncTime, and updateEventQueue.
00102 {
00103 // ASSERT if the given datastream does not start with the correct datatype
00104 // flag.
00105 // XXX: Should there be error checking for the case when vprASSERT() is
00106 // compiled out? -PH 8/21/2003
00107 vpr::Uint16 data_type = reader->readUint16();
00108 vprASSERT(data_type==MSG_DATA_EVENT_WINDOW && "[EventWindow::readObject()] Not EventWindow Data");
00109 boost::ignore_unused_variable_warning(data_type);
00110
00111 // We must save this value to set the sync time after we updateEventQueue.
00112 // This is because we can not read the timestamp from an event in the
00113 // queue since we do not have events every frame.
00114 vpr::Uint64 temp_sync = reader->readUint64();
00115
00116 // Read Current Keys using the given ObjectReader
00117 unsigned int num_keys = reader->readUint16();
00118
00119 vprASSERT(gadget::LAST_KEY == num_keys && "[EventWindow::readObject()] Different number of keys.");
00120 for ( unsigned int i = 0; i < num_keys; ++i )
00121 {
00122 mCurKeys[i] = reader->readUint32();
00123 }
00124
00125 // Read all events using the given ObjectReader
00126 unsigned num_events = reader->readUint16();
00127
00128 // -For each event
00129 // -Read the event type
00130 // -Create the correct Event subclass using the EventFactory
00131 // -Set the event type since we could not set it during construction
00132 // -Load all necissary data into event using the given ObjectReader
00133 // -Add the new event to the working event queue
00134 // -Update the event queue, which swaps the working and current queues
00135 for (unsigned i = 0; i < num_events; ++i )
00136 {
00137 EventType event_type = (EventType)reader->readUint16();
00138 EventPtr temp_event(EventFactory::instance()->createObject(event_type));
00139
00140 vprASSERT(NULL != temp_event.get() && "temp_event == NULL, Event Type does not exist.");
00141
00142 temp_event->setType(event_type);
00143 temp_event->readObject(reader);
00144
00145 addEvent(temp_event);
00146 }
00147 updateEventQueue();
00148
00149 // We must set sync time correctly here since updateEventQueue() changes it.
00150 mSyncTime.set(temp_sync, vpr::Interval::Base);
00151
00152 return vpr::ReturnStatus::Succeed;
00153 }
|
|
|
Reimplemented in gadget::EventWindowOSX. Definition at line 92 of file EventWindow.h.
00093 {
00094 boost::ignore_unused_variable_warning(element);
00095 return true;
00096 }
|
|
|
Get the interval that will be used for syncronization while only sharing keyboard data across the cluster.
Definition at line 102 of file EventWindow.h.
00103 {
00104 return mSyncTime;
00105 }
|
|
|
Is the given key pressed?
Definition at line 111 of file EventWindow.h.
00112 {
00113 return mCurKeys[keyId];
00114 }
|
|
|
Checks for the given modifier key pressed only.
Definition at line 160 of file EventWindow.cpp. References mCurKeys.
00161 {
00162 switch (modKey)
00163 {
00164 case gadget::KEY_NONE:
00165 return (!mCurKeys[gadget::KEY_SHIFT] && !mCurKeys[gadget::KEY_CTRL] && !mCurKeys[gadget::KEY_ALT]);
00166 case gadget::KEY_SHIFT:
00167 return (mCurKeys[gadget::KEY_SHIFT] && !mCurKeys[gadget::KEY_CTRL] && !mCurKeys[gadget::KEY_ALT]);
00168 case gadget::KEY_CTRL:
00169 return (!mCurKeys[gadget::KEY_SHIFT] && mCurKeys[gadget::KEY_CTRL] && !mCurKeys[gadget::KEY_ALT]);
00170 case gadget::KEY_ALT:
00171 return (!mCurKeys[gadget::KEY_SHIFT] && !mCurKeys[gadget::KEY_CTRL] && mCurKeys[gadget::KEY_ALT]);
00172 default:
00173 vprASSERT(false);
00174 return 0;
00175 }
00176 }
|
|
|
Definition at line 178 of file EventWindow.cpp.
00179 {
00180 switch(keyId)
00181 {
00182 case gadget::KEY_NONE: return std::string("KEY_NONE");
00183 case gadget::KEY_UP: return std::string("KEY_UP");
00184 case gadget::KEY_DOWN: return std::string("KEY_DOWN");
00185 case gadget::KEY_LEFT: return std::string("KEY_LEFT");
00186 case gadget::KEY_RIGHT: return std::string("KEY_RIGHT");
00187 case gadget::KEY_SHIFT: return std::string("KEY_SHIFT");
00188 case gadget::KEY_CTRL: return std::string("KEY_CTRL");
00189 case gadget::KEY_ALT: return std::string("KEY_ALT");
00190 case gadget::KEY_1: return std::string("KEY_1");
00191 case gadget::KEY_2: return std::string("KEY_2");
00192 case gadget::KEY_3: return std::string("KEY_3");
00193 case gadget::KEY_4: return std::string("KEY_4");
00194 case gadget::KEY_5: return std::string("KEY_5");
00195 case gadget::KEY_6: return std::string("KEY_6");
00196 case gadget::KEY_7: return std::string("KEY_7");
00197 case gadget::KEY_8: return std::string("KEY_8");
00198 case gadget::KEY_9: return std::string("KEY_9");
00199 case gadget::KEY_0: return std::string("KEY_0");
00200 case gadget::KEY_A: return std::string("KEY_A");
00201 case gadget::KEY_B: return std::string("KEY_B");
00202 case gadget::KEY_C: return std::string("KEY_C");
00203 case gadget::KEY_D: return std::string("KEY_D");
00204 case gadget::KEY_E: return std::string("KEY_E");
00205 case gadget::KEY_F: return std::string("KEY_F");
00206 case gadget::KEY_G: return std::string("KEY_G");
00207 case gadget::KEY_H: return std::string("KEY_H");
00208 case gadget::KEY_I: return std::string("KEY_I");
00209 case gadget::KEY_J: return std::string("KEY_J");
00210 case gadget::KEY_K: return std::string("KEY_K");
00211 case gadget::KEY_L: return std::string("KEY_L");
00212 case gadget::KEY_M: return std::string("KEY_M");
00213 case gadget::KEY_N: return std::string("KEY_N");
00214 case gadget::KEY_O: return std::string("KEY_O");
00215 case gadget::KEY_P: return std::string("KEY_P");
00216 case gadget::KEY_Q: return std::string("KEY_Q");
00217 case gadget::KEY_R: return std::string("KEY_R");
00218 case gadget::KEY_S: return std::string("KEY_S");
00219 case gadget::KEY_T: return std::string("KEY_T");
00220 case gadget::KEY_U: return std::string("KEY_U");
00221 case gadget::KEY_V: return std::string("KEY_V");
00222 case gadget::KEY_W: return std::string("KEY_W");
00223 case gadget::KEY_X: return std::string("KEY_X");
00224 case gadget::KEY_Y: return std::string("KEY_Y");
00225 case gadget::KEY_Z: return std::string("KEY_Z");
00226 case gadget::KEY_ESC: return std::string("KEY_ESC");
00227
00228 case gadget::MOUSE_POSX: return std::string("MOUSE_POSX");
00229 case gadget::MOUSE_NEGX: return std::string("MOUSE_NEGX");
00230 case gadget::MOUSE_POSY: return std::string("MOUSE_POSY");
00231 case gadget::MOUSE_NEGY: return std::string("MOUSE_NEGY");
00232 case gadget::MBUTTON1: return std::string("MBUTTON1");
00233 case gadget::MBUTTON2: return std::string("MBUTTON2");
00234 case gadget::MBUTTON3: return std::string("MBUTTON3");
00235 case gadget::MBUTTON4: return std::string("MBUTTON4");
00236 case gadget::MBUTTON5: return std::string("MBUTTON5");
00237 case gadget::NO_MBUTTON: return std::string("NO_MBUTTON");
00238
00239 case gadget::KEY_TAB : return std::string("KEY_TAB");
00240 case gadget::KEY_BACKTAB : return std::string("KEY_BACKTAB");
00241 case gadget::KEY_BACKSPACE : return std::string("KEY_BACKSPACE");
00242 case gadget::KEY_RETURN : return std::string("KEY_RETURN");
00243 case gadget::KEY_ENTER : return std::string("KEY_ENTER");
00244 case gadget::KEY_INSERT : return std::string("KEY_INSERT");
00245 case gadget::KEY_DELETE : return std::string("KEY_DELETE");
00246 case gadget::KEY_PAUSE : return std::string("KEY_PAUSE");
00247 case gadget::KEY_PRINT : return std::string("KEY_PRINT");
00248 case gadget::KEY_SYSREQ : return std::string("KEY_SYSREQ");
00249 case gadget::KEY_HOME : return std::string("KEY_HOME");
00250 case gadget::KEY_END : return std::string("KEY_END");
00251 case gadget::KEY_PRIOR : return std::string("KEY_PRIOR");
00252 case gadget::KEY_NEXT : return std::string("KEY_NEXT");
00253 case gadget::KEY_CAPS_LOCK : return std::string("KEY_CAPS_LOCK");
00254 case gadget::KEY_NUM_LOCK : return std::string("KEY_NUM_LOCK");
00255 case gadget::KEY_SCROLL_LOCK : return std::string("KEY_SCROLL_LOCK");
00256 case gadget::KEY_F1 : return std::string("KEY_F1");
00257 case gadget::KEY_F2 : return std::string("KEY_F2");
00258 case gadget::KEY_F3 : return std::string("KEY_F3");
00259 case gadget::KEY_F4 : return std::string("KEY_F4");
00260 case gadget::KEY_F5 : return std::string("KEY_F5");
00261 case gadget::KEY_F6 : return std::string("KEY_F6");
00262 case gadget::KEY_F7 : return std::string("KEY_F7");
00263 case gadget::KEY_F8 : return std::string("KEY_F8");
00264 case gadget::KEY_F9 : return std::string("KEY_F9");
00265 case gadget::KEY_F10 : return std::string("KEY_F10");
00266 case gadget::KEY_F11 : return std::string("KEY_F11");
00267 case gadget::KEY_F12 : return std::string("KEY_F12");
00268 case gadget::KEY_F13 : return std::string("KEY_F13");
00269 case gadget::KEY_F14 : return std::string("KEY_F14");
00270 case gadget::KEY_F15 : return std::string("KEY_F15");
00271 case gadget::KEY_F16 : return std::string("KEY_F16");
00272 case gadget::KEY_F17 : return std::string("KEY_F17");
00273 case gadget::KEY_F18 : return std::string("KEY_F18");
00274 case gadget::KEY_F19 : return std::string("KEY_F19");
00275 case gadget::KEY_F20 : return std::string("KEY_F20");
00276 case gadget::KEY_F21 : return std::string("KEY_F21");
00277 case gadget::KEY_F22 : return std::string("KEY_F22");
00278 case gadget::KEY_F23 : return std::string("KEY_F23");
00279 case gadget::KEY_F24 : return std::string("KEY_F24");
00280 case gadget::KEY_F25 : return std::string("KEY_F25");
00281 case gadget::KEY_F26 : return std::string("KEY_F26");
00282 case gadget::KEY_F27 : return std::string("KEY_F27");
00283 case gadget::KEY_F28 : return std::string("KEY_F28");
00284 case gadget::KEY_F29 : return std::string("KEY_F29");
00285 case gadget::KEY_F30 : return std::string("KEY_F30");
00286 case gadget::KEY_F31 : return std::string("KEY_F31");
00287 case gadget::KEY_F32 : return std::string("KEY_F32");
00288 case gadget::KEY_F33 : return std::string("KEY_F33");
00289 case gadget::KEY_F34 : return std::string("KEY_F34");
00290 case gadget::KEY_F35 : return std::string("KEY_F35");
00291
00292 case gadget::KEY_SUPER_L : return std::string("KEY_SUPER_L");
00293 case gadget::KEY_SUPER_R : return std::string("KEY_SUPER_R");
00294 case gadget::KEY_MENU : return std::string("KEY_MENU");
00295 case gadget::KEY_HYPER_L : return std::string("KEY_HYPER_L");
00296 case gadget::KEY_HYPER_R : return std::string("KEY_HYPER_R");
00297 case gadget::KEY_HELP : return std::string("KEY_HELP");
00298 case gadget::KEY_SPACE : return std::string("KEY_SPACE");
00299 case gadget::KEY_ANY : return std::string("KEY_ANY");
00300
00301 case gadget::KEY_EXCLAM : return std::string("KEY_EXCLAM");
00302 case gadget::KEY_QUOTE_DBL : return std::string("KEY_QUOTE_DBL");
00303 case gadget::KEY_NUMBER_SIGN : return std::string("KEY_NUMBER_SIGN");
00304 case gadget::KEY_DOLLAR : return std::string("KEY_DOLLAR");
00305 case gadget::KEY_PERCENT : return std::string("KEY_PERCENT");
00306 case gadget::KEY_AMPERSAND : return std::string("KEY_AMPERSAND");
00307 case gadget::KEY_APOSTROPHE : return std::string("KEY_APOSTROPHE");
00308 case gadget::KEY_PAREN_LEFT : return std::string("KEY_PAREN_LEFT");
00309 case gadget::KEY_PAREN_RIGHT : return std::string("KEY_PAREN_RIGHT");
00310 case gadget::KEY_ASTERISK : return std::string("KEY_ASTERISK");
00311 case gadget::KEY_PLUS : return std::string("KEY_PLUS");
00312 case gadget::KEY_COMMA : return std::string("KEY_COMMA");
00313 case gadget::KEY_MINUS : return std::string("KEY_MINUS");
00314 case gadget::KEY_PERIOD : return std::string("KEY_PERIOD");
00315 case gadget::KEY_SLASH : return std::string("KEY_SLASH");
00316 case gadget::KEY_COLON : return std::string("KEY_COLON");
00317 case gadget::KEY_SEMICOLON : return std::string("KEY_SEMICOLON");
00318 case gadget::KEY_LESS : return std::string("KEY_LESS");
00319 case gadget::KEY_EQUAL : return std::string("KEY_EQUAL");
00320 case gadget::KEY_GREATER : return std::string("KEY_GREATER");
00321 case gadget::KEY_QUESTION : return std::string("KEY_QUESTION");
00322 case gadget::KEY_AT : return std::string("KEY_AT");
00323 case gadget::KEY_BRACKET_LEFT : return std::string("KEY_BRACKET_LEFT");
00324 case gadget::KEY_BACKSLASH : return std::string("KEY_BACKSLASH");
00325 case gadget::KEY_BRACKET_RIGHT : return std::string("KEY_BRACKET_RIGHT");
00326 case gadget::KEY_ASCII_CIRCUM : return std::string("KEY_ASCII_CIRCUM");
00327 case gadget::KEY_UNDERSCORE : return std::string("KEY_UNDERSCORE");
00328 case gadget::KEY_QUOTE_LEFT : return std::string("KEY_QUOTE_LEFT");
00329 case gadget::KEY_BRACE_LEFT : return std::string("KEY_BRACE_LEFT");
00330 case gadget::KEY_BAR : return std::string("KEY_BAR");
00331 case gadget::KEY_BRACE_RIGHT : return std::string("KEY_BRACE_RIGHT");
00332 case gadget::KEY_ASCII_TILDE : return std::string("KEY_ASCII_TILDE");
00333
00334 case gadget::KEY_UNKNOWN : return std::string("KEY_UNKNOWN");
00335 case gadget::LAST_KEY : return std::string("LAST_KEY");
00336 }
00337
00338 // If all of the above fell through ...
00339 return std::string("Unrecognized key");
00340 }
|
|
|
Returns a copy of the current queue of events for this window.
Definition at line 342 of file EventWindow.cpp. References mCurEventQueue, and mCurEventQueueLock.
00343 {
00344 vpr::Guard<vpr::Mutex> guard(mCurEventQueueLock);
00345 return mCurEventQueue;
00346 }
|
|
|
Adds the given event object to the in-progress queue.
Definition at line 348 of file EventWindow.cpp. References mWorkingEventQueue, and mWorkingEventQueueLock. Referenced by gadget::EventWindowWin32::addKeyEvent, gadget::EventWindowWin32::addMouseButtonEvent, gadget::EventWindowWin32::addMouseMoveEvent, and readObject.
00349 {
00350 vpr::Guard<vpr::Mutex> guard(mWorkingEventQueueLock);
00351 mWorkingEventQueue.push_back(e);
00352 }
|
|
|
Copies the in-progress event queue into the current (i.e., user) queue and wipes out the in-progress queue. This should only be called when it is time to synchronize the data for the current frame.
Definition at line 354 of file EventWindow.cpp. References mCurEventQueue, mCurEventQueueLock, mSyncTime, mWorkingEventQueue, and mWorkingEventQueueLock. Referenced by readObject, gadget::EventWindowXWin::updateData, gadget::EventWindowWin32::updateData, and gadget::EventWindowOSX::updateData.
00355 {
00356 mSyncTime.setNow();
00357
00358 vpr::Guard<vpr::Mutex> work_guard(mWorkingEventQueueLock);
00359 {
00360 vpr::Guard<vpr::Mutex> cur_guard(mCurEventQueueLock);
00361 mCurEventQueue = mWorkingEventQueue;
00362 }
00363
00364 mWorkingEventQueue.clear(); // Clear old queue
00365 }
|
|
|
(0,*): Copy of keys for this frame that the user reads from between updates.
Definition at line 133 of file EventWindow.h. Referenced by gadget::EventWindowXWin::config, gadget::EventWindowWin32::config, gadget::EventWindowOSX::config, EventWindow, gadget::EventWindowXWin::isKeyPressed, gadget::EventWindowWin32::isKeyPressed, gadget::EventWindowOSX::isKeyPressed, modifierOnly, gadget::EventWindowWin32::onlyModifier, readObject, gadget::EventWindowXWin::updateData, gadget::EventWindowWin32::updateData, gadget::EventWindowOSX::updateData, and writeObject. |
|
|
Queue of events returned to users.
Definition at line 151 of file EventWindow.h. Referenced by getEventQueue, updateEventQueue, and writeObject. |
|
|
Definition at line 152 of file EventWindow.h. Referenced by getEventQueue, updateEventQueue, and writeObject. |
|
|
In-progress queue of events.
Definition at line 154 of file EventWindow.h. Referenced by addEvent, and updateEventQueue. |
|
|
Definition at line 155 of file EventWindow.h. Referenced by addEvent, and updateEventQueue. |
|
|
Holds an Interval that is syncrnized across the cluster.
Definition at line 160 of file EventWindow.h. Referenced by readObject, updateEventQueue, and writeObject. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002