From 930710ceecf32c12af5d6e416a4697f9eb9df8aa Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Thu, 17 Feb 2011 15:50:44 -0800 Subject: Added an EventAPI listener to LLWindow for hooking into key and mouse inputs. --- indra/llwindow/CMakeLists.txt | 2 + indra/llwindow/llwindow.cpp | 10 ++- indra/llwindow/llwindow.h | 2 + indra/llwindow/llwindowlistener.cpp | 174 ++++++++++++++++++++++++++++++++++++ indra/llwindow/llwindowlistener.h | 53 +++++++++++ 5 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 indra/llwindow/llwindowlistener.cpp create mode 100644 indra/llwindow/llwindowlistener.h (limited to 'indra/llwindow') diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt index 4d2677fd91..00aaba2052 100644 --- a/indra/llwindow/CMakeLists.txt +++ b/indra/llwindow/CMakeLists.txt @@ -36,6 +36,7 @@ set(llwindow_SOURCE_FILES llkeyboard.cpp llwindowheadless.cpp llwindowcallbacks.cpp + llwindowlistener.cpp ) set(llwindow_HEADER_FILES @@ -44,6 +45,7 @@ set(llwindow_HEADER_FILES llkeyboard.h llwindowheadless.h llwindowcallbacks.h + llwindowlistener.h ) set(viewer_SOURCE_FILES diff --git a/indra/llwindow/llwindow.cpp b/indra/llwindow/llwindow.cpp index 072f694c24..2d00c37719 100644 --- a/indra/llwindow/llwindow.cpp +++ b/indra/llwindow/llwindow.cpp @@ -41,6 +41,7 @@ #include "llkeyboard.h" #include "linked_lists.h" #include "llwindowcallbacks.h" +#include "llwindowlistener.h" // @@ -115,10 +116,15 @@ LLWindow::LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags) mHideCursorPermanent(FALSE), mFlags(flags), mHighSurrogate(0) -{ } +{ + mListener = new LLWindowListener(callbacks, gKeyboard); +} LLWindow::~LLWindow() -{ } +{ + delete mListener; + mListener = NULL; +} //virtual BOOL LLWindow::isValid() diff --git a/indra/llwindow/llwindow.h b/indra/llwindow/llwindow.h index e8a86a1880..6bdc01ae88 100644 --- a/indra/llwindow/llwindow.h +++ b/indra/llwindow/llwindow.h @@ -36,6 +36,7 @@ class LLSplashScreen; class LLPreeditor; class LLWindowCallbacks; +class LLWindowListener; // Refer to llwindow_test in test/common/llwindow for usage example @@ -188,6 +189,7 @@ protected: BOOL mHideCursorPermanent; U32 mFlags; U16 mHighSurrogate; + LLWindowListener* mListener; // Handle a UTF-16 encoding unit received from keyboard. // Converting the series of UTF-16 encoding units to UTF-32 data, diff --git a/indra/llwindow/llwindowlistener.cpp b/indra/llwindow/llwindowlistener.cpp new file mode 100644 index 0000000000..22cc12acee --- /dev/null +++ b/indra/llwindow/llwindowlistener.cpp @@ -0,0 +1,174 @@ +/** + * @file llwindowlistener.cpp + * @brief EventAPI interface for injecting input into LLWindow + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llwindowlistener.h" + +#include "llcoord.h" +#include "llkeyboard.h" +#include "llwindowcallbacks.h" + +LLWindowListener::LLWindowListener(LLWindowCallbacks *window, LLKeyboard * keyboard) + : LLEventAPI("LLWindow", "Inject input events into the LLWindow instance"), + mWindow(window), + mKeyboard(keyboard) +{ + add("keyDown", + "Given [\"keycode\"] or [\"char\"], will inject the given keypress event.", + &LLWindowListener::keyDown); + add("keyUp", + "Given [\"keycode\"] or [\"char\"], will inject the given key release event.", + &LLWindowListener::keyUp); + add("mouseDown", + "Given [\"button\"], [\"x\"] and [\"y\"], will inject the given mouse click event.", + &LLWindowListener::mouseDown); + add("mouseUp", + "Given [\"button\"], [\"x\"] and [\"y\"], will inject the given mouse release event.", + &LLWindowListener::mouseUp); + add("mouseMove", + "Given [\"x\"] and [\"y\"], will inject the given mouse movement event.", + &LLWindowListener::mouseMove); + add("mouseScroll", + "Given a number of [\"clicks\"], will inject the given mouse scroll event.", + &LLWindowListener::mouseScroll); +} + +void LLWindowListener::keyDown(LLSD const & evt) +{ + if(NULL == mKeyboard) + { + // *HACK to handle the fact that LLWindow subclasses have to initialize + // things in an inconvenient order + mKeyboard = gKeyboard; + } + + KEY keycode = 0; + if(evt.has("keycode")) + { + keycode = KEY(evt["keycode"].asInteger()); + } + else + { + keycode = KEY(evt["char"].asString()[0]); + } + + // *TODO - figure out how to handle the mask + mKeyboard->handleTranslatedKeyDown(keycode, 0); +} + +void LLWindowListener::keyUp(LLSD const & evt) +{ + if(NULL == mKeyboard) + { + // *HACK to handle the fact that LLWindow subclasses have to initialize + // things in an inconvenient order + mKeyboard = gKeyboard; + } + + KEY keycode = 0; + if(evt.has("keycode")) + { + keycode = KEY(evt["keycode"].asInteger()); + } + else + { + keycode = KEY(evt["char"].asString()[0]); + } + + // *TODO - figure out how to handle the mask + mKeyboard->handleTranslatedKeyDown(keycode, 0); +} + +void LLWindowListener::mouseDown(LLSD const & evt) +{ + LLCoordGL pos(evt["x"].asInteger(), evt["y"].asInteger()); + + std::string const & button = evt["button"].asString(); + + if(button == "LEFT") + { + // *TODO - figure out how to handle the mask + mWindow->handleMouseDown(NULL, pos, 0); + } + else if (button == "RIGHT") + { + // *TODO - figure out how to handle the mask + mWindow->handleRightMouseDown(NULL, pos, 0); + } + else if (button == "MIDDLE") + { + // *TODO - figure out how to handle the mask + mWindow->handleMiddleMouseDown(NULL, pos, 0); + } + else + { + llwarns << "ignoring unknown mous button \"" << button << '\"' << llendl; + } +} + +void LLWindowListener::mouseUp(LLSD const & evt) +{ + LLCoordGL pos(evt["x"].asInteger(), evt["y"].asInteger()); + + std::string const & button = evt["button"].asString(); + + if(button == "LEFT") + { + // *TODO - figure out how to handle the mask + mWindow->handleMouseUp(NULL, pos, 0); + } + else if (button == "RIGHT") + { + // *TODO - figure out how to handle the mask + mWindow->handleRightMouseUp(NULL, pos, 0); + } + else if (button == "MIDDLE") + { + // *TODO - figure out how to handle the mask + mWindow->handleMiddleMouseUp(NULL, pos, 0); + } + else + { + llwarns << "ignoring unknown mous button \"" << button << '\"' << llendl; + } +} + +void LLWindowListener::mouseMove(LLSD const & evt) +{ + LLCoordGL pos(evt["x"].asInteger(), evt["y"].asInteger()); + + // *TODO - figure out how to handle the mask + mWindow->handleMouseMove(NULL, pos, 0); +} + +void LLWindowListener::mouseScroll(LLSD const & evt) +{ + S32 clicks = evt["clicks"].asInteger(); + + mWindow->handleScrollWheel(NULL, clicks); +} + diff --git a/indra/llwindow/llwindowlistener.h b/indra/llwindow/llwindowlistener.h new file mode 100644 index 0000000000..5b234c5d1d --- /dev/null +++ b/indra/llwindow/llwindowlistener.h @@ -0,0 +1,53 @@ +/** + * @file llwindowlistener.h + * @brief EventAPI interface for injecting input into LLWindow + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLWINDOWLISTENER_H +#define LL_LLWINDOWLISTENER_H + +#include "lleventapi.h" + +class LLKeyboard; +class LLWindowCallbacks; + +class LLWindowListener : public LLEventAPI +{ +public: + LLWindowListener(LLWindowCallbacks * window, LLKeyboard * keyboard); + + void keyDown(LLSD const & evt); + void keyUp(LLSD const & evt); + void mouseDown(LLSD const & evt); + void mouseUp(LLSD const & evt); + void mouseMove(LLSD const & evt); + void mouseScroll(LLSD const & evt); + +private: + LLWindowCallbacks * mWindow; + LLKeyboard * mKeyboard; +}; + + +#endif // LL_LLWINDOWLISTENER_H -- cgit v1.2.3 From 0929315ab103433275a71f26a4900ee0615932e9 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Wed, 23 Feb 2011 05:40:08 +0000 Subject: Added headless client keyboard --- indra/llwindow/CMakeLists.txt | 2 ++ indra/llwindow/llkeyboardheadless.cpp | 50 +++++++++++++++++++++++++++++++++++ indra/llwindow/llkeyboardheadless.h | 45 +++++++++++++++++++++++++++++++ indra/llwindow/llwindowheadless.cpp | 4 +++ 4 files changed, 101 insertions(+) create mode 100644 indra/llwindow/llkeyboardheadless.cpp create mode 100644 indra/llwindow/llkeyboardheadless.h (limited to 'indra/llwindow') diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt index 00aaba2052..08ebaf7577 100644 --- a/indra/llwindow/CMakeLists.txt +++ b/indra/llwindow/CMakeLists.txt @@ -34,6 +34,7 @@ include_directories( set(llwindow_SOURCE_FILES llkeyboard.cpp + llkeyboardheadless.cpp llwindowheadless.cpp llwindowcallbacks.cpp llwindowlistener.cpp @@ -43,6 +44,7 @@ set(llwindow_HEADER_FILES CMakeLists.txt llkeyboard.h + llkeyboardheadless.h llwindowheadless.h llwindowcallbacks.h llwindowlistener.h diff --git a/indra/llwindow/llkeyboardheadless.cpp b/indra/llwindow/llkeyboardheadless.cpp new file mode 100644 index 0000000000..4dfaaed4e1 --- /dev/null +++ b/indra/llwindow/llkeyboardheadless.cpp @@ -0,0 +1,50 @@ +/** + * @file llkeyboardheadless.cpp + * @brief Handler for assignable key bindings + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "llkeyboardheadless.h" +#include "llwindowcallbacks.h" + +LLKeyboardHeadless::LLKeyboardHeadless() +{ } + +void LLKeyboardHeadless::resetMaskKeys() +{ } + + +BOOL LLKeyboardHeadless::handleKeyDown(const U16 key, const U32 mask) +{ return FALSE; } + + +BOOL LLKeyboardHeadless::handleKeyUp(const U16 key, const U32 mask) +{ return FALSE; } + +MASK LLKeyboardHeadless::currentMask(BOOL for_mouse_event) +{ return MASK_NONE; } + +void LLKeyboardHeadless::scanKeyboard() +{ } + diff --git a/indra/llwindow/llkeyboardheadless.h b/indra/llwindow/llkeyboardheadless.h new file mode 100644 index 0000000000..4e666f8ce8 --- /dev/null +++ b/indra/llwindow/llkeyboardheadless.h @@ -0,0 +1,45 @@ +/** + * @file llkeyboardheadless.h + * @brief Handler for assignable key bindings + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLKEYBOARDHEADLESS_H +#define LL_LLKEYBOARDHEADLESS_H + +#include "llkeyboard.h" + +class LLKeyboardHeadless : public LLKeyboard +{ +public: + LLKeyboardHeadless(); + /*virtual*/ ~LLKeyboardHeadless() {}; + + /*virtual*/ BOOL handleKeyUp(const U16 key, MASK mask); + /*virtual*/ BOOL handleKeyDown(const U16 key, MASK mask); + /*virtual*/ void resetMaskKeys(); + /*virtual*/ MASK currentMask(BOOL for_mouse_event); + /*virtual*/ void scanKeyboard(); +}; + +#endif diff --git a/indra/llwindow/llwindowheadless.cpp b/indra/llwindow/llwindowheadless.cpp index 35398f1c09..e6e6bc67ff 100644 --- a/indra/llwindow/llwindowheadless.cpp +++ b/indra/llwindow/llwindowheadless.cpp @@ -28,6 +28,7 @@ #include "indra_constants.h" #include "llwindowheadless.h" +#include "llkeyboardheadless.h" // // LLWindowHeadless @@ -37,6 +38,9 @@ LLWindowHeadless::LLWindowHeadless(LLWindowCallbacks* callbacks, const std::stri BOOL disable_vsync, BOOL use_gl, BOOL ignore_pixel_depth) : LLWindow(callbacks, fullscreen, flags) { + // Initialize a headless keyboard. + gKeyboard = new LLKeyboardHeadless(); + gKeyboard->setCallbacks(callbacks); } -- cgit v1.2.3 From 3f3429fa6854c6462abf3bbabf4af1dbbeb4c337 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 21 Mar 2011 17:38:16 -0400 Subject: STORM-1051: Fixup to LLWindowListener per code review. Bug: capturing a const ref to value returned by LLSD::asString() not so good. Bug: LLWindowListener::keyUp() was calling handleTranslatedKeyDown(). In keyDown and keyUp, support keysym lookup (e.g. "TAB") as well as integer keycode. In keyDown, keyUp, mouseDown, mouseUp and mouseMove, support modifier mask by accepting an array of "CONTROL", "SHIFT" etc. strings. State in operation doc strings valid values for button, keycode, keysym, mask. The LLWindowListener(... LLKeyboard*) constructor param gKeyboard is always NULL at the time LLWindowListener is constructed. Eliminate tests and global references to gKeyboard by replacing with a more Feathers-style LLKeyboard* getter function. --- indra/llwindow/llwindow.cpp | 7 +- indra/llwindow/llwindowlistener.cpp | 279 ++++++++++++++++++++++++++---------- indra/llwindow/llwindowlistener.h | 6 +- 3 files changed, 216 insertions(+), 76 deletions(-) (limited to 'indra/llwindow') diff --git a/indra/llwindow/llwindow.cpp b/indra/llwindow/llwindow.cpp index 2d00c37719..71a5df910d 100644 --- a/indra/llwindow/llwindow.cpp +++ b/indra/llwindow/llwindow.cpp @@ -42,6 +42,7 @@ #include "linked_lists.h" #include "llwindowcallbacks.h" #include "llwindowlistener.h" +#include // @@ -117,7 +118,11 @@ LLWindow::LLWindow(LLWindowCallbacks* callbacks, BOOL fullscreen, U32 flags) mFlags(flags), mHighSurrogate(0) { - mListener = new LLWindowListener(callbacks, gKeyboard); + // gKeyboard is still NULL, so it doesn't do LLWindowListener any good to + // pass its value right now. Instead, pass it a nullary function that + // will, when we later need it, return the value of gKeyboard. + // boost::lambda::var() constructs such a functor on the fly. + mListener = new LLWindowListener(callbacks, boost::lambda::var(gKeyboard)); } LLWindow::~LLWindow() diff --git a/indra/llwindow/llwindowlistener.cpp b/indra/llwindow/llwindowlistener.cpp index 22cc12acee..91b99d83c6 100644 --- a/indra/llwindow/llwindowlistener.cpp +++ b/indra/llwindow/llwindowlistener.cpp @@ -31,138 +31,271 @@ #include "llcoord.h" #include "llkeyboard.h" #include "llwindowcallbacks.h" +#include -LLWindowListener::LLWindowListener(LLWindowCallbacks *window, LLKeyboard * keyboard) +LLWindowListener::LLWindowListener(LLWindowCallbacks *window, const KeyboardGetter& kbgetter) : LLEventAPI("LLWindow", "Inject input events into the LLWindow instance"), mWindow(window), - mKeyboard(keyboard) + mKbGetter(kbgetter) { + std::string keySomething = + "Given [\"keysym\"], [\"keycode\"] or [\"char\"], inject the specified "; + std::string keyExplain = + "(integer keycode values, or keysym \"XXXX\" from any KEY_XXXX, in\n" + "http://hg.secondlife.com/viewer-development/src/tip/indra/llcommon/indra_constants.h )"; + std::string mask = + "Specify optional [\"mask\"] as an array containing any of \"CONTROL\", \"ALT\",\n" + "\"SHIFT\" or \"MAC_CONTROL\"; the corresponding modifier bits will be combined\n" + "to form the mask used with the event."; + + std::string mouseSomething = + "Given [\"button\"], [\"x\"] and [\"y\"], inject the given mouse "; + std::string mouseExplain = + "(button values \"LEFT\", \"MIDDLE\", \"RIGHT\")"; + add("keyDown", - "Given [\"keycode\"] or [\"char\"], will inject the given keypress event.", + keySomething + "keypress event.\n" + keyExplain + '\n' + mask, &LLWindowListener::keyDown); add("keyUp", - "Given [\"keycode\"] or [\"char\"], will inject the given key release event.", + keySomething + "key release event.\n" + keyExplain + '\n' + mask, &LLWindowListener::keyUp); add("mouseDown", - "Given [\"button\"], [\"x\"] and [\"y\"], will inject the given mouse click event.", + mouseSomething + "click event.\n" + mouseExplain + '\n' + mask, &LLWindowListener::mouseDown); add("mouseUp", - "Given [\"button\"], [\"x\"] and [\"y\"], will inject the given mouse release event.", + mouseSomething + "release event.\n" + mouseExplain + '\n' + mask, &LLWindowListener::mouseUp); add("mouseMove", - "Given [\"x\"] and [\"y\"], will inject the given mouse movement event.", + std::string("Given [\"x\"] and [\"y\"], inject the given mouse movement event.\n") + + mask, &LLWindowListener::mouseMove); add("mouseScroll", - "Given a number of [\"clicks\"], will inject the given mouse scroll event.", + "Given an integer number of [\"clicks\"], inject the given mouse scroll event.\n" + "(positive clicks moves downward through typical content)", &LLWindowListener::mouseScroll); } -void LLWindowListener::keyDown(LLSD const & evt) +template +class StringLookup { - if(NULL == mKeyboard) - { - // *HACK to handle the fact that LLWindow subclasses have to initialize - // things in an inconvenient order - mKeyboard = gKeyboard; - } +private: + std::string mDesc; + typedef std::map Map; + Map mMap; + +public: + StringLookup(const std::string& desc): mDesc(desc) {} - KEY keycode = 0; - if(evt.has("keycode")) + MAPPED lookup(const typename Map::key_type& key) const { - keycode = KEY(evt["keycode"].asInteger()); + typename Map::const_iterator found = mMap.find(key); + if (found == mMap.end()) + { + LL_WARNS("LLWindowListener") << "Unknown " << mDesc << " '" << key << "'" << LL_ENDL; + return MAPPED(); + } + return found->second; } - else + +protected: + void add(const typename Map::key_type& key, const typename Map::mapped_type& value) { - keycode = KEY(evt["char"].asString()[0]); + mMap.insert(typename Map::value_type(key, value)); } +}; - // *TODO - figure out how to handle the mask - mKeyboard->handleTranslatedKeyDown(keycode, 0); -} +// for WhichKeysym. KeyProxy is like the typedef KEY, except that KeyProxy() +// (default-constructed) is guaranteed to have the value KEY_NONE. +class KeyProxy +{ +public: + KeyProxy(KEY k): mKey(k) {} + KeyProxy(): mKey(KEY_NONE) {} + operator KEY() const { return mKey; } -void LLWindowListener::keyUp(LLSD const & evt) +private: + KEY mKey; +}; + +struct WhichKeysym: public StringLookup { - if(NULL == mKeyboard) + WhichKeysym(): StringLookup("keysym") { - // *HACK to handle the fact that LLWindow subclasses have to initialize - // things in an inconvenient order - mKeyboard = gKeyboard; + add("RETURN", KEY_RETURN); + add("LEFT", KEY_LEFT); + add("RIGHT", KEY_RIGHT); + add("UP", KEY_UP); + add("DOWN", KEY_DOWN); + add("ESCAPE", KEY_ESCAPE); + add("BACKSPACE", KEY_BACKSPACE); + add("DELETE", KEY_DELETE); + add("SHIFT", KEY_SHIFT); + add("CONTROL", KEY_CONTROL); + add("ALT", KEY_ALT); + add("HOME", KEY_HOME); + add("END", KEY_END); + add("PAGE_UP", KEY_PAGE_UP); + add("PAGE_DOWN", KEY_PAGE_DOWN); + add("HYPHEN", KEY_HYPHEN); + add("EQUALS", KEY_EQUALS); + add("INSERT", KEY_INSERT); + add("CAPSLOCK", KEY_CAPSLOCK); + add("TAB", KEY_TAB); + add("ADD", KEY_ADD); + add("SUBTRACT", KEY_SUBTRACT); + add("MULTIPLY", KEY_MULTIPLY); + add("DIVIDE", KEY_DIVIDE); + add("F1", KEY_F1); + add("F2", KEY_F2); + add("F3", KEY_F3); + add("F4", KEY_F4); + add("F5", KEY_F5); + add("F6", KEY_F6); + add("F7", KEY_F7); + add("F8", KEY_F8); + add("F9", KEY_F9); + add("F10", KEY_F10); + add("F11", KEY_F11); + add("F12", KEY_F12); + + add("PAD_UP", KEY_PAD_UP); + add("PAD_DOWN", KEY_PAD_DOWN); + add("PAD_LEFT", KEY_PAD_LEFT); + add("PAD_RIGHT", KEY_PAD_RIGHT); + add("PAD_HOME", KEY_PAD_HOME); + add("PAD_END", KEY_PAD_END); + add("PAD_PGUP", KEY_PAD_PGUP); + add("PAD_PGDN", KEY_PAD_PGDN); + add("PAD_CENTER", KEY_PAD_CENTER); // the 5 in the middle + add("PAD_INS", KEY_PAD_INS); + add("PAD_DEL", KEY_PAD_DEL); + add("PAD_RETURN", KEY_PAD_RETURN); + add("PAD_ADD", KEY_PAD_ADD); // not used + add("PAD_SUBTRACT", KEY_PAD_SUBTRACT); // not used + add("PAD_MULTIPLY", KEY_PAD_MULTIPLY); // not used + add("PAD_DIVIDE", KEY_PAD_DIVIDE); // not used + + add("BUTTON0", KEY_BUTTON0); + add("BUTTON1", KEY_BUTTON1); + add("BUTTON2", KEY_BUTTON2); + add("BUTTON3", KEY_BUTTON3); + add("BUTTON4", KEY_BUTTON4); + add("BUTTON5", KEY_BUTTON5); + add("BUTTON6", KEY_BUTTON6); + add("BUTTON7", KEY_BUTTON7); + add("BUTTON8", KEY_BUTTON8); + add("BUTTON9", KEY_BUTTON9); + add("BUTTON10", KEY_BUTTON10); + add("BUTTON11", KEY_BUTTON11); + add("BUTTON12", KEY_BUTTON12); + add("BUTTON13", KEY_BUTTON13); + add("BUTTON14", KEY_BUTTON14); + add("BUTTON15", KEY_BUTTON15); } +}; +static WhichKeysym keysyms; - KEY keycode = 0; - if(evt.has("keycode")) +struct WhichMask: public StringLookup +{ + WhichMask(): StringLookup("shift mask") { - keycode = KEY(evt["keycode"].asInteger()); + add("NONE", MASK_NONE); + add("CONTROL", MASK_CONTROL); // Mapped to cmd on Macs + add("ALT", MASK_ALT); + add("SHIFT", MASK_SHIFT); + add("MAC_CONTROL", MASK_MAC_CONTROL); // Un-mapped Ctrl key on Macs, not used on Windows } - else +}; +static WhichMask masks; + +static MASK getMask(const LLSD& event) +{ + MASK mask(MASK_NONE); + LLSD masknames(event["mask"]); + for (LLSD::array_const_iterator ai(masknames.beginArray()), aend(masknames.endArray()); + ai != aend; ++ai) { - keycode = KEY(evt["char"].asString()[0]); + mask |= masks.lookup(*ai); } - - // *TODO - figure out how to handle the mask - mKeyboard->handleTranslatedKeyDown(keycode, 0); + return mask; } -void LLWindowListener::mouseDown(LLSD const & evt) +static KEY getKEY(const LLSD& event) { - LLCoordGL pos(evt["x"].asInteger(), evt["y"].asInteger()); - - std::string const & button = evt["button"].asString(); - - if(button == "LEFT") - { - // *TODO - figure out how to handle the mask - mWindow->handleMouseDown(NULL, pos, 0); - } - else if (button == "RIGHT") + if (event.has("keysym")) { - // *TODO - figure out how to handle the mask - mWindow->handleRightMouseDown(NULL, pos, 0); + return keysyms.lookup(event["keysym"]); } - else if (button == "MIDDLE") + else if (event.has("keycode")) { - // *TODO - figure out how to handle the mask - mWindow->handleMiddleMouseDown(NULL, pos, 0); + return KEY(event["keycode"].asInteger()); } else { - llwarns << "ignoring unknown mous button \"" << button << '\"' << llendl; + return KEY(event["char"].asString()[0]); } } -void LLWindowListener::mouseUp(LLSD const & evt) +void LLWindowListener::keyDown(LLSD const & evt) +{ + mKbGetter()->handleTranslatedKeyDown(getKEY(evt), getMask(evt)); +} + +void LLWindowListener::keyUp(LLSD const & evt) { - LLCoordGL pos(evt["x"].asInteger(), evt["y"].asInteger()); + mKbGetter()->handleTranslatedKeyUp(getKEY(evt), getMask(evt)); +} - std::string const & button = evt["button"].asString(); +// for WhichButton +typedef BOOL (LLWindowCallbacks::*MouseFunc)(LLWindow *, LLCoordGL, MASK); +struct Actions +{ + Actions(const MouseFunc& d, const MouseFunc& u): down(d), up(u), valid(true) {} + Actions(): valid(false) {} + MouseFunc down, up; + bool valid; +}; - if(button == "LEFT") - { - // *TODO - figure out how to handle the mask - mWindow->handleMouseUp(NULL, pos, 0); - } - else if (button == "RIGHT") +struct WhichButton: public StringLookup +{ + WhichButton(): StringLookup("mouse button") { - // *TODO - figure out how to handle the mask - mWindow->handleRightMouseUp(NULL, pos, 0); + add("LEFT", Actions(&LLWindowCallbacks::handleMouseDown, + &LLWindowCallbacks::handleMouseUp)); + add("RIGHT", Actions(&LLWindowCallbacks::handleRightMouseDown, + &LLWindowCallbacks::handleRightMouseUp)); + add("MIDDLE", Actions(&LLWindowCallbacks::handleMiddleMouseDown, + &LLWindowCallbacks::handleMiddleMouseUp)); } - else if (button == "MIDDLE") +}; +static WhichButton buttons; + +static LLCoordGL getPos(const LLSD& event) +{ + return LLCoordGL(event["x"].asInteger(), event["y"].asInteger()); +} + +void LLWindowListener::mouseDown(LLSD const & evt) +{ + Actions actions(buttons.lookup(evt["button"])); + if (actions.valid) { - // *TODO - figure out how to handle the mask - mWindow->handleMiddleMouseUp(NULL, pos, 0); + (mWindow->*(actions.down))(NULL, getPos(evt), getMask(evt)); } - else +} + +void LLWindowListener::mouseUp(LLSD const & evt) +{ + Actions actions(buttons.lookup(evt["button"])); + if (actions.valid) { - llwarns << "ignoring unknown mous button \"" << button << '\"' << llendl; + (mWindow->*(actions.up))(NULL, getPos(evt), getMask(evt)); } } void LLWindowListener::mouseMove(LLSD const & evt) { - LLCoordGL pos(evt["x"].asInteger(), evt["y"].asInteger()); - - // *TODO - figure out how to handle the mask - mWindow->handleMouseMove(NULL, pos, 0); + mWindow->handleMouseMove(NULL, getPos(evt), getMask(evt)); } void LLWindowListener::mouseScroll(LLSD const & evt) diff --git a/indra/llwindow/llwindowlistener.h b/indra/llwindow/llwindowlistener.h index 5b234c5d1d..74e577ff93 100644 --- a/indra/llwindow/llwindowlistener.h +++ b/indra/llwindow/llwindowlistener.h @@ -28,6 +28,7 @@ #define LL_LLWINDOWLISTENER_H #include "lleventapi.h" +#include class LLKeyboard; class LLWindowCallbacks; @@ -35,7 +36,8 @@ class LLWindowCallbacks; class LLWindowListener : public LLEventAPI { public: - LLWindowListener(LLWindowCallbacks * window, LLKeyboard * keyboard); + typedef boost::function KeyboardGetter; + LLWindowListener(LLWindowCallbacks * window, const KeyboardGetter& kbgetter); void keyDown(LLSD const & evt); void keyUp(LLSD const & evt); @@ -46,7 +48,7 @@ public: private: LLWindowCallbacks * mWindow; - LLKeyboard * mKeyboard; + KeyboardGetter mKbGetter; }; -- cgit v1.2.3