openxr_interaction_profile.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**************************************************************************/
  2. /* openxr_interaction_profile.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef OPENXR_INTERACTION_PROFILE_H
  31. #define OPENXR_INTERACTION_PROFILE_H
  32. #include "openxr_action.h"
  33. #include "openxr_binding_modifier.h"
  34. #include "openxr_interaction_profile_metadata.h"
  35. #include "core/io/resource.h"
  36. class OpenXRActionMap;
  37. class OpenXRIPBinding : public Resource {
  38. GDCLASS(OpenXRIPBinding, Resource);
  39. private:
  40. Ref<OpenXRAction> action;
  41. String binding_path;
  42. Vector<Ref<OpenXRActionBindingModifier>> binding_modifiers;
  43. protected:
  44. friend class OpenXRActionMap;
  45. OpenXRActionMap *action_map = nullptr;
  46. static void _bind_methods();
  47. public:
  48. static Ref<OpenXRIPBinding> new_binding(const Ref<OpenXRAction> p_action, const String &p_binding_path); // Helper function for adding a new binding.
  49. OpenXRActionMap *get_action_map() { return action_map; } // Return the action map we're a part of.
  50. void set_action(const Ref<OpenXRAction> &p_action); // Set the action for this binding.
  51. Ref<OpenXRAction> get_action() const; // Get the action for this binding.
  52. void set_binding_path(const String &path);
  53. String get_binding_path() const;
  54. int get_binding_modifier_count() const; // Retrieve the number of binding modifiers in this profile path
  55. Ref<OpenXRActionBindingModifier> get_binding_modifier(int p_index) const;
  56. void clear_binding_modifiers(); // Remove all binding modifiers
  57. void set_binding_modifiers(const Array &p_bindings); // Set the binding modifiers (for loading from a resource)
  58. Array get_binding_modifiers() const; // Get the binding modifiers (for saving to a resource)
  59. void add_binding_modifier(const Ref<OpenXRActionBindingModifier> &p_binding_modifier); // Add a binding modifier object
  60. void remove_binding_modifier(const Ref<OpenXRActionBindingModifier> &p_binding_modifier); // Remove a binding modifier object
  61. // Deprecated.
  62. #ifndef DISABLE_DEPRECATED
  63. void set_paths(const PackedStringArray p_paths); // Set our paths (for loading from resource), needed for loading old action maps.
  64. PackedStringArray get_paths() const; // Get our paths (for saving to resource), needed for converted old action maps.
  65. int get_path_count() const; // Get the number of io paths.
  66. bool has_path(const String p_path) const; // Has this io path.
  67. void add_path(const String p_path); // Add an io path.
  68. void remove_path(const String p_path); // Remove an io path.
  69. #endif // DISABLE_DEPRECATED
  70. // TODO add validation that we can display in the interface that checks if no two paths belong to the same top level path
  71. ~OpenXRIPBinding();
  72. };
  73. class OpenXRInteractionProfile : public Resource {
  74. GDCLASS(OpenXRInteractionProfile, Resource);
  75. private:
  76. String interaction_profile_path;
  77. Array bindings;
  78. Vector<Ref<OpenXRIPBindingModifier>> binding_modifiers;
  79. protected:
  80. friend class OpenXRActionMap;
  81. OpenXRActionMap *action_map = nullptr;
  82. static void _bind_methods();
  83. public:
  84. static Ref<OpenXRInteractionProfile> new_profile(const char *p_input_profile_path); // Helper function to create a new interaction profile
  85. OpenXRActionMap *get_action_map() { return action_map; }
  86. void set_interaction_profile_path(const String p_input_profile_path); // Set our input profile path
  87. String get_interaction_profile_path() const; // get our input profile path
  88. int get_binding_count() const; // Retrieve the number of bindings in this profile path
  89. Ref<OpenXRIPBinding> get_binding(int p_index) const;
  90. void set_bindings(const Array &p_bindings); // Set the bindings (for loading from a resource)
  91. Array get_bindings() const; // Get the bindings (for saving to a resource)
  92. Ref<OpenXRIPBinding> find_binding(const Ref<OpenXRAction> &p_action, const String &p_binding_path) const; // Get our binding record
  93. Vector<Ref<OpenXRIPBinding>> get_bindings_for_action(const Ref<OpenXRAction> &p_action) const; // Get our binding record for a given action
  94. void add_binding(const Ref<OpenXRIPBinding> &p_binding); // Add a binding object
  95. void remove_binding(const Ref<OpenXRIPBinding> &p_binding); // Remove a binding object
  96. void add_new_binding(const Ref<OpenXRAction> &p_action, const String &p_paths); // Create a new binding for this profile
  97. void remove_binding_for_action(const Ref<OpenXRAction> &p_action); // Remove all bindings for this action
  98. bool has_binding_for_action(const Ref<OpenXRAction> &p_action); // Returns true if we have a binding for this action
  99. int get_binding_modifier_count() const; // Retrieve the number of binding modifiers in this profile path
  100. Ref<OpenXRIPBindingModifier> get_binding_modifier(int p_index) const;
  101. void clear_binding_modifiers(); // Remove all binding modifiers
  102. void set_binding_modifiers(const Array &p_bindings); // Set the binding modifiers (for loading from a resource)
  103. Array get_binding_modifiers() const; // Get the binding modifiers (for saving to a resource)
  104. void add_binding_modifier(const Ref<OpenXRIPBindingModifier> &p_binding_modifier); // Add a binding modifier object
  105. void remove_binding_modifier(const Ref<OpenXRIPBindingModifier> &p_binding_modifier); // Remove a binding modifier object
  106. ~OpenXRInteractionProfile();
  107. };
  108. #endif // OPENXR_INTERACTION_PROFILE_H