Line data Source code
1 : /** 2 : Copyright (c) 2022 Roman Katuntsev <sbkarr@stappler.org> 3 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 4 : 5 : Permission is hereby granted, free of charge, to any person obtaining a copy 6 : of this software and associated documentation files (the "Software"), to deal 7 : in the Software without restriction, including without limitation the rights 8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 : copies of the Software, and to permit persons to whom the Software is 10 : furnished to do so, subject to the following conditions: 11 : 12 : The above copyright notice and this permission notice shall be included in 13 : all copies or substantial portions of the Software. 14 : 15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 : THE SOFTWARE. 22 : **/ 23 : 24 : #ifndef XENOLITH_SCENE_INPUT_XLINPUT_H_ 25 : #define XENOLITH_SCENE_INPUT_XLINPUT_H_ 26 : 27 : #include "XLNodeInfo.h" 28 : #include "XLCoreInput.h" 29 : 30 : namespace STAPPLER_VERSIONIZED stappler::xenolith { 31 : 32 : using InputFlags = core::InputFlags; 33 : using InputMouseButton = core::InputMouseButton; 34 : using InputModifier = core::InputModifier; 35 : using InputKeyCode = core::InputKeyCode; 36 : using InputKeyComposeState = core::InputKeyComposeState; 37 : using InputEventName = core::InputEventName; 38 : using InputEventData = core::InputEventData; 39 : using TextInputType = core::TextInputType; 40 : using TextCursor = core::TextCursor; 41 : using TextCursorPosition = core::TextCursorPosition; 42 : using TextCursorLength = core::TextCursorLength; 43 : 44 : enum class InputEventState { 45 : Declined, // Получатель не заинтересован в этой цепочке событий 46 : Processed, // Получатель заинтересован в цепочке событий, но не требует эксклюзивности 47 : Captured, // Получатель запрашивает цепочку событий в эксклюзивную обработку 48 : }; 49 : 50 : struct InputEvent { 51 : InputEventData data; 52 : Vec2 originalLocation; 53 : Vec2 currentLocation; 54 : Vec2 previousLocation; 55 : uint64_t originalTime = 0; 56 : uint64_t currentTime = 0; 57 : uint64_t previousTime = 0; 58 : InputModifier originalModifiers = InputModifier::None; 59 : InputModifier previousModifiers = InputModifier::None; 60 : }; 61 : 62 : class TextInputViewInterface { 63 : public: 64 4 : virtual ~TextInputViewInterface() { } 65 : 66 : virtual void updateTextCursor(uint32_t pos, uint32_t len) = 0; 67 : virtual void updateTextInput(WideStringView str, uint32_t pos, uint32_t len, TextInputType) = 0; 68 : virtual void runTextInput(WideStringView str, uint32_t pos, uint32_t len, TextInputType) = 0; 69 : virtual void cancelTextInput() = 0; 70 : }; 71 : 72 : #ifndef __LCC__ 73 : 74 : constexpr const TextCursor TextCursor::InvalidCursor(maxOf<uint32_t>(), 0.0f); 75 : 76 : #endif 77 : 78 : } 79 : 80 : namespace std { 81 : 82 : template <> 83 : struct hash<STAPPLER_VERSIONIZED_NAMESPACE::xenolith::InputEventData> { 84 : size_t operator() (const STAPPLER_VERSIONIZED_NAMESPACE::xenolith::InputEventData &ev) const { 85 : return std::hash<uint32_t>{}(ev.id); 86 : } 87 : }; 88 : 89 : } 90 : 91 : #endif /* XENOLITH_SCENE_INPUT_XLINPUT_H_ */