input_event_configuration_dialog.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************************************************/
  2. /* input_event_configuration_dialog.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 INPUT_EVENT_CONFIGURATION_DIALOG_H
  31. #define INPUT_EVENT_CONFIGURATION_DIALOG_H
  32. #include "scene/gui/dialogs.h"
  33. class OptionButton;
  34. class Tree;
  35. class EventListenerLineEdit;
  36. class CheckBox;
  37. // Confirmation Dialog used when configuring an input event.
  38. // Separate from ActionMapEditor for code cleanliness and separation of responsibilities.
  39. class InputEventConfigurationDialog : public ConfirmationDialog {
  40. GDCLASS(InputEventConfigurationDialog, ConfirmationDialog)
  41. private:
  42. struct IconCache {
  43. Ref<Texture2D> keyboard;
  44. Ref<Texture2D> mouse;
  45. Ref<Texture2D> joypad_button;
  46. Ref<Texture2D> joypad_axis;
  47. } icon_cache;
  48. Ref<InputEvent> event;
  49. Ref<InputEvent> original_event;
  50. bool in_tree_update = false;
  51. // Listening for input
  52. EventListenerLineEdit *event_listener = nullptr;
  53. Label *event_as_text = nullptr;
  54. // List of All Key/Mouse/Joypad input options.
  55. int allowed_input_types;
  56. Tree *input_list_tree = nullptr;
  57. LineEdit *input_list_search = nullptr;
  58. // Additional Options, shown depending on event selected
  59. VBoxContainer *additional_options_container = nullptr;
  60. HBoxContainer *device_container = nullptr;
  61. OptionButton *device_id_option = nullptr;
  62. HBoxContainer *mod_container = nullptr; // Contains the subcontainer and the store command checkbox.
  63. enum ModCheckbox {
  64. MOD_ALT,
  65. MOD_SHIFT,
  66. MOD_CTRL,
  67. MOD_META,
  68. MOD_MAX
  69. };
  70. #if defined(MACOS_ENABLED)
  71. String mods[MOD_MAX] = { "Option", "Shift", "Ctrl", "Command" };
  72. #elif defined(WINDOWS_ENABLED)
  73. String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Windows" };
  74. #else
  75. String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Meta" };
  76. #endif
  77. String mods_tip[MOD_MAX] = { "Alt or Option key", "Shift key", "Control key", "Meta/Windows or Command key" };
  78. CheckBox *mod_checkboxes[MOD_MAX];
  79. CheckBox *autoremap_command_or_control_checkbox = nullptr;
  80. enum KeyMode {
  81. KEYMODE_KEYCODE,
  82. KEYMODE_PHY_KEYCODE,
  83. KEYMODE_UNICODE,
  84. };
  85. OptionButton *key_mode = nullptr;
  86. HBoxContainer *location_container = nullptr;
  87. OptionButton *key_location = nullptr;
  88. void _set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection = true);
  89. void _on_listen_input_changed(const Ref<InputEvent> &p_event);
  90. void _search_term_updated(const String &p_term);
  91. void _update_input_list();
  92. void _input_list_item_selected();
  93. void _mod_toggled(bool p_checked, int p_index);
  94. void _autoremap_command_or_control_toggled(bool p_checked);
  95. void _key_mode_selected(int p_mode);
  96. void _key_location_selected(int p_location);
  97. void _device_selection_changed(int p_option_button_index);
  98. void _set_current_device(int p_device);
  99. int _get_current_device() const;
  100. protected:
  101. void _notification(int p_what);
  102. public:
  103. // Pass an existing event to configure it. Alternatively, pass no event to start with a blank configuration.
  104. // An action name can be passed for descriptive purposes.
  105. void popup_and_configure(const Ref<InputEvent> &p_event = Ref<InputEvent>(), const String &p_current_action_name = "");
  106. Ref<InputEvent> get_event() const;
  107. void set_allowed_input_types(int p_type_masks);
  108. InputEventConfigurationDialog();
  109. };
  110. #endif // INPUT_EVENT_CONFIGURATION_DIALOG_H