From d84edc40907df3dfae6d5ece0420b9bd4bda8d82 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 25 Oct 2015 17:34:03 -0500 Subject: [PATCH] More work on transitioning to windowwrapper for keyboard and mouse interaction --- apps/OpenSpace/main.cpp | 7 +- include/openspace/engine/openspaceengine.h | 9 +- include/openspace/engine/sgctwindowhandler.h | 3 + include/openspace/engine/windowhandler.h | 3 + .../interaction/interactionhandler.h | 9 +- include/openspace/interaction/luaconsole.h | 6 +- .../openspace/interaction/mousecontroller.h | 20 +- include/openspace/util/keys.h | 422 ++++++++++++------ .../openspace/{interaction => util}/mouse.h | 66 ++- modules/onscreengui/include/gui.h | 11 +- modules/onscreengui/src/gui.cpp | 25 +- openspace.cfg | 2 +- src/CMakeLists.txt | 2 +- src/engine/openspaceengine.cpp | 37 +- src/engine/sgctwindowhandler.cpp | 30 +- src/interaction/interactionhandler.cpp | 168 +------ src/interaction/interactionhandler_lua.inl | 4 +- src/interaction/luaconsole.cpp | 34 +- src/interaction/mousecontroller.cpp | 39 +- 19 files changed, 498 insertions(+), 399 deletions(-) rename include/openspace/{interaction => util}/mouse.h (56%) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index cbac1f3d1a..97672c3e3d 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -248,12 +248,15 @@ void mainExternalControlCallback(const char* receivedChars, int size) { void mainKeyboardCallback(int key, int action) { if (OsEng.isMaster()) - OsEng.keyboardCallback(key, action); + OsEng.keyboardCallback(openspace::Key(key), + openspace::KeyModifier::NoModifier, // TODO: fix ---abock + openspace::KeyAction(action)); } void mainMouseButtonCallback(int key, int action) { if (OsEng.isMaster()) - OsEng.mouseButtonCallback(key, action); + OsEng.mouseButtonCallback(openspace::MouseButton(key), + openspace::MouseAction(action)); } void mainMousePosCallback(double x, double y) { diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 315b92f020..ec5144e1f4 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -25,9 +25,13 @@ #ifndef __OPENSPACEENGINE_H__ #define __OPENSPACEENGINE_H__ + #include #include +#include +#include + #include #include @@ -100,9 +104,10 @@ public: void postSynchronizationPreDraw(); void render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix); void postDraw(); - void keyboardCallback(int key, int action); +// void keyboardCallback(int key, int action); + void keyboardCallback(Key key, KeyModifier mod, KeyAction action); void charCallback(unsigned int codepoint); - void mouseButtonCallback(int key, int action); + void mouseButtonCallback(MouseButton button, MouseAction action); void mousePositionCallback(double x, double y); void mouseScrollWheelCallback(double pos); void externalControlCallback(const char* receivedChars, int size, int clientId); diff --git a/include/openspace/engine/sgctwindowhandler.h b/include/openspace/engine/sgctwindowhandler.h index 271e689789..b0d903ac86 100644 --- a/include/openspace/engine/sgctwindowhandler.h +++ b/include/openspace/engine/sgctwindowhandler.h @@ -36,8 +36,11 @@ public: double averageDeltaTime() override; glm::vec2 mousePosition() override; + uint32_t mouseButtons(int maxNumber) override; glm::ivec2 currentWindowSize() override; glm::ivec2 currentWindowResolution() override; + + bool isRegularRendering() override; // void forEachWindow(std::function function) override; diff --git a/include/openspace/engine/windowhandler.h b/include/openspace/engine/windowhandler.h index 19119d8bc6..156f141305 100644 --- a/include/openspace/engine/windowhandler.h +++ b/include/openspace/engine/windowhandler.h @@ -27,6 +27,7 @@ #include +#include #include namespace openspace { @@ -36,9 +37,11 @@ public: virtual void setBarrier(bool enabled) = 0; virtual void clearAllWindows() = 0; virtual double averageDeltaTime() = 0; + virtual uint32_t mouseButtons(int maxNumber = 8) = 0; virtual glm::vec2 mousePosition() = 0; virtual glm::ivec2 currentWindowSize() = 0; virtual glm::ivec2 currentWindowResolution() = 0; + virtual bool isRegularRendering() = 0; diff --git a/include/openspace/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h index 8ddd17f56f..23b6195a04 100644 --- a/include/openspace/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -79,6 +79,7 @@ #include #include #include +#include #include @@ -109,8 +110,8 @@ public: void setCamera(Camera* camera); const Camera* const camera() const; - void keyboardCallback(int key, int action); - void mouseButtonCallback(int button, int action); + void keyboardCallback(Key key, KeyAction action); + void mouseButtonCallback(MouseButton button, MouseAction action); void mousePositionCallback(double x, double y); void mouseScrollWheelCallback(double pos); @@ -131,7 +132,7 @@ public: void setRotation(const glm::quat& rotation); void resetKeyBindings(); - void bindKey(int key, const std::string& lua); + void bindKey(Key key, std::string lua); void setInteractionSensitivity(float sensitivity); float interactionSensitivity() const; @@ -170,7 +171,7 @@ private: std::mutex _mutex; bool _validKeyLua; - std::multimap _keyLua; + std::multimap _keyLua; float _controllerSensitivity; bool _invertRoll; diff --git a/include/openspace/interaction/luaconsole.h b/include/openspace/interaction/luaconsole.h index dd07cfea01..63673394fe 100644 --- a/include/openspace/interaction/luaconsole.h +++ b/include/openspace/interaction/luaconsole.h @@ -27,6 +27,8 @@ #include +#include + #include #include @@ -40,12 +42,12 @@ public: void initialize(); void deinitialize(); - void keyboardCallback(int key, int action); + void keyboardCallback(Key key, KeyAction action); void charCallback(unsigned int codepoint); void render(); - unsigned int commandInputButton(); + Key commandInputButton(); bool isVisible() const; void setVisible(bool visible); diff --git a/include/openspace/interaction/mousecontroller.h b/include/openspace/interaction/mousecontroller.h index 25b93ddf92..24f6089bd0 100644 --- a/include/openspace/interaction/mousecontroller.h +++ b/include/openspace/interaction/mousecontroller.h @@ -27,7 +27,7 @@ #include -#include +#include #include @@ -39,7 +39,7 @@ public: MouseController(); virtual ~MouseController() {} - virtual void button(MouseAction action, MouseButton button) = 0; + virtual void button(MouseButton button, MouseAction action) = 0; virtual void move(float x, float y) = 0; virtual void scrollWheel(int pos) = 0; virtual void update(const double& dt) = 0; @@ -59,13 +59,13 @@ class TrackballMouseController : public MouseController { public: TrackballMouseController(); - void button(MouseAction action, MouseButton button); + void button(MouseButton button, MouseAction action) override; - void move(float x, float y); + void move(float x, float y) override; - void scrollWheel(int pos); + void scrollWheel(int pos) override; - void update(const double& dt); + void update(const double& dt) override; protected: bool _leftMouseButtonDown; @@ -76,13 +76,13 @@ class OrbitalMouseController : public MouseController { public: OrbitalMouseController(); - void button(MouseAction action, MouseButton button); + void button(MouseButton button, MouseAction action) override; - void move(float x, float y); + void move(float x, float y) override; - void scrollWheel(int pos); + void scrollWheel(int pos) override; - void update(const double& dt); + void update(const double& dt) override; protected: bool _leftMouseButtonDown; diff --git a/include/openspace/util/keys.h b/include/openspace/util/keys.h index 9129f742a5..60ba85011b 100644 --- a/include/openspace/util/keys.h +++ b/include/openspace/util/keys.h @@ -22,150 +22,314 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +// This file is based on the definitions as presented in the GLFW library: +/************************************************************************* + * GLFW 3.1 - www.glfw.org + * A library for OpenGL, window and input + *------------------------------------------------------------------------ + * Copyright (c) 2002-2006 Marcus Geelnard + * Copyright (c) 2006-2010 Camilla Berglund + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would + * be appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not + * be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. + * + *************************************************************************/ + #ifndef __KEYS_H__ #define __KEYS_H__ -#include +// All values that are defined here are compatible with (and are based on) the +// definitions GLFW v3.1 namespace openspace { enum class KeyAction { - Press = SGCT_PRESS, - Release = SGCT_RELEASE, - Repeat = SGCT_REPEAT + Release = 0, + Press = 1, + Repeat = 2 }; enum class KeyModifier { NoModifier = 0, - Shift = GLFW_MOD_SHIFT, - Control = GLFW_MOD_CONTROL, - Alt = GLFW_MOD_ALT, - Super = GLFW_MOD_SUPER + Shift = 0x0001, + Control = 0x0002, + Alt = 0x0004, + Super = 0x0008 }; enum class Key { - Unknown = SGCT_KEY_UNKNOWN, - Space = SGCT_KEY_SPACE, - Apostrophe = SGCT_KEY_APOSTROPHE, - Comma = SGCT_KEY_COMMA, - Minus = SGCT_KEY_MINUS, - Period = SGCT_KEY_PERIOD, - Slash = SGCT_KEY_SLASH, - Num0 = SGCT_KEY_0, - Num1 = SGCT_KEY_1, - Num2 = SGCT_KEY_2, - Num3 = SGCT_KEY_3, - Num4 = SGCT_KEY_4, - Num5 = SGCT_KEY_5, - Num6 = SGCT_KEY_6, - Num7 = SGCT_KEY_7, - Num8 = SGCT_KEY_8, - Num9 = SGCT_KEY_9, - SemiColon = SGCT_KEY_SEMICOLON, - Equal = SGCT_KEY_EQUAL, - A = SGCT_KEY_A, - B = SGCT_KEY_B, - C = SGCT_KEY_C, - D = SGCT_KEY_D, - E = SGCT_KEY_E, - F = SGCT_KEY_F, - G = SGCT_KEY_G, - H = SGCT_KEY_H, - I = SGCT_KEY_I, - J = SGCT_KEY_J, - K = SGCT_KEY_K, - L = SGCT_KEY_L, - M = SGCT_KEY_M, - N = SGCT_KEY_N, - O = SGCT_KEY_O, - P = SGCT_KEY_P, - Q = SGCT_KEY_Q, - R = SGCT_KEY_R, - S = SGCT_KEY_S, - T = SGCT_KEY_T, - U = SGCT_KEY_U, - V = SGCT_KEY_V, - W = SGCT_KEY_W, - X = SGCT_KEY_X, - Y = SGCT_KEY_Y, - Z = SGCT_KEY_Z, - LeftBracket = SGCT_KEY_LEFT_BRACKET, - BackSlash = SGCT_KEY_BACKSLASH, - RightBracket = SGCT_KEY_RIGHT_BRACKET, - GraveAccent = SGCT_KEY_GRAVE_ACCENT, - World1 = SGCT_KEY_WORLD_1, - World2 = SGCT_KEY_WORLD_2, - Escape = SGCT_KEY_ESC, - Enter = SGCT_KEY_ENTER, - Tab = SGCT_KEY_TAB, - BackSpace = SGCT_KEY_BACKSPACE, - Insert = SGCT_KEY_INSERT, - Delete = SGCT_KEY_DELETE, - Right = SGCT_KEY_RIGHT, - Left = SGCT_KEY_LEFT, - Down = SGCT_KEY_DOWN, - Up = SGCT_KEY_UP, - PageUp = SGCT_KEY_PAGE_UP, - PageDown = SGCT_KEY_PAGE_DOWN, - Home = SGCT_KEY_HOME, - End = SGCT_KEY_END, - CapsLock = SGCT_KEY_CAPS_LOCK, - ScrollLock = SGCT_KEY_SCROLL_LOCK, - NumLock = SGCT_KEY_NUM_LOCK, - PrintScreen = SGCT_KEY_PRINT_SCREEN, - Pause = SGCT_KEY_PAUSE, - F1 = SGCT_KEY_F1, - F2 = SGCT_KEY_F2, - F3 = SGCT_KEY_F3, - F4 = SGCT_KEY_F4, - F5 = SGCT_KEY_F5, - F6 = SGCT_KEY_F6, - F7 = SGCT_KEY_F7, - F8 = SGCT_KEY_F8, - F9 = SGCT_KEY_F9, - F10 = SGCT_KEY_F10, - F11 = SGCT_KEY_F11, - F12 = SGCT_KEY_F12, - F13 = SGCT_KEY_F13, - F14 = SGCT_KEY_F14, - F15 = SGCT_KEY_F15, - F16 = SGCT_KEY_F16, - F17 = SGCT_KEY_F17, - F18 = SGCT_KEY_F18, - F19 = SGCT_KEY_F19, - F20 = SGCT_KEY_F20, - F21 = SGCT_KEY_F21, - F22 = SGCT_KEY_F22, - F23 = SGCT_KEY_F23, - F24 = SGCT_KEY_F24, - F25 = SGCT_KEY_F25, - Keypad0 = SGCT_KEY_KP_0, - Keypad1 = SGCT_KEY_KP_1, - Keypad2 = SGCT_KEY_KP_2, - Keypad3 = SGCT_KEY_KP_3, - Keypad4 = SGCT_KEY_KP_4, - Keypad5 = SGCT_KEY_KP_5, - Keypad6 = SGCT_KEY_KP_6, - Keypad7 = SGCT_KEY_KP_7, - Keypad8 = SGCT_KEY_KP_8, - Keypad9 = SGCT_KEY_KP_9, - KeypadDecimal = SGCT_KEY_KP_DECIMAL, - KeypadDivide = SGCT_KEY_KP_DIVIDE, - KeypadMultiply = SGCT_KEY_KP_MULTIPLY, - KeypadSubtract = SGCT_KEY_KP_SUBTRACT, - KeypadAdd = SGCT_KEY_KP_ADD, - KeypadEnter = SGCT_KEY_KP_ENTER, - LeftShift = SGCT_KEY_LEFT_SHIFT, - LeftControl = SGCT_KEY_LEFT_CONTROL, - LeftAlt = SGCT_KEY_LEFT_ALT, - LeftSuper = SGCT_KEY_LEFT_SUPER, - RightShift = SGCT_KEY_RIGHT_SHIFT, - RightControl = SGCT_KEY_RIGHT_CONTROL, - RightAlt = SGCT_KEY_RIGHT_ALT, - RightSuper = SGCT_KEY_RIGHT_SUPER, - Menu = SGCT_KEY_MENU, - Last = SGCT_KEY_LAST + Unknown = -1, + Space = 32, + Apostrophe = 39, + Comma = 44, + Minus = 45, + Period = 46, + Slash = 47, + Num0 = 48, + Num1 = 49, + Num2 = 50, + Num3 = 51, + Num4 = 52, + Num5 = 53, + Num6 = 54, + Num7 = 55, + Num8 = 56, + Num9 = 57, + SemiColon = 59, + Equal = 61, + A = 65, + B = 66, + C = 67, + D = 68, + E = 69, + F = 70, + G = 71, + H = 72, + I = 73, + J = 74, + K = 75, + L = 76, + M = 77, + N = 78, + O = 79, + P = 80, + Q = 81, + R = 82, + S = 83, + T = 84, + U = 85, + V = 86, + W = 87, + X = 88, + Y = 89, + Z = 90, + LeftBracket = 91, + BackSlash = 92, + RightBracket = 93, + GraveAccent = 96, + World1 = 161, + World2 = 162, + Escape = 256, + Enter = 257, + Tab = 258, + BackSpace = 259, + Insert = 260, + Delete = 261, + Right = 262, + Left = 263, + Down = 264, + Up = 265, + PageUp = 266, + PageDown = 267, + Home = 268, + End = 269, + CapsLock = 280, + ScrollLock = 281, + NumLock = 282, + PrintScreen = 283, + Pause = 284, + F1 = 290, + F2 = 291, + F3 = 292, + F4 = 293, + F5 = 294, + F6 = 295, + F7 = 296, + F8 = 297, + F9 = 298, + F10 = 299, + F11 = 300, + F12 = 301, + F13 = 302, + F14 = 303, + F15 = 304, + F16 = 305, + F17 = 306, + F18 = 307, + F19 = 308, + F20 = 309, + F21 = 310, + F22 = 311, + F23 = 312, + F24 = 313, + F25 = 314, + Keypad0 = 320, + Keypad1 = 321, + Keypad2 = 322, + Keypad3 = 323, + Keypad4 = 324, + Keypad5 = 325, + Keypad6 = 326, + Keypad7 = 327, + Keypad8 = 328, + Keypad9 = 329, + KeypadDecimal = 330, + KeypadDivide = 331, + KeypadMultiply = 332, + KeypadSubtract = 333, + KeypadAdd = 334, + KeypadEnter = 335, + LeftShift = 340, + LeftControl = 341, + LeftAlt = 342, + LeftSuper = 343, + RightShift = 344, + RightControl = 345, + RightAlt = 346, + RightSuper = 347, + Menu = 348, + Last = Menu }; + +static const std::map KeyMapping = { + { "SPACE", Key::Space }, + { "APOSTROPHE", Key::Apostrophe }, + { "COMMA", Key::Comma }, + { "MINUS", Key::Minus }, + { "PERIOD", Key::Period }, + { "SLASH", Key::Slash }, + { "0", Key::Num0 }, + { "1", Key::Num1 }, + { "2", Key::Num2 }, + { "3", Key::Num3 }, + { "4", Key::Num4 }, + { "5", Key::Num5 }, + { "6", Key::Num6 }, + { "7", Key::Num7 }, + { "8", Key::Num8 }, + { "9", Key::Num9 }, + { "SEMICOLON", Key::SemiColon }, + { "EQUAL", Key::Equal }, + { "A", Key::A }, + { "B", Key::B }, + { "C", Key::C }, + { "D", Key::D }, + { "E", Key::E }, + { "F", Key::F }, + { "G", Key::G }, + { "H", Key::H }, + { "I", Key::I }, + { "J", Key::J }, + { "K", Key::K }, + { "L", Key::L }, + { "M", Key::M }, + { "N", Key::N }, + { "O", Key::O }, + { "P", Key::P }, + { "Q", Key::Q }, + { "R", Key::R }, + { "S", Key::S }, + { "T", Key::T }, + { "U", Key::U }, + { "V", Key::V }, + { "W", Key::W }, + { "X", Key::X }, + { "Y", Key::Y }, + { "Z", Key::Z }, + { "LEFT_BRACKET", Key::LeftBracket }, + { "BACKSLASH", Key::BackSlash }, + { "RIGHT_BRACKET", Key::RightBracket }, + { "GRAVE_ACCENT", Key::GraveAccent }, + { "WORLD_1", Key::World1 }, + { "WORLD_2", Key::World2 }, + { "ESC", Key::Escape }, + { "ESCAPE", Key::Escape}, + { "ENTER", Key::Enter }, + { "TAB", Key::Tab }, + { "BACKSPACE", Key::BackSpace }, + { "INSERT", Key::Insert }, + { "DEL", Key::Delete }, + { "DELETE", Key::Delete }, + { "RIGHT", Key::Right }, + { "LEFT", Key::Left }, + { "DOWN", Key::Down }, + { "UP", Key::Up }, + { "PAGEUP", Key::PageUp }, + { "PAGEDOWN", Key::PageDown }, + { "PAGE_UP", Key::PageUp }, + { "PAGE_DOWN", Key::PageDown }, + { "HOME", Key::Home }, + { "END", Key::End }, + { "CAPS_LOCK", Key::CapsLock }, + { "SCROLL_LOCK", Key::ScrollLock }, + { "NUM_LOCK", Key::NumLock }, + { "PRINT_SCREEN", Key::PrintScreen }, + { "PAUSE", Key::Pause }, + { "F1", Key::F1 }, + { "F2", Key::F2 }, + { "F3", Key::F3 }, + { "F4", Key::F4 }, + { "F5", Key::F5 }, + { "F6", Key::F6 }, + { "F7", Key::F7 }, + { "F8", Key::F8 }, + { "F9", Key::F9 }, + { "F10", Key::F10 }, + { "F11", Key::F11 }, + { "F12", Key::F12 }, + { "F13", Key::F13 }, + { "F14", Key::F14 }, + { "F15", Key::F15 }, + { "F16", Key::F16 }, + { "F17", Key::F17 }, + { "F18", Key::F18 }, + { "F19", Key::F19 }, + { "F20", Key::F20 }, + { "F21", Key::F21 }, + { "F22", Key::F22 }, + { "F23", Key::F23 }, + { "F24", Key::F24 }, + { "F25", Key::F25 }, + { "KP_0", Key::Keypad0 }, + { "KP_1", Key::Keypad1 }, + { "KP_2", Key::Keypad2 }, + { "KP_3", Key::Keypad3 }, + { "KP_4", Key::Keypad4 }, + { "KP_5", Key::Keypad5 }, + { "KP_6", Key::Keypad6 }, + { "KP_7", Key::Keypad7 }, + { "KP_8", Key::Keypad8 }, + { "KP_9", Key::Keypad9 }, + { "KP_DECIMAL", Key::KeypadDecimal }, + { "KP_DIVIDE", Key::KeypadDivide }, + { "KP_MULTIPLY", Key::KeypadMultiply }, + { "KP_SUBTRACT", Key::KeypadSubtract }, + { "KP_ADD", Key::KeypadAdd }, + { "KP_ENTER", Key::KeypadEnter }, + { "KP_EQUAL", Key::KeypadEnter }, + { "LSHIFT", Key::LeftShift }, + { "LEFT_SHIFT", Key::LeftShift }, + { "LCTRL", Key::LeftControl }, + { "LEFT_CONTROL", Key::LeftControl }, + { "LALT", Key::LeftAlt }, + { "LEFT_ALT", Key::LeftAlt }, + { "LEFT_SUPER", Key::LeftSuper }, + { "RSHIFT", Key::RightShift }, + { "RIGHT_SHIFT", Key::RightShift }, + { "RCTRL", Key::RightControl }, + { "RIGHT_CONTROL", Key::RightControl }, + { "RALT", Key::RightAlt }, + { "RIGHT_ALT", Key::RightAlt }, + { "RIGHT_SUPER", Key::RightSuper }, + { "MENU", Key::Menu } +}; + } // namespace openspace diff --git a/include/openspace/interaction/mouse.h b/include/openspace/util/mouse.h similarity index 56% rename from include/openspace/interaction/mouse.h rename to include/openspace/util/mouse.h index bba0b56e5f..73c5aa940a 100644 --- a/include/openspace/interaction/mouse.h +++ b/include/openspace/util/mouse.h @@ -22,36 +22,64 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +// This file is based on the definitions as presented in the GLFW library: +/************************************************************************* + * GLFW 3.1 - www.glfw.org + * A library for OpenGL, window and input + *------------------------------------------------------------------------ + * Copyright (c) 2002-2006 Marcus Geelnard + * Copyright (c) 2006-2010 Camilla Berglund + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would + * be appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not + * be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. + * + *************************************************************************/ + +// All values that are defined here are compatible with (and are based on) the +// definitions GLFW v3.1 + #ifndef __MOUSE_H__ #define __MOUSE_H__ -#include - namespace openspace { -namespace interaction { enum class MouseAction { - Press = SGCT_PRESS, - Release = SGCT_RELEASE, - Repeat = SGCT_REPEAT + Release = 0, + Press = 1, + Repeat = 2 }; enum class MouseButton { - Left = SGCT_MOUSE_BUTTON_LEFT, - Right = SGCT_MOUSE_BUTTON_RIGHT, - Middle = SGCT_MOUSE_BUTTON_MIDDLE, - //Button1 = SGCT_MOUSE_BUTTON_1, - //Button2 = SGCT_MOUSE_BUTTON_2, - //Button3 = SGCT_MOUSE_BUTTON_3, - //Button4 = SGCT_MOUSE_BUTTON_4, - //Button5 = SGCT_MOUSE_BUTTON_5, - //Button6 = SGCT_MOUSE_BUTTON_6, - //Button7 = SGCT_MOUSE_BUTTON_7, - //Button8 = SGCT_MOUSE_BUTTON_8, - ButtonLast = SGCT_MOUSE_BUTTON_LAST, + Button1 = 0, + Button2 = 1, + Button3 = 2, + Button4 = 3, + Button5 = 4, + Button6 = 5, + Button7 = 6, + Button8 = 8, + Last = Button8, + Left = Button1, + Right = Button2, + Middle = Button3 }; -} // namespace interaction } // namespace openspace #endif // __MOUSE_H__ diff --git a/modules/onscreengui/include/gui.h b/modules/onscreengui/include/gui.h index 00e2c623cb..c835a5ff66 100644 --- a/modules/onscreengui/include/gui.h +++ b/modules/onscreengui/include/gui.h @@ -32,6 +32,9 @@ #include #include +#include +#include + namespace openspace { namespace gui { @@ -49,12 +52,14 @@ public: void initializeGL(); void deinitializeGL(); - bool mouseButtonCallback(int key, int action); + bool mouseButtonCallback(MouseButton button, MouseAction action); +// bool mouseButtonCallback(int key, int action); bool mouseWheelCallback(double position); - bool keyCallback(int key, int action); + bool keyCallback(Key key, KeyAction action); +// bool keyCallback(int key, int action); bool charCallback(unsigned int character); - void startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePos, bool mouseButtonsPressed[2]); + void startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePos, uint32_t mouseButtons); void endFrame(); void renderMainWindow(); diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index 752881d563..81a503fb35 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -257,7 +257,7 @@ void GUI::deinitializeGL() { void GUI::startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePos, - bool mouseButtonsPressed[2]) + uint32_t mouseButtonsPressed) { ImGuiIO& io = ImGui::GetIO(); @@ -268,8 +268,8 @@ void GUI::startFrame(float deltaTime, #else io.MousePos = ImVec2(mousePos.x, mousePos.y); #endif - io.MouseDown[0] = mouseButtonsPressed[0]; - io.MouseDown[1] = mouseButtonsPressed[1]; + io.MouseDown[0] = mouseButtonsPressed & (1 << 0); + io.MouseDown[1] = mouseButtonsPressed & (1 << 1); ImGui::NewFrame(); } @@ -287,7 +287,8 @@ void GUI::endFrame() { ImGui::Render(); } -bool GUI::mouseButtonCallback(int key, int action) { +bool GUI::mouseButtonCallback(MouseButton button, MouseAction action) { +//bool GUI::mouseButtonCallback(int key, int action) { ImGuiIO& io = ImGui::GetIO(); bool consumeEvent = io.WantCaptureMouse; return consumeEvent; @@ -302,14 +303,20 @@ bool GUI::mouseWheelCallback(double position) { return consumeEvent; } -bool GUI::keyCallback(int key, int action) { +bool GUI::keyCallback(Key key, KeyAction action) { +//bool GUI::keyCallback(int key, int action) { ImGuiIO& io = ImGui::GetIO(); bool consumeEvent = io.WantCaptureKeyboard; if (consumeEvent) { - if (action == SGCT_PRESS) - io.KeysDown[key] = true; - if (action == SGCT_RELEASE) - io.KeysDown[key] = false; + int keyIndex = static_cast(key); + if (keyIndex < 0) + LERROR("Pressed key of index '" << keyIndex << "' was negative"); + else { + if (action == KeyAction::Press) + io.KeysDown[keyIndex] = true; + if (action == KeyAction::Release) + io.KeysDown[keyIndex] = false; + } } return consumeEvent; } diff --git a/openspace.cfg b/openspace.cfg index 6c9f304463..cad9aaf1f8 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -7,7 +7,7 @@ return { -- Sets the scene that is to be loaded by OpenSpace. A scene file is a description -- of all entities that will be visible during an instance of OpenSpace - Scene = "${SCENE}/default_nh.scene", + Scene = "${SCENE}/default.scene", Paths = { SGCT = "${BASE_PATH}/config/sgct", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f4e59f7eac..268023182c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,7 +107,6 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/interaction/interactionhandler.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/keyboardcontroller.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/luaconsole.h - ${OPENSPACE_BASE_DIR}/include/openspace/interaction/mouse.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/mousecontroller.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/externalcontrol/externalconnectioncontroller.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/externalcontrol/externalcontrol.h @@ -148,6 +147,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/util/factorymanager.h ${OPENSPACE_BASE_DIR}/include/openspace/util/factorymanager.inl ${OPENSPACE_BASE_DIR}/include/openspace/util/keys.h + ${OPENSPACE_BASE_DIR}/include/openspace/util/mouse.h ${OPENSPACE_BASE_DIR}/include/openspace/util/openspacemodule.h ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledcoordinate.h ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledscalar.h diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index e534d36071..791bdd8253 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -689,44 +689,33 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { _renderEngine->postSynchronizationPreDraw(); - if (_isMaster && _gui->isEnabled()) { + if (_isMaster && _gui->isEnabled() && _windowHandler->isRegularRendering()) { glm::vec2 mousePosition = _windowHandler->mousePosition(); glm::ivec2 windowResolution = _windowHandler->currentWindowResolution(); + uint32_t mouseButtons = _windowHandler->mouseButtons(2); + + double dt = _windowHandler->averageDeltaTime(); - int button0 = sgct::Engine::instance()->getMouseButton(0, 0); - int button1 = sgct::Engine::instance()->getMouseButton(0, 1); - bool buttons[2] = { button0 != 0, button1 != 0 }; - - double dt = std::max(sgct::Engine::instance()->getDt(), 1.0/60.0); - _gui->startFrame(static_cast(dt), glm::vec2(windowResolution), mousePosition, buttons); + _gui->startFrame(static_cast(dt), glm::vec2(windowResolution), mousePosition, mouseButtons); } } void OpenSpaceEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &viewMatrix) { _renderEngine->render(projectionMatrix, viewMatrix); - if (_isMaster) { - // If currently writing a command, render it to screen - sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr(); - // !w->isUsingFisheyeRendering() does not exist anymore ---abock - // if (_isMaster && !w->isUsingFisheyeRendering() && _console->isVisible()) { - if (_isMaster && _console->isVisible()) { + if (_isMaster && _windowHandler->isRegularRendering()) { + if (_console->isVisible()) _console->render(); - } - if (_gui->isEnabled()) _gui->endFrame(); } } void OpenSpaceEngine::postDraw() { - //if (_isMaster) - //_interactionHandler.unlockControls(); - _renderEngine->postDraw(); } -void OpenSpaceEngine::keyboardCallback(int key, int action) { +void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) { if (_isMaster) { if (_gui->isEnabled()) { bool isConsumed = _gui->keyCallback(key, action); @@ -734,7 +723,7 @@ void OpenSpaceEngine::keyboardCallback(int key, int action) { return; } - if (static_cast(key) == _console->commandInputButton() && (action == SGCT_PRESS || action == SGCT_REPEAT)) + if (key == _console->commandInputButton() && (action == KeyAction::Press || action == KeyAction::Release)) _console->toggleVisibility(); if (!_console->isVisible()) { @@ -760,15 +749,15 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint) { } } -void OpenSpaceEngine::mouseButtonCallback(int key, int action) { +void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action) { if (_isMaster) { if (_gui->isEnabled()) { - bool isConsumed = _gui->mouseButtonCallback(key, action); - if (isConsumed && action != SGCT_RELEASE) + bool isConsumed = _gui->mouseButtonCallback(button, action); + if (isConsumed && action != MouseAction::Release) return; } - _interactionHandler->mouseButtonCallback(key, action); + _interactionHandler->mouseButtonCallback(button, action); } } diff --git a/src/engine/sgctwindowhandler.cpp b/src/engine/sgctwindowhandler.cpp index f60af53d05..c2e8d3062c 100644 --- a/src/engine/sgctwindowhandler.cpp +++ b/src/engine/sgctwindowhandler.cpp @@ -48,20 +48,44 @@ double SGCTWindowHandler::averageDeltaTime() { } glm::vec2 SGCTWindowHandler::mousePosition() { + int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); double posX, posY; - sgct::Engine::instance()->getMousePos(0, &posX, &posY); + sgct::Engine::instance()->getMousePos(id, &posX, &posY); return glm::vec2(posX, posY); } +uint32_t SGCTWindowHandler::mouseButtons(int maxNumber) { + int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); + uint32_t result = 0; + for (int i = 0; i < maxNumber; ++i) { + bool button = (sgct::Engine::instance()->getMouseButton(id, i) != 0); + if (button) + result |= (1 << i); + + } + return result; +} + glm::ivec2 SGCTWindowHandler::currentWindowSize() { - return glm::ivec2(0); + return glm::ivec2(sgct::Engine::instance()->getCurrentWindowPtr()->getXResolution(), + sgct::Engine::instance()->getCurrentWindowPtr()->getYResolution()); } glm::ivec2 SGCTWindowHandler::currentWindowResolution() { int x,y; - sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y); + sgct::Engine::instance()->getCurrentWindowPtr()->getFinalFBODimensions(x, y); return glm::ivec2(x, y); } + +bool SGCTWindowHandler::isRegularRendering() { + // TODO: Needs to implement the nonlinear rendering check ---abock + + // sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr(); + // !w->isUsingFisheyeRendering() does not exist anymore ---abock + // if (_isMaster && !w->isUsingFisheyeRendering() && _console->isVisible()) { + + return true; +} //void forEachWindow(std::function function) { // size_t n = sgct::Engine::instance()->getNumberOfWindows(); diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 55c90177a9..1dc3bd9953 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -37,149 +38,16 @@ namespace { const std::string _loggerCat = "InteractionHandler"; - int stringToKey(std::string s) { - - static std::map m = { - { "SPACE", SGCT_KEY_SPACE }, - { "APOSTROPHE", SGCT_KEY_APOSTROPHE }, - { "COMMA", SGCT_KEY_COMMA }, - { "MINUS", SGCT_KEY_MINUS }, - { "PERIOD", SGCT_KEY_PERIOD }, - { "APOSTROPHE", SGCT_KEY_SLASH }, - { "0", SGCT_KEY_0 }, - { "1", SGCT_KEY_1 }, - { "2", SGCT_KEY_2 }, - { "3", SGCT_KEY_3 }, - { "4", SGCT_KEY_4 }, - { "5", SGCT_KEY_5 }, - { "6", SGCT_KEY_6 }, - { "7", SGCT_KEY_7 }, - { "8", SGCT_KEY_8 }, - { "9", SGCT_KEY_9 }, - { "SEMICOLON", SGCT_KEY_SEMICOLON }, - { "EQUAL", SGCT_KEY_EQUAL }, - { "A", SGCT_KEY_A }, - { "B", SGCT_KEY_B }, - { "C", SGCT_KEY_C }, - { "D", SGCT_KEY_D }, - { "E", SGCT_KEY_E }, - { "F", SGCT_KEY_F }, - { "G", SGCT_KEY_G }, - { "H", SGCT_KEY_H }, - { "I", SGCT_KEY_I }, - { "J", SGCT_KEY_J }, - { "K", SGCT_KEY_K }, - { "L", SGCT_KEY_L }, - { "M", SGCT_KEY_M }, - { "N", SGCT_KEY_N }, - { "O", SGCT_KEY_O }, - { "P", SGCT_KEY_P }, - { "Q", SGCT_KEY_Q }, - { "R", SGCT_KEY_R }, - { "S", SGCT_KEY_S }, - { "T", SGCT_KEY_T }, - { "U", SGCT_KEY_U }, - { "V", SGCT_KEY_V }, - { "W", SGCT_KEY_W }, - { "X", SGCT_KEY_X }, - { "Y", SGCT_KEY_Y }, - { "Z", SGCT_KEY_Z }, - { "LEFT_BRACKET", SGCT_KEY_LEFT_BRACKET }, - { "BACKSLASH", SGCT_KEY_BACKSLASH }, - { "RIGHT_BRACKET", SGCT_KEY_RIGHT_BRACKET }, - { "GRAVE_ACCENT", SGCT_KEY_GRAVE_ACCENT }, - { "WORLD_1", SGCT_KEY_WORLD_1 }, - { "WORLD_2", SGCT_KEY_WORLD_2 }, - { "ESC", SGCT_KEY_ESC }, - { "ESCAPE", SGCT_KEY_ESCAPE }, - { "ENTER", SGCT_KEY_ENTER }, - { "TAB", SGCT_KEY_TAB }, - { "BACKSPACE", SGCT_KEY_BACKSPACE }, - { "INSERT", SGCT_KEY_INSERT }, - { "DEL", SGCT_KEY_DEL }, - { "DELETE", SGCT_KEY_DELETE }, - { "RIGHT", SGCT_KEY_RIGHT }, - { "LEFT", SGCT_KEY_LEFT }, - { "DOWN", SGCT_KEY_DOWN }, - { "UP", SGCT_KEY_UP }, - { "PAGEUP", SGCT_KEY_PAGEUP }, - { "PAGEDOWN", SGCT_KEY_PAGEDOWN }, - { "PAGE_UP", SGCT_KEY_PAGE_UP }, - { "PAGE_DOWN", SGCT_KEY_PAGE_DOWN }, - { "HOME", SGCT_KEY_HOME }, - { "END", SGCT_KEY_END }, - { "CAPS_LOCK", SGCT_KEY_CAPS_LOCK }, - { "SCROLL_LOCK", SGCT_KEY_SCROLL_LOCK }, - { "NUM_LOCK", SGCT_KEY_NUM_LOCK }, - { "PRINT_SCREEN", SGCT_KEY_PRINT_SCREEN }, - { "PAUSE", SGCT_KEY_PAUSE }, - { "F1", SGCT_KEY_F1 }, - { "F2", SGCT_KEY_F2 }, - { "F3", SGCT_KEY_F3 }, - { "F4", SGCT_KEY_F4 }, - { "F5", SGCT_KEY_F5 }, - { "F6", SGCT_KEY_F6 }, - { "F7", SGCT_KEY_F7 }, - { "F8", SGCT_KEY_F8 }, - { "F9", SGCT_KEY_F9 }, - { "F10", SGCT_KEY_F10 }, - { "F11", SGCT_KEY_F11 }, - { "F12", SGCT_KEY_F12 }, - { "F13", SGCT_KEY_F13 }, - { "F14", SGCT_KEY_F14 }, - { "F15", SGCT_KEY_F15 }, - { "F16", SGCT_KEY_F16 }, - { "F17", SGCT_KEY_F17 }, - { "F18", SGCT_KEY_F18 }, - { "F19", SGCT_KEY_F19 }, - { "F20", SGCT_KEY_F20 }, - { "F21", SGCT_KEY_F21 }, - { "F22", SGCT_KEY_F22 }, - { "F23", SGCT_KEY_F23 }, - { "F24", SGCT_KEY_F24 }, - { "F25", SGCT_KEY_F25 }, - { "KP_0", SGCT_KEY_KP_0 }, - { "KP_1", SGCT_KEY_KP_1 }, - { "KP_2", SGCT_KEY_KP_2 }, - { "KP_3", SGCT_KEY_KP_3 }, - { "KP_4", SGCT_KEY_KP_4 }, - { "KP_5", SGCT_KEY_KP_5 }, - { "KP_6", SGCT_KEY_KP_6 }, - { "KP_7", SGCT_KEY_KP_7 }, - { "KP_8", SGCT_KEY_KP_8 }, - { "KP_9", SGCT_KEY_KP_9 }, - { "KP_DECIMAL", SGCT_KEY_KP_DECIMAL }, - { "KP_DIVIDE", SGCT_KEY_KP_DIVIDE }, - { "KP_MULTIPLY", SGCT_KEY_KP_MULTIPLY }, - { "KP_SUBTRACT", SGCT_KEY_KP_SUBTRACT }, - { "KP_ADD", SGCT_KEY_KP_ADD }, - { "KP_ENTER", SGCT_KEY_KP_ENTER }, - { "KP_EQUAL", SGCT_KEY_KP_EQUAL }, - { "LSHIFT", SGCT_KEY_LSHIFT }, - { "LEFT_SHIFT", SGCT_KEY_LEFT_SHIFT }, - { "LCTRL", SGCT_KEY_LCTRL }, - { "LEFT_CONTROL", SGCT_KEY_LEFT_CONTROL }, - { "LALT", SGCT_KEY_LALT }, - { "LEFT_ALT", SGCT_KEY_LEFT_ALT }, - { "LEFT_SUPER", SGCT_KEY_LEFT_SUPER }, - { "RSHIFT", SGCT_KEY_RSHIFT }, - { "RIGHT_SHIFT", SGCT_KEY_RIGHT_SHIFT }, - { "RCTRL", SGCT_KEY_RCTRL }, - { "RIGHT_CONTROL", SGCT_KEY_RIGHT_CONTROL }, - { "RALT", SGCT_KEY_RALT }, - { "RIGHT_ALT", SGCT_KEY_RIGHT_ALT }, - { "RIGHT_SUPER", SGCT_KEY_RIGHT_SUPER }, - { "MENU", SGCT_KEY_MENU } - }; + openspace::Key stringToKey(std::string s) { // key only uppercase std::transform(s.begin(), s.end(), s.begin(), ::toupper); // default is unknown - int key = SGCT_KEY_UNKNOWN; - auto it = m.find(s); - if (it != m.end()) - key = m[s]; - return key; + auto it = openspace::KeyMapping.find(s); + if (it != openspace::KeyMapping.end()) + return it->second; + else + return openspace::Key::Unknown; } } @@ -479,9 +347,9 @@ const Camera* const InteractionHandler::camera() const { // } //} -void InteractionHandler::mouseButtonCallback(int button, int action) { +void InteractionHandler::mouseButtonCallback(MouseButton button, MouseAction action) { if (_mouseController) - _mouseController->button(MouseAction(action), MouseButton(button)); + _mouseController->button(button, action); } void InteractionHandler::mousePositionCallback(double x, double y) { @@ -768,11 +636,11 @@ void InteractionHandler::lookAt(const glm::quat& rotation) // } //} // -void InteractionHandler::keyboardCallback(int key, int action) { +void InteractionHandler::keyboardCallback(Key key, KeyAction action) { // TODO package in script const float speed = _controllerSensitivity; const float dt = static_cast(_deltaTime); - if (action == SGCT_PRESS || action == SGCT_REPEAT) { + if (action == KeyAction::Press || action == KeyAction::Repeat) { /*if (key == SGCT_KEY_S) { glm::vec3 euler(speed * dt, 0.0, 0.0); @@ -800,32 +668,32 @@ void InteractionHandler::keyboardCallback(int key, int action) { if (key == SGCT_KEY_X) { Time::ref().advanceTime(-sgct::Engine::instance()->getDt()); }*/ - if (key == 262) { + if (key == Key::Right) { glm::vec3 euler(0.0, speed * dt*0.4, 0.0); glm::quat rot = glm::quat(euler); rotateDelta(rot); } - if (key == 263) { + if (key == Key::Left) { glm::vec3 euler(0.0, -speed * dt*0.4, 0.0); glm::quat rot = glm::quat(euler); rotateDelta(rot); } - if (key == 264) { + if (key == Key::Down) { glm::vec3 euler(speed * dt*0.4, 0.0, 0.0); glm::quat rot = glm::quat(euler); rotateDelta(rot); } - if (key == 265) { + if (key == Key::Up) { glm::vec3 euler(-speed * dt*0.4, 0.0, 0.0); glm::quat rot = glm::quat(euler); rotateDelta(rot); } - if (key == SGCT_KEY_KP_SUBTRACT) { + if (key == Key::KeypadSubtract) { glm::vec2 s = OsEng.renderEngine()->camera()->scaling(); s[1] -= 0.5f; OsEng.renderEngine()->camera()->setScaling(s); } - if (key == SGCT_KEY_KP_ADD) { + if (key == Key::KeypadAdd) { glm::vec2 s = OsEng.renderEngine()->camera()->scaling(); s[1] += 0.5f; OsEng.renderEngine()->camera()->setScaling(s); @@ -886,7 +754,7 @@ void InteractionHandler::resetKeyBindings() { _validKeyLua = false; } -void InteractionHandler::bindKey(int key, const std::string& lua) { +void InteractionHandler::bindKey(Key key, std::string lua) { _keyLua.insert(std::make_pair(key, lua)); } diff --git a/src/interaction/interactionhandler_lua.inl b/src/interaction/interactionhandler_lua.inl index ee87c72341..c735aefb61 100644 --- a/src/interaction/interactionhandler_lua.inl +++ b/src/interaction/interactionhandler_lua.inl @@ -76,9 +76,9 @@ int bindKey(lua_State* L) { if (command.empty()) return luaL_error(L, "Command string is empty"); - int iKey = stringToKey(key); + openspace::Key iKey = stringToKey(key); - if (iKey == SGCT_KEY_UNKNOWN) { + if (iKey == openspace::Key::Unknown) { LERROR("Could not find key '"<< key <<"'"); return 0; } diff --git a/src/interaction/luaconsole.cpp b/src/interaction/luaconsole.cpp index 211c02dfbb..2d26a6be72 100644 --- a/src/interaction/luaconsole.cpp +++ b/src/interaction/luaconsole.cpp @@ -103,8 +103,8 @@ void LuaConsole::deinitialize() { } } -void LuaConsole::keyboardCallback(int key, int action) { - if (action == SGCT_PRESS || action == SGCT_REPEAT) { +void LuaConsole::keyboardCallback(Key key, KeyAction action) { + if (action == KeyAction::Press || action == KeyAction::Release) { const size_t windowIndex = sgct::Engine::instance()->getFocusedWindowIndex(); const bool modifierControl = sgct::Engine::instance()->getKey(windowIndex, SGCT_KEY_LEFT_CONTROL) || sgct::Engine::instance()->getKey(windowIndex, SGCT_KEY_RIGHT_CONTROL); @@ -112,37 +112,37 @@ void LuaConsole::keyboardCallback(int key, int action) { sgct::Engine::instance()->getKey(windowIndex, SGCT_KEY_RIGHT_SHIFT); // Paste from clipboard - if (modifierControl && (key == SGCT_KEY_V)) + if (modifierControl && (key == Key::V)) addToCommand(ghoul::clipboardText()); // Copy to clipboard - if (modifierControl && (key == SGCT_KEY_C)) + if (modifierControl && (key == Key::C)) ghoul::setClipboardText(_commands.at(_activeCommand)); // Go to the previous character - if ((key == SGCT_KEY_LEFT) && (_inputPosition > 0)) + if ((key == Key::Left) && (_inputPosition > 0)) --_inputPosition; // Go to the next character - if ((key == SGCT_KEY_RIGHT) && _inputPosition < _commands.at(_activeCommand).length()) + if ((key == Key::Right) && _inputPosition < _commands.at(_activeCommand).length()) ++_inputPosition; // Go to previous command - if (key == SGCT_KEY_UP) { + if (key == Key::Up) { if (_activeCommand > 0) --_activeCommand; _inputPosition = _commands.at(_activeCommand).length(); } // Go to next command (the last is empty) - if (key == SGCT_KEY_DOWN) { + if (key == Key::Down) { if (_activeCommand < _commands.size() - 1) ++_activeCommand; _inputPosition = _commands.at(_activeCommand).length(); } // Remove character before _inputPosition - if (key == SGCT_KEY_BACKSPACE) { + if (key == Key::BackSpace) { if (_inputPosition > 0) { _commands.at(_activeCommand).erase(_inputPosition - 1, 1); --_inputPosition; @@ -150,18 +150,18 @@ void LuaConsole::keyboardCallback(int key, int action) { } // Remove character after _inputPosition - if ((key == SGCT_KEY_DELETE) && (_inputPosition <= _commands.at(_activeCommand).size())) + if ((key == Key::Delete) && (_inputPosition <= _commands.at(_activeCommand).size())) _commands.at(_activeCommand).erase(_inputPosition, 1); // Go to the beginning of command string - if (key == SGCT_KEY_HOME) + if (key == Key::Home) _inputPosition = 0; // Go to the end of command string - if (key == SGCT_KEY_END) + if (key == Key::End) _inputPosition = _commands.at(_activeCommand).size(); - if (key == SGCT_KEY_ENTER) { + if (key == Key::Enter) { // SHIFT+ENTER == new line if (modifierShift) addToCommand("\n"); @@ -188,7 +188,7 @@ void LuaConsole::keyboardCallback(int key, int action) { } } - if (key == SGCT_KEY_TAB) { + if (key == Key::Tab) { // We get a list of all the available commands and initially find the first // command that starts with how much we typed sofar. We store the index so // that in subsequent "tab" presses, we will discard previous commands. This @@ -265,7 +265,7 @@ void LuaConsole::keyboardCallback(int key, int action) { } void LuaConsole::charCallback(unsigned int codepoint) { - if (codepoint == commandInputButton()) + if (codepoint == static_cast(commandInputButton())) return; #ifndef WIN32 @@ -321,10 +321,10 @@ void LuaConsole::render() { sgct_text::print(font, 15.0f + font_size*0.5f, startY - (font_size)*(n + 1)*3.0f / 2.0f, green, ss.str().c_str(), "^"); } -unsigned int LuaConsole::commandInputButton() { +Key LuaConsole::commandInputButton() { // Button left of 1 and above TAB // How to deal with different keyboard languages? ---abock - return SGCT_KEY_GRAVE_ACCENT; + return Key::GraveAccent; } void LuaConsole::addToCommand(std::string c) { diff --git a/src/interaction/mousecontroller.cpp b/src/interaction/mousecontroller.cpp index ba816eb91b..a860cc4b01 100644 --- a/src/interaction/mousecontroller.cpp +++ b/src/interaction/mousecontroller.cpp @@ -25,6 +25,7 @@ #include #include +#include #include @@ -72,9 +73,8 @@ glm::vec3 MouseController::mapToCamera(glm::vec3 trackballPos) { void MouseController::trackballRotate(int x, int y) { // Normalize mouse coordinates to [0,1] - float width = static_cast(sgct::Engine::instance()->getCurrentXResolution()); - float height = static_cast(sgct::Engine::instance()->getCurrentYResolution()); - glm::vec2 mousePos = glm::vec2((float)x / width, (float)y / height); + glm::vec2 res = OsEng.windowWrapper()->currentWindowSize(); + glm::vec2 mousePos = glm::vec2((float)x / res.x, (float)y / res.y); mousePos = glm::clamp(mousePos, -0.5f, 1.5f); // Ugly fix #1: Camera position becomes NaN on mouse values outside [-0.5, 1.5] //mousePos[1] = 0.5; // Ugly fix #2: Tempoarily only allow rotation around y @@ -116,7 +116,7 @@ TrackballMouseController::TrackballMouseController() , _leftMouseButtonDown(false) {} -void TrackballMouseController::button(MouseAction action, MouseButton button) { +void TrackballMouseController::button(MouseButton button, MouseAction action) { if (button == MouseButton::Left && action == MouseAction::Press) _leftMouseButtonDown = true; else if (button == MouseButton::Left && action == MouseAction::Release) { @@ -162,13 +162,11 @@ OrbitalMouseController::OrbitalMouseController() } } -void OrbitalMouseController::button(MouseAction action, MouseButton button) { +void OrbitalMouseController::button(MouseButton button, MouseAction action) { if (button == MouseButton::Left){ if (action == MouseAction::Press){ _leftMouseButtonDown = true; - double mouseX, mouseY; - sgct::Engine::instance()->getMousePos(sgct::Engine::instance()->getCurrentWindowPtr()->getId(), &mouseX, &mouseY); - _previousCursorPos[MouseButtons::ButtonLeft] = glm::vec2(static_cast(mouseX), static_cast(mouseY)); + _previousCursorPos[MouseButtons::ButtonLeft] = OsEng.windowWrapper()->mousePosition(); } else if (action == MouseAction::Release) { _leftMouseButtonDown = false; @@ -178,9 +176,7 @@ void OrbitalMouseController::button(MouseAction action, MouseButton button) { else if (button == MouseButton::Right){ if (action == MouseAction::Press){ _rightMouseButtonDown = true; - double mouseX, mouseY; - sgct::Engine::instance()->getMousePos(sgct::Engine::instance()->getCurrentWindowPtr()->getId(), &mouseX, &mouseY); - _previousCursorPos[MouseButtons::ButtonRight] = glm::vec2(static_cast(mouseX), static_cast(mouseY)); + _previousCursorPos[MouseButtons::ButtonRight] = OsEng.windowWrapper()->mousePosition(); } else if (action == MouseAction::Release) { _rightMouseButtonDown = false; @@ -190,9 +186,7 @@ void OrbitalMouseController::button(MouseAction action, MouseButton button) { else if (button == MouseButton::Middle){ if (action == MouseAction::Press){ _middleMouseButtonDown = true; - double mouseX, mouseY; - sgct::Engine::instance()->getMousePos(sgct::Engine::instance()->getCurrentWindowPtr()->getId(), &mouseX, &mouseY); - _previousCursorPos[MouseButtons::ButtonMiddle] = glm::vec2(static_cast(mouseX), static_cast(mouseY)); + _previousCursorPos[MouseButtons::ButtonMiddle] = OsEng.windowWrapper()->mousePosition(); } else if (action == MouseAction::Release) { _middleMouseButtonDown = false; @@ -203,19 +197,22 @@ void OrbitalMouseController::button(MouseAction action, MouseButton button) { } void OrbitalMouseController::move(float x, float y) { - int winID = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); - double mouseX, mouseY; - sgct::Engine::instance()->getMousePos(winID, &mouseX, &mouseY); - _currentCursorPos = glm::vec2(static_cast(mouseX), static_cast(mouseY)); + _currentCursorPos = OsEng.windowWrapper()->mousePosition(); if (_leftMouseButtonDown) { - _currentCursorDiff[MouseButtons::ButtonLeft] = (_currentCursorPos - _previousCursorPos[MouseButtons::ButtonLeft]) / glm::vec2(static_cast(sgct::Engine::instance()->getWindowPtr(winID)->getXResolution()), static_cast(sgct::Engine::instance()->getWindowPtr(winID)->getYResolution())); + glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonLeft]; + glm::vec2 res = OsEng.windowWrapper()->currentWindowSize(); + _currentCursorDiff[MouseButtons::ButtonLeft] = diff / res; } if (_rightMouseButtonDown) { - _currentCursorDiff[MouseButtons::ButtonRight] = (_currentCursorPos - _previousCursorPos[MouseButtons::ButtonRight]) / glm::vec2(static_cast(sgct::Engine::instance()->getWindowPtr(winID)->getXResolution()), static_cast(sgct::Engine::instance()->getWindowPtr(winID)->getYResolution())); + glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonRight]; + glm::vec2 res = OsEng.windowWrapper()->currentWindowSize(); + _currentCursorDiff[MouseButtons::ButtonRight] = diff / res; } if (_middleMouseButtonDown) { - _currentCursorDiff[MouseButtons::ButtonMiddle] = (_currentCursorPos - _previousCursorPos[MouseButtons::ButtonMiddle]) / glm::vec2(static_cast(sgct::Engine::instance()->getWindowPtr(winID)->getXResolution()), static_cast(sgct::Engine::instance()->getWindowPtr(winID)->getYResolution())); + glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonMiddle]; + glm::vec2 res = OsEng.windowWrapper()->currentWindowSize(); + _currentCursorDiff[MouseButtons::ButtonMiddle] = diff / res; } }